chen.lin
昨天 b003a49794f49a329e2702918ecfc8d14b371d0d
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/MobileServiceImpl.java
@@ -14,6 +14,7 @@
import com.vincent.rsf.server.common.security.JwtSubject;
import com.vincent.rsf.server.common.utils.FieldsUtils;
import com.vincent.rsf.server.common.utils.JwtUtil;
import com.vincent.rsf.server.common.utils.QuantityUtils;
import com.vincent.rsf.server.manager.controller.params.GenerateTaskParams;
import com.vincent.rsf.server.manager.controller.params.IsptItemsParams;
import com.vincent.rsf.server.manager.controller.params.WaitPakinParam;
@@ -258,8 +259,9 @@
            throw new CoolException("数据错误:主单不存在!!");
        }
        //TODO /**收货数量累加,1. 会出超收情况 2. 会有收货不足情况*/
        Double rcptedQty = Math.round((wkOrder.getQty() + receiptQty) * 1000000) / 1000000.0;
        wkOrder.setQty(rcptedQty).setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_EXCE_ING.val);
        Double rcptedQty = QuantityUtils.add(wkOrder.getQty(), receiptQty);
        // 新顺序:未执行(组托)→任务执行中→已完成,不再设置执行中/收货完成
        wkOrder.setQty(rcptedQty); // .setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_EXCE_ING.val)
        if (!asnOrderMapper.updateById(wkOrder)) {
            throw new CoolException("已收货数量修改失败!!");
        }
@@ -306,14 +308,14 @@
                throw new CoolException("请输入正确的时间格式!!");
            }
            Double itemRcptQty = Math.round((dto.getReceiptQty() + orderItem.getQty()) * 1000000) / 1000000.0;
            Double itemRcptQty = QuantityUtils.add(dto.getReceiptQty(), orderItem.getQty());
            Boolean allowOver = false;
            if (!Objects.isNull(config)) {
                if (Boolean.parseBoolean(config.getVal())) {
                    allowOver = true;
                }
            }
            if (itemRcptQty.compareTo(orderItem.getAnfme()) > 0 && !allowOver) {
            if (QuantityUtils.compare(itemRcptQty, orderItem.getAnfme()) > 0 && !allowOver) {
                throw new CoolException("收货数量不能大于计划数量!!");
            }
@@ -350,18 +352,18 @@
            if (asnOrderItemMapper.updateById(orderItem) < 1) {
                throw new CoolException("通知单明细数量修改失败!!");
            }
            /**保存明细至收货区**/
            extracted(loginUserId, dto, areasItem, orderItem, wkOrder, matnr);
            // 收货区已停用,不再保存至收货区
            // extracted(loginUserId, dto, areasItem, orderItem, wkOrder, matnr);
        }
        WkOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, asnCode));
        if (order.getQty().compareTo(order.getAnfme()) >= 0.00) {
            order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_RECEIPT_DONE.val).setRleStatus(Short.valueOf("1"));
            if (!asnOrderMapper.updateById(order)) {
                throw new CoolException("订单状态修改失败!!");
            }
        }
        // 新顺序:未执行(组托)→任务执行中→已完成,不再设置收货完成
        // WkOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, asnCode));
        // if (order.getQty().compareTo(order.getAnfme()) >= 0.00) {
        //     order.setExceStatus(AsnExceStatus.ASN_EXCE_STATUS_RECEIPT_DONE.val).setRleStatus(Short.valueOf("1"));
        //     if (!asnOrderMapper.updateById(order)) {
        //         throw new CoolException("订单状态修改失败!!");
        //     }
        // }
        return R.ok("收货成功!!");
    }
@@ -390,7 +392,7 @@
                .setUnit(orderItem.getStockUnit())
                .setStockUnit(orderItem.getStockUnit())
                .setBatch(StringUtils.isBlank(orderItem.getBatch()) ? SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_RECEIPT_BATCH, dto) : orderItem.getBatch())
                .setAnfme(dto.getReceiptQty())
                .setAnfme(QuantityUtils.roundToScale(dto.getReceiptQty()))
                .setSplrBatch(dto.getSplrBatch())
                .setMatnrCode(matnr.getCode())
                .setUpdateBy(loginUserId)
