pang.jiabao
2024-10-26 bbf283177eee80b573b583f2e29e62531eaf7f0a
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -96,7 +96,7 @@
     * 组托
     * 入库站,根据条码扫描生成入库工作档,工作状态 2
     */
    public synchronized void generateStoreWrkFile(Integer mark) {
    public synchronized void generateStoreWrkFile(Integer mark) throws InterruptedException {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) { //遍历输送线
            // 遍历入库口
@@ -125,10 +125,7 @@
                  是2号输送线9995拣料任务
                 */
                String barcode = barcodeThread.getBarcode();
                if (Cools.isEmpty(barcode) || !staProtocol.isInEnable() || staProtocol.isEmptyMk()
                || !staProtocol.isFullPlt() || (staProtocol.getWorkNo() == 9995 && devp.getId() == 2)) {
                    continue;
                }
                // 尺寸检测异常
                boolean back = false;
@@ -162,16 +159,16 @@
                    back = true;
                }
                if (!back && devp.getId() == 2) {
                    if(staProtocol.getWorkNo() == 9907 && '5' != barcode.charAt(0)){
                        errMsg = "条码5只能入7排";
                        back = true;
                    }
                    if(staProtocol.getWorkNo() == 9906 && '5' == barcode.charAt(0)){
                        errMsg = "条码5不能入6排";
                        back = true;
                    }
                }
//                if (!back && devp.getId() == 2) {
//                    if(staProtocol.getWorkNo() == 9907 && '5' != barcode.charAt(0)){
//                        errMsg = "条码5只能入7排";
//                        back = true;
//                    }
//                    if(staProtocol.getWorkNo() == 9906 && '5' == barcode.charAt(0)){
//                        errMsg = "条码5不能入6排";
//                        back = true;
//                    }
//                }
                // 退回
                if (back && devp.getId() == 2) {
@@ -192,6 +189,12 @@
                    devpThread.setPakMk(staProtocol.getSiteId(), false);
                    MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                    MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errMsg));
                    Thread.sleep(500);
                }
                if (Cools.isEmpty(barcode) || !staProtocol.isInEnable() || staProtocol.isEmptyMk()
                        || !staProtocol.isFullPlt() || (staProtocol.getWorkNo() <= 9000 && devp.getId() == 2)) {
                    continue;
                }
                if (staProtocol.isAutoing() && staProtocol.isInEnable()
@@ -202,24 +205,28 @@
                    //过滤判断,防止拣料再入库货物,经过入库站再入库时,被退回到退库站
                    WrkMast wrkMast1 = wrkMastMapper.selectPakInStepBarcode(barcode);
                    if (wrkMast1 !=null){
                        if (wrkMast1.getIoType()==103 || wrkMast1.getIoType()==107 || wrkMast1.getIoType()==104){
                        if (wrkMast1.getIoType()==103 || wrkMast1.getIoType() == 53 || wrkMast1.getIoType()==107 || wrkMast1.getIoType()== 57 || wrkMast1.getIoType()==104){
                            continue;
                        }
                    }
                    if (wrkMast != null && devp.getId() == 2) {
                        News.warn(""+mark+" - 4"+" - 工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
                        staProtocol.setWorkNo((short)9999);
                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
                        devpThread.setPakMk(staProtocol.getSiteId(), false);
                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        if (!result) {
                            throw new CoolException("更新plc站点信息失败");
                    if (wrkMast != null) {
                        News.warn(""+mark+" - 4"+" - 满托盘入库工作档中已存在该站状态为( 2.设备上走 )的数据,工作号={}", wrkMast.getWrkNo());
                        if (devp.getId() == 2) {
//                            staProtocol.setWorkNo((short)9999);
//                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
                            staProtocol.setWorkNo(wrkMast.getWrkNo().shortValue());
                            staProtocol.setStaNo(wrkMast.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站点信息失败");
                            }
                        }
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "工作档已存在该条码号===>>" + barcode;
                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
//                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
@@ -262,12 +269,26 @@
                                ledCommand.setTitle("全板入库");
                                ledCommand.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                ArrayList<MatDto> matDtos = new ArrayList<>();
                                MatDto matDto = new MatDto();
                                matDto.setLocNo(dto.getLocNo());
                                matDtos.add(matDto);
                                ledCommand.setMatDtos(matDtos);
                                ledCommand.setBarcode(barcode);
                                commands.add(ledCommand);
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, commands));
                                if (devp.getId() == 1) {
//                                     if (MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(1, commands))){
//                                         ledThread.setLedMk(false);
//                                     }
                                } else {
                                    if (MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, commands))){
                                        ledThread.setLedMk(false);
                                    }
                                }
//                                ledThread.errorReset();
                            }
                        } else {
                            News.error(""+mark+" - 5"+" - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            News.error(""+mark+" - 5"+" - 满板入库请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            if(devp.getId() == 2) {
                                staProtocol.setWorkNo((short)9999);
                                staProtocol.setStaNo(inSta.getBackSta().shortValue());
@@ -444,14 +465,17 @@
                            .eq("stn_no", stnNo) // 作业站点 = 拣料出库的目标站
                            .eq("crn_no", wrkMast.getCrnNo()); // 堆垛机号
                    StaDesc staDesc = staDescService.selectOne(wrapper);
                    //LED
                    LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
                    if (Cools.isEmpty(staDesc)) {
                        News.error(""+mark+" - 2"+" - 入库路径不存在!type_no={},stn_no={},crn_no={}", wrkMast.getIoType(), pickSta.getStaNo(), wrkMast.getCrnNo());
                        staProtocol.setWorkNo((short) 9999);
                        staProtocol.setStaNo(pickSta.getBackSta().shortValue());
                        devpThread.setPakMk(staProtocol.getSiteId(), false);
                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        //LED
                        LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, pickSta.getLed());
                        if (devp.getId() == 2) {
                            staProtocol.setWorkNo((short) 9999);
                            staProtocol.setStaNo(pickSta.getBackSta().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        }
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "此为拣料、并板、盘点再入库.请放在"+pickSta.getBackSta().shortValue()+"站点";
@@ -498,6 +522,29 @@
                        e.printStackTrace();
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                        continue;
                    }
                    List<LedCommand> commands = new ArrayList<>();
                    LedCommand ledCommand = new LedCommand();
                    ledCommand.setWorkNo(wrkMast.getWrkNo());
                    ledCommand.setIoType(wrkMast.getIoType());
                    ledCommand.setTitle(wrkMast.getIoType() == 53 ? "拣料再入库" : "盘点再入库");
                    ledCommand.setLocNo(wrkMast.getLocNo());
                    ledCommand.setStaNo(wrkMast.getStaNo());
                    ledCommand.setBarcode(barcode);
                    ArrayList<MatDto> matDtos = new ArrayList<>();
                    MatDto matDto = new MatDto();
                    matDto.setLocNo(wrkMast.getLocNo());
                    matDtos.add(matDto);
                    ledCommand.setMatDtos(matDtos);
                    commands.add(ledCommand);
                    if (devp.getId() == 1) {
//                        if (MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(1, commands))) {
//                            ledThread.setLedMk(false);
//                        }
                    } else {
                        if (MessageQueue.offer(SlaveType.Led, pickSta.getLed(), new Task(3, commands))){
                            ledThread.setLedMk(false);
                        }
                    }
                    // 更新站点信息 且 下发plc命令
@@ -1511,7 +1558,13 @@
                        && staProtocol.isLoading()
                ) {
                    News.warnNoLog(""+mark+" - 0"+" - 开始执行:空栈板初始化入库,叉车入库站放货");
                    // 判断上一个空托入库写入后,线程还读取到,造成重复请求
                    List<WrkMast> wrkMastList = wrkMastMapper.selectList(new EntityWrapper<WrkMast>().eq("wrk_sts",2)
                            .eq("io_type",10).eq("source_sta_no",emptyInSta.getStaNo()));
                    if(!wrkMastList.isEmpty()) {
                        log.warn("查询到一个在设备上走任务:{}",wrkMastList.get(0).getWrkNo());
                        continue;
                    }
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -1538,24 +1591,34 @@
                                News.errorNoLog(""+mark+" - 1"+" - 更新plc站点信息失败");
                                throw new CoolException("更新plc站点信息失败");
                            }
                            if (ledThread != null) {
                                // 命令集合
                                List<LedCommand> commands = new ArrayList<>();
                                // 组装命令
                                LedCommand ledCommand = new LedCommand();
                                ledCommand.setWorkNo(dto.getWorkNo());
                                ledCommand.setIoType(1);
                                ledCommand.setTitle("全板入库");
                                ledCommand.setIoType(10);
                                ledCommand.setTitle("空板入库");
                                ledCommand.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                ledCommand.setBarcode("");
                                ArrayList<MatDto> matDtos = new ArrayList<>();
                                MatDto matDto = new MatDto();
                                matDto.setLocNo(dto.getLocNo());
                                matDtos.add(matDto);
                                ledCommand.setMatDtos(matDtos);
                                commands.add(ledCommand);
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, commands));
                                if (devp.getId() == 1) {
//                                    MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(1, commands));
                                } else {
                                    MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, commands));
                                }
