#
Junjie
3 天以前 ce9c9af4a3710d17e17814bab629ab4ef474f3f1
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -76,6 +76,8 @@
    private NotifyUtils notifyUtils;
    @Autowired
    private BasShuttleChargeService basShuttleChargeService;
    @Autowired
    private DeviceConfigService deviceConfigService;
    /**
     * 初始化实时地图
@@ -309,6 +311,23 @@
                return false;
            }
            List<WrkMast> shuttleMoveList = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("io_type", 200)
            );
            for (WrkMast moveWrkMast : shuttleMoveList) {
                if(Utils.getLev(moveWrkMast.getLocNo()) != Utils.getLev(wrkMast.getSourceLocNo())) {
                    continue;
                }
                if(Utils.getLev(moveWrkMast.getLocNo()) == Utils.getLev(moveWrkMast.getSourceLocNo())) {
                    continue;
                }
                //存在换层任务,出库任务暂时不执行
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,存在换层任务,出库任务等待中", wrkMast.getWrkNo());
                return false;
            }
            boolean checkLocPathIsAvailable = navigateUtils.checkLocPathIsAvailable(wrkMast.getSourceLocNo(), liftSta.getLocNo());
            if(!checkLocPathIsAvailable) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,未计算到可执行路径,等待中", wrkMast.getWrkNo());
@@ -421,9 +440,11 @@
     */
    public synchronized void shuttleFinished() {
        try {
            for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
            List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Shuttle)));
            for (DeviceConfig device : shuttleList) {
                //获取四向穿梭车信息
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
                ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
                if (shuttleProtocol == null) {
                    continue;
@@ -676,6 +697,29 @@
                return false;
            }
            //检测楼层是否有可用穿梭车
            boolean checkLevHasShuttle = Utils.checkLevHasShuttle(liftSta.getLev());
            if (!checkLevHasShuttle) {
                if (wrkMast.getShuttleNo() != null) {
                    return false;
                }
                //获取小车待机位
                String standbyLocNo = Utils.getShuttleStandbyLocNo(liftSta.getLocNo());
                if (standbyLocNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,获取小车待机位失败", wrkMast.getWrkNo());
                    return false;
                }
                //调度小车去待机位
                boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), standbyLocNo);
                if (!dispatchShuttle) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,调度小车失败", wrkMast.getWrkNo());
                    return false;
                }
                return false;
            }
            Integer liftNo = wrkMast.getLiftNo();
            if (liftNo == null) {
                //未分配提升机
@@ -711,29 +755,6 @@
            //判断提升机是否处于入库模式
            if (!forkLiftProtocol.getIOModeType().equals(ForkLiftIoModeType.IN)) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,提升机不处于入库模式,禁止入库", wrkMast.getWrkNo());
                return false;
            }
            //检测楼层是否有可用穿梭车
            boolean checkLevHasShuttle = Utils.checkLevHasShuttle(liftSta.getLev());
            if (!checkLevHasShuttle) {
                if (wrkMast.getShuttleNo() != null) {
                    return false;
                }
                //获取小车待机位
                String standbyLocNo = Utils.getShuttleStandbyLocNo(liftSta.getLocNo());
                if (standbyLocNo == null) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,获取小车待机位失败", wrkMast.getWrkNo());
                    return false;
                }
                //调度小车去待机位
                boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(wrkMast.getWrkNo(), standbyLocNo);
                if (!dispatchShuttle) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,调度小车失败", wrkMast.getWrkNo());
                    return false;
                }
                return false;
            }
