| | |
| | | import java.util.Date; |
| | | import java.util.LinkedList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Autowired |
| | | private ProductBomHistoryService historyService; |
| | | |
| | | @Autowired |
| | | private ComponentProductHistoryService cphService; |
| | | |
| | | @Autowired |
| | | private ComponentProductApprovingService cpAService; |
| | | |
| | | @Transactional |
| | | public void audit(WorksheetLink link) { |
| | |
| | | } |
| | | |
| | | @Transactional |
| | | public void approve(WorksheetLink link) { |
| | | public void approve(WorksheetLink link, Integer componentProductFlag) { |
| | | link.setDealTime(new Date()); |
| | | //更新节点信息 |
| | | linkMapper.updateById(link); |
| | |
| | | }else{ |
| | | //审批通过,更新主表状态 |
| | | mainService.updateEndStatusById(link.getMainId(),"完结",5); |
| | | if (componentProductFlag == null) { //产品审批 |
| | | //将产品文件复制至正式路径 |
| | | QueryWrapper<ProductBomApproving> query = Wrappers.query(); |
| | | query.eq("main_id",link.getMainId()); |
| | |
| | | List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream() |
| | | .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName())) |
| | | .collect(Collectors.toList()); |
| | | newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);}); |
| | | newVersionCurrentHistoryList.forEach(history -> { |
| | | history.setEVersion(nextVersion); |
| | | }); |
| | | if(newVersionCurrentHistoryList.size()!=0) { |
| | | historyService.updateVersionBatch(newVersionCurrentHistoryList); |
| | | } |
| | | //更新散件表当前版本,更新eVersion |
| | | List<ComponentProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion); |
| | | cphService.updateVersionBatch(cphList); |
| | | |
| | | /*更新到product_bom*/ |
| | | //查询新的版本 |
| | | List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion); |
| | |
| | | }); |
| | | //更新正式bom的对应url |
| | | bomService.updateUrl(fileBomApprovingList); |
| | | }else{ //更新散装件-产品关系 |
| | | //查找到对应的散装件-产品关系数据 |
| | | List<ComponentProductApproving> cpAList = cpAService.getListByMainId(link.getMainId()); |
| | | //查询部件最新的版本号 |
| | | ProductBom product = bomService.getProduct(cpAList.get(0).getParentModel()); |
| | | int currentVersion = -1; |
| | | if (product != null) { |
| | | currentVersion = product.getVersion(); |
| | | } |
| | | Integer nextVersion = currentVersion + 1; |
| | | //关联/接触关联,更新版本 |
| | | //替换,更新版本,同时bom表历史中对应的subName 版本号不变(排除更新) |
| | | Map<Integer, List<ComponentProductApproving>> linkTypeMap = cpAList.stream().collect(Collectors.groupingBy(ComponentProductApproving::getLinkType)); |
| | | List<ComponentProductApproving> addedList = new LinkedList<>(); |
| | | List<ComponentProductApproving> replacedList = new LinkedList<>(); |
| | | List<ComponentProductApproving> removedList = new LinkedList<>(); |
| | | linkTypeMap.forEach((linkType,list)->{ |
| | | if(linkType == 1){ |
| | | addedList.addAll(list); |
| | | }else if(linkType == 2){ |
| | | replacedList.addAll(list); |
| | | }else{ |
| | | removedList.addAll(list); |
| | | } |
| | | }); |
| | | List<ComponentProductHistory> newHistoryList = new LinkedList<>(); |
| | | //查询最新版本生效的相关散装件 |
| | | List<ComponentProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); |
| | | //查询历史中最新版本生效的bom |
| | | List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); |
| | | |
| | | /* |
| | | 对于关联的,判断当前版本中是否存在替换关系,存在,则直接下个版本插入关联; |
| | | 同时,其他当前版本的相关散装件-产品记录更新版本,排除存在的替换关系 |
| | | */ |
| | | |
| | | /* |
| | | 对于替换的,判断当前版本中是否存在关联关系,存在,直接下个版本替换,记录插入; |
| | | 同时,当前版本的相关散装件-产品记录更新版本,排除存在的关联关系; |
| | | 同时,bom表更新到下个版本时,排除被替换件 |
| | | */ |
| | | |
| | | //对于解除关联的,当前版本的相关散装件-产品记录更新版本,排除解除关联的记录 |
| | | //处理思路:先解除关联,再替换,再关联 |
| | | if(removedList.size()!=0){ |
| | | removedList.forEach(remove -> { |
| | | nowHistoryList.forEach(nowHistory -> { |
| | | if (remove.getComponentId().intValue() == nowHistory.getComponentId()) { |
| | | nowHistoryList.remove(nowHistory); |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | //处理替换 |
| | | if(replacedList.size()!=0){ |
| | | replacedList.forEach(replace -> { |
| | | //当前生效的散装件-产品列表 |
| | | nowHistoryList.forEach(nowHistory -> { |
| | | if (replace.getComponentId().intValue() == nowHistory.getComponentId()) { |
| | | nowHistoryList.remove(nowHistory); |
| | | } |
| | | }); |
| | | //下个版本新增的散装件-产品列表 |
| | | ComponentProductHistory newHistory = new ComponentProductHistory(); |
| | | newHistory.setComponentId(replace.getComponentId()); |
| | | newHistory.setParentModel(replace.getParentModel()); |
| | | newHistory.setSubName(replace.getSubName()); |
| | | newHistory.setCreateTime(new Date()); |
| | | newHistory.setLinkType(2); |
| | | newHistory.setSVersion(nextVersion); |
| | | newHistory.setEVersion(nextVersion); |
| | | newHistoryList.add(newHistory); |
| | | //当前生效的bom列表 |
| | | nowBomHistoryList.forEach(nowBomHistory->{ |
| | | if(replace.getSubName().equals(nowBomHistory.getSubName())){ |
| | | nowBomHistoryList.remove(nowBomHistory); |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | //处理关联 |
| | | addedList.forEach(add -> { |
| | | nowHistoryList.forEach(nowHistory -> { |
| | | if (add.getComponentId().intValue() == nowHistory.getComponentId()) { |
| | | nowHistoryList.remove(nowHistory); |
| | | } |
| | | }); |
| | | }); |
| | | |
| | | //处理完成,进行表单数据更新,分为nowHistoryList,newHistoryList,nowBomHistoryList |
| | | |
| | | } |
| | | } |
| | | } |
| | | |