| | |
| | | @Resource |
| | | private ProductOrderService productOrderService; |
| | | |
| | | @Resource |
| | | private IProductionOrderRouteService productionOrderRouteService; |
| | | |
| | | @Override |
| | | public Long populateBlocks(Long orderId, ProductionPlanDto productionPlanDto) { |
| | | if (productionPlanDto == null) { |
| | |
| | | log.info("下发产品【{}】未查询出工艺路线", productionPlanDto.getProductName()); |
| | | return null; |
| | | } |
| | | migration(orderId, processRoute); |
| | | return processRoute.getId(); |
| | | |
| | | // 创建工艺路线 |
| | | ProductionOrderRoute productionOrderRoute = createOrderRouteSnapshot(orderId, processRoute); |
| | | migration(orderId, processRoute, productionOrderRoute.getId()); |
| | | |
| | | return productionOrderRoute.getId(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | log.info("下发产品【{}】未查询出工艺路线", productionPlanDto.getProductName()); |
| | | return null; |
| | | } |
| | | migration(orderId, processRoute); |
| | | return processRoute.getId(); |
| | | |
| | | // 创建工艺路线 |
| | | ProductionOrderRoute productionOrderRoute = createOrderRouteSnapshot(orderId, processRoute); |
| | | migration(orderId, processRoute, productionOrderRoute.getId()); |
| | | |
| | | return productionOrderRoute.getId(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | if (processRoute == null) { |
| | | throw new ServiceException("该工艺路线不存在,绑定失败"); |
| | | } |
| | | migration(productOrder.getId(), processRoute); |
| | | |
| | | // 回写工艺路线id到生产订单 |
| | | // 创建工艺路线 |
| | | ProductionOrderRoute productionOrderRoute = createOrderRouteSnapshot(productOrder.getId(), processRoute); |
| | | migration(productOrder.getId(), processRoute, productionOrderRoute.getId()); |
| | | |
| | | // 回写新的工艺路线ID到生产订单 |
| | | productOrder.setRouteId(productionOrderRoute.getId()); |
| | | productOrderService.updateById(productOrder); |
| | | } |
| | | |
| | | private ProductionOrderRoute createOrderRouteSnapshot(Long orderId, ProcessRoute processRoute) { |
| | | ProductionOrderRoute snapshot = new ProductionOrderRoute(); |
| | | BeanUtils.copyProperties(processRoute, snapshot, "id", "createTime", "updateTime", "tenantId"); |
| | | snapshot.setOrderId(orderId); |
| | | snapshot.setProcessRouteId(processRoute.getId()); |
| | | productionOrderRouteService.save(snapshot); |
| | | return snapshot; |
| | | } |
| | | |
| | | @Override |
| | | public void deleteData(Long orderId, Long processRouteId) { |
| | | public void deleteData(Long orderId, Long snapshotRouteId) { |
| | | // 删除工艺路线工序参数附表 |
| | | productionOrderRouteItemParamService.remove(new LambdaQueryWrapper<ProductionOrderRouteItemParam>() |
| | | .eq(ProductionOrderRouteItemParam::getOrderId, orderId)); |
| | |
| | | // 删除工艺路线子集附表 |
| | | productionOrderRouteItemService.remove(new LambdaQueryWrapper<ProductionOrderRouteItem>() |
| | | .eq(ProductionOrderRouteItem::getOrderId, orderId) |
| | | .eq(ProductionOrderRouteItem::getRouteId, processRouteId)); |
| | | .eq(ProductionOrderRouteItem::getRouteId, snapshotRouteId)); |
| | | |
| | | // 删除工艺路线 |
| | | productionOrderRouteService.removeById(snapshotRouteId); |
| | | |
| | | // 删除BOM子集附表 |
| | | ProcessRoute processRoute = processRouteService.getById(processRouteId); |
| | | if (processRoute != null && processRoute.getBomId() != null) { |
| | | ProductionOrderRoute snapshot = productionOrderRouteService.getById(snapshotRouteId); |
| | | if (snapshot != null && snapshot.getBomId() != null) { |
| | | productionOrderStructureService.remove(new LambdaQueryWrapper<ProductionOrderStructure>() |
| | | .eq(ProductionOrderStructure::getOrderId, orderId) |
| | | .eq(ProductionOrderStructure::getBomId, processRoute.getBomId())); |
| | | .eq(ProductionOrderStructure::getBomId, snapshot.getBomId().longValue())); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据工艺路线迁移附表数据 |
| | | */ |
| | | private void migration(Long orderId, ProcessRoute processRoute) { |
| | | private void migration(Long orderId, ProcessRoute processRoute, Long newRouteId) { |
| | | // 迁移工艺路线子集表数据,返回旧id->新instance映射 |
| | | List<ProcessRouteItem> processRouteItemList = processRouteItemService.list( |
| | | new LambdaQueryWrapper<ProcessRouteItem>().eq(ProcessRouteItem::getRouteId, processRoute.getId())); |
| | | Map<Long, ProductionOrderRouteItem> routeItemOldIdMap = migrationProcessRouteItem(orderId, processRouteItemList); |
| | | Map<Long, ProductionOrderRouteItem> routeItemOldIdMap = migrationProcessRouteItem(orderId, newRouteId, processRouteItemList); |
| | | |
| | | // 迁移工艺路线内绑定的工序参数 |
| | | if (processRouteItemList != null && !processRouteItemList.isEmpty()) { |
| | |
| | | } |
| | | } |
| | | |
| | | private Map<Long, ProductionOrderRouteItem> migrationProcessRouteItem(Long orderId, List<ProcessRouteItem> list) { |
| | | private Map<Long, ProductionOrderRouteItem> migrationProcessRouteItem(Long orderId, Long newRouteId, List<ProcessRouteItem> list) { |
| | | Map<Long, ProductionOrderRouteItem> oldIdMap = new HashMap<>(); |
| | | if (list == null || list.isEmpty()) { |
| | | return oldIdMap; |
| | |
| | | BeanUtils.copyProperties(item, instance, "id"); |
| | | instance.setIsQuality(item.getIsQuality() != null && item.getIsQuality() ? 1 : 0); |
| | | instance.setOrderId(orderId); |
| | | instance.setRouteId(newRouteId); |
| | | if (item.getId() != null) { |
| | | oldIdMap.put(item.getId(), instance); |
| | | } |