自动化立体仓库 - WMS系统
src/main/java/com/zy/asrs/task/handler/WorkErpReportHandler.java
@@ -16,6 +16,7 @@
import com.zy.asrs.task.core.ReturnT;
import com.zy.common.entity.Parameter;
import com.zy.common.utils.HttpHandler;
import com.zy.integration.iot.biz.IotInstructionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
@@ -37,6 +38,7 @@
    public static final String ERP_REPORT_PENDING_FLAG = "P";
    public static final String ERP_REPORT_SUCCESS_FLAG = "Y";
    public static final String ERP_REPORT_FAIL_FLAG = "F";
    public static final String ERP_REPORT_SKIPPED_FLAG = "S";
    private static final String DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
@@ -48,6 +50,8 @@
    private WaitPakinService waitPakinService;
    @Autowired
    private ApiLogService apiLogService;
    @Autowired
    private IotInstructionService iotInstructionService;
    @Value("${erp.switch.ErpReportOld}")
    private boolean erpReportOld;
@@ -62,6 +66,13 @@
    public ReturnT<String> start(WrkMast source) {
        WrkMast wrkMast = wrkMastService.selectById(source.getWrkNo());
        if (wrkMast == null || !Long.valueOf(ERP_REPORT_PENDING_WRK_STS).equals(wrkMast.getWrkSts())) {
            return SUCCESS;
        }
        // 历史/运行中数据可能已经在完工时被置为 ERP 待上报。
        // 调度器执行前再做一次来源判断,确保 MQTT 来源任务即使已进入待上报状态,也会被改回完成态并跳过 ERP HTTP 调用。
        if (iotInstructionService.isMqttOriginWork(wrkMast)) {
            skipReport(wrkMast);
            return SUCCESS;
        }
@@ -335,6 +346,21 @@
        }
    }
    private void skipReport(WrkMast wrkMast) {
        Date now = new Date();
        wrkMast.setWrkSts(ERP_REPORT_FINISHED_WRK_STS);
        wrkMast.setLogMk(ERP_REPORT_SKIPPED_FLAG);
        wrkMast.setExpTime(0D);
        wrkMast.setLogErrMemo(null);
        wrkMast.setLogErrTime(null);
        wrkMast.setModiTime(now);
        if (!wrkMastService.updateById(wrkMast)) {
            throw new IllegalStateException("skip inbound erp report failed, workNo=" + wrkMast.getWrkNo());
        }
        // 兼容已进入 ERP 待上报的旧任务:跳过 ERP 后补一次 MQTT 完工入队,已有记录时 queueWorkCompletion 会直接返回。
        iotInstructionService.queueWorkCompletion(wrkMast);
    }
    private String truncate(String message, int maxLength) {
        if (message == null || message.length() <= maxLength) {
            return message;