Browse Source

修改数据

hongchuangyanfa 2 years ago
parent
commit
4ebe86f9ee

+ 6 - 14
blade-service/blade-manager/pom.xml

@@ -86,19 +86,6 @@
             <version>5.3.1</version>
         </dependency>
 
-        <dependency>
-            <groupId>com.itextpdf</groupId>
-            <artifactId>html2pdf</artifactId>
-            <version>2.1.4</version>
-        </dependency>
-
-        <dependency>
-            <groupId>com.itextpdf</groupId>
-            <artifactId>itextpdf</artifactId>
-            <version>5.5.13</version>
-            <scope>compile</scope>
-        </dependency>
-
         <dependency>
             <groupId>org.jsoup</groupId>
             <artifactId>jsoup</artifactId>
@@ -157,7 +144,12 @@
             <groupId>me.zhyd.oauth</groupId>
             <artifactId>JustAuth</artifactId>
         </dependency>
-
+        <dependency>
+            <groupId>com.aspose</groupId>
+            <artifactId>aspose-cells</artifactId>
+            <version>20.4</version>
+            <scope>compile</scope>
+        </dependency>
     </dependencies>
 
 </project>

+ 237 - 27
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/ExcelTabController.java

@@ -8,11 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
-import com.itextpdf.html2pdf.ConverterProperties;
-import com.itextpdf.html2pdf.resolver.font.DefaultFontProvider;
-import com.itextpdf.io.font.FontProgram;
-import com.itextpdf.io.font.FontProgramFactory;
-import com.itextpdf.layout.font.FontProvider;
+
 import com.spire.xls.*;
 import com.spire.xls.core.spreadsheet.HTMLOptions;
 import io.swagger.annotations.*;
