1、新增cad拆单支持部件不加工状态判定;2、加工/恢复部件顶级部分加工状态判定处理;

This commit is contained in:
gaoqr
2026-05-29 17:57:59 +08:00
parent a1fbe33063
commit a1b5c12d0a
12 changed files with 875 additions and 139 deletions
@@ -27,6 +27,7 @@ import lombok.ToString;
@AllArgsConstructor
public class OrderComponentDO extends BaseDO {
public static final Long PARENT_ID_ROOT = 0L;
public static final Long TOP_LEVEL = 0L;
/**
* 主键
@@ -108,4 +109,9 @@ public class OrderComponentDO extends BaseDO {
* 加工状态
*/
private Integer processStatus;
/**
* 附加加工状态:不加工/部分加工(只有顶级)
*/
private Integer extraProcessStatus;
}
@@ -17,6 +17,7 @@ import com.cf.imes.framework.common.pojo.PageParam;
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.mybatis.core.query.LambdaUpdateWrapperX;
import com.cf.imes.module.executor.controller.admin.assemblylist.vo.AssemblyListComponentPageReqVO;
import com.cf.imes.module.executor.controller.admin.order.vo.order.OrdersViewCadViewInfoRespVO;
import com.cf.imes.module.executor.controller.admin.ordercomponent.vo.OrderComponentRespVO;
@@ -356,99 +357,190 @@ public class AssemblyListServiceImpl implements AssemblyListService {
/**
* 处理部件加工状态
*
* @param id
* @param sourceProcessStatus 来源加工状态
* @param targetProcessStatus 目标加工状态
* 规则:
* 1、顶级部件:
* - 自身加工 => extraProcessStatus = null
* - 自身未加工:
* 存在已加工子级 => PART_PROCESSED
* 否则 => null
*
* 2、子级部件:
* - 任意子级已加工 => 顶级 PART_PROCESSED
* - 所有子级未加工 => 顶级 null
*
* 3、子级自身 processStatus 正常更新
*/
private void handleComponentProcessStatus(Long id, Integer sourceProcessStatus, Integer targetProcessStatus) {
// 查询和校验部件
OrderComponentDO componentDO = orderComponentMapper.selectById(id);
AssertUtils.notEmpty(componentDO, ORDER_COMPONENT_NOT_EXIST);
if (ObjectUtil.equals(OrderComponentProcessStatusEnum.PROCESSED.getStatus(), sourceProcessStatus)) {
AssertUtils.equals(componentDO.getProcessStatus(), OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(), ORDER_COMPONENT_RESTORE_REPEAT);
private void handleComponentProcessStatus(Long id,
Integer sourceProcessStatus,
Integer targetProcessStatus) {
// =========================
// 1、查询和校验当前部件
// =========================
OrderComponentDO componentDO =
orderComponentMapper.selectById(id);
AssertUtils.notEmpty(
componentDO,
ORDER_COMPONENT_NOT_EXIST
);
// 不加工不可操作
AssertUtils.notEquals(
componentDO.getProcessStatus(),
OrderComponentProcessStatusEnum.NOT_PROCESS.getStatus(),
ORDER_COMPONENT_NOT_PROCESS
);
// =========================
// 2、状态校验
// =========================
// 当前准备变成“已加工”
boolean toBeProcessed =
Objects.equals(
targetProcessStatus,
OrderComponentProcessStatusEnum.PROCESSED.getStatus()
);
// 当前准备变成“未加工”
boolean toBeUnProcessed =
Objects.equals(
targetProcessStatus,
OrderComponentProcessStatusEnum.UNPROCESSED.getStatus()
);
// 防重复加工
if (toBeProcessed) {
AssertUtils.equals(
componentDO.getProcessStatus(),
OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(),
ORDER_COMPONENT_PROCESSED_REPEAT
);
}
if (ObjectUtil.equals(OrderComponentProcessStatusEnum.UNPROCESSED.getStatus(), sourceProcessStatus)) {
AssertUtils.equals(componentDO.getProcessStatus(), OrderComponentProcessStatusEnum.PROCESSED.getStatus(), ORDER_COMPONENT_PROCESSED_REPEAT);
// 防重复恢复
if (toBeUnProcessed) {
AssertUtils.equals(
componentDO.getProcessStatus(),
OrderComponentProcessStatusEnum.PROCESSED.getStatus(),
ORDER_COMPONENT_RESTORE_REPEAT
);
}
Long organId = componentDO.getOrganId();
Long orderId = componentDO.getOrderId();
// 查询和校验顶级部件
Long topId = componentDO.getTopId();
OrderComponentDO topComponentDO = orderComponentMapper.selectById(topId);
AssertUtils.notEmpty(topComponentDO, ORDER_COMPONENT_NOT_EXIST);
// 查询顶级部件下的所有节点
List<OrderComponentDO> topProcessedComponentList = orderComponentMapper.selectList(new LambdaQueryWrapperX<OrderComponentDO>()
.eq(OrderComponentDO::getTopId, topId)
.eqIfPresent(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.select(OrderComponentDO::getId, OrderComponentDO::getPid, OrderComponentDO::getName, OrderComponentDO::getProcessStatus, OrderComponentDO::getLevel));
if (CollUtil.isEmpty(topProcessedComponentList)) {
return;
}
// =========================
// 3、查询顶级部件
// =========================
OrderComponentDO topComponentDO =
orderComponentMapper.selectById(topId);
// 从顶级节点开始构建成树形
List<OrderComponentTreeCompareVO> treeCompareVOS = buildTree(topProcessedComponentList);
if (CollUtil.isEmpty(treeCompareVOS)) {
return;
}
OrderComponentTreeCompareVO currentTreeCompareVO = treeCompareVOS.get(0);
String structureHash = currentTreeCompareVO.getStructureHash();
AssertUtils.notEmpty(
topComponentDO,
ORDER_COMPONENT_NOT_EXIST
);
// 根据顶级部件名查询装配设置
String name = topComponentDO.getName();
CommonResult<List<AssemblyConfigRespDTO>> assemblyConfigByComponentNameListResult = assemblyConfigApi.getAssemblyConfigByPartNameList(List.of(name));
if (assemblyConfigByComponentNameListResult.isError()) {
throw new ServiceException(ORDER_COMPONENT_ASSEMBLY_CONFIG_QUERY_ERROR);
}
List<AssemblyConfigRespDTO> assemblyConfigByPartNameList = assemblyConfigByComponentNameListResult.getData();
if (CollUtil.isNotEmpty(assemblyConfigByPartNameList)) {
AssemblyConfigRespDTO assemblyConfig = assemblyConfigByPartNameList.get(0);
if (structureHash.equals(assemblyConfig.getStructureHash())) {
// 结构相同,解压配置json
String structureJson = assemblyConfig.getStructureJson();
OrderComponentTreeCompareVO structure = JSON.parseObject(JsonUtils.unzipString(structureJson), OrderComponentTreeCompareVO.class);
// 筛选出需要加工的部件id列表
Long needProcessComponentId = getNeedProcessIdsByAssemblyConfig(currentTreeCompareVO, structure, id);
if (ObjectUtil.isNull(needProcessComponentId)) {
return;
}
// 更新加工状态
orderComponentMapper.update(new LambdaUpdateWrapper<OrderComponentDO>()
.eq(OrderComponentDO::getId, needProcessComponentId)
.eq(OrderComponentDO::getOrderId, orderId)
.eq(OrderComponentDO::getOrganId, organId)
.eq(OrderComponentDO::getProcessStatus, sourceProcessStatus)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getProcessStatus, targetProcessStatus)
);
} else {
// 结构不同说明不在不加工配置,更新加工状态
orderComponentMapper.update(new LambdaUpdateWrapper<OrderComponentDO>()
// =========================
// 4、更新当前节点状态
// =========================
int updateCount = orderComponentMapper.update(
null,
new LambdaUpdateWrapperX<OrderComponentDO>()
.eq(OrderComponentDO::getId, id)
.eq(OrderComponentDO::getOrderId, orderId)
.eq(OrderComponentDO::getOrganId, organId)
.eq(OrderComponentDO::getProcessStatus, sourceProcessStatus)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getProcessStatus, targetProcessStatus)
);
}
.eq(OrderComponentDO::getProcessStatus,
sourceProcessStatus)
.eq(OrderComponentDO::getDeleted,
DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getProcessStatus,
targetProcessStatus)
);
} else {
orderComponentMapper.update(new LambdaUpdateWrapper<OrderComponentDO>()
.eq(OrderComponentDO::getId, id)
.eq(OrderComponentDO::getOrderId, orderId)
.eq(OrderComponentDO::getOrganId, organId)
.eq(OrderComponentDO::getProcessStatus, sourceProcessStatus)
.eq(OrderComponentDO::getDeleted, DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getProcessStatus, targetProcessStatus)
);
if (updateCount <= 0) {
return;
}
// =========================
// 5、重新查询整棵树(拿最新状态)
// =========================
List<OrderComponentDO> topComponentList =
orderComponentMapper.selectList(
new LambdaQueryWrapperX<OrderComponentDO>()
.eq(OrderComponentDO::getTopId, topId)
.eq(OrderComponentDO::getDeleted,
DeletedCodeEnum.NOT_DELETED.getStatus())
.select(
OrderComponentDO::getId,
OrderComponentDO::getTopId,
OrderComponentDO::getLevel,
OrderComponentDO::getProcessStatus
)
);
if (CollUtil.isEmpty(topComponentList)) {
return;
}
// =========================
// 6、统计:
// 是否存在已加工子级
// =========================
boolean hasProcessedChild =
topComponentList.stream()
// 排除顶级自己
.filter(item ->
!Objects.equals(
item.getId(),
topId
))
.anyMatch(item ->
Objects.equals(
item.getProcessStatus(),
OrderComponentProcessStatusEnum.PROCESSED.getStatus()
));
// =========================
// 7、计算顶级 extra 状态
// =========================
Integer extraProcessStatus = null;
// 顶级自身未加工
boolean topUnProcessed =
Objects.equals(
topComponentDO.getProcessStatus(),
OrderComponentProcessStatusEnum.UNPROCESSED.getStatus()
);
// 只要:
// 顶级未加工
// 且存在已加工子级
// => 部分加工
if (topUnProcessed && hasProcessedChild) {
extraProcessStatus =
OrderComponentProcessStatusEnum.PART_PROCESSED.getStatus();
}
// =========================
// 8、更新顶级 extra 状态
// =========================
orderComponentMapper.update(
null,
new LambdaUpdateWrapperX<OrderComponentDO>()
.eq(OrderComponentDO::getId, topId)
.eq(OrderComponentDO::getOrderId, orderId)
.eq(OrderComponentDO::getOrganId, organId)
.eq(OrderComponentDO::getDeleted,
DeletedCodeEnum.NOT_DELETED.getStatus())
.set(OrderComponentDO::getExtraProcessStatus,
extraProcessStatus)
);
}