自动化立体仓库 - WMS系统
lty
3 天以前 d907a822a940c7ec0fb7de0ca845472bda52229b
src/main/java/com/zy/asrs/service/impl/WorkServiceImpl.java
@@ -108,7 +108,7 @@
//        List<String> batchs = param.getList().stream().map(FullStoreParam.MatCodeStore::getBatch).distinct().collect(Collectors.toList());
        StartupDto dto = commonService.getLocNo(1, param.getDevpNo(), matnrs.get(0), null, null,locTypeDto);
        if (Cools.isEmpty(dto)){
            throw new CoolException("查询库位失败!!==》startupFullPutStore ==》 commonService.getLocNo");
            throw new CoolException("response.query_loc_failed");
        }
        // 生成工作号
        int workNo = dto.getWorkNo();
@@ -135,7 +135,7 @@
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("保存工作档失败");
            throw new CoolException("response.save_work_master_failed");
        }
        // 生成工作档明细
        List<DetlDto> detlDtos = new ArrayList<>();
@@ -155,7 +155,7 @@
        sourceStaNo.setModiUser(userId);
        sourceStaNo.setModiTime(now);
        if (!basDevpService.updateById(sourceStaNo)){
            throw new CoolException("更新源站失败");
            throw new CoolException("response.update_source_station_failed");
        }
        // 更新目标库位状态
        LocMast locMast = locMastService.selectById(dto.getLocNo());
@@ -164,10 +164,10 @@
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
            if (!locMastService.updateById(locMast)){
                throw new CoolException("改变库位状态失败");
                throw new CoolException("response.change_loc_status_failed");
            }
        } else {
            throw new CoolException(dto.getLocNo()+"目标库位已被占用");
            throw new CoolException("response.target_loc_occupied");
        }
        return dto.getLocNo();
    }
@@ -180,8 +180,8 @@
        // 获取库位明细
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
                LocDetl one = locDetlService.selectItem(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getBatch());
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount(),paramLocDetl.getBarcode())) {
                LocDetl one = locDetlService.selectItemCarton(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getBatch(),paramLocDetl.getBarcode());
                if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
            }
        }
