#
Junjie
2023-10-01 7c5a2e3430f3c0f9e6c4ba9dcdb025e59c1953cb
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -238,14 +238,14 @@
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                            // plc 处理
                            barcodeThread.setBarcode("");
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
                            }
//                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
//                            staProtocol.setStaNo(dto.getStaNo().shortValue());
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
//
//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                            if (!result) {
//                                throw new CoolException("更新plc站点信息失败");
//                            }
                            // 判断重复工作档
                            WrkMast wrkMast = wrkMastMapper.selectPakInStep11(inSta.getStaNo());
@@ -267,10 +267,10 @@
                            }
                            News.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        } else if (code == 700) {
                            staProtocol.setWorkNo((short) 32002);
                            staProtocol.setRollback102(1);//102站回退信号
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
//                            staProtocol.setWorkNo((short) 32002);
//                            staProtocol.setRollback102(1);//102站回退信号
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
//                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
                            // led 异常显示
                            if (ledThread != null) {
@@ -873,7 +873,7 @@
                return false;//找不到站点
            }
            if (liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray()) {
            if (!(liftStaProtocol.getModel() && !liftStaProtocol.getBusy() && !liftStaProtocol.getHasTray())) {
                return false;//站点必须自动、空闲、没有托盘
            }
@@ -1196,6 +1196,17 @@
        //23.小车搬运完成 ==> 24.提升机搬运中
        if (wrkMast.getWrkSts() == 23) {
            NyShuttleThread shuttleThread = (NyShuttleThread) SlaveConnection.get(SlaveType.Shuttle, wrkMast.getShuttleNo());
            if (shuttleThread == null) {
                return false;
            }
            //调度小车避让
            boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
            if (!result) {
                return false;
            }
            //获取出库站点(目标站)
            BasDevp basDevp = basDevpService.selectById(wrkMast.getStaNo());
            if (basDevp == null) {
@@ -1286,7 +1297,6 @@
                    && liftProtocol.getTaskNo() != 0
                    && !liftProtocol.getBusy()
            ) {
                boolean clearTaskNoFlag = false;//清零工作号标记
                //将任务档标记为完成
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo324104(liftProtocol.getTaskNo().intValue());
                if (wrkMast != null) {
@@ -1294,7 +1304,7 @@
                        case 3://3.提升机搬运中 ==> 4.提升机搬运完成
                            wrkMast.setWrkSts(4L);
                            wrkMast.setLiftNo(null);//释放提升机
                            if (liftProtocol.getToken() == wrkMast.getWrkNo()) {
                            if (liftProtocol.getToken().equals(wrkMast.getWrkNo())) {
                                //释放提升机令牌
                                liftProtocol.setToken(0);
                            }
@@ -1308,20 +1318,20 @@
                                //释放提升机令牌
                                liftProtocol.setToken(0);
                            }
                            if (wrkMast.getMk() == null || !wrkMast.getMk().equals("Y")) {
                                //不需要用到机械臂,直接转29.出库完成
                                wrkMast.setWrkSts(29L);
                            }
                            break;
                        case 106://106.提升机搬运中 ==> 107.提升机搬运完成
                            wrkMast.setWrkSts(107L);
//                            //清零工作号
//                            clearTaskNoFlag = true;
                            break;
                        default:
                    }
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        if (clearTaskNoFlag) {
                            //清零工作号
                            MessageQueue.offer(SlaveType.Lift, liftSlave.getId(), new Task(4, null));
                        }
                        //设置提升机为空闲状态
                        liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
                        //任务指令清零
@@ -1330,8 +1340,19 @@
                    } else {
                        News.error("提升机已确认且任务完成状态,复位失败,但未找到工作档。提升机号={},工作号={}", liftProtocol.getLiftNo(), liftProtocol.getTaskNo());
                    }
                }else {
                    LiftAssignCommand assignCommand = liftProtocol.getAssignCommand();
                    if (assignCommand != null) {
                        if (!assignCommand.getAuto()) {
                            //手动操作
                            //设置提升机为空闲状态
                            liftProtocol.setProtocolStatus(LiftProtocolStatusType.IDLE);
                            //任务指令清零
                            liftProtocol.setAssignCommand(null);
                            News.info("提升机已确认手动操作。提升机号={}", liftProtocol.getLiftNo());
                        }
                    }
                }
            }
        }
    }
