自动化立体仓库 - WCS系统
#
lsh
2022-10-12 f6decf71aa936d019a7732970744c6c33f5e6175
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -103,12 +103,14 @@
        for (DevpSlave devp : slaveProperties.getDevp()) {
            // 遍历入库口
            for (DevpSlave.Sta inSta : devp.getInSta()) {
                inSta.setStaNo(102);
                // 获取条码扫描仪信息
                BarcodeThread barcodeThread = (BarcodeThread) SlaveConnection.get(SlaveType.Barcode, inSta.getBarcode());
                if (barcodeThread == null) {
                    continue;
                }
                String barcode = barcodeThread.getBarcode();
//                barcode="ILY0127 0001";
                if(!Cools.isEmpty(barcode)) {
                    log.info("{}号条码扫描器检测条码信息:{}", inSta.getBarcode(), barcode);
                    if("NG".endsWith(barcode) || "NoRead".equals(barcode)) {
@@ -165,7 +167,7 @@
                    try {
                        LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                        locTypeDto.setLocType1((short)1);
                        SearchLocParam param = new SearchLocParam();
                        param.setBarcode(barcode);
                        param.setIoType(1);
@@ -533,14 +535,16 @@
                continue;
            }
            //堆垛机回原点任务中
            if(crnThread.isBackHpFlag()){
                continue;
            }
//            //堆垛机回原点任务中
//            if(crnThread.isBackHpFlag()){
//                continue;
//            }
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
                    && crnProtocol.getLoaded() == 0 && crnProtocol.getForkPos() == 0) {
                // 库位移转
                this.stnToStn(crn, crnProtocol);
                // 如果最近一次是入库模式
                if (crnProtocol.getLastIo().equals("I")) {
                    if (basCrnp.getInEnable().equals("Y")) {
@@ -1412,7 +1416,7 @@
                ledCommand.setStaNo(wrkMast.getStaNo());
                if (wrkMast.getIoType() != 110) {
                    List<WrkDetl> wrkDetls = wrkDetlService.findByWorkNo(wrkMast.getWrkNo());
                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatNo(), wrkDetl.getMatName(), wrkDetl.getQty())));
                    wrkDetls.forEach(wrkDetl -> ledCommand.getMatDtos().add(new MatDto(wrkDetl.getMatnr(), wrkDetl.getMaktx(), wrkDetl.getAnfme())));
                }
                commands.add(ledCommand);
            }
@@ -1557,7 +1561,7 @@
                WrkDetl wrkDetl = new WrkDetl();
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(now);
                wrkDetl.setQty(locDetl.getQty());
                wrkDetl.setAnfme(locDetl.getAnfme());
                VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
                wrkDetl.setAppeTime(now);
                wrkDetl.setModiTime(now);
@@ -1674,7 +1678,7 @@
                    WrkDetl wrkDetl = new WrkDetl();
                    wrkDetl.setWrkNo(workNo);
                    wrkDetl.setIoTime(new Date());
                    wrkDetl.setQty(locDetl.getQty());
                    wrkDetl.setAnfme(locDetl.getAnfme());
                    VersionUtils.setWrkDetl(wrkDetl, locDetl); // 版本控制
                    wrkDetl.setAppeTime(new Date());
                    wrkDetl.setModiTime(new Date());
@@ -1905,52 +1909,242 @@
    }
    /**
     * 根据PLC按钮测试信号,发送启动申请到测试系统
     * 站到站  ===>>  堆垛机109站到108站
     * 109防爆沙箱站点 出库 到 108站点
     */
    public void startTest() {
    public void stnToStn(CrnSlave slave, CrnProtocol crnProtocol){
        for (CrnSlave.CrnStn crnStn : slave.getCrnInStn()) {
            if(crnStn.getStaNo()!=109){ continue; }
            boolean flag = false;
            // 获取堆垛机入库站信息
            DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, crnStn.getDevpPlcId());
            StaProtocol staProtocol = devpThread.getStation().get(crnStn.getStaNo());
            if (staProtocol == null) {
                continue;
            } else {
                staProtocol = staProtocol.clone();
            }
            // 查询站点详细信息
            BasDevp staDetl = basDevpService.selectById(crnStn.getStaNo());
            if (staDetl == null) {
                log.error("入库 ===>> 堆垛机站点在数据库不存在, 站点编号={}", crnStn.getStaNo());
                continue;
            }
            if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.getWorkNo() > 0 && staProtocol.isInEnable()
                    && staDetl.getCanining()!=null && staDetl.getCanining().equals("Y")) {
                flag = true;
            }
            StaProtocol staProtocol1 = devpThread.getStation().get(108);
            if (staProtocol1 == null) {
                continue;
            } else {
                staProtocol1 = staProtocol1.clone();
            }
            if (!staProtocol1.isAutoing() || staProtocol1.isLoading() || staProtocol1.getWorkNo() != 0 || !staProtocol1.isOutEnable()) {
                flag = false;
            }
            if (!flag) {
                continue;
            }
            // 堆垛机控制过滤
            if (!crnProtocol.getStatusType().equals(CrnStatusType.IDLE) || crnProtocol.getTaskNo() != 0) {
                continue;
            }
            // 已经存在吊车执行任务时,则过滤
            if (wrkMastMapper.selectWorking(slave.getId()) != null) {
                continue;
            }
            // 命令下发区 --------------------------------------------------------------------------
            CrnCommand crnCommand = new CrnCommand();
            crnCommand.setCrnNo(slave.getId()); // 堆垛机编号
            crnCommand.setTaskNo((short)9999); // 工作号
            crnCommand.setAckFinish((short) 0);  // 任务完成确认位
            crnCommand.setTaskMode(CrnTaskModeType.LOC_MOVE); // 任务模式:  库位移转
            crnCommand.setSourcePosX(crnStn.getRow().shortValue());     // 源库位排
            crnCommand.setSourcePosY(crnStn.getBay().shortValue());     // 源库位列
            crnCommand.setSourcePosZ(crnStn.getLev().shortValue());     // 源库位层
            crnCommand.setDestinationPosX((short)2);     // 目标库位排
            crnCommand.setDestinationPosY((short)19);     // 目标库位列
            crnCommand.setDestinationPosZ((short)1);     // 目标库位层
            if (!MessageQueue.offer(SlaveType.Crn, 1, new Task(2, crnCommand))) {
                log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", 1, JSON.toJSON(crnCommand));
            } else {
            }
        }
    }
    /**
     * 根据PLC按钮测试、完成、暂停信号,更新testMast表中status值,交由WMS系统处理
     */
    @Transactional
    public void packTest() {
        try {
            // 根据输送线plc遍历
            for (DevpSlave devp : slaveProperties.getDevp()) {
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                if(null != devpThread){
                    if (devpThread.startSignal1 == 1){
                    for (int i = 0; i < 48; i++){
                        int olsStatus = 0;//testMast表原来status数据状态
                        int newStatus = 0;//testMast表待修改的status数据状态
                        short newSingle = 0;  //PLC地址待修改的新值
                        switch (devpThread.startSignal[i]){//根据信号查找testMast表中对应状态条件,olsStatus,newStatus根据实际流程调整
                            case 1://启动复核信号
                                olsStatus = 2;
                                newStatus = 3;
                                newSingle = 2;//测试复核,寄存器地址,1===>>2
                                break;
                            case 3://完成测试信号
                                olsStatus = 3;
                                newStatus = 4;
                                newSingle = 0;//测试完成,寄存器地址清零,3===>>0
                                break;
                            case 5://暂停信号
                                olsStatus = 99;//plc给出暂停信号
                                newStatus = 0;//WCS收到暂停信号后,更新testMast
                                newSingle = 6;//暂停测试,寄存器地址,5===>>6
                                break;
                            case 7://紧急出库确认充电线已经拔出
                                olsStatus = 99;//plc给出暂停信号
                                newStatus = 0;//WCS收到暂停信号后,更新testMast
                                newSingle = 6;//暂停测试,寄存器地址,7===>>6
                                break;
                            case 8://解除暂停
                                olsStatus = 99;
                                newStatus = 0;
                                newSingle = 0;//测试复核,寄存器地址,8===>>0
                                break;
                            case 11://入库前判断充电线是否放好
                                olsStatus = 99;
                                newStatus = 0;
                                newSingle = 11;//
                                break;
                            case 12://充电线放好
                                olsStatus = 99;
                                newStatus = 0;
                                newSingle = 0;//测试复核,寄存器地址,12===>>0
                                break;
                        }
                        TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                        .eq("channel",1).eq("status",0));
                        if(null != testMast){
                            Date now = new Date();
                            //http请求测试
                            TestDto testDto = new TestDto();
                            testDto.setLocNo(testMast.getLocNo());
                            testDto.setBarcode(testMast.getBarcode());
                            testDto.setUserId(testMast.getUserId());
                            testDto.setRequestTime(DateUtils.convert(now));
                                .eq("channel",(i+1)).eq("status",olsStatus));//查找原来的状态
                        if(null != testMast &&
                                (devpThread.startSignal[i] == 1 || devpThread.startSignal[i] == 3)){
                            testMast.setStatus(newStatus);
                            testMast.setModiTime(new Date());
                            if(!testMastService.update(testMast,new EntityWrapper<TestMast>()
                                    .eq("channel",(i+1)).eq("status",olsStatus))){
                                throw new CoolException("更新产品测试状态失败");
                            }
                            //复位PLC信号,借用输送站点实体类
                            StaProtocol staProtocol = new StaProtocol();
                            staProtocol.setSiteId(i*2);//寄存器地址
                            staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,1==>2或3==>0,5==>6
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                            if(!result){
                                log.error("更新测试信号失败===>>[channel:{},locNo:{},barcode:{}]", i+1, testMast.getLocNo(), testMast.getBarcode());
//                                throw new CoolException("更新测试信号失败===>>" + i);
                            } else {
                                devpThread.startSignal[i] = newSingle;
                            }
                        }else if (devpThread.startSignal[i] == 5){
                            SearchLocParam param = new SearchLocParam();
                            param.setBarcode(i+1+"");
                            String response = new HttpHandler.Builder()
                                    .setUri(testUrl)
                                    .setPath("/testUrlPath")
                                    .setJson(JSON.toJSONString(testDto))
                                    .setUri(wmsUrl)
                                    .setPath("/mobile/test/suspend/auth")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            if (jsonObject.getInteger("code").equals(200)) {
                                //更新测试表状态
                                testMast.setStatus(1);
                                testMast.setModiTime(now);
                                testMastService.update(testMast,new EntityWrapper<TestMast>()
                                        .eq("channel",1).eq("status",0));
                                //复位PLC信号
                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, 0));
                                //复位PLC信号,借用输送站点实体类
                                StaProtocol staProtocol = new StaProtocol();
                                staProtocol.setSiteId(i*2);//寄存器地址
                                staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,5==>6
                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                                if(!result){
                                    log.error("暂停测试失败===>>["+i+1+"]号通道");
//                                throw new CoolException("更新测试信号失败===>>" + i);
                                } else {
                                    devpThread.startSignal[i] = newSingle;
                                }
                            } else {
                                log.error("请求接口失败!!!url:{},request:{},response:{}", testUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(testDto), response);
                                log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/mobile/test/suspend/auth", JSON.toJSONString(param), response);
                            }
                        }
                        }else if (devpThread.startSignal[i] == 7){
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("channel",(i+1)));
                            if (locMast.getLocSts().equals("F")){
                                locMast.setPackStatus(7); //7.紧急出库
                                locMastService.update(locMast,new EntityWrapper<LocMast>()
                                        .eq("channel",(i+1)));
                            }
                            //复位PLC信号,借用输送站点实体类
                            StaProtocol staProtocol = new StaProtocol();
                            staProtocol.setSiteId(i*2);//寄存器地址
                            staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,7==>6
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                            if(!result){
                                log.error("更新库位紧急出库信号失败===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
//                                throw new CoolException("更新测试信号失败===>>" + i);
                            } else {
                                devpThread.startSignal[i] = newSingle;
                            }
                        }else if (devpThread.startSignal[i] == 8){
                            //复位PLC信号,借用输送站点实体类
                            StaProtocol staProtocol = new StaProtocol();
                            staProtocol.setSiteId(i*2);//寄存器地址
                            staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,8==>0
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                            if(!result){
//                                log.error("更新库位紧急出库信号失败===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
//                                throw new CoolException("更新测试信号失败===>>" + i);
                            } else {
                                devpThread.startSignal[i] = newSingle;
                            }
                        }else if (devpThread.startSignal[i] == 11){
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("channel",(i+1)));
                            if (locMast.getLocSts().equals("O")){
                                locMast.setLocSts("X");
                                locMastService.update(locMast,new EntityWrapper<LocMast>()
                                        .eq("channel",(i+1)));
                            }
                        }else if (devpThread.startSignal[i] == 12){
                            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("channel",(i+1)));
                            if (locMast.getLocSts().equals("X")){
                                locMast.setLocSts("O");
                                locMastService.update(locMast,new EntityWrapper<LocMast>()
                                        .eq("channel",(i+1)));
                            }
                            //复位PLC信号,借用输送站点实体类
                            StaProtocol staProtocol = new StaProtocol();
                            staProtocol.setSiteId(i*2);//寄存器地址
                            staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,12==>0
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(3, staProtocol));
                            if(!result){
//                                log.error("更新库位紧急出库信号失败===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
//                                throw new CoolException("更新测试信号失败===>>" + i);
                            } else {
                                devpThread.startSignal[i] = newSingle;
                            }
                        }else { }
                    }
                }
            }
        } catch (Exception e) {
            log.error("启动测试  ===>> 启动测试失败", e);
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
    }