异步更新缓存

parent a4664aaf
......@@ -4,10 +4,13 @@ package com.aps;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
@SpringBootApplication
@MapperScan("com.aps.mapper") // 扫描Mapper接口
@EnableAsync
public class ApsApplication {
public static void main(String[] args) {
......
......@@ -8,7 +8,10 @@ import com.aps.service.ProdSceneConfigService;
import com.aps.service.plan.PlanResultService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -27,6 +30,7 @@ public class LanuchController {
@Autowired
private ProdSceneConfigService prodSceneConfigService;
private static final Logger log = LoggerFactory.getLogger(LanuchController.class);
/**
* 启动工单
......@@ -34,10 +38,31 @@ public class LanuchController {
@PostMapping("/execute")
@Operation(summary = "启动工单")
public R<ProdSceneConfig> lanuch(@RequestBody Map<String, String> params) {
String sceneName = params.get("sceneName");
String userId = params.get("userId");
return lanuchService.lanuch(sceneName, userId);
R<ProdSceneConfig> result = lanuchService.lanuch(sceneName, userId);
// 异步更新物料和设备缓存
updateMaterialAndEquipmentCacheAsync();
return result;
}
@Async
public void updateMaterialAndEquipmentCacheAsync() {
try {
log.info("开始异步更新物料缓存");
planResultService.getMaterials();
log.info("物料缓存更新完成");
log.info("开始异步更新设备缓存");
planResultService.InitCalendarToAllMachines();
log.info("设备缓存更新完成");
} catch (Exception e) {
log.error("异步更新物料和设备缓存时发生错误: ", e);
}
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment