Procházet zdrojové kódy

关于权属审核导出引入类

chenendian před 1 měsícem
rodič
revize
36c83dda69

+ 1 - 0
.gitignore

@@ -83,3 +83,4 @@ nbdist/
 /siwei-modules/siwei-apply/lib/spire.doc.free-5.2.0.jar
 /.vscode/settings.json
 /.workbuddy/memory/*
+/siwei-modules/siwei-apply/lib/aspose-words-18.6-jdk16-crack.jar

+ 9 - 0
siwei-modules/siwei-apply/pom.xml

@@ -205,6 +205,15 @@
             <systemPath>${project.basedir}/lib/json-simple-1.1.1.jar</systemPath>
         </dependency>
 
+
+        <dependency>
+            <groupId>aspose-words-18.6-jdk16-crack</groupId>
+            <artifactId>aspose-words-18.6-jdk16-crack</artifactId>
+            <version>15.8.0</version>
+            <scope>system</scope>
+            <systemPath>${project.basedir}/lib/aspose-words-18.6-jdk16-crack.jar</systemPath>
+        </dependency>
+
         <!-- https://mvnrepository.com/artifact/net.sf.ucanaccess/ucanaccess -->
         <dependency>
             <groupId>net.sf.ucanaccess</groupId>

+ 47 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/domain/vo/WktsVo.java

@@ -0,0 +1,47 @@
+package com.siwei.apply.domain.vo;
+
+
+import lombok.Data;
+
+import javax.validation.constraints.NotNull;
+import java.util.ArrayList;
+import java.util.List;
+
+@Data
+public class WktsVo {
+    @NotNull
+    List<WktInfo> wktInfos = new ArrayList<>();
+
+
+    @Data
+    public static class WktInfo {
+        private String wkt;
+        private String borderColor = "#ff0000";
+        private float borderOpacity = 1;
+        //图例名称
+        private String legendText = "";
+        //图例是否显示
+        private boolean legendDisplay = false;
+        private String legendColor = "";
+        private Float legendColorOpacity;
+
+        private String fillColor = "#ffffff";
+        private float fillOpacity = 0.3F;
+
+        public String getLegendText() {
+            return legendText;
+        }
+
+        public void setLegendText(String legendText) {
+            this.legendText = legendText;
+        }
+
+        public boolean getLegendDisplay() {
+            return legendDisplay;
+        }
+
+        public void setLegendDisplay(boolean legendDisplay) {
+            this.legendDisplay = legendDisplay;
+        }
+    }
+}

+ 8 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/IImageService.java

@@ -0,0 +1,8 @@
+package com.siwei.apply.service;
+
+
+import com.siwei.apply.domain.vo.WktsVo;
+
+public interface IImageService {
+    String getSensingImage(WktsVo wktsVo) throws Exception;
+}

+ 312 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/DecisionTaskServiceImpl.java

@@ -1,19 +1,33 @@
 package com.siwei.apply.service.impl;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.siwei.apply.domain.DecisionTask;
 import com.siwei.apply.domain.vo.*;
 import com.siwei.apply.enums.DecisionType;
 import com.siwei.apply.mapper.DecisionTaskMapper;
 import com.siwei.apply.service.DecisionTaskService;
+import com.siwei.apply.service.IImageService;
+import com.siwei.apply.utils.NpoiHelper;
 import com.siwei.common.core.exception.ServiceException;
+import com.siwei.common.core.utils.DateUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.util.Units;
+import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -23,6 +37,9 @@ public class DecisionTaskServiceImpl implements DecisionTaskService {
     @Autowired
     private DecisionTaskMapper decisionTaskMapper;
 
+    @Resource
+    private IImageService imageService;
+
     @Override
     public String add(DecisionTaskVo decisionTaskVo) {
         DecisionTask decisionTask = new DecisionTask();
@@ -239,6 +256,301 @@ public class DecisionTaskServiceImpl implements DecisionTaskService {
 
 
 
+    private void createReport(Map gdbhJgMap, String reportPath) throws Exception {
+        Map d_xmxx_0 = (Map) gdbhJgMap.get("xmxx");
+        String bsm = (String) d_xmxx_0.get("bsm");
+        String xmmc = (String) d_xmxx_0.get("xmmc");
+        Integer sumNumber = (Integer) d_xmxx_0.get("sumNumber");
+        Double xzmj = (Double) d_xmxx_0.get("xzmj");
+
+        XWPFDocument document = null;
+        OutputStream outputStream = null;// 把doc输出到输出流
+        try {
+//            RequestResult res_0 = applyService.QueryGdbhJgGeom(bsm);
+//            if (res_0.isError()) {
+//                throw new Exception(String.valueOf(res_0.get(RequestResult.MSG_TAG)));
+//            }
+//            Map res_1 = (Map) res_0.get(RequestResult.DATA_TAG);
+            String ewkt = (String) d_xmxx_0.get("geom");
+
+            document = new XWPFDocument();
+
+            int pos = 0;
+            // 0、文本标题
+            NpoiHelper.title(document, "耕地保护分析报告", pos++);
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
+
+            // 1、项目选址信息
+            NpoiHelper.catalog(document, "一、耕地保护分析信息", pos++);
+            List<String> listTemp = new ArrayList<>();
+            listTemp.add("\t项目名称:" + xmmc);
+            listTemp.add("\t图斑个数:" + sumNumber + "个");
+            listTemp.add("\t图斑面积:" + xzmj + "㎡");
+            listTemp.add("\t分析时间:" + DateUtils.getTime());
+            listTemp.add("\t分析因子:");
+            NpoiHelper.content(document, listTemp, pos++);
+            //因子
+            factorWrite(document, pos++, gdbhJgMap);
+            NpoiHelper.content(document, "分析范围", pos++);
+
+            WktsVo wktsVo = new WktsVo();
+            List<WktsVo.WktInfo> wktInfos = new ArrayList<>();
+            WktsVo.WktInfo wktInfoData = new WktsVo.WktInfo();
+            wktInfoData.setWkt(ewkt);
+            wktInfos.add(wktInfoData);
+            wktsVo.setWktInfos(wktInfos);
+
+            ObjectMapper objectMapper = new ObjectMapper();
+            String jsonString = objectMapper.writeValueAsString(wktsVo);
+            System.out.println("JSON输出: " + jsonString);
+
+            //RequestResult requestResult = spatialService.getImage(wktsVo);
+            Map<String, String> imageMap =  this.getImage(wktsVo);
+            if (imageMap !=null && imageMap.get("path")!=null) {
+                //Map<String, String> map = (Map<String, String>) requestResult.get("data");
+                String path = imageMap.get("path");
+                InputStream is = new FileInputStream(path);
+                BufferedImage bufferedImage = ImageIO.read(new File(path));
+                int originalWidth = bufferedImage.getWidth();
+                int originalHeight = bufferedImage.getHeight();
+                int useWidth = 400; // Set the desired width
+                int useHeight = useWidth * originalHeight / originalWidth;
+                XWPFRun run = document.createParagraph().createRun();
+                run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
+                pos++;
+            }
+
+            //结果
+            NpoiHelper.catalog(document, "二、耕地保护分析结果", pos++);
+            NpoiHelper.content(document, "\t按照耕地保护选址范围和分析模型,经对所选范围内的所有模型进行分析,分析结果如下:", pos++);
+            jiefuo(document, pos, gdbhJgMap, bsm, ewkt);
+            File fileDoc = new File(reportPath);
+            if (fileDoc.exists()) {
+                FileUtils.forceDelete(fileDoc);
+            }
+            // word文件输出流
+            outputStream = new FileOutputStream(reportPath);
+            document.write(outputStream);
+        } catch (Exception e) {
+            e.printStackTrace();
+            // 插入任务日志
+            // TODO 插入任务日志
+            //iLogService.saveLog(bsm, "耕地保护分析", "生成耕地保护分析报告错误:" + e.getMessage(), "error");
+            throw e;
+        } finally {
+            if (document != null) {
+                try {
+                    document.close();
+                } catch (Exception ex) {
+                    System.out.println(ex.toString());
+                }
+            }
+            if (outputStream != null) {
+                try {
+                    outputStream.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+    }
+
+    //因子信息配置
+    private void factorWrite(XWPFDocument document, int pos, Map jdList) {
+        List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
+
+        NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
+        tableTitle.setKey("YXYZMCI");
+        tableTitle.setName("分析模型");
+        tableTitle.setWidth(1880);
+        tabYzTitles.add(tableTitle);
+
+        tableTitle = new NpoiHelper.TableTitle();
+        tableTitle.setKey("YXYZMCⅡ");
+        tableTitle.setName("数据名称");
+        tableTitle.setWidth(1880);
+        tabYzTitles.add(tableTitle);
+        List<Map<String, Object>> dataTablelist = getScxList(jdList);
+        NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "分析模型", pos);
+    }
+
+    private List<Map<String, Object>> getScxList(Map factorMap) {
+        List<Map<String, Object>> retList = new ArrayList<>();
+        List<Map> jdList = (List<Map>) factorMap.get("yzjg");
+        for (Map mapData : jdList) {
+            String scxname = (String) mapData.get("mx_bsmmc");
+            List<Map> mx_data = (List<Map>) mapData.get("mx_data");
+            for (Map mapMxData : mx_data) {
+                String bsmmc = (String) mapMxData.get("bsmmc");
+                Map<String, Object> factorMap00 = new HashMap<>();
+                factorMap00.put("YXYZMCI", scxname);
+                factorMap00.put("YXYZMCⅡ", bsmmc);
+                retList.add(factorMap00);
+            }
+        }
+        return retList;
+    }
+    private int jiefuo(XWPFDocument document, int pos, Map jgMap, String rwbsm, String ewkt) throws Exception {
+        if (Objects.isNull(jgMap)) {
+            return pos;
+        }
+
+//        XWPFParagraph pageBreakParagraph2 = document.createParagraph();
+//        XWPFRun pageBreakRun2 = pageBreakParagraph2.createRun();
+//        pageBreakRun2.addBreak(BreakType.PAGE);
+
+        Map sandiao = (Map) jgMap.get("sandiao");
+        String v_mx_bsmmc_0 = (String) sandiao.get("mx_bsmmc");
+        NpoiHelper.content(document, v_mx_bsmmc_0 + "; 分析结果如下:", pos++, ParagraphAlignment.CENTER);
+
+        List<Map<String, Object>> v_mx_data_0 = (List<Map<String, Object>>) sandiao.get("mx_data");
+        List sanDiaoTitles = new ArrayList<NpoiHelper.TableTitle>();
+        NpoiHelper.TableTitle tableTitle1 = new NpoiHelper.TableTitle();
+        tableTitle1.setKey("groupvalue");
+        tableTitle1.setName("三调类型");
+        tableTitle1.setWidth(2880);
+        sanDiaoTitles.add(tableTitle1);
+
+        tableTitle1 = new NpoiHelper.TableTitle();
+        tableTitle1.setKey("sumvalue");
+        tableTitle1.setName("三调类型面积(单位:㎡)");
+        tableTitle1.setWidth(3000);
+        sanDiaoTitles.add(tableTitle1);
+        NpoiHelper.setComTable(document, sanDiaoTitles, v_mx_data_0, "", pos);
+
+        List<WktsVo.WktInfo> sandiaoWtsList = new ArrayList<>();
+        WktsVo.WktInfo wktInfoData0 = new WktsVo.WktInfo();
+        wktInfoData0.setWkt(ewkt);
+        sandiaoWtsList.add(wktInfoData0);
+        if (v_mx_data_0 != null && v_mx_data_0.size() > 0) {
+            for (Map map_0 : v_mx_data_0) {
+                WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
+                String geom = (String) map_0.get("geom");
+                wktInfo.setWkt(geom);
+                String colorString = generateRandomColor();
+                wktInfo.setFillColor(colorString);
+                wktInfo.setBorderColor(colorString);
+                sandiaoWtsList.add(wktInfo);
+            }
+        }
+        WktsVo sandiaoWktsVo = new WktsVo();
+        sandiaoWktsVo.setWktInfos(sandiaoWtsList);
+        //RequestResult requestResult1 = spatialService.getImage(sandiaoWktsVo);
+        Map<String, String> sandiaoImageMap = this.getImage(sandiaoWktsVo);
+        if (sandiaoImageMap!=null && sandiaoImageMap.get("path")!=null) {
+            //Map<String, String> map = (Map<String, String>) requestResult1.get("data");
+            String path = sandiaoImageMap.get("path");
+            InputStream is = new FileInputStream(path);
+            BufferedImage bufferedImage = ImageIO.read(new File(path));
+            int originalWidth = bufferedImage.getWidth();
+            int originalHeight = bufferedImage.getHeight();
+            int useWidth = 400; // Set the desired width
+            int useHeight = useWidth * originalHeight / originalWidth;
+            XWPFRun run = document.createParagraph().createRun();
+            run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
+            pos++;
+        }
+
+        List<Map> yzjg = (List<Map>) jgMap.get("yzjg");
+        for (Map yz_data : yzjg) {
+//            XWPFParagraph pageBreakParagraph1 = document.createParagraph();
+//            XWPFRun pageBreakRun1 = pageBreakParagraph1.createRun();
+//            pageBreakRun1.addBreak(BreakType.PAGE);
+
+            String mx_bsmmc = (String) yz_data.get("mx_bsmmc");
+            String mx_bsm = (String) yz_data.get("mx_bsm");
+            NpoiHelper.content(document, mx_bsmmc + "; 分析结果如下:", pos++, ParagraphAlignment.CENTER);
+            List<Map> mx_data_list = (List<Map>) yz_data.get("mx_data");
+            for (Map d0_yz_data : mx_data_list) {
+                Integer d0_sumcount = (Integer) d0_yz_data.get("sumcount");
+                String d0_bsmmc = (String) d0_yz_data.get("bsmmc");
+                Double d0_sumvalue = (Double) d0_yz_data.get("sumvalue");
+                String d0_bsm = (String) d0_yz_data.get("bsm");
+
+                List tabYzTitles = new ArrayList<NpoiHelper.TableTitle>();
+                NpoiHelper.TableTitle tableTitle = new NpoiHelper.TableTitle();
+                tableTitle.setKey("sumcount");
+                tableTitle.setName(d0_bsmmc + "个数");
+                tableTitle.setWidth(2880);
+                tabYzTitles.add(tableTitle);
+
+                tableTitle = new NpoiHelper.TableTitle();
+                tableTitle.setKey("sumvalue");
+                tableTitle.setName(d0_bsmmc + "面积(单位:㎡)");
+                tableTitle.setWidth(3000);
+                tabYzTitles.add(tableTitle);
+                List<Map<String, Object>> dataTablelist = new ArrayList<>();
+                dataTablelist.add(d0_yz_data);
+                NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "", pos);
+
+
+                // ------ 这里获取实际数据内容
+//                RequestResult res_0 = applyService.QueryGdbhJgYz(rwbsm, mx_bsm, d0_bsm);
+//                if (res_0.isError()) {
+//                    throw new Exception(String.valueOf(res_0.get(RequestResult.MSG_TAG)));
+//                }
+//                //TODO 先测试
+//                Map<String, Object> res_11 = (Map) res_0.get(RequestResult.DATA_TAG);
+//                List<Map> res_1 = (List<Map>) res_11.get("datalist");
+                // ------ 这里获取实际数据内容
+
+                List<Map> res_1 =  new ArrayList<>();
+
+
+                WktsVo wktsVo = new WktsVo();
+                List<WktsVo.WktInfo> wktInfos = new ArrayList<>();
+                WktsVo.WktInfo wktInfoData = new WktsVo.WktInfo();
+                wktInfoData.setWkt(ewkt);
+                wktInfos.add(wktInfoData);
+
+                if (res_1 != null && res_1.size() > 0) {
+                    for (Map map_0 : res_1) {
+                        WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
+                        String geom = (String) map_0.get("geom");
+                        wktInfo.setWkt(geom);
+                        String colorString = generateRandomColor();
+                        wktInfo.setFillColor(colorString);
+                        wktInfo.setBorderColor(colorString);
+                        wktInfos.add(wktInfo);
+                    }
+                }
+                wktsVo.setWktInfos(wktInfos);
+                //RequestResult requestResult = spatialService.getImage(wktsVo);
+
+                Map<String, String> imageMap =  this.getImage(wktsVo);
+                if (imageMap !=null && imageMap.get("path")!=null) {
+                    //Map<String, String> map = (Map<String, String>) requestResult.get("data");
+                    String path = imageMap.get("path");
+                    InputStream is = new FileInputStream(path);
+                    BufferedImage bufferedImage = ImageIO.read(new File(path));
+                    int originalWidth = bufferedImage.getWidth();
+                    int originalHeight = bufferedImage.getHeight();
+                    int useWidth = 400; // Set the desired width
+                    int useHeight = useWidth * originalHeight / originalWidth;
+                    XWPFRun run = document.createParagraph().createRun();
+                    run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
+                    pos++;
+                }
+            }
+        }
+        return pos;
+    }
+
+    private String generateRandomColor() {
+        Random random = new Random();
+        int red = random.nextInt(256);
+        int green = random.nextInt(256);
+        int blue = random.nextInt(256);
+        return String.format("#%02x%02x%02x", red, green, blue);
+    }
+
+
+    public Map<String, String> getImage(WktsVo wktsVo) throws Exception {
+        String path = imageService.getSensingImage(wktsVo);
+        Map<String, String> map = new HashMap<>();
+        map.put("path", path);
+        return map;
+    }
 
 
 

+ 317 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/service/impl/ImageServiceImpl.java

@@ -0,0 +1,317 @@
+package com.siwei.apply.service.impl;
+
+
+import com.siwei.apply.domain.vo.WktsVo;
+import com.siwei.apply.service.IImageService;
+import com.siwei.common.core.utils.StringUtils;
+import org.geotools.coverage.grid.GridCoverage2D;
+import org.geotools.factory.CommonFactoryFinder;
+import org.geotools.feature.DefaultFeatureCollection;
+import org.geotools.feature.simple.SimpleFeatureBuilder;
+import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
+import org.geotools.gce.geotiff.GeoTiffReader;
+import org.geotools.geometry.jts.JTSFactoryFinder;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import org.geotools.map.FeatureLayer;
+import org.geotools.map.GridReaderLayer;
+import org.geotools.map.Layer;
+import org.geotools.map.MapContent;
+import org.geotools.referencing.crs.DefaultGeographicCRS;
+import org.geotools.renderer.GTRenderer;
+import org.geotools.renderer.label.LabelCacheImpl;
+import org.geotools.renderer.lite.StreamingRenderer;
+import org.geotools.styling.*;
+import org.geotools.styling.Stroke;
+import org.geotools.util.factory.Hints;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.geom.MultiPolygon;
+import org.locationtech.jts.io.WKTReader;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.filter.FilterFactory2;
+import org.opengis.style.ContrastMethod;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+
+import javax.imageio.ImageIO;
+import javax.imageio.stream.ImageOutputStream;
+import java.awt.*;
+import java.awt.Font;
+import java.awt.image.BufferedImage;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * 生成图片服务
+ */
+@Service
+public class ImageServiceImpl implements IImageService {
+    @Value("${Path.rsImage}")
+    public String rsImage;
+    @Value("${Path.rootPath}")
+    public String rootPath;
+
+    @Value("${Image.with}")
+    public int imageWith;
+
+    @Override
+    public String getSensingImage(WktsVo wktsVo) throws Exception {
+        System.out.println("start getSensingImage");
+        // 图片保存路径
+        String fileDir = rootPath + "/images/" + StringUtils.getUUID() + "/";
+        File dir = new File(fileDir);
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+        String filePath = fileDir + System.currentTimeMillis() + ".png";
+
+        System.out.println("imagePath:  " + filePath);
+
+        // 创建一个 MapContent 对象
+        MapContent mapContent = new MapContent();
+        mapContent.setTitle("Quickstart");
+
+        // 加载并添加 TIFF 栅格图层
+        System.out.println("tifPath:  " + rsImage);
+        File file = new File(rsImage);
+        if (file.exists()) {
+            System.out.println("file exists");
+        } else {
+            System.out.println("file not exists");
+        }
+        Hints tiffHints = new Hints();
+        tiffHints.add(new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
+        // 默认坐标系EPSG:3857
+        tiffHints.add(new Hints(Hints.DEFAULT_COORDINATE_REFERENCE_SYSTEM, DefaultGeographicCRS.WGS84));
+        GeoTiffReader tifReader = new GeoTiffReader(file, tiffHints);
+        GridCoverage2D coverage = tifReader.read(null);
+        Layer rasterLayer = new GridReaderLayer(tifReader, createRasterStyle());
+        mapContent.addLayer(rasterLayer);
+
+
+        // 获取几何对象的外接矩形
+        ReferencedEnvelope combinedBounds = new ReferencedEnvelope(DefaultGeographicCRS.WGS84);
+
+        for (WktsVo.WktInfo wktInfo : wktsVo.getWktInfos()) {
+            if (wktInfo.getWkt() == null || wktInfo.getWkt().isEmpty()) {
+                continue;
+            }
+            // 将 WKT 转换为几何对象并添加到图层
+            WKTReader wktReader = new WKTReader(JTSFactoryFinder.getGeometryFactory());
+
+            String wkt = wktInfo.getWkt().replaceFirst("^SRID=\\d+;", "");
+
+            Geometry geometry = wktReader.read(wkt);
+
+            if (geometry instanceof MultiPolygon) {
+                MultiPolygon multiPolygon = (MultiPolygon) geometry;
+                for (int i = 0; i < multiPolygon.getNumGeometries(); i++) {
+                    Geometry polygon = multiPolygon.getGeometryN(i);
+
+                    // 对每个单独的 Polygon 进行渲染
+                    SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
+                    typeBuilder.setName("geometry");
+                    typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
+                    typeBuilder.add("the_geom", Geometry.class);
+                    SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
+
+                    featureBuilder.add(polygon);
+                    SimpleFeature feature = featureBuilder.buildFeature(null);
+
+                    DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
+                    featureCollection.add(feature);
+
+                    Style wktStyle = createStyle(wktInfo.getBorderColor(), wktInfo.getBorderOpacity(), wktInfo.getFillColor(), wktInfo.getFillOpacity());
+                    Layer wktLayer = new FeatureLayer(featureCollection, wktStyle);
+                    // 添加图层
+                    mapContent.addLayer(wktLayer);
+
+                    combinedBounds.expandToInclude(featureCollection.getBounds());
+                }
+            } else {
+                SimpleFeatureTypeBuilder typeBuilder = new SimpleFeatureTypeBuilder();
+                typeBuilder.setName("geometry");
+                typeBuilder.setCRS(DefaultGeographicCRS.WGS84);
+                typeBuilder.add("the_geom", Geometry.class);
+                SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(typeBuilder.buildFeatureType());
+
+                featureBuilder.add(geometry);
+                SimpleFeature feature = featureBuilder.buildFeature(null);
+
+                DefaultFeatureCollection featureCollection = new DefaultFeatureCollection();
+                featureCollection.add(feature);
+
+                Style wktStyle = createStyle(wktInfo.getBorderColor(), wktInfo.getBorderOpacity(), wktInfo.getFillColor(), wktInfo.getFillOpacity());
+                Layer wktLayer = new FeatureLayer(featureCollection, wktStyle);
+                // 添加图层
+                mapContent.addLayer(wktLayer);
+
+                combinedBounds.expandToInclude(featureCollection.getBounds());
+            }
+        }
+
+        // 增加长和宽的10%
+//        double expandWidth = combinedBounds.getWidth() * (1 + 0.01);
+//        double expandHeight = combinedBounds.getHeight() * (1 + 0.01);
+
+        double expandWidth = combinedBounds.getWidth() ;
+        double expandHeight = combinedBounds.getHeight();
+        double bian = expandWidth>expandHeight?expandWidth:expandHeight;
+
+
+        combinedBounds.expandBy(bian, bian);
+
+        // 将地图绘制到图片
+        File outputFile = new File(filePath);
+        try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile); ImageOutputStream outputImageFile = ImageIO.createImageOutputStream(fileOutputStream);) {
+            int w = imageWith;
+            int h = (int) (w * (combinedBounds.getHeight() / combinedBounds.getWidth()));
+            BufferedImage bufferedImage = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
+            Graphics2D g2d = bufferedImage.createGraphics();
+
+            mapContent.getViewport().setMatchingAspectRatio(true);
+            mapContent.getViewport().setScreenArea(new Rectangle(w, h));
+            mapContent.getViewport().setBounds(combinedBounds);
+
+            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+            Rectangle outputArea = new Rectangle(w, h);
+
+            GTRenderer renderer = new StreamingRenderer();
+            LabelCacheImpl labelCache = new LabelCacheImpl();
+            Map<Object, Object> hints = renderer.getRendererHints();
+            if (hints == null) {
+                hints = new HashMap<>();
+            }
+            hints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache);
+            renderer.setRendererHints(hints);
+            renderer.setMapContent(mapContent);
+            renderer.paint(g2d, outputArea, combinedBounds);
+            ImageIO.write(bufferedImage, "png", outputImageFile);
+
+            // Clean up
+            g2d.dispose();
+            mapContent.dispose();
+            //添加图例
+            filePath = addLegend(filePath, wktsVo);
+        } catch (IOException ex) {
+            System.out.println("create image fail");
+            System.out.println(ex);
+            ex.printStackTrace();
+        }
+        System.out.println("create image success:  " + filePath);
+
+
+        return filePath;
+    }
+
+    private String addLegend(String filePath, WktsVo wktsVo) throws IOException {
+        // 图片保存路径
+        String fileDir = rootPath + "/images/" + StringUtils.getUUID() + "/";
+        File dir = new File(fileDir);
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+        String filePathNow = fileDir + System.currentTimeMillis() + ".png";
+
+        //添加图例
+        File file_legend = new File(filePath);
+        if (file_legend.exists()) {
+            // 将文件对象转化为图片对象
+            BufferedImage originalImage = ImageIO.read(file_legend);
+            int width = originalImage.getWidth();
+            int height = originalImage.getHeight();
+            int legend_width = (int) (width * 0.1);
+            int legend_height = (int) (height * 0.1);
+            int width_1 = width - legend_width;
+            int height_1 = height - legend_height;
+            int legend_count = wktsVo.getWktInfos().size();
+            int height_2 = legend_height / legend_count;
+
+            // 创建一个Graphics2D对象
+            Graphics2D g2d = (Graphics2D) originalImage.getGraphics();
+            int legend_i = 0;
+            for (WktsVo.WktInfo wktInfo : wktsVo.getWktInfos()) {
+                if (wktInfo.getLegendDisplay()) {
+                    String legendColor = wktInfo.getLegendColor();
+                    if (StringUtils.isEmpty(legendColor)) {
+                        legendColor = wktInfo.getFillColor();
+                    }
+                    Float legendColorOpacity = wktInfo.getLegendColorOpacity();
+                    if (legendColorOpacity == null) {
+                        legendColorOpacity = wktInfo.getFillOpacity();
+                    }
+                    legendColorOpacity = legendColorOpacity * 255;
+                    Color color = Color.decode(legendColor);
+                    int red = color.getRed();
+                    int green = color.getGreen();
+                    int blue = color.getBlue();
+                    Color colorFill = new Color(red, green, blue, legendColorOpacity.intValue());
+                    g2d.setBackground(colorFill);
+                    g2d.clearRect(width_1, height_1 + height_2 * legend_i, legend_width, legend_height); // 清除原有
+
+                    g2d.setColor(colorFill);
+                    // 设置画笔字体样式为微软雅黑,斜体,文字大小为20px
+                    if (height_2 > 20) {
+                        g2d.setFont(new Font("微软雅黑", Font.ITALIC, 20));
+                    } else {
+                        g2d.setFont(new Font("微软雅黑", Font.ITALIC, height_2));
+                    }
+                    // 写上水印文字和坐标
+                    g2d.drawString(wktInfo.getLegendText(), width_1 - legend_height, height_1 + height_2 * (legend_i) + height_2 / 2);
+                }
+                legend_i++;
+            }
+
+            // 保存新图片
+            ImageIO.write(originalImage, "png", new File(filePathNow));
+            // 释放资源
+            g2d.dispose();
+            return filePathNow;
+        } else {
+            return null;
+        }
+    }
+
+    private Style createStyle(String borderColor, float borderOpacity, String fillColor, float fillOpacity) {
+        // 创建样式工厂和过滤工厂
+        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
+        FilterFactory2 filterFactory = CommonFactoryFinder.getFilterFactory2();
+
+        // 创建笔刷和填充样式
+        Color colorBorder = Color.decode(borderColor);
+        Color colorFill = Color.decode(fillColor);
+
+        Stroke stroke = styleFactory.createStroke(filterFactory.literal(colorBorder), filterFactory.literal(borderOpacity));
+        Fill fill = styleFactory.createFill(filterFactory.literal(colorFill), filterFactory.literal(fillOpacity));
+
+        // 创建符号样式
+        PolygonSymbolizer polygonSymbolizer = styleFactory.createPolygonSymbolizer(stroke, fill, null);
+        Rule rule = styleFactory.createRule();
+        rule.symbolizers().add(polygonSymbolizer);
+
+        FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(new Rule[]{rule});
+        Style style = styleFactory.createStyle();
+        style.featureTypeStyles().add(fts);
+
+        return style;
+    }
+
+    private Style createRasterStyle() {
+        StyleFactory sf = CommonFactoryFinder.getStyleFactory();
+        FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2();
+
+        ContrastEnhancement ce = sf.contrastEnhancement(ff.literal(1.0), ContrastMethod.NORMALIZE);
+        SelectedChannelType sctRed = sf.createSelectedChannelType(String.valueOf(1), ce);
+        SelectedChannelType sctGreen = sf.createSelectedChannelType(String.valueOf(2), ce);
+        SelectedChannelType sctBlue = sf.createSelectedChannelType(String.valueOf(3), ce);
+
+        RasterSymbolizer sym = sf.getDefaultRasterSymbolizer();
+        ChannelSelection sel = sf.channelSelection(sctRed, sctGreen, sctBlue);
+        sym.setChannelSelection(sel);
+
+        return SLD.wrapSymbolizers(sym);
+    }
+}

