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/ProductService.java | 522 +++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 465 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/whyc/service/ProductService.java b/src/main/java/com/whyc/service/ProductService.java index 9fa4fc0..bdc8e43 100644 --- a/src/main/java/com/whyc/service/ProductService.java +++ b/src/main/java/com/whyc/service/ProductService.java @@ -3,18 +3,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; import com.baomidou.mybatisplus.core.toolkit.Wrappers; +import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.whyc.dto.FileUrlDTO; import com.whyc.dto.Response; +import com.whyc.mapper.ProductHistoryMapper; import com.whyc.mapper.ProductMapper; import com.whyc.pojo.*; -import com.whyc.util.ActionUtil; -import com.whyc.util.CommonUtil; import com.whyc.util.DateUtil; -import com.whyc.util.FileUtil; -import com.whyc.util.Zip4jUtil; +import com.whyc.util.*; +import org.apache.poi.hssf.usermodel.*; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -24,12 +25,19 @@ import java.io.*; import java.text.SimpleDateFormat; import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.regex.Pattern; import java.util.stream.Collectors; @Service public class ProductService { @Autowired(required = false) private ProductMapper mapper; + + @Autowired(required = false) + private ProductHistoryMapper hisMapper; @Autowired private ProductHistoryService phService; @@ -49,10 +57,13 @@ @Autowired private ProductLockLogService productLockLogService; + @Autowired + private MaterialHistoryService materialHistoryService; + //鏌ヨ鍑烘墍鏈夌殑浜у搧淇℃伅(鍒嗛〉鍔犳ā绯婃煡璇�<浜у搧鐨勭紪鐮侊紝鍨嬪彿锛屽悕瀛楋紝瀹氬埗琛ㄧ紪鍙�> - public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode, int pageCurr, int pageSize) { - /*PageHelper.startPage(pageCurr,pageSize); - QueryWrapper wrapper=new QueryWrapper(); + public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode,Integer enabled, int pageCurr, int pageSize) { + PageHelper.startPage(pageCurr,pageSize); + /*QueryWrapper wrapper=new QueryWrapper(); if(parentCode!=null){ wrapper.like("parent_code",parentCode); } @@ -71,7 +82,15 @@ } wrapper.orderByAsc("id"); List list=mapper.selectList(wrapper);*/ - List list=mapper.getAllProduct(subCode,parentCode,parentName,parentModel,customCode); + List<Product> list=mapper.getAllProduct(subCode,parentCode,parentName,parentModel,customCode,enabled); + /*list.stream().forEach(product -> { + //1.鏌ヨ鏄惁瀛樺湪璇ヨ褰� + QueryWrapper qwrapper=new QueryWrapper(); + qwrapper.eq("id",product.getId()); + qwrapper.last("limit 1"); + ProductHistory pHis=hisMapper.selectOne(qwrapper); + product.setEnabled(pHis.getEnabled()); + });*/ PageInfo pageInfo=new PageInfo(list); return new Response().setII(1,list.size()>0,pageInfo,"杩斿洖浜у搧淇℃伅"); } @@ -130,8 +149,11 @@ File parentFile = new File(filePath); String originalFilename = file.getOriginalFilename(); File zipFile = new File(filePath + File.separator + originalFilename); - if (!zipFile.exists()) { + /*if (!zipFile.exists()) { zipFile.mkdirs(); + }*/ + if (!parentFile.exists()) { + parentFile.mkdirs(); } file.transferTo(zipFile); //瑙e帇鏂囦欢澶� @@ -146,14 +168,16 @@ String fileTempUrl = fileList.get(i); //鏌ヨ闇�涓婁紶鐨刡om鏁版嵁 //if (fileTempUrl.contains(".xls") && fileTempUrl.contains("(BOM)")) { + int excelType = 1; //.xls if (fileTempUrl.substring(fileTempUrl.lastIndexOf(File.separator)+1).contains("(BOM).xls")) { Workbook workbook = null; InputStream inputStream = new FileInputStream(new File(fileTempUrl)); workbook = WorkbookFactory.create(inputStream); inputStream.close(); - List<? extends PictureData> allPictures = workbook.getAllPictures(); + //List<? extends PictureData> allPictures = workbook.getAllPictures(); if(fileTempUrl.substring(fileTempUrl.lastIndexOf(".")+1).equals("xlsx")) { - Collections.sort(allPictures, new Comparator<PictureData>() { + excelType = 2; //.xlsx + /*Collections.sort(allPictures, new Comparator<PictureData>() { @Override public int compare(PictureData o1, PictureData o2) { // Name: /xl/media/image1.png - Content Type: image/png @@ -171,19 +195,76 @@ } - }); + });*/ } //鍙栫涓�涓猻heet琛� Sheet sheet = workbook.getSheetAt(0); + //瀛樺偍鍥剧墖淇℃伅鍙婃墍鍦ㄥ垎椤� + Map<Integer,PictureData> pictureDataMap = new HashMap<>(); + if(excelType == 1){ //.xls + HSSFPatriarch drawingPatriarch = ((HSSFSheet) sheet).getDrawingPatriarch(); + if(drawingPatriarch!=null) { + List<HSSFShape> children = drawingPatriarch.getChildren(); + for (HSSFShape child : children) { + HSSFPicture picture = (HSSFPicture) child; + HSSFPictureData pictureData = picture.getPictureData(); + HSSFClientAnchor anchor = (HSSFClientAnchor) child.getAnchor(); + //琛�,涓嶈兘璺ㄨ; + int row1 = anchor.getRow1(); + int row2 = anchor.getRow2(); + if (row1 == row2) { + //涓嶈法琛�,鏈夋晥 + pictureDataMap.put(row1, pictureData); + } + } + } + } + else if(excelType == 2){ //.xlsx + XSSFDrawing drawingPatriarch = ((XSSFSheet) sheet).getDrawingPatriarch(); + if(drawingPatriarch!=null) { + List<XSSFShape> children = drawingPatriarch.getShapes(); + for (XSSFShape child : children) { + XSSFPicture picture = (XSSFPicture) child; + XSSFPictureData pictureData = picture.getPictureData(); + XSSFClientAnchor anchor = (XSSFClientAnchor) child.getAnchor(); + //琛�,涓嶈兘璺ㄨ; + int row1 = anchor.getRow1(); + int row2 = anchor.getRow2(); + if (row1 == row2) { + //涓嶈法琛�,鏈夋晥 + pictureDataMap.put(row1, pictureData); + } + } + } + } + Set<Integer> pictureRowSet = new HashSet<>(); + if(!pictureDataMap.isEmpty()) { + pictureRowSet = pictureDataMap.keySet(); + } int lastRowNum = sheet.getLastRowNum(); //鍙栫涓夎,骞朵互绗笁琛屽紑濮� Row row2 = sheet.getRow(1); + //鐜板湪瑙勫畾涓�17鍒� short lastCellNum = row2.getLastCellNum(); + if(lastCellNum !=18){ + return response.set(1, false, "涓婁紶鏂囦欢鐨刡om娓呭崟鍒楁暟涓嶅"); + } for (int k = 2; k < lastRowNum + 1; k++) { if(k==2){ product.setParentCode(sheet.getRow(2).getCell(1).getStringCellValue()); + if(!originalFilename.contains(product.getParentCode())){ + return response.set(1,false,"涓婁紶鐨勪骇鍝佸帇缂╁寘蹇呴』鍖呭惈浜у搧缂栫爜"); + } product.setParentName(sheet.getRow(2).getCell(2).getStringCellValue()); - product.setParentModel(sheet.getRow(2).getCell(3).getStringCellValue()); + String parentModel = sheet.getRow(2).getCell(3).getStringCellValue(); + parentModel = parentModel.trim(); + String regexStr = "[\\/*?\"|:<>\t]"; + boolean matches = Pattern.compile(regexStr).matcher(parentModel).find(); + if(!matches) { + product.setParentModel(parentModel); + }else{ + return response.set(1,false,"姣嶆枡鍨嬪彿鍖呭惈闈炴硶瀛楃:\\/*?\"|:<>鎴栧墠缃┖鏍�"); + } } ProductBom bom = new ProductBom(); for (int j = 0; j < lastCellNum; j++) { @@ -191,9 +272,9 @@ Cell cell = row.getCell(j); String cellValue = null; Double cellValueInt = 0d; - if (j == 9 || j == 0) { + if (j == 9 || j == 0) { //1鍜�10鍒椾负鏁板�� cellValueInt = cell.getNumericCellValue(); - } else if (j != 15) { + } else if (j != 16) { //16鍒椾负鍥剧墖 cellValue = cell.getStringCellValue(); } if(cellValue!=null) { @@ -245,22 +326,27 @@ } break; case 11: { - bom.setMaterial(cellValue); + bom.setProducerSpecification(cellValue); } break; case 12: { - bom.setThickness(cellValue); + bom.setMaterial(cellValue); } break; case 13: { - bom.setSurfaceDetail(cellValue); + bom.setThickness(cellValue); } break; case 14: { - bom.setNotes(cellValue); + bom.setSurfaceDetail(cellValue); } break; case 15: { + bom.setNotes(cellValue); + } + break; + case 16: { + /* 寮冪敤,涓嶉�傜敤浜� 鍥剧墖涓嶆寜椤哄簭鎽嗘斁鎯呭喌 //鍥剧墖,浠�0寮�濮�,鍒板浘鐗噑ize涓烘 int m = k - 2; if (m < allPictures.size()) { @@ -281,6 +367,44 @@ fileOutputStream.write(data); bom.setPictureUrl(picturePathFront); + }*/ + if (!pictureRowSet.isEmpty() && pictureRowSet.contains(k)) { + + PictureData pictureData = pictureDataMap.get(k); + //鍒ゆ柇鐗╂枡鍨嬪彿鏄惁鍖呭惈闈炴硶瀛楃(鍥剧墖浼氳浆鍖栦负璺緞) + if(bom.getSubModel()!=null) { + String regexStr = "[\\/*?\"|:<>\t]"; + boolean matches = Pattern.compile(regexStr).matcher(bom.getSubModel()).find(); + if (matches) { + return response.set(1, false, "鍨嬪彿涓�"+bom.getSubModel()+"鐨勭墿鏂欏寘鍚潪娉曞瓧绗�:\\/*?\"|:<>鎴栧墠缃┖鏍�"); + } + } + //鍥剧墖瀛樺偍 product_submit/username/2022-07/ + String approvingPath = rootFile + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp; + File provingFile = new File(approvingPath); + if (!provingFile.exists()) { + provingFile.mkdirs(); + } + String suffix = pictureData.suggestFileExtension(); + String picturePath = approvingPath + File.separator + bom.getSubModel() + "-bom." + suffix; + String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "-bom." + suffix; + byte[] data = pictureData.getData(); + FileOutputStream fileOutputStream = null; + File pictureFile = new File(picturePath); + fileOutputStream = new FileOutputStream(pictureFile); + fileOutputStream.write(data); + + bom.setPictureUrl(picturePathFront); + } + } + break; + case 17: { + if(cellValue!=null && !cellValue.trim().equals("")) { + if(cellValue.contains(",") || cellValue.contains("锛�")){ + bom.setRelatedMaterialCodes(cellValue); + }else{ + return response.set(1, false, "涓婁紶鏂囦欢鐨刡om娓呭崟鍐呮浛鏂欐牸寮忎笉瀵�"); + } } } break; @@ -288,6 +412,19 @@ } bomList.add(bom); } + //杩藉姞鐗╂枡瑙勮寖鏍¢獙 鏆傛椂鍘婚櫎杩欎釜鍔熻兘 + /*List<MaterialCheckDTO> checkList = bomList.stream().map(bom->{ + MaterialCheckDTO dto = new MaterialCheckDTO(); + dto.setNum(bom.getId()); + dto.setSubCode(bom.getSubCode()); + dto.setSubName(bom.getSubName()); + dto.setSubModel(bom.getSubModel()); + return dto; + }).collect(Collectors.toList()); + List<MaterialCheckDTO> irregularList = CommonUtil.checkFormat(checkList); + if(irregularList.size()>0){ + return response.setII(1,false,irregularList,"鍚嶇О鎴栧瀷鍙峰懡鍚嶄笉瑙勮寖"); + }*/ product.setBomList(bomList); } } @@ -311,17 +448,32 @@ return list; } - @Transactional + /** + * 杩欎釜鎺ュ彛鏄繘琛屼骇鍝佹柊澧�,浜у搧bom鏂板鐨勬帴鍙�. + * 鏂板鏂瑰紡鏈夊緢澶�,鏈夌洿鎺ヤ粠zip瑙f瀽鏂板浜у搧,涔熷彲浠ュ熀浜庡師鏈変骇鍝佸鍒惰繘琛屽畾鍒剁瓑.闇�瑕佹敞鎰忓吋瀹�! + * @param product 浜у搧鏂板,bom鏂板,浜у搧鐗堟湰鏇存柊 + * @return + * @throws IOException + */ + @Transactional(rollbackFor = {RuntimeException.class,Exception.class}) public Response add(Product product) throws IOException { String parentCode = product.getParentCode(); String customCode = product.getCustomCode(); String parentModel = product.getParentModel(); List<ProductBom> bomList = product.getBomList(); String zipFilePath = product.getFileUrl(); - String fileUrl = zipFilePath.substring(0,zipFilePath.lastIndexOf(File.separator)); Date date = new Date(); + String dateStr = DateUtil.YYYY_MM_DD_HH_MM_SS_UNION.format(date); + Long userId = ActionUtil.getUser().getId(); boolean isCopyCustom = false; Product relatedProduct = null; + //鏍¢獙鍑℃槸鏈夊畾鍒惰〃鍗曞彿鐨勪骇鍝侊紝涓嶈兘浣跨敤宸蹭笂浼犺繃鐨勬爣鍑嗕骇鍝佺紪鐮� + if(customCode!=null && !customCode.trim().equals("")){ + ProductHistory standard = phService.getStandard(parentCode); + if(standard !=null){ + return new Response().set(1,false,"绯荤粺瀛樺湪姝ゆ姣嶇墿鏂欑紪鐮佺殑鏍囧噯浜у搧,鎷掔粷鎻愪氦"); + } + } //鍒ゆ柇鏄惁涓轰緷鎹骇鍝佸鍒跺畾鍒剁殑浜у搧 if(bomList == null){ bomList = pbService.getBomByProductId(product.getId()); @@ -330,6 +482,11 @@ if(product.getId() != null){ //鍏宠仈鍏崇郴浠庝骇鍝乮d缁ф壙 relatedProduct = getById(product.getId()); } + } + //涓嶆槸鍩轰簬浜у搧澶嶅埗,鍒欏繀瀹氬瓨鍦▃ip鍖�,蹇呯劧瀛樺湪璺緞 + String fileUrl = null; + if(!isCopyCustom) { + fileUrl = zipFilePath.substring(0, zipFilePath.lastIndexOf(File.separator)); } //鏌ヨ鏂板浜у搧鏈�鏂扮殑鐗堟湰鍙� ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode); @@ -423,6 +580,103 @@ } } + //鏌ヨ鏄惁bomList涓湁鏇挎枡 + // 鏈夌殑璇�,妫�鏌ュ叧鑱旇〃涓槸鍚﹀凡瀛樺湪鎴栨湰鐗堟湰宸茬敓鏁� + List<MaterialProductHistory> newAddedList = new LinkedList<>(); + List<MaterialProductHistory> versionUpdateList = new LinkedList<>(); + + List<MaterialProductHistory> mpListInDB = mphService.getListByParentCodeAndCustomCodeAndSubMaterialIdAndVersion(parentCode,customCode,bomList,currentVersion); + List<String> subMaterialListInDB = mpListInDB.stream().map(mp->mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).collect(Collectors.toList()); + bomList.forEach(bom->{ + if(bom.getRelatedMaterialCodes()!=null) { + String relatedMaterialCodes = bom.getRelatedMaterialCodes().trim(); + if (!relatedMaterialCodes.equals("")) { + if(subMaterialListInDB!=null&&subMaterialListInDB.size()>0){ + if (subMaterialListInDB.contains(bom.getSubCode()+"_"+bom.getSubModel())) { //褰撳墠鐗╂枡鏈夋浛浠f枡 + String[] relatedList; + if (relatedMaterialCodes.contains(",")) { + relatedList = relatedMaterialCodes.split(","); + } else { + relatedList = relatedMaterialCodes.split("锛�"); + } + for (String related : relatedList) { + bom.setRelatedMaterialCodes(related); + boolean exists = false; + for (MaterialProductHistory mp : mpListInDB) { + //鐗╂枡鐩稿悓,鏇夸唬鏂欑浉鍚� + if ((mp.getSubMaterial().getSubCode()+"_"+mp.getSubMaterial().getSubModel()).equals(bom.getSubCode()+"_"+bom.getSubModel()) + && mp.getRelatedSubMaterial().getSubCode().equals(related)) { + //鍙彲鑳藉瓨鍦�0 鍜� 1 鐨勬儏鍐�,鍥犱负鏌ヨ鐨勬槸 >=涓婁釜鐗堟湰 + if (nextVersion - mp.getEVersion() == 0) { //宸插瓨鍦�,鏃犻渶娣诲姞 + //break; + } else if (nextVersion - mp.getEVersion() == 1) { //鏇存柊鍒板綋鍓嶇増鏈� + mp.setEVersion(nextVersion); + versionUpdateList.add(mp); + } + exists = true; + } + } + if(!exists) { //涓嶅瓨鍦ㄧ浉閭诲強鐩稿悓鐨勮褰曠増鏈�,鏂板 + MaterialProductHistory newTemp = new MaterialProductHistory(); + newTemp.setParentCode(parentCode); + newTemp.setCustomCode(customCode); + newTemp.setSubCode(bom.getSubCode()); + Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true); + newTemp.setSubMaterialId(material.getId()); + newTemp.setSVersion(nextVersion); + newTemp.setEVersion(nextVersion); + newTemp.setQuantity(bom.getQuantity()); + //2323-09-08 涓庢潹绾㈠叞寰俊纭<灏辨寜鐓ф垜涓婁紶娓呭崟鐨勬椂闂达紝绯荤粺閲屾渶鏂扮殑鏄暐鍨嬪彿锛屽氨鍙栦粈涔堝瀷鍙�> + Material relatedMaterial = mService.getLastByCode(related); + if(relatedMaterial == null){ + throw new RuntimeException("褰撳墠鏇挎枡"+related+",缂栫爜鍦ㄥ钩鍙颁腑涓嶅瓨鍦�,鏃犳硶鍏宠仈鏇夸唬"); + } + newTemp.setMaterialId(relatedMaterial.getId()); + newTemp.setCreateTime(date); + newAddedList.add(newTemp); + } + } + } + else{ + String[] relatedList; + if (relatedMaterialCodes.contains(",")) { + relatedList = relatedMaterialCodes.split(","); + } else { + relatedList = relatedMaterialCodes.split("锛�"); + } + for (String related : relatedList) { + MaterialProductHistory newTemp = new MaterialProductHistory(); + newTemp.setParentCode(parentCode); + newTemp.setCustomCode(customCode); + newTemp.setSubCode(bom.getSubCode()); + Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true); + newTemp.setSubMaterialId(material.getId()); + newTemp.setSVersion(nextVersion); + newTemp.setEVersion(nextVersion); + newTemp.setQuantity(bom.getQuantity()); + //2323-09-08 涓庢潹绾㈠叞寰俊纭<灏辨寜鐓ф垜涓婁紶娓呭崟鐨勬椂闂达紝绯荤粺閲屾渶鏂扮殑鏄暐鍨嬪彿锛屽氨鍙栦粈涔堝瀷鍙�> + Material relatedMaterial = mService.getLastByCode(related); + if(relatedMaterial == null){ + throw new RuntimeException("褰撳墠鏇挎枡"+related+",缂栫爜鍦ㄥ钩鍙颁腑涓嶅瓨鍦�,鏃犳硶鍏宠仈鏇夸唬"); + } + newTemp.setMaterialId(relatedMaterial.getId()); + newTemp.setCreateTime(date); + newAddedList.add(newTemp); + } + } + } + } + } + }); + //鎵ц鏇存柊 + if(newAddedList.size()!=0) { + mphService.insertBatch(newAddedList); + } + if(versionUpdateList.size()!=0) { + mphService.updateVersionBatch(versionUpdateList); + } + + //灏嗕骇鍝佹枃浠跺鍒惰嚦姝e紡璺緞 //鏂囦欢杞Щ,鏈窡瀛愪欢鎸傞挬鐨勬墍鏈夊浘绾稿浘鐗囪浆绉诲埌浜у搧鐗堟湰涓�:doc_file/product/{浜у搧鍨嬪彿}/standard鎴栬�厈customCode}}/{version}/ //璺熷瓙浠舵寕閽╃殑杞Щ鍒板瓙浠跺浘绾镐笅:doc_file/material/ @@ -444,14 +698,15 @@ his.setVersionTime(product.getVersionTime()); his.setVersion(1); his.setSubVersionMax(1); - his.setEnabled(1); + //涓婁紶鍚庣殑鏈�鍒濆浣胯兘鐘舵�佷负-1 + //绗竴娆¤В閿佸悗,鍚庣画鐨勯攣瀹氬拰瑙i攣鍦�0鍜�1涔嬮棿鍒囨崲 + his.setEnabled(-1); phService.insertAndUpdateEnabled(his); //phService.insert(his); - // -> product + // -> product 鐜版湁浜у搧鍜屼骇鍝乥om闇�瑕佹彃鍏�,version榛樿涓�-1,鍚屾椂瑕佸仛鍒犻櫎鍘熸潵鐨勬棫鐗堟湰 product.setId(his.getId()); product.setCreateTime(date); - product.setVersion(1); - //insert(product); + product.setVersion(-1); deleteAndInsert(product); // -> bom bomList.forEach(bom-> { @@ -470,6 +725,7 @@ bomHistory.setMaterial(bom.getMaterial()); bomHistory.setNotes(bom.getNotes()); bomHistory.setProducer(bom.getProducer()); + bomHistory.setProducerSpecification(bom.getProducerSpecification()); bomHistory.setSurfaceDetail(bom.getSurfaceDetail()); bomHistory.setThickness(bom.getThickness()); bomHistory.setSubSVersion(1); @@ -491,7 +747,7 @@ fileUrlList = FileUtil.getStaticFilePath(file, fileUrlList); //鍥剧焊dwg 瀛愪欢/浜у搧 - excelExcludeUrlList = fileUrlList.stream().filter(url -> !(url.contains(".xls") || url.contains(".xlsx") || url.contains(".zip"))).collect(Collectors.toList()); + excelExcludeUrlList = fileUrlList.stream().filter(url -> !(url.contains(".xls") || url.contains(".xlsx"))).collect(Collectors.toList()); //picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList()); List<ProductBom> finalBomList = bomList; @@ -500,13 +756,14 @@ for (ProductBom bom : finalBomList) { String filename = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1, excelExcludeUr.lastIndexOf(".")); String fileFullName = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1); + String fileSuffix = fileFullName.substring(fileFullName.lastIndexOf(".")); if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase()) && excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("dwg")) { materialUrlList.add(excelExcludeUr); existFlag = true; - bom.setDwgUrl("doc_file" + File.separator + "material" - + File.separator + fileFullName); + bom.setDwgUrl("doc_file" + File.separator + "material" + File.separator + bom.getSubCode() + "-" + bom.getSubModel() + + File.separator + filename + "_" + dateStr + fileSuffix); break; } else if((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase()) && (excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("png") ||excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("jpeg")) @@ -515,8 +772,8 @@ existFlag = true; - bom.setPictureUrl("doc_file" + File.separator + "material" - + File.separator + fileFullName); + bom.setPictureUrl("doc_file" + File.separator + "material" + File.separator + bom.getSubCode() + "-" + bom.getSubModel() + + File.separator + filename + "_" + dateStr + fileSuffix); break; } } @@ -573,54 +830,102 @@ } }); - materialUrlList.forEach(materialUrl -> { - String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4); + //鐗╂枡dwg鍥剧焊瀛樺埌瀵瑰簲鐨� 鐗╂枡缂栫爜+鍨嬪彿 涓嬮潰 + for (String materialUrl : materialUrlList) { try { - File dwgFile = new File(materialDir + File.separator + dwgName + ".dwg"); - if(!dwgFile.exists()) { + String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4); + //纭畾鐗╂枡鐨勫叿浣撳瀷鍙� + String subModel = null; + String subCode = null; + for (ProductBom bom : bomList) { + String bomSubMode = bom.getSubModel(); + if (bomSubMode.toUpperCase().equals(dwgName.toUpperCase())) { + subModel = bomSubMode; + subCode = bom.getSubCode(); + break; + } + } + File dwgFile; + if (subModel != null) { + dwgFile = new File(materialDir + File.separator + subCode + "-" + subModel + File.separator + dwgName + "_" + dateStr + ".dwg"); + File dwgDir = new File(materialDir + File.separator + subCode + "-" + subModel); + if(!dwgDir.exists()){ + dwgDir.mkdirs(); + } + } else { + dwgFile = new File(materialDir + File.separator + dwgName + "_" + dateStr + ".dwg"); + } + if (!dwgFile.exists()) { FileCopyUtils.copy(new File(materialUrl), dwgFile); } } catch (IOException e) { e.printStackTrace(); } - }); + } - picUrlList.forEach(picUrl -> { + for (String picUrl : picUrlList) { String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1); + String picSubModel = picFullName.substring(0, picFullName.lastIndexOf(".")); + String picSuffix = picFullName.substring(picFullName.lastIndexOf(".")); try { - File picFile = new File(materialDir + File.separator + picFullName); - if(!picFile.exists()) { + //纭畾鐗╂枡鐨勫叿浣撳瀷鍙峰拰缂栫爜 + String subModel = null; + String subCode = null; + for (ProductBom bom : bomList) { + String bomSubMode = bom.getSubModel(); + if ((bomSubMode + "-bom").toUpperCase().equals(picSubModel.toUpperCase())) { + subModel = bomSubMode; + subCode = bom.getSubCode(); + break; + } + } + File picFile; + if (subModel != null) { + picFile = new File(materialDir + File.separator + subCode + "-" + subModel + File.separator + picSubModel + "_" + dateStr + picSuffix); + File picDir = new File(materialDir + File.separator + subCode + "-" + subModel); + if(!picDir.exists()){ + picDir.mkdirs(); + } + } else { + picFile = new File(materialDir + File.separator + picSubModel + "_" + dateStr + picSuffix); + } + if (!picFile.exists()) { FileCopyUtils.copy(new File(picUrl), picFile); } } catch (IOException e) { e.printStackTrace(); } - }); + } //鐗╂枡琛ㄤ腑涓嶅瓨鍦ㄧ殑(渚濇嵁:鐗╂枡缂栫爜+鐗╂枡鍨嬪彿),鍒欐坊鍔犲埌鐗╂枡琛ㄤ腑鍘�(鍖呭惈product杩欎釜鐗╂枡) - //娌℃湁鍥剧焊鍜屽浘鐗囩殑,鏇存柊鍥剧焊鍜屽浘鐗�;鏈夊浘绾稿拰鍥剧墖鐨�,涓嶆洿鏂板浘绾稿拰鍥剧墖 + //鏇存柊鍥剧焊鍜屽浘鐗� List<Material> materialExistList = mService.getListByCodeAndModelList2(bomList); //List<String> subCodeList = materialExistList.stream().map(Material::getSubCode).collect(Collectors.toList()); List<String> subCodeList = materialExistList.stream().map(material -> material.getSubCode()+"/"+material.getSubModel()).collect(Collectors.toList()); - List<Material> materialList = new LinkedList<>(); + //闇�瑕佹洿鏂板埌鐗╂枡琛ㄤ腑鐨勭墿鏂�(瀛樺湪鍥剧焊鎴栬�呭浘鐗�) + List<MaterialHistory> materialHistoryList = new LinkedList<>(); + //鏂扮墿鏂� + List<Material> newMaterialList = new LinkedList<>(); + //鍒ゆ柇鐗╂枡鏄惁宸茬粡瀛樺湪浜庣墿鏂欒〃涓� List<Material> materialUpdateList = new LinkedList<>(); - bomList.forEach(bom -> { - if (!subCodeList.contains(bom.getSubCode()+"/"+bom.getSubModel())) { + for (ProductBom bom : bomList) { + if (!subCodeList.contains(bom.getSubCode() + "/" + bom.getSubModel())) { Material material = new Material(); material.setCreateDate(date); material.setDwgUrl(bom.getDwgUrl()); material.setFileUrl(bom.getFileUrl()); material.setPictureUrl(bom.getPictureUrl()); - // TODO 鏄惁瑕佹洿鏂板悓鐗╂枡缂栫爜鐨勮�佺墿鏂欑姸鎬佷负0? material.setStatus(1); material.setSubCode(bom.getSubCode()); material.setSubModel(bom.getSubModel()); material.setSubName(bom.getSubName()); material.setType(bom.getType()); material.setUnit(bom.getUnit()); + material.setUpUserId(userId); - materialList.add(material); - }else{ //鐗╂枡宸茬粡瀛樺湪鐨� + newMaterialList.add(material); + } else { //鐗╂枡宸茬粡瀛樺湪鐨� + // 鐗╂枡鍘嗗彶琛ㄦ槸涓轰簡瀛樺偍鐗╂枡鐨勫巻鍙插浘鐗囧拰dwg鍥剧焊 Material material = new Material(); if (bom.getPictureUrl() != null) { material.setPictureUrl(bom.getPictureUrl()); @@ -628,15 +933,18 @@ if (bom.getDwgUrl() != null) { material.setDwgUrl(bom.getDwgUrl()); } - if(material.getPictureUrl()!=null || material.getDwgUrl()!=null){ + if (material.getPictureUrl() != null || material.getDwgUrl() != null) { material.setSubCode(bom.getSubCode()); material.setSubModel(bom.getSubModel()); materialUpdateList.add(material); } } - }); + } + //瀵规柊澧炲埌鐗╂枡琛ㄤ腑鐨勭墿鏂�,鏍规嵁 鐗╂枡缂栫爜+鐗╂枡鍨嬪彿 杩涜鍘婚噸澶勭悊 + newMaterialList = newMaterialList.stream().filter(distinctByKey(m->m.getSubCode()+"/"+m.getSubModel())).collect(Collectors.toList()); + //姣嶆枡鏄惁瀛樺湪 - Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel()); + Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel(),true); if (materialDB == null) { Material material = new Material(); material.setSubCode(product.getParentCode()); @@ -644,11 +952,12 @@ material.setSubModel(product.getParentModel()); material.setCreateDate(date); material.setStatus(1); + material.setUpUserId(userId); - materialList.add(material); + newMaterialList.add(material); } - if(materialList.size()!=0) { - mService.insertBatch(materialList); + if(newMaterialList.size()!=0) { + mService.insertBatch(newMaterialList); } if(materialUpdateList.size()!=0) { mService.updateDwgUrlAndPicUrl(materialUpdateList); @@ -657,7 +966,20 @@ // product鐨勪富閿部鐢ㄥ搴攑roduct_history鐨� //鏍规嵁缂栫爜鍜屽瀷鍙风‘瀹氱墿鏂檌d骞跺搴攓uantity,瀛樺叆鏁版嵁搴�. //List<Material> bomMaterialList = mService.getListByCodeAndModelList2(bomList); - List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList); + //List<ProductBom> bomMaterialList = pbService.getListByCodeAndModelList2(bomList); + List<Material> existMaterialListWithSameSubCodeAndModel = mService.getSameSubCodeAndModel(bomList); + List<ProductBom> bomMaterialList; + bomList.forEach(bom->{ + String codeModelUnionStr = bom.getSubCode() + "/" + bom.getSubModel(); + for (int i = 0; i < existMaterialListWithSameSubCodeAndModel.size(); i++) { + Material materialExists = existMaterialListWithSameSubCodeAndModel.get(i); + if(codeModelUnionStr.equals(materialExists.getSubCode() + "/" + materialExists.getSubModel())){ + bom.setId(materialExists.getId()); + break; + } + } + }); + bomMaterialList = bomList; // -> product_history ProductHistory productHistory = new ProductHistory(); productHistory.setParentCode(product.getParentCode()); @@ -670,12 +992,13 @@ productHistory.setVersion(nextVersion); //鐗堟湰鏂板,鍒濆bom瀛愪欢鐗堟湰涓�1 productHistory.setSubVersionMax(1); - productHistory.setEnabled(1); + + productHistory.setEnabled(-1); phService.insertAndUpdateEnabled(productHistory); - // -> product + // -> product 鐜版湁浜у搧鍜屼骇鍝乥om闇�瑕佹彃鍏�,version榛樿涓�-1,鍚屾椂瑕佸仛鍒犻櫎鍘熸潵鐨勬棫鐗堟湰 product.setId(productHistory.getId()); product.setCreateTime(date); - product.setVersion(nextVersion); + product.setVersion(-1); deleteAndInsert(product); // -> product_bom List<ProductBom> productBomList = new LinkedList<>(); @@ -688,6 +1011,7 @@ bom.setMaterial(bomMaterial.getMaterial()); bom.setNotes(bomMaterial.getNotes()); bom.setProducer(bomMaterial.getProducer()); + bom.setProducerSpecification(bomMaterial.getProducerSpecification()); bom.setSurfaceDetail(bomMaterial.getSurfaceDetail()); bom.setThickness(bomMaterial.getThickness()); bom.setSubVersion(1); @@ -707,6 +1031,7 @@ bomHistory.setMaterial(bomMaterial.getMaterial()); bomHistory.setNotes(bomMaterial.getNotes()); bomHistory.setProducer(bomMaterial.getProducer()); + bomHistory.setProducerSpecification(bomMaterial.getProducerSpecification()); bomHistory.setSurfaceDetail(bomMaterial.getSurfaceDetail()); bomHistory.setThickness(bomMaterial.getThickness()); bomHistory.setSubSVersion(1); @@ -716,6 +1041,58 @@ bomHistoryList.add(bomHistory); }); pbhService.insertBatch(bomHistoryList); + //鎻掑叆鍒扮墿鏂欏巻鍙茶〃鐨�, + // 鍖呭惈鏂扮墿鏂欏寘鍚浘绾稿浘鐗囩殑, + // 涔熷寘鍚棫鐗╂枡鍖呭惈鍥剧焊鍥剧墖鐨� + if(newMaterialList.size()>0){ + for (Material material : newMaterialList) { + //瀛樺湪鍥剧焊鎴栬�呭浘鐗�,灏辨彃鍏ュ巻鍙� + if(material.getDwgUrl()!=null || material.getPictureUrl()!=null) { + MaterialHistory materialHistory = new MaterialHistory(); + materialHistory.setPictureUrl(material.getPictureUrl()); + materialHistory.setProductId(productHistory.getId()); + materialHistory.setDwgUrl(material.getDwgUrl()); + materialHistory.setUpUserId(userId.intValue()); + materialHistory.setCreateTime(date); + materialHistory.setMaterialId(material.getId()); + materialHistoryList.add(materialHistory); + } + } + } + if(materialUpdateList.size()>0) { + //鏇存柊鐗╂枡鍥剧焊鍥剧墖鐨勫悓鏃�,娣诲姞鏂扮殑鍥剧焊鍥剧墖淇℃伅鍒扮墿鏂欏巻鍙茶〃涓� + for (Material material : materialUpdateList) { + MaterialHistory materialHistory = new MaterialHistory(); + materialHistory.setPictureUrl(material.getPictureUrl()); + materialHistory.setProductId(productHistory.getId()); + materialHistory.setDwgUrl(material.getDwgUrl()); + materialHistory.setUpUserId(userId.intValue()); + materialHistory.setCreateTime(date); + for (Material materialInDB : materialExistList) { + if ((material.getSubCode() + "/" + material.getSubModel()).equals(materialInDB.getSubCode() + "/" + materialInDB.getSubModel())) { + materialHistory.setMaterialId(materialInDB.getId()); + break; + } + } + materialHistoryList.add(materialHistory); + } + } + if(materialHistoryList.size()>0) { + materialHistoryService.addBatch(materialHistoryList); + } + //濡傛灉鏂颁笂浼犵殑bom涓瓨鍦�0108銆�0109寮�澶寸殑鐗╂枡,(鑲畾浼氳璇嗗埆鎴愭柊鐗╂枡,涔嬪墠鐨勬搷浣滃凡缁忚鎻掑叆鍒拌〃涓�) + // 鍦ㄦ暟鎹簱瀛樺湪鐩稿悓鐨勭墿鏂欑紪鐮佸瓨鍦ㄤ笖涓嶅悓鐨勭墿鏂欏瀷鍙�,鍒欏皢鏁版嵁搴撴渶鏂扮殑鐗╂枡鐨勯檮浠跺鍒朵竴浠藉苟鐘舵�佸悓姝�,濉厖鍒版柊鐨勭墿鏂欒〃涓� + for (Material material : newMaterialList) { //鏂扮墿鏂� + String subCode = material.getSubCode(); + String subModel = material.getSubModel(); + if(subCode.startsWith("0108") || subCode.startsWith("0109")){ + Material materialWithSameCodeLatest = mService.getByCodeAndModel(subCode, subModel, false); + if(materialWithSameCodeLatest!=null){ + //闄勪欢杞Щ骞惰缃� + mService.transferCopiedAttachment(materialWithSameCodeLatest,material); + } + } + } } //娣诲姞鏂板鏃ュ織鍒皌b_product_lock_log琛� @@ -731,7 +1108,7 @@ lockLog.setLockFlag(-1); productLockLogService.insert(lockLog); - return new Response().setII(1,"鏂板瀹屾垚"); + return new Response().set(1,true,"鏂板瀹屾垚"); } private void deleteAndInsert(Product product) { @@ -741,6 +1118,14 @@ pbService.deleteByProductId(productDB.getId()); } mapper.insert(product); + } + + private void delete(Product product) { + Product productDB = getByProductCodeAndCustomCode(product.getParentCode(), product.getCustomCode()); + if(productDB!=null) { + mapper.deleteById(productDB.getId()); + pbService.deleteByProductId(productDB.getId()); + } } private Product getByProductCodeAndCustomCode(String parentCode, String customCode) { @@ -759,4 +1144,27 @@ List listProduct=mapper.selectListProduct(productId); return new Response().setIII(1,listMaterial.size()>0||listProduct.size()>0,listMaterial,listProduct,""); } + + //鍙嶉绠$悊-鏌ヨ鎵�鏈夌殑浜у搧 + public Response getFkProduct() { + //QueryWrapper wrapper=new QueryWrapper(); + //wrapper.ne("version",-1); + List list=mapper.selectList(null); + return new Response().setII(1,list.size()>0,list,"鍙嶉绠$悊-鏌ヨ鎵�鏈夌殑浜у搧"); + } + + //浜у搧瀵规瘮涓嬫媺閫変腑 + public Response getCompareProduct() { + List list=mapper.selectList(null); + return new Response().setII(1,list.size()>0,list,"浜у搧瀵规瘮涓嬫媺閫変腑-鏌ヨ褰撳墠浣跨敤鐨勬墍鏈夌殑浜у搧"); + } + public static <T> Predicate<T> distinctByKey(Function<? super T, Object> keyExtractor) { + Map<Object, Boolean> seen = new ConcurrentHashMap<>(); + return object -> seen.putIfAbsent(keyExtractor.apply(object), Boolean.TRUE) == null; + } + //楠岃瘉姣嶆枡缂栫爜鏄惁瀛樺湪浜у搧涓� + public Response judgeParentCode(String parentCode,String customCode) { + int count = mapper.judgeParentCode(parentCode,customCode); + return new Response().set(1,count>0,"楠岃瘉姣嶆枡缂栫爜鏄惁瀛樺湪浜у搧涓�"); + } } -- Gitblit v1.9.1