#
Junjie
2023-10-13 03e68b2be24ea024eae645c47da1d4cb1773302a
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -1190,16 +1190,27 @@
                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) {
                return false;//出库站点不存在
            }
            //获取源站对应的牛眼提升机站点编号(起点编号)
            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(basDevp.getLiftNo(), Utils.getLev(wrkMast.getSourceLocNo()));
            if (liftStaProtocol == null) {
                return false;//找不到站点
            }
            Integer startSta = liftStaProtocol.getStaNo();
            NyShuttleProtocol shuttleProtocol = shuttleThread.getShuttleProtocol();
            if (shuttleProtocol.getCurrentLocNo().equals(liftStaProtocol.getLocNo())) {
                //小车还在输送站点
                //调度小车避让
                boolean result = Utils.searchEmptyGroupToMoveShuttle(Utils.getLev(wrkMast.getSourceLocNo()), wrkMast.getShuttleNo(), shuttleThread);
                if (!result) {
                    return false;
                }
            }
            if (!basDevp.getOutEnable().equals("Y")) {
@@ -1214,6 +1225,7 @@
            if (liftProtocol == null) {
                return false;
            }
            if (!liftProtocol.isIdle()) {
                return false;
            }
@@ -1226,13 +1238,6 @@
            if (liftWrkMast != null) {
                return false;//当前提升机存在未完成任务,等待下一次轮询
            }
            //获取源站对应的牛眼提升机站点编号(起点编号)
            LiftStaProtocol liftStaProtocol = NyLiftUtils.getLiftStaByLev(liftThread.getSlave().getId(), Utils.getLev(wrkMast.getSourceLocNo()));
            if (liftStaProtocol == null) {
                return false;//找不到站点
            }
            Integer startSta = liftStaProtocol.getStaNo();
            //获目标站源站对应的输送站点
            BasDevp targetBasDevp = basDevpService.selectById(wrkMast.getStaNo());
@@ -1999,8 +2004,43 @@
                    targetSta = (short) 317;
                    if (wrkMast.getStaNo() != 303 && wrkMast.getStaNo() != 317) {
                        //向AGV发起组托请求
//                        try {
//                            HashMap<String, Object> param = new HashMap<>();
//                            param.put("wrkNo", wrkMast.getWrkNo());
//                            String response = new HttpHandler.Builder()
//                                    .setUri(wmsUrl)
//                                    .setPath("/openAGV")
//                                    .setJson(JSON.toJSONString(param))
//                                    .build()
//                                    .doPost();
//                            JSONObject jsonObject = JSON.parseObject(response);
//                            Integer code = jsonObject.getInteger("code");
//                            if (code.equals(200)) {//AGV组托成功
//                                //覆盖工作档目标站
//                                wrkMast.setStaNo(targetSta.intValue());
//                                wrkMast.setShuttleNo(null);//释放小车
//                                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;
//                                }
//                            }
//                        } catch (Exception e) {
//                            e.printStackTrace();
//                            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                        }
                        //覆盖工作档目标站
                        wrkMast.setStaNo(targetSta.intValue());
                        wrkMast.setShuttleNo(null);//释放小车
                        if (wrkMastMapper.updateById(wrkMast) > 0) {
                            //向300站写入目标站
                            staProtocol = staProtocol.clone();
@@ -2026,15 +2066,15 @@
                if (wrkMast == null) {
                    continue;
                }
                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
                if (wrkDetl == null) {
                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                if (wrkDetls.isEmpty()) {
                    continue;
                }
                if (wrkMast.getInvWh() == null) {
                    wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "303");
                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetls.size(), "303");
                    }
                }
            }else if (staProtocol317.isAutoing() && staProtocol317.isLoading() && staProtocol317.getWorkNo() != 0) {
@@ -2044,18 +2084,82 @@
                if (wrkMast == null) {
                    continue;
                }
                WrkDetl wrkDetl = wrkDetlService.selectById(wrkMast.getWrkNo());
                if (wrkDetl == null) {
                List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                if (wrkDetls.isEmpty()) {
                    continue;
                }
                if (wrkMast.getInvWh() == null) {
                    wrkMast.setInvWh("Y");//标记已经下发机械臂任务
                    if (wrkMastMapper.updateById(wrkMast) > 0) {
                        RobotUtils.sendTask(staProtocol303.getWorkNo().toString(), wrkDetl.getAnfme().intValue(), "317");
                        RobotUtils.sendTask(staProtocol317.getWorkNo().toString(), wrkDetls.size(), "317");
                    }
                }
            }
        }
    }
    /**
     * AGV补货(通知AGV取货)
     */
    public void agvRestockInto() {
        //检测309和312站是否自动、有物
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 获取入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
            StaProtocol staProtocol309 = devpThread.getStation().get(309);
            StaProtocol staProtocol312 = devpThread.getStation().get(312);
            if (staProtocol309 == null || staProtocol312 == null) {
                continue;
            }
            if (staProtocol309.isAutoing() && staProtocol309.isLoading()) {
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 11);//308站条码器
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                if(!Cools.isEmpty(barcode)) {
                    //通知AGV取货
                    agvRestockCall("CS-301-001-01@3", barcode);
                }
            } else if (staProtocol312.isAutoing() && staProtocol312.isLoading()) {
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, 12);//311站条码器
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                if(!Cools.isEmpty(barcode)) {
                    //通知AGV取货
                    agvRestockCall("CS-302-001-01@3", barcode);
                }
            }
        }
    }
    //通知AGV取货
    private boolean agvRestockCall(String staNo, String barcode) {
        try {
            HashMap<String, Object> param = new HashMap<>();
            param.put("staNo", staNo);
            param.put("barcode", barcode);
            String response = new HttpHandler.Builder()
                    .setUri(wmsUrl)
                    .setPath("/callAGV")
                    .setJson(JSON.toJSONString(param))
                    .build()
                    .doPost();
            JSONObject jsonObject = JSON.parseObject(response);
            Integer code = jsonObject.getInteger("code");
            if (code.equals(200)) {//呼叫AGV
                return true;
            }
        } catch (Exception e) {
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return false;
    }
    // 300站拣料
@@ -2986,6 +3090,9 @@
                wrkMast.setModiTime(now);
                wrkMastMapper.updateById(wrkMast);
                shuttleProtocol.setShuttleNo((short) 0);//释放小车
                shuttleProtocol.setToken(0);//释放小车
                if (wrkMast.getWrkSts() == 111) {
                    // 保存工作主档历史档
                    if (wrkMastLocMapper.save(wrkMast.getWrkNo()) <= 0) {