From 51a54c31b1fb937d23e1b1ddd0777076da009fe5 Mon Sep 17 00:00:00 2001 From: whycxzp <perryhsu@163.com> Date: 星期五, 29 七月 2022 16:59:45 +0800 Subject: [PATCH] 更新工作流 --- src/main/java/com/whyc/service/WorksheetLinkService.java | 209 +++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 180 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/whyc/service/WorksheetLinkService.java b/src/main/java/com/whyc/service/WorksheetLinkService.java index 2d58845..dfcea9f 100644 --- a/src/main/java/com/whyc/service/WorksheetLinkService.java +++ b/src/main/java/com/whyc/service/WorksheetLinkService.java @@ -1,13 +1,23 @@ package com.whyc.service; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.whyc.mapper.ProductBomApprovingMapper; import com.whyc.mapper.WorksheetLinkMapper; -import com.whyc.pojo.WorksheetLink; +import com.whyc.pojo.*; +import com.whyc.util.CommonUtil; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.FileCopyUtils; import javax.annotation.Resource; +import java.io.File; +import java.io.IOException; import java.util.Date; +import java.util.LinkedList; import java.util.List; +import java.util.stream.Collectors; @Service public class WorksheetLinkService { @@ -18,6 +28,14 @@ @Resource private WorksheetLinkMapper linkMapper; + @Autowired + private ProductBomApprovingMapper approvingMapper; + + @Autowired + private ProductBomService bomService; + + @Autowired + private ProductBomHistoryService historyService; @Transactional public void audit(WorksheetLink link) { @@ -25,20 +43,8 @@ //鏇存柊鑺傜偣淇℃伅 linkMapper.updateById(link); if(link.getLinkStatus() == 2){ //椹冲洖 - //椹冲洖鍒板憳宸ヨ繘琛屽鐞� - //鏌ヨ宸ュ崟鐨勫憳宸� - Long createUserId = mainService.getInfoById(link.getMainId()).getCreateUserId(); - WorksheetLink link2 = new WorksheetLink(); - link2.setMainId(link.getMainId()); - link2.setParentId(link.getId()); - link2.setDealUserId(createUserId); - link2.setDealType(0); - link2.setDealDesc("宸ュ崟琚粡鐞嗛┏鍥�,椹冲洖淇℃伅:"+link.getDealReason()); - link2.setLinkStatus(0); - link2.setEnableArchive(0); - linkMapper.insert(link2); - //鏇存柊涓昏〃鐘舵�� - mainService.updateStatusById(link.getMainId(),0); + //椤圭洰缁忕悊椹冲洖,椹冲洖鍗崇粓姝� + mainService.updateEndStatusById(link.getMainId(),"缁忕悊椹冲洖",0); }else{ //杩涘叆涓嬩竴鑺傜偣,鎬荤粡鐞嗗鎵� WorksheetLink link2 = new WorksheetLink(); @@ -49,6 +55,7 @@ link2.setDealDesc("宸ュ崟琚粡鐞嗗鏍搁�氳繃,淇℃伅:"+link.getDealReason()); link2.setLinkStatus(0); link2.setEnableArchive(1); + link2.setRejectVersion(link.getRejectVersion()); linkMapper.insert(link2); //鏇存柊涓昏〃鐘舵�� mainService.updateStatusById(link.getMainId(),2); @@ -61,23 +68,143 @@ //鏇存柊鑺傜偣淇℃伅 linkMapper.updateById(link); if(link.getLinkStatus() == 2){ //椹冲洖 - //椹冲洖鍒板憳宸ヨ繘琛屽鐞� - //鏌ヨ宸ュ崟鐨勫憳宸� - Long createUserId = mainService.getInfoById(link.getMainId()).getCreateUserId(); - WorksheetLink link2 = new WorksheetLink(); - link2.setMainId(link.getMainId()); - link2.setParentId(link.getId()); - link2.setDealUserId(createUserId); - link2.setDealType(0); - link2.setDealDesc("宸ュ崟琚粡鐞嗛┏鍥�,椹冲洖淇℃伅:"+link.getDealReason()); - link2.setLinkStatus(0); - link2.setEnableArchive(0); - linkMapper.insert(link2); - //鏇存柊涓昏〃鐘舵�� - mainService.updateStatusById(link.getMainId(),0); + if(link.getParentId()!=0) { + //鏌ヨ瀵瑰簲鐨勯」鐩粡鐞� + Long createUserId = linkMapper.selectById(link.getParentId()).getDealUserId(); + WorksheetLink link2 = new WorksheetLink(); + link2.setMainId(link.getMainId()); + link2.setParentId(link.getId()); + link2.setDealUserId(createUserId); + link2.setDealType(0); + link2.setDealDesc("宸ュ崟琚�荤粡鐞嗛┏鍥�,椹冲洖淇℃伅:" + link.getDealReason()); + link2.setLinkStatus(0); + link2.setEnableArchive(0); + link2.setRejectVersion(link.getRejectVersion()); + linkMapper.insert(link2); + //鏇存柊涓昏〃鐘舵�� + mainService.updateStatusById(link.getMainId(), 1); + }else{ + //璇存槑鏄」鐩粡鐞嗘彁浜ょ殑,椹冲洖鍗崇粓姝� + mainService.updateEndStatusById(link.getMainId(),"鎬荤粡鐞嗛┏鍥�",0); + } }else{ //瀹℃壒閫氳繃,鏇存柊涓昏〃鐘舵�� mainService.updateEndStatusById(link.getMainId(),"瀹岀粨",5); + //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞 + QueryWrapper<ProductBomApproving> query = Wrappers.query(); + query.eq("main_id",link.getMainId()); + List<ProductBomApproving> approvingList = approvingMapper.selectList(query); + + //澧炲姞->澧炲姞閮ㄤ欢(澧炲姞璁板綍,鍚屾椂鎵�鏈塭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); + } + //杞寲涓簆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); + } + /*鏇存柊鍒皃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); } } @@ -89,4 +216,28 @@ public List<WorksheetLink> getInfoList(Long id) { return linkMapper.getInfoList(id); } + + /** + * + * @param userId 鎬荤粡鐞嗗搴旂殑userId + * @param statusExp 0:鏈鎵�,1:宸插鎵�(鍖呭惈鐘舵�佸��1,2) + * @return + */ + public List<WorksheetMain> getInfoList2(Long userId, int statusExp) { + return linkMapper.getInfoList2(userId,statusExp); + } + + /** + * + * @param userId 鎬荤粡鐞嗗搴旂殑userId + * @param statusExp 0:鏈鎵�,1:宸插鎵�(鍖呭惈鐘舵�佸��1,2) + * @return + */ + public List<WorksheetMain> getInfoList3(Long userId, int statusExp) { + return linkMapper.getInfoList3(userId,statusExp); + } + + public DocUser getApprovingUser(Integer mainId) { + return linkMapper.getApprovingUser(mainId); + } } -- Gitblit v1.9.1