@@ -1306,8 +1302,14 @@ public class ExcelTabController extends BladeController {
 
 
         String tabName = wbsTreeContract.getInitTableName();
+
+        // 字段查询 并去掉公式字段
+
+        String colkeys = "SELECT GROUP_CONCAT(e_key) as colkeys from m_wbs_tree a ,m_wbs_form_element b WHERE a.init_table_name = '"+tabName+"' and a.id=b.f_id and b.id not in(SELECT element_id from m_formula c where c.is_deleted=0) ";
+        Map<String, Object> stringObjectMap = jdbcTemplate.queryForMap(colkeys);
+        colkeys = stringObjectMap.get("colkeys")+"";
         // 复制表数据
-        String querySql = "select * from " + tabName + " where p_key_id=" + pkeyId;
+        String querySql = "select "+colkeys+" from " + tabName + " where p_key_id=" + pkeyId;
         Map<String, Object> dataMap2 = jdbcTemplate.queryForMap(querySql);
 
         dataMap2.remove("p_key_id");
@@ -1459,26 +1461,6 @@ public class ExcelTabController extends BladeController {
         return R.status(this.excelTabService.removeBussTabInfoById(pkeyid));
     }
 
-    /**
-     * 设置BaseFont
-     *
-     * @param fontPath 字体路径
-     * @return
-     */
-    private static ConverterProperties creatBaseFont(String fontPath) {
-        ConverterProperties properties = new ConverterProperties();
-        FontProvider fontProvider = new DefaultFontProvider();
-        FontProgram fontProgram;
-        try {
-            fontProgram = FontProgramFactory.createFont(fontPath);
-            fontProvider.addFont(fontProgram);
-            properties.setFontProvider(fontProvider);
-        } catch (IOException e) {
-            System.out.println("creat base font erro");
-        }
-        return properties;
-    }
-
 
     @PostMapping("/save_buss_data")
     @ApiOperationSupport(order = 13)
@@ -2054,6 +2036,206 @@ public class ExcelTabController extends BladeController {
         return R.data(300, null, "未找到对应的业务数据");
     }
 
+    /**
+     * 预览首件PDF
+     */
+    @GetMapping("/get-first-pdf-info")
+    @ApiOperationSupport(order = 28)
+    @ApiOperation(value = "获取首件填报记录")
+    @ApiImplicitParam(name = "firstId", value = "首件列表ID")
+    public R<String> getFirstPdfInfo(String firstId) {
+        if (StringUtils.isNotEmpty(firstId)) {
+            //PDF路径集合
+            List<String> pdfUrls = new ArrayList<>();
+
+            //获取配置的路径
+            String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+            //获取数据
+            JSONObject firstJson = this.informationQueryClient.queryFirstBusinessDataByFirstId(firstId);
+            if (firstJson != null) {
+                if (StringUtils.isNotEmpty(firstJson.getString("eVisaPdfUrl")) || StringUtils.isNotEmpty(firstJson.getString("pdfUrl"))) {
+                    pdfUrls.add(StringUtils.isNotEmpty(firstJson.getString("eVisaPdfUrl")) ? firstJson.getString("eVisaPdfUrl") : firstJson.getString("pdfUrl"));
+                } else {
+                    //没有生成拼接的记录,生成
+                    //获取html
+                    WbsTreeContract tableNode = this.wbsTreeContractService.getOne(Wrappers.<WbsTreeContract>lambdaQuery().eq(WbsTreeContract::getPKeyId, firstJson.getString("tableId")));
+
+                    if (tableNode == null) {
+                        return R.fail("该数据下无此节点!");
+                    }
+
+                    if (StringUtils.isEmpty(tableNode.getHtmlUrl())) {
+                        return R.fail("请关联清表!");
+                    }
+
+                    // 获取清表信息
+                    ExcelTab excelTab = excelTabService.getById(tableNode.getExcelId());
+                    if (excelTab == null) {
+                        return R.fail("失败");
+                    }
+
+                    List<Map<String, Object>> businessDataMapList = this.getFirstBusinessData(firstId).getData();
+
+                    try {
+                        //处理数据
+                        for (Map<String, Object> dataMap : businessDataMapList) {
+                            // 获取excel流 和 html流
+                            Workbook wb = new Workbook();
+                            wb.loadFromMHtml(CommonUtil.getOSSInputStream(excelTab.getFileUrl()));
+                            //获取工作表
+                            Worksheet sheet = wb.getWorksheets().get(0);
+
+                            // 数据不为空 &&
+                            if (StringUtils.isNotEmpty(tableNode.getHtmlUrl())) {
+                                File htmlFile = ResourceUtil.getFile(tableNode.getHtmlUrl());
+                                if (htmlFile.exists()) {
+                                    String htmlString = IoUtil.readToString(new FileInputStream(htmlFile));
+                                    Document doc = Jsoup.parse(htmlString);
+                                    Element table = doc.select("table").first();
+                                    Elements trs = table.select("tr");
+
+                                    if (ObjectUtil.isNotEmpty(dataMap)) {
+                                        for (String val : dataMap.keySet()) {
+                                            if (val.indexOf("__") >= 0) {
+                                                String DataVal[] = val.split("__");
+                                                String[] xy = DataVal[1].split("_");
+                                                Element data = trs.get(Integer.parseInt(xy[0])).select("td").get(Integer.parseInt(xy[1]));
+
+                                                if (data.html().indexOf("x1") >= 0 && data.html().indexOf("y1") >= 0) {
+                                                    int x1, y1;
+
+                                                    if (data.html().indexOf("el-tooltip") >= 0) {
+                                                        x1 = Integer.parseInt(data.children().get(0).children().get(0).attr("x1"));
+                                                        y1 = Integer.parseInt(data.children().get(0).children().get(0).attr("y1"));
+                                                    } else {
+                                                        x1 = Integer.parseInt(data.children().get(0).attr("x1"));
+                                                        y1 = Integer.parseInt(data.children().get(0).attr("y1"));
+                                                    }
+                                                    if (x1 == 0) {
+                                                        x1 = 1;
+                                                    }
+                                                    String myData = dataMap.get(val) + "";
+                                                    if (myData.indexOf("T") >= 0 && myData.indexOf("-") >= 0) {
+                                                        if (myData.indexOf(",") >= 0 && myData.indexOf("]") >= 0) {
+                                                            myData = myData.replace("[", "").replace("]", "");
+                                                            String[] dataVal = myData.split(",");
+                                                            String Start_dataStr[] = dataVal[0].split("T")[0].split("-");
+                                                            String StartDate = StringUtil.format("{}年{}月{}日", new Object[]{Start_dataStr[0], Start_dataStr[1], Integer.parseInt(Start_dataStr[2]) + 1});
+
+                                                            String end_dataStr[] = dataVal[1].split("T")[0].split("-");
+                                                            String endDate = StringUtil.format("{}年{}月{}日", new Object[]{end_dataStr[0], end_dataStr[1], Integer.parseInt(end_dataStr[2]) + 1});
+
+                                                            if (StartDate.equals(endDate)) {
+                                                                myData = StartDate;
+                                                            } else {
+                                                                myData = StartDate + "-" + endDate;
+                                                            }
+                                                        } else {
+                                                            String dataStr[] = myData.split("T")[0].split("-");
+                                                            myData = StringUtil.format("{}年{}月{}日", new Object[]{dataStr[0], dataStr[1], Integer.parseInt(dataStr[2]) + 1});
+                                                        }
+                                                    }
+
+                                                    if (myData.indexOf("https") >= 0 && myData.indexOf("aliyuncs") >= 0) {
+                                                        Element element = trs.get(y1).select("td").get(x1);
+                                                        String styles[] = element.attr("style").split(";");
+                                                        int Height = 0;
+                                                        for (String sty : styles) {
+                                                            if (sty.indexOf("height:") >= 0) {
+                                                                Height = Integer.parseInt(sty.replace("height:", "").replace("px", ""));
+                                                            }
+                                                        }
+
+                                                        BufferedImage image = ImageIO.read(CommonUtil.getOSSInputStream(myData));
+                                                        ExcelPicture pic = sheet.getPictures().add(y1, x1, image);
+                                                        pic.setHeight(Height);
+                                                        sheet.getCellRange(y1, x1).getStyle().setShrinkToFit(true);
+
+                                                    } else {
+                                                        final CellRange cellRange = sheet.getCellRange(y1, x1);
+                                                        cellRange.setText(myData);
+                                                    }
+                                                }
+                                            }
+                                        }
+                                    }
+
+                                    // 组装电签设置
+                                    QueryWrapper<TextdictInfo> queryWrapper = new QueryWrapper<>();
+                                    queryWrapper.eq("type", 2);
+                                    queryWrapper.eq("tab_id", tableNode.getPKeyId());
+
+                                    final List<TextdictInfo> textdictInfos = textdictInfoService.getBaseMapper().selectList(queryWrapper);
+                                    if (textdictInfos != null && !textdictInfos.isEmpty()) {
+                                        textdictInfos.forEach(e -> {
+                                            String key = e.getColKey();
+                                            String keys[] = key.split("__");
+                                            String[] trtd = keys[1].split("_");
+                                            Element data = trs.get(Integer.parseInt(trtd[0])).select("td").get(Integer.parseInt(trtd[1]));
+                                            int x1 = Integer.parseInt(data.children().get(0).attr("x1"));
+                                            if (x1 == 0) {
+                                                x1 = 1;
+                                            }
+                                            int y1 = Integer.parseInt(data.children().get(0).attr("y1"));
+
+                                            final CellRange cellRange = sheet.getCellRange(y1, x1);
+
+                                            cellRange.setText(e.getId() + "");
+                                            cellRange.getCellStyle().getFont().setColor(Color.white);
+
+                                        });
+                                    }
+                                }
+                            }
+
+                            Long fileName = SnowFlakeUtil.getId();
+                            String onePdfPath = file_path + "/pdf//" + fileName + ".pdf";
+
+                            sheet.saveToPdf(onePdfPath);
+
+                            BladeFile bladeFile = this.newIOSSClient.uploadFile(fileName + ".pdf", onePdfPath);
+
+                            pdfUrls.add(bladeFile.getLink());
+
+                            wb.dispose();
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+
+                if (pdfUrls.size() > 0) {
+                    try {
+                        //关联的数据
+                        if (StringUtils.isNotEmpty(firstJson.getString("linkMergePdfUrl"))) {
+                            pdfUrls.add(firstJson.getString("linkMergePdfUrl"));
+                        }
+                        //总结报告,暂时无
+
+                        //上传
+                        String mergePdfPath = file_path + "/pdf//" + firstId + ".pdf";
+                        File oldMergePdf = ResourceUtil.getFile(mergePdfPath);
+                        if (oldMergePdf.exists()) {
+                            oldMergePdf.delete();
+                        }
+                        //合并
+                        FileUtils.mergePdfPublicMethods(pdfUrls, mergePdfPath);
+                        //上传
+                        BladeFile mergeFile = this.newIOSSClient.uploadFile(firstId + '-' + new Date().getTime() + ".pdf", mergePdfPath);
+
+                        //返回
+                        return R.data(mergeFile.getLink());
+
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }
+        }
+
+        return R.data(300, null, "未找到数据");
+    }
+
     @PostMapping("/save_log_first_buss_data")
     @ApiOperationSupport(order = 29)
     @ApiOperation(value = "填报页面数据保存", notes = "填报页面数据保存")
@@ -2118,16 +2300,44 @@ public class ExcelTabController extends BladeController {
 
     public R getFirstExcelHtml() throws Exception {
         String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
-        String sql ="SELECT n.p_key_id,excelId from (SELECT p_key_id,(SELECT id from m_excel_tab x where x.alias like '%1542045893564796930%' and x.name =m.full_name) as excelId  from m_wbs_tree_private m where m.project_id = '1578599210897772545' and m.type='2'  and m.p_key_id!='1578599432939634723' ) n where excelId is not null ";
+        String sql ="SELECT n.p_key_id,excelId from (SELECT p_key_id,(SELECT id from m_excel_tab x where x.alias like '%1542045893564796930%' and parent_id='1559347745306148865' and is_deleted=0 and x.name =m.full_name) as excelId  from m_wbs_tree_private m where m.project_id = '1578599210897772545' and m.type='2'   ) n where excelId is not null and p_key_id!='1578599433161932807' ";
         List<Map<String, Object>> dataInof = jdbcTemplate.queryForList(sql);
         System.out.println(dataInof.size());
         for (int i = 0; i < dataInof.size(); i++) {
             String p_key_id = dataInof.get(i).get("p_key_id") + "";
             Long excelId = Long.parseLong(dataInof.get(i).get("excelId") + "");
+            System.out.println(p_key_id+"__"+excelId);
             this.saveLinkeTab(excelId, Long.valueOf(p_key_id));
+           // this.saveLinkeTab(, excelId);
             System.out.println(i);
         }
 
         return R.data("");
     }
+
+    /**
+     * 表单填写 图片添加 并压缩
+     * @param file
+     * @return
+     */
+    @SneakyThrows
+    @PostMapping("/add-buss-imginfo")
+    @ApiOperationSupport(order = 32)
+    @ApiOperation(value = "表单填写图片上传", notes = "表单填写图片上传")
+    public R addBussFile(@RequestParam MultipartFile file) {
+        String file_path = ParamCache.getValue(CommonConstant.SYS_LOCAL_URL);
+        BladeFile bladeFile=new BladeFile();
+        if(file.getSize()>=1024){
+            String filecode = SnowFlakeUtil.getId() + "";
+            String imgUrl = file_path+"/pdf/"+  filecode+".jpg";
+            FileUtils.CompressImage(imgUrl,file.getInputStream());
+            bladeFile= this.newIOSSClient.uploadFile(file.getOriginalFilename(),imgUrl);
+            File imgFile = ResourceUtil.getFile(imgUrl);
+            imgFile.delete();
+        }else{
+            bladeFile = this.newIOSSClient.uploadFileByInputStream(file);
+        }
+        return R.data(bladeFile);
+    }
+
 }

+ 3 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/controller/TextdictInfoController.java

@@ -231,13 +231,13 @@ public class TextdictInfoController extends BladeController {
             element.empty().append(selectText);
         } else if (textdictInfo.getTextId().equals("radio")) { // 单选按钮
 
-            String radioText = "<template v-model=" + vmode + " keyname=" + keyname + " weighing=" + weighing + " placeholder=" + placeholder + " trIndex=" + trindex + " tdIndex=" + tdindex + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + ">";
+            String radioText = "<el-radio-group  v-model=" + vmode + " keyname=" + keyname + " weighing=" + weighing + " placeholder=" + placeholder + " trIndex=" + trindex + " tdIndex=" + tdindex + "  x1=" + x1 + " x2=" + x2 + " y1=" + y1 + " y2=" + y2 + ">";
             List<TextdictInfo_vo> optionList = textdictInfo.getTextInfo();
             if (optionList != null && optionList.size() >= 1) {
                 for (int i = 0; i < optionList.size(); i++)
-                    radioText += " <el-radio v-model=" + vmode + "  label=" + i + ">" + optionList.get(i).getDictValue() + "</el-radio>";
+                    radioText += " <el-radio label=" + i + ">" + optionList.get(i).getDictValue() + "</el-radio>";
             }
-            radioText += "</template>";
+            radioText += "</el-radio-group >";
             element.empty().append(radioText);
         } else if (textdictInfo.getTextId().equals("checkbox")) { // 多选框
             List<TextdictInfo_vo> optionList = textdictInfo.getTextInfo();

+ 13 - 13
blade-service/blade-manager/src/main/java/org/springblade/manager/service/impl/ExcelTabServiceImpl.java

@@ -25,10 +25,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.mixsmart.utils.ListUtils;
-import com.spire.xls.CellRange;
-import com.spire.xls.ExcelPicture;
-import com.spire.xls.Workbook;
-import com.spire.xls.Worksheet;
+import com.spire.xls.*;
 import lombok.AllArgsConstructor;
 import org.apache.commons.lang.StringUtils;
 import org.jsoup.Jsoup;
@@ -652,6 +649,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         }
 
         String pdfPath = file_path + "/pdf//" + pkeyId + ".pdf";
+        String excelPath = file_path + "/pdf//" + pkeyId + ".xlsx";
         File tabpdf = ResourceUtil.getFile(pdfPath);
         if (tabpdf.exists()) {
             tabpdf.delete();
@@ -717,9 +715,6 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                 }
                                 String myData = DataInfo.get(val) + "";
 
-                                if(myData.equals("30.72")){
-                                    System.out.println("");
-                                }
 
                                 if (myData.indexOf("T") >= 0 && myData.indexOf("-") >= 0) {
                                     if (myData.indexOf(",") >= 0 && myData.indexOf("]") >= 0) {
@@ -754,7 +749,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                     if(rowspan==0){
                                         String dataInfo = trs.get(y1).attr("height");
                                         if(StringUtils.isEmpty(dataInfo)){
-                                             Element firstTd = trs.get(y1).children().get(0);
+                                             Element firstTd = trs.get(y1-1).children().get(0);
                                             String heg[] =firstTd.attr("style").split(";");
                                             for (String str:heg){
                                                 if(str.indexOf("height:")>=0){
@@ -783,13 +778,19 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
                                     }
 
                                     ExcelPicture pic = sheet.getPictures().add(y1, x1, image);
+                                    pic.setAutoSize(true);
                                     pic.setWidth(picWidth - 10);
+
+                                    System.out.println(sheet.get(y1,x1).getRowHeight());
+                                    System.out.println(sheet.get(y1,x1).getRows());
                                     pic.setHeight(picHeight);
                                     pic.setLeft(5);
                                 } else {
                                     CellRange cellRange = sheet.getCellRange(y1, x1);
-                                    System.out.println(cellRange.getText());
+                                    cellRange.getCellStyle().getExcelFont().setFontName("EUDC");
                                     cellRange.setText(myData);
+                                    System.out.println(cellRange.getStyle().getFont().getFontName());;
+                                    System.out.println("后"+cellRange.getText());
                                 }
                             }
                         }
@@ -823,10 +824,8 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
             }
         }
 
-
-
-        sheet.saveToPdf(pdfPath);
-
+        wb.saveToFile(excelPath, ExcelVersion.Version2010);
+        FileUtils.excelToPdf(excelPath,pdfPath);
         BladeFile bladeFile = newIOSSClient.uploadFile(pkeyId + ".pdf", pdfPath);
         //
         TableFile tableFile1 = tableFileService.getBaseMapper().selectOne(Wrappers.<TableFile>query().lambda()
@@ -858,6 +857,7 @@ public class ExcelTabServiceImpl extends BaseServiceImpl<ExcelTabMapper, ExcelTa
         File tabpdf2 = ResourceUtil.getFile(pdfPath2);
         if (tabpdf2.exists()) {
             tabpdf2.delete();
+
         }
         FileUtils.mergePdfPublicMethods(dataListPdf, pdfPath2);
 

+ 98 - 4
blade-service/blade-manager/src/main/java/org/springblade/manager/utils/FileUtils.java

@@ -1,22 +1,26 @@
 package org.springblade.manager.utils;
 
+import com.aspose.cells.SaveFormat;
 import com.itextpdf.text.Document;
 import com.itextpdf.text.pdf.PdfCopy;
 import com.itextpdf.text.pdf.PdfReader;
+import com.sun.image.codec.jpeg.JPEGCodec;
+import com.sun.image.codec.jpeg.JPEGImageEncoder;
 import org.apache.commons.lang.StringUtils;
 import org.apache.poi.ss.usermodel.ClientAnchor;
 import org.apache.poi.ss.usermodel.Sheet;
+import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.poi.ss.util.CellRangeAddress;
 import org.apache.poi.util.Units;
 import org.springblade.common.utils.CommonUtil;
 import org.springblade.common.vo.DataVO;
 import org.springblade.core.tool.utils.IoUtil;
+import org.springblade.core.tool.utils.ResourceUtil;
 
+import javax.imageio.ImageIO;
 import javax.servlet.http.HttpServletResponse;
-import java.io.BufferedOutputStream;
-import java.io.DataOutputStream;
-import java.io.FileOutputStream;
-import java.io.InputStream;
+import java.awt.image.BufferedImage;
+import java.io.*;
 import java.net.URLEncoder;
 import java.util.Arrays;
 import java.util.List;
@@ -191,4 +195,94 @@ public class FileUtils {
         }
     }
 
+    /**
+     * excel 转pdf
+     * @param exUrl
+     * @param pdfUrl
+     */
+    public static void excelToPdf(String exUrl,String pdfUrl){
+
+        org.apache.poi.ss.usermodel.Workbook ss = null;
+        ByteArrayInputStream byteArrayInputStream = null;
+        InputStream pdfInput = null;
+        ByteArrayOutputStream outReport = null, bos = null;
+        try{
+            File file1 = ResourceUtil.getFile(exUrl);
+            InputStream inputStream = new FileInputStream(file1);
+            ss = WorkbookFactory.create(inputStream);
+            for(int i = 0, l = ss.getNumberOfSheets(); i < l; i ++){
+                Sheet sheet = ss.getSheetAt(i);
+                //去掉表格虚线
+                sheet.setPrintGridlines(false);
+                //设置 整个工作表为一页
+                sheet.setFitToPage(true);
+            }
+            outReport = new ByteArrayOutputStream();
+            ss.write(outReport);
+            byteArrayInputStream = new ByteArrayInputStream(outReport.toByteArray());
+            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook(byteArrayInputStream);
+            File pdfFile = new File(pdfUrl);
+            if(!pdfFile.exists()){
+                pdfFile.mkdir();
+            }
+            wb.save(pdfUrl, SaveFormat.PDF);
+
+        }catch (Exception e){
+            e.printStackTrace();
+        } finally {
+            if(bos != null){
+                IoUtil.closeQuietly(bos);
+            }
+            if(outReport != null){
+                IoUtil.closeQuietly(outReport);
+            }
+            if(pdfInput != null){
+                IoUtil.closeQuietly(pdfInput);
+            }
+            if(byteArrayInputStream != null){
+                IoUtil.closeQuietly(byteArrayInputStream);
+            }
+            if(ss != null){
+                IoUtil.closeQuietly(ss);
+            }
+        }
+    }
+
+    /**
+     * 图片压缩
+     * @param imgUrl
+     */
+    public static void CompressImage(String imgUrl,InputStream img){
+        try {
+            //图片所在路径
+            BufferedImage templateImage = ImageIO.read(img);
+            //原始图片的长度和宽度
+            int height = templateImage.getHeight();
+            int width = templateImage.getWidth();
+
+            //通过比例压缩
+            float scale = 0.5f;
+
+            //通过固定长度压缩
+            /*int doWithHeight = 100;
+            int dowithWidth = 300;*/
+
+            //压缩之后的长度和宽度
+            int doWithHeight = (int) (scale * height);
+            int dowithWidth = (int) (scale * width);
+
+            BufferedImage finalImage = new BufferedImage(dowithWidth, doWithHeight, BufferedImage.TYPE_INT_RGB);
+
+            finalImage.getGraphics().drawImage(templateImage.getScaledInstance(dowithWidth, doWithHeight, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
+
+
+            //图片输出路径,以及图片名
+            FileOutputStream  fileOutputStream = new FileOutputStream(imgUrl);
+            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fileOutputStream);
+            encoder.encode(finalImage);
+            fileOutputStream.close();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
 }