| | |
| | | //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); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | // 打印查询参数到控制台 |
| | |
| | | */ |
| | | @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); |
| | | } |
| | | |