自动化立体仓库 - WMS系统
#
lfd
2025-03-06 d3234825d804a6a205dba1c6092acc8e29981b81
src/main/java/com/zy/common/service/CommonService.java
@@ -50,7 +50,7 @@
    /**
     * 生成工作号
     * @param wrkMk 0:入库 1 - 3000 ; 1:拣料/并板/盘点 3001 - 6000 ; 2: 出库 6001 -9000 ; 3:其他 9001 -9999
     * @param wrkMk
     * @return workNo(工作号)
     */
    public int getWorkNo(Integer wrkMk) {
@@ -97,10 +97,38 @@
     */
    @Transactional
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, int times) {
        whsType = getWhsType(sourceStaNo, times);
//        whsType = getWhsType(sourceStaNo, times);
        switch (sourceStaNo){
            case 101:
            case 109:
            case 117:
                whsType=1;  //1-8货架
                slaveProperties.setDoubleDeep(false);
                slaveProperties.setGroupCount(2);
                break;
            case 201:
                slaveProperties.setDoubleDeep(true);
                slaveProperties.setGroupCount(4);
                whsType=2;  //9-12货架
                break;
            case 207:
                whsType=3;  //13-14货架
                slaveProperties.setDoubleDeep(false);
                slaveProperties.setGroupCount(2);
                break;
            case 213:
                slaveProperties.setDoubleDeep(true);
                slaveProperties.setGroupCount(4);
                whsType=4;  //15-18货架
                break;
            default:
                throw new CoolException("根据入库站获取库位排号分配失败,入库站:" + sourceStaNo);
        }
        StartupDto startupDto = new StartupDto();
        // 生成工作号
        int workNo = getWorkNo(0);
        RowLastno rowLastno = rowLastnoService.selectById(whsType);
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员");
@@ -118,7 +146,7 @@
        LocMast locMast = null;
        // 靠近摆放规则 --- 同天同规格物料
        if (!Cools.isEmpty(matNos)) {
        if (!Cools.isEmpty(matNos) && (whsType==2 || whsType==4)) {
            List<String> locNos = locDetlService.getSameDetlToday(matNos.get(0), sRow, eRow);
            for (String locNo : locNos) {
                if (Utils.isShallowLoc(slaveProperties, locNo)) {
@@ -140,7 +168,7 @@
        }
        // 靠近摆放规则 --- 空托
        if (staDescId == 10) {
        if (staDescId == 10  && (whsType==2 || whsType==4)) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>().eq("loc_sts", "D").ge("row1", sRow).le("row1", eRow));
            if (locMasts.size() > 0) {
                for (LocMast loc : locMasts) {
@@ -162,40 +190,46 @@
        }
        // 如果没有相近物料,则按规则轮询货架
        if (null == locMast) {
            Shelves shelves = new Shelves(rowCount, crn_qty);
            if (whsType != 4) {
                int divides = (int) Arith.divides(1, curRow - 1, 16);
                curRow = (int) Arith.remainder(curRow, 16);
                if (curRow == 0) {
                    curRow = 16;
                }
                for (int i = 0; i < shelves.group; i ++) {
                    curRow = shelves.start(curRow);
                    if (curRow < 0) {
                        throw new CoolException("检索库位失败,请联系管理员");
                    }
                    Integer crnNo1 = shelves.get(curRow);
                    crnNo1 = crnNo1 + divides*4;
                    if (basCrnpService.checkSiteError(crnNo1, true)) {
                        crnNo = crnNo1;
                        break;
                    }
                }
            } else {
                for (int i = 0; i < shelves.group; i ++) {
                    curRow = shelves.start(curRow);
                    if (curRow < 0) {
                        throw new CoolException("检索库位失败,请联系管理员");
                    }
                    Integer crnNo1 = shelves.get(curRow);
                    if (basCrnpService.checkSiteError(crnNo1, true)) {
                        crnNo = crnNo1;
                        break;
                    }
                }
        if (null == locMast){
            curRow = getCurRow(curRow);
            if (curRow == 0){
                crnNo = 0;
            }else if( curRow <= 8 && curRow > 0){
                crnNo=(curRow+1)/2;
            }else if (curRow <= 12 && curRow >= 9){
                crnNo=5;
            }else if (curRow <= 14 && curRow >= 13){
                crnNo=6;
            }else if (curRow <= 18 && curRow >= 15){
                crnNo=7;
            }
            if (curRow!=0 && !basCrnpService.checkSiteError(crnNo, true)) {
                crnNo = 0;
            }
        }
//        // 如果没有相近物料,则按规则轮询货架
//        if (null == locMast) {
//            Shelves shelves = new Shelves(rowCount, crn_qty);
//            int divides = (int) Arith.divides(1, curRow - 1, 4);
//            curRow = (int) Arith.remainder(curRow, 4);
//            if (curRow == 0) {
//                curRow = 4;
//            }
//            for (int i = 0; i < shelves.group; i ++) {
//                curRow = shelves.start(curRow);
//                if (curRow < 0) {
//                    throw new CoolException("检索库位失败,请联系管理员");
//                }
//                Integer crnNo1 = shelves.get(curRow);
//                crnNo1 = crnNo1 + divides*1;
//                if (basCrnpService.checkSiteError(crnNo1, true)) {
//                    crnNo = crnNo1;
//                    curRow = curRow + divides*4;
//                    break;
//                }
//            }
//        }
        if (crnNo == 0) {
            throw new CoolException("没有可用的堆垛机");
@@ -214,6 +248,7 @@
        if (!staNo.getAutoing().equals("Y")) {
            throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
        }
        // 更新库位排号
        rowLastno.setCurrentRow(curRow);
        rowLastnoService.updateById(rowLastno);
@@ -222,7 +257,7 @@
        // 1.当检索库排为浅库位排时,优先寻找当前库排的深库位排
        if (locMast == null) {
            if (Utils.isShallowLoc(slaveProperties, curRow)) {
            if ((whsType==2 || whsType==4) && Utils.isShallowLoc(slaveProperties, curRow)) {
                Integer deepRow = Utils.getDeepRow(slaveProperties, curRow);
                locMast = locMastService.queryFreeLocMast(deepRow, locTypeDto.getLocType1());
                // todo:luxiaotao 如果用浅排找到的深库位,那么则需要判断这个深库位对应的浅库位是否有货(F、X、D)
@@ -238,17 +273,61 @@
                    locMast = null;
                }
                // 目标库位 ===>> 浅库位, 则校验其深库位是否为 F D X
                if (null != locMast && Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) {
                if ((whsType==2 || whsType==4) && null != locMast && Utils.isShallowLoc(slaveProperties, locMast.getLocNo())) {
                    LocMast deepLoc = locMastService.selectById(Utils.getDeepLoc(slaveProperties, locMast.getLocNo()));
                    if (!deepLoc.getLocSts().equals("F") && !deepLoc.getLocSts().equals("D") && !deepLoc.getLocSts().equals("X")) {
                        locMast = null;
                    }
                }
                // 目标库位 ===>> 深库位, 则校验其浅库位是否为 O
                if (null != locMast && Utils.isDeepLoc(slaveProperties, locMast.getLocNo())) {
                if ((whsType==2 || whsType==4) && null != locMast && Utils.isDeepLoc(slaveProperties, locMast.getLocNo())) {
                    LocMast shallowLoc = locMastService.selectById(Utils.getShallowLoc(slaveProperties, locMast.getLocNo()));
                    if (!shallowLoc.getLocSts().equals("O")) {
                        locMast = null;
                    }
                }
            }
        }
        //20230203添加  lfd料箱库根据输送线筛选入库
        if (!Cools.isEmpty(locMast) && locMast.getCrnNo()<5){
            int wrkMastsC0 = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", locMast.getCrnNo()).eq("io_type",1));
            if (wrkMastsC0>3 && times < rowCount){
                int locO1 = locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", "O").eq("crn_no", 1));
                BasCrnp basCrnp1 = basCrnpService.selectById(1);
                if (!Cools.isEmpty(locO1) && basCrnp1.getInEnable().equals("Y") && basCrnp1.getCrnSts().equals(3)){
                    int wrkMastsC1 = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", 1).eq("io_type",1));
                    if (wrkMastsC0>wrkMastsC1){
                        locMast=null;
                    }
                }
                if (!Cools.isEmpty(locMast)){
                    locO1=locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", "O").eq("crn_no", 2));
                    BasCrnp basCrnp2 = basCrnpService.selectById(2);
                    if (!Cools.isEmpty(locO1) && basCrnp2.getInEnable().equals("Y") && basCrnp2.getCrnSts().equals(3)){
                        int wrkMastsC2 = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", 2).eq("io_type",1));
                        if (wrkMastsC0>wrkMastsC2){
                            locMast=null;
                        }
                    }
                }
                if (!Cools.isEmpty(locMast)){
                    locO1=locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", "O").eq("crn_no", 2));
                    BasCrnp basCrnp3 = basCrnpService.selectById(3);
                    if (!Cools.isEmpty(locO1) && basCrnp3.getInEnable().equals("Y") && basCrnp3.getCrnSts().equals(3)){
                        int wrkMastsC3 = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", 3).eq("io_type",1));
                        if (wrkMastsC0>wrkMastsC3){
                            locMast=null;
                        }
                    }
                }
                if (!Cools.isEmpty(locMast)){
                    locO1=locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", "O").eq("crn_no", 2));
                    BasCrnp basCrnp4 = basCrnpService.selectById(4);
                    if (!Cools.isEmpty(locO1) && basCrnp4.getInEnable().equals("Y") && basCrnp4.getCrnSts().equals(3)){
                        int wrkMastsC4 = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", 4).eq("io_type",1));
                        if (wrkMastsC0>wrkMastsC4){
                            locMast=null;
                        }
                    }
                }
            }
@@ -262,16 +341,28 @@
                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, times);
            }
            // 轻货物找轻库位为空时,可以去找重库位仓
            if (locTypeDto.getLocType1() == 1) {
                locTypeDto.setLocType1((short) 2);
//            // 轻货物找轻库位为空时,可以去找重库位仓
//            if (locTypeDto.getLocType1() == 1) {
//                locTypeDto.setLocType1((short) 2);
//                return getLocNo(1, staDescId, source2StaNo, matNos, locTypeDto, times);
//            }
            if ((times < rowCount+2) && (whsType==2 || whsType==4)) {
                times = times + 1;
                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, times);
            }
            log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
            throw new CoolException("没有空库位");
        }
        String locNo = locMast.getLocNo();
        if (crnNo==5 || crnNo==7){
            int i = locMastService.selectCount(new EntityWrapper<LocMast>().eq("loc_sts", "O").eq("crn_no", crnNo));
            if (i<=10){
                throw new CoolException("空库位数小于等于10个,禁止入库");
            }
        }
        // 生成工作号
        int workNo = getWorkNo(0);
        // 返回dto
        startupDto.setWorkNo(workNo);
        startupDto.setCrnNo(crnNo);
@@ -299,31 +390,54 @@
    /**
     * 根据入库站获取库位排号分配
     */
    private Integer getWhsType(Integer sourceStaNo, int times) {
        if (times >= 16) {
            return 4;
    private Integer getCurRow(Integer curRow) {
        boolean sign=false;
        int count=0;
        while (!sign){
            count=count+1;
            if (count==5){
                return 0;
            }
            switch (curRow){
                case 1:
                case 3:
                case 5:
                case 2:
                case 4:
                case 6:
                    curRow=curRow+2;
                    break;
                case 7:
                    curRow=2;
                    break;
                case 8:
                    curRow=1;
                    break;
                case 13:
                    return 14;
                case 14:
                    return 13;
                case 9:
                    return 12;
                case 10:
                    return 11;
                case 11:
                    return 9;
                case 12:
                    return 10;
                case 15:
                    return 18;
                case 16:
                    return 17;
                case 17:
                    return 15;
                case 18:
                    return 16;
                default:
                    throw new CoolException("库位排号异常:排号:"+curRow);
            }
            sign = basCrnpService.checkSiteError((curRow+1)/2, true);
        }
        switch (sourceStaNo) {
            case 173:
            case 176:
            case 180:
            case 185:
                return 1;
            case 189:
            case 194:
            case 198:
            case 202:
                return 2;
            case 206:
//            case 211:
//            case 215:
//            case 219:
//            case 223:
            case 227:
                return 3;
            default:
                throw new CoolException("根据入库站获取库位排号分配失败,入库站:" + sourceStaNo);
        }
        return curRow;
    }
}