自动化立体仓库 - WCS系统
#
LSH
2023-01-29 8041b12390fac65e6c60f1d7613a0639397b78b8
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -104,15 +104,6 @@
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                if (!Cools.isEmpty(barcode)) {
                    log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                    if ("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                        continue;
                    }
                } else {
                    continue;
                }
                // 获取入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
@@ -123,46 +114,84 @@
                    staProtocol = staProtocol.clone();
                }
                //LED
                LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, inSta.getLed());
                // 入出库模式判断
//                if ( inSta.getStaNo()==203 && devpThread.ioModeOf2F != IoModeType.PAKIN_MODE) { continue; }
                if (inSta.getStaNo() == 203 && devpThread.ioModeOf2F == IoModeType.PAKOUT_MODE) {
                    continue;
                }
//                if (inSta.getStaNo() == 203 && devpThread.ioModeOf2F == IoModeType.PAKOUT_MODE) {
//                    continue;
//                }
                // 判断是否满足入库条件
                if (staProtocol.isAutoing() && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && !staProtocol.isEmptyMk() && (staProtocol.getWorkNo() == 0 || staProtocol.getWorkNo() > 9990)
                        && staProtocol.isPakMk()) {// && !Cools.isEmpty(barcode)) {
                        && staProtocol.isPakMk() && staProtocol.getStamp()>=2) {// && !Cools.isEmpty(barcode)) {
//                    if(Cools.isEmpty(barcode) || "NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                        log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
//                        //条码为空或者不符合,退库到172站点
//                        staProtocol.setWorkNo((short)9999);
//                        staProtocol.setStaNo((short)172);
//                        devpThread.setPakMk(staProtocol.getSiteId(), false);
//                        boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
//                        if (!result) {
//                            throw new CoolException("更新plc站点信息失败");
//                        }
//                        continue;
//                    }
//                    try {
//                        Thread.sleep(300);
//                    }catch (Exception e){}
                    String barcode = barcodeThread.getBarcode();
                    if(!Cools.isEmpty(barcode)) {
                        log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                        if("NG".endsWith(barcode) || "NoRead".equals(barcode) || "empty".equals(barcode)) {
                            staProtocol.setWorkNo((short) 9999);
                            staProtocol.setStaNo(inSta.getBackSta().shortValue());
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            log.info("扫码失败1 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = "扫码失败,请重试";
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
                            }
                            continue;
                        }
                    } else {
                        staProtocol.setWorkNo((short) 9999);
                        staProtocol.setStaNo(inSta.getBackSta().shortValue());
                        devpThread.setPakMk(staProtocol.getSiteId(), false);
                        MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                        log.info("扫码失败2 ===>> {}号条码扫描器检测条码信息:{},站点:{}", inSta.getBarcode(), barcode, inSta.getStaNo());
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "扫码失败,请重试";
                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
                    // 判断重复工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep1(inSta.getStaNo(), barcode);
                    //过滤判断,防止拣料再入库货物,经过入库站再入库时,被退回到退库站
                    WrkMast wrkMast1 = wrkMastMapper.selectPakInStepBarcode(barcode);
                    if (wrkMast1 !=null){
                        if (wrkMast1.getIoType()==103 || wrkMast1.getIoType()==107 || wrkMast1.getIoType()==104){
                            continue;
                        }
                    }
                    if (wrkMast != null) {
                        log.error("工作档中已存在该站状态为( 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站点信息失败");
                        }
                        // led 异常显示
                        if (ledThread != null) {
                            String errorMsg = "工作档已存在该条码号===>>" + barcode;
                            MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
                        }
                        continue;
                    }
//                    // 获取入库通知档
//                    List<WaitPakin> waitPakins = waitPakinMapper.selectList(new EntityWrapper<WaitPakin>().eq("zpallet", barcode).eq("io_status", "N"));
//                    if (waitPakins.isEmpty()) {
//                        log.error("无此入库条码数据。条码号={}", barcode);
//                        continue;
//                    }
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                        SearchLocParam param = new SearchLocParam();
@@ -188,67 +217,38 @@
                            if (!result) {
                                throw new CoolException("更新plc站点信息失败");
                            }
                            // led 入库信息显示
                            if (ledThread != null) {
                                // 命令集合
                                List<LedCommand> commands = new ArrayList<>();
                                // 组装命令
                                LedCommand ledCommand = new LedCommand();
                                ledCommand.setWorkNo(dto.getWorkNo());
                                ledCommand.setIoType(1);
                                ledCommand.setTitle("全板入库");
                                ledCommand.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                commands.add(ledCommand);
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(3, commands));
//                                ledThread.errorReset();
                            }
                        } else {
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            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站点信息失败");
                            }
                            // led 异常显示
                            if (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                MessageQueue.offer(SlaveType.Led, inSta.getLed(), new Task(5, errorMsg));
                            }
                        }
