From cf9a5039e6db9d1d5963e3fe1a37d00169ec2ef7 Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期三, 25 六月 2025 11:18:22 +0800 Subject: [PATCH] 验收报告修改 --- src/main/java/com/whyc/service/ProductBomService.java | 113 +++++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 90 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/whyc/service/ProductBomService.java b/src/main/java/com/whyc/service/ProductBomService.java index 3898f7d..d688662 100644 --- a/src/main/java/com/whyc/service/ProductBomService.java +++ b/src/main/java/com/whyc/service/ProductBomService.java @@ -9,6 +9,7 @@ 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.ProductBomMapper; import com.whyc.mapper.ProductMapper; @@ -16,16 +17,18 @@ import com.whyc.util.ActionUtil; import org.apache.poi.hssf.usermodel.*; import org.apache.poi.ss.usermodel.ClientAnchor; -import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.IndexedColors; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.bind.annotation.RequestParam; import javax.imageio.ImageIO; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.awt.image.BufferedImage; import java.io.*; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.Date; import java.util.LinkedList; @@ -43,6 +46,9 @@ @Autowired(required = false) private ProductMapper productMapper; + + @Autowired(required = false) + private AttachLockMapper attachLockMapper; @Autowired private DocLogService logService; @@ -187,6 +193,35 @@ } } + //鏂囦欢澶圭殑鎷疯礉绉婚櫎productId瀵瑰簲鐨勮閿佸畾鐨� + public void copyDirWithOutProductId(String sourcePathDir, String newPathDir,int productId) { + File start = new File(sourcePathDir); + File end = new File(newPathDir); + if(!start.exists()) { + return; + } + String[] filePath = start.list();//鑾峰彇璇ユ枃浠跺す涓嬬殑鎵�鏈夋枃浠朵互鍙婄洰褰曠殑鍚嶅瓧 + if(!end.exists()) { + end.mkdir(); + } + if(filePath.length>=0){ + for(String temp : filePath) { + //娣诲姞婊¤冻鎯呭喌鐨勬潯浠� + if(new File(sourcePathDir + File.separator + temp ).isFile()) { + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("product_id",productId); + wrapper.eq("attach_name",temp); + wrapper.eq("lock_flag",1); + wrapper.last("limit 1"); + AttachLock attachLock=attachLockMapper.selectOne(wrapper); + if(attachLock==null){ + //涓烘枃浠跺垯杩涜鎷疯礉 + copyFile(new File(sourcePathDir + File.separator + temp ), newPathDir ); + } + } + } + } + } public void updateUrl(List<ProductBomApproving> fileBomApprovingList) { mapper.updateUrl(fileBomApprovingList); } @@ -210,7 +245,8 @@ return new Response().setII(1,list!=null,pageInfo,"杩斿洖鏁版嵁"); }*/ //浜у搧涓嬭浇(浜у搧id鍜岀増鏈�) - public void downloadProduct(HttpServletRequest req, HttpServletResponse resp, int productId , int version) { + public void downloadProduct(HttpServletRequest req, HttpServletResponse resp, int productId , int version + , @RequestParam String oprateReason, @RequestParam String oprateInfo) { HSSFWorkbook wb = new HSSFWorkbook(); //璇诲彇浜у搧淇℃伅 QueryWrapper wrapper=new QueryWrapper(); @@ -224,6 +260,17 @@ List<ProductBom> endList=new ArrayList<>(); list.stream().forEach(bom -> { bom.setConnFlag(0); + if(bom.getDwgUrl()!=null){ + QueryWrapper qwrapper=new QueryWrapper(); + qwrapper.eq("material_id",bom.getMaterialId()); + qwrapper.eq("attach_name",bom.getDwgUrl().substring(bom.getDwgUrl().lastIndexOf("\\")+1)); + qwrapper.eq("lock_flag",1); + qwrapper.last("limit 1"); + AttachLock attachLock=attachLockMapper.selectOne(qwrapper); + if(attachLock!=null){ + bom.setDwgUrl(""); + } + } endList.add(bom); if(bom.getMaterials()!=null&&bom.getMaterials().size()>0){ for (Material m:bom.getMaterials()) { @@ -241,18 +288,13 @@ withOutDwg+=File.separator+"standard"+File.separator+version; } //鐢熸垚excel骞跺皢dwg鏂囦欢鏀惧湪鍚屼竴鎶ヤ笅鍘嬬缉 - creatBomExcel(req,resp,product,endList,wb,withOutDwg); - //璁板綍鏃ュ織 - DocUser docUser= ActionUtil.getUser(); - String operationDetail="鍏蜂綋浜у搧淇℃伅涓�:"+product.toString(); - String opreationMsg="鎵ц浜嗘渶鏂扮増浜у搧涓嬭浇鎿嶄綔"; - String terminalIp=req.getRemoteAddr(); - logService.recordOperationLog(docUser.getId(),docUser.getName(), UserOperation.TYPE_DOWNLOAD.getType(),new Date(),terminalIp,opreationMsg,operationDetail); + creatBomExcel(req,resp,product,endList,wb,withOutDwg,ActionUtil.sdfwithALL.format(product.getVersionTime()),oprateReason,oprateInfo); } //鏍规嵁浜у搧淇℃伅鍒涘缓excel琛ㄦ牸骞跺瓨鏀惧湪鎸囧畾鐩綍 - private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String withOutDwg){ + private void creatBomExcel(HttpServletRequest req, HttpServletResponse resp,Product product,List list, HSSFWorkbook wb,String withOutDwg + , String oprateVersion, @RequestParam String oprateReason, @RequestParam String oprateInfo){ String fileDirName = FileDirPath.getFileDirName(); String rootFace=""; String excelName=""; @@ -260,9 +302,11 @@ ,"鍩烘湰鍗曚綅","瀛愪欢鏁伴噺","鐢熶骇鍟�","灏佽绫诲瀷/鏉愯川","鍏冧欢缂栧彿/鏂欏帤","琛ㄩ潰澶勭悊/鐗╂枡璇︽儏","澶囨敞","鍥剧墖"}; //瀛椾綋鏍煎紡-鍔犵矖 HSSFCellStyle cellStyle = wb.createCellStyle(); + cellStyle.setFillForegroundColor(IndexedColors.GOLD.getIndex());//娣诲姞鍓嶆櫙鑹�,鍐呭鐪嬬殑娓呮 + cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); - font.setColor(HSSFFont.COLOR_RED); + //font.setColor(HSSFFont.COLOR_RED); cellStyle.setFont(font); //鍒涘缓鍗曚釜sheet HSSFSheet sheet = wb.createSheet("浜у搧淇℃伅"); @@ -296,7 +340,7 @@ } //灏嗘病鏈夌鐞咮OM鐨刣wg鏂囦欢鎷疯礉涓嬭浇 withOutDwg=fileDirName+File.separator+withOutDwg; - copyDir(withOutDwg,rootFace); + copyDirWithOutProductId(withOutDwg,rootFace,product.getId()); //灏嗛�変腑鐨勬枃浠跺瓨鍏ユ寚瀹氱洰褰曚笅鎵撳寘涓嬭浇 if(list!=null&&list.size()>0){ for (int i=0;i<list.size();i++) { @@ -400,7 +444,7 @@ BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(fileDirName+File.separator+bom.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)); @@ -440,9 +484,10 @@ ZipUtils.toZip(rootFace, forootFace,true); // 杞爜闃叉涔辩爜 - resp.addHeader("Content-Disposition", "attachment;filename=" + /*resp.addHeader("Content-Disposition", "attachment;filename=" + new String(excelName.getBytes("UTF-8"), "ISO8859-1") - + ".zip"); + + ".zip");*/ + resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode (excelName+".zip", "utf-8")); OutputStream out = resp.getOutputStream(); FileInputStream in = new FileInputStream(rootFace+".zip"); int len=0; @@ -460,6 +505,9 @@ } catch (IOException e) { e.printStackTrace(); } + //璁板綍鏃ュ織 + logService.recordOperationLogDownLoad(ActionUtil.getUser().getId(),ActionUtil.getUser().getName(), UserOperation.TYPE_DOWNLOAD_PRODUCT.getType(),new Date(),req.getRemoteAddr() + ,excelName+".zip",rootFace+".zip",oprateReason,oprateInfo,oprateVersion); } //鏌ヨ鎵�鏈変骇鍝佷腑娌℃湁涓庢寚瀹氭暎瑁呬欢鍏宠仈鐨勫瓙浠� public Response getAllSubWithOutMaterial(int materialId) { @@ -492,6 +540,20 @@ //鏍规嵁浜у搧id鏌ヨ瀛愪欢鍙婂叾鍏宠仈鐨勭墿鏂欎俊鎭� public Response getBomAndMaterial(int productId,int version) { List<ProductBom> list=mapper.getBomAndMaterial(productId,version); + if(list!=null&&list.size()>0){ + list.stream().forEach(bom -> { + if(bom.getDwgUrl()!=null){ + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("material_id",bom.getMaterialId()); + wrapper.eq("attach_name",bom.getDwgUrl().substring(bom.getDwgUrl().lastIndexOf("\\")+1)); + wrapper.last("limit 1"); + AttachLock attachLock=attachLockMapper.selectOne(wrapper); + if(attachLock!=null){ + bom.setDwgUrl(""); + } + } + }); + } return new Response().setII(1,list.size()>0,list,"杩斿洖鐗╂枡淇℃伅鍙婂叧鑱旂墿鏂�"); } @@ -499,17 +561,17 @@ private ProductBom copyMaterialToBom(Material m) { ProductBom bom=new ProductBom(); bom.setType(m.getType()); - bom.setCategory(m.getCategory()); + //bom.setCategory(m.getCategory()); bom.setSubCode(m.getSubCode()); bom.setSubName(m.getSubName()); bom.setSubModel(m.getSubModel()); bom.setUnit(m.getUnit()); //bom.setQuantity(m.getQuantity()); - bom.setProducer(m.getProducer()); - bom.setMaterial(m.getMaterial()); - bom.setThickness(m.getThickness()); - bom.setSurfaceDetail(m.getSurfaceDetail()); - bom.setNotes(m.getNotes()); + //bom.setProducer(m.getProducer()); + //bom.setMaterial(m.getMaterial()); + //bom.setThickness(m.getThickness()); + //bom.setSurfaceDetail(m.getSurfaceDetail()); + //bom.setNotes(m.getNotes()); bom.setPictureUrl(m.getPictureUrl()); bom.setDwgUrl(m.getDwgUrl()); bom.setFileUrl(m.getFileUrl()); @@ -538,7 +600,12 @@ return mapper.getListByCodeAndModelList2(bomList); } - public ProductBom getEnabledStandardBomListByParentCode(String parentCode) { - return mapper.getEnabledStandardBomListByParentCode(parentCode); + public List<ProductBom> getEnabledBomListByParentCodeAndCustomCode(String parentCode, String customCode) { + return mapper.getEnabledBomListByParentCodeAndCustomCode(parentCode,customCode); + } + + public void updateMaterialField2Bom() { + List<ProductBom> bomList = mapper.selectListWithMaterialField(); + mapper.updateMaterialField2BomBatch(bomList); } } -- Gitblit v1.9.1