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;
|
private Long actualWarehouseId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 实际库区IDs(逗号分隔)
|
||||||
|
*/
|
||||||
|
private String actualWarehouseIds;
|
||||||
|
|
||||||
//材料类型
|
//材料类型
|
||||||
@NotBlank(message = "材料类型不能为空", groups = { AddGroup.class, EditGroup.class })
|
@NotBlank(message = "材料类型不能为空", groups = { AddGroup.class, EditGroup.class })
|
||||||
private String materialType;
|
private String materialType;
|
||||||
|
|||||||
@@ -1076,24 +1076,47 @@ public class WmsMaterialCoilServiceImpl implements IWmsMaterialCoilService {
|
|||||||
qw.isNotNull("mc.transfer_type");
|
qw.isNotNull("mc.transfer_type");
|
||||||
qw.ne("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() != null) {
|
||||||
if (bo.getActualWarehouseId() == -1) {
|
actualWarehouseIdList.add(bo.getActualWarehouseId());
|
||||||
// 当actualWarehouseId为-1时,查询actual_warehouse_id为空的记录(无库区)
|
}
|
||||||
qw.isNull("mc.actual_warehouse_id");
|
if (StringUtils.isNotBlank(bo.getActualWarehouseIds())) {
|
||||||
} else {
|
String[] actualWarehouseIdArray = bo.getActualWarehouseIds().split(",");
|
||||||
// 正常传值时,需要处理库位的层级关系
|
for (String actualWarehouseIdStr : actualWarehouseIdArray) {
|
||||||
// 如果传入的是二级库位,需要查询其下所有的三级/四级库位
|
if (StringUtils.isNotBlank(actualWarehouseIdStr)) {
|
||||||
List<Long> warehouseIds = getWarehouseIdsIncludingChildren(bo.getActualWarehouseId());
|
try {
|
||||||
if (warehouseIds.isEmpty()) {
|
actualWarehouseIdList.add(Long.parseLong(actualWarehouseIdStr.trim()));
|
||||||
// 如果没有找到任何库位,则直接匹配该ID
|
} catch (NumberFormatException ignore) {
|
||||||
qw.eq("mc.actual_warehouse_id", bo.getActualWarehouseId());
|
}
|
||||||
} else {
|
|
||||||
// 使用IN查询包含该库位及其所有子库位的钢卷
|
|
||||||
qw.in("mc.actual_warehouse_id", warehouseIds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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未空时候
|
// // 新增查询逻辑也就是当saleId未空时候
|
||||||
// if (bo.getSaleId() != null) {
|
// if (bo.getSaleId() != null) {
|
||||||
// if (bo.getSaleId() == -1) {
|
// if (bo.getSaleId() == -1) {
|
||||||
|
|||||||
Reference in New Issue
Block a user