@@ -1911,15 +1932,15 @@
                        Integer code = jsonObject.getInteger("code");
                        if (code.equals(200)) {
                            StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                            // 更新站点信息 且 下发plc命令
                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
                            staProtocol.setStaNo(dto.getStaNo().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
                            }
                            barcodeThread.setBarcode("");
//                            // 更新站点信息 且 下发plc命令
//                            staProtocol.setWorkNo(dto.getWorkNo().shortValue());
//                            staProtocol.setStaNo(dto.getStaNo().shortValue());
//                            devpThread.setPakMk(staProtocol.getSiteId(), false);
//                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                            if (!result) {
//                                throw new CoolException("更新plc站点信息失败");
//                            }
                        } else {
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
@@ -1937,6 +1958,97 @@
                }
            }
        }
    }
    /**
     * AGV补货 => 机械臂拣料
     */
    public void agvRestockByRobot() {
        //检测300站是否自动、有物、工作号
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 获取入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            StaProtocol staProtocol = devpThread.getStation().get(300);
            if (staProtocol == null) {
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() != 0) {
                //查询是否有工作档
                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol.getWorkNo().intValue());
                if (wrkMast == null) {
                    continue;
                }
                if (wrkMast.getWrkSts() != 25) {//25.提升机搬运完成
                    continue;
                }
                if (wrkMast.getMk() != null && wrkMast.getMk().equals("Y")) {//标记为Y表示需要用到机械臂拣料
                    Short targetSta = null;//目标站
                    //判断机械臂拣料站是否空闲
                    StaProtocol staProtocol303 = devpThread.getStation().get(303);
                    StaProtocol staProtocol317 = devpThread.getStation().get(317);
                    if (staProtocol303.isAutoing() && !staProtocol303.isLoading()) {
                        //自动、无物
                        targetSta = (short) 303;
                    } else if (staProtocol317.isAutoing() && !staProtocol317.isLoading()) {
                        //自动、无物
                        targetSta = (short) 317;
                    }else {
                        continue;//没有空闲站点
                    }
                    targetSta = (short) 317;
                    if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
                        //覆盖工作档目标站
                        wrkMast.setStaNo(targetSta.intValue());
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            //向300站写入目标站
                            staProtocol = staProtocol.clone();
                            staProtocol.setStaNo(targetSta);//移动到目标站
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            try {
                                Thread.sleep(500);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                            continue;
                        }
                    }
                }
            }
            StaProtocol staProtocol303 = devpThread.getStation().get(303);
            StaProtocol staProtocol317 = devpThread.getStation().get(317);
            if (staProtocol303.isAutoing() && staProtocol303.isLoading() && staProtocol303.getWorkNo() != 0) {
                //调度机械臂
//                //查询是否有工作档
//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol303.getWorkNo().intValue());
//                if (wrkMast == null) {
//                    continue;
//                }
//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
//                if (wrkDetl == null) {
//                    continue;
//                }
//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "303");
                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "303");
            }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
                //调度机械臂
//                //查询是否有工作档
//                WrkMast wrkMast = wrkMastMapper.selectByWorkNo(staProtocol317.getWorkNo().intValue());
//                if (wrkMast == null) {
//                    continue;
//                }
//                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
//                if (wrkDetl == null) {
//                    continue;
//                }
//                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "317");
                RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), -1, "317");
            }
        }
    }
@@ -2236,7 +2348,8 @@
                }
            } else if (wrkCharge.getWrkSts() == 52) {
                //检测小车是否满电
                if (shuttleProtocol.getPowerPercent() < 100) {
                int maxPower = 95;
                if (shuttleProtocol.getPowerPercent() < maxPower) {
                    continue;
                }
@@ -2252,21 +2365,34 @@
                assignCommand.setSourceLocNo(shuttleProtocol.getCurrentLocNo());//源库位(小车当前位置)
                assignCommand.setCommands(commands);//运行命令
                //下发任务
                MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                try {
                    Thread.sleep(3000);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                wrkCharge.setWrkSts(53L);//52.小车去充电中 => 53.小车充电完成
                wrkCharge.setModiTime(new Date());
                if (wrkChargeMapper.updateById(wrkCharge) > 0) {
                    //下发任务
                    MessageQueue.offer(SlaveType.Shuttle, assignCommand.getShuttleNo().intValue(), new Task(3, assignCommand));
                    shuttleProtocol.setProtocolStatus(ShuttleProtocolStatusType.IDLE.id);
                    shuttleProtocol.setTaskNo(0);
                    shuttleProtocol.setPakMk(false);
                }
            } else if (wrkCharge.getWrkSts() == 53) {
                boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkCharge.getLocNo()), shuttleThread.getSlave().getId(), shuttleThread);
                if (!result) {
                    continue;
                }
                if (shuttleProtocol.getChargState() == 0) {//小车处于未充电状态
                    boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkCharge.getLocNo()), shuttleThread.getSlave().getId(), shuttleThread);
                    if (!result) {
                        continue;
                    }
                wrkCharge.setWrkSts(60L);//53.小车充电完成 => 60.充电任务完成
                wrkCharge.setModiTime(new Date());
                wrkChargeMapper.updateById(wrkCharge);
                    wrkCharge.setWrkSts(60L);//53.小车充电完成 => 60.充电任务完成
                    wrkCharge.setModiTime(new Date());
                    if (wrkChargeMapper.updateById(wrkCharge) > 0) {
                    }
                }
            }
        }
@@ -2489,6 +2615,7 @@
                assignCommand.setLiftNo(liftProtocol.getLiftNo());
                assignCommand.setTaskNo(wrkMast.getWrkNo().shortValue());
                assignCommand.setTaskMode(NyLiftTaskModelType.MOVE_CAR.id.shortValue());
                assignCommand.setAuto(false);
                wrkMast.setLiftNo(liftThread.getSlave().getId());//锁定提升机防止被占用
                wrkMast.setModiTime(now);