//                        // 检索库位
//                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
//                        List<String> matNos = waitPakins.stream().map(WaitPakin::getMatnr).distinct().collect(Collectors.toList());
//                        StartupDto startupDto = commonService.getLocNo(1, 1, inSta.getStaNo(), matNos, locTypeDto, 0);
//                        // 工作号
//                        int workNo = startupDto.getWorkNo();
//                        // 插入工作明细档
//                        wrkDetlService.createWorkDetail(workNo, waitPakins, barcode);
//
//                        // 插入工作主档
//                        wrkMast = new WrkMast();
//                        wrkMast.setWrkNo(workNo);
//                        wrkMast.setIoTime(new Date());
//                        wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
//                        wrkMast.setIoType(1); // 入出库状态:1.入库
//                        wrkMast.setIoPri(10D); // 优先级:10
//                        wrkMast.setCrnNo(startupDto.getCrnNo());
//                        wrkMast.setSourceStaNo(startupDto.getSourceStaNo());
//                        wrkMast.setStaNo(startupDto.getStaNo());
//                        wrkMast.setLocNo(startupDto.getLocNo());
//                        wrkMast.setBarcode(barcode); // 托盘码
//                        wrkMast.setFullPlt("Y"); // 满板:Y
//                        wrkMast.setPicking("N"); // 拣料
//                        wrkMast.setExitMk("N"); // 退出
//                        wrkMast.setEmptyMk("N"); // 空板
//                        wrkMast.setLinkMis("N");
//                        // 操作人员数据
//                        wrkMast.setAppeTime(new Date());
//                        wrkMast.setModiTime(new Date());
//                        Integer insert = wrkMastMapper.insert(wrkMast);
//                        if (insert == 0) {
//                            throw new CoolException("保存工作档失败");
//                        }
//                        // 更新目标库位状态
//                        LocMast locMast = locMastService.selectById(startupDto.getLocNo());
//                        locMast.setLocSts("S"); // S.入库预约
//                        locMast.setModiTime(new Date());
//                        if (!locMastService.updateById(locMast)){
//                            throw new CoolException("改变库位状态失败");
//                        }
//                        // 将入库通知档修改为已启动
//                        if (wrkMastMapper.updateWaitPakInStep1(barcode) == 0) {
//                            throw new CoolException("修改入库通知档状态为已启动失败");
//                        }
//
//                        // 命令下发区 --------------------------------------------------------------------------
//
//                        // 更新站点信息 且 下发plc命令
//                        barcodeThread.setBarcode("");
//                        staProtocol.setWorkNo((short) workNo);
//                        staProtocol.setStaNo(startupDto.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站点信息失败");
//                        }
                    } catch (Exception e) {
                        e.printStackTrace();
@@ -256,7 +256,6 @@
                    }
                }
            }
        }
