| | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.exception.ServiceException; |
| | | import com.ruoyi.common.utils.OrderUtils; |
| | | |
| | | import java.time.LocalDateTime; |
| | | import com.ruoyi.technology.bean.dto.TechnologyRoutingDto; |
| | | import com.ruoyi.technology.bean.vo.TechnologyRoutingVo; |
| | | import com.ruoyi.production.mapper.ProductionOrderRoutingMapper; |
| | |
| | | |
| | | import java.time.LocalDate; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.HashMap; |
| | | import java.util.LinkedHashMap; |
| | | import java.util.LinkedHashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Override |
| | | public Long saveTechnologyRouting(TechnologyRouting technologyRouting) { |
| | | String code = OrderUtils.countTodayByCreateTime(technologyRoutingMapper, "GYLX", "process_route_code", technologyRouting.getCreateTime() != null ? technologyRouting.getCreateTime() : LocalDateTime.now()); |
| | | String code = OrderUtils.countTodayByCreateTime(technologyRoutingMapper, "GYLX", "process_route_code"); |
| | | technologyRouting.setProcessRouteCode(code); |
| | | technologyRoutingMapper.insert(technologyRouting); |
| | | // 带入bom产品结构 |
| | |
| | | |
| | | /** |
| | | * 按当前选择的 BOM 重建工艺路线工序: |
| | | * 1. 先删除该工艺路线下已有工序 |
| | | * 2. 读取 BOM 结构中的 operation_id |
| | | * 3. 按 BOM 出现顺序去重后重新写入工艺路线工序表 |
| | | * 1. 先删除该工艺路线下已有工序及参数快照 |
| | | * 2. 读取扁平 BOM 明细中的 operation_id |
| | | * 3. 按 BOM 中首次出现的顺序对工序去重,每道工序生成一条路线工序 |
| | | * 4. 每条路线工序的产出规格固定为工艺路线的成品规格 |
| | | */ |
| | | private void syncRoutingOperationsByBom(TechnologyRouting technologyRouting) { |
| | | List<TechnologyRoutingOperation> oldRoutingOperationList = technologyRoutingOperationMapper.selectList( |
| | |
| | | Wrappers.<TechnologyBomStructure>lambdaQuery() |
| | | .eq(TechnologyBomStructure::getBomId, technologyRouting.getBomId()) |
| | | .isNotNull(TechnologyBomStructure::getOperationId) |
| | | .orderByDesc(TechnologyBomStructure::getId) |
| | | .orderByAsc(TechnologyBomStructure::getId) |
| | | ); |
| | | if (bomStructures.isEmpty()) { |
| | | throw new ServiceException("bom产品结构为空!"); |
| | | } |
| | | |
| | | // 同一个 BOM 中可能重复引用相同工序,按照上一层的父节点的产品是否相同和工序是否相同 |
| | | Map<Long, TechnologyBomStructure> structureById = new HashMap<>(); |
| | | // 扁平 BOM 中多个物料可以指向同一道工序,这里只按工序去重 |
| | | Set<Long> uniqueOperationIdList = new LinkedHashSet<>(); |
| | | for (TechnologyBomStructure bomStructure : bomStructures) { |
| | | if (bomStructure != null && bomStructure.getId() != null) { |
| | | structureById.put(bomStructure.getId(), bomStructure); |
| | | } |
| | | } |
| | | |
| | | Map<String, TechnologyBomStructure> uniqueOperationMap = new LinkedHashMap<>(); |
| | | for (TechnologyBomStructure bomStructure : bomStructures) { |
| | | Long outputProductModelId = resolveOutputProductModelId(bomStructure, structureById, technologyRouting.getProductModelId()); |
| | | uniqueOperationMap.putIfAbsent(buildBomOperationDedupKey(bomStructure, outputProductModelId), bomStructure); |
| | | uniqueOperationIdList.add(bomStructure.getOperationId()); |
| | | } |
| | | |
| | | int dragSort = 1; |
| | | for (TechnologyBomStructure bomStructure : uniqueOperationMap.values()) { |
| | | for (Long operationId : uniqueOperationIdList) { |
| | | TechnologyRoutingOperation routingOperation = new TechnologyRoutingOperation(); |
| | | routingOperation.setTechnologyRoutingId(technologyRouting.getId()); |
| | | routingOperation.setProductModelId(resolveOutputProductModelId(bomStructure, structureById, technologyRouting.getProductModelId())); |
| | | routingOperation.setTechnologyOperationId(bomStructure.getOperationId()); |
| | | routingOperation.setProductModelId(technologyRouting.getProductModelId()); |
| | | routingOperation.setTechnologyOperationId(operationId); |
| | | routingOperation.setDragSort(dragSort++); |
| | | TechnologyOperation technologyOperation = getOperation(bomStructure.getOperationId()); |
| | | TechnologyOperation technologyOperation = getOperation(operationId); |
| | | routingOperation.setIsQuality(technologyOperation != null ? technologyOperation.getIsQuality() : null); |
| | | routingOperation.setIsProduction(technologyOperation != null ? technologyOperation.getIsProduction() : null); |
| | | routingOperation.setType(technologyOperation != null ? technologyOperation.getType() : null); |
| | | technologyRoutingOperationMapper.insert(routingOperation); |
| | | syncRoutingOperationParams(routingOperation.getId(), bomStructure.getOperationId()); |
| | | syncRoutingOperationParams(routingOperation.getId(), operationId); |
| | | } |
| | | } |
| | | |
| | | private String buildBomOperationDedupKey(TechnologyBomStructure bomStructure, Long outputProductModelId) { |
| | | Long operationId = bomStructure == null ? null : bomStructure.getOperationId(); |
| | | Long parentId = bomStructure == null ? null : bomStructure.getParentId(); |
| | | return operationId + "#" |
| | | + outputProductModelId + "#" |
| | | + parentId; |
| | | } |
| | | |
| | | private Long resolveOutputProductModelId(TechnologyBomStructure bomStructure, |
| | | Map<Long, TechnologyBomStructure> structureById, |
| | | Long routingProductModelId) { |
| | | if (bomStructure == null) { |
| | | return routingProductModelId; |
| | | } |
| | | Long parentId = bomStructure.getParentId(); |
| | | if (parentId == null) { |
| | | return routingProductModelId != null ? routingProductModelId : bomStructure.getProductModelId(); |
| | | } |
| | | TechnologyBomStructure parent = structureById.get(parentId); |
| | | if (parent != null && parent.getProductModelId() != null) { |
| | | return parent.getProductModelId(); |
| | | } |
| | | return routingProductModelId != null ? routingProductModelId : bomStructure.getProductModelId(); |
| | | } |
| | | |
| | | private void syncRoutingOperationParams(Long technologyRoutingOperationId, Long technologyOperationId) { |