Kaynağa Gözat

报告下载

gushoubang 8 ay önce
ebeveyn
işleme
9620eb42a4

+ 69 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/domain/FzxzFactorDTO.java

@@ -0,0 +1,69 @@
+package com.onemap.analyse.domain;
+
+import com.baomidou.mybatisplus.annotation.TableField;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import lombok.Data;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+@TableName("t_fzss_fzxz_factor")
+@Data
+public class FzxzFactorDTO {
+    // id
+    private String id;
+    // 标识码
+    private String bsm;
+    // 影响因子名称
+    private String name;
+    // 目录等级
+    private Integer level;
+    // 上级标识码
+    private String parent_id;
+    // 是否包含影响值
+    @TableField("order_index")
+    @JsonIgnore
+    private Float orderIndex;
+    // 状态 1启用 2禁用
+    @JsonIgnore
+    private Integer status;
+    // 条件信息
+    @TableField("condition_info")
+    private String conditionInfo;
+
+
+    // 查找每个最后一级节点与根节点的对应关系
+    public static Map<String, FzxzFactorDTO> getLastLevelToRootMapping(List<FzxzFactorDTO> allNodes) {
+        Map<String, FzxzFactorDTO> nodeMap = new HashMap<>();
+        Map<String, FzxzFactorDTO> result = new HashMap<>();
+
+        // 构建节点ID映射
+        for (FzxzFactorDTO node : allNodes) {
+            nodeMap.put(node.id, node);
+        }
+
+        // 查找最后一级节点与根节点的对应关系
+        for (FzxzFactorDTO node : allNodes) {
+            if (isLastLevelNode(node, nodeMap)) {
+                FzxzFactorDTO rootNode = findRootNode(node, nodeMap);
+                result.put(node.id, rootNode);
+            }
+        }
+        return result;
+    }
+
+    // 判断是否为最后一级节点(没有子节点)
+    private static boolean isLastLevelNode(FzxzFactorDTO node, Map<String, FzxzFactorDTO> nodeMap) {
+        return nodeMap.values().stream().noneMatch(child -> node.id.equals(child.parent_id));
+    }
+
+    // 递归查找根节点
+    private static FzxzFactorDTO findRootNode(FzxzFactorDTO node, Map<String, FzxzFactorDTO> nodeMap) {
+        while (node.level != 0) {
+            node = nodeMap.get(node.parent_id);
+        }
+        return node;
+    }
+}

+ 14 - 0
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/mapper/FzxzFactorMapper.java

@@ -0,0 +1,14 @@
+package com.onemap.analyse.mapper;
+
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.onemap.analyse.domain.FzxzFactorDTO;
+
+/**
+ * 数据层
+ *
+ * @author onemap
+ */
+public interface FzxzFactorMapper extends BaseMapper<FzxzFactorDTO> {
+
+}

+ 4 - 3
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/FzssServiceImpl.java

