自动化立体仓库 - WMS系统
skyouc
昨天 b0e463fbc3acbbe84ca0efaf924a99e53d2ab380
src/main/java/com/zy/common/service/CommonService.java
@@ -122,35 +122,17 @@
    public StartupDto getLocNo(Integer staDescId, Integer sourceStaNo, Integer whsType, FindLocNoAttributeVo findLocNoAttributeVo,
                               LocTypeDto locTypeDto) {
        try {
//            Integer whsType = Utils.GetWhsType(sourceStaNo);
//            RowLastno rowLastno = rowLastnoService.selectById(whsType);
//            RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId());
            /**
             * 库型 1: 标准堆垛机库 2: 平库 3: 穿梭板 4: 四向车 5: AGV 0: 未知
             */
            return getLocNoRun(staDescId, whsType,  sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0);
            // switch (rowLastnoType.getType()) {
            // case 1:
            // return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0,
            // locTypeDto, 0);
            //// case 2:
            //// log.error("站点={} 未查询到对应的规则", sourceStaNo);
            //// break;
            //// case 3:
            //// log.error("站点={} 未查询到对应的规则", sourceStaNo);
            //// break;
            //// case 4:
            //// return getLocNoRun4(whsType, staDescId, sourceStaNo, findLocNoAttributeVo,
            // 4, locTypeDto, 0);
            //// case 5:
            //// return getLocNoRun5(whsType, staDescId, sourceStaNo, findLocNoAttributeVo,
            // 0, locTypeDto, 0);
            //// default:
            //// log.error("站点={} 未查询到对应的规则", sourceStaNo);
            //// break;
            // }
            RowLastno rowLastno = rowLastnoService.selectById(whsType);
            RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId());
//            /**
//             * 库型 1: 标准堆垛机库 2: 平库 3: 穿梭板 4: 四向车 5: AGV 0: 未知
//             */
            if (rowLastnoType.getType() == 3) {
                return getDoubleLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo,
                        4, locTypeDto, 0);
            } else {
                return getLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, 0, locTypeDto, 0);
            }
        } catch (Exception e) {
            log.error("站点={} 未查询到对应的规则", sourceStaNo);
        }
