| | |
| | | import com.whyc.mapper.ProductBomApprovingMapper; |
| | | import com.whyc.mapper.WorksheetLinkMapper; |
| | | import com.whyc.pojo.*; |
| | | import com.whyc.util.CommonUtil; |
| | | import com.whyc.util.FileUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.util.FileCopyUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | //审批通过,更新主表状态 |
| | | mainService.updateEndStatusById(link.getMainId(), "完结", 5); |
| | | if (type.intValue() == EnumWorksheetType.ProductBom.getType()) { //产品审批 |
| | | //将产品文件复制至正式路径 TODO |
| | | |
| | | ProductApproving productApproving = paService.getByMainId(link.getMainId()); |
| | | List<ProductBomApproving> approvingList = pbaService.getList(productApproving.getId()); |
| | | //查询产品最新的版本号 |
| | | String parentModel = productApproving.getParentModel(); |
| | | String parentCode = productApproving.getParentCode(); |
| | | String customCode = productApproving.getCustomCode(); |
| | | Product product = productService.getVersion(parentCode, customCode); |
| | |
| | | currentVersion = product.getVersion(); |
| | | } |
| | | Integer nextVersion = currentVersion + 1; |
| | | //将产品文件复制至正式路径 |
| | | //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/ |
| | | //跟子件挂钩的转移到子件图纸下:doc_file/material/ |
| | | //存储本次审批文件夹绝对路径 |
| | | String fileUrl = productApproving.getFileUrl(); |
| | | File file = new File(fileUrl); |
| | | List<String> fileUrlList = new LinkedList<>(); |
| | | List<String> dwgUrlList = null; |
| | | List<String> picUrlList = null; |
| | | //存于物料下,bom内有对应 |
| | | List<String> materialUrlList = new LinkedList<>(); |
| | | //存于产品下,bom内没对应 |
| | | List<String> productUrlList = new LinkedList<>(); |
| | | |
| | | List<String> productUrlNameList = new LinkedList<>(); |
| | | List<String> materialUrlNameList = new LinkedList<>(); |
| | | List<String> picUrlNameList = new LinkedList<>(); |
| | | |
| | | fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList); |
| | | //图纸dwg 子件/产品 |
| | | dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList()); |
| | | picUrlList = fileUrlList.stream().filter(url->url.contains(".png") || url.contains(".jpeg")).collect(Collectors.toList()); |
| | | |
| | | dwgUrlList.forEach(dwgUrl->{ |
| | | boolean existFlag = false; |
| | | for (ProductBomApproving approving :approvingList){ |
| | | String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4); |
| | | if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){ |
| | | materialUrlList.add(dwgUrl); |
| | | existFlag = true; |
| | | break; |
| | | } |
| | | } |
| | | if(!existFlag) { |
| | | productUrlList.add(dwgUrl); |
| | | } |
| | | }); |
| | | |
| | | //一定是有对应物料的,从bom内剥离的 |
| | | picUrlList.forEach(picUrl->{ |
| | | for (ProductBomApproving approving :approvingList){ |
| | | String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.length() - 4); |
| | | if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){ |
| | | picUrlNameList.add(picUrl); |
| | | break; |
| | | } |
| | | } |
| | | }); |
| | | |
| | | //转移路径 |
| | | String projectDir = CommonUtil.getProjectDir(); |
| | | //doc_file/product/{产品型号}/standard或者{customCode}}/{version}/ |
| | | //跟子件挂钩的转移到子件图纸下:doc_file/material/ |
| | | String customCodeString = null; |
| | | if(customCode==null) { |
| | | customCodeString = "standard"; |
| | | }else{ |
| | | customCodeString = customCode; |
| | | } |
| | | String productDir = projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + parentModel |
| | | + File.separator + customCodeString + File.separator +nextVersion; |
| | | String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material"; |
| | | File productDirFile = new File(productDir); |
| | | File materialFile = new File(materialDir); |
| | | if(!productDirFile.exists()){ |
| | | productDirFile.mkdirs(); |
| | | } |
| | | if(!materialFile.exists()){ |
| | | materialFile.mkdirs(); |
| | | } |
| | | productUrlList.forEach(productUrl->{ |
| | | String dwgName = productUrl.substring(productUrl.lastIndexOf(File.separator) + 1, productUrl.length() - 4); |
| | | productUrlNameList.add(dwgName); |
| | | try { |
| | | FileCopyUtils.copy(new File(productUrl),new File(productDir+File.separator+dwgName+".dwg")); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | materialUrlList.forEach(materialUrl->{ |
| | | String dwgName = materialUrl.substring(materialUrl.lastIndexOf(File.separator) + 1, materialUrl.length() - 4); |
| | | materialUrlNameList.add(dwgName); |
| | | try { |
| | | FileCopyUtils.copy(new File(materialUrl),new File(materialDir+File.separator+dwgName+".dwg")); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | //转移审批表数据到历史表/最新版本表 product_history/product_bom_history/product/product_bom |
| | | List<ProductBomApproving> approvingList = pbaService.getList(productApproving.getId()); |
| | | ProductHistory productHistory = new ProductHistory(); |
| | | productHistory.setParentCode(parentCode); |
| | | productHistory.setParentName(productApproving.getParentName()); |
| | | productApproving.setParentModel(productApproving.getParentModel()); |
| | | productApproving.setParentModel(parentModel); |
| | | productHistory.setNotes(productApproving.getNotes()); |
| | | productHistory.setCustomCode(customCode); |
| | | productHistory.setCreateTime(new Date()); |
| | |
| | | historyService.addBatch(productBomHistoryList); |
| | | bomService.insertBatch(productBomList); |
| | | |
| | | //物料表中不存在的,则添加到物料表中去 TODO 考虑是否需要这么操作 |
| | | //物料表中不存在的,则添加到物料表中去 |
| | | List<String> codeList = approvingList.stream().map(ProductBomApproving::getSubCode).collect(Collectors.toList()); |
| | | List<String> existCodeList = mService.getListByCodeList(codeList); |
| | | List<Material> materialList = new LinkedList<>(); |
| | | approvingList.forEach(approving->{ |
| | | if(!existCodeList.contains(approving.getSubCode())){ //这个审批bom中的物料不在物料管理内 |
| | | Material temp = new Material(); |
| | | temp.setCategory(approving.getCategory()); |
| | | temp.setCreateDate(new Date()); |
| | | temp.setDwgUrl(approving.getDwgUrl()); |
| | | temp.setFileUrl(approving.getFileUrl()); |
| | | temp.setMaterial(approving.getMaterial()); |
| | | temp.setNotes(approving.getNotes()); |
| | | temp.setPictureUrl(approving.getPictureUrl()); |
| | | temp.setProducer(approving.getProducer()); |
| | | temp.setQuantity(approving.getQuantity()); |
| | | temp.setStatus(1); |
| | | temp.setSubCode(approving.getSubCode()); |
| | | temp.setSubModel(approving.getSubModel()); |
| | | temp.setSubName(approving.getSubName()); |
| | | temp.setSurfaceDetail(approving.getSurfaceDetail()); |
| | | temp.setThickness(approving.getThickness()); |
| | | temp.setType(approving.getType()); |
| | | temp.setUnit(approving.getUnit()); |
| | | materialList.add(temp); |
| | | } |
| | | }); |
| | | mService.insertBatch(materialList); |
| | | |
| | | //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/ |
| | | //跟子件挂钩的转移到子件图纸下:doc_file/material/ TODO |
| | | //将dwg图纸和pic图片,全部更新到对应的记录url中 TODO |
| | | |
| | | /*List<ProductBomApproving> fileBomApprovingList = approvingList.stream() |
| | | .filter(productBomApproving -> |
| | | productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null |