demand: TMS系统 - 运输管理 -漏组批次全量扫描/根据线路扫描添加任务执行监控,只有上一个任务执行完毕,才能再次执行
committer: heyu
This commit is contained in:
parent
0f4d66fb45
commit
aa83c06225
@ -903,26 +903,56 @@ public class EmisCommonController extends EmisBaseController
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 定时扫描运单货物组批次是否正确录入
|
* 定时扫描运单货物组批次是否正确录入
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@GetMapping("/autoScanSiteBatch")
|
@GetMapping("/autoScanSiteBatch")
|
||||||
public AjaxResult autoScanSiteBatch(String lineCode) {
|
public AjaxResult autoScanSiteBatch(String lineCode) {
|
||||||
String lockKey="autoScanSiteBatch";
|
String statusKey = "autoScanSiteBatch_status";
|
||||||
log.info("autoScanSiteBatch start");
|
log.info("autoScanSiteBatch start");
|
||||||
|
|
||||||
// 加锁查询
|
// 检查任务是否正在执行
|
||||||
redissonService.lock(lockKey,300);
|
String currentStatus = redissonService.getStr(statusKey);
|
||||||
|
if ("RUNNING".equals(currentStatus)) {
|
||||||
|
log.warn("autoScanSiteBatch is already running, request rejected");
|
||||||
|
return AjaxResult.error("任务正在执行中,请稍后再试");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// 设置任务状态为运行中,设置较长的过期时间(30分钟)
|
||||||
|
// 这样即使异步任务没有正确清除状态,也会在30分钟后自动过期
|
||||||
|
redissonService.setStr(statusKey, "RUNNING", 1800);
|
||||||
|
|
||||||
|
// 异步执行任务
|
||||||
emisTmsSiteBatchMissService.autoScanSiteBatch(lineCode);
|
emisTmsSiteBatchMissService.autoScanSiteBatch(lineCode);
|
||||||
|
log.info("autoScanSiteBatch async task started");
|
||||||
|
|
||||||
|
return AjaxResult.success("异步任务已启动,请稍后查看执行结果");
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
log.error("autoScanSiteBatch exception:" + ex.getMessage());
|
log.error("autoScanSiteBatch exception:" + ex.getMessage());
|
||||||
|
// 如果启动失败,清除状态
|
||||||
|
redissonService.setStr(statusKey, "", 0);
|
||||||
|
return AjaxResult.error("任务启动失败:" + ex.getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.info("autoScanSiteBatch end");
|
|
||||||
|
|
||||||
redissonService.unlock(lockKey);
|
/**
|
||||||
return AjaxResult.success("发送成功");
|
* 查询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("任务未在执行");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
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.*;
|
||||||
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType;
|
||||||
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||||
@ -55,6 +56,9 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
|
|||||||
@Autowired
|
@Autowired
|
||||||
private EmisTmsSiteBatchMissRecordMapper emisTmsSiteBatchMissRecordMapper;
|
private EmisTmsSiteBatchMissRecordMapper emisTmsSiteBatchMissRecordMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
RedissonService redissonService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询TMS漏组批次信息
|
* 查询TMS漏组批次信息
|
||||||
*
|
*
|
||||||
@ -428,6 +432,14 @@ public class EmisTmsSiteBatchMissServiceImpl extends EmisBaseService implements
|
|||||||
Thread.currentThread().interrupt();
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user