自动化立体仓库 - WMS系统
#
LSH
2023-03-27 dca272efbaf315859decfcd339b39f9f647fffad
src/main/java/com/zy/common/service/CommonService.java
@@ -10,7 +10,6 @@
import com.zy.asrs.utils.Utils;
import com.zy.asrs.utils.VersionUtils;
import com.zy.common.model.LocTypeDto;
import com.zy.common.model.Shelves;
import com.zy.common.model.StartupDto;
import com.zy.common.properties.SlaveProperties;
import lombok.extern.slf4j.Slf4j;
@@ -29,13 +28,18 @@
public class CommonService {
    public static final List<Integer> FIRST_GROUP_ROW_LIST = new ArrayList<Integer>() {{
        add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);
        add(11);add(12);add(13);add(14);add(15);add(16);add(17);
        add(1);add(2);add(3);add(4);add(5);add(6);add(7);add(8);add(9);add(10);
    }};
    public static final List<Integer> FIRST_GROUP_ROW_LIST_SHORT = new ArrayList<Integer>() {{
        add(8);add(9);add(10);
    }};
    public static final List<Integer> SECOND_GROUP_ROW_LIST = new ArrayList<Integer>() {{
        add(18);add(19);add(20);
        add(21);add(22);add(23);add(24);add(25);add(26);add(27);add(28);add(29);add(30);
        add(12);add(13);add(14);add(15);add(16);add(17);add(18);
    }};
    public static final List<Integer> THIRD_GROUP_ROW_LIST = new ArrayList<Integer>() {{
        add(20);add(21);add(22);add(23);
    }};
    @Autowired
    private WrkMastService wrkMastService;