@@ -329,20 +328,20 @@
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历拣料入库口
            for (DevpSlave.Sta pickSta : devp.getPickSta()) {
//                // 获取条码扫描仪信息
//                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
//                if (barcodeThread == null) {
//                    continue;
//                }
//                String barcode = barcodeThread.getBarcode();
//                if(!Cools.isEmpty(barcode)) {
//                    log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
//                    if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
//                        continue;
//                    }
//                } else {
//                    continue;
//                }
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, pickSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
                if(!Cools.isEmpty(barcode)) {
                    log.info("{}号条码扫描器检测条码信息:{}", pickSta.getBarcode(), barcode);
                    if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
                        continue;
                    }
                } else {
                    continue;
                }
                // 获取拣料入库站信息
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
@@ -357,8 +356,8 @@
//                if (devpThread.ioMode != IoModeType.PAKIN_MODE) { continue; }
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable() && staProtocol.isPakMk()) {
//                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
                    WrkMast wrkMast = wrkMastMapper.selectPickStep(barcode);
//                    WrkMast wrkMast = wrkMastMapper.selectPakInStep3(staProtocol.getWorkNo().intValue());
                    if (wrkMast == null) {
                        // 无拣料数据
                        continue;
@@ -712,7 +711,7 @@
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
            crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
            crnCommand.setAckFinish((short) 0);  // 任务完成确认位
//            crnCommand.setAckFinish((short) 0);  // 任务完成确认位
            crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
            crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
            crnCommand.setSourcePosY(crnStn.getBay().shortValue());     // 源库位列
@@ -860,7 +859,7 @@
                    CrnCommand crnCommand = new CrnCommand();
                    crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
                    crnCommand.setTaskNo(wrkMast.getWrkNo().shortValue()); // 工作号
                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
//                    crnCommand.setAckFinish((short) 0);  // 任务完成确认位
                    crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
                    crnCommand.setSourcePosX(sourceSta.getRow1().shortValue());     // 源库位排
                    crnCommand.setSourcePosY(sourceSta.getBay1().shortValue());     // 源库位列
@@ -1251,9 +1250,18 @@
                    staProtocol = staProtocol.clone();
                }
                LedThread ledThread = null;
                if (!Cools.isEmpty(emptyInSta.getLed()))  {
                    ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, emptyInSta.getLed());
                }
                // 站点条件判断
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk() && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999) && staProtocol.isPakMk()) {
                if (staProtocol.isAutoing()
                        && staProtocol.isLoading()
                        && staProtocol.isInEnable()
                        && staProtocol.isEmptyMk()
                        && (staProtocol.getWorkNo() > 9990 && staProtocol.getWorkNo() <= 9999)
                        && staProtocol.isPakMk()) {
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
@@ -1280,7 +1288,36 @@
                            if (!result) {
                                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.setLocNo(dto.getLocNo());
                                ledCommand.setStaNo(dto.getStaNo());
                                commands.add(ledCommand);
                                MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(3, commands));
//                                ledThread.errorReset();
                            }
                        } else {
                            staProtocol.setWorkNo((short)9999);
                            staProtocol.setStaNo(emptyInSta.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 (ledThread != null) {
                                String errorMsg = jsonObject.getString("msg");
                                if (!Cools.isEmpty(errorMsg)) {
                                    MessageQueue.offer(SlaveType.Led, emptyInSta.getLed(), new Task(5, errorMsg));
                                }
                            }
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
                    } catch (Exception e) {
@@ -1288,62 +1325,7 @@
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
//                    // 检索库位
//                    LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
//                    StartupDto startupDto = commonService.getLocNo(1, 10, emptyInSta.getStaNo(), null, locTypeDto, 0);
//                    // 工作号
//                    int workNo = startupDto.getWorkNo();
//
//                    try {
//                        // 插入工作主档
//                        WrkMast wrkMast = new WrkMast();
//                        wrkMast.setWrkNo(workNo);
//                        wrkMast.setIoTime(new Date());
//                        wrkMast.setWrkSts(2L); // 工作状态:2.设备上走
//                        wrkMast.setIoType(10); // 入出库状态:10.空板入库
//                        wrkMast.setIoPri(10D); // 优先级:10
//                        wrkMast.setCrnNo(startupDto.getCrnNo());
//                        wrkMast.setSourceStaNo(startupDto.getSourceStaNo());
//                        wrkMast.setStaNo(startupDto.getStaNo());
//                        wrkMast.setLocNo(startupDto.getLocNo());
//                        wrkMast.setFullPlt("N"); // 满板
//                        wrkMast.setPicking("N"); // 拣料
//                        wrkMast.setExitMk("N"); // 退出
//                        wrkMast.setEmptyMk("Y"); // 空板
//                        wrkMast.setLinkMis("N");
////                    wrkMast.setCtnType(sourceStaNo.getCtnType()); // 容器类型
//                        // 操作人员数据
//                        wrkMast.setAppeTime(new Date());
//                        wrkMast.setModiTime(new Date());
//                        Integer insert = wrkMastMapper.insert(wrkMast);
//                        if (insert == 0) {
//                            throw new CoolException("保存工作档失败");
//                        }
//                        // 更新目标库位状态
//                        LocMast locMast = locMastService.selectById(startupDto.getLocNo());
//                        locMast.setLocSts("S"); // S.入库预约
//                        locMast.setModiTime(new Date());
//                        if (!locMastService.updateById(locMast)){
//                            throw new CoolException("改变库位状态失败");
//                        }
//                        // 命令下发区 --------------------------------------------------------------------------
//
//                        // 更新站点信息 且 下发plc命令
//                        staProtocol.setWorkNo((short) workNo);
//                        staProtocol.setStaNo(startupDto.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站点信息失败");
//                        }
//                    } catch (Exception e) {
//                        e.printStackTrace();
//                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
//                    }
                }
            }
        }
@@ -1469,33 +1451,6 @@
     * 其他  ===>> LED显示器复位,显示默认信息
     */
    public synchronized void ledReset() {
//        for (LedSlave led : slaveProperties.getLed()) {
//            // 获取输送线plc线程
//            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
//            // 命令集合
//            boolean reset = true;
//            for (Integer staNo : led.getStaArr()) {
//                // 获取叉车站点
//                StaProtocol staProtocol = devpThread.getStation().get(staNo);
//                if (staProtocol == null) {
//                    continue;
//                } else {
//                    staProtocol = staProtocol.clone();
//                }
//                if (staProtocol.getWorkNo() != 0) {
//                    reset = false;
//                    break;
//                }
//            }
//            // 获取led线程
//            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getDevpPlcId());
//            // led显示默认内容
//            if (reset) {
//                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
//                    log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
//                }
//            }
//        }
        for (LedSlave led : slaveProperties.getLed()) {
            // 获取输送线plc线程
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, led.getDevpPlcId());
@@ -1516,20 +1471,11 @@
            LedThread ledThread = (LedThread) SlaveConnection.get(SlaveType.Led, led.getId());
            // led显示默认内容
            if (reset && !ledThread.isLedMk()) {
                if (led.getId() == 7) {
                    ledThread.setLedMk(true);
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
                ledThread.setLedMk(true);
                if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(4, new ArrayList<>()))) {
                    log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                } else {
                    ledThread.setLedMk(true);
                    if (!MessageQueue.offer(SlaveType.Led, led.getId(), new Task(2, new ArrayList<>()))) {
                        log.error("{}号LED命令下发失败!!![ip:{}] [port:{}]", led.getId(), led.getIp(), led.getPort());
                    } else {
                    }
                }
            }
        }