@@ -419,8 +421,7 @@
        if (!Objects.isNull(serviceOne)) {
            item.setId(serviceOne.getId());
            Double anfme = Math.round((item.getAnfme() + serviceOne.getAnfme()) * 1000000) / 1000000.0;
            item.setAnfme(anfme);
            item.setAnfme(QuantityUtils.add(item.getAnfme(), serviceOne.getAnfme()));
        }
        //未质检
@@ -511,11 +512,13 @@
     * @description 获取收货区
     * @time 2025/3/11 10:12
     */
    /** 收货区已停用,返回空列表 */
    @Override
    public R getReceiptAreas() {
        List<WarehouseAreas> areas = warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>()
                .eq(WarehouseAreas::getType, WarehouseAreaType.WAREHOUSE_AREA_RECEIPT.type));
        return R.ok(areas);
        // List<WarehouseAreas> areas = warehouseAreasService.list(new LambdaQueryWrapper<WarehouseAreas>()
        //         .eq(WarehouseAreas::getType, WarehouseAreaType.WAREHOUSE_AREA_RECEIPT.type));
        // return R.ok(areas);
        return R.ok(Collections.emptyList());
    }
    /**
@@ -552,7 +555,7 @@
//            throw new CoolException("票号不能为空!!");
//        }
//        if (Objects.isNull(code)) {
//            throw new CoolException("容器号不能为空!!");
//            throw new CoolException("料箱码不能为空!!");
//        }
//        BasContainer container = basContainerService.getOne(new LambdaQueryWrapper<BasContainer>().eq(BasContainer::getCode, barcode));
//        if (Objects.isNull(container)) {
@@ -579,7 +582,7 @@
                || !Objects.isNull(fieldIndex) || !Cools.isEmpty(matnrCode) || !Cools.isEmpty(asnCode);
        
        if (!hasValidCondition) {
            throw new CoolException("请至少输入一个查询条件:物料编码、ASN单号、跟踪码、批次或票号");
            throw new CoolException("请至少输入一个查询条件:物料编码、WMS单号、批号");/*、跟踪码、批次或票号*/
        }
        
        // 如果扫描物料编码且ASN单号为空,直接从物料信息表获取,不查询收货区
