自动化立体仓库 - WMS系统
src/main/java/com/zy/asrs/task/WorkMastScheduler.java
@@ -9,6 +9,7 @@
import com.zy.asrs.service.WrkMastService;
import com.zy.asrs.task.core.ReturnT;
import com.zy.asrs.task.handler.WorkMastHandler;
import com.zy.asrs.task.support.OutboundBatchSeqReleaseGuard;
import com.zy.asrs.utils.Utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -32,8 +33,6 @@
public class WorkMastScheduler {
    private static final Logger log = LoggerFactory.getLogger(WorkMastScheduler.class);
    private static final long OUT_LOCK_REPORT_SUCCESS_WRK_STS = 21L;
    private static final long OUT_LOCK_REPORT_FAIL_WRK_STS = 22L;
    @Autowired
    private WcsApiService wcsApiService;
@@ -41,6 +40,8 @@
    private WrkMastService wrkMastService;
    @Autowired
    private WorkMastHandler workMastHandler;
    @Autowired
    private OutboundBatchSeqReleaseGuard outboundBatchSeqReleaseGuard;
    @Scheduled(cron = "0/3 * * * * ? ")
    private void execute(){
@@ -93,8 +94,13 @@
                continue;
            }
            WorkTaskParams params = buildWorkTaskParams(wrkMast);
            if (isOutboundPublishTask(wrkMast)) {
                if (Cools.isEmpty(wrkMast.getBatchSeq())) {
                    log.warn("出库进仓编号(batchSeq)为空,跳过下发, wrkNo={}, userNo={}",
                            wrkMast.getWrkNo(), wrkMast.getUserNo());
                    continue;
                }
                WorkTaskParams params = buildWorkTaskParams(wrkMast);
                String userNo = normalizeGroupKey(wrkMast.getUserNo());
                String batchSeq = normalizeGroupKey(wrkMast.getBatchSeq());
                outboundTasksByUserNo
@@ -102,7 +108,7 @@
                        .computeIfAbsent(batchSeq, key -> new ArrayList<>())
                        .add(params);
            } else {
                paramsList.add(params);
                paramsList.add(buildWorkTaskParams(wrkMast));
            }
        }
@@ -123,10 +129,9 @@
            batchSeqs.sort(this::compareBatchSeqNatural);
            for (String batchSeq : batchSeqs) {
                String blockingBatchSeq = findFirstUnfinishedOutboundBatchSeq(userNo);
                if (blockingBatchSeq != null && compareBatchSeqNatural(batchSeq, blockingBatchSeq) != 0) {
                    log.info("出库批次未完成,暂停后续下发, userNo={}, blockingBatchSeq={}, nextBatchSeq={}",
                            userNo, blockingBatchSeq, batchSeq);
                String blockMsg = outboundBatchSeqReleaseGuard.validateReady(userNo, batchSeq);
                if (!Cools.isEmpty(blockMsg)) {
                    log.info(blockMsg);
                    break;
                }
@@ -183,30 +188,6 @@
    private boolean isOutboundPublishTask(WrkMast wrkMast) {
        return wrkMast != null && Objects.equals(wrkMast.getIoType(), 101);
    }
    private String findFirstUnfinishedOutboundBatchSeq(String userNo) {
        EntityWrapper<WrkMast> wrapper = new EntityWrapper<>();
        if (Cools.isEmpty(userNo)) {
            wrapper.isNull("user_no");
        } else {
            wrapper.eq("user_no", userNo);
        }
        wrapper.eq("io_type", 101);
        wrapper.last(" and (wrk_sts < 14 or wrk_sts in ("
                + OUT_LOCK_REPORT_SUCCESS_WRK_STS + "," + OUT_LOCK_REPORT_FAIL_WRK_STS + "))");
        List<WrkMast> rows = wrkMastService.selectList(wrapper);
        if (rows == null || rows.isEmpty()) {
            return null;
        }
        String firstBatchSeq = null;
        for (WrkMast row : rows) {
            String batchSeq = normalizeGroupKey(row.getBatchSeq());
            if (firstBatchSeq == null || compareBatchSeqNatural(batchSeq, firstBatchSeq) < 0) {
                firstBatchSeq = batchSeq;
            }
        }
        return firstBatchSeq;
    }
    private int compareBatchSeqNatural(String left, String right) {