自动化立体仓库 - WCS系统
野心家
2023-10-27 77c5a9937bd6a2ffbb2a45c10fa5d65d66015397
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -96,6 +96,8 @@
    @Value("${test.url}")
    private String testUrl;
    @Autowired
    private WrkMastService wrkMastService;
    /**
     * 组托
@@ -210,7 +212,7 @@
                            barcodeThread.setBarcode("");
                            staProtocol.setWorkNo((short)9999);
                            staProtocol.setStaNo((short)201);
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            devpThread.setPakMk(staProtocol.getSiteId(), true);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            log.error("url:{};request:{};response:{}", wmsUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }else {
@@ -218,7 +220,7 @@
                            barcodeThread.setBarcode("");
                            staProtocol.setWorkNo((short)9999);
                            staProtocol.setStaNo((short)201);
                            devpThread.setPakMk(staProtocol.getSiteId(), false);
                            devpThread.setPakMk(staProtocol.getSiteId(), true);
                            boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(2, staProtocol));
                            log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl+"/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                        }
@@ -500,7 +502,7 @@
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (staProtocol.isAutoing() && (staProtocol.isLoading()||staProtocol.getSiteId()==109) && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                if (staProtocol.isAutoing() && (staProtocol.isLoading()||staProtocol.getSiteId()==1000) && (staProtocol.getWorkNo() == 0 || staProtocol.getStaNo() == null)) {
                    // 查询工作档
                    WrkMast wrkMast = wrkMastMapper.selectPakOutStep2(staProtocol.getSiteId());
                    if (wrkMast == null) {
@@ -567,12 +569,53 @@
//            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);
            }else {
                continue;
            }
            try{
                Thread.sleep(1000);
            }catch (Exception e){
                continue;
            }
            crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) { continue; }
            basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
                    && crnProtocol.getLoaded() == 0 && crnProtocol.getForkPos() == 0) {
                // 库位移转
                this.locToLoc(crn, crnProtocol);
            }else {
                continue;
            }
            try{
                Thread.sleep(1000);
            }catch (Exception e){
                continue;
            }
            crnThread = (CrnThread) SlaveConnection.get(SlaveType.Crn, crn.getId());
            crnProtocol = crnThread.getCrnProtocol();
            if (crnProtocol == null) { continue; }
            basCrnp = basCrnpService.selectById(crn.getId());
            if (basCrnp == null) {
                log.error("{}号堆垛机尚未在数据库进行维护!", crn.getId());
                continue;
            }
            // 只有当堆垛机空闲 并且 无任务时才继续执行
            if (crnProtocol.getStatusType() == CrnStatusType.IDLE && crnProtocol.getTaskNo() == 0 && crnProtocol.getModeType() == CrnModeType.AUTO
                    && crnProtocol.getLoaded() == 0 && crnProtocol.getForkPos() == 0) {
                // 如果最近一次是入库模式
                if (crnProtocol.getLastIo().equals("I")) {
                    if (basCrnp.getInEnable().equals("Y")) {
@@ -595,7 +638,6 @@
                }
            }
            // 库位移转
            this.locToLoc(crn, crnProtocol);
//            this.crnRebackHp(crnProtocol, crnThread);
        }
@@ -907,6 +949,7 @@
                        break;
//                        return;
                    }
                    // 1.堆垛机开始移动
                    CrnCommand crnCommand = new CrnCommand();
@@ -2348,6 +2391,7 @@
                SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, devp.getId());
                if(null != devpThread){
                    for (int i = 0; i < 48; i++){
                        boolean fig=false;
                        //查询在库和预约出库
                        LocMast locMast=locMastService.selectztgx("F","R",i);
                        if(!Cools.isEmpty(locMast)){
@@ -2365,25 +2409,50 @@
                            //testMast.setStatus
                            //"状态 0: 待申请  1: 申请中  2: 已复核 3:测试中 4:完成 5:移库 6:火警"
                            if(devpThread.startSignal[i][0]==1){
                            if(devpThread.startSignal[i][0]==8){
                                testMast.setStatus(1);
                                locMast.setPackStatus(1);
                                testMast.setModiTime(new Date());
                            }else if(devpThread.startSignal[i][0]==2){
                            }else if(devpThread.startSignal[i][0]==2 && locMast.getPackStatus()!=2){
                                testMast.setStatus(3);
                                locMast.setPackStatus(2);
                                testMast.setModiTime(new Date());
                                //NG转OK需要还原源库位和目标库位状态,OK转NG 删除任务档
                                WrkMast wrkMast=wrkMastService.selectOne(new EntityWrapper<WrkMast>()
                                        .eq("source_loc_no",locMast.getLocNo())
                                        .eq("wrk_sts",11));
                                if(!Cools.isEmpty(wrkMast)){
                                    if(wrkMast.getWrkSts()==11){
                                    if(wrkMast.getIoType()==11){
                                        LocMast locMast1=locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",wrkMast.getLocNo()));
                                        locMast1.setLocSts("O");
                                        locMastService.update(locMast1,new EntityWrapper<LocMast>().eq("loc_no",wrkMast.getLocNo()));
                                    }
                                    wrkMastMapper.delete(new EntityWrapper<WrkMast>()
                                                .eq("wrk_sts",11)
                                                .eq("source_loc_no",locMast.getLocNo()));
                                    locMast.setLocSts("F");
                                    wrkDetlService.delete(new EntityWrapper<WrkDetl>().eq("zpallet",wrkMast.getBarcode()));
                                    if(!locMastService.update(locMast,new EntityWrapper<LocMast>()
                                            .eq("channel",i+1))){
                                        log.error("修改测试库位状态失败"+locMast.getLocNo(),locMast);
                                    }else{
                                        fig=true;
                                    }
                                }}
                            }else if(devpThread.startSignal[i][0]==3){
                                locMast.setPackStatus(7);
                                testMast.setModiTime(new Date());
                            }else if(devpThread.startSignal[i][0]==4 && testMast.getStatus()!=4){
                            }else if(devpThread.startSignal[i][0]==4 && testMast.getStatus()!=4&&locMast.getFireStatus()!=1&&testMast.getStatus()!=6){
                                locMast.setPackStatus(3);
                                testMast.setStatus(4);
                                testMast.setModiTime(new Date());
                                testMastService.insertPackQualified(true,new Date());
                            }else if(devpThread.startSignal[i][0]==5 && testMast.getStatus()!=4){
                                testMastService.insertPackQualified(true,new Date(),testMast.getBarcode());
                            }else if(devpThread.startSignal[i][0]==5 && testMast.getStatus()!=4&&locMast.getFireStatus()!=1&&testMast.getStatus()!=6){
                                locMast.setPackStatus(4);
                                testMast.setStatus(4);
                                testMast.setModiTime(new Date());
                                testMastService.insertPackQualified(false,new Date());
                                testMastService.insertPackQualified(false,new Date(),testMast.getBarcode());
                            }
//                            else if(devpThread.startSignal[i][0]==6||devpThread.startSignal[i][0]==7||devpThread.startSignal[i][0]==8){
//                                locMast.setPackStatus(devpThread.startSignal[i][0]+3);
@@ -2391,16 +2460,26 @@
                            //通道启动按钮状态,1:可以启动出库或者移库,0:不能启动出库或者移库
                            locMast.setCtnKind(devpThread.startSignal[i][2]);
                            if(devpThread.startSignal[i][2]==1){
                                WrkMast wrkMast=wrkMastService.selectOne(new EntityWrapper<WrkMast>().eq("source_loc_no",locMast.getLocNo()));
                                if(!Cools.isEmpty(wrkMast)){
                                    wrkMast.setMk("Y");
                                    if(!wrkMastService.update(wrkMast,new EntityWrapper<WrkMast>()
                                            .eq("source_loc_no",locMast.getLocNo()))){
                                        log.error("修改任务档启动按钮状态,任务档状态失败"+wrkMast.getSourceLocNo(),wrkMast);
                                    }
                                }
                                if(!locMastService.update(locMast,new EntityWrapper<LocMast>()
                                        .eq("loc_sts","R")
                                        .eq("channel",i+1))){
                                    log.error("修改启动按钮状态,测试库位状态失败"+locMast.getLocNo(),locMast);
                                }
                            }else if(!locMast.getLocSts().equals("R")){
                                if(!locMastService.update(locMast,new EntityWrapper<LocMast>()
                                        .eq("loc_sts","F")
                                        .eq("channel",i+1))){
                                    log.error("修改测试库位状态失败"+locMast.getLocNo(),locMast);
                                if(!fig){
                                    if(!locMastService.update(locMast,new EntityWrapper<LocMast>()
                                            .eq("loc_sts","F")
                                            .eq("channel",i+1))){
                                        log.error("修改测试库位状态失败"+locMast.getLocNo(),locMast);
                                    }
                                }
                                if(!testMastService.update(testMast,new EntityWrapper<TestMast>()
                                        .eq("loc_no",locMast.getLocNo())
@@ -2410,12 +2489,18 @@
                            }
                        }
                    }
                    //当充放电库位为O空库位时
                    //库位状态改为8空闲
                    //给PLC写消防信号
                    for (int i=0;i<48;i++){
                        LocMast locMast=locMastService.selectOne(new EntityWrapper<LocMast>().eq("channel",i+1));
                        TestMast testMast=testMastService.selectOne(new EntityWrapper<TestMast>()
                                .eq("loc_no",locMast.getLocNo())
                                .eq("user_id",locMast.getBarcode()));
                        if((locMast.getLocSts().equals("O")||locMast.getLocSts().equals("S"))&&devpThread.startSignal[i][0]!=8){
                            Thread.sleep(1000);
                            MessageQueue.offer(SlaveType.Devp, 1, new Task(6,locMast.getChannel()-1));
                        }
                        try{
                            if(locMast.getFireStatus()!=devpThread.startSignal[i][1]){
                                messageQueueOffer2(i,(short)((int)locMast.getFireStatus()),SlaveType.Devp, devp.getId());
@@ -2436,6 +2521,8 @@
                        }
                    }
                }
            }