@@ -620,60 +623,102 @@
            return R.ok(resultList);
        }
        
        //TODO 后续需根据策略配置,获取组拖数据。如:混装,按批次混装等
        LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new LambdaQueryWrapper<>();
        // 构建OR查询条件组
        // 统计有效条件数量
        int conditionCount = 0;
        if (!Cools.isEmpty(code)) conditionCount++;
        if (!Cools.isEmpty(batch)) conditionCount++;
        if (!Objects.isNull(fieldIndex)) conditionCount++;
        if (!Cools.isEmpty(matnrCode)) conditionCount++;
        if (!Cools.isEmpty(asnCode)) conditionCount++;
        // 如果只有一个条件,直接使用eq;如果有多个条件,使用and包裹or条件组
        if (conditionCount == 1) {
            // 单个条件,直接查询
            if (!Cools.isEmpty(code)) {
                queryWrapper.eq(WarehouseAreasItem::getTrackCode, code);
            } else if (!Cools.isEmpty(batch)) {
                queryWrapper.eq(WarehouseAreasItem::getSplrBatch, batch);
            } else if (!Objects.isNull(fieldIndex)) {
                queryWrapper.eq(WarehouseAreasItem::getFieldsIndex, fieldIndex);
            } else if (!Cools.isEmpty(matnrCode)) {
                queryWrapper.eq(WarehouseAreasItem::getMatnrCode, matnrCode);
            } else if (!Cools.isEmpty(asnCode)) {
                queryWrapper.eq(WarehouseAreasItem::getAsnCode, asnCode);
        // 收货区已停用:有ASN单号时从订单明细查可组托物料;可组盘数量 = 计划数量 - 已组托数量 - 已上架数量
        if (!Cools.isEmpty(asnCode)) {
            WkOrder order = asnOrderMapper.getOne(new LambdaQueryWrapper<WkOrder>().eq(WkOrder::getCode, asnCode));
            if (order == null) {
                logger.info("未找到ASN单号: {}", asnCode);
                return R.ok(Collections.emptyList());
            }
        } else {
            // 多个条件,使用OR连接
            queryWrapper.and(wrapper -> {
                boolean first = true;
            // 按明细汇总已组托数量(组托数量不会因改单而变)
            List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getAsnId, order.getId()));
            Map<Long, Double> palletizedByItemId = pakinItems.stream()
                    .collect(Collectors.groupingBy(WaitPakinItem::getAsnItemId, Collectors.summingDouble(w -> w.getAnfme() != null ? w.getAnfme() : 0.0)));
            palletizedByItemId.replaceAll((k, v) -> QuantityUtils.roundToScale(v));
            LambdaQueryWrapper<WkOrderItem> itemWrapper = new LambdaQueryWrapper<WkOrderItem>().eq(WkOrderItem::getOrderId, order.getId());
            if (!Cools.isEmpty(matnrCode)) itemWrapper.eq(WkOrderItem::getMatnrCode, matnrCode);
            if (!Cools.isEmpty(batch)) itemWrapper.eq(WkOrderItem::getSplrBatch, batch);
            if (!Objects.isNull(fieldIndex)) itemWrapper.eq(WkOrderItem::getFieldsIndex, fieldIndex);
            if (!Cools.isEmpty(code)) itemWrapper.eq(WkOrderItem::getTrackCode, code);
            List<WkOrderItem> orderItems = asnOrderItemMapper.selectList(itemWrapper);
            List<WarehouseAreasItem> list = new ArrayList<>();
            for (WkOrderItem oi : orderItems) {
                Double anfme = QuantityUtils.roundToScale(oi.getAnfme() != null ? oi.getAnfme() : 0.0);
                Double qty = QuantityUtils.roundToScale(oi.getQty() != null ? oi.getQty() : 0.0);
                Double workQty = palletizedByItemId.getOrDefault(oi.getId(), 0.0); // 已组托数量
                if (QuantityUtils.compare(QuantityUtils.subtract(QuantityUtils.subtract(anfme, workQty), qty), 0.0) <= 0) continue; // 可组盘数量<=0 不返回
                WarehouseAreasItem v = new WarehouseAreasItem();
                v.setId(oi.getId());
                v.setAsnItemId(oi.getId());
                v.setAsnId(order.getId());
                v.setAsnCode(order.getCode());
                v.setAnfme(anfme);
                v.setQty(qty);
                v.setWorkQty(QuantityUtils.roundToScale(workQty));
                v.setMatnrCode(oi.getMatnrCode());
                v.setMaktx(oi.getMaktx());
                v.setSplrBatch(oi.getSplrBatch());
                v.setPlatItemId(oi.getPlatItemId());
                v.setStockUnit(oi.getStockUnit());
                v.setUnit(oi.getStockUnit());
                v.setMatnrId(oi.getMatnrId());
                v.setFieldsIndex(oi.getFieldsIndex());
                v.setTrackCode(oi.getTrackCode());
                if (oi.getFieldsIndex() != null) {
                    v.setExtendFields(FieldsUtils.getFields(oi.getFieldsIndex()));
                }
                list.add(v);
            }
            logger.info("=== 从订单明细查询可组托物料(收货区已停用)asnCode: {} 返回 {} 条", asnCode, list.size());
            return R.ok(list);
        }
        // 无ASN单号时按其他条件查(收货区已停用,此处仅保留兼容,通常无数据)
        LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new LambdaQueryWrapper<>();
        {
            // 没有ASN单号时,可以扫描任意物料组托,使用OR连接多个条件
            // 统计有效条件数量
            int conditionCount = 0;
            if (!Cools.isEmpty(code)) conditionCount++;
            if (!Cools.isEmpty(batch)) conditionCount++;
            if (!Objects.isNull(fieldIndex)) conditionCount++;
            if (!Cools.isEmpty(matnrCode)) conditionCount++;
            // 如果只有一个条件,直接使用eq
            if (conditionCount == 1) {
                if (!Cools.isEmpty(code)) {
                    wrapper.eq(WarehouseAreasItem::getTrackCode, code);
                    first = false;
                    queryWrapper.eq(WarehouseAreasItem::getTrackCode, code);
                } else if (!Cools.isEmpty(batch)) {
                    queryWrapper.eq(WarehouseAreasItem::getSplrBatch, batch);
                } else if (!Objects.isNull(fieldIndex)) {
                    queryWrapper.eq(WarehouseAreasItem::getFieldsIndex, fieldIndex);
                } else if (!Cools.isEmpty(matnrCode)) {
                    queryWrapper.eq(WarehouseAreasItem::getMatnrCode, matnrCode);
                }
                if (!Cools.isEmpty(batch)) {
                    if (!first) wrapper.or();
                    wrapper.eq(WarehouseAreasItem::getSplrBatch, batch);
                    first = false;
                }
                if (!Objects.isNull(fieldIndex)) {
                    if (!first) wrapper.or();
                    wrapper.eq(WarehouseAreasItem::getFieldsIndex, fieldIndex);
                    first = false;
                }
                if (!Cools.isEmpty(matnrCode)) {
                    if (!first) wrapper.or();
                    wrapper.eq(WarehouseAreasItem::getMatnrCode, matnrCode);
                    first = false;
                }
                if (!Cools.isEmpty(asnCode)) {
                    if (!first) wrapper.or();
                    wrapper.eq(WarehouseAreasItem::getAsnCode, asnCode);
                }
            });
            } else if (conditionCount > 1) {
                // 多个条件,使用OR连接
                queryWrapper.and(wrapper -> {
                    boolean first = true;
                    if (!Cools.isEmpty(code)) {
                        wrapper.eq(WarehouseAreasItem::getTrackCode, code);
                        first = false;
                    }
                    if (!Cools.isEmpty(batch)) {
                        if (!first) wrapper.or();
                        wrapper.eq(WarehouseAreasItem::getSplrBatch, batch);
                        first = false;
                    }
                    if (!Objects.isNull(fieldIndex)) {
                        if (!first) wrapper.or();
                        wrapper.eq(WarehouseAreasItem::getFieldsIndex, fieldIndex);
                        first = false;
                    }
                    if (!Cools.isEmpty(matnrCode)) {
                        if (!first) wrapper.or();
                        wrapper.eq(WarehouseAreasItem::getMatnrCode, matnrCode);
                    }
                });
            }
        }
        
        // 打印查询参数到控制台
