自动化立体仓库 - WMS系统
#
lsh
2024-06-20 bf22f0953d5a2e699b6a69dc4b6bfab8ec0a7c7d
src/main/java/com/zy/common/service/CommonService.java
@@ -139,9 +139,9 @@
                    log.error("站点={} 未查询到对应的规则",sourceStaNo);
                    break;
                case 4:
                    return getLocNoRun2(whsType,staDescId,sourceStaNo,matnr,batch,grade,4,locTypeDto,0);
                    return getLocNoRun4(whsType,staDescId,sourceStaNo,matnr,batch,grade,4,locTypeDto,0);
                case 5:
                    return getLocNoRun2(whsType,staDescId,sourceStaNo,matnr,batch,grade,3,locTypeDto,0);
                    return getLocNoRun5(whsType,staDescId,sourceStaNo,matnr,batch,grade,0,locTypeDto,0);
                default:
                    log.error("站点={} 未查询到对应的规则",sourceStaNo);
                    break;
@@ -462,7 +462,7 @@
        return startupDto;
    }
    public StartupDto getLocNoRun2(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
    public StartupDto getLocNoRun4(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        if (Cools.isEmpty(matnr)) {  //物料号
            matnr = "";
        }
@@ -847,16 +847,12 @@
//            }
        }
        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 getLocNoRun(whsType, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times);
                return getLocNoRun4(whsType, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times);
            }
//            // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位
//            if (locTypeDto.getLocType1() < 2) {
@@ -878,6 +874,137 @@
        startupDto.setLocNo(locNo);
        return startupDto;
    }
    public StartupDto getLocNoRun5(Integer whsType, Integer staDescId, Integer sourceStaNo, String matnr, String batch, String grade, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        if (Cools.isEmpty(matnr)) {  //物料号
            matnr = "";
        }
        if (Cools.isEmpty(batch)) {  //批次
            batch = "";
        }
        if (Cools.isEmpty(grade)) {  //备用
            grade = "";
        }
        // 初始化参数
        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 = eRow-sRow+1;
        // ===============>>>> 开始执行
        curRow = rowLastno.getCurrentRow();
        if (!Cools.isEmpty(moveCrnNo) && moveCrnNo!=0){
            crnNumber = moveCrnNo;
        }
        //此程序用于优化堆垛机异常时的运行时间
        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];
                break;
            } else {
                times++;
            }
        }
        if (crnNo == 0) {
            throw new CoolException("无可用库位");
        }
        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 (Utils.BooleanWhsTypeSta(rowLastno, staDescId) && 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)){
                    //获取目标库位所在巷道最深空库位
                    LocMast locMast2 = locMastService.selectLocByLocStsPakInO(curRow,nearRow,locMast1,rowLastnoType.getType().longValue());
                    if (!Cools.isEmpty(locMast2) && locMast2.getBay1()==curRow) {
                        locMast = locMast2;
                        break;
                    }
                }
            }
        }
        // 递归查询
        if (Cools.isEmpty(locMast) || !locMast.getLocSts().equals("O")) {
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times < rowCount*2) {
                times = times + 1;
                return getLocNoRun5(whsType, staDescId, sourceStaNo, matnr, batch, grade,moveCrnNo, locTypeDto, times);
            }
            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 static String zerofill(String msg, Integer count) {
        if (msg.length() == count) {