@@ -189,7 +189,7 @@
            // 启动出库开始 101.出库
            stockOut(staNo, locDetlDtos, null, userId);
        } else {
            throw new CoolException("库存不存在");
            throw new CoolException("response.stock_not_exist");
        }
    }
    /**
@@ -206,7 +206,7 @@
        LocGroupOrder currentGroup = locGroupAscOrder.stream()
                .filter(g -> g.getRowList().contains(locMast.getRow1()))
                .findFirst()
                .orElseThrow(() -> new CoolException("当前排不在任何出库优先分组中,无法进行深库位检查: row=" + locMast.getRow1()));
                .orElseThrow(() -> new CoolException("response.current_row_not_in_priority_group"));
        List<Integer> orderedRows = currentGroup.getRowList();
@@ -235,7 +235,7 @@
            // 前方有货(F状态)
            if ("F".equals(prevLoc.getLocSts())) {
                throw new CoolException(locNo + " 的前方位置 " + prevLoc.getLocNo() + " 有货,禁止出库");
                throw new CoolException("response.front_loc_has_goods_forbid_out");
            }
            // 前方有入库任务(假设 io_type=100 为入库,根据实际调整)
@@ -248,12 +248,12 @@
            );
            if (frontTask != null) {
                throw new CoolException(locNo + " 的前方位置 " + prevLoc.getLocNo() + " 存在入库任务,禁止出库");
                throw new CoolException("response.front_loc_has_in_task_forbid_out");
            }
        }
        if (!foundSelf) {
            throw new CoolException("分组内未找到目标库位,请检查数据一致性: " + locNo);
            throw new CoolException("response.target_loc_not_found_in_group");
        }
    }
    private boolean isInNormalRule(LocMast lm) {
@@ -273,8 +273,10 @@
    /**
     * 检查正常库位前方是否堵塞(深库位规则:前方排是否有货或入库任务)
     *
     * 只对属于出库分组规则内的库位进行检查
     * 如果库位不在分组规则内,则视为不需要严格检查(返回 false,不触发补齐)
     * 判断依据:
     * 1. 只检查属于出库分组规则内的库位(通过分组的 rowList 确定范围)
     * 2. 前方 = 分组中索引大于当前库位的排(假设分组 rowList 已按出库顺序排列,大索引 = 前方更深)
     * 3. 堵塞条件:前方有货(F状态)或有入库任务
     *
     * @param normalMasts 需要检查的正常库位列表(已通过 isInNormalRule 过滤)
     * @return true = 前方有堵塞(需要补齐),false = 前方清空或无需检查
@@ -283,11 +285,25 @@
        if (normalMasts == null || normalMasts.isEmpty()) {
            return false;
        }
        // 获取出库分组配置(用于确认规则范围)
        // 获取出库分组配置
        List<LocGroupOrder> locGroupAscOrder = slaveProperties.getLocGroupAscOrder();
        if (locGroupAscOrder == null || locGroupAscOrder.isEmpty()) {
            return false; // 无配置时默认不检查
        }
        // 假设所有 normalMasts 在同一个分组(常见情况,若多分组可循环处理)
        LocMast representative = normalMasts.get(0);
        LocGroupOrder group = locGroupAscOrder.stream()
                .filter(g -> g.getRowList() != null && g.getRowList().contains(representative.getRow1()))
                .findFirst()
                .orElse(null);
        if (group == null || group.getRowList() == null || group.getRowList().isEmpty()) {
            return false; // 不在任何分组,不检查
        }
        List<Integer> fullRows = group.getRowList(); // 分组内所有排号列表(按出库顺序排列)
        // 遍历每个正常库位
        for (LocMast lm : normalMasts) {
@@ -299,10 +315,17 @@
                continue;
            }
            // 深库位检查方向:假设 row 越大越深(前方是更大 row 的位置)
            // 你可以根据实际出库方向调整循环条件(例如从小 row 到大 row 或反之)
            for (int row = currentRow + 1; row <= 5; row++) { // 假设深库位范围到 5 排,可调整
                LocMast front = getLocMastByRow(row, bay1, lev1);
            // 在分组 rowList 中找到当前排的索引
            int currentIndex = fullRows.indexOf(currentRow);
            if (currentIndex < 0) {
                continue; // 当前排不在分组内,跳过
            }
            // 前方 = 分组中索引更大的位置(假设分组 rowList 从前到后排列,大索引 = 更深)
            // 如果你的分组列表是倒序的(从后到前),则需改为 currentIndex - 1 到 0
            for (int i = currentIndex + 1; i < fullRows.size(); i++) {
                Integer frontRow = fullRows.get(i);
                LocMast front = getLocMastByRow(frontRow, bay1, lev1);
                if (front == null) {
                    continue;
                }
@@ -312,12 +335,12 @@
                    return true;
                }
                // 有入库任务 → 堵塞
                WrkMast frontTask = wrkMastService.selectOne(
                        new EntityWrapper<WrkMast>()
                                .eq("source_loc_no", front.getLocNo())
                                .eq("io_type", 100) // 假设 100 为入库类型,可调整
                                .in("loc_sts", Arrays.asList("S", "Q")) // 支持 loc_sts 为 S 或 Q
                );
                if (frontTask != null) {
                    return true;
                }
@@ -365,7 +388,7 @@
        );
        if (allSelectedMasts.size() != locNos.size()) {
            throw new CoolException("部分选中库位不存在或数据异常");
            throw new CoolException("response.selected_loc_not_exist_or_error");
        }
        // 2. 区分正常库位(需要严格深库位检查)与补充库位
@@ -402,7 +425,7 @@
        allMasts.addAll(supplementMasts);
        if (allMasts.isEmpty()) {
            throw new CoolException("没有有效的出库库位");
            throw new CoolException("response.no_valid_out_loc");
        }
        // 5. 统一按排号(row)倒序排序(高排先出)
@@ -447,7 +470,7 @@
                dto = dtos.stream()
                        .filter(d -> d.getLocNo().equals(locNo))
                        .findFirst()
                        .orElseThrow(() -> new CoolException("找不到对应的出库明细:" + locNo));
                        .orElseThrow(() -> new CoolException("response.out_detail_not_found"));
                // 生成工作档
                wrkMast.setWrkNo(workNo);
                wrkMast.setIoTime(now);
@@ -468,7 +491,7 @@
                wrkMast.setAppeTime(now);
                wrkMast.setModiUser(userId);
                wrkMast.setModiTime(now);
                locSts = ioType != 101? "R" : "P";
                locSts = ioType != 101? "P" : "R";
                // 生成工作档明细(保留原逻辑)
                for (LocDetlDto detlDto : dto.getLocDetlDtos()) {
                    if (detlDto.getCount() == null || detlDto.getCount() <= 0.0D) {
@@ -476,7 +499,6 @@
                    }
                    WrkDetl wrkDetl = new WrkDetl();
                    wrkDetl.sync(detlDto.getLocDetl());
                    wrkDetl.setOrderNo("");
                    wrkDetl.setWrkNo(workNo);
                    wrkDetl.setIoTime(now);
                    Double anfme = ioType == 101 ? detlDto.getLocDetl().getAnfme() : detlDto.getCount();
@@ -486,8 +508,8 @@
                    wrkDetl.setModiTime(now);
                    wrkDetl.setModiUser(userId);
                    if (!wrkDetlService.insert(wrkDetl)) {
                        throw new CoolException("保存工作档明细失败");
                    }
            throw new CoolException("response.save_work_detail_failed");
        }
                }
            }else{
                List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no",locNo));
@@ -532,13 +554,13 @@
                        wrkDetl.setModiTime(now);
                        wrkDetl.setModiUser(userId);
                        if (!wrkDetlService.insert(wrkDetl)) {
                            throw new CoolException("保存工作档明细失败");
                            throw new CoolException("response.save_work_detail_failed");
                        }
                    }
                }
            }
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,库位:" + locNo);
                throw new CoolException("response.save_work_master_failed_loc|" + locNo);
            }
            if(locMastNew != null){
@@ -547,10 +569,10 @@
                    locMastNew.setModiUser(userId);
                    locMastNew.setModiTime(now);
                    if (!locMastService.updateById(locMastNew)) {
                        throw new CoolException("更新库位状态失败,库位:" + locNo);
                        throw new CoolException("response.update_loc_status_failed_loc|" + locNo);
                    }
                } else {
                    throw new CoolException("库位状态异常,非空板状态:" + locNo);
                    throw new CoolException("response.loc_status_error_not_empty|" + locNo);
                }
            }
            // 更新库位状态
@@ -560,11 +582,11 @@
                locMast.setModiUser(userId);
                locMast.setModiTime(now);
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("预约库位状态失败,库位号:" + locNo);
                }
            } else {
                throw new CoolException(locNo + " 库位不是在库状态");
                throw new CoolException("response.reserve_loc_status_failed|" + locNo);
            }
        } else {
            throw new CoolException("response.loc_not_in_store|" + locNo);
        }
        }
    }
@@ -575,7 +597,7 @@
        List<LocDto> locDtos = taskDto.getLocDtos();
        for (LocDto locDto : locDtos) {
            if (!taskDto.getLocNo().equals(locDto.getLocNo()) && !taskDto.getStaNo().equals(locDto.getStaNo())) {
                throw new CoolException("订单出库异常,请联系管理员");
                throw new CoolException("response.order_out_error_contact_admin");
            }
        }
        // 获取库位
@@ -607,14 +629,15 @@
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (!wrkMastService.insert(wrkMast)) {
            throw new CoolException("保存工作档失败,出库库位号:"+taskDto.getLocNo());
            throw new CoolException("response.save_work_master_failed_out_loc|" + taskDto.getLocNo());
        }
        // 生成工作档明细
        for (LocDto locDto : taskDto.getLocDtos()) {
            if (locDto.getAnfme()==null || locDto.getAnfme() <= 0.0D) { continue; }
            OrderDetl orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), locDto.getBatch());
            Order order = orderService.selectByNo(locDto.getOrderNo());
            OrderDetl orderDetl = orderDetlService.selectItem(order.getId(), locDto.getMatnr(), locDto.getBatch(),locDto.getBarcode());
            if (orderDetl == null) {
                orderDetl = orderDetlService.selectItem(locDto.getOrderNo(), locDto.getMatnr(), null);
                orderDetl = orderDetlService.selectItem(order.getId(), locDto.getMatnr(), null,locDto.getBarcode());
            }
            WrkDetl wrkDetl = new WrkDetl();
            wrkDetl.sync(orderDetl);
@@ -629,11 +652,11 @@
            wrkDetl.setModiTime(now);
            wrkDetl.setModiUser(userId);
            if (!wrkDetlService.insert(wrkDetl)) {
                throw new CoolException("保存工作档明细失败");
                throw new CoolException("response.save_work_detail_failed");
            }
            // 修改订单明细
            if (!orderDetlService.increaseWorkQty(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme())) {
                throw new CoolException("修改订单明细数量失败");
            if (!orderDetlService.increaseWorkQty(orderDetl.getOrderId(), orderDetl.getMatnr(), orderDetl.getBatch(), locDto.getAnfme(),locDto.getBarcode())) {
                throw new CoolException("response.update_order_detail_qty_failed");
            }
            orderService.updateSettle(orderDetl.getOrderId(), 2L, userId);
        }
@@ -644,10 +667,10 @@
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
            if (!locMastService.updateById(locMast)) {
                throw new CoolException("预约库位状态失败,库位号:"+taskDto.getLocNo());
                throw new CoolException("response.reserve_loc_status_failed_loc|" + taskDto.getLocNo());
            }
        } else {
            throw new CoolException(taskDto.getLocNo() + "库位不是在库状态");
            throw new CoolException("response.loc_not_in_store_status|" + taskDto.getLocNo());
        }
    }
@@ -685,14 +708,14 @@
        wrkMast.setModiTime(now);
        boolean res = wrkMastService.insert(wrkMast);
        if (!res) {
            throw new CoolException("保存工作档失败");
            throw new CoolException("response.save_work_master_failed");
        }
        // 更新源站点信息
        sourceStaNo.setWrkNo(workNo);
        sourceStaNo.setModiUser(userId);
        sourceStaNo.setModiTime(now);
        if (!basDevpService.updateById(sourceStaNo)){
            throw new CoolException("更新源站失败");
            throw new CoolException("response.update_source_station_failed");
        }
        // 更新目标库位状态
        LocMast locMast = locMastService.selectById(dto.getLocNo());
@@ -701,10 +724,10 @@
            locMast.setModiUser(userId);
            locMast.setModiTime(now);
            if (!locMastService.updateById(locMast)){
                throw new CoolException("改变库位状态失败");
                throw new CoolException("response.change_loc_status_failed");
            }
        } else {
            throw new CoolException(dto.getLocNo()+"目标库位已被占用");
            throw new CoolException("response.target_loc_occupied|" + dto.getLocNo());
        }
        return dto.getLocNo();
    }
@@ -729,7 +752,7 @@
        );
        if (selectedMasts.size() != selectedLocNos.size()) {
            return LockingCheckResultParam.fail("部分选中库位不存在或数据异常");
            return LockingCheckResultParam.fail("response.selected_loc_invalid_or_missing");
        }
        // 2. 按分组聚合选中的库位(支持多分组)
@@ -738,7 +761,7 @@
            LocGroupOrder group = locGroupAscOrder.stream()
                    .filter(g -> g.getRowList().contains(lm.getRow1()))
                    .findFirst()
                    .orElseThrow(() -> new CoolException("排不在出库分组配置中: row=" + lm.getRow1()));
                    .orElseThrow(() -> new CoolException("response.row_not_in_group_config|" + lm.getRow1()));
            groupSelected.computeIfAbsent(group, k -> new ArrayList<>()).add(lm);
        }
@@ -762,7 +785,7 @@
            // 检查是否重复或无效
            if (selectedRows.size() != selected.size()) {
                return LockingCheckResultParam.fail("选中库位存在重复或无效排");
                return LockingCheckResultParam.fail("response.selected_loc_duplicate_or_invalid_row");
            }
            int minIndex = fullRows.indexOf(selectedRows.get(0));
@@ -771,7 +794,7 @@
            // 1. 必须是连续段(无缺口)
            if (maxIndex - minIndex + 1 != selectedRows.size()) {
                return LockingCheckResultParam.fail(
                        "选中排必须连续,无缺口。从 " + fullRows.get(minIndex) + " 到 " + fullRows.get(maxIndex)
                        "response.selected_rows_must_be_continuous|" + fullRows.get(minIndex) + "|" + fullRows.get(maxIndex)
                );
            }
@@ -798,15 +821,14 @@
            // 4. 至少有一侧清空才允许出库(修改:放宽,如果两侧都堵,返回特定错误码或继续)
            if (!leftClear && !rightClear) {
                return LockingCheckResultParam.fail(
                        "选中段 " + fullRows.get(minIndex) + "~" + fullRows.get(maxIndex) +
                                " 两侧前方都有空板/故障,无法出库(正序或倒序方向都堵塞)"
                        "response.both_sides_blocked|" + fullRows.get(minIndex) + "|" + fullRows.get(maxIndex)
                );
            }
            // 5. 选中段内所有库位必须是 D 状态
            for (LocMast lm : selected) {
                if (!"D".equals(lm.getLocSts())) {
                    return LockingCheckResultParam.fail("选中库位非空板状态: " + lm.getLocNo());
                    return LockingCheckResultParam.fail("response.selected_loc_not_empty_status|" + lm.getLocNo());
                }
            }
@@ -855,7 +877,7 @@
        LocGroupOrder group = locGroupAscOrder.stream()
                .filter(g -> g.getRowList().contains(normalMasts.get(0).getRow1()))
                .findFirst()
                .orElseThrow(() -> new CoolException("分组异常"));
                .orElseThrow(() -> new CoolException("response.group_exception"));
        List<Integer> fullRows = group.getRowList();
@@ -922,7 +944,7 @@
    @Transactional
    public void emptyPlateOut(EmptyPlateOutParam param, Long userId) {
        if (Cools.isEmpty(param.getOutSite())) {
            throw new CoolException("站点不存在");
            throw new CoolException("response.site_not_exist");
        }
        // 使用出库专用分组配置
@@ -934,7 +956,7 @@
        );
        if (selectedMasts.size() != param.getLocNos().size()) {
            throw new CoolException("部分选中库位不存在或数据异常");
            throw new CoolException("response.selected_loc_abnormal");
        }
        // 2. 区分正常分组内的库位 和 需要补充的库位(规则外的)
@@ -964,7 +986,7 @@
            if (!checkResult.isSuccess()) {
                String errMsg = checkResult.getErrorMessage();
                if (errMsg.contains("两侧前方都有空板/故障")) {
                if (errMsg.contains("response.both_sides_blocked")) {
                    // 两侧都堵 → 进入补齐逻辑
                    supplementBothSidesBlocked(normalMasts, locGroupAscOrder, supplementMasts, isLeftSideSupplement);
                } else {
@@ -981,7 +1003,7 @@
        allMasts.addAll(supplementMasts);
        if (allMasts.isEmpty()) {
            throw new CoolException("没有有效的空板库位可出库");
            throw new CoolException("response.no_valid_empty_pallet_loc");
        }
        // 5. 统一按 row → bay → lev 排序(从小到大)
@@ -1015,7 +1037,7 @@
            Integer sourceStaNo = staDesc != null ? staDesc.getCrnStn() : null;
            if (Cools.isEmpty(sourceStaNo)) {
                throw new CoolException("检索源站失败,库位:" + locNo);
                throw new CoolException("response.query_source_station_failed_loc|" + locNo);
            }
            // 计算优先级(示例:补充的优先级稍低)
@@ -1075,7 +1097,7 @@
            }
            if (!wrkMastService.insert(wrkMast)) {
                throw new CoolException("保存工作档失败,库位:" + locNo);
                throw new CoolException("response.save_work_master_failed_loc|" + locNo);
            }
            if(locMastNew != null){
@@ -1084,10 +1106,10 @@
                    locMastNew.setModiUser(userId);
                    locMastNew.setModiTime(now);
                    if (!locMastService.updateById(locMastNew)) {
                        throw new CoolException("更新库位状态失败,库位:" + locNo);
                        throw new CoolException("response.update_loc_status_failed_loc|" + locNo);
                    }
                } else {
                    throw new CoolException("库位状态异常,非空板状态:" + locNo);
                    throw new CoolException("response.loc_status_error_not_empty|" + locNo);
                }
            }
@@ -1097,10 +1119,10 @@
                locMast.setModiUser(userId);
                locMast.setModiTime(now);
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("更新库位状态失败,库位:" + locNo);
                    throw new CoolException("response.update_loc_status_failed_loc|" + locNo);
                }
            } else {
                throw new CoolException("库位状态异常,非空板状态:" + locNo);
                throw new CoolException("response.loc_status_error_not_empty|" + locNo);
            }
        }
    }
@@ -1109,7 +1131,7 @@
    public WrkMast emptyPlateOut(EmptyPlateOutParam param) {
        WrkMast wrkMast = new WrkMast();
        if (Cools.isEmpty(param.getOutSite())) {
            throw new CoolException("站点不存在");
            throw new CoolException("response.site_not_exist");
        }
        for (String locNo : param.getLocNos()) {
            // 获取工作号
@@ -1117,7 +1139,7 @@
            // 获取库位
            LocMast locMast = locMastService.selectById(locNo);
            if (Cools.isEmpty(locMast)) {
                throw new CoolException(locNo+"库位不存在");
                throw new CoolException("response.loc_not_exist|" + locNo);
            }
            // 获取源站
            Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
@@ -1127,7 +1149,7 @@
            StaDesc staDesc = staDescService.selectOne(wrapper);
            Integer sourceStaNo = staDesc.getCrnStn();
            if (Cools.isEmpty(sourceStaNo)) {
                throw new CoolException("检索源站失败");
                throw new CoolException("response.query_source_station_failed");
            }
            Date now = new Date();
            // 保存工作档
@@ -1150,10 +1172,10 @@
            wrkMast.setAppeTime(now);
            wrkMast.setModiUser(1L);
            wrkMast.setModiTime(now);
            wrkMast.setMemo("生成自动空板出库");
            wrkMast.setMemo("response.memo_auto_empty_pallet_out");
            boolean res = wrkMastService.insert(wrkMast);
            if (!res) {
                throw new CoolException("保存工作档失败");
                throw new CoolException("response.save_work_master_failed");
            }
            // 更新库位状态 D.空板 -> R.出库预约
            if (locMast.getLocSts().equals("D")){
@@ -1161,7 +1183,7 @@
                locMast.setModiUser(1L);
                locMast.setModiTime(now);
                if (!locMastService.updateById(locMast)) {
                    throw new CoolException("更新库位状态失败");
                    throw new CoolException("response.update_loc_status_failed_simple");
                }
            }
        }
@@ -1176,8 +1198,8 @@
        // 获取库位明细
        List<LocDetlDto> locDetlDtos = new ArrayList<>();
        for (StockOutParam.LocDetl paramLocDetl : param.getLocDetls()) {
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount())) {
                LocDetl one = locDetlService.selectItem(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getBatch());
            if (!Cools.isEmpty(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getCount(),paramLocDetl.getBarcode())) {
                LocDetl one = locDetlService.selectItemCarton(paramLocDetl.getLocNo(), paramLocDetl.getMatnr(), paramLocDetl.getBatch(),paramLocDetl.getBarcode());
                if (null != one) locDetlDtos.add(new LocDetlDto(one, paramLocDetl.getCount()));
            }
        }
@@ -1187,10 +1209,10 @@
                // 启动出库开始 107.盘点出库
                stockOut(staNo, locDetlDtos, IoWorkType.CHECK_OUT, userId);
            }else {
                throw new CoolException("所选库位存在状态不为F的库位,库位号:"+locMast.getLocNo()+" 、当前状态:"+locMast.getLocSts()+"-"+locMast.getLocSts$());
                throw new CoolException("response.selected_loc_status_error|" + locMast.getLocNo() + "," + locMast.getLocSts() + "-" + locMast.getLocSts$());
            }
        } else {
            throw new CoolException("库位物料不存在");
            throw new CoolException("response.loc_material_not_exist");
        }
    }
@@ -1200,17 +1222,17 @@
        LocMast sourceLoc = locMastService.selectById(sourceLocNo);
        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("loc_no", sourceLocNo));
        if (Cools.isEmpty(sourceLoc)){
            throw new CoolException("未找到库位");
            throw new CoolException("response.loc_not_found");
        }
        LocMast loc = locMastService.selectById(locNo);
        if (Cools.isEmpty(loc)){
            throw new CoolException("未找到库位");
            throw new CoolException("response.loc_not_found");
        }
        if (!loc.getLocSts().equals("O") || (!sourceLoc.getLocSts().equals("F") && !sourceLoc.getLocSts().equals("D"))){
            throw new CoolException("库位状态已改变");
            throw new CoolException("response.loc_status_changed");
        }
        if (!sourceLoc.getCrnNo().equals(loc.getCrnNo())) {
            throw new CoolException("移转库位属于不同堆垛机");
            throw new CoolException("response.transfer_loc_diff_crn");
        }
        Date now = new Date();
        // 获取工作号
@@ -1237,7 +1259,7 @@
        wrkMast.setModiTime(now);
        boolean res = wrkMastService.insert(wrkMast);
        if (!res) {
            throw new CoolException("保存工作档失败");
            throw new CoolException("response.save_work_master_failed_simple");
        }
        // 工作档明细保存
        for (LocDetl locDetl : locDetls) {
@@ -1251,7 +1273,7 @@
            wrkDetl.setModiTime(now);
            wrkDetl.setModiUser(userId);
            if (!wrkDetlService.insert(wrkDetl)) {
                throw new CoolException("保存工作档明细失败");
                throw new CoolException("response.save_work_detail_failed");
            }
        }
        // 修改源库位状态
@@ -1260,10 +1282,10 @@
            sourceLoc.setModiUser(userId);
            sourceLoc.setModiTime(now);
            if (!locMastService.updateById(sourceLoc)){
                throw new CoolException("更新源库位状态失败");
                throw new CoolException("response.update_source_loc_status_failed");
            }
        } else {
            throw new CoolException("源库位出库失败,状态:"+sourceLoc.getLocSts$());
            throw new CoolException("response.source_loc_out_failed_status|" + sourceLoc.getLocSts$());
        }
        // 修改目标库位状态
        if (loc.getLocSts().equals("O")) {
@@ -1271,10 +1293,10 @@
            loc.setModiTime(now);
            loc.setModiUser(userId);
            if (!locMastService.updateById(loc)) {
                throw new CoolException("更新目标库位状态失败");
                throw new CoolException("response.update_target_loc_status_failed");
            }
        } else {
            throw new CoolException("移转失败,目标库位状态:"+loc.getLocSts$());
            throw new CoolException("response.transfer_failed_target_loc_status|" + loc.getLocSts$());
        }
    }
@@ -1283,10 +1305,10 @@
    public void completeWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){
            throw new CoolException(workNo+"工作档不存在");
            throw new CoolException("response.work_master_not_exist|" + workNo);
        }
        if (wrkMast.getWrkSts() == 4 || wrkMast.getWrkSts() == 14) {
            throw new CoolException("当前工作档已完成");
            throw new CoolException("response.work_master_completed");
        }
        // 出库
        if (wrkMast.getIoType() > 100) {
@@ -1302,9 +1324,9 @@
        wrkMast.setModiTime(now);
        wrkMast.setModiUser(userId);
        // 完成操作人员记录
        wrkMast.setManuType("手动完成");
        wrkMast.setManuType("response.manu_complete");
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("修改工作档失败");
            throw new CoolException("response.update_work_master_failed");
        }
    }
@@ -1314,10 +1336,10 @@
        param.integrate();
        LocMast locMast = locMastService.selectById(param.getLocNo());
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("库位不存在");
            throw new CoolException("response.loc_not_exist_simple");
        }
        if (!(locMast.getLocSts().equals("F") || locMast.getLocSts().equals("D") || locMast.getLocSts().equals("O"))) {
            throw new CoolException("当前库位不可调整!库位状态:" + locMast.getLocSts$());
            throw new CoolException("response.loc_not_adjustable|" + locMast.getLocSts$());
        }
        Date now = new Date();
@@ -1338,8 +1360,8 @@
                    if (!locDetl.getAnfme().equals(adjust.getCount())) {
                        // todo 盘点记录
                        // 修改库存
                        if (!locDetlService.updateAnfme(adjust.getCount(), locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch())) {
                            throw new CoolException(locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "批号修改数量失败");
                        if (!locDetlService.updateAnfme(adjust.getCount(), locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(),locDetl.getBarcode())) {
                            throw new CoolException("response.update_stock_qty_failed|" + locDetl.getLocNo() + "," + locDetl.getMatnr() + "," + locDetl.getBatch());
                        }
                        // 保存调整记录
                        AdjDetl adjDetl = new AdjDetl();
@@ -1363,8 +1385,8 @@
        // 删除库存
        for (LocDetl locDetl : locDetls) {
            // todo 盘点记录
            if (!locDetlService.updateAnfme(-1.0D, locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch())) {
                throw new CoolException("删除" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "批号库存明细失败");
            if (!locDetlService.updateAnfme(-1.0D, locDetl.getLocNo(), locDetl.getMatnr(), locDetl.getBatch(),locDetl.getBarcode())) {
                throw new CoolException("response.delete_stock_detail_failed|" + locDetl.getLocNo() + "," + locDetl.getMatnr() + "," + locDetl.getBatch());
            }
            // 保存调整记录
            AdjDetl adjDetl = new AdjDetl();
@@ -1394,7 +1416,7 @@
            locDetl.setAppeUser(userId);
            locDetl.setAppeTime(now);
            if (!locDetlService.insert(locDetl)) {
                throw new CoolException("添加" + locDetl.getLocNo() + "库位," + locDetl.getMatnr() + "商品," + locDetl.getBatch() + "批号库存明细失败");
                throw new CoolException("response.add_stock_detail_failed|" + locDetl.getLocNo() + "," + locDetl.getMatnr() + "," + locDetl.getBatch());
            }
            // 保存调整记录
            AdjDetl adjDetl = new AdjDetl();
@@ -1424,7 +1446,7 @@
        locMast.setModiUser(userId);
        locMast.setModiTime(now);
        if (!locMastService.updateById(locMast)) {
            throw new CoolException("更新库位状态失败");
            throw new CoolException("response.update_loc_status_failed");
        }
    }
@@ -1435,7 +1457,7 @@
        Date now = new Date();
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){
            throw new CoolException(workNo+"工作档不存在");
            throw new CoolException("response.work_master_not_exist|" + workNo);
        }
        String locNo = ""; // 待修改目标库位
        String locSts = ""; // 待修改目标库位状态
@@ -1449,7 +1471,7 @@
                // 库位转移:源库位
                LocMast locMast = locMastService.selectById(wrkMast.getSourceLocNo());
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("取消库位转移失败,源库位不存在:"+ wrkMast.getSourceLocNo());
                    throw new CoolException("response.cancel_transfer_failed_source_not_exist|" + wrkMast.getSourceLocNo());
                }
                locMast.setLocSts(wrkMast.getFullPlt().equalsIgnoreCase("N")?"D":"F");
                locMast.setModiTime(now);
@@ -1471,7 +1493,7 @@
                // 库位转移:目标库位
                LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
                if (Cools.isEmpty(locMast)) {
                    throw new CoolException("取消库位转移失败,目标库位不存在:"+ wrkMast.getSourceLocNo());
                    throw new CoolException("response.cancel_transfer_failed_target_not_exist|" + wrkMast.getLocNo());
                }
                locMast.setLocSts("O");
                locMast.setModiTime(now);
@@ -1479,7 +1501,7 @@
                locMastService.updateById(locMast);
            }
        } else {
            throw new CoolException("当前工作状态无法取消");
            throw new CoolException("response.work_status_cannot_cancel");
        }
        //取消入库工作档时,查询组托表,如果有将状态改为待处理
@@ -1503,7 +1525,7 @@
            for (WrkDetl wrkDetl : wrkDetls) {
                if (!Cools.isEmpty(wrkDetl.getOrderNo())) {
                    if (!orderDetlService.decrease(wrkDetl.getOrderNo(), wrkDetl.getMatnr(), wrkDetl.getBatch(), wrkDetl.getAnfme())) {
                        throw new CoolException("订单数据回滚失败");
                        throw new CoolException("response.order_data_rollback_failed");
                    }
                    //修改订单主表状态,没有作业数量时才可以修改
@@ -1522,7 +1544,7 @@
                            order.setUpdateTime(now);
                        }
                        if(!orderService.update(order,new EntityWrapper<Order>().eq("order_no",wrkDetl.getOrderNo()))){
                            throw new CoolException("修改订单状态失败");
                            throw new CoolException("response.update_order_status_failed");
                        }
                    }
                }
@@ -1543,15 +1565,15 @@
//        }
        // 取消操作人员记录
        wrkMast.setManuType("手动取消");
        wrkMast.setManuType("response.manu_cancel");
        wrkMast.setModiUser(userId);
        wrkMast.setModiTime(now);
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("取消工作档失败");
            throw new CoolException("response.cancel_work_master_failed");
        }
        // 保存工作主档历史档
        if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
            throw new CoolException("保存工作历史档失败, workNo = " + wrkMast.getWrkNo());
            throw new CoolException("response.save_work_log_failed|" + wrkMast.getWrkNo());
        }
        // 删除工作主档
        boolean wrkMastRes = wrkMastService.deleteById(wrkMast);
@@ -1568,14 +1590,14 @@
        // 修改库位状态
        LocMast locMast = locMastService.selectById(locNo);
        if (Cools.isEmpty(locMast)) {
            throw new CoolException("取消工作档失败,库位不存在:"+ locNo);
            throw new CoolException("response.cancel_work_master_failed_loc_not_exist|" + locNo);
        }
        locMast.setLocSts(locSts);
        locMast.setModiTime(now);
        locMast.setModiUser(userId);
        boolean locMastRes = locMastService.updateById(locMast);
        if (!wrkMastRes || !locMastRes) {
            throw new CoolException("保存数据失败");
            throw new CoolException("response.save_data_failed");
        }
        //wms取消任务 同时调用wcs任务取消接口通知wcs
@@ -1600,7 +1622,7 @@
                flag = true;
            }else {
                log.error("wms取消任务下发wcs失败--->url:{};request:{};response:{}", url+"/"+cancel, JSON.toJSONString(wrkCancel), response);
                throw new CoolException("wms取消任务下发wcs失败");
                throw new CoolException("response.wms_cancel_task_wcs_failed");
            }
        }catch (Exception e){
            log.error("fail", e);
@@ -1629,15 +1651,15 @@
    public void pickWrkMast(String workNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(workNo);
        if (Cools.isEmpty(wrkMast)){
            throw new CoolException(workNo+"工作档不存在");
            throw new CoolException("response.work_master_not_exist|" + workNo);
        }
        // 入出库类型判断
        if (wrkMast.getIoType() != 103 && wrkMast.getIoType() != 104 && wrkMast.getIoType() != 107) {
            throw new CoolException("当前入出库类型无法进行操作");
            throw new CoolException("response.io_type_cannot_operate");
        }
        // 工作状态判断
        if (wrkMast.getWrkSts() < 11 || wrkMast.getWrkSts() == 15) {
            throw new CoolException("当前工作状态无法进行操作");
            throw new CoolException("response.work_status_cannot_operate");
        }
        // 保存工作明细档历史档
//        if (!wrkDetlLogService.save(wrkMast.getWrkNo())) {
@@ -1645,7 +1667,7 @@
//        }
        // 保存工作主档历史档
        if (!wrkMastLogService.save(wrkMast.getWrkNo())) {
            throw new CoolException("保存工作主档历史档失败");
            throw new CoolException("response.save_work_master_log_failed");
        }
        // 获取目标站
        Wrapper<StaDesc> wrapper = new EntityWrapper<StaDesc>()
@@ -1654,7 +1676,7 @@
                .eq("crn_no", wrkMast.getCrnNo()); // 堆垛机号
        StaDesc staDesc = staDescService.selectOne(wrapper);
        if (Cools.isEmpty(staDesc)) {
            throw new CoolException("入库路径不存在");
            throw new CoolException("response.in_route_not_exist");
        }
        Date now = new Date();
        // 堆垛机站点(目标站)
@@ -1669,7 +1691,7 @@
        wrkMast.setModiTime(now);
        wrkMast.setModiUser(userId);
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("更新工作档数据状态失败");
            throw new CoolException("response.update_work_master_status_failed");
        }
        // 修改库位状态 Q.拣料/盘点/并板再入库
        LocMast locMast = locMastService.selectById(wrkMast.getLocNo());
@@ -1677,14 +1699,14 @@
        locMast.setModiTime(now);
        locMast.setModiUser(userId);
        if (!locMastService.updateById(locMast)) {
            throw new CoolException("修改库位状态失败");
            throw new CoolException("response.update_loc_status_failed");
        }
    }
    @Override
    public StartupDto createWaitPainWrkMastStart(List<WaitPakin> list, Long userId) {
        if (Cools.isEmpty(list)) {
            throw new CoolException("入库通知档不能为空");
            throw new CoolException("response.wait_pakin_empty");
        }
        LocTypeDto locTypeDto = new LocTypeDto();
        locTypeDto.setLocType1((short) 1);
@@ -1696,7 +1718,7 @@
    public String dealPreHaveStart(Integer wrkNo, Long userId) {
        WrkMast wrkMast = wrkMastService.selectById(wrkNo);
        if (wrkMast == null) {
            throw new CoolException("任务已失效");
            throw new CoolException("response.task_invalid");
        }
        String locNo = wrkMast.getLocNo();
        LocMast locMast = locMastService.selectById(locNo);
@@ -1746,14 +1768,14 @@
        }
        if (targetLoc == null) {
            throw new CoolException("操作失败,当前仓库找不到空库位");
            throw new CoolException("response.no_empty_loc_found");
        }
        Date now = new Date();
        // 修改工作档
        StaDesc staDesc = staDescService.queryCrnStn(targetLoc.getCrnNo());
        if (Cools.isEmpty(staDesc)) {
            throw new CoolException("入库路径不存在");
            throw new CoolException("response.in_route_not_exist");
        }
        wrkMast.setWrkSts(2L);
        wrkMast.setLocNo(targetLoc.getLocNo());
@@ -1763,7 +1785,7 @@
        wrkMast.setModiUser(userId);
        wrkMast.setPreHave("N");
        if (!wrkMastService.updateById(wrkMast)) {
            throw new CoolException("修改工作档失败");
            throw new CoolException("response.update_work_master_failed");
        }
        // 修改库位状态 O ===>>> S
        if (targetLoc.getLocSts().equals("O")){
@@ -1771,10 +1793,10 @@
            targetLoc.setModiUser(userId);
            targetLoc.setModiTime(now);
            if (!locMastService.updateById(targetLoc)){
                throw new CoolException("改变库位状态失败");
                throw new CoolException("response.update_loc_status_failed");
            }
        } else {
            throw new CoolException(targetLoc.getLocNo()+"目标库位已被占用");
            throw new CoolException("response.target_loc_occupied|" + targetLoc.getLocNo());
        }
        // 禁用异常库位
//        locMast.setLocSts("X"); // X.禁用
@@ -1791,16 +1813,16 @@
    public void turnMatLocDetl(EmptyPlateOutParam param, Long userId) {
        Mat mat = matService.selectOne(new EntityWrapper<Mat>().eq("id", param.getMatId()));
        if (Cools.isEmpty(mat)){
            throw new CoolException("目标库位商品编码有误!");
            throw new CoolException("response.target_loc_mat_error");
        }
        List<LocDetl> locDetls = locDetlService.selectList(new EntityWrapper<LocDetl>().eq("matnr", param.getLocDetls().get(0).getMatnr()));
        if (Cools.isEmpty(locDetls) || locDetls.size()<1){
            throw new CoolException("待修改商品无库存,无需修改!  品号:"+param.getLocDetls().get(0).getMatnr());
            throw new CoolException("response.mat_no_stock_no_need_update|" + param.getLocDetls().get(0).getMatnr());
        }
        try {
            locDetlService.updateMatTurn(param.getLocDetls().get(0).getMatnr(),mat.getMatnr());
        }catch (Exception e){
            throw new CoolException("对数据库修改出错!");
            throw new CoolException("response.db_update_error");
        }
        for (LocDetl locDetl:locDetls){
            // 保存调整记录