@@ -945,7 +990,7 @@
    @Override
    public R operateToStock(OpStockParams params) {
        if (org.apache.commons.lang3.StringUtils.isBlank(params.getBarcode())) {
            throw new CoolException("托盘码不能为空!!");
            throw new CoolException("料箱码不能为空!!");
        }
        WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
                .eq(WaitPakin::getBarcode, params.getBarcode())
@@ -1000,7 +1045,7 @@
            throw new CoolException("当前业务:" + SerialRuleCode.SYS_STOCK_CODE + ",编码规则不存在!!");
        }
        List<WkOrderItem> itemList = params.getItemList();
        double sum = itemList.stream().mapToDouble(WkOrderItem::getAnfme).sum();
        Double sum = QuantityUtils.roundToScale(itemList.stream().mapToDouble(WkOrderItem::getAnfme).sum());
        stock.setAnfme(sum)
                .setSourceId(order.getId())
                .setType(order.getType())
@@ -1154,15 +1199,15 @@
                .eq(WaitPakin::getFlagDefect, flagDefect)
                .in(WaitPakin::getIoStatus, asList));
//        if (!Cools.isEmpty(waitPakin)) {
//            throw new CoolException("托盘不可用,在组托中已存在");
//            throw new CoolException("料箱不可用,在组托中已存在");
//        }
        List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, params.get("barcode").toString()));
        if (!tasks.isEmpty()) {
            throw new CoolException("托盘码已在任务档执行!!");
            throw new CoolException("料箱码已在任务档执行!!");
        }
        List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, params.get("barcode").toString()));
        if (!Cools.isEmpty(locs)) {
            throw new CoolException("托盘不可用,在库位中已存在");
            throw new CoolException("料箱不可用,在库位中已存在");
        }