@@ -160,7 +142,7 @@
    /**
     * 检索库位号
     *
     * @param whsType              类型 1:双深式货架
     * @param whsType              类型 1:单伸式货架
     * @param staDescId            路径ID
     * @param sourceStaNo          源站
     * @param findLocNoAttributeVo 属性
@@ -170,8 +152,8 @@
     * @return locNo 检索到的库位号
     */
    @Transactional
    public StartupDto getLocNoRun( Integer staDescId, Integer whsType, Integer sourceStaNo,
            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
    public StartupDto getLocNoRun(Integer staDescId, Integer whsType, Integer sourceStaNo,
                                  FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        staDescId = 1;
        // 初始化参数
        int crnNo = 0; // 堆垛机号
@@ -197,7 +179,7 @@
                .ge("row1", rowLastno.getsRow())
                .le("row1", rowLastno.geteRow())
                .eq("crn_no", crnNo)
                .eq("move_status", 0)
//                .eq("move_status", 0)
                .eq("loc_sts", "O")
                .orderAsc(Arrays.asList("lev1", "row1", "bay1")));
        // int crnCountO = wrkMastService.selectCount(new
@@ -213,8 +195,313 @@
        return startupDto;
    }
    /**
     * 检索库位号
     *
     * @param whsType              类型 1:双深式货架
     * @param staDescId            路径ID
     * @param sourceStaNo          源站
     * @param findLocNoAttributeVo 属性
     * @param moveCrnNo            源
     * @param locTypeDto           类型
     * @param times                轮询次数
     * @return locNo 检索到的库位号
     */
    public StartupDto getDoubleLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        // 初始化参数
        int crnNo = 0;      //堆垛机号
        int nearRow = 0;    //最浅库位排
        int curRow = 0;     //最深库位排
        int rowCount = 0;   //轮询轮次
        LocMast locMast = null;     // 目标库位
        StartupDto startupDto = new StartupDto();
        RowLastno rowLastno = rowLastnoService.selectById(whsType);
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员===>库位规则未知");
        }
        RowLastnoType rowLastnoType = rowLastnoTypeService.selectById(rowLastno.getTypeId());
        if (Cools.isEmpty(rowLastnoType)) {
            throw new CoolException("数据异常,请联系管理员===》库位规则类型未知");
        }
        int sRow = rowLastno.getsRow();
        int eRow = rowLastno.geteRow();
        int crnNumber = rowLastno.getCrnQty();
        // ===============>>>> 开始执行
        curRow = rowLastno.getCurrentRow();
        if (!Cools.isEmpty(moveCrnNo) && moveCrnNo != 0) {
            crnNumber = moveCrnNo;
            if (times == 0) {
                curRow = moveCrnNo * 4 - 1;
            } else {
                curRow = moveCrnNo * 4 - 2;
            }
        }
        //此程序用于优化堆垛机异常时的运行时间
        for (int i = times; i < crnNumber * 2; i++) {
            int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRow, crnNumber);
            curRow = locNecessaryParameters[1];
            crnNo = locNecessaryParameters[2];
            if (basCrnpService.checkSiteError(crnNo, true)) {
                rowCount = locNecessaryParameters[0];
                nearRow = locNecessaryParameters[3];
                List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                        .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()));
                int crnCountO = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100));
                if (locMasts.size() - crnCountO <= 2) {
                    log.error(crnNo + "号堆垛机没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
                    nearRow = 0;
                    times++;
                    continue;
                }
                break;
            } else {
                times++;
            }
        }
        if (nearRow == 0) {
            throw new CoolException("无可用堆垛机");
        }
        boolean signRule1 = false;
        boolean signRule2 = false;
        if (Utils.BooleanWhsTypeStaIoType(rowLastno)) {
            // 靠近摆放规则 --- 同天同规格物料 //分离版
            if (!Cools.isEmpty(findLocNoAttributeVo.getMatnr()) && staDescId == 1) {
                signRule1 = true;
            }
            // 靠近摆放规则 --- 同天同规格物料 //互通版
            if (!Cools.isEmpty(findLocNoAttributeVo.getMatnr()) && staDescId == 1) {
                signRule2 = true;
            }
            if (!Cools.isEmpty(findLocNoAttributeVo.getMatnr()) && (staDescId == 11 || staDescId == 111)) {
                signRule1 = true;
            }
        }
        if (signRule1) {
            if (nearRow != curRow) {
                List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                        .eq("row1", nearRow).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()));
                for (LocMast locMast1 : locMasts) {
                    //获取巷道
//                    List<String> groupOutsideLocCrn = Utils.getGroupOutLocCrn(curRow,nearRow,locMast1.getLocNo(), curRow>nearRow);
//                    LocMast locMastGro = locMastService.selectById(wrkMast.getLocNo());
                    //获取目标库位所在巷道最浅非空库位
                    LocMast locMastF = locMastService.selectLocByLocStsPakInF(curRow, nearRow, locMast1, rowLastnoType.getType().longValue());
                    if (!Cools.isEmpty(locMastF) && locMastF.getLocSts().equals("F")) {
                        LocDetl locDetl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", locMastF.getLocNo()));
                        if (!Cools.isEmpty(locDetl) && findLocNoAttributeVo.getMatnr().equals(locDetl.getMatnr())
                                && findLocNoAttributeVo.getBatch().equals(locDetl.getBatch())
                                && findLocNoAttributeVo.getBrand().equals(locDetl.getBrand())) {
                            //获取目标库位所在巷道最深空库位
                            locMast = locMastService.selectLocByLocStsPakInO(curRow, nearRow, locMast1, rowLastnoType.getType().longValue());
                            break;
                        }
                    }
                }
            }
        } else if (signRule2) {
            List<String> locNos = locDetlService.getSameDetlToday(findLocNoAttributeVo.getMatnr(), sRow, eRow);
            for (String locNo : locNos) {
                if (Utils.isShallowLoc(slaveProperties, locNo)) {
                    continue;
                }
                String shallowLocNo = Utils.getShallowLoc(slaveProperties, locNo);
                // 检测目标库位是否为空库位
                LocMast shallowLoc = locMastService.selectById(shallowLocNo);
                if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
                    if (VersionUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) {
                        if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
                            locMast = shallowLoc;
                            crnNo = locMast.getCrnNo();
                            break;
                        }
                    }
                }
            }
        }
