自动化立体仓库 - WMS系统
zyx
2023-12-04 20a1449f65a9d577c2c9c0af62f3c4af3dd8d172
src/main/java/com/zy/common/service/CommonService.java
@@ -144,6 +144,13 @@
            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
        }
        //存货分类编码规则
        locMast = getLocNoCodeStepRule(matNos, locTypeDto);
        if (locMast != null) {
            //找到库位,返回dto
            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
        }
        // 靠近摆放规则 --- 相同订单号, 同天同规格物料
        locMast = getLocNoStep3(staDescId, matNos, locTypeDto);
        if (locMast != null) {
@@ -164,7 +171,13 @@
            //找到库位,返回dto
            return getLocNoStep6(staDescId, sourceStaNo, locMast);//返回dto
        }
        if(locTypeDto.getLocType1()==1){
            locTypeDto.setLocType1((short)2);
            return getLocNo(staDescId, 1, sourceStaNo, matNos, locTypeDto,0);
        }else if(locTypeDto.getLocType1()==2){
            locTypeDto.setLocType1((short)3);
            return getLocNo(staDescId, 1, sourceStaNo, matNos, locTypeDto,0);
        }
        //找不到库位,抛出异常
        throw new CoolException("没有空库位");
    }
@@ -189,12 +202,8 @@
                }
                List<LocMast> locMasts = locMastService.queryFreeLocMast2(locTypeDto.getLocType1(), locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd());
                for (LocMast locMast0 : locMasts) {
                    //预留空库位
                    if (locMastService.checkEmptyCount(locMast0, 10)) {
                        return locMast0;
                    }
                }
                locMast = locFilter(locMasts, matNos,locTypeDto);
            }
            if (locRules.get(0).getKeepGo() == 0) {
@@ -203,6 +212,46 @@
                throw new CoolException("规则区域没有空库位");
            }
        }
        return locMast;
    }
    /**
     * 库位编码规则
     */
    private LocMast getLocNoCodeStepRule(List<String> matNos, LocTypeDto locTypeDto) {
        LocMast locMast = null;
        //库位编码规则只能在相同编码货物中生效
        String matnr = "";
        for(String matNo : matNos){
            if("".equals(matnr)){
                matnr = matNo.substring(0, 4);
            }
            if(!matnr.equals(matNo.substring(0, 4))){
                return null;
            }
        }
        // 库区锁定
        List<LocRule> locRules = locRuleService.findCode(Cools.isEmpty(matNos) ? null : matNos.get(0),null);
        if (locRules == null || locRules.isEmpty()) {
            return null;//没有库位规则,跳出当前任务
        }
        for (LocRule locRule : locRules) {
            if (locRule == null) {
                continue;
            }
            List<LocMast> locMasts = locMastService.queryFreeLocMast2(locTypeDto.getLocType1(), locRule.getRowBeg(), locRule.getRowEnd(), locRule.getBayBeg(), locRule.getBayEnd(), locRule.getLevBeg(), locRule.getLevEnd());
            locMast = locFilter(locMasts, matNos,locTypeDto);
        }
//            if (locRules.get(0).getKeepGo() == 0) {
//                //找不到空库位,且禁止继续寻找其他非混载区域库位
//                //找不到库位,抛出异常
//                throw new CoolException("规则区域没有空库位");
//            }
        return locMast;
    }
@@ -226,7 +275,7 @@
                //再判断库存明细档,料号相同的明细库位
                List<String> locNos = locDetlService.getSameDetl(matNos.get(0));
                for (String locNo : locNos) {
                    LocMast locMast0 = locMastService.findNearloc(locNo);
                    LocMast locMast0 = locMastService.findInnerLoc(locNo);
                    if (null != locMast0) {
                        // 浅库位符合尺寸检测
                        if (VersionUtils.checkLocType(locMast0, locTypeDto)) {
@@ -310,6 +359,7 @@
        if (matNos.size() == 1) {
            //单品
            List<LocMast> locMasts = locMastService.selectAreaEmpty(locTypeDto.getLocType1(), 2);//搜索单品库位
            for (LocMast mast : locMasts) {
                List<String> groupLoc = Utils.getGroupLoc(mast.getLocNo());
                if (!locMastService.checkAllLocEmpty(groupLoc)) {
@@ -337,11 +387,82 @@
                    break;
                }
            }
            if (locMast == null) {
                //单品找不到库位,允许尝试从混放区域中进行搜索
                List<LocMast> locMasts2 = locMastService.selectAreaEmpty(locTypeDto.getLocType1(), 1);//搜索单品库位
                //混放区域直接取第一个即可
                for (LocMast mast : locMasts2) {
                    //预留空库位
                    if (locMastService.checkEmptyCount(mast, 10)) {
                        locMast = mast;
                        break;
                    }
                }
            }
        }
        return locMast;
    }
    /*
    库存规则搜索到的库位确认
     */
    private LocMast locFilter(List<LocMast> locMasts,List<String> matNos,LocTypeDto locTypeDto){
        for (LocMast locMast0 : locMasts) {
            if(!VersionUtils.checkLocType(locMast0,locTypeDto)){
                continue;
            }
            if (matNos.size() == 1) {
                //单品物料
                if(Cools.isEmpty(Utils.getGroupDeepLoc(locMast0.getLocNo()))){
                    return locMast0;
                }else{
                    List<String> groupInnerLoc = Utils.getGroupInnerLoc(locMast0.getLocNo());
                    if (Cools.isEmpty(groupInnerLoc)) {
                        return locMast0;
                    }else {
                        //获取最深的库位
                        String loc = groupInnerLoc.get(groupInnerLoc.size() - 1);
                        LocMast locMast1 = locMastService.selectByLoc(loc);
                        if("O".equals(locMast1.getLocSts())){
                            return locMast1;
                        }else {
                            if(!"F".equals(locMast1.getLocSts())){
                                continue;
                            }
                            List<LocDetl> locDetls = locDetlService.selectByLocNo(loc);
                            if(!Cools.eq(locDetls.get(0).getMatnr(),matNos.get(0))){
                                continue;
                            }
                            for (int i=groupInnerLoc.size()-1; i>=0 ;i--){
                                LocMast locMast2 = locMastService.selectByLoc(groupInnerLoc.get(i));
                                if("O".equals(locMast2.getLocSts())){
                                    return locMast2;
                                }else if("F".equals(locMast2.getLocSts())){
                                    if(i==0){
                                        return locMast1;
                                    }else {
                                        continue;
                                    }
                                }else {
                                    break;
                                }
                            }
                        }
                    }
                }
            }else {
                if(Cools.isEmpty(Utils.getGroupDeepLoc(locMast0.getLocNo()))){
                    return locMast0;
                }
            }
        }
        return null;
    }
    //返回dto
    private StartupDto getLocNoStep6(Integer staDescId, Integer sourceStaNo, LocMast locMast) {
        StartupDto startupDto = new StartupDto();