chen.lin
3 天以前 f679ac0947417416900ab28308dd3bf235336078
rsf-server/src/main/java/com/vincent/rsf/server/api/service/impl/MobileServiceImpl.java
@@ -623,57 +623,74 @@
        //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) {
            // 单个条件,直接查询
        // 如果有ASN单号,则只查询该单号下的物料(ASN单号作为必须条件)
        if (!Cools.isEmpty(asnCode)) {
            // ASN单号作为必须条件
            queryWrapper.eq(WarehouseAreasItem::getAsnCode, asnCode);
            // 如果同时有物料编码,则查询该ASN单号下的该物料
            if (!Cools.isEmpty(matnrCode)) {
                queryWrapper.eq(WarehouseAreasItem::getMatnrCode, matnrCode);
            }
            // 如果同时有批次,则查询该ASN单号下的该批次
            if (!Cools.isEmpty(batch)) {
                queryWrapper.eq(WarehouseAreasItem::getSplrBatch, batch);
            }
            // 如果同时有票号,则查询该ASN单号下的该票号
            if (!Objects.isNull(fieldIndex)) {
                queryWrapper.eq(WarehouseAreasItem::getFieldsIndex, fieldIndex);
            }
            // 如果同时有跟踪码,则查询该ASN单号下的该跟踪码
            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);
            }
        } else {
            // 多个条件,使用OR连接
            queryWrapper.and(wrapper -> {
                boolean first = true;
            // 没有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 +962,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())
@@ -1154,15 +1171,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 -> {
@@ -1252,10 +1269,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);
    }