#
LSH
2023-05-17 ea242c8b2c7456b86e2b1196744d89ba6a660bc1
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -104,7 +104,6 @@
        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) {
@@ -2008,171 +2007,184 @@
                        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
                        switch (devpThread.startSignal[i][0]){//根据信号查找testMast表中对应状态条件,olsStatus,newStatus根据实际流程调整
                            case 0://初始状态,入库
                                olsStatus = 1;//待测
                                newStatus = 1;//待测
                                newSingle = 1;//库存有资料,寄存器地址,0===>>1
                                break;
                            case 2://完成测试信号
                                olsStatus = 3;
                                newStatus = 3;
                                newSingle = 3;//测试完成,寄存器地址清零,2===>>3
                            case 4://完成测试信号
                                olsStatus = 3;
                                newStatus = 4;
                                newSingle = 0;//测试完成,寄存器地址清零,4===>>0
                            case 2://启动复核信号
                                olsStatus = 1;//待测
                                newStatus = 2;//复核中
                                newSingle = 3;//测试复核,寄存器地址,2===>>3
                                break;
                            case 5://暂停信号
                            case 3://测试完成
                                olsStatus = 4;//测试完成
                                newStatus = 4;//测试完成
                                newSingle = 4;//测试完成,寄存器地址,3===>>4
                                break;
                            case 5://NG测试信号
                            case 6://完成测试信号
                            case 22://完成测试信号
                                olsStatus = 4;//测试完成
                                newStatus = 5;//已移库
                                newSingle = 0;//启动移库,寄存器地址清零,5/6===>>0
                                break;
                            case 7://暂停信号
                                olsStatus = 99;//plc给出暂停信号
                                newStatus = 0;//WCS收到暂停信号后,更新testMast
                                newSingle = 6;//暂停测试,寄存器地址,5===>>6
                                newSingle = 8;//暂停测试,寄存器地址,7===>>8
                                break;
                            case 7://紧急出库确认充电线已经拔出
                            case 9://紧急出库确认充电线已经拔出
                                olsStatus = 99;//plc给出暂停信号
                                newStatus = 0;//WCS收到暂停信号后,更新testMast
                                newSingle = 6;//暂停测试,寄存器地址,7===>>6
                                newSingle = 8;//暂停测试,寄存器地址,9===>>8
                                break;
                            case 8://解除暂停
                                olsStatus = 99;
                                newStatus = 0;
                                newSingle = 0;//测试复核,寄存器地址,8===>>0
                            case 10://解除暂停信号
                                olsStatus = 0;//plc给出暂停信号
                                newStatus = 1;//WCS收到暂停信号后,更新testMast
                                newSingle = 0;//暂停测试,寄存器地址,10===>>0/11
                                break;
                            case 11://入库前判断充电线是否放好
                                olsStatus = 99;
                                newStatus = 0;
                                newSingle = 11;//
                            case 12://紧急出库确认充电线已经拔出
                                newSingle = 11;//暂停测试,寄存器地址,12===>>11
                                break;
                            case 12://充电线放好
                                olsStatus = 99;
                                newStatus = 0;
                                newSingle = 0;//测试复核,寄存器地址,12===>>0
                            case 13://入库前判断充电线是否放好
                                newSingle = 14;//禁用库位,寄存器地址,13===>>14
                                break;
                            case 15://充电线放好
                                newSingle = 0;//复位,寄存器地址,12===>>0
                                break;
                            default:
                                log.error("读取测试库位信号出错");
                                break;
                        }
                        TestMast testMast = testMastService.selectOne(new EntityWrapper<TestMast>()
                                .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 (null != testMast && devpThread.startSignal[i] == 2){
                            if (testMast.getStatus()==3){
                                LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                                        .eq("channel",(i+1)));
                                if (locMast.getLocSts().equals("F") && locMast.getPackStatus()==3){
                                    //复位PLC信号,借用输送站点实体类
                                    StaProtocol staProtocol = new StaProtocol();
                                    staProtocol.setSiteId(i*2);//寄存器地址
                                    staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,2==>3
                                    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;
                        LocMast locMast=null;
                        boolean sign=false;
                        switch (devpThread.startSignal[i][0]){
                            case 0:
                            case 3:
                                if (!Cools.isEmpty(testMast)){
                                    locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel",(i+1)));
                                    if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")){
                                        sign=true;
                                    }
                                }
                            }
                        }else if (devpThread.startSignal[i] == 5){
                            SearchLocParam param = new SearchLocParam();
                            param.setBarcode(i+1+"");
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/mobile/test/suspend/auth")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            if (jsonObject.getInteger("code").equals(200)) {
                                //复位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;
                                break;
                            case 5:
                            case 6:
                                if (!Cools.isEmpty(testMast)){
                                    locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel",(i+1)));
                                    if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F")){
                                        if (devpThread.startSignal[i][0]==5 && locMast.getPackStatus()==4){
                                            sign=true;
                                        }else if (devpThread.startSignal[i][0]==6 && locMast.getPackStatus()==3){
                                            sign=true;
                                        }else {
                                            log.error("测试完成移库时按下完成按钮与测试结果不一致===>>[channel:{}", i+1);
                                        }
                                    }else {
                                        log.error("测试完成移库时未查询到测试档案===>>[channel:{}", i+1);
                                    }
                                }
                            } else {
                                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(8); //8.紧急出库
                                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));
                                break;
                            case 2:
                                if (!Cools.isEmpty(testMast)){
                                    testMast.setStatus(newStatus);
                                    testMast.setModiTime(new Date());
                                    if(!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("channel",(i+1)).eq("barcode",testMast.getBarcode()))){
                                        throw new CoolException("更新产品测试状态失败");
                                    }else {
                                        sign=true;
                                    }
                                }else {
                                    log.error("启动测试时未查询到测试档案===>>[channel:{}", i+1);
                                }
                                break;
                            case 7:
                                SearchLocParam param = new SearchLocParam();
                                param.setBarcode(i+1+"");
                                String response = new HttpHandler.Builder()
                                        .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 = testMastService.selectOne(new EntityWrapper<TestMast>().eq("channel",(i+1)));
                                    testMast.setStatus(newStatus);
                                    testMast.setModiTime(new Date());
                                    if(!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("channel",(i+1)).eq("barcode",testMast.getBarcode()))){
                                        log.error("更新产品测试状态失败");
                                    }
                                    sign=true;
                                } else {
                                    log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/mobile/test/suspend/auth", JSON.toJSONString(param), response);
                                }
                                break;
                            case 9:
                            case 12:
                                locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel",(i+1)));
                                if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D")){
                                    locMast.setPackStatus(8); //8.紧急出库
                                    if (locMastService.update(locMast,new EntityWrapper<LocMast>().eq("channel",(i+1)))){
                                        log.info("库位:{},紧急出库!",locMast.getLocNo());
                                    }
                                }else {
                                    log.error("库位不是在库状态,无需紧急出库!");
                                }
                                sign=true;
                                break;
                            case 10:
                                if (!Cools.isEmpty(testMast)){
                                    locMast = locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel",(i+1)));
                                    if (!Cools.isEmpty(locMast) && locMast.getLocSts().equals("F") ){
                                        if ( locMast.getFireStatus().equals(1)){
                                            newSingle=11;
                                        }else {
                                            testMast.setStatus(newStatus);
                                            testMast.setModiTime(new Date());
                                            if(!testMastService.update(testMast,new EntityWrapper<TestMast>().eq("channel",(i+1)).eq("barcode",testMast.getBarcode()))){
                                                throw new CoolException("更新产品测试状态失败");
                                            }else {
                                                sign=true;
                                            }
                                        }
                                    }
                                }
                                sign=true;
                                break;
                            case 13:
                                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)));
                                }
                                sign=true;
                                break;
                            case 15:
                                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)));
                                }
                                sign=true;
                                break;
                            default:
                                log.error("读取测试库位信号出错");
                                continue;
                        }
                        if (sign){
                            boolean result = messageQueueOffer(i,newSingle,SlaveType.Devp, devp.getId());
                            if(!result){
                                log.error("更新库位紧急出库信号失败===>>[channel:{},locNo:{},barcode:{}]", i+1, locMast.getLocNo(), locMast.getBarcode());
//                                throw new CoolException("更新测试信号失败===>>" + i);
                                log.error("更新测试信号失败===>>[channel:{},locNo:{},barcode:{}]", i+1, testMast.getLocNo(), testMast.getBarcode());
                            } else {
                                devpThread.startSignal[i] = newSingle;
                                devpThread.startSignal[i][0]  = 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 { }
                        }
                    }
                }
@@ -2185,6 +2197,14 @@
        }
    }
    public boolean messageQueueOffer(int i ,short newSingle,SlaveType devp,Integer id){
        //复位PLC信号,借用输送站点实体类
        StaProtocol staProtocol = new StaProtocol();
        staProtocol.setSiteId(i*2);//寄存器地址
        staProtocol.setStaNo(newSingle);//修改PLC寄存器地址值,8==>0
        return MessageQueue.offer(devp, id, new Task(3, staProtocol));
    }
    /**
     * 将火警报警信号写入到堆垛机PLC中
     */