From 57f2d2e696c5d46bae8149f824baefd73f4b5f46 Mon Sep 17 00:00:00 2001 From: whycxzp <perryhsu@163.com> Date: 星期二, 09 八月 2022 17:30:35 +0800 Subject: [PATCH] 更新散装件审批 --- src/main/java/com/whyc/service/WorksheetLinkService.java | 333 ++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 221 insertions(+), 112 deletions(-) diff --git a/src/main/java/com/whyc/service/WorksheetLinkService.java b/src/main/java/com/whyc/service/WorksheetLinkService.java index 9f25750..cc8d85f 100644 --- a/src/main/java/com/whyc/service/WorksheetLinkService.java +++ b/src/main/java/com/whyc/service/WorksheetLinkService.java @@ -17,6 +17,8 @@ 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 @@ -36,6 +38,12 @@ @Autowired private ProductBomHistoryService historyService; + + @Autowired + private ComponentProductHistoryService cphService; + + @Autowired + private ComponentProductApprovingService cpAService; @Transactional public void audit(WorksheetLink link) { @@ -75,7 +83,7 @@ } @Transactional - public void approve(WorksheetLink link) { + public void approve(WorksheetLink link, Integer componentProductFlag) { link.setDealTime(new Date()); //鏇存柊鑺傜偣淇℃伅 linkMapper.updateById(link); @@ -99,124 +107,225 @@ //璇存槑鏄」鐩粡鐞嗘彁浜ょ殑,椹冲洖鍗崇粓姝� mainService.updateEndStatusById(link.getMainId(),"鎬荤粡鐞嗛┏鍥�,椹冲洖鍘熷洜:"+link.getDealReason(),0); } - }else{ + }else { //瀹℃壒閫氳繃,鏇存柊涓昏〃鐘舵�� - mainService.updateEndStatusById(link.getMainId(),"瀹岀粨",5); - //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞 - QueryWrapper<ProductBomApproving> query = Wrappers.query(); - query.eq("main_id",link.getMainId()); - List<ProductBomApproving> approvingList = approvingMapper.selectList(query); + mainService.updateEndStatusById(link.getMainId(), "瀹岀粨", 5); + if (componentProductFlag == null) { //浜у搧瀹℃壒 + //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞 + QueryWrapper<ProductBomApproving> query = Wrappers.query(); + query.eq("main_id", link.getMainId()); + List<ProductBomApproving> approvingList = approvingMapper.selectList(query); - //澧炲姞->澧炲姞閮ㄤ欢(澧炲姞璁板綍,鍚屾椂鎵�鏈塭Version+1) - //淇敼->淇敼閮ㄤ欢鍥剧焊,淇敼閮ㄤ欢闈炲浘绾�(澧炲姞璁板綍,鍚屾椂淇敼闈炲師閮ㄤ欢鐨勬墍鏈塭Version+1) - //鍒犻櫎? TODO 闇�瑕佺害瀹氶�昏緫 + //澧炲姞->澧炲姞閮ㄤ欢(澧炲姞璁板綍,鍚屾椂鎵�鏈塭Version+1) + //淇敼->淇敼閮ㄤ欢鍥剧焊,淇敼閮ㄤ欢闈炲浘绾�(澧炲姞璁板綍,鍚屾椂淇敼闈炲師閮ㄤ欢鐨勬墍鏈塭Version+1) + //鍒犻櫎? TODO 闇�瑕佺害瀹氶�昏緫 - //鏌ヨ閮ㄤ欢鏈�鏂扮殑鐗堟湰鍙� - ProductBom product = bomService.getProduct(approvingList.get(0).getParentModel()); - int currentVersion = -1; - if(product!=null){ - currentVersion = product.getVersion(); - } - Integer nextVersion = currentVersion+1; - //鏇存柊鍒皃roduct_bom_history,澧炲姞杩涘幓鐨勯渶瑕乻Version鍜宔Version涓�鑷� - //澧炲姞鎵�鏈夐儴浠�,鎺掓煡鍑虹浉鍏崇殑鍘熼儴浠�,闈炰篃鏄洿鏂� - List<ProductBomHistory> currentHistoryList = historyService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion); - List<String> currentSubNameList = currentHistoryList.stream().map(ProductBomHistory::getSubName).collect(Collectors.toList()); - - List<ProductBomHistory> newHistoryList = new LinkedList<>(); - approvingList.forEach(approvingBom->{ - if(currentSubNameList.contains(approvingBom.getSubName())){ - approvingBom.setVersion(1); - }else{ - approvingBom.setVersion(0); + //鏌ヨ閮ㄤ欢鏈�鏂扮殑鐗堟湰鍙� + ProductBom product = bomService.getProduct(approvingList.get(0).getParentModel()); + int currentVersion = -1; + if (product != null) { + currentVersion = product.getVersion(); } - //杞寲涓簆roductBomHistory - ProductBomHistory his = new ProductBomHistory(); - his.setCategory(approvingBom.getCategory()); - his.setCreateDate(approvingBom.getCreateDate()); - his.setDwgUrl(approvingBom.getDwgUrl()); - 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.setPictureUrl(approvingBom.getPictureUrl()); - his.setProducer(approvingBom.getProducer()); - his.setQuantity(approvingBom.getQuantity()); - his.setSubCode(approvingBom.getSubCode()); - his.setSubModel(approvingBom.getSubModel()); - his.setSubName(approvingBom.getSubName()); - his.setSurfaceDetail(approvingBom.getSurfaceDetail()); - his.setSVersion(nextVersion); - his.setThickness(approvingBom.getThickness()); - his.setType(approvingBom.getType()); - his.setUnit(approvingBom.getUnit()); - his.setUpUserId(approvingBom.getUpUserId()); + Integer nextVersion = currentVersion + 1; + //鏇存柊鍒皃roduct_bom_history,澧炲姞杩涘幓鐨勯渶瑕乻Version鍜宔Version涓�鑷� + //澧炲姞鎵�鏈夐儴浠�,鎺掓煡鍑虹浉鍏崇殑鍘熼儴浠�,闈炰篃鏄洿鏂� + List<ProductBomHistory> currentHistoryList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), currentVersion); + List<String> currentSubNameList = currentHistoryList.stream().map(ProductBomHistory::getSubName).collect(Collectors.toList()); - newHistoryList.add(his); - }); - //鏈瀹℃牳涓瓙浠惰淇敼鐨勫瓙浠堕泦鍚� - List<String> approvingUpdateSubNameList = approvingList.stream().filter(approvingBom -> approvingBom.getVersion() == 1).map(ProductBomApproving::getSubName).collect(Collectors.toList()); - - historyService.addBatch(newHistoryList); - /*鏇存柊浜у搧鐨勫綋鍓嶇増鏈�,鏇存柊鍒版渶鏂扮殑鐗堟湰*/ - //褰撳墠鐗堟湰鐨勬墍鏈塨om鐨別Version鏇存柊,鎺掗櫎琚慨鏀圭殑瀛愪欢 - List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream() - .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName())) - .collect(Collectors.toList()); - newVersionCurrentHistoryList.forEach(history->{history.setEVersion(nextVersion);}); - if(newVersionCurrentHistoryList.size()!=0) { - historyService.updateVersionBatch(newVersionCurrentHistoryList); - } - /*鏇存柊鍒皃roduct_bom*/ - //鏌ヨ鏂扮殑鐗堟湰 - List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion); - bomService.updateNewBom(newBomList); - - /*String projectDir = CommonUtil.getProjectDir(); - FileUtil.copyDir()*/ - - - /*灏嗕骇鍝乥om琛ㄧ殑url淇,鏇存柊鍒版寮忚〃*/ - //瀹℃壒瀹屽悗,灏嗘湰娆$殑bom甯rl鐨勫叏閮ㄥ鍒跺埌姝e紡鏂囦欢澶逛腑 - List<ProductBomApproving> fileBomApprovingList = approvingList.stream() - .filter(productBomApproving -> - productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null - ).collect(Collectors.toList()); - String projectDir = CommonUtil.getProjectDir(); - fileBomApprovingList.forEach(fileBom->{ - try { - String pictureUrl = fileBom.getPictureUrl(); - String dwgUrl = fileBom.getDwgUrl(); - if(pictureUrl !=null){ - String newPictureUrl ="doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()+File.separator+ pictureUrl.substring(pictureUrl.lastIndexOf(File.separator)+1); - File newPictureDir = new File(projectDir + File.separator + "doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()); - if(!newPictureDir.exists()){ - newPictureDir.mkdirs(); - } - FileCopyUtils.copy(new File(projectDir+File.separator+ pictureUrl), - new File(projectDir+File.separator+newPictureUrl)); - fileBom.setPictureUrl(newPictureUrl); + List<ProductBomHistory> newHistoryList = new LinkedList<>(); + approvingList.forEach(approvingBom -> { + if (currentSubNameList.contains(approvingBom.getSubName())) { + approvingBom.setVersion(1); + } else { + approvingBom.setVersion(0); } - if(dwgUrl !=null){ - String newDwgUrl ="doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()+File.separator+ dwgUrl.substring(dwgUrl.lastIndexOf(File.separator)+1); - File newDwgDir = new File(projectDir + File.separator + "doc_file"+File.separator+"product"+File.separator+fileBom.getParentModel()); - if(!newDwgDir.exists()){ - newDwgDir.mkdirs(); - } - FileCopyUtils.copy(new File(projectDir+File.separator+ dwgUrl), - new File(projectDir + File.separator + newDwgUrl)); - fileBom.setDwgUrl(newDwgUrl); - } - } catch (IOException e) { - e.printStackTrace(); + //杞寲涓簆roductBomHistory + ProductBomHistory his = new ProductBomHistory(); + his.setCategory(approvingBom.getCategory()); + his.setCreateDate(approvingBom.getCreateDate()); + his.setDwgUrl(approvingBom.getDwgUrl()); + 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.setPictureUrl(approvingBom.getPictureUrl()); + his.setProducer(approvingBom.getProducer()); + his.setQuantity(approvingBom.getQuantity()); + his.setSubCode(approvingBom.getSubCode()); + his.setSubModel(approvingBom.getSubModel()); + his.setSubName(approvingBom.getSubName()); + his.setSurfaceDetail(approvingBom.getSurfaceDetail()); + his.setSVersion(nextVersion); + his.setThickness(approvingBom.getThickness()); + his.setType(approvingBom.getType()); + his.setUnit(approvingBom.getUnit()); + his.setUpUserId(approvingBom.getUpUserId()); + + newHistoryList.add(his); + }); + //鏈瀹℃牳涓瓙浠惰淇敼鐨勫瓙浠堕泦鍚� + List<String> approvingUpdateSubNameList = approvingList.stream().filter(approvingBom -> approvingBom.getVersion() == 1).map(ProductBomApproving::getSubName).collect(Collectors.toList()); + + historyService.addBatch(newHistoryList); + /*鏇存柊浜у搧鐨勫綋鍓嶇増鏈�,鏇存柊鍒版渶鏂扮殑鐗堟湰*/ + //褰撳墠鐗堟湰鐨勬墍鏈塨om鐨別Version鏇存柊,鎺掗櫎琚慨鏀圭殑瀛愪欢 + List<ProductBomHistory> newVersionCurrentHistoryList = currentHistoryList.stream() + .filter(currentHistory -> !approvingUpdateSubNameList.contains(currentHistory.getSubName())) + .collect(Collectors.toList()); + newVersionCurrentHistoryList.forEach(history -> { + history.setEVersion(nextVersion); + }); + if (newVersionCurrentHistoryList.size() != 0) { + historyService.updateVersionBatch(newVersionCurrentHistoryList); } - }); - //鏇存柊姝e紡bom鐨勫搴攗rl - bomService.updateUrl(fileBomApprovingList); + //鏇存柊鏁d欢琛ㄥ綋鍓嶇増鏈�,鏇存柊eVersion + List<ComponentProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion); + cphService.updateVersionBatch(cphList); + + /*鏇存柊鍒皃roduct_bom*/ + //鏌ヨ鏂扮殑鐗堟湰 + List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion); + bomService.updateNewBom(newBomList); + + /*String projectDir = CommonUtil.getProjectDir(); + FileUtil.copyDir()*/ + + + /*灏嗕骇鍝乥om琛ㄧ殑url淇,鏇存柊鍒版寮忚〃*/ + //瀹℃壒瀹屽悗,灏嗘湰娆$殑bom甯rl鐨勫叏閮ㄥ鍒跺埌姝e紡鏂囦欢澶逛腑 + List<ProductBomApproving> fileBomApprovingList = approvingList.stream() + .filter(productBomApproving -> + productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null + ).collect(Collectors.toList()); + String projectDir = CommonUtil.getProjectDir(); + fileBomApprovingList.forEach(fileBom -> { + try { + String pictureUrl = fileBom.getPictureUrl(); + String dwgUrl = fileBom.getDwgUrl(); + if (pictureUrl != null) { + String newPictureUrl = "doc_file" + File.separator + "product" + File.separator + fileBom.getParentModel() + File.separator + pictureUrl.substring(pictureUrl.lastIndexOf(File.separator) + 1); + File newPictureDir = new File(projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + fileBom.getParentModel()); + if (!newPictureDir.exists()) { + newPictureDir.mkdirs(); + } + FileCopyUtils.copy(new File(projectDir + File.separator + pictureUrl), + new File(projectDir + File.separator + newPictureUrl)); + fileBom.setPictureUrl(newPictureUrl); + } + if (dwgUrl != null) { + String newDwgUrl = "doc_file" + File.separator + "product" + File.separator + fileBom.getParentModel() + File.separator + dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1); + File newDwgDir = new File(projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + fileBom.getParentModel()); + if (!newDwgDir.exists()) { + newDwgDir.mkdirs(); + } + FileCopyUtils.copy(new File(projectDir + File.separator + dwgUrl), + new File(projectDir + File.separator + newDwgUrl)); + fileBom.setDwgUrl(newDwgUrl); + } + } catch (IOException e) { + e.printStackTrace(); + } + }); + //鏇存柊姝e紡bom鐨勫搴攗rl + bomService.updateUrl(fileBomApprovingList); + }else{ //鏇存柊鏁h浠�-浜у搧鍏崇郴 + //鏌ユ壘鍒板搴旂殑鏁h浠�-浜у搧鍏崇郴鏁版嵁 + 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琛ㄥ巻鍙蹭腑瀵瑰簲鐨剆ubName 鐗堟湰鍙蜂笉鍙�(鎺掗櫎鏇存柊) + 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<>(); + //鏌ヨ鏈�鏂扮増鏈敓鏁堢殑鐩稿叧鏁h浠� + List<ComponentProductHistory> nowHistoryList = cphService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); + //鏌ヨ鍘嗗彶涓渶鏂扮増鏈敓鏁堢殑bom + List<ProductBomHistory> nowBomHistoryList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), currentVersion); + + /* + 瀵逛簬鍏宠仈鐨�,鍒ゆ柇褰撳墠鐗堟湰涓槸鍚﹀瓨鍦ㄦ浛鎹㈠叧绯�,瀛樺湪,鍒欑洿鎺ヤ笅涓増鏈彃鍏ュ叧鑱�; + 鍚屾椂,鍏朵粬褰撳墠鐗堟湰鐨勭浉鍏虫暎瑁呬欢-浜у搧璁板綍鏇存柊鐗堟湰,鎺掗櫎瀛樺湪鐨勬浛鎹㈠叧绯� + */ + + /* + 瀵逛簬鏇挎崲鐨�,鍒ゆ柇褰撳墠鐗堟湰涓槸鍚﹀瓨鍦ㄥ叧鑱斿叧绯�,瀛樺湪,鐩存帴涓嬩釜鐗堟湰鏇挎崲,璁板綍鎻掑叆; + 鍚屾椂,褰撳墠鐗堟湰鐨勭浉鍏虫暎瑁呬欢-浜у搧璁板綍鏇存柊鐗堟湰,鎺掗櫎瀛樺湪鐨勫叧鑱斿叧绯�; + 鍚屾椂,bom琛ㄦ洿鏂板埌涓嬩釜鐗堟湰鏃�,鎺掗櫎琚浛鎹欢 + */ + + //瀵逛簬瑙i櫎鍏宠仈鐨�,褰撳墠鐗堟湰鐨勭浉鍏虫暎瑁呬欢-浜у搧璁板綍鏇存柊鐗堟湰,鎺掗櫎瑙i櫎鍏宠仈鐨勮褰� + //澶勭悊鎬濊矾:鍏堣В闄ゅ叧鑱�,鍐嶆浛鎹�,鍐嶅叧鑱� + 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); + //褰撳墠鐢熸晥鐨刡om鍒楄〃 + 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 + + } } } -- Gitblit v1.9.1