From cf9a5039e6db9d1d5963e3fe1a37d00169ec2ef7 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期三, 25 六月 2025 11:18:22 +0800 Subject: [PATCH] 验收报告修改 --- src/main/java/com/whyc/service/WorksheetLinkService.java | 672 +++++++++++++++++++++++++++++++++++++------------------ 1 files changed, 454 insertions(+), 218 deletions(-) diff --git a/src/main/java/com/whyc/service/WorksheetLinkService.java b/src/main/java/com/whyc/service/WorksheetLinkService.java index d2cb427..a93f1d8 100644 --- a/src/main/java/com/whyc/service/WorksheetLinkService.java +++ b/src/main/java/com/whyc/service/WorksheetLinkService.java @@ -3,10 +3,13 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import com.whyc.config.EnumWorksheetType; +import com.whyc.dto.Response; import com.whyc.mapper.ProductBomApprovingMapper; import com.whyc.mapper.WorksheetLinkMapper; import com.whyc.pojo.*; import com.whyc.util.CommonUtil; +import com.whyc.util.FileUtil; +import com.whyc.util.WordUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -14,9 +17,9 @@ import javax.annotation.Resource; import java.io.File; +import java.io.FilenameFilter; import java.io.IOException; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; import java.util.stream.Collectors; @Service @@ -27,21 +30,51 @@ @Resource private WorksheetLinkMapper linkMapper; - - @Autowired + //lxw淇敼 + @Autowired(required = false) private ProductBomApprovingMapper approvingMapper; @Autowired private ProductBomService bomService; @Autowired + private ProductApprovingService paService; + + @Autowired + private ProductService productService; + + @Autowired private ProductBomHistoryService historyService; @Autowired - private ComponentProductHistoryService cphService; + private ProductBomApprovingService pbaService; @Autowired - private ComponentProductApprovingService cpAService; + private MaterialProductHistoryService mphService; + + @Autowired + private MaterialProductApprovingService cpAService; + + @Autowired + private MaterialApprovingService mAService; + + @Autowired + private MaterialService mService; + + @Autowired + private ProductSoftwareApprovingService productSoftwareApprovingService; + + @Autowired + private ProductSoftwareService productSoftwareService; + + @Autowired + private ProductHistoryService phService; + + @Autowired + private ProcedureDocApprovingService procedureDocApprovingService; + + @Autowired + private ProcedureDocService procedureDocService; @Transactional public void audit(WorksheetLink link) { @@ -49,6 +82,10 @@ //鏇存柊鑺傜偣淇℃伅 linkMapper.updateById(link); if(link.getLinkStatus() == 2){ //椹冲洖 + //鏌ョ湅鏄惁涓虹墿鏂欏鎵�,鏄垯闇�瑕佹洿鏂扮墿鏂欏鎵硅〃涓殑鐘舵�佷负瀹岀粨 + if(mainService.getInfoById(link.getMainId()).getType().equals(EnumWorksheetType.Material.getType())){ + mAService.endStatus(link.getMainId()); + } //椤圭洰缁忕悊椹冲洖,椹冲洖鍗崇粓姝� mainService.updateEndStatusById(link.getMainId(),"缁忕悊椹冲洖,椹冲洖鍘熷洜:"+link.getDealReason(),0); //椤圭洰缁忕悊椹冲洖鍓�,杩樻浘缁忚繃鎬荤粡鐞�,鍒欓渶瑕佸鍔犳�荤粡鐞嗛┏鍥炲師鍥� @@ -73,7 +110,6 @@ link2.setDealDesc("宸ュ崟琚粡鐞嗗鏍搁�氳繃,淇℃伅:"+link.getDealReason()); link2.setLinkStatus(0); link2.setEnableArchive(1); - link2.setRejectVersion(link.getRejectVersion()); linkMapper.insert(link2); //鏇存柊涓昏〃鐘舵�� mainService.updateStatusById(link.getMainId(),2); @@ -99,7 +135,6 @@ link2.setDealDesc("宸ュ崟琚�荤粡鐞嗛┏鍥�,椹冲洖淇℃伅:" + link.getDealReason()); link2.setLinkStatus(0); link2.setEnableArchive(0); - link2.setRejectVersion(link.getRejectVersion()); linkMapper.insert(link2); //鏇存柊涓昏〃鐘舵�� mainService.updateStatusById(link.getMainId(), 1); @@ -111,93 +146,256 @@ //瀹℃壒閫氳繃,鏇存柊涓昏〃鐘舵�� mainService.updateEndStatusById(link.getMainId(), "瀹岀粨", 5); if (type.intValue() == EnumWorksheetType.ProductBom.getType()) { //浜у搧瀹℃壒 - //灏嗕骇鍝佹枃浠跺鍒惰嚦姝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(); + ProductApproving productApproving = paService.getByMainId(link.getMainId()); + List<ProductBomApproving> approvingList = pbaService.getList(productApproving.getId()); + //鏌ヨ浜у搧鏈�鏂扮殑鐗堟湰鍙� + String parentModel = productApproving.getParentModel(); + String parentCode = productApproving.getParentCode(); + String customCode = productApproving.getCustomCode(); + ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode); + ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode); + int currentVersion = 0; + if (latestProduct != null) { + currentVersion = latestProduct.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); + //浜у搧鐗╂枡鍏崇郴杩佺Щ + //鏌ヨ鐢熸晥鐗堟湰鐨勫叧鑱斿叧绯� + if(latestProduct!=null &&enabledProduct!=null) { + List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion()); + if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) { + //鏈�鏂扮増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰杩炵潃鐨� + mphService.updateVersionBatch(mpList); } else { - approvingBom.setVersion(0); + //鏃х増鏈敓鏁�,鍏宠仈鍏崇郴鐗堟湰涓嶈繛鐫� + mpList.forEach(mp -> { + mp.setSVersion(nextVersion); + mp.setEVersion(nextVersion); + }); + mphService.insertBatch(mpList); } - //杞寲涓簆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); } - //鏇存柊鏁d欢琛ㄥ綋鍓嶇増鏈�,鏇存柊eVersion - List<ComponentProductHistory> cphList = cphService.getListByParentModel(approvingList.get(0).getParentModel(),currentVersion); - if(cphList.size()!=0){cphService.updateVersionBatch(cphList);} - /*鏇存柊鍒皃roduct_bom*/ - //鏌ヨ鏂扮殑鐗堟湰 - List<ProductBomHistory> newBomList = historyService.getListByParentModel(approvingList.get(0).getParentModel(), nextVersion); - bomService.updateNewBom(newBomList); + //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞 + //鏂囦欢杞Щ,鏈窡瀛愪欢鎸傞挬鐨勬墍鏈夊浘绾稿浘鐗囪浆绉诲埌浜у搧鐗堟湰涓�:doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/ + //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/ + //瀛樺偍鏈瀹℃壒鏂囦欢澶圭粷瀵硅矾寰� + String fileUrl = productApproving.getFileUrl(); + File file = new File(fileUrl); + List<String> fileUrlList = new LinkedList<>(); + List<String> dwgUrlList = null; + List<String> picUrlList = null; + //瀛樹簬鐗╂枡涓�,bom鍐呮湁瀵瑰簲 + List<String> materialUrlList = new LinkedList<>(); + //瀛樹簬浜у搧涓�,bom鍐呮病瀵瑰簲 + List<String> productUrlList = new LinkedList<>(); - /*String projectDir = CommonUtil.getProjectDir(); - FileUtil.copyDir()*/ + List<Material> materialDwgUrlNameList = new LinkedList<>(); + + fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList); + //鍥剧焊dwg 瀛愪欢/浜у搧 + dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList()); + picUrlList = fileUrlList.stream().filter(url->url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList()); + + dwgUrlList.forEach(dwgUrl->{ + boolean existFlag = false; + for (ProductBomApproving approving :approvingList){ + String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4); + String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1); + if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){ + materialUrlList.add(dwgUrl); + existFlag = true; + + Material temp = new Material(); + temp.setSubModel(approving.getSubModel()); + temp.setNotes("doc_file" + File.separator + "material" + + File.separator + fileFullName); + materialDwgUrlNameList.add(temp); + break; + } + } + if(!existFlag) { + productUrlList.add(dwgUrl); + } + }); + + //涓�瀹氭槸鏈夊搴旂墿鏂欑殑,浠巄om鍐呭墺绂荤殑 + picUrlList.forEach(picUrl->{ + for (ProductBomApproving approving :approvingList){ + String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.length() - 4); + String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1); + if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){ + approving.setPictureUrl("doc_file" + File.separator + "material" + + File.separator + fileFullName); + break; + } + } + }); + + //杞Щ璺緞 + String projectDir = CommonUtil.getProjectDir(); + //doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/ + //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/ + String customCodeString = null; + if(customCode!=null && !customCode.equals("")) { + customCodeString = customCode; + }else{ + customCodeString = "standard"; + } + String productDir = projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + parentModel + + File.separator + customCodeString + File.separator +nextVersion; + String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material"; + File productDirFile = new File(productDir); + File materialFile = new File(materialDir); + if(!productDirFile.exists()){ + productDirFile.mkdirs(); + } + if(!materialFile.exists()){ + materialFile.mkdirs(); + } + productUrlList.forEach(productUrl->{ + String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4); + + try { + FileCopyUtils.copy(new File(productUrl),new File(productDir+File.separator+dwgName+".dwg")); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + materialUrlList.forEach(materialUrl->{ + String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4); + try { + FileCopyUtils.copy(new File(materialUrl),new File(materialDir+File.separator+dwgName+".dwg")); + } catch (IOException e) { + e.printStackTrace(); + } + }); + + picUrlList.forEach(picUrl->{ + String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1); + try { + FileCopyUtils.copy(new File(picUrl),new File(materialDir+File.separator+picFullName)); + } catch (IOException e) { + e.printStackTrace(); + } + }); - /*灏嗕骇鍝乥om琛ㄧ殑url淇,鏇存柊鍒版寮忚〃*/ - //瀹℃壒瀹屽悗,灏嗘湰娆$殑bom甯rl鐨勫叏閮ㄥ鍒跺埌姝e紡鏂囦欢澶逛腑 - List<ProductBomApproving> fileBomApprovingList = approvingList.stream() + //杞Щ瀹℃壒琛ㄦ暟鎹埌鍘嗗彶琛�/鏈�鏂扮増鏈〃 product_history/product_bom_history/product/product_bom + ProductHistory productHistory = new ProductHistory(); + productHistory.setParentCode(parentCode); + productHistory.setParentName(productApproving.getParentName()); + productHistory.setParentModel(parentModel); + productHistory.setNotes(productApproving.getNotes()); + productHistory.setCustomCode(customCode); + productHistory.setCreateTime(new Date()); + productHistory.setVersion(nextVersion); + productHistory.setEnabled(1); + + Product productNew = new Product(); + productNew.setParentCode(parentCode); + productNew.setParentName(productApproving.getParentName()); + productNew.setParentModel(parentModel); + productNew.setNotes(productApproving.getNotes()); + productNew.setCustomCode(customCode); + productNew.setCreateTime(new Date()); + productNew.setVersion(nextVersion); + + //瀹為檯鐢熸晥鐨勫彧鏈塱nsert,鍥犱负鐘舵�佽缃负鏈惎鐢ㄥ凡缁忓湪鎻愪氦瀹℃壒鏃跺彉鏇翠簡 + phService.insertAndUpdateEnabled(productHistory); + + productService.insert(productNew); + + List<ProductBomHistory> productBomHistoryList = new LinkedList<>(); + List<ProductBom> productBomList = new LinkedList<>(); + approvingList.forEach(approving->{ + ProductBomHistory bomHistory = new ProductBomHistory(); + ProductBom bom = new ProductBom(); + + bom.setProductId(productNew.getId()); + bom.setCategory(approving.getCategory()); + bom.setCreateDate(new Date()); + bom.setDwgUrl(approving.getDwgUrl()); + bom.setFileUrl(approving.getFileUrl()); + bom.setMaterial(approving.getMaterial()); + bom.setNotes(approving.getNotes()); + bom.setPictureUrl(approving.getPictureUrl()); + bom.setProducer(approving.getProducer()); + bom.setQuantity(approving.getQuantity()); + bom.setSubCode(approving.getSubCode()); + bom.setSubModel(approving.getSubModel()); + bom.setSubName(approving.getSubName()); + bom.setSurfaceDetail(approving.getSurfaceDetail()); + bom.setThickness(approving.getThickness()); + bom.setType(approving.getType()); + bom.setUnit(approving.getUnit()); + //bom.setUpUserId(approving.getUpUserId()); + bom.setVersion(nextVersion); + + bomHistory.setProductId(productHistory.getId()); + bomHistory.setCategory(approving.getCategory()); + bomHistory.setCreateDate(new Date()); + bomHistory.setDwgUrl(approving.getDwgUrl()); + bomHistory.setFileUrl(approving.getFileUrl()); + bomHistory.setMaterial(approving.getMaterial()); + bomHistory.setNotes(approving.getNotes()); + bomHistory.setPictureUrl(approving.getPictureUrl()); + bomHistory.setProducer(approving.getProducer()); + bomHistory.setQuantity(approving.getQuantity()); + bomHistory.setSubCode(approving.getSubCode()); + bomHistory.setSubModel(approving.getSubModel()); + bomHistory.setSubName(approving.getSubName()); + bomHistory.setSurfaceDetail(approving.getSurfaceDetail()); + bomHistory.setThickness(approving.getThickness()); + bomHistory.setType(approving.getType()); + bomHistory.setUnit(approving.getUnit()); + //bomHistory.setUpUserId(approving.getUpUserId()); + bomHistory.setVersion(nextVersion); + + productBomHistoryList.add(bomHistory); + productBomList.add(bom); + }); + historyService.addBatch(productBomHistoryList); + bomService.insertBatch(productBomList); + + //鐗╂枡琛ㄤ腑涓嶅瓨鍦ㄧ殑,鍒欐坊鍔犲埌鐗╂枡琛ㄤ腑鍘� + List<String> codeList = approvingList.stream().map(ProductBomApproving::getSubCode).collect(Collectors.toList()); + List<String> existCodeList = mService.getListByCodeList(codeList); + List<Material> materialList = new LinkedList<>(); + approvingList.forEach(approving->{ + if(!existCodeList.contains(approving.getSubCode())){ //杩欎釜瀹℃壒bom涓殑鐗╂枡涓嶅湪鐗╂枡绠$悊鍐� + Material temp = new Material(); + //temp.setCategory(approving.getCategory()); + temp.setCreateDate(new Date()); + temp.setDwgUrl(approving.getDwgUrl()); + temp.setFileUrl(approving.getFileUrl()); + //temp.setMaterial(approving.getMaterial()); + temp.setNotes(approving.getNotes()); + temp.setPictureUrl(approving.getPictureUrl()); + //temp.setProducer(approving.getProducer()); + //TODO quantity + //temp.setQuantity(approving.getQuantity()); + temp.setStatus(1); + temp.setSubCode(approving.getSubCode()); + temp.setSubModel(approving.getSubModel()); + temp.setSubName(approving.getSubName()); + //temp.setSurfaceDetail(approving.getSurfaceDetail()); + //temp.setThickness(approving.getThickness()); + temp.setType(approving.getType()); + temp.setUnit(approving.getUnit()); + materialList.add(temp); + } + }); + if(materialList.size()!=0) { + mService.insertBatch(materialList); + } + //灏哾wg鍥剧焊,鍏ㄩ儴鏇存柊鍒板搴旂殑璁板綍url涓� + if(materialDwgUrlNameList.size()!=0) { + mService.updateDwgUrl(materialDwgUrlNameList); + } + /*List<ProductBomApproving> fileBomApprovingList = approvingList.stream() .filter(productBomApproving -> productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null ).collect(Collectors.toList()); @@ -231,152 +429,133 @@ } }); //鏇存柊姝e紡bom鐨勫搴攗rl - bomService.updateUrl(fileBomApprovingList); + bomService.updateUrl(fileBomApprovingList);*/ } - else if(type.intValue() == EnumWorksheetType.Component.getType()){ //鏁h浠� TODO + else if(type.intValue() == EnumWorksheetType.Material.getType()){ //鐗╂枡 + List<MaterialApproving> approvingList = mAService.getListByMainId(link.getMainId()); + List<Material> materialList = new LinkedList<>(); + //鍖哄垎鏄柊澧炶繕鏄垹闄� + Integer materialId = approvingList.get(0).getMaterialId(); + if(materialId==null) { //鏂板 + String fileUrl = approvingList.get(0).getFileUrl(); + File file = new File(fileUrl); - } - else if(type.intValue() == EnumWorksheetType.ComponentProduct.getType()){ //鏇存柊鏁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(); + List<String> fileUrlList = new LinkedList<>(); + List<String> dwgUrlList = null; + List<String> materialUrlList = new LinkedList<>(); + List<Material> materialDwgUrlNameList = new LinkedList<>(); + + fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList); + dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList()); + //鍥剧焊涓庣墿鏂檓odel瀵瑰簲,鍒欏浘绾搁渶瑕佷繚鐣欏苟杞Щ鍒版寮忔枃浠跺す + //鍚屾椂,淇濈暀鍥剧焊瀵瑰簲鐨勭墿鏂檓odel鍜屾寮忔枃浠跺す涓殑http url + dwgUrlList.forEach(dwgUrl-> { + approvingList.forEach(approving -> { + String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4); + String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1); + if (approving.getSubModel().toUpperCase().equals(filename.toUpperCase())) { + materialUrlList.add(dwgUrl); + + Material temp = new Material(); + temp.setSubModel(approving.getSubModel()); + temp.setNotes("doc_file" + File.separator + "material" + + File.separator + fileFullName); + materialDwgUrlNameList.add(temp); + } + }); + }); + String projectDir = CommonUtil.getProjectDir(); + String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material"; + File materialFile = new File(materialDir); + if(!materialFile.exists()){ + materialFile.mkdirs(); + } + + materialUrlList.forEach(materialUrl->{ + String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4); + try { + FileCopyUtils.copy(new File(materialUrl),new File(materialDir+File.separator+dwgName+".dwg")); + } catch (IOException e) { + e.printStackTrace(); + } + }); + //灏嗙墿鏂欎粠瀹℃壒琛ㄤ腑杞Щ鍒版寮忚〃 + 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()); + //TODO quantity + //material.setQuantity(approve.getQuantity()); + //material.setProducer(approve.getProducer()); + material.setNotes(approve.getNotes()); + material.setCreateDate(new Date()); + material.setStatus(1); + materialDwgUrlNameList.forEach(materialDwgUrlName->{ + if(materialDwgUrlName.getSubModel().equals(approve.getSubModel())){ + material.setDwgUrl(materialDwgUrlName.getDwgUrl()); + } + }); + materialList.add(material); + }); + mService.insertBatch(materialList); + }else{ //鍒犻櫎 + List<Integer> materialIdList = approvingList.stream().map(MaterialApproving::getMaterialId).collect(Collectors.toList()); + mService.deleteBatch(materialIdList); } - 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<>(); + //鏇存柊鐗╂枡瀹℃壒瀛愯〃涓璽ype涓哄畬缁� + mAService.endStatus(link.getMainId()); + } + else if(type.intValue() == EnumWorksheetType.MaterialProduct.getType()){ //鏇存柊鐗╂枡-浜у搧鍏崇郴 + //鏌ユ壘鍒板搴旂殑鐗╂枡-浜у搧鍏崇郴鏁版嵁 + List<MaterialProductApproving> cpAList = cpAService.getListByMainId(link.getMainId()); + //褰撳墠鐗堟湰 + int version = cpAList.get(0).getVersion(); + //鏂板鍏宠仈/绉婚櫎鍏宠仈 + Map<Integer, List<MaterialProductApproving>> linkTypeMap = cpAList.stream().collect(Collectors.groupingBy(MaterialProductApproving::getLinkType)); + List<MaterialProductHistory> addedList = new LinkedList<>(); + List<MaterialProductApproving> removedList = new LinkedList<>(); linkTypeMap.forEach((linkType,list)->{ if(linkType == 1){ - addedList.addAll(list); - }else if(linkType == 2){ - replacedList.addAll(list); + list.forEach(approving->{ + MaterialProductHistory his = new MaterialProductHistory(); + his.setParentCode(approving.getParentCode()); + his.setCustomCode(approving.getCustomCode()); + his.setSVersion(approving.getVersion()); + his.setEVersion(approving.getVersion()); + his.setSubMaterialId(approving.getSubMaterialId()); + his.setQuantity(approving.getQuantity()); + his.setMaterialId(approving.getMaterialId()); + his.setCreateTime(new Date()); + + addedList.add(his); + }); }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); - } - });*/ - Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator(); - while (iterator.hasNext()){ - if(remove.getComponentId().intValue() == iterator.next().getComponentId()){ - iterator.remove(); - break; - } - } - }); + //鏂板鍏宠仈 + if(addedList.size()!=0) { + mphService.insertBatch(addedList); } - - //澶勭悊鏇挎崲 - if(replacedList.size()!=0){ - replacedList.forEach(replace -> { - //褰撳墠鐢熸晥鐨勬暎瑁呬欢-浜у搧鍒楄〃 - /*nowHistoryList.forEach(nowHistory -> { - if (replace.getComponentId().intValue() == nowHistory.getComponentId()) { - nowHistoryList.remove(nowHistory); - } - });*/ - Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator(); - while (iterator.hasNext()){ - if(replace.getComponentId().intValue() == iterator.next().getComponentId()){ - iterator.remove(); - break; - } - } - //涓嬩釜鐗堟湰鏂板鏇挎崲鐨勬暎瑁呬欢-浜у搧鍒楄〃 - 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); - } - });*/ - Iterator<ProductBomHistory> iterator1 = nowBomHistoryList.iterator(); - while (iterator1.hasNext()){ - if(replace.getSubName().equals(iterator1.next().getSubName())){ - iterator1.remove(); - break; - } - } - }); + //绉婚櫎鍏宠仈 + if(removedList.size()!=0) { + mphService.updateVersionSubtractBatch(removedList); } + } + else if(type.intValue() == EnumWorksheetType.ProductSoftware.getType()){ //杞欢涓嬭浇 + //杞Щ璁板綍鍒版寮忚〃 + ProductSoftwareApproving productSoftwareApproving = productSoftwareApprovingService.getByMainId(link.getMainId()); + ProductSoftware productSoftware = new ProductSoftware(); + productSoftware.setParentModel(productSoftwareApproving.getParentModel()); + productSoftware.setSoftwareName(productSoftwareApproving.getSoftwareName()); + productSoftware.setSoftwareUrl(productSoftwareApproving.getSoftwareUrl()); + productSoftware.setSubmitTime(productSoftwareApproving.getCreateTime()); + productSoftware.setCreateTime(new Date()); - //澶勭悊鍏宠仈 - addedList.forEach(add -> { - /*nowHistoryList.forEach(nowHistory -> { - if (add.getComponentId().intValue() == nowHistory.getComponentId()) { - nowHistoryList.remove(nowHistory); - } - });*/ - Iterator<ComponentProductHistory> iterator = nowHistoryList.iterator(); - while (iterator.hasNext()){ - if(add.getComponentId().intValue() == iterator.next().getComponentId()){ - iterator.remove(); - break; - } - } - - ComponentProductHistory newHistory = new ComponentProductHistory(); - newHistory.setComponentId(add.getComponentId()); - newHistory.setParentModel(add.getParentModel()); - newHistory.setSubName(add.getSubName()); - newHistory.setCreateTime(new Date()); - newHistory.setLinkType(1); - 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)); - - cphService.updateVersionBatch(nowHistoryList); - cphService.insertBatch(newHistoryList); - historyService.updateVersionBatch(nowBomHistoryList); - //鏇存柊ProductBom - List<ProductBomHistory> newBomList = historyService.getListByParentModel(cpAList.get(0).getParentModel(), nextVersion); - bomService.updateNewBom(newBomList); + productSoftwareService.insert(productSoftware); } } } @@ -413,4 +592,61 @@ public DocUser getApprovingUser(Integer mainId) { return linkMapper.getApprovingUser(mainId); } + + @Transactional + public Response confirmProductProcedureAndSOP(WorksheetLink link) throws IOException { + Integer mainId = linkMapper.selectById(link.getId()).getMainId(); + //鏇存柊瀛愯〃 + linkMapper.updateById(link); + if(link.getLinkStatus() ==1){ + //鏌ヨ褰撳墠鍗曟嵁瀛愯〃鏄惁宸茬粡鍏ㄩ儴鍚屾剰 + QueryWrapper<WorksheetLink> query = Wrappers.query(); + query.eq("main_id",mainId); + List<WorksheetLink> linkList = linkMapper.selectList(query); + List<WorksheetLink> rejectList = linkList.stream().filter(linkFilter -> linkFilter.getLinkStatus() != 1).collect(Collectors.toList()); + if(rejectList == null){ + //閮戒负1,宸茬‘璁� + mainService.updateEndStatusById(mainId,"宸茬‘璁�",5); + //鏂囦欢杞Щ鍒板鎵瑰畬鎴愬悗鐨勬寮忚矾寰� 鏂囦欢淇濆瓨鍦�/doc_file/procedure/xxx.doc + ProcedureDocApproving approving = procedureDocApprovingService.getByMainId(mainId); + String fileRelativePath = approving.getFile(); + String projectDir = CommonUtil.getProjectDir(); + String inFilePath = projectDir + File.separator + fileRelativePath; + String outFilePath = (projectDir + File.separator + fileRelativePath).replace("_approving",""); + WordUtil.fillValue(inFilePath,outFilePath,Arrays.asList(approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb())); + //鍒犻櫎涔嬪墠棰勮浜х敓鐨勪腑闂存枃浠� + String filename = fileRelativePath.substring(fileRelativePath.lastIndexOf(File.separator)+1,fileRelativePath.lastIndexOf(".")); + File approvingDir = new File(projectDir + File.separator + "procedure_approving"); + FilenameFilter filenameFilter = new FilenameFilter() { + @Override + public boolean accept(File dir, String name) { + name = name.substring(0,name.lastIndexOf(".")); + if(name.contains(filename) && !name.equals(filename)){ + return true; + } + return false; + } + }; + File[] files = approvingDir.listFiles(filenameFilter); + for (File file : files) { + file.delete(); + } + + //娴佺▼鏂囦欢鏁版嵁杞Щ + ProcedureDoc procedureDoc = new ProcedureDoc(); + procedureDoc.setName(approving.getName()); + procedureDoc.setDescription(approving.getDescription()); + procedureDoc.setVersion(approving.getVersion()); + procedureDoc.setFzr(approving.getFzr()); + procedureDoc.setBz(approving.getBz()); + procedureDoc.setType(approving.getType()); + procedureDoc.setCreateTime(new Date()); + procedureDoc.setFile(fileRelativePath.replace("_approving","")); + procedureDocService.insert(procedureDoc); + } + }else{ + mainService.updateEndStatusById(mainId,"宸查┏鍥�",0); + } + return new Response().set(1); + } } -- Gitblit v1.9.1