@@ -902,9 +923,11 @@
     */
    public synchronized void forkLiftFinished() {
        try {
            for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
            List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.ForkLift)));
            for (DeviceConfig device : forkliftList) {
                //获取提升机信息
                ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
                ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
                ForkLiftProtocol forkLiftProtocol = forkLiftThread.getStatus();
                if (forkLiftProtocol == null) {
                    continue;
@@ -974,9 +997,11 @@
     */
    private void recShuttleErr() {
        Date now = new Date();
        for (ShuttleSlave shuttleSlave : slaveProperties.getShuttle()) {
        List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.Shuttle)));
        for (DeviceConfig device : shuttleList) {
            // 获取四向穿梭车信息
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttleSlave.getId());
            ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
            if (shuttleThread == null) {
                continue;
            }
@@ -987,7 +1012,7 @@
            if (shuttleProtocol.getTaskNo() != 0) {
                //有任务
                BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(shuttleSlave.getId(), shuttleProtocol.getTaskNo());
                BasShuttleErrLog latest = basShuttleErrLogService.findLatestByTaskNo(device.getDeviceNo(), shuttleProtocol.getTaskNo());
                // 有异常
                if (latest == null) {
                    if (shuttleProtocol.getErrorCode() != null && Integer.parseInt(shuttleProtocol.getErrorCode()) != 0) {
@@ -1005,7 +1030,7 @@
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                shuttleSlave.getId(),    // 四向穿梭车
                                device.getDeviceNo(),    // 四向穿梭车
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
@@ -1023,7 +1048,7 @@
                                JSON.toJSONString(shuttleProtocol)    // 系统状态数据
                        );
                        if (!basShuttleErrLogService.insert(basShuttleErrLog)) {
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", shuttleSlave.getId(), errName);
                            News.error("四向穿梭车plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName);
                        }
                    }
                } else {
@@ -1033,7 +1058,7 @@
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basShuttleErrLogService.updateById(latest)) {
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", shuttleSlave.getId(), latest.getId());
                            News.error("四向穿梭车plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", device.getDeviceNo(), latest.getId());
                        }
                    }
                }
@@ -1046,9 +1071,11 @@
     */
    private void recLiftErr() {
        Date now = new Date();
        for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
        List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
        for (DeviceConfig device : forkliftList) {
            // 获取提升机信息
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, forkLiftSlave.getId());
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, device.getDeviceNo());
            if (forkLiftThread == null) {
                continue;
            }
@@ -1059,7 +1086,7 @@
            if (forkLiftProtocol.getTaskNo() != 0) {
                //有任务
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(forkLiftSlave.getId(), forkLiftProtocol.getTaskNo());
                BasLiftErrLog latest = basLiftErrLogService.findLatestByTaskNo(device.getDeviceNo(), forkLiftProtocol.getTaskNo());
                // 有异常
                if (latest == null) {
                    if (forkLiftProtocol.getErrorCode() != null && forkLiftProtocol.getErrorCode() != 0) {
@@ -1078,7 +1105,7 @@
                                null,    // 结束时间
                                wrkMast.getWrkSts(),    // 工作状态
                                wrkMast.getIoType(),    // 入出库类型
                                forkLiftSlave.getId(),    // 提升机
                                device.getDeviceNo(),    // 提升机
                                null,    // plc
                                wrkMast.getLocNo(),    // 目标库位
                                wrkMast.getStaNo(),    // 目标站
@@ -1096,7 +1123,7 @@
                                JSON.toJSONString(forkLiftProtocol)    // 系统状态数据
                        );
                        if (!basLiftErrLogService.insert(basLiftErrLog)) {
                            News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", forkLiftSlave.getId(), errName);
                            News.error("提升机plc异常记录失败 ===>> [id:{}] [error:{}]", device.getDeviceNo(), errName);
                        }
                    }
                } else {
@@ -1106,7 +1133,7 @@
                        latest.setUpdateTime(now);
                        latest.setStatus(2);
                        if (!basLiftErrLogService.updateById(latest)) {
                            News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", forkLiftSlave.getId(), latest.getId());
                            News.error("提升机plc异常记录修复失败 ===>> [id:{}] [errLogId:{}]", device.getDeviceNo(), latest.getId());
                        }
                    }
                }
