自动化立体仓库 - WMS系统
skyouc
3 天以前 6efbf154b3ed88d376763b9d9807256c7bd5eaeb
src/main/java/com/zy/common/service/CommonService.java
@@ -122,40 +122,112 @@
    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);
        }
        return null;
    }
    /**
     * 检索库位号
     *
     * @param whsType              类型 1:单伸式货架
     * @param staDescId            路径ID
     * @param sourceStaNo          源站
     * @param findLocNoAttributeVo 属性
     * @param moveCrnNo            源
     * @param locTypeDto           类型
     * @param times                轮询次数
     * @return locNo 检索到的库位号
     */
    @Transactional
    public StartupDto getLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo,
                                  FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        staDescId = 1;
        // 初始化参数
        int crnNo = 0; // 堆垛机号
        int nearRow = 0; // 最浅库位排
        LocMast locMast = null; // 目标库位
        RowLastno rowLastno = rowLastnoService.selectById(whsType);
        if (Cools.isEmpty(rowLastno)) {
            throw new CoolException("数据异常,请联系管理员===>库位规则未知");
        }
        int minCount = Integer.MAX_VALUE;
        if (whsType == 2) {
            if (locTypeDto.getLocType1() == 2) {
                // 均衡分布堆垛机
                for (int i = 4; i <= 5; i++) {
                    int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
                    if (count < minCount) {
                        minCount = count;
                        crnNo = i;
                    }
                }
            } else {
                for (int i = 4; i <= 6; i++) {
                    int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
                    if (count < minCount) {
                        minCount = count;
                        crnNo = 6;
                    }
                }
                if (crnNo == 6) {
                    return getDoubleLocNoRun(3, 1, sourceStaNo, findLocNoAttributeVo, null, locTypeDto, times);
                }
            }
        } else {
            // 均衡分布堆垛机
            for (int i = rowLastno.getsCrnNo(); i <= rowLastno.geteCrnNo(); i++) {
                int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
                if (count < minCount) {
                    minCount = count;
                    crnNo = i;
                }
            }
        }
        StartupDto startupDto = new StartupDto();
        locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                .ge("row1", rowLastno.getsRow())
                .le("row1", rowLastno.geteRow())
                .eq("crn_no", crnNo)
                .eq("loc_type1", locTypeDto.getLocType1())
                .eq("loc_sts", "O")
                .orderAsc(Arrays.asList("lev1", "row1", "bay1")));
        // int crnCountO = wrkMastService.selectCount(new
        // EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100));
        // 生成工作号
        int workNo;
        if (whsType == 2) {
            // 生成工作号
            workNo = getWorkNo(3);
        } else {
            // 生成工作号
            workNo = getWorkNo(0);
        }
        // 返回dto
        startupDto.setWorkNo(workNo);
        startupDto.setCrnNo(locMast.getCrnNo());
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setLocNo(locMast.getLocNo());
        return startupDto;
    }
    /**
     * 检索库位号
@@ -169,52 +241,121 @@
     * @param times                轮询次数
     * @return locNo 检索到的库位号
     */
    @Transactional
    public StartupDto getLocNoRun( Integer staDescId, Integer whsType, Integer sourceStaNo,
            FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        staDescId = 1;
        // 初始化参数
        int crnNo = 0; // 堆垛机号
        int nearRow = 0; // 最浅库位排
        LocMast locMast = null; // 目标库位
    public StartupDto getDoubleLocNoRun(Integer whsType, Integer staDescId, Integer sourceStaNo, FindLocNoAttributeVo findLocNoAttributeVo, Integer moveCrnNo, LocTypeDto locTypeDto, int times) {
        // 1. 初始化参数
        int crnNo = 6;      // 堆垛机号
        int deepRow, shallowRow;
        int rowCount = 2;   // 轮询两组货架 (11/12 对 和 14/13 对)
        // 根据轮询次数切换排,严格保证深位优先
        if (times % 2 == 0) {
            deepRow = 11;
            shallowRow = 12;
        } else {
            deepRow = 14;
            shallowRow = 13;
        }
        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 minCount = Integer.MAX_VALUE;
        for (int i = rowLastno.getsCrnNo(); i <= rowLastno.geteCrnNo(); i++) {
            int count = wrkMastService.selectCount(new EntityWrapper<WrkMast>().eq("crn_no", i));
            if (count < minCount) {
                minCount = count;
                crnNo = i;
        LocMast locMast = null;
        // 2. 开始检索 (优先级:深位堆叠 > 深位空位 > 浅位空位)
        // A. 优先尝试:深位为空,且其对应的浅位已经存放了相同物料 (实现 signRule1 的核心逻辑)
        if (Utils.BooleanWhsTypeStaIoType(rowLastno) && !Cools.isEmpty(findLocNoAttributeVo.getMatnr())) {
            List<LocMast> shallowMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("row1", shallowRow)
                    .eq("loc_sts", "F")
                    .eq("crn_no", crnNo));
            for (LocMast sLoc : shallowMasts) {
                LocDetl detl = locDetlService.selectOne(new EntityWrapper<LocDetl>().eq("loc_no", sLoc.getLocNo()));
                if (detl != null && detl.getMatnr().equals(findLocNoAttributeVo.getMatnr())
                        && detl.getBatch().equals(findLocNoAttributeVo.getBatch())) {
                    String dLocNo = Utils.getDeepLoc(slaveProperties, sLoc.getLocNo());
                    LocMast dLoc = locMastService.selectOne(new EntityWrapper<LocMast>()
                            .eq("loc_no", dLocNo)
                            .eq("loc_sts", "O"));
                    if (dLoc != null && VersionUtils.locMoveCheckLocTypeComplete(dLoc, locTypeDto)) {
                        locMast = dLoc;
                        break;
                    }
                }
            }
        }
        StartupDto startupDto = new StartupDto();
        locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                .ge("row1", rowLastno.getsRow())
                .le("row1", rowLastno.geteRow())
                .eq("crn_no", crnNo)
                .eq("move_status", 0)
                .eq("loc_sts", "O")
                .orderAsc(Arrays.asList("lev1", "row1", "bay1")));
        // int crnCountO = wrkMastService.selectCount(new
        // EntityWrapper<WrkMast>().eq("crn_no", crnNo).le("io_type", 100));
        // 生成工作号
        // B. 次优先:深位为空,且浅位也为空 (入深位)
        if (locMast == null) {
            List<LocMast> deepMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("row1", deepRow)
                    .eq("loc_sts", "O")
                    .eq("crn_no", crnNo)
                    .orderBy("lev1", true).orderBy("bay1", true));
            for (LocMast dLoc : deepMasts) {
                String sLocNo = Utils.getShallowLoc(slaveProperties, dLoc.getLocNo());
                LocMast sLoc = locMastService.selectOne(new EntityWrapper<LocMast>()
                        .eq("loc_no", sLocNo)
                        .eq("loc_sts", "O"));
                if (sLoc != null && VersionUtils.locMoveCheckLocTypeComplete(dLoc, locTypeDto)) {
                    locMast = dLoc;
                    break;
                }
            }
        }
        // C. 最后:如果深位实在没法放(深位已满或浅位挡路且物料不同),再考虑浅位为空
        if (locMast == null) {
            List<LocMast> shallowMasts = locMastService.selectList(new EntityWrapper<LocMast>()
                    .eq("row1", shallowRow)
                    .eq("loc_sts", "O")
                    .eq("crn_no", crnNo)
                    .orderBy("lev1", true).orderBy("bay1", true));
            for (LocMast sLoc : shallowMasts) {
                if (VersionUtils.locMoveCheckLocTypeComplete(sLoc, locTypeDto)) {
                    locMast = sLoc;
                    break;
                }
            }
        }
        // 3. 递归与异常处理
        if (Cools.isEmpty(locMast)) {
            // 当前这组货架找完了,递归尝试下一组
            if (times < rowCount * 2) {
                return getDoubleLocNoRun(whsType, staDescId, sourceStaNo, findLocNoAttributeVo, moveCrnNo, locTypeDto, times + 1);
            }
            log.error("系统没有空库位!!! 尺寸规格: {}, 轮询次数:{}", JSON.toJSONString(locTypeDto), times);
            throw new CoolException("没有空库位");
        }
        // 4. 返回结果
        String locNo = locMast.getLocNo();
        int workNo = getWorkNo(0);
        // 返回dto
        startupDto.setWorkNo(workNo);
        startupDto.setCrnNo(locMast.getCrnNo());
        startupDto.setCrnNo(crnNo);
        startupDto.setSourceStaNo(sourceStaNo);
        startupDto.setLocNo(locMast.getLocNo());
        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 +448,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 +521,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 +620,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 +701,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 +846,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; // 堆垛机号