//        List<WaitPakinItem> items = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, waitPakin.getId()));
//        items.forEach(item -> {
@@ -1185,14 +1230,14 @@
    @Override
    public R getUnItemByContainer(Map<String, Object> params) {
        if (Cools.isEmpty(params.get("barcode")) && Cools.isEmpty(params.get("code"))) {
            throw new CoolException("容器号与组托档编码不能全为空");
            throw new CoolException("料箱码与组托档编码不能全为空");
        }
        WaitPakin waitPakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
                .eq(!Cools.isEmpty(params.get("barcode")), WaitPakin::getBarcode, params.get("barcode"))
                .eq(!Cools.isEmpty(params.get("code")), WaitPakin::getCode, params.get("code"))
                .eq(WaitPakin::getIoStatus, PakinIOStatus.PAKIN_IO_STATUS_DONE.val));
        if (Objects.isNull(waitPakin)) {
            return R.error("未找到该容器码的组托明细,请检查组托状态");
            return R.error("未找到该料箱码的组托明细,请检查组托状态");
        }
        List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>()
                .eq(WaitPakinItem::getPakinId, waitPakin.getId()));
@@ -1252,10 +1297,14 @@
     */
    @Override
    public R getDeviceSites() {
        List<DeviceSite> sites = deviceSiteMapper.selectList(new LambdaQueryWrapper<DeviceSite>()
        // 先查全部再按 site 去重,避免 GROUP BY 与 only_full_group_by 冲突
        List<DeviceSite> all = deviceSiteMapper.selectList(new LambdaQueryWrapper<DeviceSite>()
                .select(DeviceSite::getId, DeviceSite::getSite, DeviceSite::getName)
                .eq(DeviceSite::getStatus, 1)
                .groupBy(DeviceSite::getSite, DeviceSite::getId, DeviceSite::getName));
                .eq(DeviceSite::getStatus, 1));
        List<DeviceSite> sites = all.stream()
                .collect(Collectors.toMap(DeviceSite::getSite, d -> d, (a, b) -> a))
                .values().stream()
                .collect(Collectors.toList());
        return R.ok(sites);
    }
@@ -1304,11 +1353,11 @@
                    .setMaktx(asnOrderItem.getMaktx())
                    .setFieldsIndex(asnOrderItem.getFieldsIndex())
                    .setBarcode(asnOrderItem.getTrackCode())
                    .setQty(asnOrderItem.getQty())
                    .setQty(QuantityUtils.roundToScale(asnOrderItem.getQty()))
                    .setStockUnit(asnOrderItem.getStockUnit())
                    .setPurUnit(asnOrderItem.getPurUnit())
                    .setPoCode(asnOrderItem.getPoCode())
                    .setAnfme(asnOrderItem.getAnfme())
                    .setAnfme(QuantityUtils.roundToScale(asnOrderItem.getAnfme()))
                    .setPurQty(asnOrderItem.getPurQty())
                    .setSplrBatch(asnOrderItem.getSplrBatch())
                    .setExtendFields(asnOrderItem.getExtendFields())
@@ -1339,7 +1388,7 @@
            if (Objects.isNull(stockItem)) {
                detlsDto.setStockQty(0.0);
            } else {
                Double anfme = Math.round((stockItem.getAnfme() + stockItem.getWorkQty()) * 1000000) / 1000000.0;
                Double anfme = QuantityUtils.add(stockItem.getAnfme(), stockItem.getWorkQty());
                detlsDto.setStockQty(anfme);
            }