demand: TMS系统 - 运输管理 -漏组批次全量扫描/根据线路扫描添加任务执行监控,只有上一个任务执行完毕,才能再次执行

committer: heyu
This commit is contained in:
aike 2025-10-23 10:46:25 +08:00
parent 0f4d66fb45
commit aa83c06225
2 changed files with 54 additions and 12 deletions

View File

@ -903,26 +903,56 @@ public class EmisCommonController extends EmisBaseController
/**
* 定时扫描运单货物组批次是否正确录入
*
* @return
*/
@GetMapping("/autoScanSiteBatch")
public AjaxResult autoScanSiteBatch(String lineCode){
String lockKey="autoScanSiteBatch";
public AjaxResult autoScanSiteBatch(String lineCode) {
String statusKey = "autoScanSiteBatch_status";
log.info("autoScanSiteBatch start");
// 加锁查询
redissonService.lock(lockKey,300);
try{
emisTmsSiteBatchMissService.autoScanSiteBatch(lineCode);
}catch(Exception ex){
ex.printStackTrace();
log.error("autoScanSiteBatch exception:"+ex.getMessage());
// 检查任务是否正在执行
String currentStatus = redissonService.getStr(statusKey);
if ("RUNNING".equals(currentStatus)) {
log.warn("autoScanSiteBatch is already running, request rejected");
return AjaxResult.error("任务正在执行中,请稍后再试");
}
log.info("autoScanSiteBatch end");
redissonService.unlock(lockKey);
return AjaxResult.success("发送成功");
try {
// 设置任务状态为运行中,设置较长的过期时间(30分钟)
// 这样即使异步任务没有正确清除状态,也会在30分钟后自动过期
redissonService.setStr(statusKey, "RUNNING", 1800);
// 异步执行任务
emisTmsSiteBatchMissService.autoScanSiteBatch(lineCode);
log.info("autoScanSiteBatch async task started");
return AjaxResult.success("异步任务已启动,请稍后查看执行结果");
} catch (Exception ex) {
ex.printStackTrace();
log.error("autoScanSiteBatch exception:" + ex.getMessage());
// 如果启动失败,清除状态
redissonService.setStr(statusKey, "", 0);
return AjaxResult.error("任务启动失败:" + ex.getMessage());
}
}
/**
* 查询autoScanSiteBatch任务状态
*
* @return
*/
@GetMapping("/checkAutoScanSiteBatchStatus")
public AjaxResult checkAutoScanSiteBatchStatus() {
String statusKey = "autoScanSiteBatch_status";
String currentStatus = redissonService.getStr(statusKey);
if ("RUNNING".equals(currentStatus)) {
return AjaxResult.success("任务正在执行中");
} else {
return AjaxResult.success("任务未在执行");
}
}
/**

View File

@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import cn.hutool.core.collection.CollectionUtil;
import com.xdadan.erp.common.core.redis.RedissonService;
import com.xdadan.erp.emis.domain.*;
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
import com.xdadan.erp.emis.domain.exception.EmisBizError;
@ -55,6 +56,9 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
@Autowired
private EmisTmsSiteBatchMissRecordMapper emisTmsSiteBatchMissRecordMapper;
@Autowired
RedissonService redissonService;
/**
* 查询TMS漏组批次信息
*
@ -428,6 +432,14 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
Thread.currentThread().interrupt();
}
}
// 清除任务状态
try {
String statusKey = "autoScanSiteBatch_status";
redissonService.setStr(statusKey, "", 0);
log.info("autoScanSiteBatch task status cleared");
} catch (Exception e) {
log.error("Failed to clear autoScanSiteBatch status", e);
}
}
}