From 1f15333b0a97a327865f7aab8f1e3f9ba8fc16f8 Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期五, 18 十月 2024 12:45:59 +0800
Subject: [PATCH] 电路站点报告调试+总报告ing

---
 inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java |  449 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 404 insertions(+), 45 deletions(-)

diff --git a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
index 4d1bf27..d7805c8 100644
--- a/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
+++ b/inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -1,49 +1,83 @@
 package com.yuanchu.mom.service.impl;
 
-import com.aspose.words.License;
-import com.aspose.words.SaveFormat;
+import cn.hutool.core.util.ObjectUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.aspose.words.*;
+import com.aspose.words.Document;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.deepoove.poi.XWPFTemplate;
-import com.deepoove.poi.data.Pictures;
+import com.deepoove.poi.config.Configure;
+import com.deepoove.poi.config.ConfigureBuilder;
+import com.deepoove.poi.data.*;
+import com.deepoove.poi.data.style.*;
+import com.deepoove.poi.data.style.Style;
+import com.deepoove.poi.data.style.TableStyle;
+import com.deepoove.poi.util.TableTools;
+import com.itextpdf.text.BadElementException;
+import com.itextpdf.text.DocumentException;
+import com.itextpdf.text.pdf.PdfContentByte;
+import com.itextpdf.text.pdf.PdfReader;
+import com.itextpdf.text.pdf.PdfStamper;
 import com.yuanchu.mom.common.GetLook;
 import com.yuanchu.mom.common.PrintChina;
+import com.yuanchu.mom.dto.InsReportDto;
+import com.yuanchu.mom.dto.InsReportDto1;
 import com.yuanchu.mom.dto.ReportPageDto;
+import com.yuanchu.mom.dto.SampleProductDto;
 import com.yuanchu.mom.exception.ErrorException;
-import com.yuanchu.mom.mapper.InsOrderMapper;
-import com.yuanchu.mom.mapper.InsReportMapper;
-import com.yuanchu.mom.mapper.UserMapper;
-import com.yuanchu.mom.pojo.InsOrder;
-import com.yuanchu.mom.pojo.InsReport;
+import com.yuanchu.mom.mapper.*;
+import com.yuanchu.mom.pojo.*;
 import com.yuanchu.mom.service.InsReportService;
+import com.yuanchu.mom.service.StandardTemplateService;
+import com.yuanchu.mom.utils.JackSonUtil;
+import com.yuanchu.mom.utils.MatrixToImageWriter;
 import com.yuanchu.mom.utils.QueryWrappers;
+import com.yuanchu.mom.utils.WordUtils;
+import com.yuanchu.mom.vo.Result;
+import org.apache.commons.io.IOUtils;
+import org.apache.logging.log4j.util.Strings;
+import org.apache.poi.xwpf.usermodel.*;
+import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.*;
 import java.nio.file.Files;
+import java.nio.file.Path;
 import java.nio.file.Paths;
+import java.nio.file.StandardCopyOption;
 import java.time.LocalDateTime;
-import java.util.HashMap;
-import java.util.Map;
+import java.time.format.DateTimeFormatter;
+import java.util.*;
+import java.util.List;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+import java.util.zip.ZipOutputStream;
 
 /**
-* @author Administrator
-* @description 閽堝琛ㄣ�恑ns_report(妫�楠屾姤鍛�)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
-* @createDate 2024-03-17 22:10:02
-*/
+ * @author Administrator
+ * @description 閽堝琛ㄣ�恑ns_report(妫�楠屾姤鍛�)銆戠殑鏁版嵁搴撴搷浣淪ervice瀹炵幇
+ * @createDate 2024-03-17 22:10:02
+ */
 @Service
 public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
