feat(WmsMaterialCoil): 添加实际库区IDs多值查询支持
- 新增 actualWarehouseIds 字段用于支持逗号分隔的多个库区ID查询 - 统一处理 actualWarehouseId 与 actualWarehouseIds 的查询逻辑 - 实现多值库区ID解析和层级展开功能 - 支持 -1 空库区条件与正常库区ID的组合查询 - 优化查询条件构建,支持 NULL 和 IN 条件的联合查询
This commit is contained in:
@@ -157,6 +157,11 @@ public class WmsMaterialCoilBo extends BaseEntity {
|
||||
|
||||
private Long actualWarehouseId;
|
||||
|
||||
/**
|
||||
* 实际库区IDs(逗号分隔)
|
||||
*/
|
||||
private String actualWarehouseIds;
|
||||
|
||||
//材料类型
|
||||
@NotBlank(message = "材料类型不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||
private String materialType;
|
||||
|
||||
@@ -1076,22 +1076,45 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
||||
qw.isNotNull("mc.transfer_type");
|
||||
qw.ne("mc.transfer_type", "");
|
||||
}
|
||||
// 如果actualWarehouseId不为空,则根据实际库区ID进行查询 如果为-1,则查询无库区的数据
|
||||
// 统一处理 actualWarehouseId 与 actualWarehouseIds(实际库区):
|
||||
// 将单值和逗号分隔的多值统一收集,支持层级展开与-1空库区查询
|
||||
List<Long> actualWarehouseIdList = new ArrayList<>();
|
||||
if (bo.getActualWarehouseId() != null) {
|
||||
if (bo.getActualWarehouseId() == -1) {
|
||||
// 当actualWarehouseId为-1时,查询actual_warehouse_id为空的记录(无库区)
|
||||
qw.isNull("mc.actual_warehouse_id");
|
||||
} else {
|
||||
// 正常传值时,需要处理库位的层级关系
|
||||
// 如果传入的是二级库位,需要查询其下所有的三级/四级库位
|
||||
List<Long> warehouseIds = getWarehouseIdsIncludingChildren(bo.getActualWarehouseId());
|
||||
if (warehouseIds.isEmpty()) {
|
||||
// 如果没有找到任何库位,则直接匹配该ID
|
||||
qw.eq("mc.actual_warehouse_id", bo.getActualWarehouseId());
|
||||
} else {
|
||||
// 使用IN查询包含该库位及其所有子库位的钢卷
|
||||
qw.in("mc.actual_warehouse_id", warehouseIds);
|
||||
actualWarehouseIdList.add(bo.getActualWarehouseId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(bo.getActualWarehouseIds())) {
|
||||
String[] actualWarehouseIdArray = bo.getActualWarehouseIds().split(",");
|
||||
for (String actualWarehouseIdStr : actualWarehouseIdArray) {
|
||||
if (StringUtils.isNotBlank(actualWarehouseIdStr)) {
|
||||
try {
|
||||
actualWarehouseIdList.add(Long.parseLong(actualWarehouseIdStr.trim()));
|
||||
} catch (NumberFormatException ignore) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!actualWarehouseIdList.isEmpty()) {
|
||||
List<Long> expandedIds = new ArrayList<>();
|
||||
boolean hasNullCondition = false;
|
||||
for (Long awId : actualWarehouseIdList) {
|
||||
if (awId != null && awId == -1) {
|
||||
hasNullCondition = true;
|
||||
} else if (awId != null && awId > 0) {
|
||||
List<Long> children = getWarehouseIdsIncludingChildren(awId);
|
||||
if (children.isEmpty()) {
|
||||
expandedIds.add(awId);
|
||||
} else {
|
||||
expandedIds.addAll(children);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (hasNullCondition && expandedIds.isEmpty()) {
|
||||
qw.isNull("mc.actual_warehouse_id");
|
||||
} else if (hasNullCondition && !expandedIds.isEmpty()) {
|
||||
qw.and(w -> w.isNull("mc.actual_warehouse_id")
|
||||
.or().in("mc.actual_warehouse_id", expandedIds.stream().distinct().collect(Collectors.toList())));
|
||||
} else if (!expandedIds.isEmpty()) {
|
||||
qw.in("mc.actual_warehouse_id", expandedIds.stream().distinct().collect(Collectors.toList()));
|
||||
}
|
||||
}
|
||||
// // 新增查询逻辑也就是当saleId未空时候
|
||||
|
||||
Reference in New Issue
Block a user