异步更新访问量

This commit is contained in:
wangliwen 2022-07-07 12:00:42 +08:00
parent fc715c9cd4
commit e494a94c57
1 changed files with 7 additions and 1 deletions

View File

@ -27,6 +27,9 @@ import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* 浏览记录
@ -38,6 +41,7 @@ import java.util.Map;
@RequestMapping("/resourceBrowse")
@Api(tags = "浏览记录")
public class ResourceBrowseController {
private static final ExecutorService executor = Executors.newWorkStealingPool();
@Autowired
private ResourceBrowseService resourceBrowseService;
@Autowired
@ -86,7 +90,9 @@ public class ResourceBrowseController {
dto.setCreator(SecurityUser.getUserId());
dto.setUserId(SecurityUser.getUserId());
resourceBrowseService.save(dto);
jdbcTemplate.update("UPDATE tb_data_resource SET visitor = (SELECT COUNT(id) FROM tb_resource_browse WHERE resource_id = tb_data_resource.id) WHERE tb_data_resource.id = " + dto.getResourceId());
CompletableFuture.runAsync(() -> {
jdbcTemplate.update("UPDATE tb_data_resource SET visitor = (SELECT COUNT(id) FROM tb_resource_browse WHERE resource_id = tb_data_resource.id) WHERE tb_data_resource.id = " + dto.getResourceId());
}, executor);
return new Result().ok(dto);
}