| | |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.stream.Collectors; |
| | |
| | | private OthFileMapper othFileMapper; |
| | | @Value("${dy.webFile.fmUrl}") |
| | | private String fmUrl ; |
| | | |
| | | @Autowired |
| | | public void setAssemblyDao(PrAssemblyPlanMapper assemblyDao) { |
| | | this.assemblyDao = assemblyDao; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setProcessDao(PrProductionProcessMapper dao){ |
| | | processDao = dao; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setNodeDao(PrProductionNodeMapper dao){ |
| | | nodeDao = dao; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setWorkDao(PrWorkingInstructionMapper dao){ |
| | | workDao = dao; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setUserUtil(UserUtil userUtil){ |
| | | this.userUtil = userUtil; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setFileOperate(FileOperate fileOperate){ |
| | | this.fileOperate = fileOperate; |
| | | } |
| | | |
| | | @Autowired |
| | | public void setOthFileMapper(OthFileMapper othFileMapper){ |
| | | this.othFileMapper = othFileMapper; |
| | | } |
| | | |
| | | @Transactional |
| | | public int save(PrProductionProcess process){ |
| | | //流程名称不能重复 |
| | |
| | | throw new RuntimeException("流程名称不能重复"); |
| | | } |
| | | PrProductionProcess originProductionProcess = processDao.selectByPrimaryKey(process.id); |
| | | //如果已经绑定任务(目前不包括暂停\结束状态 投入数为0的任务 以外的 所有任务),产品\节点id不能删除不能修改 |
| | | if(!originProductionProcess.getProName().equals(process.getProName())){ |
| | | //组装任务计划 |
| | | //如果已经绑定组装任务计划(目前不包括暂停\结束状态 投入数为0的任务 以外的 所有任务),产品\节点id不能删除不能修改 |
| | | PrAssemblyPlan params = new PrAssemblyPlan(); |
| | | params.setProcessId(process.id); |
| | | List<PrAssemblyPlan> planList = assemblyDao.selectAssyPlanSimplify(params); |
| | | List<PrAssemblyPlan> onlinePlanList = planList.stream().filter(plan -> plan.getStatus() == PlanStatusEnum.NORMAL.getCode()).collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(planList)) { |
| | | if (planList.stream().anyMatch(plan -> plan.getInputNumber() > 0)) { |
| | | throw new RuntimeException("存在绑定的任务,并且投入生产,产品不能修改"); |
| | | if (planList.stream().anyMatch(plan -> plan.getInputNumber() > 0)) { //存在任务已经投入生产 |
| | | if (!originProductionProcess.getProName().equals(process.getProName())) { |
| | | throw new RuntimeException("存在已经投入生产绑定的任务,产品不能修改"); |
| | | } |
| | | //节点id不能删除 |
| | | if (!originProductionProcess.getNodes().stream().allMatch(node -> process.getNodes().stream().anyMatch(node::equals))) { |
| | | throw new RuntimeException("存在已经投入生产绑定的任务,节点不能删除"); |
| | | } |
| | | }else if(CollectionUtils.isNotEmpty(onlinePlanList)){ |
| | | //先将组装任务置为暂停状态 |
| | | onlinePlanList.forEach(plan -> { |
| | |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | prepareProcess(process); |
| | | int count = processDao.updateByPrimaryKeySelective(process); |
| | | // 优化:只有当节点有变更时才删除并重新插入 |
| | | if (!process.nodes.isEmpty()) { |
| | | List<Long> nodeIdsToDelete = process.getNodes().stream() |
| | | // 优化:只有当节点有变更时 根据ID更新内容 没有匹配到的ID 删除 多余的ID 新增 |
| | | |
| | | List<Long> nodeIdsToDelete = originProductionProcess.getNodes().stream() |
| | | .filter(node -> process.nodes.stream().filter(newNode -> node.getId().equals(newNode.getId())).count() == 0) |
| | | .map(PrProductionNode::getId) // 映射节点到其ID |
| | | .collect(Collectors.toList()); |
| | | if (CollectionUtils.isNotEmpty(nodeIdsToDelete)) { |
| | | nodeDao.deleteByNodeId(nodeIdsToDelete); |
| | | workDao.deleteByNodeId(nodeIdsToDelete); |
| | | nodeDao.deleteByProcessId(process.id); |
| | | } |
| | | saveNodesAndInstructions(process); |
| | | return count; |
| | |
| | | |
| | | // 将节点和工作指示的保存逻辑封装到一个方法中 |
| | | private void saveNodesAndInstructions(PrProductionProcess process){ |
| | | List<PrProductionNode> haveIdList = new ArrayList<>(); |
| | | List<PrProductionNode> noIdList = new ArrayList<>(); |
| | | |
| | | process.nodes.forEach(node -> { |
| | | node.processId = process.id; |
| | | if (node.getId() != null && node.getId() != 0) { |
| | | haveIdList.add(node); |
| | | } else { |
| | | noIdList.add(node); |
| | | } |
| | | }); |
| | | try{ |
| | | nodeDao.insertMany(process.nodes); |
| | | if (haveIdList.size() > 0) { |
| | | for (int i = 0; i < haveIdList.size(); i++) { |
| | | nodeDao.updateByPrimaryKeySelective(haveIdList.get(i)); |
| | | } |
| | | } |
| | | if (noIdList.size() > 0) {//CollectionUtils.isNotEmpty(noIdList) |
| | | nodeDao.insertMany(noIdList); |
| | | } |
| | | }catch (DuplicateKeyException e){ |
| | | throw new RuntimeException("节点顺序重复"); |
| | | } |
| | |
| | | workDao.insertMany(workList); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public int delete(Long id){ |
| | | return processDao.deleteLogicById(id); |