-    implements InsReportService{
+        implements InsReportService {
 
     @Resource
     private GetLook getLook;
@@ -60,8 +94,47 @@
     @Value("${file.path}")
     private String imgUrl;
 
+    @Value("${twoCode}")
+    private String twoCode;
+
     @Resource
     private InsOrderMapper insOrderMapper;
+
+    @Resource
+    private StandardMethodListMapper standardMethodListMapper;
+
+    @Resource
+    private InsOrderStateMapper insOrderStateMapper;
+
+    @Resource
+    WordUtils wordUtils;
+
+    @Resource
+    private InsProductMapper insProductMapper;
+
+    @Resource
+    private InsProductResultMapper insProductResultMapper;
+
+    @Resource
+    private InsProductResult2Mapper insProductResult2Mapper;
+
+    @Resource
+    private InsOrderUserMapper insOrderUserMapper;
+
+    @Resource
+    private InsSampleMapper insSampleMapper;
+
+    @Resource
+    private InsSampleUserMapper insSampleUserMapper;
+
+    @Resource
+    private CustomMapper customMapper;
+
+    @Resource
+    private InsOrderFileMapper insOrderFileMapper;
+
+    @Resource
+    private StandardTemplateService standardTemplateService;
 
     @Override
     public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) {
@@ -69,7 +142,19 @@
         map.put("head", PrintChina.printChina(ReportPageDto.class));
         Map<String, Integer> map1 = getLook.selectPowerByMethodAndUserId("pageInsReport");
         if (map1.get("look") == 1) reportPageDto.setCreateUser(map1.get("userId"));
-        map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto)));
+        User user = userMapper.selectById(map1.get("userId"));//褰撳墠鐧诲綍鐨勪汉
+        //鑾峰彇褰撳墠浜烘墍灞炲疄楠屽id
+        String departLimsId = user.getDepartLimsId();
+        String laboratory = null;
+        if (ObjectUtils.isNotEmpty(departLimsId) && !departLimsId.equals("")) {
+            String[] split = departLimsId.split(",");
+            //鏌ヨ瀵瑰簲鏋舵瀯鍚嶇О(閫氫俊瀹為獙瀹�,鐢靛姏瀹為獙瀹�,妫�娴嬪姙)
+            String departLims = insOrderMapper.seldepLimsId(Integer.parseInt(split[split.length - 1]));
+            if (departLims.contains("瀹為獙瀹�")) {
+                laboratory = departLims;
+            }
+        }
+        map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto), laboratory));
         return map;
     }
 
@@ -98,16 +183,16 @@
         String signatureUrl;
         try {
             signatureUrl = userMapper.selectById(insReport.getWriteUserId()).getSignatureUrl();
-        }catch (Exception e){
+        } catch (Exception e) {
             throw new ErrorException("鎵句笉鍒扮紪鍒朵汉鐨勭鍚�");
         }
         //绯荤粺鐢熸垚鎶ュ憡鍦板潃
         String url = insReport.getUrl();
         //鎵嬪姩涓婁紶鎶ュ憡鍦板潃
         String urlS = insReport.getUrlS();
-        wordInsertUrl(new HashMap<String, Object>(){{
-            put("writeUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).create());
-        }}, (urlS==null?url:urlS).replace("/word", wordUrl));
+        wordInsertUrl(new HashMap<String, Object>() {{
+            put("writeUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
+        }}, (urlS == null ? url : urlS).replace("/word", wordUrl));
         return insReportMapper.updateById(insReport);
     }
 
@@ -121,7 +206,7 @@
         }
         insReport.setExamineUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//瀹℃牳浜�
         insReport.setExamineTime(LocalDateTime.now());//瀹℃牳鏃堕棿