//        // 靠近摆放规则 --- 空托  //分离版
//        if (staDescId == 10 && Utils.BooleanWhsTypeStaIoType(whsType)) {
//            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("row1", nearRow).eq("loc_sts", "O"));
//            for (LocMast locMast1:locMasts){
//                if (VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
//                    continue;
//                }
//                String shallowLoc = Utils.getDeepLoc(slaveProperties,locMast1.getLocNo());
//                LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>().eq("loc_no",shallowLoc));
//                if (!Cools.isEmpty(locMast2) && locMast2.getLocSts().equals("D")){
//                    locMast = locMast1;
//                    break;
//                }
//            }
//        }
//        // 靠近摆放规则 --- 空托 //互通版
//        if (staDescId == 10 && Utils.BooleanWhsTypeStaIoType(rowLastno)) {
//            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
//                    .eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow).eq("whs_type", rowLastnoType.getType().longValue()));
//            if (!locMasts.isEmpty()) {
//                for (LocMast loc : locMasts) {
//                    if (Utils.isShallowLoc(slaveProperties, loc.getLocNo())) {
//                        continue;
//                    }
//                    String shallowLocNo = Utils.getShallowLoc(slaveProperties, loc.getLocNo());
//                    // 检测目标库位是否为空库位
//                    LocMast shallowLoc = locMastService.selectById(shallowLocNo);
//                    if (shallowLoc != null && shallowLoc.getLocSts().equals("O")) {
//                        if (VersionUtils.locMoveCheckLocTypeComplete(shallowLoc, locTypeDto)) {
//                            if (basCrnpService.checkSiteError(shallowLoc.getCrnNo(), true)) {
//                                locMast = shallowLoc;
//                                crnNo = locMast.getCrnNo();
//                                break;
//                            }
//                        }
//                    }
//                }
//            }
//        }
        Wrapper<StaDesc> wrapper = null;
        StaDesc staDesc = null;
        BasDevp staNo = null;
//        if (Utils.BooleanWhsTypeSta(rowLastno, staDescId)) {
//            // 获取目标站
//            wrapper = new EntityWrapper<StaDesc>()
//                    .eq("type_no", staDescId)
//                    .eq("stn_no", sourceStaNo)
//                    .eq("crn_no", crnNo);
//            staDesc = staDescService.selectOne(wrapper);
//            if (Cools.isEmpty(staDesc)) {
//                log.error("type_no={},stn_no={},crn_no={}", staDescId, sourceStaNo, crnNo);
////                throw new CoolException("入库路径不存在");
//                crnNo = 0;
//            } else {
//                staNo = basDevpService.selectById(staDesc.getCrnStn());
//                if (!staNo.getAutoing().equals("Y")) {
//                    log.error("目标站" + staDesc.getCrnStn() + "不可用");
////                throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
//                    crnNo = 0;
//                }
//                startupDto.setStaNo(staNo.getDevNo());
//            }
//            // 更新库位排号
//            if (Cools.isEmpty(locMast)) {
//                rowLastno.setCurrentRow(curRow);
//                rowLastnoService.updateById(rowLastno);
//            }
//        }
        // 开始查找库位 ==============================>>
        // 1.按规则查找库位
        if (Cools.isEmpty(locMast) && crnNo != 0) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("row1", nearRow)
                    .eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue())
                    .orderBy("lev1", true).orderBy("bay1", true));
            for (LocMast locMast1 : locMasts) {
                if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                    continue;
                }
                if (Utils.BooleanWhsTypeStaIoType(rowLastno)) {
                    String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo());
                    LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", shallowLoc).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()));
                    if (!Cools.isEmpty(locMast2)) {
                        locMast = locMast2;
                        break;
                    }
                } else {
                    if (!Cools.isEmpty(locMast1)) {
                        locMast = locMast1;
                        break;
                    }
                }
            }
            if (Cools.isEmpty(locMast) && Utils.BooleanWhsTypeStaIoType(rowLastno)) {
                for (LocMast locMast1 : locMasts) {
                    if (!VersionUtils.locMoveCheckLocTypeComplete(locMast1, locTypeDto)) {
                        continue;
                    }
                    if (Utils.BooleanWhsTypeStaIoType(rowLastno)) {
                        String shallowLoc = Utils.getDeepLoc(slaveProperties, locMast1.getLocNo());
                        LocMast locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                .eq("loc_no", shallowLoc).eq("loc_sts", "O").eq("whs_type", rowLastnoType.getType().longValue()));
                        if (!Cools.isEmpty(locMast2)) {
                            locMast = locMast2;
                            break;
                        } else {
                            locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                    .eq("loc_no", shallowLoc).eq("loc_sts", "F").eq("whs_type", rowLastnoType.getType().longValue()));
                            if (!Cools.isEmpty(locMast2)) {
                                locMast = locMast1;
                                break;
                            } else {
                                locMast2 = locMastService.selectOne(new EntityWrapper<LocMast>()
                                        .eq("loc_no", shallowLoc).eq("loc_sts", "D").eq("whs_type", rowLastnoType.getType().longValue()));
                                if (!Cools.isEmpty(locMast2)) {
                                    locMast = locMast1;
                                    break;
                                }
                            }
                        }
                    } else {
                        if (!Cools.isEmpty(locMast1)) {
                            locMast = locMast1;
                            break;
                        }
                    }
                }
            }
        }
        if (!Cools.isEmpty(locMast) && !basCrnpService.checkSiteError(crnNo, true)) {
            locMast = null;
        }
        // 递归查询
        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) {
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times < rowCount * 2) {
                times = times + 1;
                return getDoubleLocNoRun(whsType, 1, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times);
            }