@@ -1125,9 +1152,11 @@
                return;//无充电桩
            }
            for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
            List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Shuttle)));
            for (DeviceConfig device : shuttleList) {
                //获取四向穿梭车线程
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, shuttle.getId());
                ShuttleThread shuttleThread = (ShuttleThread) SlaveConnection.get(SlaveType.Shuttle, device.getDeviceNo());
                ShuttleProtocol shuttleProtocol = shuttleThread.getStatus();
                if (shuttleProtocol == null) {
                    continue;
@@ -1200,15 +1229,15 @@
                wrkMast.setIoType(WrkIoType.SHUTTLE_CHARGE.id);//300.充电
                wrkMast.setIoPri((double) 999);
                wrkMast.setLocNo(chargeLocNo);
                wrkMast.setShuttleNo(shuttle.getId());
                wrkMast.setShuttleNo(device.getDeviceNo());
                wrkMast.setMemo("charge");
                wrkMast.setAppeTime(new Date());
                if (!wrkMastService.insert(wrkMast)) {
                    News.error("保存{}号四向穿梭车充电任务失败!!!", shuttle.getId());
                    News.error("保存{}号四向穿梭车充电任务失败!!!", device.getDeviceNo());
                    continue;
                }
                News.info("保存{}号四向穿梭车充电任务成功!!!", shuttle.getId());
                News.info("保存{}号四向穿梭车充电任务成功!!!", device.getDeviceNo());
            }
        } catch (Exception e) {
            e.printStackTrace();
@@ -1221,8 +1250,10 @@
    public synchronized void executeShuttleCharge() {
        try {
            //查询小车充电任务
            for (ShuttleSlave shuttle : slaveProperties.getShuttle()) {
                WrkMast wrkMast = wrkMastService.selectChargeWorking(shuttle.getId());
            List<DeviceConfig> shuttleList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                    .eq("device_type", String.valueOf(SlaveType.Shuttle)));
            for (DeviceConfig device : shuttleList) {
                WrkMast wrkMast = wrkMastService.selectChargeWorking(device.getDeviceNo());
                if(wrkMast == null) {
                    continue;
                }
@@ -1343,7 +1374,7 @@
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id);//出库模式
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE_ON.id);//充电开
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, true);
@@ -1384,7 +1415,7 @@
            ShuttleAssignCommand assignCommand = new ShuttleAssignCommand();
            assignCommand.setShuttleNo(shuttleProtocol.getShuttleNo());//四向穿梭车号
            assignCommand.setTaskNo(wrkMast.getWrkNo());//任务号
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE.id);//出库模式
            assignCommand.setTaskMode(ShuttleTaskModeType.CHARGE_OFF.id);//充电关
            assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
            List<ShuttleCommand> commands = shuttleOperaUtils.getShuttleChargeCommand(assignCommand, shuttleThread, false);
@@ -1561,6 +1592,15 @@
                return false;
            }
            //小车已在近点位置无需前往
            if (shuttleProtocol.getCurrentLocNo().equals(endLocation)) {
                wrkMast.setWrkSts(WrkStsType.MOVE_NEARBY_COMPLETE.sts);//小车移动到提升机中  301.生成小车移库任务 ==> 303.小车移动至近点完成
                wrkMast.setModiTime(now);
                wrkMast.setSystemMsg("");//清空消息
                wrkMastService.updateById(wrkMast);
                return true;
            }
            //获取小车到近点行走命令
            List<ShuttleCommand> commands = shuttleOperaUtils.getStartToTargetCommands(shuttleProtocol.getCurrentLocNo(), endLocation, NavigationMapType.NORMAL.id, assignCommand, shuttleThread);
            if (commands == null) {
@@ -1642,6 +1682,22 @@
            if (liftStaTarget.getHasCar()) {
                News.taskInfo(wrkMast.getWrkNo(), "{}任务,目标站存在小车", wrkMast.getWrkNo());
                return false;
            }
            List<WrkMast> outWrkMastList = wrkMastService.selectList(new EntityWrapper<WrkMast>()
                    .eq("io_type", 101)
                    .in("wrk_sts"
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN.sts
                            , WrkStsType.OUTBOUND_SHUTTLE_RUN_COMPLETE.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN.sts
                            , WrkStsType.OUTBOUND_LIFT_RUN_COMPLETE.sts
                    )
            );
            for (WrkMast outWrkMast : outWrkMastList) {
                if(Utils.getLev(outWrkMast.getSourceLocNo()) == Utils.getLev(wrkMast.getLocNo())) {
                    News.taskInfo(wrkMast.getWrkNo(), "{}任务,存在正在执行的小车出库任务,禁止移动至站点", wrkMast.getWrkNo());
                    return false;
                }
            }
            if (wrkMast.getLiftNo() == null) {
@@ -1867,8 +1923,10 @@
    //自动切换出入库模式
    public void autoSwitchForkLiftIOMode() {
        for (ForkLiftSlave forkLiftSlave : slaveProperties.getForkLift()) {
            Integer liftNo = forkLiftSlave.getId();
        List<DeviceConfig> forkliftList = deviceConfigService.selectList(new EntityWrapper<DeviceConfig>()
                .eq("device_type", String.valueOf(SlaveType.ForkLift)));
        for (DeviceConfig device : forkliftList) {
            Integer liftNo = device.getDeviceNo();
            ForkLiftThread forkLiftThread = (ForkLiftThread) SlaveConnection.get(SlaveType.ForkLift, liftNo);
            if (forkLiftThread == null) {
                continue;