Procházet zdrojové kódy

Merge branch 'f-xiaogu' into dev

gushoubang před 9 měsíci
rodič
revize
fde8c6479a

+ 15 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/domain/calculation/ReportImage.java

@@ -0,0 +1,15 @@
+package com.onemap.analyse.domain.calculation;
+
+import lombok.Data;
+
+import java.io.InputStream;
+
+/**
+ * 报告图片
+ */
+@Data
+public class ReportImage {
+    InputStream inputStream;
+    int useWidth;
+    int useHeight;
+}

+ 51 - 82
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/ReportServiceImpl.java

@@ -6,6 +6,7 @@ import com.onemap.analyse.domain.FactorUseDTO;
 import com.onemap.analyse.domain.FzxzEntityDTO;
 import com.onemap.analyse.domain.FzxzReport;
 import com.onemap.analyse.domain.SelectionResDTO;
+import com.onemap.analyse.domain.calculation.ReportImage;
 import com.onemap.analyse.domain.res.GeomRes;
 import com.onemap.analyse.domain.vo.FactorSpatialVo;
 import com.onemap.analyse.mapper.FactorUseMapper;
@@ -125,7 +126,7 @@ public class ReportServiceImpl implements IReportService {
             // optionCENTER.setAlign(ParagraphAlignment.CENTER);
             // document.setParagraph(NpoiHelper.newParagraph(document, sdf.format(new Date()), optionCENTER), pos++);
 
-            // 1、项目选址信息
+            // 、项目选址信息
             NpoiHelper.catalog(document, "一、项目选址信息", pos++);
             String ydmj = NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(res.getYdmjbegin())) + " - " + NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(res.getYdmjend()));
             List<String> listTemp = new ArrayList<>();
@@ -173,74 +174,28 @@ public class ReportServiceImpl implements IReportService {
 
                 dataTablelist.add(map);
             }
-            XWPFTable tableYz = NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "表1:选址影响因子", pos++);
+            NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "表1:选址影响因子", pos++);
 
             // TODO 二、选址范围分析
             NpoiHelper.catalog(document, "二、选址范围分析", pos++);
-            // 查询辅助选址分析图斑
-            // QueryWrapper<FzxzGeomInfoDTO1> wrapperTb = new QueryWrapper<>();
-            // wrapperTb.eq("rwbsm", res.getBsm());
-            // wrapperTb.groupBy("objectid", "rwbsm", "ydyhfldm", "ydyhflmc", "frequency", "sum_mj");
-            // List<FzxzGeomInfoDTO1> fzxzTbEntityDTOList = fzxzTbMapper.selectList(wrapperTb);
-
-            // 计算面积总和
-            // TODO
-            double sumcount = 0;
-            // for (int i = 0; i < fzxzTbEntityDTOList.size(); i++) {
-            //     sumcount = sumcount + fzxzTbEntityDTOList.get(i).getSumMj();
-            // }
-
-            // List<FzxzGeomInfoDTO> list = fzxzTbEntityDTOList.stream().sorted(Comparator.comparing(FzxzGeomInfoDTO::getSumMj).reversed()).collect(Collectors.toList());
             String fwfx = "\t根据指定选址分析得出,所选范围共" + NumberUtil.double2TwoDecimal(UnitsUtil.m2ToMu(geomRes.getArea())) + "亩,其中";
-            List<Map<String, Object>> fztable = new ArrayList<>();
-            // 生成地类分析统计表
-            // TODO
-            // for (int i = 0; i < list.size(); i++) {
-            //     FzxzGeomInfoDTO item = list.get(i);
-            //     String zb = String.format("%.1f", item.getSumMj() / sumcount * 100);
-            //     if (i < 5) {
-            //         // 面积前五的占比地类计算
-            //         fwfx += item.getYdyhflmc() + Math.round(item.getSumMj()) + "平方米,占比" + zb + "%;";
-            //     }
-            //     // List<FzxzTbEntityDTO>转List<Map<String, Object>> 地类编码	地类名称	面积(平方千米)	占比(%)
-            //     Map map = new HashMap();
-            //     map.put("ZB", zb);
-            //     map.put("YDYHFLDM", item.getYdyhfldm());
-            //     map.put("YDYHFLMC", item.getYdyhflmc());
-            //     map.put("SUM_MJ", Math.round(item.getSumMj()));
-            //     fztable.add(map);
-            // }
             fwfx = fwfx.substring(0, fwfx.length() - 1) + "。详情如下:";
             NpoiHelper.content(document, fwfx, pos++);
