From 66db1d15cf5d4b51a346a42b66f0505bd7f31ce0 Mon Sep 17 00:00:00 2001 From: whycxzp <glperry@163.com> Date: 星期三, 03 一月 2024 15:23:47 +0800 Subject: [PATCH] 解压 --- src/main/java/com/whyc/service/ProductService.java | 216 ++++++++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 179 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/whyc/service/ProductService.java b/src/main/java/com/whyc/service/ProductService.java index 7a2090c..dea5255 100644 --- a/src/main/java/com/whyc/service/ProductService.java +++ b/src/main/java/com/whyc/service/ProductService.java @@ -3,9 +3,11 @@ 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.DateUtil; @@ -34,6 +36,9 @@ @Autowired(required = false) private ProductMapper mapper; + @Autowired(required = false) + private ProductHistoryMapper hisMapper; + @Autowired private ProductHistoryService phService; @@ -52,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); } @@ -74,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,"杩斿洖浜у搧淇℃伅"); } @@ -233,6 +249,9 @@ 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()); String parentModel = sheet.getRow(2).getCell(3).getStringCellValue(); parentModel = parentModel.trim(); @@ -433,8 +452,17 @@ List<ProductBom> bomList = product.getBomList(); String zipFilePath = product.getFileUrl(); 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()); @@ -581,7 +609,7 @@ newTemp.setParentCode(parentCode); newTemp.setCustomCode(customCode); newTemp.setSubCode(bom.getSubCode()); - Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel()); + Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true); newTemp.setSubMaterialId(material.getId()); newTemp.setSVersion(nextVersion); newTemp.setEVersion(nextVersion); @@ -609,7 +637,7 @@ newTemp.setParentCode(parentCode); newTemp.setCustomCode(customCode); newTemp.setSubCode(bom.getSubCode()); - Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel()); + Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true); newTemp.setSubMaterialId(material.getId()); newTemp.setSVersion(nextVersion); newTemp.setEVersion(nextVersion); @@ -657,14 +685,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-> { @@ -714,13 +743,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")) @@ -729,8 +759,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; } } @@ -787,36 +817,83 @@ } }); - 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<>(); for (ProductBom bom : bomList) { if (!subCodeList.contains(bom.getSubCode() + "/" + bom.getSubModel())) { @@ -825,16 +902,17 @@ 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); + newMaterialList.add(material); } else { //鐗╂枡宸茬粡瀛樺湪鐨� + // 鐗╂枡鍘嗗彶琛ㄦ槸涓轰簡瀛樺偍鐗╂枡鐨勫巻鍙插浘鐗囧拰dwg鍥剧焊 Material material = new Material(); if (bom.getPictureUrl() != null) { material.setPictureUrl(bom.getPictureUrl()); @@ -850,10 +928,10 @@ } } //瀵规柊澧炲埌鐗╂枡琛ㄤ腑鐨勭墿鏂�,鏍规嵁 鐗╂枡缂栫爜+鐗╂枡鍨嬪彿 杩涜鍘婚噸澶勭悊 - materialList = materialList.stream().filter(distinctByKey(m->m.getSubCode()+"/"+m.getSubModel())).collect(Collectors.toList()); + 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()); @@ -861,11 +939,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); @@ -900,12 +979,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<>(); @@ -948,6 +1028,56 @@ 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); + //闄勪欢杞Щ骞惰缃� + mService.transferCopiedAttachment(materialWithSameCodeLatest,material); + } + } } //娣诲姞鏂板鏃ュ織鍒皌b_product_lock_log琛� @@ -963,7 +1093,7 @@ lockLog.setLockFlag(-1); productLockLogService.insert(lockLog); - return new Response().setII(1,"鏂板瀹屾垚"); + return new Response().set(1,true,"鏂板瀹屾垚"); } private void deleteAndInsert(Product product) { @@ -973,6 +1103,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) { @@ -1009,5 +1147,9 @@ 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