+ 578 - 0
siwei-modules/siwei-apply/src/main/java/com/siwei/apply/utils/NpoiHelper.java

@@ -0,0 +1,578 @@
+package com.siwei.apply.utils;
+
+import com.aspose.words.*;
+import com.siwei.common.core.utils.StringUtils;
+import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
+import org.apache.poi.util.Units;
+import org.apache.poi.xwpf.usermodel.*;
+import org.apache.poi.xwpf.usermodel.LineSpacingRule;
+import org.apache.poi.xwpf.usermodel.ParagraphAlignment;
+import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
+
+import javax.imageio.ImageIO;
+import java.awt.image.BufferedImage;
+import java.io.*;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public class NpoiHelper {
+    /**
+     * 添加段落
+     *
+     * @param document
+     * @param text
+     * @param option
+     * @return
+     */
+    public static XWPFParagraph newParagraph(XWPFDocument document, String text, Option option) {
+        if (option == null)
+            option = new Option();
+        List<String> list = new ArrayList<String>() {
+            {
+                add(text);
+            }
+        };
+        return newParagraph(document, list, option);
+    }
+
+    /// <summary>
+    /// 添加段落
+    /// </summary>
+    /// <param name="document"></param>
+    /// <param name="texts">多行文本</param>
+    /// <param name="option">参数</param>
+    /// <returns></returns>
+    public static XWPFParagraph newParagraph(XWPFDocument document, List<String> texts, Option option) {
+        if (option == null)
+            option = new Option();
+
+        XWPFParagraph paragraph = document.createParagraph();//创建段落对象
+        paragraph.setAlignment(option.getAlign());//文字显示位置,段落排列(左对齐,居中,右对齐)
+        paragraph.setSpacingBetween(option.getRowSpacing(), LineSpacingRule.AUTO);
+        //if (texts[0].StartsWith("\t"))
+        //{
+        //    paragraph.IndentationFirstLine = 400;
+        //}
+
+        for (int i = 0; i < texts.size(); i++) {
+            XWPFRun xwpfRun = paragraph.createRun();//创建段落文本对象
+            xwpfRun.setBold(option.isBold);//文字加粗
+            xwpfRun.setText(texts.get(i));//填充内容
+            xwpfRun.setFontSize(option.getFontSize());//设置文字大小
+            xwpfRun.setItalic(option.isItalic());//是否设置斜体(字体倾斜)
+            xwpfRun.setColor(option.getFontColor());//设置字体颜色--十六进制
+            xwpfRun.setFontFamily(option.getFontFamily(), XWPFRun.FontCharRange.eastAsia); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
+            if (i < texts.size() - 1)
+                xwpfRun.addCarriageReturn();
+        }
+        return paragraph;
+    }
+
+    /**
+     * 设置表格字体样式
+     *
+     * @param table
+     * @param text
+     * @param option
+     * @return
+     */
+    public static XWPFParagraph setCellText(XWPFTable table, String text, Option option) {
+        if (option == null)
+            option = new Option();
+
+        //table中的文字格式设置
+        XWPFParagraph pCell = new XWPFParagraph(CTP.Factory.newInstance(), table.getBody());
+        pCell.setWordWrapped(true);
+        pCell.setAlignment(option.getAlign()); //字体居中
+        pCell.setVerticalAlignment(TextAlignment.CENTER);//字体居中
+        //pCell.setSpacingBetween(option.RowSpacing, LineSpacingRule.AUTO);
+
+        XWPFRun xwpfRun = pCell.createRun();//创建段落文本对象
+        xwpfRun.setBold(option.isBold());//文字加粗
+        xwpfRun.setText(text);//填充内容
+        xwpfRun.setFontSize(option.getFontSize());//设置文字大小
+        xwpfRun.setItalic(option.isItalic());//是否设置斜体(字体倾斜)
+        xwpfRun.setColor(option.getFontColor());//设置字体颜色--十六进制
+        xwpfRun.setFontFamily(option.getFontFamily(), XWPFRun.FontCharRange.ascii); //设置标题样式如:(微软雅黑,隶书,楷体)根据自己的需求而定
+
+
+        return pCell;
+    }
+
+    /**
+     * 通用表格
+     *
+     * @param document
+     * @param tableTitle
+     * @param datas
+     * @param title
+     * @param pos
+     * @return
+     */
+    public static XWPFTable setComTable(XWPFDocument document, List<TableTitle> tableTitle
+            , List<Map<String, Object>> datas, String title, int pos) {
+        //标题
+        if (!StringUtils.isEmpty(title) && pos > -1) {
+            Option option = new Option();
+            option.setAlign(ParagraphAlignment.CENTER);
+            option.setRowSpacing(1);
+            document.setParagraph(newParagraph(document, title, option), pos);
+        }
+        //表格
+        XWPFTable table = document.createTable(1, tableTitle.size());
+        table.setWidth(tableTitle.stream().mapToInt(TableTitle::getWidth).sum());
+        //表头
+        for (int i = 0; i < tableTitle.size(); i++) {
+
+            XWPFTableCell cell = table.getRow(0).getCell(i);
+
+            CTTcPr ctTcPr = cell.getCTTc().isSetTcPr() ? cell.getCTTc().getTcPr() : cell.getCTTc().addNewTcPr();
+            CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
+            int width = tableTitle.get(i).getWidth();
+            ctTblWidth.setW(BigInteger.valueOf(width));
+            ctTblWidth.setType(STTblWidth.DXA);
+
+            cell.setColor("DBE5F1");
+            Option option = new Option();
+            option.setBold(true);
+            option.setAlign(ParagraphAlignment.CENTER);
+            XWPFParagraph paragraph = setCellText(table, tableTitle.get(i).getName(), option);
+            cell.setParagraph(paragraph);
+        }
+
+        //内容
+        for (int row = 0; row < datas.size(); row++) {
+            XWPFTableRow mr = table.createRow();
+            for (int col = 0; col < tableTitle.size(); col++) {
+                TableTitle cobj = tableTitle.get(col);
+                XWPFTableCell cell = mr.getCell(col);
+
+                // 设置内容单元格的宽度
+                CTTc ctTc = cell.getCTTc();
+                CTTcPr ctTcPr = ctTc.isSetTcPr() ? ctTc.getTcPr() : ctTc.addNewTcPr();
+                CTTblWidth ctTblWidth = ctTcPr.addNewTcW();
+                int width = tableTitle.get(col).getWidth();
+                ctTblWidth.setW(BigInteger.valueOf(width));
+                ctTblWidth.setType(STTblWidth.DXA);
+
+                Object o = datas.get(row).get(cobj.key);
+                String text = o == null ? "" : o.toString();
+                if (cobj.xsw > -1) {
+                    BigDecimal bd = new BigDecimal(Double.parseDouble(text));
+                    Double f1 = bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
+                    text = f1.toString();
+                }
+                Option option = new Option();
+                option.setAlign(cobj.align);
+                XWPFParagraph paragraph = setCellText(table, text, option);
+                cell.setParagraph(paragraph);
+            }
+        }
+        return table;
+    }
+
+    /**
+     * 跨列合并
+     *
+     * @param table
+     * @param row
+     * @param fromCell
+     * @param toCell
+     */
+    public static void mergeHorizontal(XWPFTable table, int row, int fromCell, int toCell) {
+        for (int cellIndex = fromCell; cellIndex <= toCell; cellIndex++) {
+            XWPFTableCell cell = table.getRow(row).getCell(cellIndex);
+            if (cellIndex == fromCell) {
+                cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.RESTART);
+            } else {
+                cell.getCTTc().addNewTcPr().addNewHMerge().setVal(STMerge.CONTINUE);
+            }
+        }
+    }
+
+    /**
+     * 跨行合并
+     *
+     * @param table
+     * @param col
+     * @param fromRow
+     * @param toRow
+     */
+    public void mergeVertically(XWPFTable table, int col, int fromRow, int toRow) {
+        for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
+            XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
+            if (rowIndex == fromRow) {
+                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
+            } else {
+                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
+            }
+        }
+        //合并后垂直居中
+        table.getRow(fromRow).getCell(col).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
+    }
+
+    /**
+     * 跨行合并
+     *
+     * @param table
+     * @param col
+     * @param fromRow
+     * @param toRow
+     */
+    public static void mergeCellsVertically(XWPFTable table, int col, int fromRow, int toRow) {
+        for (int rowIndex = fromRow; rowIndex <= toRow; rowIndex++) {
+            XWPFTableCell cell = table.getRow(rowIndex).getCell(col);
+            CTTc cttc = cell.getCTTc();
+            if (cttc.getTcPr() == null) {
+                cttc.addNewTcPr();
+            }
+            //第一个合并单元格用重启合并值设置
+            if (rowIndex == fromRow) {
+                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.RESTART);
+            } else {
+                //合并第一个单元格的单元被设置为“继续”
+                cell.getCTTc().addNewTcPr().addNewVMerge().setVal(STMerge.CONTINUE);
+            }
+        }
+    }
+
+    /**
+     * 标题
+     *
+     * @param document
+     * @param title
+     * @param pos
+     */
+
+    public static void title(XWPFDocument document, String title, int pos) {
+        List list = new ArrayList<String>() {
+            {
+                add("");
+                add(title);
+            }
+        };
+        Option option = new Option();
+        option.setFontSize(19);
+        option.setAlign(ParagraphAlignment.CENTER);
+        option.setBold(true);
+        document.setParagraph(newParagraph(document, list, option), pos);
+    }
+
+    /**
+     * 目录
+     *
+     * @param document
+     * @param text
+     * @param pos
+     */
+    public static void catalog(XWPFDocument document, String text, int pos) {
+        Option option = new Option();
+        option.setFontSize(14);
+        option.setBold(true);
+        document.setParagraph(newParagraph(document, text, option), pos);
+    }
+
+    /**
+     * 内容
+     *
+     * @param document
+     * @param count
+     * @param pos
+     */
+    public static void content(XWPFDocument document, String count, int pos) {
+        document.setParagraph(newParagraph(document, count, null), pos);
+    }
+
+    /**
+     * 内容
+     * @param document
+     * @param text
+     * @param pos
+     * @param alignment
+     */
+    public static void content(XWPFDocument document, String text, int pos, ParagraphAlignment alignment) {
+        XWPFParagraph paragraph = document.createParagraph();
+        paragraph.setAlignment(alignment);
+        XWPFRun run = paragraph.createRun();
+        run.setText(text);
+        document.setParagraph(paragraph, pos);
+    }
+
+    /**
+     * 内容
+     *
+     * @param document
+     * @param contents
+     * @param pos
+     */
+    public static void content(XWPFDocument document, List<String> contents, int pos) {
+        document.setParagraph(newParagraph(document, contents, null), pos);
+    }
+
+    // 选项类
+    public static class Option {
+        public Option() {
+            setAlign(ParagraphAlignment.LEFT);
+            setBold(false);
+            setFontColor("000000");
+            setFontFamily("宋体");
+            setRowSpacing(1.5);
+            setFontSize(12);
+        }
+
+        // 水平对齐
+        private ParagraphAlignment align;
+        // 文字加粗
+        private boolean isBold;
+        // 文字斜体
+        private boolean isItalic;
+        // 字体大小(默认小四 12)
+        private int fontSize;
+        // 字体(宋体,微软雅黑,隶书,楷体)
+        private String fontFamily;
+        // 字体颜色(十六进制)
+        private String fontColor;
+        // 行间距(默认1.5)
+        private double rowSpacing;
+
+        public ParagraphAlignment getAlign() {
+            return align;
+        }
+
+        public void setAlign(ParagraphAlignment align) {
+            this.align = align;
+        }
+
+        public boolean isBold() {
+            return isBold;
+        }
+
+        public void setBold(boolean bold) {
+            isBold = bold;
+        }
+
+        public boolean isItalic() {
+            return isItalic;
+        }
+
+        public void setItalic(boolean italic) {
+            isItalic = italic;
+        }
+
+        public int getFontSize() {
+            return fontSize;
+        }
+
+        public void setFontSize(int fontSize) {
+            this.fontSize = fontSize;
+        }
+
+        public String getFontFamily() {
+            return fontFamily;
+        }
+
+        public void setFontFamily(String fontFamily) {
+            this.fontFamily = fontFamily;
+        }
+
+        public String getFontColor() {
+            return fontColor;
+        }
+
+        public void setFontColor(String fontColor) {
+            this.fontColor = fontColor;
+        }
+
+        public double getRowSpacing() {
+            return rowSpacing;
+        }
+
+        public void setRowSpacing(double rowSpacing) {
+            this.rowSpacing = rowSpacing;
+        }
+    }
+
+    // 表格头
+    public static class TableTitle {
+        public TableTitle() {
+            setAlign(ParagraphAlignment.LEFT);
+            setWidth(1000);
+            setXsw(-1);
+        }
+
+        ;
+        // 主键
+        private String key;
+        // 名称
+        private String name;
+        /// 水平对齐
+        private ParagraphAlignment align;
+        /// 宽
+        private int width;
+        /// 小数位(-1表示不计算,通常为汉字)
+        private int xsw;
+
+        public String getKey() {
+            return key;
+        }
+
+        public void setKey(String key) {
+            this.key = key;
+        }
+
+        public String getName() {
+            return name;
+        }
+
+        public void setName(String name) {
+            this.name = name;
+        }
+
+        public ParagraphAlignment getAlign() {
+            return align;
+        }
+
+        public void setAlign(ParagraphAlignment align) {
+            this.align = align;
+        }
+
+        public int getWidth() {
+            return width;
+        }
+
+        public void setWidth(int width) {
+            this.width = width;
+        }
+
+        public int getXsw() {
+            return xsw;
+        }
+
+        public void setXsw(int xsw) {
+            this.xsw = xsw;
+        }
+    }
+
+    public static boolean getLicense() {
+        boolean result = false;
+        InputStream is = null;
+        try {
+            String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n" +
+                    "<License>\n" +
+                    "    <Data>\n" +
+                    "        <Products>\n" +
+                    "            <Product>Aspose.Total for Java</Product>\n" +
+                    "            <Product>Aspose.Words for Java</Product>\n" +
+                    "        </Products>\n" +
+                    "        <EditionType>Enterprise</EditionType>\n" +
+                    "        <SubscriptionExpiry>20991231</SubscriptionExpiry>\n" +
+                    "        <LicenseExpiry>20991231</LicenseExpiry>\n" +
+                    "        <SerialNumber>8bfe198c-7f0c-4ef8-8ff0-acc3237bf0d7</SerialNumber>\n" +
+                    "    </Data>\n" +
+                    "    <Signature>sNLLKGMUdF0r8O1kKilWAGdgfs2BvJb/2Xp8p5iuDVfZXmhppo+d0Ran1P9TKdjV4ABwAgKXxJ3jcQTqE/2IRfqwnPf8itN8aFZlV3TJPYeD3yWE7IT55Gz6EijUpC7aKeoohTb4w2fpox58wWoF3SNp6sK6jDfiAUGEHYJ9pjU=</Signature>\n" +
+                    "</License>\n";
+            is = new ByteArrayInputStream(xml.getBytes());
+            License aposeLic = new License();
+            aposeLic.setLicense(is);
+            result = true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+            if (is != null) {
+                try {
+                    is.close();
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return result;
+    }
+
+    public static boolean doc2pdf(String inPath, String outPath) {
+        if (!getLicense()) { // 验证License 若不验证则转化出的pdf文档会有水印产生
+            return false;
+        }
+        FileOutputStream os = null;
+        try {
+            //取用户字体目录
+            String userfontsfoloder = System.getProperty("user.home") + "\\Microsoft\\Windows\\Fonts\\";
+            System.out.println("userfontsfoloder:" + userfontsfoloder);
+            FontSourceBase[] fontSourceBases = FontSettings.getDefaultInstance().getFontsSources();
+            FontSourceBase[] updatedFontSources = new FontSourceBase[FontSettings.getDefaultInstance().getFontsSources().length + 1];
+
+            //将用户目录字体添加到字体源中
+            FolderFontSource folderFontSource = new FolderFontSource(userfontsfoloder, true);
+
+            for (int i = 0; i < fontSourceBases.length; i++) {
+                updatedFontSources[i] = fontSourceBases[i];
+            }
+            updatedFontSources[fontSourceBases.length] = folderFontSource;
+
+            FontSettings.getDefaultInstance().setFontsSources(updatedFontSources);
+
+            long old = System.currentTimeMillis();
+            File file = new File(outPath); // 新建一个空白pdf文档
+            os = new FileOutputStream(file);
+            com.aspose.words.Document doc = new com.aspose.words.Document(inPath); // Address是将要被转化的word文档
+            doc.save(os, SaveFormat.PDF);// 全面支持DOC, DOCX, OOXML, RTF HTML, OpenDocument, PDF,
+            // EPUB, XPS, SWF 相互转换
+            long now = System.currentTimeMillis();
+            System.out.println("pdf转换成功,共耗时:" + ((now - old) / 1000.0) + "秒"); // 转化用时
+        } catch (Exception e) {
+            e.printStackTrace();
+            return false;
+        } finally {
+            if (os != null) {
+                try {
+                    os.flush();
+                    os.close();
+                } catch (IOException e) {
+                    e.printStackTrace();
+                }
+            }
+        }
+        return true;
+    }
+
+
+    public static void addImagesToWord(XWPFDocument document, File[] imgs) throws IOException, InvalidFormatException {
+//        try (XWPFDocument document = new XWPFDocument()) {
+            for (File img : imgs) {
+                // 只对指定后缀的图片处理
+                if (img.getName().endsWith("jpeg") || img.getName().endsWith("jpg") || img.getName().endsWith("png")) {
+                    BufferedImage bufferedImage = ImageIO.read(img);
+                    int imageType = XWPFDocument.PICTURE_TYPE_JPEG;
+                    if (img.getName().endsWith(".png")) {
+                        imageType = XWPFDocument.PICTURE_TYPE_PNG;
+                    }
+
+                    int width = bufferedImage.getWidth();
+                    int height = bufferedImage.getHeight();
+
+                    // Create a new run and add the image
+                    XWPFRun run = document.createParagraph().createRun();
+//                    log.warn("fileName:{},height:{},width:{}", img.getName(), height, width);
+                    run.addPicture(new FileInputStream(img), imageType, img.getName(), Units.toEMU(width), Units.toEMU(height));
+                    // Optionally, you can add more text or formatting here
+
+                    // Add a new line for the next image
+//                    document.createParagraph();
+                } else {
+                    continue;
+                }
+
+//                // Save the modified document
+//                try (FileOutputStream fos = new FileOutputStream("D:\\tmp\\tmp\\20231208\\modify.doc")) {
+//                    document.write(fos);
+//                    System.out.println("Images added to Word document successfully.");
+//                }
+            }
+//        } catch (InvalidFormatException e) {
+//            throw new RuntimeException(e);
+//        }
+    }
+}