#
Junjie
昨天 2c02ce3745c94be523b045d6f00815ec9f3b9b9a
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -2,7 +2,6 @@
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.core.common.SpringUtils;
import com.zy.asrs.domain.enums.NotifyMsgType;
import com.zy.asrs.entity.*;
import com.zy.asrs.service.*;
@@ -143,7 +142,7 @@
    public synchronized boolean shuttleInExecuteStep1(WrkMast wrkMast) {
        if (wrkMast.getWrkSts() == WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts) {
            //获取目标站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftSta == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,缺少站点信息,禁止派发", wrkMast.getWrkNo());
                return false;
@@ -272,30 +271,30 @@
            Integer liftNo = wrkMast.getLiftNo();
            if (liftNo == null) {
                //通过输送线站号获取提升机号
                liftNo = ForkLiftUtils.getConveyorBindLiftNo(wrkMast.getStaNo());
                liftNo = LiftUtils.getConveyorBindLiftNo(wrkMast.getStaNo());
                if (liftNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,未找到匹配的提升机", wrkMast.getWrkNo());
                    return false;
                }
            }
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
            if (liftThread == null) {
                return false;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                return false;
            }
            //判断提升机是否处于出库模式
            if (!forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.OUT)) {
            if (!liftProtocol.getIOModeType().equals(LiftIoModeType.OUT)) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,提升机不处于出库模式,禁止出库", wrkMast.getWrkNo());
                return false;
            }
            //获取源站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByLev(liftNo, Utils.getLev(wrkMast.getSourceLocNo()));
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByLev(liftNo, Utils.getLev(wrkMast.getSourceLocNo()));
            if (liftSta == null) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,缺少站点信息,禁止派发", wrkMast.getWrkNo());
                return false;
@@ -617,18 +616,13 @@
        //1.生成入库任务 ==> 3.提升机搬运中
        if (wrkMast.getWrkSts() == WrkStsType.NEW_INBOUND.sts) {
            //获取目标输送站
            ForkLiftStaProtocol liftSta = ForkLiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            LiftStaProtocol liftSta = LiftUtils.getLiftStaByStaNo(wrkMast.getStaNo());
            if (liftSta == null) {
                return false;//找不到站点
            }
            if (liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在托盘", wrkMast.getWrkNo());
                return false;
            }
            if (liftSta.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在小车", wrkMast.getWrkNo());
                return false;
            }
@@ -701,7 +695,7 @@
            }
            //获取提升机命令
            LiftCommand liftCommand = liftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getLev());
            LiftCommand liftCommand = liftThread.getPickAndPutCommand(wrkMast.getWrkNo(), wrkMast.getSourceStaNo(), liftSta.getSiteId());
            ArrayList<LiftCommand> commands = new ArrayList<>();
            commands.add(liftCommand);
@@ -710,7 +704,7 @@
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftNo);
            assignCommand.setTaskNo(wrkMast.getWrkNo());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id);
            assignCommand.setTaskMode(LiftTaskModeType.PICK_PUT.id);
            wrkMast.setWrkSts(WrkStsType.INBOUND_LIFT_RUN.sts);//提升机搬运中  1.生成入库任务 ==> 3.提升机搬运中
            wrkMast.setSystemMsg("");//清空消息