@@ -282,9 +282,10 @@ public class FzssServiceImpl implements IFzssService {
         // 保存成功日志
         iLogService.saveLog(fzxzDTO.getBsm(), "辅助选址", "计算完成", "info");
 
-        // 7.生成报告,生成world文件
-        FzxzReport fzxzReport = iReportService.createReport(fzxzDTO.getBsm(), null);
-        updateFzxzReport(taskId, fzxzReport.getReportfile());
+        // TODO:暂时不需要生成报告
+        // // 7.生成报告,生成world文件
+        // FzxzReport fzxzReport = iReportService.createReport(fzxzDTO.getBsm(), null);
+        // updateFzxzReport(taskId, fzxzReport.getReportfile());
 
         // 8.开始规划,更新任务状态
         updateFzxzStatus(taskId, Rwzt.getComplete());

+ 103 - 11
onemap-modules/onemap-analyse/src/main/java/com/onemap/analyse/service/impl/ReportServiceImpl.java

@@ -1,20 +1,21 @@
 package com.onemap.analyse.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-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.*;
 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.domain.vo.TableNameIdsVo;
 import com.onemap.analyse.mapper.FactorUseMapper;
+import com.onemap.analyse.mapper.FzxzFactorMapper;
 import com.onemap.analyse.mapper.FzxzMapper;
 import com.onemap.analyse.mapper.base.FzxzResMapper;
 import com.onemap.analyse.mapper.base.ShpFileMapper;
 import com.onemap.analyse.mapper.vector.GhdkaMapper;
+import com.onemap.analyse.service.CreateUtilsDBService;
 import com.onemap.analyse.service.ILogService;
 import com.onemap.analyse.service.IReportService;
+import com.onemap.analyse.service.ITableDateService;
 import com.onemap.analyse.utils.JsonUtils;
 import com.onemap.analyse.utils.NpoiHelper;
 import com.onemap.analyse.utils.NumberUtil;
@@ -31,10 +32,12 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import javax.imageio.ImageIO;
+import java.awt.*;
 import java.awt.image.BufferedImage;
 import java.io.*;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.List;
 
 /**
  * 生成报告
@@ -50,6 +53,8 @@ public class ReportServiceImpl implements IReportService {
     private ILogService iLogService;
     @Resource
     private FactorUseMapper fzxzXzyzMapper;
+    @Resource
+    private FzxzFactorMapper fzxzFactorMapper;
 
     @Resource
     ShpFileMapper shpFileMapper;
@@ -63,6 +68,11 @@ public class ReportServiceImpl implements IReportService {
     @Resource
     SpatialService spatialService;
 
+    @Resource
+    CreateUtilsDBService createUtilsDBService;
+    @Resource
+    ITableDateService tableDateService;
+
     // 根据选址任务生成报告
     public FzxzReport createReport(String bsm, List<String> dkIds) {
         // 保存生成报告日志
@@ -82,7 +92,6 @@ public class ReportServiceImpl implements IReportService {
                 f.mkdirs();
             }
             String reportPath = "选址报告_" + timeStamp + ".docx";
-            // TODO ###选址报告耗时,暂时隐藏###
             createReport(res, allPath + "/" + reportPath, dkIds);
             // 生成返回结果
             fzxzReport.setReportfile(filePath + "/" + reportPath);
@@ -154,6 +163,22 @@ public class ReportServiceImpl implements IReportService {
             tableTitle.setAlign(ParagraphAlignment.CENTER);
             tableTitle.setWidth(2880);
             tabYzTitles.add(tableTitle);
+
+            // 获取全部的因子,用于进行因子分类
+            QueryWrapper<FzxzFactorDTO> factorWrapper = new QueryWrapper<>();
+            factorWrapper.eq("status", 1);
+            factorWrapper.orderByAsc("order_index");
+            List<FzxzFactorDTO> fzxzFactorDTOS = fzxzFactorMapper.selectList(factorWrapper);
+
+            List<FzxzFactorDTO> rootFactors = new ArrayList<>();
+            for (FzxzFactorDTO fzxzFactorDTO : fzxzFactorDTOS) {
+                if (fzxzFactorDTO.getLevel() == 0) rootFactors.add(fzxzFactorDTO);
+            }
+            // 获取最后一级节点与根节点的对应关系
+            Map<String, FzxzFactorDTO> rootMap = FzxzFactorDTO.getLastLevelToRootMapping(fzxzFactorDTOS);
+            // 因子按照大类区分
+            Map<String, List<FactorUseDTO>> factorImageMap = new HashMap<>();
+
             // 查询选址因子,并且转换为List<Map> 因子条件(包含:C、不包含:N、分析:A)
             QueryWrapper<FactorUseDTO> wrapper = new QueryWrapper<>();
             wrapper.eq("task_id", res.getBsm());
@@ -170,11 +195,45 @@ public class ReportServiceImpl implements IReportService {
                 map.put("YXYZMC", fzxzXzyzDTO.getFactorName());
                 map.put("YZTJ_TEXT", factorMap.get("YZTJ_TEXT"));
                 map.put("YXZ", factorMap.get("YXZ"));
-
                 dataTablelist.add(map);
+
+                // 添加因子图片
+                FzxzFactorDTO factorRoot = rootMap.get(fzxzXzyzDTO.getFactorBsm());
+                if (factorImageMap.containsKey(factorRoot.getId())) {
+                    factorImageMap.get(factorRoot.getId()).add(fzxzXzyzDTO);
+                } else {
+                    List<FactorUseDTO> factorUseDTOS = new ArrayList<>();
+                    factorUseDTOS.add(fzxzXzyzDTO);
+                    factorImageMap.put(factorRoot.getId(), factorUseDTOS);
+                }
             }
             NpoiHelper.setComTable(document, tabYzTitles, dataTablelist, "表1:选址影响因子", pos++);
 
+            // 生成因子图片
+            for (FzxzFactorDTO rootFactor : rootFactors) {
+                if (factorImageMap.containsKey(rootFactor.getId())) {
+                    List<FactorUseDTO> factorUseDTOS = factorImageMap.get(rootFactor.getId());
+                    List<WktsVo.WktInfo> wktInfos = new ArrayList<>();
+                    for (FactorUseDTO factorUseDTO : factorUseDTOS) {
+                        String ewkt = getFactorWkt(geomRes.getGeom(), factorUseDTO.getFactorBsm());
+
+                        Random random = new Random();
+                        int rgb = random.nextInt(0xFFFFFF + 1);
+                        String color = String.format("#%06X", rgb);
+
+
+                        WktsVo.WktInfo wktInfo = new WktsVo.WktInfo();
+                        wktInfo.setWkt(ewkt);
+                        wktInfo.setBorderColor(color);
+                        wktInfo.setBorderColor(color);
+
+                        wktInfos.add(wktInfo);
+                    }
+
+                    reportImg(wktInfos);
+                }
+            }
+
             // 添加分页
             XWPFParagraph pageBreakParagraph0 = document.createParagraph();
             XWPFRun pageBreakRun0 = pageBreakParagraph0.createRun();
@@ -193,8 +252,7 @@ public class ReportServiceImpl implements IReportService {
             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()));
+            imageRun.addPicture(reportImage.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null, Units.toEMU(reportImage.getUseWidth()), Units.toEMU(reportImage.getUseHeight()));
             pos++;
 
             // 添加分页
@@ -279,8 +337,7 @@ public class ReportServiceImpl implements IReportService {
                 XWPFParagraph paraImag = row.getCell(0).addParagraph();
                 paraImag.setAlignment(ParagraphAlignment.CENTER); // 居中对齐
                 XWPFRun run = paraImag.createRun();
-                run.addPicture(imageTable.getInputStream(), XWPFDocument.PICTURE_TYPE_PNG, null,
-                        Units.toEMU(imageTable.getUseWidth()), Units.toEMU(imageTable.getUseHeight()));
+                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()) {
@@ -438,7 +495,7 @@ public class ReportServiceImpl implements IReportService {
     }
 
     /**
-     * 导出报告图片
+     * 导出单个矢量图片
      *
      * @param wkt
      * @return
@@ -460,6 +517,26 @@ public class ReportServiceImpl implements IReportService {
         return path;
     }
 
+    /**
+     * 导出多个矢量图片
+     *
+     * @param wktInfos
+     * @return
+     */
+    private String reportImg(List<WktsVo.WktInfo> wktInfos) {
+        String path = "";
+
+        WktsVo wktsVo = new WktsVo();
+        wktsVo.setWktInfos(wktInfos);
+
+        RequestResult requestResult = spatialService.getImage(wktsVo);
+        if (requestResult.isSuccess()) {
+            Map<String, String> map = (Map<String, String>) requestResult.get("data");
+            path = map.get("path");
+        }
+        return path;
+    }
+
     /**
      * 获取报告图片
      *
@@ -485,4 +562,19 @@ public class ReportServiceImpl implements IReportService {
         reportImage.setUseHeight(useHeight);
         return reportImage;
     }
+
+    /**
+     * 获取选址因子的矢量数据
+     *
+     * @param ewkt
+     * @param tableName
+     * @return
+     */
+    private String getFactorWkt(String ewkt, String tableName) {
+        String tempName = createUtilsDBService.intersectionTableWkt(tableName, null, ewkt);
+        TableNameIdsVo tableNameIdsVo = new TableNameIdsVo();
+        tableNameIdsVo.setTableName(tempName);
+        String ewktRes = tableDateService.getGeomUnion(tableNameIdsVo);
+        return ewktRes;
+    }
 }

