| | |
| | | @Autowired |
| | | private ProductLockLogService productLockLogService; |
| | | |
| | | @Autowired |
| | | private MaterialHistoryService materialHistoryService; |
| | | |
| | | //查询出所有的产品信息(分页加模糊查询<产品的编码,型号,名字,定制表编号> |
| | | public Response getAllProduct(String subCode,String parentCode, String parentName, String parentModel, String customCode,Integer enabled, int pageCurr, int pageSize) { |
| | | PageHelper.startPage(pageCurr,pageSize); |
| | |
| | | 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(); |
| | |
| | | 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; |
| | | //校验凡是有定制表单号的产品,不能使用已上传过的标准产品编码 |
| | |
| | | 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")) |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | } |
| | | }); |
| | | |
| | | 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()); |
| | |
| | | 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 { //物料已经存在的 |
| | |
| | | material.setSubModel(product.getParentModel()); |
| | | material.setCreateDate(date); |
| | | material.setStatus(1); |
| | | material.setUpUserId(userId); |
| | | |
| | | materialList.add(material); |
| | | } |
| | |
| | | }); |
| | | pbhService.insertBatch(bomHistoryList); |
| | | |
| | | if(materialUpdateList.size()>0) { |
| | | //更新物料图纸图片的同时,添加新的图纸图片信息到物料历史表中 |
| | | List<MaterialHistory> materialHistoryList = new LinkedList<>(); |
| | | 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); |
| | | } |
| | | materialHistoryService.addBatch(materialHistoryList); |
| | | } |
| | | } |
| | | //添加新增日志到tb_product_lock_log表 |
| | | ProductLockLog lockLog = new ProductLockLog(); |