| | |
| | | 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); |
| | | //解压文件夹 |
| | |
| | | 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(bom.getRelatedMaterialCodes()!=null) { |
| | | String relatedMaterialCodes = bom.getRelatedMaterialCodes().trim(); |
| | | if (!relatedMaterialCodes.equals("")) { |
| | | if (subMaterialListInDB.contains(bom.getSubCode()+"_"+bom.getSubModel())) { //当前物料有替代料 |
| | | 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); |
| | | if(subMaterialListInDB!=null&&subMaterialListInDB.size()>0){ |
| | | if (subMaterialListInDB.contains(bom.getSubCode()+"_"+bom.getSubModel())) { //当前物料有替代料 |
| | | 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; |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | if(!exists) { //不存在相邻及相同的记录版本,新增 |
| | | } |
| | | 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()); |
| | | Material material = mService.getByCodeAndModel(bom.getSubCode(), bom.getSubModel(),true); |
| | | newTemp.setSubMaterialId(material.getId()); |
| | | newTemp.setSVersion(nextVersion); |
| | | newTemp.setEVersion(nextVersion); |
| | |
| | | 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()); |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | |
| | | 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())) { |
| | |
| | | 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()); |
| | |
| | | } |
| | | } |
| | | //对新增到物料表中的物料,根据 物料编码+物料型号 进行去重处理 |
| | | 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()); |
| | |
| | | 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); |
| | |
| | | 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) { |
| | | //更新物料图纸图片的同时,添加新的图纸图片信息到物料历史表中 |
| | | List<MaterialHistory> materialHistoryList = new LinkedList<>(); |
| | | for (Material material : materialUpdateList) { |
| | | MaterialHistory materialHistory = new MaterialHistory(); |
| | | materialHistory.setPictureUrl(material.getPictureUrl()); |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | //添加新增日志到tb_product_lock_log表 |
| | | ProductLockLog lockLog = new ProductLockLog(); |
| | |
| | | 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,"反馈管理-查询当前使用的所有的产品"); |
| | | //QueryWrapper wrapper=new QueryWrapper(); |
| | | //wrapper.ne("version",-1); |
| | | List list=mapper.selectList(null); |
| | | return new Response().setII(1,list.size()>0,list,"反馈管理-查询所有的产品"); |
| | | } |
| | | |
| | | //产品对比下拉选中 |