| | |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.concurrent.atomic.AtomicReference; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | |
| | | @Resource |
| | | private WorksheetLinkMapper linkMapper; |
| | | |
| | | @Autowired |
| | | //lxw修改 |
| | | @Autowired(required = false) |
| | | private ProductBomApprovingMapper approvingMapper; |
| | | |
| | | @Autowired |
| | |
| | | private ProductBomHistoryService historyService; |
| | | |
| | | @Autowired |
| | | private ComponentProductHistoryService cphService; |
| | | private MaterialProductHistoryService cphService; |
| | | |
| | | @Autowired |
| | | private ComponentProductApprovingService cpAService; |
| | | private MaterialProductApprovingService cpAService; |
| | | |
| | | @Autowired |
| | | private MaterialApprovingService cAService; |
| | | |
| | | @Autowired |
| | | private MaterialService cService; |
| | | |
| | | @Transactional |
| | | public void audit(WorksheetLink link) { |
| | |
| | | //更新节点信息 |
| | | linkMapper.updateById(link); |
| | | if(link.getLinkStatus() == 2){ //驳回 |
| | | //查看是否为散装件审批,是则需要更新散装件审批表中的状态为完结 |
| | | if(mainService.getInfoById(link.getMainId()).getType().equals(EnumWorksheetType.Material.getType())){ |
| | | cAService.endStatus(link.getMainId()); |
| | | } |
| | | //项目经理驳回,驳回即终止 |
| | | mainService.updateEndStatusById(link.getMainId(),"经理驳回,驳回原因:"+link.getDealReason(),0); |
| | | //项目经理驳回前,还曾经过总经理,则需要增加总经理驳回原因 |
| | |
| | | his.setCategory(approvingBom.getCategory()); |
| | | his.setCreateDate(approvingBom.getCreateDate()); |
| | | his.setDwgUrl(approvingBom.getDwgUrl()); |
| | | his.setEVersion(nextVersion); |
| | | //lxw注释 |
| | | //his.setEVersion(nextVersion); |
| | | his.setFileUrl(approvingBom.getFileUrl()); |
| | | his.setMaterial(approvingBom.getMaterial()); |
| | | his.setNotes(approvingBom.getNotes()); |
| | | his.setParentCode(approvingBom.getParentCode()); |
| | | his.setParentModel(approvingBom.getParentModel()); |
| | | his.setParentName(approvingBom.getParentName()); |
| | | his.setParentVersion(approvingBom.getParentVersion()); |
| | | //his.setParentCode(approvingBom.getParentCode()); |
| | | //his.setParentModel(approvingBom.getParentModel()); |
| | | //his.setParentName(approvingBom.getParentName()); |
| | | //his.setParentVersion(approvingBom.getParentVersion()); |
| | | his.setPictureUrl(approvingBom.getPictureUrl()); |
| | | his.setProducer(approvingBom.getProducer()); |
| | | his.setQuantity(approvingBom.getQuantity()); |
| | |
| | | his.setSubModel(approvingBom.getSubModel()); |
| | | his.setSubName(approvingBom.getSubName()); |
| | | his.setSurfaceDetail(approvingBom.getSurfaceDetail()); |
| | | his.setSVersion(nextVersion); |
| | | //his.setSVersion(nextVersion); |
| | | his.setThickness(approvingBom.getThickness()); |
| | | his.setType(approvingBom.getType()); |
| | | his.setUnit(approvingBom.getUnit()); |
| | |
| | | .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName())) |
| | | .collect(Collectors.toList()); |
| | | newVersionCurrentHistoryList.forEach(history -> { |
| | | history.setEVersion(nextVersion); |
| | | //lxw修改 |
| | | //history.setEVersion(nextVersion); |
| | | }); |
| | | if (newVersionCurrentHistoryList.size() != 0) { |
| | | historyService.updateVersionBatch(newVersionCurrentHistoryList); |
| | | } |
| | | //更新散件表当前版本,更新eVersion |
| | | List<ComponentProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion); |
| | | List<MaterialProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion); |
| | | if(cphList.size()!=0){cphService.updateVersionBatch(cphList);} |
| | | |
| | | /*更新到product_bom*/ |
| | |
| | | //更新正式bom的对应url |
| | | bomService.updateUrl(fileBomApprovingList); |
| | | } |
| | | else if(type.intValue() == EnumWorksheetType.Component.getType()){ //散装件 TODO |
| | | |
| | | else if(type.intValue() == EnumWorksheetType.Material.getType()){ //散装件 |
| | | List<MaterialApproving> approvingList = cAService.getListByMainId(link.getMainId()); |
| | | List<Material> MaterialList = new LinkedList<>(); |
| | | //区分是新增还是删除 |
| | | Integer MaterialId = approvingList.get(0).getMaterialId(); |
| | | if(MaterialId==null) { //新增 |
| | | //将散装件从审批表中转移到正式表 |
| | | approvingList.forEach(approve -> { |
| | | Material Material = new Material(); |
| | | Material.setCategory(approve.getCategory()); |
| | | Material.setSubCode(approve.getSubCode()); |
| | | Material.setSubName(approve.getSubName()); |
| | | Material.setSubModel(approve.getSubModel()); |
| | | Material.setUnit(approve.getUnit()); |
| | | Material.setQuantity(approve.getQuantity()); |
| | | Material.setProducer(approve.getProducer()); |
| | | Material.setNotes(approve.getNotes()); |
| | | Material.setCreateDate(new Date()); |
| | | Material.setStatus(1); |
| | | MaterialList.add(Material); |
| | | }); |
| | | cService.insertBatch(MaterialList); |
| | | }else{ //删除 |
| | | List<Integer> MaterialIdList = approvingList.stream().map(MaterialApproving::getMaterialId).collect(Collectors.toList()); |
| | | cService.deleteBatch(MaterialIdList); |
| | | } |
| | | //更新散装件审批子表中type为完结 |
| | | cAService.endStatus(link.getMainId()); |
| | | } |
| | | else if(type.intValue() == EnumWorksheetType.ComponentProduct.getType()){ //更新散装件-产品关系 |
| | | else if(type.intValue() == EnumWorksheetType.MaterialProduct.getType()){ //更新散装件-产品关系 |
| | | //查找到对应的散装件-产品关系数据 |
| | | List<ComponentProductApproving> cpAList = cpAService.getListByMainId(link.getMainId()); |
| | | List<MaterialProductApproving> cpAList = cpAService.getListByMainId(link.getMainId()); |
| | | //查询部件最新的版本号 |
| | | ProductBom product = bomService.getProduct(cpAList.get(0).getParentModel()); |
| | | //lxw修改 |
| | | //ProductBom product = bomService.getProduct(cpAList.get(0).getParentModel()); |
| | | ProductBom product=new ProductBom(); |
| | | 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<>(); |
| | | Map<Integer, List<MaterialProductApproving>> linkTypeMap = cpAList.stream().collect(Collectors.groupingBy(MaterialProductApproving::getLinkType)); |
| | | List<MaterialProductApproving> addedList = new LinkedList<>(); |
| | | List<MaterialProductApproving> replacedList = new LinkedList<>(); |
| | | List<MaterialProductApproving> removedList = new LinkedList<>(); |
| | | linkTypeMap.forEach((linkType,list)->{ |
| | | if(linkType == 1){ |
| | | addedList.addAll(list); |
| | |
| | | removedList.addAll(list); |
| | | } |
| | | }); |
| | | List<ComponentProductHistory> newHistoryList = new LinkedList<>(); |
| | | List<MaterialProductHistory> newHistoryList = new LinkedList<>(); |
| | | //查询最新版本生效的相关散装件 |
| | | List<ComponentProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); |
| | | //lxw注释 |
| | | //List<MaterialProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); |
| | | List<MaterialProductHistory> nowHistoryList =new ArrayList<>(); |
| | | //查询历史中最新版本生效的bom |
| | | List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); |
| | | |
| | | //List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); |
| | | List<ProductBomHistory> nowBomHistoryList = new ArrayList<>(); |
| | | /* |
| | | 对于关联的,判断当前版本中是否存在替换关系,存在,则直接下个版本插入关联; |
| | | 同时,其他当前版本的相关散装件-产品记录更新版本,排除存在的替换关系 |
| | |
| | | if(removedList.size()!=0){ |
| | | removedList.forEach(remove -> { |
| | | /*nowHistoryList.forEach(nowHistory -> { |
| | | if (remove.getComponentId().intValue() == nowHistory.getComponentId()) { |
| | | if (remove.getMaterialId().intValue() == nowHistory.getMaterialId()) { |
| | | nowHistoryList.remove(nowHistory); |
| | | } |
| | | });*/ |
| | | Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator(); |
| | | Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator(); |
| | | while (iterator.hasNext()){ |
| | | if(remove.getComponentId().intValue() == iterator.next().getComponentId()){ |
| | | MaterialProductHistory next = iterator.next(); |
| | | //lxw注释 |
| | | /*if(remove.getMaterialId().intValue() == next.getMaterialId() |
| | | &&remove.getSubName().equals(next.getSubName()) |
| | | ){ |
| | | iterator.remove(); |
| | | break; |
| | | } |
| | | }*/ |
| | | } |
| | | }); |
| | | } |
| | |
| | | replacedList.forEach(replace -> { |
| | | //当前生效的散装件-产品列表 |
| | | /*nowHistoryList.forEach(nowHistory -> { |
| | | if (replace.getComponentId().intValue() == nowHistory.getComponentId()) { |
| | | if (replace.getMaterialId().intValue() == nowHistory.getMaterialId()) { |
| | | nowHistoryList.remove(nowHistory); |
| | | } |
| | | });*/ |
| | | Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator(); |
| | | while (iterator.hasNext()){ |
| | | if(replace.getComponentId().intValue() == iterator.next().getComponentId()){ |
| | | iterator.remove(); |
| | | break; |
| | | if(nowHistoryList.size()!=0) { |
| | | Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | MaterialProductHistory next = iterator.next(); |
| | | //lxw注释 |
| | | /*if (replace.getMaterialId().intValue() == next.getMaterialId() |
| | | && replace.getSubName().equals(next.getSubName()) |
| | | ) { |
| | | iterator.remove(); |
| | | break; |
| | | }*/ |
| | | } |
| | | } |
| | | //下个版本新增替换的散装件-产品列表 |
| | | ComponentProductHistory newHistory = new ComponentProductHistory(); |
| | | newHistory.setComponentId(replace.getComponentId()); |
| | | newHistory.setParentModel(replace.getParentModel()); |
| | | newHistory.setSubName(replace.getSubName()); |
| | | MaterialProductHistory newHistory = new MaterialProductHistory(); |
| | | newHistory.setMaterialId(replace.getMaterialId()); |
| | | //lxw注释 |
| | | //newHistory.setParentModel(replace.getParentModel()); |
| | | //newHistory.setSubName(replace.getSubName()); |
| | | newHistory.setQuantity(replace.getQuantity()); |
| | | newHistory.setCreateTime(new Date()); |
| | | newHistory.setLinkType(2); |
| | | newHistory.setSVersion(nextVersion); |
| | | newHistory.setEVersion(nextVersion); |
| | | //newHistory.setSVersion(nextVersion); |
| | | //newHistory.setEVersion(nextVersion); |
| | | newHistoryList.add(newHistory); |
| | | //当前生效的bom列表 |
| | | /*nowBomHistoryList.forEach(nowBomHistory->{ |
| | |
| | | });*/ |
| | | Iterator<ProductBomHistory> iterator1 = nowBomHistoryList.iterator(); |
| | | while (iterator1.hasNext()){ |
| | | if(replace.getSubName().equals(iterator1.next().getSubName())){ |
| | | //lxw注释 |
| | | /*if(replace.getSubName().equals(iterator1.next().getSubName())){ |
| | | iterator1.remove(); |
| | | break; |
| | | } |
| | | }*/ |
| | | } |
| | | }); |
| | | } |
| | |
| | | //处理关联 |
| | | addedList.forEach(add -> { |
| | | /*nowHistoryList.forEach(nowHistory -> { |
| | | if (add.getComponentId().intValue() == nowHistory.getComponentId()) { |
| | | if (add.getMaterialId().intValue() == nowHistory.getMaterialId()) { |
| | | nowHistoryList.remove(nowHistory); |
| | | } |
| | | });*/ |
| | | Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator(); |
| | | while (iterator.hasNext()){ |
| | | if(add.getComponentId().intValue() == iterator.next().getComponentId()){ |
| | | iterator.remove(); |
| | | break; |
| | | if(nowHistoryList.size()!=0) { |
| | | Iterator<MaterialProductHistory> iterator = nowHistoryList.iterator(); |
| | | while (iterator.hasNext()) { |
| | | MaterialProductHistory next = iterator.next(); |
| | | //lxw注释 |
| | | /*if (add.getMaterialId().intValue() == next.getMaterialId() |
| | | && add.getSubName().equals(next.getSubName()) |
| | | ) { |
| | | iterator.remove(); |
| | | break; |
| | | }*/ |
| | | } |
| | | } |
| | | |
| | | ComponentProductHistory newHistory = new ComponentProductHistory(); |
| | | newHistory.setComponentId(add.getComponentId()); |
| | | newHistory.setParentModel(add.getParentModel()); |
| | | newHistory.setSubName(add.getSubName()); |
| | | MaterialProductHistory newHistory = new MaterialProductHistory(); |
| | | newHistory.setMaterialId(add.getMaterialId()); |
| | | //newHistory.setParentModel(add.getParentModel()); |
| | | //newHistory.setSubName(add.getSubName()); |
| | | newHistory.setQuantity(add.getQuantity()); |
| | | newHistory.setCreateTime(new Date()); |
| | | newHistory.setLinkType(1); |
| | | newHistory.setSVersion(nextVersion); |
| | | newHistory.setEVersion(nextVersion); |
| | | //newHistory.setSVersion(nextVersion); |
| | | //newHistory.setEVersion(nextVersion); |
| | | newHistoryList.add(newHistory); |
| | | |
| | | }); |
| | | |
| | | //处理完成,进行表单数据更新,分为nowHistoryList,newHistoryList,nowBomHistoryList |
| | | //nowHistoryList.forEach(nowHis->nowHis.setEVersion(nextVersion)); |
| | | newHistoryList.forEach(newHis->{newHis.setEVersion(nextVersion);newHis.setSVersion(nextVersion);}); |
| | | nowBomHistoryList.forEach(nowBomHis->nowBomHis.setEVersion(nextVersion)); |
| | | //lxw注释 |
| | | //if(newHistoryList.size()!=0){newHistoryList.forEach(newHis->{newHis.setEVersion(nextVersion);newHis.setSVersion(nextVersion);});} |
| | | //if(nowBomHistoryList.size()!=0){nowBomHistoryList.forEach(nowBomHis->nowBomHis.setEVersion(nextVersion));} |
| | | |
| | | cphService.updateVersionBatch(nowHistoryList); |
| | | cphService.insertBatch(newHistoryList); |
| | | historyService.updateVersionBatch(nowBomHistoryList); |
| | | if(nowHistoryList.size()!=0){cphService.updateVersionBatch(nowHistoryList);} |
| | | if(newHistoryList.size()!=0){cphService.insertBatch(newHistoryList);} |
| | | if(nowBomHistoryList.size()!=0){historyService.updateVersionBatch(nowBomHistoryList);} |
| | | //更新ProductBom |
| | | List<ProductBomHistory> newBomList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), nextVersion); |
| | | bomService.updateNewBom(newBomList); |
| | | //lxw注释 |
| | | //List<ProductBomHistory> newBomList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), nextVersion); |
| | | //bomService.updateNewBom(newBomList); |
| | | } |
| | | else if(type.intValue() == EnumWorksheetType.ProductSoftware.getType()){ |
| | | //转移记录 |
| | | } |
| | | } |
| | | } |