| | |
| | | import com.whyc.dto.Response; |
| | | 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.openxml4j.exceptions.InvalidFormatException; |
| | | import org.apache.poi.ss.usermodel.*; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | |
| | | 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.stream.Collectors; |
| | | |
| | | @Service |
| | |
| | | } else if (j != 15) { |
| | | cellValue = cell.getStringCellValue(); |
| | | } |
| | | if(cellValue!=null) { |
| | | cellValue = cellValue.trim(); |
| | | } |
| | | switch (j) { |
| | | case 0: { |
| | | bom.setId(cellValueInt.intValue()); |
| | |
| | | provingFile.mkdirs(); |
| | | } |
| | | String suffix = pictureData.suggestFileExtension(); |
| | | String picturePath = approvingPath + File.separator + bom.getSubModel() + "." + suffix; |
| | | String picturePathFront = "doc_file" + File.separator + "product_submit" + File.separator + user.getName() + File.separator + dateFormat + File.separator + timeStamp + File.separator + bom.getSubModel() + "." + suffix; |
| | | 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); |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | //产品bom对比 |
| | | Map<String,List> compareMap = pbhService.parseCompare(baseProduct,product); |
| | | return response.setIII(1, true, product,compareMap, filePath); |
| | | //return response.setIII(1, true, product,compareMap, filePath); |
| | | return response.setIII(1, true, product,compareMap, zipFile.toString()); |
| | | |
| | | } |
| | | |
| | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 这个接口是进行产品新增,产品bom新增的接口. |
| | | * 新增方式有很多,有直接从zip解析新增产品,也可以基于原有产品复制进行定制等.需要注意兼容! |
| | | * @param product 产品新增,bom新增,产品版本更新 |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | @Transactional |
| | | 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 fileUrl = product.getFileUrl(); |
| | | String zipFilePath = product.getFileUrl(); |
| | | Date date = new Date(); |
| | | boolean isCopyCustom = false; |
| | | Product relatedProduct = null; |
| | |
| | | if(product.getId() != null){ //关联关系从产品id继承 |
| | | relatedProduct = getById(product.getId()); |
| | | } |
| | | } |
| | | //不是基于产品复制,则必定存在zip包,必然存在路径 |
| | | String fileUrl = null; |
| | | if(!isCopyCustom) { |
| | | fileUrl = zipFilePath.substring(0, zipFilePath.lastIndexOf(File.separator)); |
| | | } |
| | | //查询新增产品最新的版本号 |
| | | ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode); |
| | |
| | | bomHistory.setProductId(his.getId()); |
| | | bomHistory.setMaterialId(bom.getMaterialId()); |
| | | bomHistory.setQuantity(bom.getQuantity()); |
| | | bomHistory.setCategory(bom.getCategory()); |
| | | bomHistory.setMaterial(bom.getMaterial()); |
| | | bomHistory.setNotes(bom.getNotes()); |
| | | bomHistory.setProducer(bom.getProducer()); |
| | | bomHistory.setSurfaceDetail(bom.getSurfaceDetail()); |
| | | bomHistory.setThickness(bom.getThickness()); |
| | | bomHistory.setSubSVersion(1); |
| | | bomHistory.setSubEVersion(1); |
| | | bomHistoryList.add(bomHistory); |
| | |
| | | File file = new File(fileUrl); |
| | | List<String> fileUrlList = new LinkedList<>(); |
| | | List<String> excelExcludeUrlList = null; |
| | | List<String> picUrlList = null; |
| | | List<String> picUrlList = new LinkedList<>(); |
| | | //存于物料下,bom内有对应 |
| | | List<String> materialUrlList = new LinkedList<>(); |
| | | //存于产品下,bom内没对应 |
| | |
| | | fileUrlList = FileUtil.getStaticFilePath(file, fileUrlList); |
| | | //图纸dwg 子件/产品 |
| | | 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()); |
| | | //picUrlList = fileUrlList.stream().filter(url -> url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList()); |
| | | |
| | | List<ProductBom> finalBomList = bomList; |
| | | excelExcludeUrlList.forEach(excelExcludeUr -> { |
| | | boolean existFlag = false; |
| | | for (ProductBom bom : finalBomList) { |
| | | String filename = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1, excelExcludeUr.length() - 4); |
| | | String filename = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1, excelExcludeUr.lastIndexOf(".")); |
| | | String fileFullName = excelExcludeUr.substring(excelExcludeUr.lastIndexOf(File.separator) + 1); |
| | | if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase()) && excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("dwg")) { |
| | | materialUrlList.add(excelExcludeUr); |
| | |
| | | + File.separator + fileFullName); |
| | | break; |
| | | } |
| | | else if((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase()) && (excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("png") ||excelExcludeUr.substring(excelExcludeUr.lastIndexOf(".")+1).equals("jpeg")) |
| | | ){ |
| | | picUrlList.add(excelExcludeUr); |
| | | existFlag = true; |
| | | |
| | | |
| | | bom.setPictureUrl("doc_file" + File.separator + "material" |
| | | + File.separator + fileFullName); |
| | | break; |
| | | } |
| | | } |
| | | if (!existFlag) { |
| | | productUrlList.add(excelExcludeUr); |
| | | } |
| | | }); |
| | | |
| | | //一定是有对应物料的,从bom内剥离的 |
| | | /*//一定是有对应物料的,包含从bom内剥离的(删除掉:上面已经处理) |
| | | picUrlList.forEach(picUrl -> { |
| | | for (ProductBom bom : finalBomList) { |
| | | String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.lastIndexOf(".")); |
| | | String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1); |
| | | if (bom.getSubModel().toUpperCase().equals(filename.toUpperCase())) { |
| | | if ((bom.getSubModel().toUpperCase()+"-BOM").equals(filename.toUpperCase())) { |
| | | bom.setPictureUrl("doc_file" + File.separator + "material" |
| | | + File.separator + fileFullName); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | });*/ |
| | | |
| | | //转移路径 |
| | | String projectDir = CommonUtil.getProjectDir(); |
| | |
| | | if (!materialFile.exists()) { |
| | | materialFile.mkdirs(); |
| | | } |
| | | //之前上传的产品bom压缩包,转移到正式版本下留存 |
| | | File zipFileNew = new File(productDir + File.separator + zipFilePath.substring(zipFilePath.lastIndexOf(File.separator) + 1)); |
| | | FileCopyUtils.copy(new File(zipFilePath), zipFileNew); |
| | | |
| | | productUrlList.forEach(productUrl -> { |
| | | String fileName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1); |
| | | |
| | |
| | | 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")); |
| | | File dwgFile = new File(materialDir + File.separator + dwgName + ".dwg"); |
| | | if(!dwgFile.exists()) { |
| | | FileCopyUtils.copy(new File(materialUrl), dwgFile); |
| | | } |
| | | } 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)); |
| | | File picFile = new File(materialDir + File.separator + picFullName); |
| | | 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<>(); |
| | | bomList.forEach(bom -> { |
| | | if (!subCodeList.contains(bom.getSubCode()+"/"+bom.getSubModel())) { |
| | | List<Material> materialUpdateList = new LinkedList<>(); |
| | | for (ProductBom bom : bomList) { |
| | | if (!subCodeList.contains(bom.getSubCode() + "/" + bom.getSubModel())) { |
| | | Material material = new Material(); |
| | | material.setCategory(bom.getCategory()); |
| | | material.setCreateDate(date); |
| | | material.setDwgUrl(bom.getDwgUrl()); |
| | | material.setFileUrl(bom.getFileUrl()); |
| | | material.setMaterial(bom.getMaterial()); |
| | | material.setNotes(bom.getNotes()); |
| | | material.setPictureUrl(bom.getPictureUrl()); |
| | | material.setProducer(bom.getProducer()); |
| | | // TODO 是否要更新同物料编码的老物料状态为0? |
| | | material.setStatus(1); |
| | | material.setSubCode(bom.getSubCode()); |
| | | material.setSubModel(bom.getSubModel()); |
| | | material.setSubName(bom.getSubName()); |
| | | material.setSurfaceDetail(bom.getSurfaceDetail()); |
| | | material.setThickness(bom.getThickness()); |
| | | material.setType(bom.getType()); |
| | | material.setUnit(bom.getUnit()); |
| | | |
| | | materialList.add(material); |
| | | } else { //物料已经存在的 |
| | | Material material = new Material(); |
| | | if (bom.getPictureUrl() != null) { |
| | | material.setPictureUrl(bom.getPictureUrl()); |
| | | } |
| | | if (bom.getDwgUrl() != null) { |
| | | material.setDwgUrl(bom.getDwgUrl()); |
| | | } |
| | | if (material.getPictureUrl() != null || material.getDwgUrl() != null) { |
| | | material.setSubCode(bom.getSubCode()); |
| | | material.setSubModel(bom.getSubModel()); |
| | | materialUpdateList.add(material); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | //对新增到物料表中的物料,根据 物料编码+物料型号 进行去重处理 |
| | | materialList = materialList.stream().filter(distinctByKey(m->m.getSubCode()+"/"+m.getSubModel())).collect(Collectors.toList()); |
| | | |
| | | //母料是否存在 |
| | | Material materialDB = mService.getByCodeAndModel(product.getParentCode(), product.getParentModel()); |
| | | if (materialDB == null) { |
| | |
| | | material.setSubCode(product.getParentCode()); |
| | | material.setSubName(product.getParentName()); |
| | | material.setSubModel(product.getParentModel()); |
| | | material.setCreateDate(date); |
| | | material.setStatus(1); |
| | | |
| | | materialList.add(material); |
| | |
| | | if(materialList.size()!=0) { |
| | | mService.insertBatch(materialList); |
| | | } |
| | | if(materialUpdateList.size()!=0) { |
| | | mService.updateDwgUrlAndPicUrl(materialUpdateList); |
| | | } |
| | | //更新product_history/product_bom_history/product/product_bom, |
| | | // product的主键沿用对应product_history的 |
| | | //根据编码和型号确定物料id并对应quantity,存入数据库. |
| | | //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()); |
| | |
| | | bom.setProductId(product.getId()); |
| | | bom.setMaterialId(bomMaterial.getId()); |
| | | bom.setQuantity(bomMaterial.getQuantity()); |
| | | bom.setCategory(bomMaterial.getCategory()); |
| | | bom.setMaterial(bomMaterial.getMaterial()); |
| | | bom.setNotes(bomMaterial.getNotes()); |
| | | bom.setProducer(bomMaterial.getProducer()); |
| | | bom.setSurfaceDetail(bomMaterial.getSurfaceDetail()); |
| | | bom.setThickness(bomMaterial.getThickness()); |
| | | bom.setSubVersion(1); |
| | | bom.setCreateDate(date); |
| | | |
| | |
| | | bomHistory.setProductId(productHistory.getId()); |
| | | bomHistory.setMaterialId(bomMaterial.getId()); |
| | | bomHistory.setQuantity(bomMaterial.getQuantity()); |
| | | bomHistory.setCategory(bomMaterial.getCategory()); |
| | | bomHistory.setMaterial(bomMaterial.getMaterial()); |
| | | bomHistory.setNotes(bomMaterial.getNotes()); |
| | | bomHistory.setProducer(bomMaterial.getProducer()); |
| | | bomHistory.setSurfaceDetail(bomMaterial.getSurfaceDetail()); |
| | | bomHistory.setThickness(bomMaterial.getThickness()); |
| | | bomHistory.setSubSVersion(1); |
| | | bomHistory.setSubEVersion(1); |
| | | bomHistory.setCreateDate(date); |
| | |
| | | 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(wrapper); |
| | | 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; |
| | | } |
| | | |
| | | } |