-        if (isExamine==0){
+        if (isExamine == 0) {
             //濡傛灉瀹℃牳涓嶉�氳繃
             insReport.setState(0);//鎻愪氦鐘舵�佹敼涓哄緟鎻愪氦
             return insReportMapper.updateById(insReport);
@@ -130,23 +215,23 @@
         String signatureUrl;
         try {
             signatureUrl = userMapper.selectById(insReport.getExamineUserId()).getSignatureUrl();
-        }catch (Exception e){
+        } catch (Exception e) {
             throw new ErrorException("鎵句笉鍒板鏍镐汉鐨勭鍚�");
         }
         //绯荤粺鐢熸垚鎶ュ憡鍦板潃
         String url = insReport.getUrl();
         //鎵嬪姩涓婁紶鎶ュ憡鍦板潃
         String urlS = insReport.getUrlS();
-        wordInsertUrl(new HashMap<String, Object>(){{
-            put("examineUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).create());
-        }}, (urlS==null?url:urlS).replace("/word", wordUrl));
+        wordInsertUrl(new HashMap<String, Object>() {{
+            put("examineUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
+        }}, (urlS == null ? url : urlS).replace("/word", wordUrl));
         return insReportMapper.updateById(insReport);
     }
 
     //鎵瑰噯
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public int ratifyReport(Integer id, Integer isRatify, String ratifyTell) {
+    public int ratifyReport(Integer id, Integer isRatify, String ratifyTell, String sealUrl) {
         InsReport insReport = insReportMapper.selectById(id);
         insReport.setIsRatify(isRatify);
         if (ObjectUtils.isNotEmpty(ratifyTell)) {
@@ -154,7 +239,7 @@
         }
         insReport.setRatifyUserId(getLook.selectPowerByMethodAndUserId(null).get("userId"));//鎵瑰噯浜�
         insReport.setRatifyTime(LocalDateTime.now());//鎵瑰噯鏃堕棿
-        if (isRatify==0){
+        if (isRatify == 0) {
             //濡傛灉鎵瑰噯涓嶉�氳繃
             insReport.setState(0);//鎻愪氦鐘舵�佹敼涓哄緟鎻愪氦
             return insReportMapper.updateById(insReport);
@@ -163,26 +248,30 @@
         String signatureUrl;
         try {
             signatureUrl = userMapper.selectById(insReport.getRatifyUserId()).getSignatureUrl();
-        }catch (Exception e){
+        } catch (Exception e) {
             throw new ErrorException("鎵句笉鍒版壒鍑嗕汉鐨勭鍚�");
         }
-        String sealUrl;
+        //鑾峰彇鍦烘墍鐨勬姤鍛婁笓鐢ㄧ珷
+       /* String sealUrl;
         try {
             String laboratory = insOrderMapper.selectById(insReport.getInsOrderId()).getLaboratory();
             sealUrl = insReportMapper.getLaboratoryByName(laboratory);
-        }catch (Exception e){
-            throw new ErrorException("鎵句笉鍒版姤鍛婄珷鍗�");
+        } catch (Exception e) {
+            throw new ErrorException("鎵句笉鍒版姤鍛婁笓鐢ㄧ珷");
         }
+        if (sealUrl == null) throw new ErrorException("鎵句笉鍒版姤鍛婁笓鐢ㄧ珷");*/
         //绯荤粺鐢熸垚鎶ュ憡鍦板潃
         String url = insReport.getUrl();
         //鎵嬪姩涓婁紶鎶ュ憡鍦板潃
         String urlS = insReport.getUrlS();
-        wordInsertUrl(new HashMap<String, Object>(){{
-            put("ratifyUrl", Pictures.ofLocal(imgUrl+"/"+signatureUrl).create());
-            put("seal1", Pictures.ofLocal(imgUrl+"/"+sealUrl).create());
-            put("seal2", Pictures.ofLocal(imgUrl+"/"+sealUrl).create());
-        }}, (urlS==null?url:urlS).replace("/word", wordUrl));
-        wordToPdf((urlS == null ? url : urlS).replace("/word", wordUrl));
+        String finalUrl = (urlS == null ? url : urlS).replace("/word", wordUrl);
+        wordInsertUrl(new HashMap<String, Object>() {{
+            put("ratifyUrl", Pictures.ofLocal(imgUrl + "/" + signatureUrl).create());
+            put("seal1", Pictures.ofLocal(imgUrl + "/" + sealUrl).create());
+            put("seal2", Pictures.ofLocal(imgUrl + "/" + sealUrl).create());
+        }}, finalUrl);
+        wordToPdf(finalUrl, sealUrl);
+
         InsOrder insOrder = new InsOrder();
         insOrder.setId(insReportMapper.selectById(id).getInsOrderId());
         insOrder.setState(4);
@@ -201,11 +290,190 @@
         return 1;
     }
 
+
+    //鎶ュ憡鎵归噺涓嬭浇
     @Override
-    public void wordToPdf(String path) {
+    @Transactional(rollbackFor = Exception.class)
+    public String downAll(String ids) {
+        List<Long> list = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
+        List<InsReport> insReports = insReportMapper.selectBatchIds(list);
+        String zipFilePath = null;
+        // 涓存椂鏂囦欢澶硅矾寰�
+        try {
+            String tempFolderPath = wordUrl + "/tempFolder";
+            File tempFolder = new File(tempFolderPath);
+            if (tempFolder.exists()) {
+                deleteDirectory(tempFolder); // 鍒犻櫎鏃х殑涓存椂鏂囦欢澶�
+            }
+            tempFolder.mkdirs(); // 鍒涘缓鏂扮殑涓存椂鏂囦欢澶�
+            for (InsReport insReport : insReports) {
+                File sourceFile = new File((ObjectUtils.isNotEmpty(insReport.getUrlS()) ? insReport.getUrlS() : insReport.getUrl()).replace("/word", wordUrl));
+                File destinationFile = new File(tempFolder, sourceFile.getName());
+                Files.copy(sourceFile.toPath(), destinationFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
+            }
+            // 鍘嬬缉涓存椂鏂囦欢澶�
+            zipFilePath = wordUrl + "/zip/output.zip";
+            zipDirectory(tempFolderPath, zipFilePath);
+
+            // 娓呯悊涓存椂鏂囦欢澶�
+            deleteDirectory(tempFolder);
+
+            System.out.println("ZIP鏂囦欢鍒涘缓瀹屾垚锛�");
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return "/word/zip/output.zip";
+    }
+
+    //鎵归噺涓婁紶
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int upAll(MultipartFile file) throws IOException {
+        File tempFile = null;
+        File unzipDir = null;
+        try {
+            tempFile = File.createTempFile(wordUrl, ".zip");
+            file.transferTo(tempFile);
+
+            unzipDir = new File("uploaded_files");
+            if (!unzipDir.exists()) {
+                unzipDir.mkdir();
+            }
+            unzip(tempFile, unzipDir);
+            // 澶勭悊瑙e帇鍚庣殑鏂囦欢
+            File[] files = unzipDir.listFiles();
+            if (files != null) {
+                for (File f : files) {
+                    // 鏍规嵁鏂囦欢鍚嶆煡璇d
+                    String name = f.getName();
+                    InsReport insReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery().like(InsReport::getCode, f.getName().replace(".docx", "")));
+                    if (ObjectUtils.isEmpty(insReport)) {
+                        throw new ErrorException("娌℃湁鎵惧埌 " + f.getName() + " 杩欎釜鏂囦欢瀵瑰簲鐨勬姤鍛婃暟鎹�");
+                    }
+                    String urlString;
+                    String pathName;
+                    try {
+                        String path = wordUrl;
+                        File realpath = new File(path);
+                        if (!realpath.exists()) {
+                            realpath.mkdirs();
+                        }
+                        pathName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyMMddHHmmss")) + "_" + f.getName();
+                        urlString = realpath + "/" + pathName;
+                        // 澶嶅埗鏂囦欢鍒版寚瀹氳矾寰�
+                        Files.copy(f.toPath(), new File(urlString).toPath(), StandardCopyOption.REPLACE_EXISTING);
+                        inReport("/word/" + pathName, insReport.getId());
+                    } catch (IOException e) {
+                        throw new ErrorException("鏂囦欢涓婁紶澶辫触");
+                    }
+                }
+            }
+        } catch (IOException e) {
+            throw new ErrorException("鏂囦欢澶勭悊澶辫触");
+        } finally {
+            if (tempFile != null && tempFile.exists()) {
+                tempFile.delete();
+            }
+            // 閫掑綊鍒犻櫎瑙e帇鐩綍鍙婂叾涓殑鏂囦欢
+            if (unzipDir.exists()) {
+                deleteDirectory(unzipDir); // 鍒犻櫎鏃х殑涓存椂鏂囦欢澶�
+            }
+        }
+        return 0;
+    }
+
+    //鏄惁闇�瑕佺敓鎴愭姤鍛�: 0涓嶉渶瑕�;1闇�瑕�
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int isReport(InsReportDto insReportDto) {
+        //鍏堝垽鏂璁㈠崟鏄惁鍙互鍘荤敓浜ф姤鍛�
+        Long count = insOrderStateMapper.selectCount(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, insReportDto.getId()).eq(InsOrderState::getInsState, 5));
+        if (count > 0) {
+            if (insReportDto.getState() == 1) {
+                List<InsReportDto1> insReportDto1s = insReportDto.getInsReportDto1s();
+                wordUtils.generateReport(insReportDto.getId(), insReportDto1s);
+            } else {
+                //缁撴潫璁㈠崟
+                InsOrder insOrder = new InsOrder();
+                insOrder.setId(insReportDto.getId());
+                insOrder.setState(4);
+                insOrderMapper.updateById(insOrder);
+            }
+        } else {
+            throw new ErrorException("璇ヨ鍗曡繕鏈粨鏉熻瘯楠�,鏃犳硶鐢熶骇鎶ュ憡!");
+        }
+        return 0;
+    }
+
+    //鏌ュ嚭璇ヨ鍗曚笅姣忎釜绔欑偣涓嬬殑妫�楠屾鏁�
+    @Override
+    public List<InsOrderState> getInsOrderStateCount(Integer id) {
+        List<InsOrderState> insOrderStates = insOrderStateMapper.getInsOrderStateCount(id);
+        return insOrderStates;
+    }
+
+
+    //瑙e帇鏂囦欢澶�
+    private void unzip(File zipFile, File destDir) throws IOException {
+        try (ZipFile zip = new ZipFile(zipFile)) {
+            Enumeration<? extends ZipEntry> entries = zip.entries();
+            while (entries.hasMoreElements()) {
+                ZipEntry entry = entries.nextElement();
+                File file = new File(destDir, entry.getName());
+                if (entry.isDirectory()) {
+                    file.mkdirs();
+                } else {
+                    file.getParentFile().mkdirs();
+                    try (InputStream in = zip.getInputStream(entry);
+                         OutputStream out = new FileOutputStream(file)) {
+                        byte[] buffer = new byte[1024];
+                        int len;
+                        while ((len = in.read(buffer)) > 0) {
+                            out.write(buffer, 0, len);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    // 鍘嬬缉鏂囦欢澶�
+    public static void zipDirectory(String sourceDirPath, String zipFilePath) throws IOException {
+        try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFilePath))) {
+            Path sourceDir = Paths.get(sourceDirPath);
+            Files.walk(sourceDir)
+                    .filter(path -> !Files.isDirectory(path))
+                    .forEach(path -> {
+                        ZipEntry zipEntry = new ZipEntry(sourceDir.relativize(path).toString());
+                        try {
+                            zipOut.putNextEntry(zipEntry);
+                            Files.copy(path, zipOut);
+                            zipOut.closeEntry();
+                        } catch (IOException e) {
+                            e.printStackTrace();
+                        }
+                    });
+        }
+    }
+
+    // 鍒犻櫎鏂囦欢澶瑰強鍏跺唴瀹�
+    public static void deleteDirectory(File directory) throws IOException {
+        if (directory.isDirectory()) {
+            File[] files = directory.listFiles();
+            if (files != null) {
+                for (File file : files) {
+                    deleteDirectory(file);
+                }
+            }
+        }
+        Files.delete(directory.toPath());
+    }
+
+    @Override
+    public void wordToPdf(String path, String sealUrl) {
         CompletableFuture.supplyAsync(() -> {
             try {
-                wordToPdf(path, path.replace(".docx", ".pdf"));
+                wordToPdf(path, path.replace(".docx", ".pdf"), sealUrl);
                 return null;
             } catch (Exception e) {
                 throw new ErrorException("杞崲澶辫触");
@@ -217,11 +485,23 @@
         });
     }
 
-    public String wordToPdf(String wordPath,String pdfPath) {
+    public String wordToPdf(String wordPath, String pdfPath, String sealUrl) {
         FileOutputStream os = null;
         try {
             //鍑瘉 涓嶇劧鍒囨崲鍚庢湁姘村嵃
 //            InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml");
+            /*String url;
+            try {
+                InputStream inputStream = this.getClass().getResourceAsStream("/lib/license.xml");
+                File file = File.createTempFile("temp", ".tmp");
+                OutputStream outputStream = new FileOutputStream(file);
+                IOUtils.copy(inputStream, outputStream);
+                url = file.getAbsolutePath();
+            } catch (FileNotFoundException e) {
+                throw new ErrorException("鎵句笉鍒版ā鏉挎枃浠�");
+            } catch (IOException e) {
+                throw new RuntimeException(e);
+            }*/
             InputStream is = new ClassPathResource("/lib/license.xml").getInputStream();
             License license = new License();
             license.setLicense(is);
@@ -230,11 +510,29 @@
                 return null;
             }
             //鐢熸垚涓�涓┖鐨凱DF鏂囦欢
-            File file = new File(pdfPath);
+            File file = new File(pdfPath.replace(".pdf", "-1.pdf"));
             os = new FileOutputStream(file);
             //瑕佽浆鎹㈢殑word鏂囦欢
             com.aspose.words.Document doc = new com.aspose.words.Document(wordPath);
+            TableCollection tables = doc.getFirstSection().getBody().getTables();
+            for (Table table : tables) {
+                RowCollection rows = table.getRows();
+                table.setAllowAutoFit(false);
+                for (Row row : rows) {
+                    CellCollection cells = row.getCells();
+                    for (Cell cell : cells) {
+                        CellFormat cellFormat = cell.getCellFormat();
+                        cellFormat.setFitText(false);  //璁剧疆鑷�傚簲鍏抽棴
+                        cellFormat.setWrapText(true);  // 璁剧疆鑷姩鎹㈣
+                    }
+                }
+            }
             doc.save(os, SaveFormat.PDF);
+
+            //娣诲姞楠戠紳绔�
+            stamperCheckMarkPDF(pdfPath.replace(".pdf", "-1.pdf"), pdfPath, imgUrl + "/" + sealUrl);
+
+
         } catch (Exception e) {
             e.printStackTrace();
         } finally {
@@ -248,8 +546,69 @@
         }
         return null;
     }
+
+    /**
+     * 鍒囧壊鍥剧墖
+     *
+     * @param Path 鍥剧墖璺緞
+     * @param n    鍒囧壊浠芥暟
+     */
+    public static com.itextpdf.text.Image[] slicingImages(String Path, int n) throws IOException, BadElementException {
+        com.itextpdf.text.Image[] nImage = new com.itextpdf.text.Image[n];
+        BufferedImage img = ImageIO.read(new File(Path));
+
+        int h = img.getHeight();
+        int w = img.getWidth();
+
+        int sw = w / n;
+        for (int i = 0; i < n; i++) {
+            BufferedImage subImg;
+            if (i == n - 1) {//鏈�鍚庡墿浣欓儴鍒�
+                subImg = img.getSubimage(i * sw, 0, w - i * sw, h);
+            } else {//鍓峮-1鍧楀潎鍖�鍒�
+                subImg = img.getSubimage(i * sw, 0, sw, h);
+            }
+            ByteArrayOutputStream out = new ByteArrayOutputStream();
+            ImageIO.write(subImg, Path.substring(Path.lastIndexOf('.') + 1), out);
+            nImage[i] = com.itextpdf.text.Image.getInstance(out.toByteArray());
+
+        }
+        return nImage;
+    }
+
+    /**
+     * 鐩栭獞缂濈珷
+     *
+     * @param infilePath  鍘烶DF璺緞
+     * @param outFilePath 杈撳嚭PDF璺緞
+     */
+    public static void stamperCheckMarkPDF(String infilePath, String outFilePath, String picPath) throws IOException, DocumentException {
+        PdfReader reader = new PdfReader(infilePath);//閫夋嫨闇�瑕佸嵃绔犵殑pdf
+        PdfStamper stamp = new PdfStamper(reader, new FileOutputStream(outFilePath));//鍔犲畬鍗扮珷鍚庣殑pdf
+
+
+        com.itextpdf.text.Rectangle pageSize = reader.getPageSize(1);//鑾峰緱绗竴椤�
+        float height = pageSize.getHeight();
+        float width = pageSize.getWidth();
+
+        int nums = reader.getNumberOfPages();
+        com.itextpdf.text.Image[] nImage = slicingImages(picPath, nums);//鐢熸垚楠戠紳绔犲垏鍓插浘鐗�
+
+        for (int n = 1; n <= nums; n++) {
+            PdfContentByte over = stamp.getOverContent(n);//璁剧疆鍦ㄧ鍑犻〉鎵撳嵃鍗扮珷
+            com.itextpdf.text.Image img = nImage[n - 1];//閫夋嫨鍥剧墖
+            float newHeight = 100f;
+            float newWidth = img.getWidth() / (img.getHeight() / 100);
+            img.scaleAbsolute(newWidth, newHeight);//鎺у埗鍥剧墖澶у皬
+            img.setAbsolutePosition(width - newWidth, height / 2 - newHeight / 2);//鎺у埗鍥剧墖浣嶇疆
+            over.addImage(img);
+        }
+        stamp.close();
+    }
 }
 
 
 
 
+
+

--
Gitblit v1.9.3