+ 7 - 7
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/impl/ImageServiceImpl.java

@@ -55,7 +55,7 @@ public class ImageServiceImpl implements IImageService {
 
     @Override
     public String getSensingImage(WktsVo wktsVo) throws Exception {
-        System.out.println("开始生成图片");
+        System.out.println("start getSensingImage");
         // 图片保存路径
         String fileDir = rootPath + "/images/" + StringUtils.getUUID() + "/";
         File dir = new File(fileDir);
@@ -64,19 +64,19 @@ public class ImageServiceImpl implements IImageService {
         }
         String filePath = fileDir + System.currentTimeMillis() + ".png";
 
-        System.out.println("图片地址:" + filePath);
+        System.out.println("imagePath:  " + filePath);
 
         // 创建一个 MapContent 对象
         MapContent mapContent = new MapContent();
         mapContent.setTitle("Quickstart");
 
         // 加载并添加 TIFF 栅格图层
-        System.out.println("影像地址:" + rsImage);
+        System.out.println("tifPath:  " + rsImage);
         File file = new File(rsImage);
         if (file.exists()) {
-            System.out.println("文件存在");
+            System.out.println("file exists");
         } else {
-            System.out.println("文件不存在");
+            System.out.println("file not exists");
         }
         Hints tiffHints = new Hints();
         tiffHints.add(new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE));
@@ -152,11 +152,11 @@ public class ImageServiceImpl implements IImageService {
             renderer.paint(g2d, outputArea, combinedBounds);
             ImageIO.write(bufferedImage, "png", outputImageFile);
         } catch (IOException ex) {
-            System.out.println("生成图片失败");
+            System.out.println("create image fail");
             System.out.println(ex);
             ex.printStackTrace();
         }
-        System.out.println("生成图片成功:" + filePath);
+        System.out.println("create image success:  " + filePath);
         return filePath;
     }
 

+ 1 - 0
sql/pgsql/0_init.sql

@@ -82,6 +82,7 @@ values('3029','表与服务关联管理导出', '3024', '5',  '#', '', 1, 0, 'F'
 -- 添加表
 -- vector.TB_CZKFBJ_ONE
 -- vector.TB_GYX
+-- vector.TB_FJFW
 -- 同步数据
 -- base.t_fzss_fzxz_sjy
 -- base.t_fzss_fzxz_factor_temp