自动化立体仓库 - WCS系统
#
yxFwq
2024-07-19 2b4b495c41695a21b10c548599a0af98e984eda5
src/main/java/com/zy/asrs/service/impl/MainServiceImpl.java
@@ -59,6 +59,7 @@
//    private static final int[][] execute = new int[][]{{1,4},{2,4},{3,4},{4,4},{5,6},{6,6},{7,4},{8,4},{9,3},{10,4},{11,4}};
    private static final int[][] execute = new int[][]{{1,4},{2,4},{3,4},{4,4},{5,6},{6,6},{7,4},{8,4},{9,3},{10,4},{11,4}};
    private static final Integer jarMaxLoc = 6;
    @Autowired
    private CommonService commonService;
    @Autowired
@@ -270,7 +271,7 @@
                            staProtocol.setWorkNo(dto.getWorkNo());
                            if(Cools.isEmpty(dto.getRgvNo()) || dto.getRgvNo() <= 0) {
                                staProtocol.setStaNo(dto.getStaNo());
                                staProtocol.setStaNo(607);//607
                            } else {//如果存在RGV编号,说明需要RGV接驳,先下发任务到RGV源站
                                staProtocol.setStaNo(dto.getRgvSstaNo());
                            }
@@ -1959,6 +1960,10 @@
                        crnCommandParam.setDestinationPosX((short)0);     // 目标库位排
                        crnCommandParam.setDestinationPosY((short)0);     // 目标库位列
                        crnCommandParam.setDestinationPosZ((short)0);     // 目标库位层
                        if (!MessageQueue.offer(SlaveType.Devp, crnStn.getDevpPlcId(), new Task(99, crnCommandParam.getCrnNo()-2))) {
                            log.error("输送线锁定命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), crnCommandParam.getCrnNo()-2);
                            continue;
                        }
                        if (!MessageQueue.offer(SlaveType.Crn, crnCommandParam.getCrnNo(), new Task(9, crnCommandParam))) {
                            log.error("堆垛机命令下发失败,堆垛机号={},任务数据={}", wrkMast.getCrnNo(), JSON.toJSONString(crnCommandParam));
                        } else {
@@ -3733,6 +3738,46 @@
                } else {
                    staProtocol = staProtocol.clone();
                }
                if (emptyInSta.getStaNo()==607 && staProtocol.getStaNo()==607 && staProtocol.getWorkNo()>20000 && staProtocol.isLoading() && staProtocol.isAutoing()){
                    try {
                        BasDevp basDevp = basDevpService.selectById(staProtocol.getStaNo());
                        if (basDevp.getReportSign()==0){
                            LocTypeDto locTypeDto = new LocTypeDto(staProtocol);
                            SearchLocParam param = new SearchLocParam();
                            param.setIoType(10);
                            param.setSourceStaNo(emptyInSta.getStaNo());
                            param.setLocType1(locTypeDto.getLocType1());
                            String response = new HttpHandler.Builder()
                                    .setUri(wmsUrl)
                                    .setPath("/rpc/pakin/loc/v1")
                                    .setJson(JSON.toJSONString(param))
                                    .build()
                                    .doPost();
                            JSONObject jsonObject = JSON.parseObject(response);
                            if (jsonObject.getInteger("code").equals(200)) {
                                basDevp.setReportSign(1);
                                basDevpService.updateById(basDevp);
                                StartupDto dto = jsonObject.getObject("data", StartupDto.class);
                                // 更新站点信息 且 下发plc命令
                                staProtocol.setWorkNo(dto.getWorkNo());
                                staProtocol.setStaNo(607);
                                devpThread.setPakMk(staProtocol.getSiteId(), false);
                                boolean result = MessageQueue.offer(SlaveType.Devp, devp.getId(), new Task(5, staProtocol));
                                if (!result) {
                                    throw new CoolException("更新plc站点信息失败");
                                }
                            } else {
                                log.error("请求接口失败!!!url:{};request:{};response:{}", wmsUrl + "/rpc/pakin/loc/v1", JSON.toJSONString(param), response);
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                    }
                    return;
                }
                // 站点条件判断
                if (staProtocol.isAutoing() && staProtocol.isLoading() && staProtocol.isInEnable()
@@ -4771,10 +4816,10 @@
                            if (basJarMastService.selectJarMastOperation(jarSlave.getJarOtherId(),3)!=0){
                                break;
                            }
                            if (basJarMastService.getJarMastByJarIdCount(jarSlave.getId())>=14){
                            if (basJarMastService.getJarMastByJarIdCount(jarSlave.getId())>=jarMaxLoc*2){
                                break;
                            }
                            if (basJarMastService.selectJarMastOperation(jarSlave.getId(),0,9)>=7){
                            if (basJarMastService.selectJarMastOperation(jarSlave.getId(),0,9)>=jarMaxLoc){
                                break;
                            }
                            if (!Objects.equals
@@ -4793,7 +4838,7 @@
                                    break;
                                }
                                jarLocDigit = 1;
                            } else if (jarMastByJarIdMax.getJarLocDigit()<7){
                            } else if (jarMastByJarIdMax.getJarLocDigit()<jarMaxLoc){
                                jarLocDigit = jarMastByJarIdMax.getJarLocDigit()+1;
                            } else {
                                continue;
@@ -4899,10 +4944,25 @@
                    List<WrkMastExecute> wrkMastExecuteList = wrkMastExecuteService.selectWrkMastExecuteByWrk(wrkMastExecuteSou);
                    for (WrkMastExecute wrkMastExecute : wrkMastExecuteList){
                        log.error("Jar任务完成===>行={}",4564);
                        BasJarMast jarMastByWrkNo = basJarMastService.getJarMastByWrkNo(wrkMastExecute.getWrkNo());
                        jarMastByWrkNo.setStatus(jarMastByWrkNo.getStatusComplete());
                        if (!basJarMastService.updateById(jarMastByWrkNo)){
                            log.error("硫化区域分段任务完成异常,BasJarMast={},异常信息={}",JSON.toJSONString(jarMastByWrkNo),"更新basJarMast失败");
                        if (wrkMastExecute.getIoType()<7 || wrkMastExecute.getIoType()==9){
                            BasJarMast jarMastByWrkNo = basJarMastService.getJarMastByWrkNo(wrkMastExecute.getWrkNo());
                            jarMastByWrkNo.setStatus(jarMastByWrkNo.getStatusComplete(wrkMastExecute.getIoType()));
                            if (wrkMastExecute.getIoType()==3 && jarMastByWrkNo.getStatus()==8){
                                List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarMastByWrkNo.getJarId(), new ArrayList<Integer>() {{
                                    add(6);//硫化完成
                                }});
                                if (basJarMastList.isEmpty()){
                                    continue;
                                }
                                Integer integer = basJarMastService.updateStatus(jarMastByWrkNo.getJarId(), 6, 8);
                                if (basJarMastList.size()!=integer){
                                    log.error("{}号硫化罐硫化完成后开门完成修改硫化档案状态结果数量不一致!!!查询资料数量={},更新返回数量={}",jarMastByWrkNo.getJarId(),basJarMastList.size(),integer);
                                }
                            } else {
                                if (!basJarMastService.updateById(jarMastByWrkNo)){
                                    log.error("硫化区域分段任务完成异常,BasJarMast={},异常信息={}",JSON.toJSONString(jarMastByWrkNo),"更新basJarMast失败");
                                }
                            }
                        }
                        wrkMastExecute.setWrkSts(wrkMastExecute.getWrkStsComplete());
                        wrkMastExecute.setWrkType(2);
@@ -5254,7 +5314,7 @@
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
                add(4);
            }});
            if (basJarMastList.size() != 7){
            if (basJarMastList.size() != jarMaxLoc){
                return false;
            }
@@ -5293,13 +5353,13 @@
                    log.error("{}号硫化罐查询设备档案无信息!!!",jarProtocol.getJarNo());
                    return false;
                }
                if (basJar.getJarCount()!=7){
                if (!basJar.getJarCount().equals(jarMaxLoc)){
                    log.error("{}号硫化罐查询设备库存数异常!!!库存待入数:{}",jarProtocol.getJarNo(),basJar.getJarCount());
                    return false;
                }
                //门作业  无
                if (jarProtocol.isAutoing() && jarProtocol.statusType == JarStatusType.WAITING3 && jarProtocol.jarErr==0
                if (jarProtocol.isAutoing() && jarProtocol.statusType != JarStatusType.SOS && jarProtocol.jarErr==0
                        && jarProtocol.isRightDoor() && jarProtocol.isLeftDoor()
                        && jarProtocol.leftDoorOpen==0  && jarProtocol.leftDoorClose==0 && jarProtocol.rightDoorOpen==0  && jarProtocol.rightDoorClose==0){
                    //关进料门
@@ -5331,7 +5391,7 @@
            List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
                add(6);
            }});
            if (basJarMastList.size() != 7){
            if (basJarMastList.size() != jarMaxLoc){
                return false;
            }
            if (basJarMastService.selectJarMastOperation(jarSlave.getJarOtherId(),5)!=0){
@@ -6779,7 +6839,7 @@
                    } else {
                        //调车  == > endRow
                        if (!jarRgvMoveTake(wrkMastExecute,SteAndJarUtil.getRgvJarNowRow(wrkMastExecute.getJarId()))){
                        if (!jarRgvMoveTake(wrkMastExecute,SteAndJarUtil.getRgvJarNowRow(jarProtocolOther.getJarNo()))){
                            log.error("平衡车RGV命令下发失败,rgv号={},任务数据={},硫化罐数据={},sign={}",
                                    wrkMastExecute.getJarId(), JSON.toJSONString(wrkMastExecute), JSON.toJSONString(jarProtocol),sign);
                        }
@@ -7472,7 +7532,7 @@
                }
                //WAITING2(4, "硫化完成"),
                if (jarProtocol.getJarErr()==0 && jarProtocol.getStatusType().equals(JarStatusType.WAITING2)
                        && jarProtocol.isRightDoor() && jarProtocol.isLeftDoor()
                        && !jarProtocol.isRightDoor() && !jarProtocol.isLeftDoor()
                        && jarProtocol.leftDoorOpen==0 && jarProtocol.leftDoorClose==0 && jarProtocol.rightDoorOpen==0 && jarProtocol.rightDoorClose==0
                ){
                    List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarSlave.getId(), new ArrayList<Integer>() {{
@@ -7520,7 +7580,7 @@
                        }
                    }
                } else if (jarProtocol.getJarErr()==0
                        && jarProtocol.isRightDoor() && jarProtocol.isLeftDoor()
                        && !jarProtocol.isRightDoor() && !jarProtocol.isLeftDoor()
                        && jarProtocol.leftDoorClose!=1 && jarProtocol.leftDoorClose!=3
                        && jarProtocol.rightDoorClose!=1 && jarProtocol.rightDoorClose!=3
                        && (jarProtocol.leftDoorClose==2  || jarProtocol.rightDoorClose==2)){
@@ -7683,10 +7743,11 @@
                try{
                    if (jarWrkMastExecuteGenerateSteStatus(steSlave.getId(),1,SteStatusType.IDLE,false)){
                        List<WrkMastExecute> wrkMastExecutes = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 5, null);
                        if (wrkMastExecutes.isEmpty()){
                            List<WrkMastExecute> wrkMastExecutesB = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 6, null);
                            List<WrkMastExecute> wrkMastExecutesC = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 9, null);
                        List<WrkMastExecute> wrkMastExecutes = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 5, null,steProtocol.getSteNo().intValue());
                        List<WrkMastExecute> wrkMastExecutes100 = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 100, null,steProtocol.getSteNo().intValue());
                        if (wrkMastExecutes.isEmpty() && wrkMastExecutes100.isEmpty()){
                            List<WrkMastExecute> wrkMastExecutesB = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 6, null,steProtocol.getSteNo().intValue());
                            List<WrkMastExecute> wrkMastExecutesC = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 9, null,steProtocol.getSteNo().intValue());
                            if (!wrkMastExecutesB.isEmpty() || !wrkMastExecutesC.isEmpty()){
                                WrkMastExecute wrkMastExecute = !wrkMastExecutesB.isEmpty() ? wrkMastExecutesB.get(0) : wrkMastExecutesC.get(0);
@@ -7704,11 +7765,11 @@
                            }
                        }
                    } else if (jarWrkMastExecuteGenerateSteStatus(steSlave.getId(),2,SteStatusType.IDLE,false)){
                        List<WrkMastExecute> wrkMastExecutes = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 6, null);
                        List<WrkMastExecute> wrkMastExecutes = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 6, null,steProtocol.getSteNo().intValue());
                        if (wrkMastExecutes.isEmpty()){
                            List<WrkMastExecute> wrkMastExecutesA = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 5, null);
                            List<WrkMastExecute> wrkMastExecutesC = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 9, null);
                            List<WrkMastExecute> wrkMastExecutes100 = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 100, null);
                            List<WrkMastExecute> wrkMastExecutesA = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 5, null,steProtocol.getSteNo().intValue());
                            List<WrkMastExecute> wrkMastExecutesC = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 9, null,steProtocol.getSteNo().intValue());
                            List<WrkMastExecute> wrkMastExecutes100 = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 100, null,steProtocol.getSteNo().intValue());
                            if (!wrkMastExecutes100.isEmpty()){
                                WrkMastExecute wrkMastExecute = wrkMastExecutes100.get(0);
                                BasJar basJar = basJarMapper.selectById(wrkMastExecute.getJarId());
@@ -7759,11 +7820,11 @@
                            }
                        }
                    } else if (jarWrkMastExecuteGenerateSteStatus(steSlave.getId(),3,SteStatusType.IDLE,false)){
                        List<WrkMastExecute> wrkMastExecutes = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 9, null);
                        List<WrkMastExecute> wrkMastExecutes = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 9, null,steProtocol.getSteNo().intValue());
                        if (wrkMastExecutes.isEmpty()){
                            List<WrkMastExecute> wrkMastExecutesB = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 6, null);
                            List<WrkMastExecute> wrkMastExecutesA = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 5, null);
                            List<WrkMastExecute> wrkMastExecutes100 = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 100, null);
                            List<WrkMastExecute> wrkMastExecutesB = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 6, null,steProtocol.getSteNo().intValue());
                            List<WrkMastExecute> wrkMastExecutesA = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 5, null,steProtocol.getSteNo().intValue());
                            List<WrkMastExecute> wrkMastExecutes100 = wrkMastExecuteService.selectWrkMastExecuteByTypeAndIoTyperAndWrkType(null, 100, null,steProtocol.getSteNo().intValue());
                            if (!wrkMastExecutes100.isEmpty()){
                                WrkMastExecute wrkMastExecute = wrkMastExecutes100.get(0);
                                BasJar basJar = basJarMapper.selectById(wrkMastExecute.getJarId());
@@ -7838,6 +7899,14 @@
                        continue;
                    }
                } else if (steProtocol.getCharge()<80.0F){
                    List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusListCharge(steSlave.getId(), new ArrayList<Integer>() {{
                        add(5);
                        add(11);
                        add(17);
                    }});
                    if(!basJarMastList.isEmpty()){
                        continue;
                    }
                    if (wrkMastExecuteService.selectNoStart(steSlave.getId())!=0){
                        continue;
                    }
@@ -7937,9 +8006,16 @@
                if (steProtocol.getCharge()>95.0F || steProtocol.getFullCharge()){
                } else if (steProtocol.getCharge()>50.0F){
                    if (wrkMastExecuteService.selectNoStartCharge(steSlave.getId())==0){
                        if (wrkMastExecuteService.selectMoveStart(steSlave.getId())==0){
                            continue;
                    List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusListCharge(steSlave.getId(), new ArrayList<Integer>() {{
                        add(5);
                        add(11);
                        add(17);
                    }});
                    if(basJarMastList.isEmpty()){
                        if (wrkMastExecuteService.selectNoStartCharge(steSlave.getId())==0){
                            if (wrkMastExecuteService.selectMoveStart(steSlave.getId())==0){
                                continue;
                            }
                        }
                    }
                } else {
@@ -7988,5 +8064,105 @@
        }
        return false;
    }
    /**
     * 其他  ===>> 607分配硫化罐
     */
    public synchronized void stackingCompletionDriveTray() {
        Integer staNo1 = jarGetStartStaNo(607);
        if (staNo1!=0){
            SiemensDevpThread devpThread = (SiemensDevpThread) SlaveConnection.get(SlaveType.Devp, 2);
            StaProtocol staProtocol607 = devpThread.getStation().get(607);
            if (staProtocol607.getWorkNo()<9001 && staProtocol607.getWorkNo()!=0 && staProtocol607.isLoading() && staProtocol607.isAutoing() && staProtocol607.getStaNo() == 607){
                staProtocol607.setStaNo(staNo1);
                boolean result2 = MessageQueue.offer(SlaveType.Devp, 2, new Task(5, staProtocol607));
            }
        }
    }
    public synchronized Integer jarGetStartStaNo(Integer staNo) {
        try {
            int[] jarNos=new int[]{4,2,3,1};//(607分配硫化罐)
            ArrayList<Integer> staNos = new ArrayList<Integer>() {{
                add(607);add(608);add(609);add(610);add(611);add(612);
                add(613);add(614);add(615);add(616);add(617);add(618);
                add(619);add(620);add(621);add(622);
            }};
            ArrayList<Integer> jarNoList = new ArrayList<>();
            ArrayList<Integer> jarNoListNow = new ArrayList<>();
            for (int jarNo : jarNos) {
                List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarNo, new ArrayList<Integer>() {{
                    add(0);
                    add(1);
                    add(2);
                    add(3);
                    add(4);
                }});
                if (basJarMastList.isEmpty()){
                    continue;
                }
                if (basJarMastList.size()>0 && basJarMastList.size()<jarMaxLoc){
                    jarNoList.add(jarNo);
                }
            }
            jarNoList.add(4);
            jarNoList.add(2);
            jarNoList.add(3);
            jarNoList.add(1);
            for (int jarNo : jarNoList) {
                if (jarNoListNow.contains(jarNo)){
                    continue;
                }
                // 获取硫化罐信息
                JarThread jarThread = (JarThread) SlaveConnection.get(SlaveType.Jar, jarNo);
                JarProtocol jarProtocol = jarThread.getJarProtocol();
                if (jarProtocol == null) {
                    continue;
                }
                if (jarProtocol.modeType != JarModeType.AUTO){
                    continue;
                }
                if (jarProtocol.statusType .equals(JarStatusType.SOS)){
                    continue;
                }
                if (jarProtocol.getJarTemperature()>50){
                    log.error("{}号硫化罐查询设备温度过高,等待降温....!!!",jarProtocol.getJarNo());
                    continue;
                }
                BasJar basJar = basJarMapper.selectById(jarProtocol.getJarNo());
                if (Cools.isEmpty(basJar)){
                    log.error("{}号硫化罐查询设备档案无信息!!!",jarProtocol.getJarNo());
                    continue;
                }
                List<BasJarMast> basJarMastList = basJarMastService.getJarMastByJarIdAndStatusList(jarNo, new ArrayList<Integer>() {{
                    add(0);
                    add(1);
                    add(2);
                    add(3);
                    add(4);
                }});
                DevpThread devpThread = (DevpThread) SlaveConnection.get(SlaveType.Devp, 2);
                Integer count = basJarMastList.size();
                ArrayList<Integer> wrkNoList = new ArrayList<>();
                for (Integer staNoEnt : staNos){
                    StaProtocol staProtocolEnt = devpThread.getStation().get(staNoEnt);
                    if (staProtocolEnt != null && staProtocolEnt.getWorkNo()!=0 && !wrkNoList.contains(staProtocolEnt.getWorkNo())){
                        if (staProtocolEnt.getStaNo().equals(basJar.getEntStaNo$())){
                            count++;
                            wrkNoList.add(staProtocolEnt.getWorkNo());
                        }
                    }
                }
                if (count<jarMaxLoc){
                    return basJar.getEntStaNo$();
                }
            }
        }catch (Exception e){
//            e.printStackTrace();
//            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            log.error("其他  ===>> 分配硫化罐进入下一步"+e);
        }
        return 0;
    }
}