3.11需求变更:1、/component/top/list实现;2、/assembly/list列表接口实现;2、加工接口修改为只修改本身,新增加工状态恢复接口;

This commit is contained in:
gaoqr
2026-03-12 15:57:17 +08:00
parent 4b93fc14bf
commit ebee7a2630
16 changed files with 390 additions and 161 deletions
@@ -193,4 +193,5 @@ public class ErrorCodeConstants {
public static final ErrorCode ORDER_COMPONENT_PROCESSED_REPEAT = new ErrorCode(1_003_010_004, "order.component.processed.repeat");
public static final ErrorCode ORDER_COMPONENT_ASSEMBLY_CONFIG_QUERY_ERROR = new ErrorCode(1_003_010_005, "order.component.assembly.config.query.error");
public static final ErrorCode ORDER_COMPONENT_NOT_PROCESS = new ErrorCode(1_003_010_006, "order.component.not.process");
public static final ErrorCode ORDER_COMPONENT_RESTORE_REPEAT = new ErrorCode(1_003_010_007, "order.component.restore.repeat");
}
@@ -61,4 +61,12 @@ public class AssemblyListController {
assemblyListService.processComponent(id);
return CommonResult.success(true);
}
@PostMapping("/restore/{id}")
@Operation(summary = "装配清单-恢复未加工")
@Parameter(name = "id", description = "部件编号", required = true, example = "1024")
public CommonResult<Boolean> restoreComponent(@PathVariable Long id) {
assemblyListService.restoreComponent(id);
return CommonResult.success(true);
}
}
@@ -7,6 +7,7 @@ import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrderDetai
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrderDetailComponentPageReqVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrdersTopComponentListReqVO;
import com.cf.imes.module.executor.controller.admin.plate.vo.OrderViewPlatePageRespVO;
import com.cf.imes.module.executor.service.assemblylist.AssemblyListService;
import com.cf.imes.module.executor.service.ordercomponent.OrderComponentService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@@ -41,6 +42,9 @@ public class OrderComponentController {
@Resource
private OrderComponentService orderComponentService;
@Resource
private AssemblyListService assemblyListService;
@PostMapping("/detail/list")
@Operation(summary = "查询订单详情部件列表")
public CommonResult<List<OrderComponentRespVO>> getOrderComponentList(@Valid @RequestBody OrderDetailComponentListReqVO reqVO) {
@@ -50,7 +54,7 @@ public class OrderComponentController {
@PostMapping("/top/list")
@Operation(summary = "查询订单顶级部件列表")
public CommonResult<List<OrderComponentRespVO>> getOrderTopComponentList(@Valid @RequestBody OrdersTopComponentListReqVO reqVO) {
return success(orderComponentService.getOrderTopComponentList(reqVO));
return success(assemblyListService.getOrderTopComponentList(reqVO));
}
@PostMapping("/view/list")
@@ -1,5 +1,7 @@
package com.cf.imes.module.executor.controller.admin.ordercomponent.vo;
import com.cf.imes.framework.common.validation.InEnum;
import com.cf.imes.module.executor.enums.ordercomponent.OrderComponentProcessStatusEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Size;
import lombok.AllArgsConstructor;
@@ -33,4 +35,7 @@ public class OrdersTopComponentListReqVO {
@Length(max = 64, message = "{order.component.assemble.req.name.max}")
private String name;
@Schema(description = "加工状态:0不加工、1未加工、2已加工、3部分加工", example = "1")
@InEnum(OrderComponentProcessStatusEnum.class)
private List<Integer> processStatus;
}
@@ -28,7 +28,12 @@ public enum OrderComponentProcessStatusEnum implements IntArrayValuable {
/**
* 已加工
*/
PROCESSED(2);
PROCESSED(2),
/**
* 部分加工
*/
PART_PROCESSED(3);
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(OrderComponentProcessStatusEnum::getStatus).toArray();
@@ -3,6 +3,7 @@ package com.cf.imes.module.executor.service.assemblylist;
import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.module.executor.controller.admin.assemblylist.vo.AssemblyListComponentPageReqVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrderComponentRespVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrdersTopComponentListReqVO;
import com.cf.imes.module.executor.controller.admin.plate.vo.OrderViewPlatePageRespVO;
import java.util.List;
@@ -42,4 +43,18 @@ public interface AssemblyListService {
* @param id
*/
void processComponent(Long id);
/**
* 恢复部件未加工状态
* @param id
*/
void restoreComponent(Long id);
/**
* 查询订单顶级部件列表
*
* @param reqVO
* @return
*/
List<OrderComponentRespVO> getOrderTopComponentList(OrdersTopComponentListReqVO reqVO);
}
@@ -18,9 +18,11 @@ import com.cf.imes.framework.common.pojo.PageResult;
import com.cf.imes.framework.common.util.Assert.AssertUtils;
import com.cf.imes.framework.common.util.json.JsonUtils;
import com.cf.imes.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cf.imes.framework.security.core.util.SecurityFrameworkUtils;
import com.cf.imes.module.executor.controller.admin.assemblylist.vo.AssemblyListComponentPageReqVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrderComponentRespVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrderComponentTreeCompareVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrdersTopComponentListReqVO;
import com.cf.imes.module.executor.controller.admin.plate.vo.OrderViewPlatePageRespVO;
import com.cf.imes.module.executor.dal.dataobject.orderItem.OrderBodyViewPlatesPageDO;
import com.cf.imes.module.executor.dal.dataobject.ordercomponent.OrderComponentDO;
@@ -43,6 +45,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
@@ -50,6 +53,7 @@ import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_COMPONE
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_COMPONENT_NOT_EXIST;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_COMPONENT_NOT_PROCESS;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_COMPONENT_PROCESSED_REPEAT;
import static com.cf.imes.module.executor.enums.ErrorCodeConstants.ORDER_COMPONENT_RESTORE_REPEAT;
/**
* 装配清单 ServiceImpl 实现类
@@ -74,6 +78,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
@Override
public List<OrderComponentRespVO> getComponentList(AssemblyListComponentPageReqVO reqVO) {
Set<Long> componentIds = reqVO.getComponentIds();
List<Long> orderIds = reqVO.getOrderIds();
if (CollUtil.isEmpty(componentIds)) {
return Collections.emptyList();
}
@@ -81,7 +86,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
// 查询入参部件
List<OrderComponentDO> componentDOS = orderComponentMapper.selectList(new LambdaUpdateWrapper<OrderComponentDO>()
.in(OrderComponentDO::getId, componentIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds()));
.in(OrderComponentDO::getOrderId, orderIds));
if (CollUtil.isEmpty(componentDOS) || componentDOS.size() != componentIds.size()) {
throw new ServiceException(ORDER_COMPONENT_NOT_EXIST);
}
@@ -91,19 +96,21 @@ public class AssemblyListServiceImpl implements AssemblyListService {
.map(OrderComponentDO::getTopId)
.toList();
OrderComponentProcessStatusEnum orderComponentProcessStatusEnum = OrderComponentProcessStatusEnum.fromValue(reqVO.getProcessStatus());
if (OrderComponentProcessStatusEnum.NOT_PROCESS.equals(orderComponentProcessStatusEnum)) {
// 不加工
return getNotProcessComponentList(reqVO, topIds);
} else if (OrderComponentProcessStatusEnum.UNPROCESSED.equals(orderComponentProcessStatusEnum)) {
// 未加工
return getUnProcessedComponentList(reqVO, topIds, false);
} else if (OrderComponentProcessStatusEnum.PROCESSED.equals(orderComponentProcessStatusEnum)) {
// 已加工
return getProcessedComponentList(reqVO, topIds);
} else {
return getUnProcessedComponentList(reqVO, topIds, true);
// 根据部件的topid查询树上所有已加工节点
List<OrderComponentDO> topUnProcessedComponentList = orderComponentMapper.selectList(new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getTopId, topIds)
.in(OrderComponentDO::getOrderId, orderIds)
.select(OrderComponentDO::getId, OrderComponentDO::getPid, OrderComponentDO::getName, OrderComponentDO::getProcessStatus));
// 计算部件状态
List<OrderComponentTreeCompareVO> treeCompareVOS = calculateProcessingStatusAccordingToAssemblyConfig(topUnProcessedComponentList);
List<OrderComponentRespVO> result = new ArrayList<>();
// 树形扁平化
for (OrderComponentTreeCompareVO vo : treeCompareVOS) {
flatTree(vo, result);
}
return result;
}
/**
@@ -123,7 +130,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
return orderComponentTreeRespVOS;
}
CommonResult<List<AssemblyConfigRespDTO>> assemblyConfigByComponentNameListResult = assemblyConfigApi.getAssemblyConfigByPartNameList(topComponentNames);
if(assemblyConfigByComponentNameListResult.isError()) {
if (assemblyConfigByComponentNameListResult.isError()) {
throw new ServiceException(ORDER_COMPONENT_ASSEMBLY_CONFIG_QUERY_ERROR);
}
List<AssemblyConfigRespDTO> assemblyConfigByComponentNameList = assemblyConfigByComponentNameListResult.getData();
@@ -136,7 +143,6 @@ public class AssemblyListServiceImpl implements AssemblyListService {
(v1, v2) -> v1 // 如果重复保留第一个
));
// 从当前树的顶级中匹配name+hash,匹配上的存id:json用于解析加工状态
Map<Long, String> result = orderComponentTreeRespVOS.stream()
.map(vo -> {
@@ -168,77 +174,6 @@ public class AssemblyListServiceImpl implements AssemblyListService {
return orderComponentTreeRespVOS;
}
/**
* 查询已配置的部件列表
*
* @return
*/
private List<OrderComponentRespVO> getProcessedComponentList(AssemblyListComponentPageReqVO reqVO, List<Long> topIds) {
// 根据部件的topid查询树上所有已加工节点
List<OrderComponentDO> topProcessedComponentList = orderComponentMapper.selectList(new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getTopId, topIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.likeIfPresent(OrderComponentDO::getName, reqVO.getName())
.eqIfPresent(OrderComponentDO::getProcessStatus, OrderComponentProcessStatusEnum.PROCESSED.getStatus())
.select(OrderComponentDO::getId, OrderComponentDO::getPid, OrderComponentDO::getName, OrderComponentDO::getProcessStatus));
return BeanUtil.copyToList(topProcessedComponentList, OrderComponentRespVO.class);
}
/**
* 查询未加工的部件列表
*
* @param topIds
* @param reqVO
* @return
*/
private List<OrderComponentRespVO> getUnProcessedComponentList(AssemblyListComponentPageReqVO reqVO, List<Long> topIds, boolean showAll) {
// 根据部件的topid查询树上所有已加工节点
List<OrderComponentDO> topUnProcessedComponentList = orderComponentMapper.selectList(new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getTopId, topIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.likeIfPresent(OrderComponentDO::getName, reqVO.getName())
.neIfPresent(OrderComponentDO::getProcessStatus, showAll ? null : OrderComponentProcessStatusEnum.PROCESSED.getStatus())
.select(OrderComponentDO::getId, OrderComponentDO::getPid, OrderComponentDO::getName, OrderComponentDO::getProcessStatus));
// 计算部件状态
List<OrderComponentTreeCompareVO> treeCompareVOS = calculateProcessingStatusAccordingToAssemblyConfig(topUnProcessedComponentList);
List<OrderComponentRespVO> result = new ArrayList<>();
// 树形扁平化
for (OrderComponentTreeCompareVO vo : treeCompareVOS) {
flatTree(vo, result);
}
return result;
}
/**
* 查询不加工的部件列表
*
* @param topIds
* @param reqVO
* @return
*/
private List<OrderComponentRespVO> getNotProcessComponentList(AssemblyListComponentPageReqVO reqVO, List<Long> topIds) {
// 根据部件的topid查询树上所有节点
List<OrderComponentDO> topComponentList = orderComponentMapper.selectList(new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getTopId, topIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.likeIfPresent(OrderComponentDO::getName, reqVO.getName())
.select(OrderComponentDO::getId, OrderComponentDO::getPid, OrderComponentDO::getName, OrderComponentDO::getProcessStatus));
// 计算部件状态
List<OrderComponentTreeCompareVO> treeCompareVOS = calculateProcessingStatusAccordingToAssemblyConfig(topComponentList);
List<OrderComponentRespVO> result = new ArrayList<>();
// 树形扁平化
for (OrderComponentTreeCompareVO vo : treeCompareVOS) {
flatTree(vo, result);
}
return result.stream().filter(o -> ObjectUtil.equals(o.getProcessStatus(), OrderComponentProcessStatusEnum.NOT_PROCESS.getStatus())).toList();
}
/**
* 构建树
*
@@ -375,7 +310,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
* @param result
*/
private void flatTree(OrderComponentTreeCompareVO node,
List<OrderComponentRespVO> result) {
List<OrderComponentRespVO> result) {
if (node == null) {
return;
@@ -402,12 +337,35 @@ public class AssemblyListServiceImpl implements AssemblyListService {
@Override
public void processComponent(Long id) {
// 未加工 -> 加工
handleComponentProcessStatus(id, OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(), OrderComponentProcessStatusEnum.PROCESSED.getStatus());
}
@Override
public void restoreComponent(Long id) {
// 加工 -> 未加工
handleComponentProcessStatus(id, OrderComponentProcessStatusEnum.PROCESSED.getStatus(), OrderComponentProcessStatusEnum.UNPROCESSED.getStatus());
}
/**
* 处理部件加工状态
*
* @param id
* @param sourceProcessStatus 来源加工状态
* @param targetProcessStatus 目标加工状态
*/
private void handleComponentProcessStatus(Long id, Integer sourceProcessStatus, Integer targetProcessStatus) {
// 查询和校验部件
OrderComponentDO componentDO = orderComponentMapper.selectById(id);
AssertUtils.notEmpty(componentDO, ORDER_COMPONENT_NOT_EXIST);
AssertUtils.equals(componentDO.getProcessStatus(), OrderComponentProcessStatusEnum.PROCESSED.getStatus(), ORDER_COMPONENT_PROCESSED_REPEAT);
if (ObjectUtil.equals(OrderComponentProcessStatusEnum.PROCESSED.getStatus(), sourceProcessStatus)) {
AssertUtils.equals(componentDO.getProcessStatus(), OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(), ORDER_COMPONENT_RESTORE_REPEAT);
}
if (ObjectUtil.equals(OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(), sourceProcessStatus)) {
AssertUtils.equals(componentDO.getProcessStatus(), OrderComponentProcessStatusEnum.PROCESSED.getStatus(), ORDER_COMPONENT_PROCESSED_REPEAT);
}
int level = componentDO.getLevel();
Long organId = componentDO.getOrganId();
Long orderId = componentDO.getOrderId();
@@ -449,38 +407,30 @@ public class AssemblyListServiceImpl implements AssemblyListService {
OrderComponentTreeCompareVO structure = JSON.parseObject(JsonUtils.unzipString(structureJson), OrderComponentTreeCompareVO.class);
// 筛选出需要加工的部件id列表
List<Long> needProcessComponentIds = getNeedProcessIdsByAssemblyConfig(currentTreeCompareVO, structure, id);
if (CollUtil.isEmpty(needProcessComponentIds)) {
Long needProcessComponentId = getNeedProcessIdsByAssemblyConfig(currentTreeCompareVO, structure, id);
if (ObjectUtil.isNull(needProcessComponentId)) {
return;
}
// 更新加工状态
orderComponentMapper.update(new LambdaUpdateWrapper<OrderComponentDO>()
.in(OrderComponentDO::getId, needProcessComponentIds)
.eq(OrderComponentDO::getId, needProcessComponentId)
.eq(OrderComponentDO::getOrderId, orderId)
.eq(OrderComponentDO::getOrganId, organId)
.ge(OrderComponentDO::getLevel, level)
.eq(OrderComponentDO::getProcessStatus, OrderComponentProcessStatusEnum.UNPROCESSED.getStatus())
.eq(OrderComponentDO::getProcessStatus, sourceProcessStatus)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getProcessStatus, OrderComponentProcessStatusEnum.PROCESSED.getStatus())
.set(OrderComponentDO::getProcessStatus, targetProcessStatus)
);
}
} else {
// 没有对应的装配设置,更新未加工的本身和下级
List<Long> needProcessComponentIds = topProcessedComponentList.stream().filter(o ->
ObjectUtil.notEqual(OrderComponentProcessStatusEnum.PROCESSED.getStatus(), o.getProcessStatus()) && o.getLevel() >= level).map(OrderComponentDO::getId).toList();
if (CollUtil.isEmpty(needProcessComponentIds)) {
return;
}
orderComponentMapper.update(new LambdaUpdateWrapper<OrderComponentDO>()
.in(OrderComponentDO::getId, needProcessComponentIds)
.eq(OrderComponentDO::getId, id)
.eq(OrderComponentDO::getOrderId, orderId)
.eq(OrderComponentDO::getOrganId, organId)
.ge(OrderComponentDO::getLevel, level)
.eq(OrderComponentDO::getProcessStatus, OrderComponentProcessStatusEnum.UNPROCESSED.getStatus())
.eq(OrderComponentDO::getProcessStatus, sourceProcessStatus)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getProcessStatus, OrderComponentProcessStatusEnum.PROCESSED.getStatus())
.set(OrderComponentDO::getProcessStatus, targetProcessStatus)
);
}
}
@@ -488,10 +438,10 @@ public class AssemblyListServiceImpl implements AssemblyListService {
/**
* 点击加工入口方法
*/
public static List<Long> getNeedProcessIdsByAssemblyConfig(OrderComponentTreeCompareVO aRoot, OrderComponentTreeCompareVO bRoot, Long currentComponentId) {
public static Long getNeedProcessIdsByAssemblyConfig(OrderComponentTreeCompareVO aRoot, OrderComponentTreeCompareVO bRoot, Long currentComponentId) {
if (aRoot == null || bRoot == null || currentComponentId == null) {
return Collections.emptyList();
return null;
}
// 1. 构建 B 的 processMap
@@ -500,7 +450,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
// 2. 找到 A 中点击的节点
OrderComponentTreeCompareVO startNode = findNodeById(aRoot, currentComponentId);
if (startNode == null) {
return Collections.emptyList();
return null;
}
// 判断当前节点是否允许加工
@@ -511,8 +461,8 @@ public class AssemblyListServiceImpl implements AssemblyListService {
throw new ServiceException(ORDER_COMPONENT_NOT_PROCESS);
}
// 3. 过滤需要加工的节点
return collectNeedProcessNodes(startNode, processMap);
// 3. 本身没有不加工,返回id
return currentComponentId;
}
/**
@@ -568,44 +518,6 @@ public class AssemblyListServiceImpl implements AssemblyListService {
return map;
}
/**
* 收集需要加工的节点
*/
private static List<Long> collectNeedProcessNodes(
OrderComponentTreeCompareVO startNode,
Map<String, Boolean> processMap) {
List<Long> result = new ArrayList<>();
Deque<OrderComponentTreeCompareVO> stack = new ArrayDeque<>();
stack.push(startNode);
while (!stack.isEmpty()) {
OrderComponentTreeCompareVO node = stack.pop();
String key = buildKey(node.getName(), node.getLevel());
Boolean configProcess = processMap.get(key);
boolean allowProcess = !Boolean.FALSE.equals(configProcess);
boolean alreadyProcessed = OrderComponentProcessStatusEnum.PROCESSED.getStatus().equals(node.getProcessStatus());
// 规则 1:B 中配置为 false → 不加入
// 规则 2:已经加工过 → 不加入
if (allowProcess && !alreadyProcessed) {
result.add(node.getId());
}
if (node.getChildren() != null) {
for (OrderComponentTreeCompareVO child : node.getChildren()) {
stack.push(child);
}
}
}
return result;
}
/**
* 构建匹配 key
*/
@@ -675,7 +587,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
List<OrderBodyViewPlatesPageDO> records = pageRes.getRecords();
List<OrderViewPlatePageRespVO> resultList = new ArrayList<>();
if(total > 0) {
if (total > 0) {
resultList = records.stream().map(item -> {
OrderViewPlatePageRespVO vo = new OrderViewPlatePageRespVO();
BeanUtil.copyProperties(item, vo);
@@ -736,7 +648,7 @@ public class AssemblyListServiceImpl implements AssemblyListService {
List<OrderBodyViewPlatesPageDO> records = viewPlatesPage.getRecords();
List<OrderViewPlatePageRespVO> resultList = new ArrayList<>();
if(CollUtil.isNotEmpty(records)) {
if (CollUtil.isNotEmpty(records)) {
resultList = records.stream().map(item -> {
OrderViewPlatePageRespVO vo = new OrderViewPlatePageRespVO();
BeanUtil.copyProperties(item, vo);
@@ -788,4 +700,209 @@ public class AssemblyListServiceImpl implements AssemblyListService {
}
return needDeleteIds;
}
@Override
public List<OrderComponentRespVO> getOrderTopComponentList(OrdersTopComponentListReqVO reqVO) {
/**
* 规则:
* 部件装配的状态:
* 1、已加工:部件根节点已加工
* 2、未加工:部件根节点未加工,且子节点均为未加工状态
* 3、部份加工:部件根节点未加工,且子节点至少有一个已加工
* 4、不加工: 部件装配设置中至少有一个节点标记为不加工
*/
if (CollUtil.isEmpty(reqVO.getOrderIds())) {
return Collections.emptyList();
}
List<TopComponentState> states = buildTopComponentStates(reqVO);
if (CollUtil.isEmpty(states)) {
return Collections.emptyList();
}
Set<OrderComponentProcessStatusEnum> statusSet =
Optional.ofNullable(reqVO.getProcessStatus())
.orElse(Collections.emptyList())
.stream()
.map(OrderComponentProcessStatusEnum::fromValue)
.collect(Collectors.toSet());
List<OrderComponentTreeCompareVO> result = states.stream()
.filter(state -> matchAnyStatus(state, statusSet))
.map(state -> state.node)
.toList();
return BeanUtil.copyToList(result, OrderComponentRespVO.class);
}
private List<TopComponentState> buildTopComponentStates(OrdersTopComponentListReqVO reqVO) {
List<OrderComponentDO> topComponents = orderComponentMapper.selectList(
new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.eq(OrderComponentDO::getPid, OrderComponentDO.PARENT_ID_ROOT)
.likeIfPresent(OrderComponentDO::getName, reqVO.getName())
);
if (CollUtil.isEmpty(topComponents)) {
return Collections.emptyList();
}
List<String> names = topComponents.stream()
.map(OrderComponentDO::getName)
.distinct()
.toList();
List<Long> topIds = topComponents.stream()
.map(OrderComponentDO::getId)
.toList();
// 查询不加工配置
CommonResult<List<AssemblyConfigRespDTO>> configResult =
assemblyConfigApi.getNotProcessAssemblyConfigByPartNameList(names);
if (configResult.isError()) {
throw new ServiceException(ORDER_COMPONENT_ASSEMBLY_CONFIG_QUERY_ERROR);
}
Set<String> configSet = configResult.getData().stream()
.map(dto -> dto.getComponentName() + "#" + dto.getStructureHash())
.collect(Collectors.toSet());
// 查询整棵树
List<OrderComponentDO> allNodes = orderComponentMapper.selectList(
new LambdaQueryWrapperX<OrderComponentDO>()
.in(OrderComponentDO::getTopId, topIds)
.in(OrderComponentDO::getOrderId, reqVO.getOrderIds())
.select(OrderComponentDO::getId,
OrderComponentDO::getPid,
OrderComponentDO::getName,
OrderComponentDO::getProcessStatus)
);
List<OrderComponentTreeCompareVO> tree = buildTree(allNodes);
List<TopComponentState> result = new ArrayList<>();
for (OrderComponentTreeCompareVO root : tree) {
ProcessStats stats = analyzeTree(root);
TopComponentState state = new TopComponentState();
state.node = root;
state.rootProcessed = ObjectUtil.equals(root.getProcessStatus(), OrderComponentProcessStatusEnum.PROCESSED.getStatus());
state.allUnprocessed = stats.allUnprocessed;
state.anyChildProcessed = stats.anyChildProcessed;
state.notProcessConfig =
configSet.contains(root.getName() + "#" + root.getStructureHash());
result.add(state);
}
return result;
}
private ProcessStats analyzeTree(OrderComponentTreeCompareVO node) {
ProcessStats stats = new ProcessStats();
// 默认认为全未加工
stats.allUnprocessed =
ObjectUtil.equals(OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(),
node.getProcessStatus());
stats.anyChildProcessed = false;
List<OrderComponentTreeCompareVO> children = node.getChildren();
if (CollUtil.isNotEmpty(children)) {
for (OrderComponentTreeCompareVO child : children) {
ProcessStats childStats = analyzeTree(child);
// 只要有一个不是未加工
if (!childStats.allUnprocessed) {
stats.allUnprocessed = false;
}
// 子树存在已加工
if (childStats.anyChildProcessed ||
ObjectUtil.equals(OrderComponentProcessStatusEnum.PROCESSED.getStatus(),
child.getProcessStatus())) {
stats.anyChildProcessed = true;
}
}
}
return stats;
}
private boolean matchAnyStatus(TopComponentState state,
Set<OrderComponentProcessStatusEnum> statusSet) {
if (CollUtil.isEmpty(statusSet)) {
return true;
}
for (OrderComponentProcessStatusEnum status : statusSet) {
switch (status) {
case PROCESSED:
if (state.rootProcessed) {
return true;
}
break;
case UNPROCESSED:
if (!state.rootProcessed
&& state.allUnprocessed
&& !state.notProcessConfig) {
return true;
}
break;
case PART_PROCESSED:
if (!state.rootProcessed
&& state.anyChildProcessed
&& !state.notProcessConfig) {
return true;
}
break;
case NOT_PROCESS:
if (state.notProcessConfig) {
return true;
}
break;
}
}
return false;
}
class ProcessStats {
boolean allUnprocessed = true;
boolean anyChildProcessed = false;
}
class TopComponentState {
OrderComponentTreeCompareVO node;
boolean rootProcessed;
boolean allUnprocessed;
boolean anyChildProcessed;
boolean notProcessConfig;
}
}
@@ -32,4 +32,5 @@ order.component.restore.parent.is.deleted=该部件上级已被删除,请先
order.component.no.need.to.restore=该部件未删除,无需恢复
order.component.processed.repeat=该部件已加工勿重复操作,请刷新列表后检查状态
order.component.assembly.config.query.error=装配设置查询失败,请检查服务状态
order.component.not.process=当前部件无需加工,请刷新列表后检查状态
order.component.not.process=当前部件无需加工,请刷新列表后检查状态
order.component.restore.repeat=该部件已恢复勿重复操作,请刷新列表后检查状态
@@ -32,4 +32,5 @@ order.component.restore.parent.is.deleted=該部件上級已被删除,請先
order.component.no.need.to.restore=該部件未删除,無需恢復
order.component.processed.repeat=該部件已加工勿重複操作,請重繪清單後檢查狀態
order.component.assembly.config.query.error=裝配設定査詢失敗,請檢查服務狀態
order.component.not.process=當前部件無需加工,請重繪清單後檢查狀態
order.component.not.process=當前部件無需加工,請重繪清單後檢查狀態
order.component.restore.repeat=該部件已恢復勿重複操作,請重繪清單後檢查狀態
@@ -32,4 +32,5 @@ order.component.restore.parent.is.deleted=The upper level of this component has
order.component.no.need.to.restore=This component has not been deleted and does not need to be restored
order.component.processed.repeat=This component has been processed and should not be operated repeatedly. Please refresh the list and check the status
order.component.assembly.config.query.error=Assembly settings query failed, please check service status
order.component.not.process=The current component does not require processing. Please refresh the list and check the status
order.component.not.process=The current component does not require processing. Please refresh the list and check the status
order.component.restore.repeat=The component has been restored. Do not repeat the operation. Please refresh the list and check the status