自动化立体仓库 - WMS系统
skyouc
2 天以前 b4c6f129662be7fb14f71235817a24e15f824449
src/main/java/com/zy/asrs/service/impl/MobileServiceImpl.java
@@ -599,6 +599,12 @@
        if (Objects.isNull(param.getBarcode())) {
            throw new CoolException("托盘码不能为空!!");
        }
        BasContainer container = basContainerService
                .selectOne(new EntityWrapper<BasContainer>().eq("barcode", param.getBarcode()));
        if (Objects.isNull(container)) {
            throw new CoolException("数据错误:容器码不存在!!");
        }
        // if (param.getBarcode().length() != 8) {
        // throw new CoolException("条码长度不是8位===>>" + param.getBarcode());
        // }
@@ -1534,7 +1540,7 @@
            station.setModiTime(new Date());
            station.setModiUser(userId);
            if (!basStationService.updateById(station)) {
                throw new CoolException("更新目标库位状态失败");
                throw new CoolException("更新目标站点状态失败");
            }
        } else {
            throw new CoolException("移转失败,目标库位状态:" + station.getLocSts());
@@ -1604,6 +1610,7 @@
        if (Objects.isNull(param.getBarcode())) {
            throw new CoolException("托盘码不能为空!!");
        }
        if (Objects.isNull(param.getCombMats()) || param.getCombMats().isEmpty()) {
            throw new CoolException("组托明细不能为空!!");
        }
@@ -1734,6 +1741,7 @@
                    throw new CoolException("数据错误,站点不存在!!");
                }
                station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
                station.setBarcode(null);
                if (!basStationService.updateById(station)) {
                    throw new CoolException("站点状态更新失败!!");
                }
@@ -1778,6 +1786,7 @@
        }
        station.setLocSts(LocStsType.LOC_STS_TYPE_O.type);
        station.setBarcode(null);
        if (!basStationService.updateById(station)) {
            throw new CoolException("站点状态修改失败!");
        }
