| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.whyc.config.EnumWorksheetType; |
| | | import com.whyc.dto.Response; |
| | | 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 com.whyc.util.WordUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.File; |
| | | import java.io.FilenameFilter; |
| | | import java.io.IOException; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | |
| | | |
| | | @Autowired |
| | | private ProductHistoryService phService; |
| | | |
| | | @Autowired |
| | | private ProcedureDocApprovingService procedureDocApprovingService; |
| | | |
| | | @Autowired |
| | | private ProcedureDocService procedureDocService; |
| | | |
| | | @Transactional |
| | | public void audit(WorksheetLink link) { |
| | |
| | | String parentModel = productApproving.getParentModel(); |
| | | String parentCode = productApproving.getParentCode(); |
| | | String customCode = productApproving.getCustomCode(); |
| | | Product product = productService.getVersion(parentCode, customCode); |
| | | ProductHistory latestProduct = phService.getLatestVersion(parentCode, customCode); |
| | | ProductHistory enabledProduct = phService.getEnabledByParentCodeAndCustomCode(parentCode, customCode); |
| | | int currentVersion = 0; |
| | | if (product != null) { |
| | | currentVersion = product.getVersion(); |
| | | if (latestProduct != null) { |
| | | currentVersion = latestProduct.getVersion(); |
| | | } |
| | | Integer nextVersion = currentVersion + 1; |
| | | //产品物料关系迁移 |
| | | //查询生效版本的关联关系 |
| | | if(latestProduct!=null &&enabledProduct!=null) { |
| | | List<MaterialProductHistory> mpList = mphService.getListByParentCodeAndCustomCodeAndVersion(parentCode, customCode, enabledProduct.getVersion()); |
| | | if (latestProduct.getVersion().intValue() == enabledProduct.getVersion()) { |
| | | //最新版本生效,关联关系版本连着的 |
| | | mphService.updateVersionBatch(mpList); |
| | | } else { |
| | | //旧版本生效,关联关系版本不连着 |
| | | mpList.forEach(mp -> { |
| | | mp.setSVersion(nextVersion); |
| | | mp.setEVersion(nextVersion); |
| | | }); |
| | | mphService.insertBatch(mpList); |
| | | } |
| | | } |
| | | |
| | | //将产品文件复制至正式路径 |
| | | //文件转移,未跟子件挂钩的所有图纸图片转移到产品版本下:doc_file/product/{产品型号}/standard或者{customCode}}/{version}/ |
| | | //跟子件挂钩的转移到子件图纸下:doc_file/material/ |
| | |
| | | |
| | | Material temp = new Material(); |
| | | temp.setSubModel(approving.getSubModel()); |
| | | temp.setNotes(CommonUtil.getProjectDir() + File.separator + "doc_file" + File.separator + "material" |
| | | temp.setNotes("doc_file" + File.separator + "material" |
| | | + File.separator + fileFullName); |
| | | materialDwgUrlNameList.add(temp); |
| | | break; |
| | |
| | | String filename = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1, picUrl.length() - 4); |
| | | String fileFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1); |
| | | if(approving.getSubModel().toUpperCase().equals(filename.toUpperCase())){ |
| | | approving.setPictureUrl(CommonUtil.getProjectDir() + File.separator + "doc_file" + File.separator + "material" |
| | | approving.setPictureUrl("doc_file" + File.separator + "material" |
| | | + File.separator + fileFullName); |
| | | break; |
| | | } |
| | |
| | | //doc_file/product/{产品型号}/standard或者{customCode}}/{version}/ |
| | | //跟子件挂钩的转移到子件图纸下:doc_file/material/ |
| | | String customCodeString = null; |
| | | if(customCode==null) { |
| | | customCodeString = "standard"; |
| | | }else{ |
| | | if(customCode!=null && !customCode.equals("")) { |
| | | customCodeString = customCode; |
| | | }else{ |
| | | customCodeString = "standard"; |
| | | } |
| | | String productDir = projectDir + File.separator + "doc_file" + File.separator + "product" + File.separator + parentModel |
| | | + File.separator + customCodeString + File.separator +nextVersion; |
| | |
| | | } |
| | | }); |
| | | |
| | | picUrlList.forEach(picUrl->{ |
| | | String picFullName = picUrl.substring(picUrl.lastIndexOf(File.separator) + 1); |
| | | try { |
| | | FileCopyUtils.copy(new File(picUrl),new File(materialDir+File.separator+picFullName)); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | |
| | | |
| | | //转移审批表数据到历史表/最新版本表 product_history/product_bom_history/product/product_bom |
| | | ProductHistory productHistory = new ProductHistory(); |
| | | productHistory.setParentCode(parentCode); |
| | | productHistory.setParentName(productApproving.getParentName()); |
| | | productApproving.setParentModel(parentModel); |
| | | productHistory.setParentModel(parentModel); |
| | | productHistory.setNotes(productApproving.getNotes()); |
| | | productHistory.setCustomCode(customCode); |
| | | productHistory.setCreateTime(new Date()); |
| | | productHistory.setVersion(nextVersion); |
| | | productHistory.setEnabled(1); |
| | | |
| | | Product productNew = new Product(); |
| | | productNew.setParentCode(parentCode); |
| | | productNew.setParentName(productApproving.getParentName()); |
| | | productNew.setParentModel(parentModel); |
| | | productNew.setNotes(productApproving.getNotes()); |
| | | productNew.setCustomCode(customCode); |
| | | productNew.setCreateTime(new Date()); |
| | | productNew.setVersion(nextVersion); |
| | | |
| | | //实际生效的只有insert,因为状态设置为未启用已经在提交审批时变更了 |
| | | phService.insertAndUpdateEnabled(productHistory); |
| | | int productId = productService.updateVersion(parentCode,customCode,nextVersion); |
| | | |
| | | productService.insert(productNew); |
| | | |
| | | List<ProductBomHistory> productBomHistoryList = new LinkedList<>(); |
| | | List<ProductBom> productBomList = new LinkedList<>(); |
| | |
| | | ProductBomHistory bomHistory = new ProductBomHistory(); |
| | | ProductBom bom = new ProductBom(); |
| | | |
| | | bom.setProductId(productId); |
| | | bom.setProductId(productNew.getId()); |
| | | bom.setCategory(approving.getCategory()); |
| | | bom.setCreateDate(new Date()); |
| | | bom.setDwgUrl(approving.getDwgUrl()); |
| | |
| | | bom.setThickness(approving.getThickness()); |
| | | bom.setType(approving.getType()); |
| | | bom.setUnit(approving.getUnit()); |
| | | bom.setUpUserId(approving.getUpUserId()); |
| | | //bom.setUpUserId(approving.getUpUserId()); |
| | | bom.setVersion(nextVersion); |
| | | |
| | | bomHistory.setProductId(productHistory.getId()); |
| | |
| | | bomHistory.setThickness(approving.getThickness()); |
| | | bomHistory.setType(approving.getType()); |
| | | bomHistory.setUnit(approving.getUnit()); |
| | | bomHistory.setUpUserId(approving.getUpUserId()); |
| | | //bomHistory.setUpUserId(approving.getUpUserId()); |
| | | bomHistory.setVersion(nextVersion); |
| | | |
| | | productBomHistoryList.add(bomHistory); |
| | |
| | | approvingList.forEach(approving->{ |
| | | if(!existCodeList.contains(approving.getSubCode())){ //这个审批bom中的物料不在物料管理内 |
| | | Material temp = new Material(); |
| | | temp.setCategory(approving.getCategory()); |
| | | //temp.setCategory(approving.getCategory()); |
| | | temp.setCreateDate(new Date()); |
| | | temp.setDwgUrl(approving.getDwgUrl()); |
| | | temp.setFileUrl(approving.getFileUrl()); |
| | | temp.setMaterial(approving.getMaterial()); |
| | | //temp.setMaterial(approving.getMaterial()); |
| | | temp.setNotes(approving.getNotes()); |
| | | temp.setPictureUrl(approving.getPictureUrl()); |
| | | temp.setProducer(approving.getProducer()); |
| | | temp.setQuantity(approving.getQuantity()); |
| | | //temp.setProducer(approving.getProducer()); |
| | | //TODO quantity |
| | | //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.setSurfaceDetail(approving.getSurfaceDetail()); |
| | | //temp.setThickness(approving.getThickness()); |
| | | temp.setType(approving.getType()); |
| | | temp.setUnit(approving.getUnit()); |
| | | materialList.add(temp); |
| | | } |
| | | }); |
| | | mService.insertBatch(materialList); |
| | | |
| | | if(materialList.size()!=0) { |
| | | mService.insertBatch(materialList); |
| | | } |
| | | //将dwg图纸,全部更新到对应的记录url中 |
| | | mService.updateDwgUrl(materialDwgUrlNameList); |
| | | if(materialDwgUrlNameList.size()!=0) { |
| | | mService.updateDwgUrl(materialDwgUrlNameList); |
| | | } |
| | | /*List<ProductBomApproving> fileBomApprovingList = approvingList.stream() |
| | | .filter(productBomApproving -> |
| | | productBomApproving.getPictureUrl() != null || productBomApproving.getDwgUrl() != null |
| | |
| | | //区分是新增还是删除 |
| | | Integer materialId = approvingList.get(0).getMaterialId(); |
| | | if(materialId==null) { //新增 |
| | | String fileUrl = approvingList.get(0).getFileUrl(); |
| | | File file = new File(fileUrl); |
| | | |
| | | List<String> fileUrlList = new LinkedList<>(); |
| | | List<String> dwgUrlList = null; |
| | | List<String> materialUrlList = new LinkedList<>(); |
| | | List<Material> materialDwgUrlNameList = new LinkedList<>(); |
| | | |
| | | fileUrlList = FileUtil.getStaticFilePath(file,fileUrlList); |
| | | dwgUrlList = fileUrlList.stream().filter(url->url.contains(".dwg")).collect(Collectors.toList()); |
| | | //图纸与物料model对应,则图纸需要保留并转移到正式文件夹 |
| | | //同时,保留图纸对应的物料model和正式文件夹中的http url |
| | | dwgUrlList.forEach(dwgUrl-> { |
| | | approvingList.forEach(approving -> { |
| | | String filename = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1, dwgUrl.length() - 4); |
| | | String fileFullName = dwgUrl.substring(dwgUrl.lastIndexOf(File.separator) + 1); |
| | | if (approving.getSubModel().toUpperCase().equals(filename.toUpperCase())) { |
| | | materialUrlList.add(dwgUrl); |
| | | |
| | | Material temp = new Material(); |
| | | temp.setSubModel(approving.getSubModel()); |
| | | temp.setNotes("doc_file" + File.separator + "material" |
| | | + File.separator + fileFullName); |
| | | materialDwgUrlNameList.add(temp); |
| | | } |
| | | }); |
| | | }); |
| | | String projectDir = CommonUtil.getProjectDir(); |
| | | String materialDir = projectDir + File.separator + "doc_file" + File.separator + "material"; |
| | | File materialFile = new File(materialDir); |
| | | if(!materialFile.exists()){ |
| | | materialFile.mkdirs(); |
| | | } |
| | | |
| | | 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")); |
| | | } catch (IOException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | //将物料从审批表中转移到正式表 |
| | | approvingList.forEach(approve -> { |
| | | Material material = new Material(); |
| | | material.setCategory(approve.getCategory()); |
| | | //material.setCategory(approve.getCategory()); |
| | | material.setSubCode(approve.getSubCode()); |
| | | material.setSubName(approve.getSubName()); |
| | | material.setSubModel(approve.getSubModel()); |
| | | material.setUnit(approve.getUnit()); |
| | | material.setQuantity(approve.getQuantity()); |
| | | material.setProducer(approve.getProducer()); |
| | | //TODO quantity |
| | | //material.setQuantity(approve.getQuantity()); |
| | | //material.setProducer(approve.getProducer()); |
| | | material.setNotes(approve.getNotes()); |
| | | material.setCreateDate(new Date()); |
| | | material.setStatus(1); |
| | | materialDwgUrlNameList.forEach(materialDwgUrlName->{ |
| | | if(materialDwgUrlName.getSubModel().equals(approve.getSubModel())){ |
| | | material.setDwgUrl(materialDwgUrlName.getDwgUrl()); |
| | | } |
| | | }); |
| | | materialList.add(material); |
| | | }); |
| | | mService.insertBatch(materialList); |
| | |
| | | his.setCustomCode(approving.getCustomCode()); |
| | | his.setSVersion(approving.getVersion()); |
| | | his.setEVersion(approving.getVersion()); |
| | | his.setSubCode(approving.getSubCode()); |
| | | his.setSubMaterialId(approving.getSubMaterialId()); |
| | | his.setQuantity(approving.getQuantity()); |
| | | his.setMaterialId(approving.getMaterialId()); |
| | | his.setCreateTime(new Date()); |
| | |
| | | } |
| | | }); |
| | | //新增关联 |
| | | mphService.insertBatch(addedList); |
| | | if(addedList.size()!=0) { |
| | | mphService.insertBatch(addedList); |
| | | } |
| | | //移除关联 |
| | | mphService.updateVersionSubtractBatch(removedList); |
| | | if(removedList.size()!=0) { |
| | | mphService.updateVersionSubtractBatch(removedList); |
| | | } |
| | | } |
| | | else if(type.intValue() == EnumWorksheetType.ProductSoftware.getType()){ //软件下载 |
| | | //转移记录到正式表 |
| | |
| | | public DocUser getApprovingUser(Integer mainId) { |
| | | return linkMapper.getApprovingUser(mainId); |
| | | } |
| | | |
| | | @Transactional |
| | | public Response confirmProductProcedureAndSOP(WorksheetLink link) throws IOException { |
| | | Integer mainId = linkMapper.selectById(link.getId()).getMainId(); |
| | | //更新子表 |
| | | linkMapper.updateById(link); |
| | | if(link.getLinkStatus() ==1){ |
| | | //查询当前单据子表是否已经全部同意 |
| | | QueryWrapper<WorksheetLink> query = Wrappers.query(); |
| | | query.eq("main_id",mainId); |
| | | List<WorksheetLink> linkList = linkMapper.selectList(query); |
| | | List<WorksheetLink> rejectList = linkList.stream().filter(linkFilter -> linkFilter.getLinkStatus() != 1).collect(Collectors.toList()); |
| | | if(rejectList == null){ |
| | | //都为1,已确认 |
| | | mainService.updateEndStatusById(mainId,"已确认",5); |
| | | //文件转移到审批完成后的正式路径 文件保存在/doc_file/procedure/xxx.doc |
| | | ProcedureDocApproving approving = procedureDocApprovingService.getByMainId(mainId); |
| | | String fileRelativePath = approving.getFile(); |
| | | String projectDir = CommonUtil.getProjectDir(); |
| | | String inFilePath = projectDir + File.separator + fileRelativePath; |
| | | String outFilePath = (projectDir + File.separator + fileRelativePath).replace("_approving",""); |
| | | WordUtil.fillValue(inFilePath,outFilePath,Arrays.asList(approving.getFzr(),approving.getBz(),approving.getZz(),approving.getPb())); |
| | | //删除之前预览产生的中间文件 |
| | | String filename = fileRelativePath.substring(fileRelativePath.lastIndexOf(File.separator)+1,fileRelativePath.lastIndexOf(".")); |
| | | File approvingDir = new File(projectDir + File.separator + "procedure_approving"); |
| | | FilenameFilter filenameFilter = new FilenameFilter() { |
| | | @Override |
| | | public boolean accept(File dir, String name) { |
| | | name = name.substring(0,name.lastIndexOf(".")); |
| | | if(name.contains(filename) && !name.equals(filename)){ |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | }; |
| | | File[] files = approvingDir.listFiles(filenameFilter); |
| | | for (File file : files) { |
| | | file.delete(); |
| | | } |
| | | |
| | | //流程文件数据转移 |
| | | ProcedureDoc procedureDoc = new ProcedureDoc(); |
| | | procedureDoc.setName(approving.getName()); |
| | | procedureDoc.setDescription(approving.getDescription()); |
| | | procedureDoc.setVersion(approving.getVersion()); |
| | | procedureDoc.setFzr(approving.getFzr()); |
| | | procedureDoc.setBz(approving.getBz()); |
| | | procedureDoc.setType(approving.getType()); |
| | | procedureDoc.setCreateTime(new Date()); |
| | | procedureDoc.setFile(fileRelativePath.replace("_approving","")); |
| | | procedureDocService.insert(procedureDoc); |
| | | } |
| | | }else{ |
| | | mainService.updateEndStatusById(mainId,"已驳回",0); |
| | | } |
| | | return new Response().set(1); |
| | | } |
| | | } |