-            // 地类编码	地类名称	面积(平方千米)	占比(%)
-            List<NpoiHelper.TableTitle> tabYztbTitles = new ArrayList();
-            NpoiHelper.TableTitle tableTitleTb = new NpoiHelper.TableTitle();
-            tableTitleTb.setKey("YDYHFLDM");
-            tableTitleTb.setName("地类编码");
-            tableTitleTb.setAlign(ParagraphAlignment.CENTER);
-            tableTitleTb.setWidth(2010);
-            tabYztbTitles.add(tableTitleTb);
-            tableTitleTb = new NpoiHelper.TableTitle();
-            tableTitleTb.setKey("YDYHFLMC");
-            tableTitleTb.setName("地类名称");
-            tableTitleTb.setWidth(2910);
-            tabYztbTitles.add(tableTitleTb);
-            tableTitleTb = new NpoiHelper.TableTitle();
-            tableTitleTb.setKey("SUM_MJ");
-            tableTitleTb.setName("面积(平方千米)");
-            tableTitleTb.setAlign(ParagraphAlignment.CENTER);
-            tableTitleTb.setWidth(1870);
-            tabYztbTitles.add(tableTitleTb);
-            tableTitleTb = new NpoiHelper.TableTitle();
-            tableTitleTb.setKey("ZB");
-            tableTitleTb.setName("占比(%)");
-            tableTitleTb.setAlign(ParagraphAlignment.CENTER);
-            tableTitleTb.setWidth(1700);
-            tabYztbTitles.add(tableTitleTb);
-            XWPFTable tableYztb = NpoiHelper.setComTable(document, tabYztbTitles, fztable, "表2:地类分析统计表", pos++);
-            // 查询结果
-            List<SelectionResDTO> fzxzJgGisDTOList = fzxzResMapper.getListByRwbsm(res.getBsm(), dkIds);
+
+            // 获取插入图片
+            ReportImage reportImage = getReportImage(geomRes.getGeom(), 300);
+
+            XWPFParagraph imageParagraph = document.createParagraph();
+            imageParagraph.setAlignment(ParagraphAlignment.CENTER); // Center align the image
+            XWPFRun imageRun = imageParagraph.createRun();
+            imageRun.addPicture(reportImage.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG,
+                    null, Units.toEMU(reportImage.getUseWidth()), Units.toEMU(reportImage.getUseHeight()));
+            pos++;
+
+
+            // 三、选址分析
             NpoiHelper.catalog(document, "三、选址分析", pos++);
+            List<SelectionResDTO> fzxzJgGisDTOList = fzxzResMapper.getListByRwbsm(res.getBsm(), dkIds);
             String ydmc = res.getYdmc();
             if (!StringUtils.isEmpty(ydmc)) {
                 if (ydmc.lastIndexOf("用地") == ydmc.length() - 2) {
@@ -275,14 +230,14 @@ public class ReportServiceImpl implements IReportService {
                 // row
                 // table.getRow(4).getCell(0).setColor("DBE5F1");
                 NpoiHelper.mergeHorizontal(table, dkList.size(), 1, 3);// 合并单元格
-                table.getRow(dkList.size()).getCell(0).setParagraph(NpoiHelper.setCellText(table, "配建机动车位说明", optionIsBold));
+                table.getRow(dkList.size()).getCell(0).setParagraph(NpoiHelper.setCellText(table, "配建机动车位说明", null));
 
                 // 准地价预估(万元)
                 NpoiHelper.mergeHorizontal(table, dkList.size() + 1, 1, 3);// 合并单元格
-                table.getRow(dkList.size() + 1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "准地价预估(万元)", optionIsBold));
+                table.getRow(dkList.size() + 1).getCell(0).setParagraph(NpoiHelper.setCellText(table, "准地价预估(万元)", null));
                 // 地块位置
                 NpoiHelper.mergeHorizontal(table, dkList.size() + 2, 0, 3);
-                table.getRow(dkList.size() + 2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块位置", optionIsBold));
+                table.getRow(dkList.size() + 2).getCell(0).setParagraph(NpoiHelper.setCellText(table, "地块位置", null));
 
                 // Table 图片
                 NpoiHelper.mergeHorizontal(table, dkList.size() + 3, 0, 3);
@@ -294,28 +249,16 @@ public class ReportServiceImpl implements IReportService {
                     cell.removeParagraph(0);
                 }
 
+                // 获取地块图片
                 String geomWkt = item.getGeom();
-                String path = reportImg(geomWkt);
+                ReportImage imageTable = getReportImage(geomWkt, 300);
 
                 // 在合并后的单元格中创建一个新的段落
                 XWPFParagraph paraImag = row.getCell(0).addParagraph();
                 paraImag.setAlignment(ParagraphAlignment.CENTER); // 居中对齐
-
-                System.out.println("图片路径path:" + path);
-
                 XWPFRun run = paraImag.createRun();
-                // File imageFile = new File("states.png");
-                File imageFile = new File(path);
-                BufferedImage bufferedImage = ImageIO.read(imageFile);
-
-                int originalWidth = bufferedImage.getWidth();
-                int originalHeight = bufferedImage.getHeight();
-
-                int useWidth = 300;
-                int useHeight = useWidth * originalHeight / originalWidth;
-
-                InputStream is = new FileInputStream(imageFile);
-                run.addPicture(is, XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(useWidth), Units.toEMU(useHeight));
+                run.addPicture(imageTable.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null,
+                        Units.toEMU(imageTable.getUseWidth()), Units.toEMU(imageTable.getUseHeight()));
             }
             File fileDoc = new File(reportPath);
             if (fileDoc.exists()) {
@@ -481,8 +424,34 @@ public class ReportServiceImpl implements IReportService {
         RequestResult requestResult = spatialService.getImage(wktsVo);
         if (requestResult.isSuccess()) {
             Map<String, String> map = (Map<String, String>) requestResult.get("data");
-            path=map.get("path");
+            path = map.get("path");
         }
         return path;
     }
+
+    /**
+     * 获取报告图片
+     *
+     * @param wkt
+     * @return
+     * @throws IOException
+     */
+    private ReportImage getReportImage(String wkt, int with) throws IOException {
+        ReportImage reportImage = new ReportImage();
+        String path = reportImg(wkt);
+
+        System.out.println("图片路径path:" + path);
+
+        InputStream is = new FileInputStream(path);
+        BufferedImage bufferedImage = ImageIO.read(new File(path));
+        int originalWidth = bufferedImage.getWidth();
+        int originalHeight = bufferedImage.getHeight();
+        int useWidth = with; // Set the desired width
+        int useHeight = useWidth * originalHeight / originalWidth;
+
+        reportImage.setInputStream(is);
+        reportImage.setUseWidth(useWidth);
+        reportImage.setUseHeight(useHeight);
+        return reportImage;
+    }
 }