@@ -1799,6 +1808,13 @@
        generateCrnInTask(waitPakins, station, param.getLocType1(), userId);
    }
    /**
     * SO/EO 区组托
     * @author Ryan
     * @date 2025/12/18 15:19
     * @param params
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R collectionPakin(CollectionPakinParams params, Long userId) {
@@ -2171,8 +2187,8 @@
        // 判断根据分拣出库后,还需要出多少托盘或料箱;如果余料大于0, 出新托盘或料箱
        if (totalOut.get().compareTo(0.0) > 0) {
            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId);
            //TODO 细化区分,当前出库托盘是滞满足拣货数量
            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
            //TODO 细化区分,当前出库托盘是满足拣货数量
        } else {
            LocMast locMast = locMastService.selectOne(new EntityWrapper<LocMast>()
                    // todo 根据物料种类,区分库区类型
@@ -2182,7 +2198,7 @@
            CrnTaskDetlDTO crnTaskDetlDTO = new CrnTaskDetlDTO().setLocNo(locMast.getLocNo()).setLocDetlList(locDetls);
            locMasts.add(crnTaskDetlDTO);
            // 空板出库
            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId);
            generateTask(locMasts, TaskIOType.MERGE_OUT.type, basDevp, userId, station);
        }
    }
@@ -2190,11 +2206,12 @@
     * 生成堆垛机出库任务
     *
     * @param locMasts
     * @param station
     * @author Ryan
     * @date 2025/12/6 14:44
     */
    @Transactional(rollbackFor = Exception.class)
    public void generateTask(List<CrnTaskDetlDTO> locMasts, Integer ioType, BasDevp devp, Long userId) {
    public void generateTask(List<CrnTaskDetlDTO> locMasts, Integer ioType, BasDevp devp, Long userId, BasStation station) {
        Date now = new Date();
        for (CrnTaskDetlDTO crnTaskDetlDTO : locMasts) {
@@ -2221,6 +2238,9 @@
                wrkMast.setSourceStaNo(staDesc.getCrnStn() + ""); // 源站
                wrkMast.setStaNo(staDesc.getStnNo() + ""); // 目标站
                wrkMast.setSourceLocNo(locMast.getLocNo()); // 源库位
                //小松项目,缓存出库AGV站点,用于清空缓存区库存
                wrkMast.setPauseMk(station.getDevNo());
//                wrkMast.setAvgSta(station.getDevNo());;
                wrkMast.setFullPlt("Y"); // 满板:Y
                wrkMast.setPicking("N"); // 拣料
                wrkMast.setExitMk("N"); // 退出
@@ -2244,6 +2264,8 @@
                wrkDetl.setOrderNo(""); // 手动出库不需要带出库存中的单据编号
                wrkDetl.setWrkNo(workNo);
                wrkDetl.setIoTime(now);
                wrkDetl.setZpallet(null);
                wrkDetl.setBarcode(null);
                wrkDetl.setAppeTime(now);
                wrkDetl.setAppeUser(userId);
                wrkDetl.setModiTime(now);
@@ -2282,7 +2304,7 @@
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(11L) // 工作状态:11.生成出库ID
                .setWrkSts(301L) // 工作状态:11.生成出库ID
                .setIoType(loc.getLocSts().equals("D") ? 110 : 101) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
@@ -2374,7 +2396,7 @@
        Task task = new Task();
        task.setWrkNo(workNo)
                .setIoTime(new Date())
                .setWrkSts(1L) // 工作状态:11.生成出库ID
                .setWrkSts(201L) // 工作状态:11.生成出库ID
                .setIoType(1) // 入出库状态: 11.库格移载
                .setTaskType("agv")
                .setIoPri(10D)
@@ -2443,7 +2465,7 @@
        if (station.getLocSts().equals(LocStsType.LOC_STS_TYPE_O.type)) {
            station.setLocSts("R"); // S.入库预约
            station.setBarcode(barcode);
//            station.setBarcode(barcode);
            station.setModiTime(new Date());
            station.setModiUser(userId);
            if (!basStationService.updateById(station)) {
@@ -2507,4 +2529,69 @@
        }
        return result;
    }
    /**
     * 呼叫AGV返回
     * @author Ryan
     * @date 2025/9/24
     * @param callAgvBackParam
     * @return com.core.common.R
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public R agvCallback(AgvCallParams callAgvBackParam, Long userId) {
        if (Objects.isNull(callAgvBackParam.getOrgSite())) {
            return R.error("参数不能为空!!");
        }
        // 按当前查找库位顺序,查到一个后,不再往下查询
        LocCache locCache = findPriorityLocCache();
        if (Objects.isNull(locCache)) {
            return R.error("未查询到可用库位");
        }
        try {
            generateAgvTask("agv", locCache, callAgvBackParam.getOrgSite(), callAgvBackParam.getBarcode(), userId);
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
        return R.ok(locCache);
    }
    /**
     * 按优先级查找可用库位
     * 顺序:入库缓存区 -> SO区 -> EO区
     */
    private LocCache findPriorityLocCache() {
        // 1. Try Inbound Cache Area
        LocCache loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_IN_CACHE);
        if (loc != null) return loc;
        // 2. Try SO Area
        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_SO);
        if (loc != null) return loc;
        // 3. Try EO Area
        loc = findAvailableLocByAreaType(LocAreaType.LOC_AREA_TYPE_EO);
        return loc;
    }
    /**
     * 根据区域类型查找可用库位
     */
    private LocCache findAvailableLocByAreaType(LocAreaType areaType) {
        BasAreas area = basAreasService.selectOne(new EntityWrapper<BasAreas>().eq("whs_type_id", areaType.type));
        if (area == null) {
            return null;
        }
        return locCacheService.selectOne(new EntityWrapper<LocCache>()
                .eq("area_id", area.getId())
                .eq("frozen", 0)
                .eq("loc_sts", LocStsType.LOC_STS_TYPE_O.type)
                .orderAsc(Arrays.asList("loc_no"))
                .last("OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY"));
    }
}