@@ -97,64 +101,46 @@
    }
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, int times) {
        LocTypeDto oldLocType = locTypeDto.clone();
        return getLocNo(whsType, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
        return getLocNo(staDescId, sourceStaNo, matNos, locTypeDto, times);
    }
    /**
     * 检索库位号
     * @param whsType 类型 1:双深式货架
     * @param staDescId 路径ID
     * @param sourceStaNo 源站
     * @param matNos 物料号集合
     * @return locNo 检索到的库位号
     */
    public StartupDto getLocNo(Integer whsType, Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto, LocTypeDto oldLocType, int times) {
    public StartupDto getLocNo(Integer staDescId, Integer sourceStaNo, List<String> matNos, LocTypeDto locTypeDto,int times) {
        StartupDto startupDto = new StartupDto();
        int start;
        int end;
        switch (sourceStaNo) {
            case 103:
                whsType = 1;
                start = 1;
                end = 14;
                break;
            case 203:
                whsType = 2;
                start = 8;
                end = 21;
                break;
            default:
                throw new CoolException("检索库位失败,请联系管理员");
        }
        // 生成工作号
        int workNo = getWorkNo(0);
        RowLastno rowLastno = rowLastnoService.selectById(whsType);
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员");
        }
        int curRow = rowLastno.getCurrentRow();  // 当前列
        int sRow = rowLastno.getsRow();          // 起始列
        int eRow = rowLastno.geteRow();          // 终止列
        int crn_qty = rowLastno.getCrnQty();     // 堆垛机数量(巷道数量)
        int rowCount = eRow - sRow + 1;          // 库排总数
        // 目标堆垛机号
        int crnNo = 0;
        // 目标库位
        LocMast locMast = null;
        // 靠近摆放规则 --- 同天同规格物料
        if (!Cools.isEmpty(matNos)) {
            List<String> locNos = locDetlService.getSameDetl(matNos.get(0), start, end);
            for (String locNo : locNos) {
                List<String> groupLoc = Utils.getGroupLoc(locNo);
                locMast = locMastService.findOutMost(groupLoc);
                if (null != locMast) {
        // 靠近摆放规则 --- 相同订单号, 同天同规格物料
        if (!Cools.isEmpty(matNos) && matNos.size() == 1 && staDescId == 1) {
            //先判断工作档,查找主档IOType=1, wrkSts < 10的工作明细,料号相同的明细库位
            List<WrkMast> wrkMasts = wrkMastService.selectSameMatnrs(matNos.get(0));
            for (WrkMast wrkMast : wrkMasts) {
                LocMast locMast0 = locMastService.findNearloc(wrkMast.getLocNo());
                if (null != locMast0) {
                    // 浅库位符合尺寸检测
                    if (VersionUtils.locMoveCheckLocType(locMast, locTypeDto)) {
                        // 浅库位对应堆垛机必须可用且无异常
                        if (basCrnpService.checkSiteError(locMast.getCrnNo(), true)) {
                            crnNo = locMast.getCrnNo();
                    if (VersionUtils.locMoveCheckLocType(locMast0, locTypeDto)) {
                        locMast = locMast0;
                        break;
                    }
                }
            }
            if (Cools.isEmpty(locMast)) {
                //再判断库存明细档,料号相同的明细库位
                List<String> locNos = locDetlService.getSameDetl(matNos.get(0));
                for (String locNo : locNos) {
                    LocMast locMast0 = locMastService.findNearloc(locNo);
                    if (null != locMast0) {
                        // 浅库位符合尺寸检测
                        if (VersionUtils.locMoveCheckLocType(locMast0, locTypeDto)) {
                            locMast = locMast0;
                            break;
                        }
                    }
@@ -162,22 +148,20 @@
            }
        }
        // 靠近摆放规则 --- 空托
        if (staDescId == 10) {
            List<LocMast> locMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("loc_sts", "D").ge("row1", start).le("row1", end));
                    .eq("loc_sts", "D"));
            if (locMasts.size() > 0) {
                for (LocMast loc : locMasts) {
                    List<String> groupLoc = Utils.getGroupLoc(loc.getLocNo());
                    locMast = locMastService.findOutMost(groupLoc);
                    if (null != locMast) {
                    LocMast locMast0 = locMastService.findNearloc(loc.getLocNo());
                    if (null != locMast0) {
                        // 浅库位符合尺寸检测
                        if (VersionUtils.locMoveCheckLocType(locMast, locTypeDto)) {
                            // 浅库位对应堆垛机必须可用且无异常
                            if (basCrnpService.checkSiteError(locMast.getCrnNo(), true)) {
                                crnNo = locMast.getCrnNo();
                                break;
                            }
                        if (VersionUtils.locMoveCheckLocType(locMast0, locTypeDto)) {
                            locMast = locMast0;
                            break;
                        }
                    }
                }
@@ -185,146 +169,70 @@
        }
        // 如果没有相近物料,则按规则轮询货架
        int currentRow = 1;
        if (null == locMast) {
            Shelves shelves = new Shelves(rowCount, crn_qty);
            for (int i = 0; i < shelves.group; i ++) {
                curRow = shelves.start(curRow);
                if (curRow < 0) {
                    throw new CoolException("检索库位失败,请联系管理员");
                }
                currentRow = curRow;
                int crnNo1 = shelves.get(curRow);
                if (whsType == 1) {
                    switch (curRow) {
                        case 1:
                            curRow = 1;
                            break;
                        case 2:
                            curRow = 7;
                            break;
                        case 3:
                            curRow = 8;
                            break;
                        case 4:
                            curRow = 14;
                            break;
                        default:
                            throw new CoolException("检索库位失败,请联系管理员");
                    }
                } else {
                    switch (curRow) {
                        case 1:
                            curRow = 8;
                            break;
                        case 2:
                            curRow = 14;
                            break;
                        case 3:
                            curRow = 15;
                            break;
                        case 4:
                            curRow = 21;
                            break;
                        default:
                            throw new CoolException("检索库位失败,请联系管理员");
                    }
                    crnNo1 = crnNo1 + 1;
                }
                if (basCrnpService.checkSiteError(crnNo1, true)) {
                    crnNo = crnNo1;
                    break;
                }
            }
        }
        if (crnNo == 0) {
            throw new CoolException("没有可用的堆垛机");
        }
        // 获取目标站
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
                .eq("type_no", staDescId)
                .eq("stn_no", sourceStaNo)
                .eq("crn_no", crnNo);
                .eq("stn_no", sourceStaNo);
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            log.error("入库路径不存在, staDescId={}, sourceStaNo={}, crnNo={}", staDescId, sourceStaNo, crnNo);
            log.error("入库路径不存在, staDescId={}, sourceStaNo={}", staDescId, sourceStaNo);
            throw new CoolException("入库路径不存在");
        }
        // 检测目标站
        BasDevp staNo = basDevpService.selectById(staDesc.getCrnStn());
        if (!staNo.getAutoing().equals("Y")) {
            throw new CoolException("目标站"+staDesc.getCrnStn()+"不可用");
            throw new CoolException("目标站" + staDesc.getCrnStn() + "不可用");
        }
        // 更新库位排号
        rowLastno.setCurrentRow(currentRow);
        rowLastnoService.updateById(rowLastno);
        // 开始查找库位 ==============================>>
        // 1.当检索库排为浅库位排时,优先寻找当前库排的深库位排
        if (locMast == null) {
            List<Integer> rows = Utils.getGroupLoc(curRow);
            List<LocMast> locMasts = locMastService.queryFreeLocMast(rows, rows.size(), locTypeDto.getLocType1());
            if (!Cools.isEmpty(locMasts)) {
                Integer innermostRow = Utils.getInnermostRow(locMasts.get(0).getLocNo());
                for (LocMast one : locMasts) {
                    if (one.getRow1().equals(innermostRow)) {
                        locMast = one;
                        break;
                    }
            List<LocMast> peakLocs = locMastService.selectAllPeakLoc();
            for (LocMast peakLoc : peakLocs) {
                List<String> groupInsideLoc = Utils.getGroupInsideLoc(peakLoc.getLocNo());
                if (!Cools.isEmpty(groupInsideLoc)){
                    if (!locMastService.checkAllLocEmpty(groupInsideLoc)) continue;
                    locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", groupInsideLoc.get(0)));
                    break;
                }else {
                    locMast=peakLoc;
                    break;
                }
            }
            // 因库位移转、需预留空库位
//            if (!locMastService.checkEmptyCount(locMast)) {
//                locMast = null;
//            }
        }
        // 2.库位当前所属尺寸无空库位时,调整尺寸参数,向上兼容检索库位
        if (Cools.isEmpty(locMast)) {
            // 当前巷道无空库位时,递归调整至下一巷道,检索全部巷道无果后,跳出递归
            if (times < rowCount) {
                times = times + 1;
                return getLocNo(whsType, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
            } else {
                times = 0;
            List<LocMast> peakLocs = locMastService.selectAllPeakLoc();
            for (LocMast peakLoc : peakLocs) {
                List<String> groupOuterLoc = Utils.getGroupInsideLoc(peakLoc.getLocNo());
                if (!Cools.isEmpty(groupOuterLoc)){
                    if (!locMastService.checkAllLocEmpty(groupOuterLoc)) continue;
                    locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", groupOuterLoc.get(0)));
                }else {
                    locMast = peakLoc;
                }
            }
            // 货物检索低库位仓失败,兼容高库位仓后继续执行
            if (locTypeDto.getLocType1() == 1) {
                locTypeDto.setLocType1((short) 2);
                return getLocNo(1, staDescId, sourceStaNo, matNos, locTypeDto, oldLocType, times);
            if (Cools.isEmpty(locMast)) {
                log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
                throw new CoolException("没有空库位");
            }
            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.setStaNo(staNo.getDevNo());
        startupDto.setLocNo(locNo);
        return startupDto;
    }
    public static String zerofill(String msg, Integer count) {
        if (msg.length() == count) {
            return msg;
        } else if (msg.length() > count) {
            return msg.substring(0, 16);
        } else {
            StringBuilder msgBuilder = new StringBuilder(msg);
            for(int i = 0; i < count - msg.length(); ++i) {
                msgBuilder.insert(0, "0");
            }
            return msgBuilder.toString();
        }
    }
}