| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.constant.UserOperation; |
| | | import com.whyc.dto.FIleSilkLock; |
| | | import com.whyc.dto.FileDirPath; |
| | | import com.whyc.dto.Response; |
| | | import com.whyc.dto.ZipUtils; |
| | | import com.whyc.mapper.AttachLockMapper; |
| | | import com.whyc.mapper.MaterialMapper; |
| | | import com.whyc.mapper.ProductBomHistoryMapper; |
| | | import com.whyc.mapper.ProductHistoryMapper; |
| | |
| | | @Autowired |
| | | @Lazy |
| | | private ProductService productService; |
| | | |
| | | @Autowired(required = false) |
| | | private AttachLockMapper attachLockMapper; |
| | | |
| | | //根据子件名称和母料型号查询历史版本记录 |
| | | public Response getBomHistoryByPModelAndSName(String pmodel, String sname) { |
| | |
| | | ProductHistory pHistory=pHistoryMapper.selectOne(wrapper); |
| | | |
| | | List<ProductBomHistory> list=mapper.getBomHistoryAndMaterial(productId,pHistory.getSubVersionMax()); |
| | | if(list!=null&&list.size()>0){ |
| | | list.stream().forEach(bomH -> { |
| | | if(bomH.getDwgUrl()!=null){ |
| | | QueryWrapper qwrapper=new QueryWrapper(); |
| | | qwrapper.eq("material_id",bomH.getMaterialId()); |
| | | qwrapper.eq("attach_name",bomH.getDwgUrl().substring(bomH.getDwgUrl().lastIndexOf("\\")+1)); |
| | | qwrapper.eq("lock_flag",1); |
| | | qwrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(qwrapper); |
| | | if(attachLock!=null){ |
| | | bomH.setDwgUrl(""); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | //查询产品的软件 |
| | | List<Software> listsoft=mapper.selectSoftware(pHistory.getParentCode()); |
| | | //将没有管理BOM的dwg文件 |
| | |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | //将没有管理BOM的dwg文件拷贝下载 |
| | | //将没有管理BOM的dwg文件(丝印)拷贝下载 |
| | | fileDirName=fileDirName+File.separator+withOutDwg; |
| | | File start = new File(fileDirName); |
| | | FIleSilkLock fIleSilkLock=new FIleSilkLock(); |
| | | String[] files =new String[]{}; |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int i=0;i<files.length;i++) { |
| | | files[i]=withOutDwg+File.separator+files[i]; |
| | | fIleSilkLock.setFiles(files); |
| | | } |
| | | } |
| | | } |
| | | return new Response().setIIII(1,list.size()>0,list,listsoft,files,"返回物料信息及关联物料"); |
| | | List<AttachLock> attachLocks=mapper.selectInAttachLock(productId); |
| | | fIleSilkLock.setAttachLocks(attachLocks); |
| | | return new Response().setIIII(1,list.size()>0,list,listsoft,fIleSilkLock,"返回物料信息及关联物料"); |
| | | } |
| | | //历史产品信息查看(产品中有0120开头的物料其实是产品,查看产品信息) |
| | | public Response getBomHistoryAndMaterial_0120(String parentCode, String parentName, String parentModel) { |
| | | |
| | | QueryWrapper wrapper=new QueryWrapper(); |
| | | wrapper.eq("parent_code",parentCode); |
| | | wrapper.eq("parent_name",parentName); |
| | | wrapper.eq("parent_model",parentModel); |
| | | wrapper.eq("enabled",1); |
| | | wrapper.last("limit 1"); |
| | | ProductHistory pHistory=pHistoryMapper.selectOne(wrapper); |
| | | int productId =pHistory.getId(); |
| | | int version = pHistory.getVersion(); |
| | | List<ProductBomHistory> list=mapper.getBomHistoryAndMaterial(productId,pHistory.getSubVersionMax()); |
| | | if(list!=null&&list.size()>0){ |
| | | list.stream().forEach(bomH -> { |
| | | if(bomH.getDwgUrl()!=null){ |
| | | QueryWrapper qwrapper=new QueryWrapper(); |
| | | qwrapper.eq("material_id",bomH.getMaterialId()); |
| | | qwrapper.eq("attach_name",bomH.getDwgUrl().substring(bomH.getDwgUrl().lastIndexOf("\\")+1)); |
| | | qwrapper.eq("lock_flag",1); |
| | | qwrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(qwrapper); |
| | | if(attachLock!=null){ |
| | | bomH.setDwgUrl(""); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | //查询产品的软件 |
| | | List<Software> listsoft=mapper.selectSoftware(pHistory.getParentCode()); |
| | | //将没有管理BOM的dwg文件 |
| | | String withOutDwg="doc_file/product"+File.separator+pHistory.getParentModel(); |
| | | if(pHistory.getCustomCode()!=null&&!pHistory.getCustomCode().isEmpty()){ |
| | | withOutDwg+=File.separator+pHistory.getCustomCode()+File.separator+version; |
| | | }else{ |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | //将没有管理BOM的dwg文件(丝印)拷贝下载 |
| | | fileDirName=fileDirName+File.separator+withOutDwg; |
| | | File start = new File(fileDirName); |
| | | FIleSilkLock fIleSilkLock=new FIleSilkLock(); |
| | | String[] files =new String[]{}; |
| | | if(start.exists()) { |
| | | files= start.list();//获取该文件夹下的所有文件名字 |
| | | if(files.length>=0){ |
| | | for(int i=0;i<files.length;i++) { |
| | | files[i]=withOutDwg+File.separator+files[i]; |
| | | fIleSilkLock.setFiles(files); |
| | | } |
| | | } |
| | | } |
| | | List<AttachLock> attachLocks=mapper.selectInAttachLock(productId); |
| | | fIleSilkLock.setAttachLocks(attachLocks); |
| | | return new Response().setIIII(1,list.size()>0,list,listsoft,fIleSilkLock,"返回物料信息及关联物料"); |
| | | } |
| | | //历史产品下载(产品id和版本<下载的版本>) |
| | | public void downloadProductHistory(HttpServletRequest req, HttpServletResponse resp, int productId, int version) { |
| | | //读取产品信息 |
| | |
| | | //处理存在关联关系的物料 |
| | | List<ProductBomHistory> endList=new ArrayList<>(); |
| | | list.stream().forEach(bomHistory -> { |
| | | if(bomHistory.getDwgUrl()!=null){ |
| | | QueryWrapper qwrapper=new QueryWrapper(); |
| | | qwrapper.eq("material_id",bomHistory.getMaterialId()); |
| | | qwrapper.eq("attach_name",bomHistory.getDwgUrl().substring(bomHistory.getDwgUrl().lastIndexOf("\\")+1)); |
| | | qwrapper.eq("lock_flag",1); |
| | | qwrapper.last("limit 1"); |
| | | AttachLock attachLock=attachLockMapper.selectOne(qwrapper); |
| | | if(attachLock!=null){ |
| | | bomHistory.setDwgUrl(""); |
| | | } |
| | | } |
| | | bomHistory.setConnFlag(0); |
| | | endList.add(bomHistory); |
| | | if(bomHistory.getMaterials()!=null&&bomHistory.getMaterials().size()>0){ |
| | |
| | | } |
| | | //将没有管理BOM的dwg文件拷贝下载 |
| | | withOutDwg=fileDirName+File.separator+withOutDwg; |
| | | bomService.copyDir(withOutDwg,rootFace); |
| | | bomService.copyDirWithOutProductId(withOutDwg,rootFace,pHistory.getId()); |
| | | //将选中的文件存入指定目录下打包下载 |
| | | if(list!=null&&list.size()>0){ |
| | | for (int i=0;i<list.size();i++) { |
| | |
| | | BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(fileDirName+File.separator+bomHistory.getPictureUrl()))); |
| | | ImageIO.write(bufferImg, "png", byteArrayOut); |
| | | //anchor主要用于设置图片的属性 |
| | | HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) 16, rownum+i+1, (short) 16, rownum+i+1); |
| | | HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) 16, rownum, (short) 16, rownum); |
| | | anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE); |
| | | //插入图片 |
| | | patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG)); |
| | |
| | | private ProductBomHistory copyMaterialToBomHis(Material m) { |
| | | ProductBomHistory bomHis=new ProductBomHistory(); |
| | | bomHis.setType(m.getType()); |
| | | bomHis.setCategory(m.getCategory()); |
| | | //bomHis.setCategory(m.getCategory()); |
| | | bomHis.setSubCode(m.getSubCode()); |
| | | bomHis.setSubName(m.getSubName()); |
| | | bomHis.setSubModel(m.getSubModel()); |
| | | bomHis.setUnit(m.getUnit()); |
| | | bomHis.setProducer(m.getProducer()); |
| | | bomHis.setMaterial(m.getMaterial()); |
| | | bomHis.setThickness(m.getThickness()); |
| | | bomHis.setSurfaceDetail(m.getSurfaceDetail()); |
| | | bomHis.setNotes(m.getNotes()); |
| | | //bomHis.setProducer(m.getProducer()); |
| | | //bomHis.setMaterial(m.getMaterial()); |
| | | //bomHis.setThickness(m.getThickness()); |
| | | //bomHis.setSurfaceDetail(m.getSurfaceDetail()); |
| | | //bomHis.setNotes(m.getNotes()); |
| | | bomHis.setPictureUrl(m.getPictureUrl()); |
| | | bomHis.setDwgUrl(m.getDwgUrl()); |
| | | bomHis.setFileUrl(m.getFileUrl()); |
| | |
| | | List<ProductBomHistory> addList = new LinkedList<>(); |
| | | List<ProductBomHistory> deleteList = new LinkedList<>(); |
| | | //物料id,对比字段:数量 |
| | | String separator = "&&&&&"; |
| | | baseBomHistoryList.forEach(baseBom->{ |
| | | bomHistoryList.forEach(bom->{ |
| | | StringBuilder diffStr = new StringBuilder(); |
| | | if(bom.getMaterialId().equals(baseBom.getMaterialId())){ |
| | | if(!bom.getQuantity().equals(baseBom.getQuantity())){ |
| | | String diffQuantity = separator+"原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | diffStr.append(diffQuantity); |
| | | } |
| | | if(!bom.getProducer().equals(baseBom.getProducer())){ |
| | | String diffProducer = separator+"原生产商:"+baseBom.getProducer()+"/新生产商:"+bom.getProducer(); |
| | | diffStr.append(diffProducer); |
| | | } |
| | | if(!bom.getMaterial().equals(baseBom.getMaterial())){ |
| | | String diffMaterial = separator+"原封装类型|材质:"+baseBom.getMaterial()+"/新封装类型|材质:"+bom.getMaterial(); |
| | | diffStr.append(diffMaterial); |
| | | } |
| | | if(!bom.getThickness().equals(baseBom.getThickness())){ |
| | | String diffThickness = separator+"原元件编号|料厚:"+baseBom.getThickness()+"/新元件编号|料厚:"+bom.getThickness(); |
| | | diffStr.append(diffThickness); |
| | | } |
| | | if(!bom.getSurfaceDetail().equals(baseBom.getSurfaceDetail())){ |
| | | String diffSurfaceDetail = separator+"原表面处理|物料详情:"+baseBom.getSurfaceDetail()+"/新表面处理|物料详情:"+bom.getSurfaceDetail(); |
| | | diffStr.append(diffSurfaceDetail); |
| | | } |
| | | if(!bom.getNotes().equals(baseBom.getNotes())){ |
| | | String diffNotes = separator+"原备注:"+baseBom.getNotes()+"/新备注:"+bom.getNotes(); |
| | | diffStr.append(diffNotes); |
| | | } |
| | | |
| | | String diff = diffStr.toString(); |
| | | if(!diff.equals("")) { |
| | | ProductBomHistory history = new ProductBomHistory(); |
| | | String diffQuantity = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | history.setNotes(diffQuantity); |
| | | history.setNotes(diff.substring(5)); |
| | | history.setMaterialObj(bom.getMaterialObj()); |
| | | diffList.add(history); |
| | | } |
| | |
| | | List<ProductBom> deleteList = new LinkedList<>(); |
| | | |
| | | //查找到基准产品 |
| | | if(baseProduct == null){ //查找上传的产品最新标准版本 |
| | | if(baseProduct == null){ //查找上传的现有产品表内未锁定的版本 |
| | | baseProductBomList = bomService.getEnabledBomListByParentCodeAndCustomCode(product.getParentCode(),""); |
| | | }else{ //根据baseProduct的code和custom_code |
| | | baseProductBomList = bomService.getEnabledBomListByParentCodeAndCustomCode(baseProduct.getParentCode(),baseProduct.getCustomCode()); |
| | |
| | | Map<String, List<ProductBom>> groupedBaseBomList = baseProductBomList.stream().collect(Collectors.groupingBy(bom -> bom.getMaterialObj().getSubCode() + "/" + bom.getMaterialObj().getSubModel())); |
| | | List<String> codeModelList = bomList.stream().map(bom -> bom.getSubCode() + "/" + bom.getSubModel()).collect(Collectors.toList()); |
| | | |
| | | |
| | | String separator = "&&&&&"; |
| | | bomList.forEach(bom->{ |
| | | String codeModel = bom.getSubCode() + "/" + bom.getSubModel(); |
| | | if(!baseCodeModelList.contains(codeModel)){ |
| | | addList.add(bom); |
| | | }else{ |
| | | ProductBom baseBom = groupedBaseBomList.get(codeModel).get(0); |
| | | if(bom.getQuantity().intValue()!=baseBom.getQuantity()){ |
| | | /*if(bom.getQuantity().intValue()!=baseBom.getQuantity()){ |
| | | ProductBom diffBom = new ProductBom(); |
| | | String diffQuantity = "原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | diffBom.setNotes(diffQuantity); |
| | | diffBom.setMaterialObj(baseBom.getMaterialObj()); |
| | | diffList.add(diffBom); |
| | | }*/ |
| | | StringBuilder diffStr = new StringBuilder(); |
| | | if(!bom.getQuantity().equals(baseBom.getQuantity())){ |
| | | String diffQuantity = separator+"原数量:"+baseBom.getQuantity()+"/新数量:"+bom.getQuantity(); |
| | | diffStr.append(diffQuantity); |
| | | } |
| | | if(!bom.getProducer().equals(baseBom.getProducer())){ |
| | | String diffProducer = separator+"原生产商:"+baseBom.getProducer()+"/新生产商:"+bom.getProducer(); |
| | | diffStr.append(diffProducer); |
| | | } |
| | | if(!bom.getMaterial().equals(baseBom.getMaterial())){ |
| | | String diffMaterial = separator+"原封装类型|材质:"+baseBom.getMaterial()+"/新封装类型|材质:"+bom.getMaterial(); |
| | | diffStr.append(diffMaterial); |
| | | } |
| | | if(!bom.getThickness().equals(baseBom.getThickness())){ |
| | | String diffThickness = separator+"原元件编号|料厚:"+baseBom.getThickness()+"/新元件编号|料厚:"+bom.getThickness(); |
| | | diffStr.append(diffThickness); |
| | | } |
| | | if(!bom.getSurfaceDetail().equals(baseBom.getSurfaceDetail())){ |
| | | String diffSurfaceDetail = separator+"原表面处理|物料详情:"+baseBom.getSurfaceDetail()+"/新表面处理|物料详情:"+bom.getSurfaceDetail(); |
| | | diffStr.append(diffSurfaceDetail); |
| | | } |
| | | if(!bom.getNotes().equals(baseBom.getNotes())){ |
| | | String diffNotes = separator+"原备注:"+baseBom.getNotes()+"/新备注:"+bom.getNotes(); |
| | | diffStr.append(diffNotes); |
| | | } |
| | | |
| | | String diff = diffStr.toString(); |
| | | if(!diff.equals("")) { |
| | | ProductBom diffBom = new ProductBom(); |
| | | diffBom.setNotes(diff.substring(5)); |
| | | diffBom.setMaterialObj(baseBom.getMaterialObj()); |
| | | diffList.add(diffBom); |
| | | } |
| | |
| | | //query2.eq("product_id",productId).le("sub_s_version",latestSubVersion).ge("sub_e_version",latestSubVersion); |
| | | return mapper.getBomListByProductIdAndSubVersion(productId,latestSubVersion); |
| | | } |
| | | |
| | | public void updateMaterialField2BomHistory() { |
| | | List<ProductBomHistory> bomHistoryList = mapper.selectListWithMaterialField(); |
| | | mapper.updateMaterialField2BomHistoryBatch(bomHistoryList); |
| | | |
| | | } |
| | | //根据产品母料型号,定制单号,版本下载原始压缩包文件 |
| | | public Response getOriginalZip(String parentModel, String customCode, int version) { |
| | | String fileDirName = FileDirPath.getFileDirName(); |
| | | String withOutDwg=fileDirName+File.separator+"doc_file"+File.separator+"product"+File.separator+parentModel; |
| | | if(customCode!=null&&!customCode.isEmpty()){ |
| | | withOutDwg+=File.separator+customCode+File.separator+version; |
| | | }else{ |
| | | withOutDwg+=File.separator+"standard"+File.separator+version; |
| | | } |
| | | boolean bl=false; |
| | | File file = new File(withOutDwg); |
| | | if(!file.exists()) { |
| | | return new Response().setII(1,bl,withOutDwg.replace(fileDirName,""),"原始文件相对路径"); |
| | | } |
| | | String[] filePath = file.list();//获取该文件夹下的所有文件以及目录的名字 |
| | | if(filePath!=null&&filePath.length>0){ |
| | | for (String tmp:filePath) { |
| | | if(tmp.contains(".zip")){ |
| | | bl=true; |
| | | withOutDwg=withOutDwg+File.separator+tmp; |
| | | } |
| | | } |
| | | } |
| | | return new Response().setII(1,bl,withOutDwg.replace(fileDirName,""),"原始文件相对路径"); |
| | | } |
| | | |
| | | public void getFixItem() { |
| | | List<ProductBomHistory> bomHistoryList = mapper.selectList(null); |
| | | Map<Integer, List<ProductBomHistory>> productMap = bomHistoryList.stream().collect(Collectors.groupingBy(ProductBomHistory::getProductId)); |
| | | Set<Integer> productIdSet = productMap.keySet(); |
| | | List<ProductBomHistory> needToDealWith = new LinkedList<>(); |
| | | for (Integer productId : productIdSet) { |
| | | List<ProductBomHistory> bomList = productMap.get(productId); |
| | | Map<Integer, List<ProductBomHistory>> materialIdMap = bomList.stream().collect(Collectors.groupingBy(ProductBomHistory::getMaterialId)); |
| | | Set<Integer> materialIdSet = materialIdMap.keySet(); |
| | | for (Integer materialId : materialIdSet) { |
| | | List<ProductBomHistory> temp = materialIdMap.get(materialId); |
| | | if(temp.size()!=1){ |
| | | System.err.println("需要手动处理的productBomHistory和productBom:"+productId+",物料id:"+materialId); |
| | | needToDealWith.add(temp.get(0)); |
| | | } |
| | | } |
| | | } |
| | | System.err.println("可能需要处理的条数为:"+needToDealWith.size()); |
| | | } |
| | | } |