From 31f95f2aaf83857dc53a9b43dc45762689df4d2c Mon Sep 17 00:00:00 2001 From: whyclxw <810412026@qq.com> Date: 星期一, 16 六月 2025 10:27:27 +0800 Subject: [PATCH] 验收信息表导出修改 --- src/main/java/com/whyc/service/BomAcceptanceService.java | 155 ++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 138 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/whyc/service/BomAcceptanceService.java b/src/main/java/com/whyc/service/BomAcceptanceService.java index 7a29d8a..c49e2f8 100644 --- a/src/main/java/com/whyc/service/BomAcceptanceService.java +++ b/src/main/java/com/whyc/service/BomAcceptanceService.java @@ -14,15 +14,21 @@ import com.whyc.util.CommonUtil; import com.whyc.util.FileUtil; import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.ss.usermodel.BorderStyle; +import org.apache.poi.ss.usermodel.ClientAnchor; import org.apache.poi.ss.usermodel.IndexedColors; +import org.apache.poi.ss.util.CellRangeAddress; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.multipart.MultipartFile; +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.List; @@ -233,12 +239,32 @@ } } //缂栬緫鍗曚釜鍥剧墖涓婁紶 - public Response updateDevPic(MultipartFile filePic, int num,int picNum,String picUrl) throws IOException { + public Response updateDevPic(MultipartFile filePic, int num,int picNum) throws IOException { Date date = new Date(); long time = date.getTime(); String rootFile = CommonUtil.getRootFile(); String devDirSuffix = "acceptance_bom" + File.separator + time + File.separator+ "dev" + File.separator; String devDir = rootFile + devDirSuffix; + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("num",num); + wrapper.last("limit 1"); + BomAcceptance bomAcceptance=mapper.selectOne(wrapper); + String picUrl=""; + if(picNum==1){ + picUrl=bomAcceptance.getDevPicleft(); + } + if(picNum==2){ + picUrl=bomAcceptance.getDevPicright(); + } + if(picNum==3){ + picUrl=bomAcceptance.getDevPicfront(); + } + if(picNum==4){ + picUrl=bomAcceptance.getDevPicback(); + } + if(picNum==6){ + picUrl=bomAcceptance.getBomAgreement(); + } //鍚庨潰鍥� if(filePic!=null){ //瀛樺偍鏂囦欢 @@ -257,9 +283,14 @@ } } //缂栬緫澶氫釜鍥剧墖涓婁紶 - public Response updatePartPic(List<MultipartFile> multipartFileList, String picUrl) throws IOException { + public Response updatePartPic(List<MultipartFile> multipartFileList, int num) throws IOException { String rootFile = CommonUtil.getRootFile(); rootFile=rootFile.replace("doc_file",""); + QueryWrapper wrapper=new QueryWrapper(); + wrapper.eq("num",num); + wrapper.last("limit 1"); + BomAcceptance bomAcceptance=mapper.selectOne(wrapper); + String picUrl=bomAcceptance.getSparePicpart(); //閰嶄欢瀛樺偍 if(multipartFileList!=null && multipartFileList.size()!=0){ for (int i = 0; i < multipartFileList.size(); i++) { @@ -285,30 +316,66 @@ wrapper.last("limit 1"); BomAcceptance bomAcceptance=mapper.selectOne(wrapper); //鐢熸垚excel - creatBomAcceptanceExcel(req,resp,bomAcceptance); + creatBomAcceptanceExcel(resp,bomAcceptance); } //鐢熸垚excel - private void creatBomAcceptanceExcel(HttpServletRequest req, HttpServletResponse resp, BomAcceptance bomAcceptance) { + private void creatBomAcceptanceExcel( HttpServletResponse resp, BomAcceptance bomAcceptance) { + String rootFile = CommonUtil.getRootFile(); + List<String> sparePicList=new ArrayList<>(); + if(bomAcceptance.getSparePicpart()!=null||!bomAcceptance.getSparePicpart().isEmpty()){ + String filePath=rootFile+bomAcceptance.getSparePicpart(); + //鑾峰彇鏂囦欢澶逛笅鎵�鏈夌殑鍥剧墖鍚� + sparePicList=FileUtil.getFileNameWithOutDirectory(filePath); + } + String devRoot=rootFile.replace("doc_file", ""); + List<String> devPicList=new ArrayList<>(); + if(bomAcceptance.getDevPicleft()!=null||!bomAcceptance.getDevPicleft().isEmpty()){ + devPicList.add(bomAcceptance.getDevPicleft()); + } + if(bomAcceptance.getDevPicright()!=null||!bomAcceptance.getDevPicright().isEmpty()){ + devPicList.add(bomAcceptance.getDevPicright()); + } + if(bomAcceptance.getDevPicfront()!=null||!bomAcceptance.getDevPicfront().isEmpty()){ + devPicList.add(bomAcceptance.getDevPicfront()); + } + if(bomAcceptance.getDevPicback()!=null||!bomAcceptance.getDevPicback().isEmpty()){ + devPicList.add(bomAcceptance.getDevPicback()); + } + String fileName="浜у搧楠屾敹淇℃伅璁板綍"; //鍒涘缓鍗曚釜sheet HSSFWorkbook wb = new HSSFWorkbook(); //瀛椾綋鏍煎紡-鍔犵矖 HSSFCellStyle cellStyle = wb.createCellStyle(); - cellStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER); + cellStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); + + cellStyle.setBorderBottom(BorderStyle.THICK); + cellStyle.setBorderLeft(BorderStyle.THICK); + cellStyle.setBorderRight(BorderStyle.THICK); + cellStyle.setBorderTop(BorderStyle.THICK); + HSSFFont font = wb.createFont(); font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); cellStyle.setFont(font); HSSFSheet sheet = wb.createSheet("浜у搧楠屾敹淇℃伅璁板綍"); - sheet.setColumnWidth(1,10000); + sheet.setColumnWidth(0,10000); + if(sparePicList!=null&&sparePicList.size()>0){ + int length = sparePicList.size(); + length=length>5?length:4; + for (int i = 1; i < length+1; i++){ + sheet.setColumnWidth(i,5000); + } + } sheet.setDefaultRowHeight((short)(1000)); //鍥剧墖鍏冪礌 HSSFPatriarch patriarch = sheet.createDrawingPatriarch(); int rowNum=0; HSSFRow row=sheet.createRow(rowNum); HSSFCell cell=row.createCell(0); - cell=row.createCell(0); - cell.setCellValue("浜у搧楠屾敹淇℃伅璁板綍"); + cell.setCellValue("浜у搧楠屾敹淇℃伅璁板綍琛�"); cell.setCellStyle(cellStyle); + sheet.addMergedRegion(new CellRangeAddress(0,0,0,1)); rowNum++; row=sheet.createRow(rowNum); @@ -337,6 +404,7 @@ cell.setCellValue(bomAcceptance.getBomModel()); cell.setCellStyle(cellStyle); + rowNum++; row=sheet.createRow(rowNum); cell=row.createCell(0); @@ -363,6 +431,7 @@ cell=row.createCell(1); cell.setCellValue(bomAcceptance.getStandParam()); cell.setCellStyle(cellStyle); + sheet.addMergedRegion(new CellRangeAddress(4,5,0,0)); rowNum++; row=sheet.createRow(rowNum); @@ -396,18 +465,66 @@ cell=row.createCell(0); cell.setCellValue("涓绘満鐓х墖(宸︿晶鍥撅紝姝i潰鍥撅紝鍙充晶鍥撅紝鍚庨潰鍥�)"); cell.setCellStyle(cellStyle); - cell=row.createCell(1); - cell.setCellValue(bomAcceptance.getDevWeightAll()); - cell.setCellStyle(cellStyle); + if(devPicList!=null&&devPicList.size()>0){ + ByteArrayOutputStream byteArrayOut = null; + for(int i=0;i<devPicList.size();i++){ + String picUrl=devPicList.get(i); + try { + byteArrayOut = new ByteArrayOutputStream(); + String path=devRoot+File.separator+picUrl; + BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(path))); + ImageIO.write(bufferImg, "png", byteArrayOut); + //anchor涓昏鐢ㄤ簬璁剧疆鍥剧墖鐨勫睘鎬� + HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) (i+1), rowNum, (short) (i+1), rowNum); + anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE); + //鎻掑叆鍥剧墖 + patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG)); + } catch (IOException e) { + e.printStackTrace(); + }finally { + if (byteArrayOut != null) { + try { + byteArrayOut.close(); + } catch (IOException e) { + System.out.println("鍏抽棴ByteArrayOutputStream澶辫触"); + } + } + } + } + } rowNum++; row=sheet.createRow(rowNum); cell=row.createCell(0); cell.setCellValue("閰嶄欢鐓х墖"); cell.setCellStyle(cellStyle); - cell=row.createCell(1); - cell.setCellValue(bomAcceptance.getDevWeightAll()); - cell.setCellStyle(cellStyle); + if(sparePicList!=null&&sparePicList.size()>0){ + ByteArrayOutputStream byteArrayOut = null; + for(int i=0;i<sparePicList.size();i++){ + String picUrl=sparePicList.get(i); + try { + byteArrayOut = new ByteArrayOutputStream(); + String path=rootFile+File.separator+bomAcceptance.getSparePicpart()+File.separator+picUrl; + BufferedImage bufferImg = ImageIO.read(new FileInputStream(new File(path))); + ImageIO.write(bufferImg, "png", byteArrayOut); + //anchor涓昏鐢ㄤ簬璁剧疆鍥剧墖鐨勫睘鎬� + HSSFClientAnchor anchor = new HSSFClientAnchor(50, 20, 1000, 230,(short) (i+1), rowNum, (short) (i+1), rowNum); + anchor.setAnchorType(ClientAnchor.MOVE_AND_RESIZE); + //鎻掑叆鍥剧墖 + patriarch.createPicture(anchor, wb.addPicture(byteArrayOut.toByteArray(), HSSFWorkbook.PICTURE_TYPE_JPEG)); + } catch (IOException e) { + e.printStackTrace(); + }finally { + if (byteArrayOut != null) { + try { + byteArrayOut.close(); + } catch (IOException e) { + System.out.println("鍏抽棴ByteArrayOutputStream澶辫触"); + } + } + } + } + } rowNum++; row=sheet.createRow(rowNum); @@ -424,9 +541,13 @@ cell.setCellValue("绔彛鍗忚鏂囨湰"); cell.setCellStyle(cellStyle); cell=row.createCell(1); - String agreement=bomAcceptance.getBomAgreement(); - cell.setCellValue(agreement); - cell.setCellStyle(cellStyle); + if(bomAcceptance.getBomAgreement()!=null||!bomAcceptance.getBomAgreement().equals("")){ + String agreement=bomAcceptance.getBomAgreement(); + String agreementName = agreement.substring(agreement.lastIndexOf(".")+1); + cell.setCellValue(agreementName); + cell.setCellStyle(cellStyle); + } + //灏嗘枃浠跺瓨鍒版寚瀹氫綅缃� OutputStream os = null; try { -- Gitblit v1.9.1