Junjie
3 天以前 63b01db83d9aad8a15276b4236a9a22e4aeef065
src/main/java/com/zy/core/service/WrkCommandRollbackService.java
@@ -1,6 +1,7 @@
package com.zy.core.service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.core.common.Cools;
import com.core.exception.CoolException;
import com.zy.asrs.domain.param.ManualRollbackTaskParam;
@@ -70,13 +71,21 @@
        saveWrkLog(wrkMast.getWrkNo());
        wrkMast.setWrkSts(updateStatus);
        wrkMast.setSendFailCount(nextFailCount);
        wrkMast.setErrorTime(new Date());
        wrkMast.setErrorMemo(failMessage);
        wrkMast.setSystemMsg(failMessage);
        wrkMast.setModiTime(new Date());
        wrkMastService.updateById(wrkMast);
        Long currentWrkSts = wrkMast.getWrkSts();
        Date now = new Date();
        boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
                .set("wrk_sts", updateStatus)
                .set("send_fail_count", nextFailCount)
                .set("error_time", now)
                .set("error_memo", failMessage)
                .set("system_msg", failMessage)
                .set("modi_time", now)
                .eq("wrk_no", wrkMast.getWrkNo())
                .eq("wrk_sts", currentWrkSts));
        if (!updated) {
            log.info("工作档状态已变化,跳过命令失败回滚。wrkNo={}", wrkMast.getWrkNo());
            return;
        }
        if (manualRequired) {
            News.taskError(wrkMast.getWrkNo(), "{}下发命令失败,已达到自动回滚上限({}),请在工作档手动回滚。原因: {}", deviceName, rollbackLimit, failMessage);
@@ -99,11 +108,17 @@
        saveWrkLog(wrkMast.getWrkNo());
        wrkMast.setWrkSts(rollbackStatus);
        wrkMast.setSendFailCount(0);
        wrkMast.setSystemMsg("人工回滚完成,等待重新下发");
        wrkMast.setModiTime(new Date());
        wrkMastService.updateById(wrkMast);
        Long currentWrkSts = wrkMast.getWrkSts();
        boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
                .set("wrk_sts", rollbackStatus)
                .set("send_fail_count", 0)
                .set("system_msg", "人工回滚完成,等待重新下发")
                .set("modi_time", new Date())
                .eq("wrk_no", wrkMast.getWrkNo())
                .eq("wrk_sts", currentWrkSts));
        if (!updated) {
            throw new CoolException("任务状态已变化,请刷新后重试");
        }
        News.taskInfo(wrkMast.getWrkNo(), "人工回滚完成,任务状态已恢复为待执行");
        return true;
    }
@@ -118,12 +133,17 @@
        saveWrkLog(wrkMast.getWrkNo());
        wrkMast.setSendFailCount(0);
        wrkMast.setErrorTime(null);
        wrkMast.setErrorMemo(null);
        wrkMast.setSystemMsg("");
        wrkMast.setModiTime(new Date());
        wrkMastService.updateById(wrkMast);
        boolean updated = wrkMastService.update(null, new UpdateWrapper<WrkMast>()
                .set("send_fail_count", 0)
                .set("error_time", null)
                .set("error_memo", null)
                .set("system_msg", "")
                .set("modi_time", new Date())
                .eq("wrk_no", wrkMast.getWrkNo())
                .eq("wrk_sts", wrkMast.getWrkSts()));
        if (!updated) {
            log.info("工作档状态已变化,跳过清理下发失败标记。wrkNo={}", wrkMast.getWrkNo());
        }
    }
    private WrkMast findWrkMast(Integer wrkNo, String taskNo) {
@@ -168,18 +188,22 @@
    private boolean isSingleCrnRunStatus(Long wrkSts) {
        return Long.valueOf(WrkStsType.INBOUND_RUN.sts).equals(wrkSts)
                || Long.valueOf(WrkStsType.OUTBOUND_RUN.sts).equals(wrkSts)
                || Long.valueOf(WrkStsType.LOC_MOVE_RUN.sts).equals(wrkSts);
                || Long.valueOf(WrkStsType.LOC_MOVE_RUN.sts).equals(wrkSts)
                || Long.valueOf(WrkStsType.CRN_MOVE_RUN.sts).equals(wrkSts);
    }
    private Long getRollbackStatus(Long wrkSts) {
        if (Long.valueOf(WrkStsType.INBOUND_RUN.sts).equals(wrkSts)) {
            return WrkStsType.INBOUND_DEVICE_RUN.sts;
            return WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts;
        }
        if (Long.valueOf(WrkStsType.OUTBOUND_RUN.sts).equals(wrkSts)) {
            return WrkStsType.NEW_OUTBOUND.sts;
        }
        if (Long.valueOf(WrkStsType.LOC_MOVE_RUN.sts).equals(wrkSts)) {
            return WrkStsType.NEW_LOC_MOVE.sts;
        }
        if (Long.valueOf(WrkStsType.CRN_MOVE_RUN.sts).equals(wrkSts)) {
            return WrkStsType.NEW_CRN_MOVE.sts;
        }
        return null;
    }
@@ -194,12 +218,15 @@
        if (Long.valueOf(WrkStsType.LOC_MOVE_RUN.sts).equals(wrkSts)) {
            return WrkStsType.LOC_MOVE_MANUAL.sts;
        }
        if (Long.valueOf(WrkStsType.CRN_MOVE_RUN.sts).equals(wrkSts)) {
            return WrkStsType.CRN_MOVE_MANUAL.sts;
        }
        return null;
    }
    private Long getRollbackStatusFromManual(Long wrkSts) {
        if (Long.valueOf(WrkStsType.INBOUND_MANUAL.sts).equals(wrkSts)) {
            return WrkStsType.INBOUND_DEVICE_RUN.sts;
            return WrkStsType.INBOUND_STATION_RUN_COMPLETE.sts;
        }
        if (Long.valueOf(WrkStsType.OUTBOUND_MANUAL.sts).equals(wrkSts)) {
            return WrkStsType.NEW_OUTBOUND.sts;
@@ -207,6 +234,9 @@
        if (Long.valueOf(WrkStsType.LOC_MOVE_MANUAL.sts).equals(wrkSts)) {
            return WrkStsType.NEW_LOC_MOVE.sts;
        }
        if (Long.valueOf(WrkStsType.CRN_MOVE_MANUAL.sts).equals(wrkSts)) {
            return WrkStsType.NEW_CRN_MOVE.sts;
        }
        return null;
    }
}