/component/direct-children接口修改为同时查询下级部件+板件配件,替换两个id列表入参的模式

This commit is contained in:
gaoqr
2026-07-14 17:48:48 +08:00
parent cfaa9796d1
commit 12854d7fb4
2 changed files with 19 additions and 85 deletions
@@ -17,13 +17,9 @@ import java.util.List;
@Schema(description = "装配清单 - 查询部件子元素表格请求")
public class AssemblyComponentChildPrintReqVO {
@Schema(description = "上级部件ID列表", example = "[1001, 1002]")
@Size(max = 200)
@Size(max = 1000)
private List<Long> componentIds;
@Schema(description = "底层部件ID列表", example = "[1003, 1004]")
@Size(max = 200)
private List<Long> bottomComponentIds;
@Schema(description = "订单 ID 列表", example = "[10001, 10002]", requiredMode = Schema.RequiredMode.REQUIRED)
@NotEmpty(message = "订单 ID 不能为空")
@Size(max = 100)
@@ -225,50 +225,16 @@ public class AssemblyListServiceImpl implements AssemblyListService {
@Override
public List<AssemblyComponentChildPrintRespVO> getDirectChildComponentList(AssemblyComponentChildPrintReqVO reqVO) {
/*
* componentIds
* 查询这些部件的“直接下级部件”。
*
* bottomComponentIds
* 查询这些部件直属的“板件、配件”。
*
* 两个集合之间允许存在相同 ID。
* 相同 ID 在两个集合中时,必须返回两个独立父节点:
* 1. 一个节点只承载直接下级部件;
* 2. 一个节点只承载板件、配件。
*/
List<Long> componentIds = new ArrayList<>(new LinkedHashSet<>(
Optional.ofNullable(reqVO.getComponentIds()).orElseGet(Collections::emptyList)));
List<Long> bottomComponentIds = new ArrayList<>(new LinkedHashSet<>(
Optional.ofNullable(reqVO.getBottomComponentIds()).orElseGet(Collections::emptyList)));
if (CollUtil.isEmpty(componentIds) && CollUtil.isEmpty(bottomComponentIds)) {
if (CollUtil.isEmpty(componentIds)) {
return Collections.emptyList();
}
/*
* 数据库查询时可合并去重,减少重复查库;
* 但仅用于查询,绝不能直接作为最终结果集。
*
* 原因:同一个部件同时出现在两个入参集合时,
* 最终需要返回两份不同用途的父节点数据。
*/
Set<Long> queryParentIds = new LinkedHashSet<>();
queryParentIds.addAll(componentIds);
queryParentIds.addAll(bottomComponentIds);
/*
* 部件与订单强关联:
* orderIds 必须参与查询,既限制本次查询范围,
* 也便于 MyCAT 按订单分片路由。
*/
// 查询入参部件的信息
Set<Long> queryIds = new LinkedHashSet<>(componentIds);
List<OrderComponentDO> parentComponents = orderComponentMapper.selectList(
new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getId, queryParentIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.in(OrderComponentDO::getId, queryIds)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.select(
OrderComponentDO::getId,
@@ -286,36 +252,24 @@ public class AssemblyListServiceImpl implements AssemblyListService {
* 2. 部件已删除;
* 3. 部件不属于前端传入的订单范围。
*/
if (parentComponents.size() != queryParentIds.size()) {
if (parentComponents.size() != queryIds.size()) {
throw new ServiceException(ORDER_COMPONENT_NOT_EXIST);
}
Map<Long, OrderComponentDO> componentDOMap = parentComponents.stream()
.collect(Collectors.toMap(OrderComponentDO::getId, Function.identity()));
List<Long> orderIds = parentComponents.stream()
.map(OrderComponentDO::getOrderId)
.distinct()
.toList();
/*
* 必须创建两份独立的父节点 Map。
*
* 即使 componentIds 和 bottomComponentIds 中包含相同的部件 ID
* 两个 Map 中也会存在两个不同的 RespVO 实例,防止子数据混合。
*/
Map<Long, AssemblyComponentChildPrintRespVO> directChildParentMap =
Map<Long, AssemblyComponentChildPrintRespVO> parentMap =
createPrintParentMap(componentIds, componentDOMap);
Map<Long, AssemblyComponentChildPrintRespVO> bottomComponentParentMap =
createPrintParentMap(bottomComponentIds, componentDOMap);
/*
* 第一类父节点:
* 仅查询并挂载“直接下级部件”。
*
* 这里按 pid 查询,只查一层,不递归查询孙级部件。
*/
if (CollUtil.isNotEmpty(componentIds)) {
List<OrderComponentDO> childComponents = orderComponentMapper.selectList(
new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getPid, componentIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.in(OrderComponentDO::getOrderId, orderIds)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.orderByAsc(OrderComponentDO::getId)
.select(
@@ -332,7 +286,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
for (OrderComponentDO child : childComponents) {
AssemblyComponentChildPrintRespVO parent =
directChildParentMap.get(child.getPid());
parentMap.get(child.getPid());
if (parent != null) {
// false:子部件不创建 children
@@ -341,11 +295,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
}
}
/*
* 第二类父节点:
* 仅查询并挂载直属板件、配件。
*/
if (CollUtil.isNotEmpty(bottomComponentIds)) {
{
/*
* 板件数量在业务上固定为 1。
* SQL 已根据 order_item.comp_id 取得板件归属部件,
@@ -353,7 +303,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
*/
List<AssemblyComponentChildPrintItemDO> plates =
orderItemMapper.selectAssemblyComponentPrintPlates(
reqVO.getOrderIds(), new LinkedHashSet<>(bottomComponentIds));
orderIds, new LinkedHashSet<>(componentIds));
/*
* 配件可能对应多条 order_item 明细。
@@ -361,14 +311,14 @@ public class AssemblyListServiceImpl implements AssemblyListService {
*/
List<AssemblyComponentChildPrintItemDO> partRows =
orderItemMapper.selectAssemblyComponentPrintParts(
reqVO.getOrderIds(), new LinkedHashSet<>(bottomComponentIds));
orderIds, new LinkedHashSet<>(componentIds));
List<AssemblyComponentChildPrintItemDO> parts =
mergeAssemblyComponentPrintParts(partRows);
for (AssemblyComponentChildPrintItemDO plate : plates) {
AssemblyComponentChildPrintRespVO parent =
bottomComponentParentMap.get(plate.getCompId());
parentMap.get(plate.getCompId());
if (parent != null) {
parent.getChildren().add(convertPrintItem(plate));
@@ -377,7 +327,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
for (AssemblyComponentChildPrintItemDO part : parts) {
AssemblyComponentChildPrintRespVO parent =
bottomComponentParentMap.get(part.getCompId());
parentMap.get(part.getCompId());
if (parent != null) {
parent.getChildren().add(convertPrintItem(part));
@@ -385,19 +335,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
}
}
/*
* 两类父节点分段返回,不能合并。
*
* 若同一部件 ID 同时位于两个集合:
* - 第一段:展示其直接下级部件;
* - 第二段:展示其板件、配件。
*/
List<AssemblyComponentChildPrintRespVO> result = new ArrayList<>(
directChildParentMap.size() + bottomComponentParentMap.size());
result.addAll(directChildParentMap.values());
result.addAll(bottomComponentParentMap.values());
return result;
return new ArrayList<>(parentMap.values());
}
/**