//                                ledThread.errorReset();
                            }
                            Thread.sleep(1000);
                        } else {
                            staProtocol.setWorkNo((short)9991);
                            staProtocol.setStaNo((short)100);
                            staProtocol.setStaNo(emptyInSta.getBackSta().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            if (!result) {
@@ -1569,7 +1632,7 @@
                                    MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                                }
                            }
                            News.error(""+mark+" - 3"+" - 请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            News.error(""+mark+" - 3"+" - 空板入库请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
@@ -1599,6 +1662,9 @@
            // 工作档集合
            List<WrkMast> wrkMasts = new ArrayList<>();
            for (Integer staNo : led.getStaArr()) {
                if (staNo == 104 || staNo == 204 || staNo == 304) {
                    continue;
                }
                // 获取叉车站点
                StaProtocol staProtocol = devpThread.getStation().get(staNo);
                if (null == staProtocol || null == staProtocol.getWorkNo() || 0 == staProtocol.getWorkNo() || !staProtocol.isLoading()) {
@@ -1673,7 +1739,7 @@
                    } else {
                        ledThread.setLedMk(false);
                    }
                } else {
                } else if(led.getId() == 1 || led.getId() == 2){
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(1, commands))) {
                        News.error(""+mark+" - 3"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                        continue;
@@ -1744,11 +1810,20 @@
            // led显示默认内容
            if (reset && !ledThread.isLedMk()) {
                ledThread.setLedMk(true);
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                    News.error(""+mark+" - 1"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                } else {
                if (led.getId() <=2 ) {
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                        News.error(""+mark+" - 1"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
                } else {
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                        News.error(""+mark+" - 1"+" - {}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
                }
            }
        }
        News.infoNoLog(""+mark+" - 0"+" - 执行完成:其他  ===>> LED显示器复位,显示默认信息");
@@ -2324,4 +2399,16 @@
        }
    }
    public void resetOneLed() {
        // 根据输送线plc遍历
        for (DevpSlave devp : slaveProperties.getDevp()) { //遍历输送线
            if (devp.getId() == 1) {
                // 遍历入库口
                for (DevpSlave.Sta inSta : devp.getInSta()) {  // 遍历入库口
                    SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                    StaProtocol staProtocol = devpThread.getStation().get(inSta.getStaNo());
                }
            }
        }
    }
}