@@ -774,11 +768,6 @@
                return false;
            }
            if (liftSta.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点存在小车,禁止派发", wrkMast.getWrkNo(), liftSta.getSiteId());
                return false;
            }
            if (!liftSta.getHasTray()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,{}站点无托盘,禁止派发", wrkMast.getWrkNo(), liftSta.getSiteId());
                return false;
@@ -788,7 +777,7 @@
            if (liftNo == null) {
                //未分配提升机
                Integer staNo = wrkMast.getStaNo();
                liftNo = ForkLiftUtils.getConveyorBindLiftNo(staNo);
                liftNo = LiftUtils.getConveyorBindLiftNo(staNo);
                if(liftNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,未找到匹配的提升机", wrkMast.getWrkNo());
                    return false;
@@ -838,7 +827,7 @@
            assignCommand.setCommands(commands);
            assignCommand.setLiftNo(liftNo);
            assignCommand.setTaskNo(wrkMast.getWrkNo());
            assignCommand.setTaskMode(ForkLiftTaskModeType.PICK_PUT.id);
            assignCommand.setTaskMode(LiftTaskModeType.PICK_PUT.id);
            wrkMast.setWrkSts(WrkStsType.OUTBOUND_LIFT_RUN.sts);//提升机搬运中  103.生成入库任务 ==> 104.提升机搬运中
            wrkMast.setShuttleNo(null);//释放小车
@@ -904,8 +893,8 @@
                            News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
                        }
                    }else {
                        boolean checkPreviewDispatchForkLift = commonService.checkWorkNoContainMk(liftProtocol.getTaskNo(), WrkIoType.PREVIEW_LIFT_MOVE.id);
                        if (checkPreviewDispatchForkLift) {
                        boolean checkPreviewDispatchLift = commonService.checkWorkNoContainMk(liftProtocol.getTaskNo(), WrkIoType.PREVIEW_LIFT_MOVE.id);
                        if (checkPreviewDispatchLift) {
                            //属于提升机预调度移动任务
                            //无工作档支撑,直接确认完成
                            liftThread.setSyncTaskNo(0);
@@ -1011,31 +1000,31 @@
     */
    private void recLiftErr() {
        Date now = new Date();
        List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
        for (DeviceConfig device : forkliftList) {
        List<DeviceConfig> liftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Lift)));
        for (DeviceConfig device : liftList) {
            // 获取提升机信息
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
            if (forkLiftThread == null) {
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, device.getDeviceNo());
            if (liftThread == null) {
                continue;
            }
            ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
            if (forkLiftProtocol == null) {
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                continue;
            }
            if (forkLiftProtocol.getTaskNo() != 0) {
            if (liftProtocol.getTaskNo() != 0) {
                //有任务
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(device.getDeviceNo(), forkLiftProtocol.getTaskNo());
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(device.getDeviceNo(), liftProtocol.getTaskNo());
                // 有异常
                if (latest == null) {
                    if (forkLiftProtocol.getErrorCode() != null && forkLiftProtocol.getErrorCode() != 0) {
                        WrkMast wrkMast = wrkMastService.selectByWorkNo(forkLiftProtocol.getWrkNo());
                    if (liftProtocol.getErrorCode() != null && liftProtocol.getErrorCode() != 0) {
                        WrkMast wrkMast = wrkMastService.selectByWorkNo(liftProtocol.getTaskNo());
                        if (wrkMast == null) {
                            continue;
                        }
                        BasLiftErr basLiftErr = basLiftErrService.queryByCode(forkLiftProtocol.getErrorCode());
                        BasLiftErr basLiftErr = basLiftErrService.queryByCode(liftProtocol.getErrorCode());
                        String errName = basLiftErr==null? "未知异常":basLiftErr.getErrName();
                        BasLiftErrLog basLiftErrLog = new BasLiftErrLog(
@@ -1060,7 +1049,7 @@
                                now,    // 修改时间
                                null,    // 修改人员
                                "任务中异常",    // 备注
                                JSON.toJSONString(forkLiftProtocol)    // 系统状态数据
                                JSON.toJSONString(liftProtocol)    // 系统状态数据
                        );
                        if (!basLiftErrLogService.insert(basLiftErrLog)) {
                            News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName);
@@ -1068,7 +1057,7 @@
                    }
                } else {
                    // 异常修复
                    if (forkLiftProtocol.getErrorCode() == null || forkLiftProtocol.getErrorCode() == 0) {
                    if (liftProtocol.getErrorCode() == null || liftProtocol.getErrorCode() == 0) {
                        latest.setEndTime(now);
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
@@ -1388,6 +1377,11 @@
                return false;
            }
            Object limitObj = redisUtil.get(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo());
            if (limitObj != null) {
                return false;
            }
            //小车已经在充电桩位置,下发停止充电命令
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
@@ -1400,6 +1394,7 @@
            //下发任务
            shuttleAction.assignWork(shuttleProtocol.getShuttleNo(), assignCommand);
            redisUtil.set(RedisKeyType.TASK_RUN_LIMIT.key + wrkMast.getWrkNo(), "limit", 10);
            return false;
        }
        return true;
@@ -1949,4 +1944,75 @@
        return true;
    }
    //自动切换出入库模式
    public void autoSwitchLiftIOMode() {
        List<DeviceConfig> liftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Lift)));
        for (DeviceConfig device : liftList) {
            Integer liftNo = device.getDeviceNo();
            LiftThread liftThread = (LiftThread) SlaveConnection.get(SlaveType.Lift, liftNo);
            if (liftThread == null) {
                continue;
            }
            LiftProtocol liftProtocol = liftThread.getStatus();
            if (liftProtocol == null) {
                continue;
            }
            List<Integer> liftAllStaNo = LiftUtils.getLiftAllStaNo(liftNo);
            if (liftAllStaNo.isEmpty()) {
                continue;
            }
            List<Integer> conveyorBindLiftAllStaNo = LiftUtils.getConveyorBindLiftAllStaNo(liftNo);
            if (conveyorBindLiftAllStaNo.isEmpty()) {
                continue;
            }
            //获取入库任务
            List<WrkMast> inWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .in("sta_no", liftAllStaNo)
                    .in("wrk_sts"
                            , WrkStsType.NEW_INBOUND.sts
                            , WrkStsType.INBOUND_DEVICE_RUN.sts
                            , WrkStsType.INBOUND_LIFT_RUN.sts
                            , WrkStsType.INBOUND_LIFT_RUN_COMPLETE.sts
                            , WrkStsType.INBOUND_SHUTTLE_RUN.sts
                            , WrkStsType.INBOUND_SHUTTLE_RUN_COMPLETE.sts
                    ));
            //获取出库任务
            List<WrkMast> outWrkMasts = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .in("sta_no", conveyorBindLiftAllStaNo)
                    .in("wrk_sts"
                            , WrkStsType.NEW_OUTBOUND.sts
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN.sts
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN_COMPLETE.sts
                    ));
            if (liftProtocol.getIOModeType().equals(LiftIoModeType.NONE)) {
                //未知模式
                if (!inWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.IN);
                } else if (!outWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.OUT);
                }else {
                    liftThread.switchIOMode(LiftIoModeType.IN);
                }
            } else if (liftProtocol.getIOModeType().equals(LiftIoModeType.IN)) {
                //入库模式
                if (inWrkMasts.isEmpty() && !outWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.OUT);
                }
            } else if (liftProtocol.getIOModeType().equals(LiftIoModeType.OUT)) {
                //出库模式
                if (outWrkMasts.isEmpty() && !inWrkMasts.isEmpty()) {
                    liftThread.switchIOMode(LiftIoModeType.IN);
                }
            }
        }
    }
}