Junjie
2023-04-10 d91105438a87e013c6de439af89e49f055827b65
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -68,6 +68,10 @@
    @Autowired
    private BasSteErrLogService basSteErrLogService;
    @Autowired
    private BasShuttleErrLogService basShuttleErrLogService;
    @Autowired
    private BasShuttleErrService basShuttleErrService;
    @Autowired
    private BasCrnErrorMapper basCrnErrorMapper;
    @Autowired
    private BasSteService basSteService;
@@ -2918,6 +2922,7 @@
     */
    public void recErr() {
        try {
            this.recShuttleErr();
            this.recCrnErr();
            this.recSteErr();
        } catch (Exception e) {
@@ -2926,6 +2931,124 @@
    }
    /**
     * 四向穿梭车异常信息记录
     */
    private void recShuttleErr() {
        Date now = new Date();
        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
            // 获取堆垛机信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
            if (shuttleThread == null) {
                continue;
            }
            ShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol == null) {
                continue;
            }
            if (shuttleProtocol.getTaskNo() != 0) {
                //有任务
                BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo().intValue());
                // 有异常
                if (latest == null) {
                    if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) {
                        WrkMast wrkMast = wrkMastMapper.selectById(shuttleProtocol.getTaskNo());
                        if (wrkMast == null) {
                            continue;
                        }
                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue());
                        String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName();
                        BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
                                null,    // 编号
                                wrkMast.getWrkNo(),    // 工作号
                                now,    // 发生时间
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                shuttleSlave.getId(),    // 四向穿梭车
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
                                wrkMast.getSourceStaNo(),    // 源站
                                wrkMast.getSourceLocNo(),    // 源库位
                                wrkMast.getBarcode(),    // 条码
                                (int) shuttleProtocol.getStatusErrorCode(),    // 异常码
                                errName,    // 异常
                                1,    // 异常情况
                                now,    // 添加时间
                                null,    // 添加人员
                                now,    // 修改时间
                                null,    // 修改人员
                                "任务中异常"    // 备注
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
                        }
                    }
                } else {
                    // 异常修复
                    if (shuttleProtocol.getStatusErrorCode() == null || shuttleProtocol.getStatusErrorCode() == 0) {
                        latest.setEndTime(now);
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basShuttleErrLogService.updateById(latest)) {
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
                        }
                    }
                }
            }else {
                //无任务
                BasShuttleErrLog latest = basShuttleErrLogService.findLatest(shuttleSlave.getId());
                // 有异常
                if (shuttleProtocol.getStatusErrorCode() != null && shuttleProtocol.getStatusErrorCode() > 0) {
                    // 记录新异常
                    if (latest == null || (latest.getErrCode() != shuttleProtocol.getStatusErrorCode().intValue())) {
                        BasShuttleErr basShuttleErr = basShuttleErrService.queryByCode(shuttleProtocol.getStatusErrorCode().intValue());
                        String errName = basShuttleErr==null? "未知异常":basShuttleErr.getErrName();
                        BasShuttleErrLog basShuttleErrLog = new BasShuttleErrLog(
                                null,    // 编号
                                null,    // 工作号
                                now,    // 发生时间
                                null,    // 结束时间
                                null,    // 工作状态
                                null,    // 入出库类型
                                shuttleSlave.getId(),    // 四向穿梭车
                                null,    // plc
                                null,    // 目标库位
                                null,    // 目标站
                                null,    // 源站
                                null,    // 源库位
                                null,    // 条码
                                (int)shuttleProtocol.getStatusErrorCode(),    // 异常码
                                errName,    // 异常
                                1,    // 异常情况
                                now,    // 添加时间
                                null,    // 添加人员
                                now,    // 修改时间
                                null,    // 修改人员
                                "无任务异常"    // 备注
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
                        }
                    }
                    // 无异常
                } else {
                    // 异常修复
                    if (latest != null && latest.getStatus() == 1) {
                        latest.setEndTime(now);
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basShuttleErrLogService.updateById(latest)) {
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
                        }
                    }
                }
            }
        }
    }
    /**
     * 堆垛机异常信息记录
     */
    private void recCrnErr(){