//            // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位
//            if (locTypeDto.getLocType1() < 2) {
//                int i = locTypeDto.getLocType1() + 1;
//                locTypeDto.setLocType1((short)i);
//                return getLocNo(1, staDescId, sourceStaNo, matnr,batch,grade, locTypeDto, 0);
//            }
            log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
            throw new CoolException("没有空库位");
        }
        String locNo = locMast.getLocNo();
        // 生成工作号
        int workNo = getWorkNo(0);
        // 返回dto
        startupDto.setWorkNo(workNo);
        startupDto.setCrnNo(crnNo);
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setLocNo(locNo);
        return startupDto;
    }
    public StartupDto getLocNoRun4(Integer whsType, Integer staDescId, Integer sourceStaNo,
            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
                                   FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        // 初始化参数
        int crnNo = 0; // 堆垛机号
@@ -307,7 +594,7 @@
                    if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                            && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                            && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                        int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                        curRowW = locNecessaryParameters[1];
                        nearRowW = locNecessaryParameters[3];
@@ -380,7 +667,7 @@
                    if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                            && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                            && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                        int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                        curRowW = locNecessaryParameters[1];
                        nearRowW = locNecessaryParameters[3];
@@ -479,7 +766,7 @@
                    if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                            && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                            && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                        int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                        curRowW = locNecessaryParameters[1];
                        nearRowW = locNecessaryParameters[3];
@@ -560,7 +847,7 @@
                    if (!(Utils.getRow(locMastGro.getLocNo()) > nearRowW
                            && Utils.getRow(locMastGro.getLocNo()) <= curRowW)
                            && !(Utils.getRow(locMastGro.getLocNo()) < nearRowW
                                    && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                            && Utils.getRow(locMastGro.getLocNo()) >= curRowW)) {
                        int[] locNecessaryParameters = Utils.LocNecessaryParameters(rowLastno, curRowW, crnNumber);
                        curRowW = locNecessaryParameters[1];
                        nearRowW = locNecessaryParameters[3];
@@ -705,7 +992,7 @@
    }
    public StartupDto getLocNoRun5(Integer whsType, Integer staDescId, Integer sourceStaNo,
            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
                                   FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        // 初始化参数
        int crnNo = 0; // 堆垛机号