Quellcode durchsuchen

先提交一版吧

wanger vor 5 Monaten
Ursprung
Commit
082d3790e5

+ 62 - 2
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/controller/DataController.java

@@ -157,9 +157,9 @@ public class DataController {
      * @return
      */
     @RequestMapping("/analysevector")
-    public RequestResult analysevector() {
+    public RequestResult analysevector(String name) {
         try {
-            return dataService.analysevector();
+            return dataService.analysevector(name);
         } catch (Exception e) {
             e.printStackTrace();
             return RequestResult.error("失败", null);
@@ -230,4 +230,64 @@ public class DataController {
             return RequestResult.error("失败", null);
         }
     }
+
+    /**
+     * 获取地图配置
+     *
+     * @return
+     */
+    @RequestMapping("/getMapConfig")
+    public RequestResult getMapConfig(String key) {
+        try {
+            return dataService.getMapConfig(key);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("失败", null);
+        }
+    }
+
+    /**
+     * 修改地图配置
+     *
+     * @return
+     */
+    @RequestMapping("/updateMapConfig")
+    public RequestResult updateMapConfig(HttpServletRequest request, HttpServletResponse response) {
+        try {
+            return dataService.updateMapConfig(request);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("失败", null);
+        }
+    }
+
+    /**
+     * 执行套合分析
+     *
+     * @return
+     */
+    @RequestMapping("/overlapAnalysis")
+    public RequestResult overlapAnalysis(String modelname, String tablename) {
+        try {
+            return dataService.overlapAnalysis(modelname, tablename);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("失败", null);
+        }
+    }
+
+    /**
+     * 导出分析报告
+     *
+     * @return
+     */
+    @RequestMapping("/exportReport")
+    public RequestResult exportReport(String modelname, String tablename, String layername, HttpServletRequest request, HttpServletResponse response) {
+        try {
+            return dataService.exportReport(modelname, tablename, layername, request, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("失败", null);
+        }
+    }
 }

+ 10 - 2
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/service/DataService.java

@@ -6,7 +6,7 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletRequest;
-import java.io.IOException;
+import javax.servlet.http.HttpServletResponse;
 
 public interface DataService {
 
@@ -18,7 +18,7 @@ public interface DataService {
 
     RequestResult basevector();
 
-    RequestResult analysevector();
+    RequestResult analysevector(String name);
 
     RequestResult modeldelete(String modelname);
 
@@ -39,4 +39,12 @@ public interface DataService {
     RequestResult getTableRecord(String tablename, Integer page, Integer limit);
 
     void start();
+
+    RequestResult getMapConfig(String key);
+
+    RequestResult updateMapConfig(HttpServletRequest request);
+
+    RequestResult overlapAnalysis(String modelname, String tablename);
+
+    RequestResult exportReport(String modelname, String tablename, String layername, HttpServletRequest request, HttpServletResponse response);
 }

+ 222 - 16
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/service/impl/DataImp.java

@@ -1,18 +1,14 @@
 package com.onemap.overlap.service.impl;
 
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.common.security.utils.SecurityUtils;
 //import com.onemap.overlap.config.ResourcesConfig;
 import com.onemap.overlap.service.DataService;
 import com.onemap.overlap.utils.*;
-import org.apache.poi.xwpf.usermodel.BreakType;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.core.io.InputStreamResource;
 import org.springframework.http.HttpHeaders;
@@ -21,19 +17,15 @@ import org.springframework.http.ResponseEntity;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.imageio.ImageIO;
-import javax.media.jai.JAI;
+import javax.servlet.ServletException;
 import javax.servlet.http.HttpServletRequest;
-import java.awt.image.RenderedImage;
+import javax.servlet.http.HttpServletResponse;
 import java.io.*;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
+import java.sql.*;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -63,6 +55,8 @@ public class DataImp implements DataService {
     String qgis;
     @Value("${swid}")
     String swid;
+    @Value("${exportFields}")
+    String exportFields;
 
     @Override
     public void start() {
@@ -142,8 +136,8 @@ public class DataImp implements DataService {
                 //TODO 用通用sql语句插入  效率慢 且 大数据插入有超长问题
                 //Boolean bool = ShpToSpatiaLite.ImportShpToSpatialite(dbpath, shpPath, shpWkid, tablename, ufield);
                 //TODO 使用QGIS的gdal环境入库
-                String command = qgis + "ogr2ogr.exe -progress -f \"SQLite\" -lco DIM=2 " + dbpath + " " + shpPath + " -overwrite -lco " +
-                        "GEOMETRY_NAME=geom -lco FID=" + swid + " -nln " + tablename + " -nlt PROMOTE_TO_MULTI -lco PRECISION=NO";
+                String command = qgis + "ogr2ogr.exe -progress -f  SQLite  -lco DIM=2 " + dbpath + " " + shpPath + " -overwrite -lco " +
+                        "GEOMETRY_NAME=geom -lco FID=id -nln " + tablename + " -nlt PROMOTE_TO_MULTI -lco PRECISION=NO";
                 String msg = ExecuteCMD(command);
                 Boolean bool = msg.contains("...");
                 if (!bool) {
@@ -156,6 +150,11 @@ public class DataImp implements DataService {
         try {
             Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
             Statement statement = connection.createStatement();
+            //增加swid字段
+            String swidSql = "ALTER TABLE " + tablename + " ADD COLUMN swid TEXT";
+            statement.execute(swidSql);
+            swidSql = "UPDATE " + tablename + " set swid = " + ufield;
+            statement.execute(swidSql);
             //注册数据到属性表
             String insertSQL = "";
             if ("base".equals(type)) {//管控数据
@@ -257,7 +256,7 @@ public class DataImp implements DataService {
                 String layername = (String) curObj.get("layername");
                 String isvalid = (String) curObj.get("isvalid");
                 String type = (String) curObj.get("type");
-                String insertSQL = "insert into t_model (layername , type, \"index\" , isvalid, modelname) values ('" + layername + "' , '" + type + "', " + i + " , '" + isvalid + "', '" + modelname + "')";
+                String insertSQL = "insert into t_model (layername , type,  index  , isvalid, modelname) values ('" + layername + "' , '" + type + "', " + i + " , '" + isvalid + "', '" + modelname + "')";
                 statement.execute(insertSQL);
             }
             connection.close();
@@ -499,6 +498,8 @@ public class DataImp implements DataService {
                 cur.put("tablename", resultSet.getString("tablename"));
                 cur.put("serviceuri", resultSet.getString("serviceuri"));
                 cur.put("servicetype", resultSet.getString("servicetype"));
+                cur.put("servicename", resultSet.getString("servicename"));
+                cur.put("serviceproj", resultSet.getString("serviceproj"));
                 res.add(cur);
             }
             connection.close();
@@ -510,11 +511,14 @@ public class DataImp implements DataService {
     }
 
     @Override
-    public RequestResult analysevector() {
+    public RequestResult analysevector(String name) {
         try {
+            if (StringUtils.isEmpty(name)) {
+                name = "";
+            }
             Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
             Statement statement = connection.createStatement();
-            String querySQL = "select * from t_analyse_vector order by inserttime desc";
+            String querySQL = "select * from t_analyse_vector where layername like '%" + name + "%'  order by inserttime desc";
             ResultSet resultSet = statement.executeQuery(querySQL);
             List<Map> res = new ArrayList<Map>();
             while (resultSet.next()) {
@@ -523,6 +527,11 @@ public class DataImp implements DataService {
                 cur.put("layername", resultSet.getString("layername"));
                 cur.put("tablename", resultSet.getString("tablename"));
                 cur.put("inserttime", resultSet.getString("inserttime"));
+                cur.put("fxzt", resultSet.getString("fxzt"));
+                cur.put("fxkssj", resultSet.getString("fxkssj"));
+                cur.put("fxjssj", resultSet.getString("fxjssj"));
+                cur.put("fxrz", resultSet.getString("fxrz"));
+                cur.put("fxmodel", resultSet.getString("fxmodel"));
                 res.add(cur);
             }
             connection.close();
@@ -533,7 +542,185 @@ public class DataImp implements DataService {
         return RequestResult.error("查询失败!", null);
     }
 
+    @Override
+    public RequestResult getMapConfig(String key) {
+        try {
+            Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
+            Statement statement = connection.createStatement();
+            String querySQL = "select name, value from t_map_config ";
+            if (StringUtils.isNotEmpty(key)) {
+                querySQL = querySQL + " where name = '" + key + "'";
+            }
+            ResultSet resultSet = statement.executeQuery(querySQL);
+            Map res = new HashMap();
+            while (resultSet.next()) {
+                res.put(resultSet.getString("name"), resultSet.getString("value"));
+            }
+            connection.close();
+            return RequestResult.success("查询成功!", res);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return RequestResult.error("查询失败!", null);
+    }
+
+    @Override
+    public RequestResult updateMapConfig(HttpServletRequest request) {
+        try {
+            JSONObject parameters = (JSONObject) new JSONParser().parse(request.getReader());
+            Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
+            Statement statement = connection.createStatement();
+            for (Object name : parameters.keySet()) {
+                Object value = parameters.get(name);
+                String updateSQL = "update t_map_config set value = '" + (String) value + "' where name = '" + (String) name + "'";
+                statement.execute(updateSQL);
+            }
+            connection.close();
+            return RequestResult.success("修改成功!", 1);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return RequestResult.error("失败!", null);
+    }
+
+    @Override
+    public RequestResult overlapAnalysis(String modelname, String tablename) {
+        try {
+            Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
+            // 创建Statement对象
+            Statement statement = connection.createStatement();
+            // 修改数据的分析状态和开始时间
+            String updateSql = "update t_analyse_vector set fxzt = '1' , fxkssj = CURRENT_TIMESTAMP, fxmodel= '" + modelname + "' where tablename = '" + tablename + "'";
+            statement.execute(updateSql);
+            try {
+                // 对分析数据新增研判结果字段
+                statement.execute("ALTER TABLE " + tablename + " ADD COLUMN 合法性判断 TEXT");
+                statement.execute("ALTER TABLE " + tablename + " ADD COLUMN 合法性说明 TEXT");
+                statement.execute("ALTER TABLE " + tablename + " ADD COLUMN 面积 TEXT");
+                statement.execute("ALTER TABLE " + tablename + " ADD COLUMN 面积集合 TEXT");
+                statement.execute("ALTER TABLE " + tablename + " ADD COLUMN 编号集合 TEXT");
+//                statement.executeBatch();
+//            statement.clearBatch();
+            } catch (Exception e) {
+
+            }
+            String resetSql = "update " + tablename + " set 合法性判断 = '' , 合法性说明 = '' , 面积 = '' , 编号集合 = '', 面积集合 = ''";
+            statement.execute(resetSql);
+            // 查询分析模型因子
+            String querySQL = "select t.type, t.layername,b.tablename from t_model t left join t_base_vector b on b.layername = t.layername  where t.modelname = '" + modelname + "' and t.isvalid = '有效' order by t.layername";
+            List<String> sqlOverlap = new ArrayList<>();
+            ResultSet resultSet = statement.executeQuery(querySQL);
+            while (resultSet.next()) {
+                String layerName = resultSet.getString("layername");
+                String tableName = resultSet.getString("tablename");
+                String type = resultSet.getString("type");
+                //TODO wanger 执行分析模型因子叠加分析
+                if (type.equals("外部")) {
+                    // 重叠部分赋值
+                    String updateOutside = "UPDATE " + tablename + " AS c  " +
+                            "SET 合法性说明 = c.合法性说明 || dd.note,面积 = c.面积 || dd.totalarea, 编号集合 = c.编号集合 || dd.targetid, 面积集合 = c.面积集合 || dd.area " +
+                            " from  " +
+                            "(SELECT " +
+                            "sss.swid AS swid, group_concat( sss.targetid, ',' ) || ';' AS targetid,  sss.note AS note, group_concat( sss.area, ',' ) || ';' AS area, round( sum( sss.area ), 2 ) || ';' AS totalarea  " +
+                            " FROM  ( " +
+                            " SELECT  c.swid,   d.swid AS targetid,  '疑似" + layerName + "内建设;' AS note, round( ST_Area ( ST_Intersection ( c.geom, d.geom ) ), 2 ) || '' AS area  " +
+                            " FROM " +
+                            "  " + tablename + " c, " +
+                            "  " + tableName + " d, " +
+                            "  idx_" + tablename + "_geom a, " +
+                            "  idx_" + tableName + "_geom b  " +
+                            " WHERE  (  a.xmax >= b.xmin   AND a.xmin <= b.xmax AND a.ymax >= b.ymin  AND a.ymin <= b.ymax  )  " +
+                            "  AND ( a.rowid = c.rowid AND b.rowid = d.rowid )  " +
+                            "  AND intersects ( c.geom, d.geom )  " +
+                            "  AND st_intersection ( c.geom, d.geom ) IS NOT NULL  " +
+                            " ORDER BY   c.swid,   d.swid  ) sss  " +
+                            "GROUP BY  sss.swid)  dd WHERE  c.swid = dd.swid;";
+                    sqlOverlap.add(updateOutside);
+                    //不重叠部分赋值
+                    String updateOutsideOther = "UPDATE " + tablename + " AS c  " +
+                            "SET 合法性说明 = c.合法性说明 || ';',面积 = c.面积 || ';', 编号集合 = c.编号集合 || ';', 面积集合 = c.面积集合 || ';'  " +
+                            " where c.swid not in  " +
+                            "(SELECT " +
+                            "sss.swid AS swid " +
+                            " FROM  ( " +
+                            " SELECT  c.swid,   d.swid AS targetid,  '疑似" + layerName + "内建设;' AS note, round( ST_Area ( ST_Intersection ( c.geom, d.geom ) ), 2 ) || '' AS area  " +
+                            " FROM " +
+                            "  " + tablename + " c, " +
+                            "  " + tableName + " d, " +
+                            "  idx_" + tablename + "_geom a, " +
+                            "  idx_" + tableName + "_geom b  " +
+                            " WHERE  (  a.xmax >= b.xmin   AND a.xmin <= b.xmax AND a.ymax >= b.ymin  AND a.ymin <= b.ymax  )  " +
+                            "  AND ( a.rowid = c.rowid AND b.rowid = d.rowid )  " +
+                            "  AND intersects ( c.geom, d.geom )  " +
+                            "  AND st_intersection ( c.geom, d.geom ) IS NOT NULL  " +
+                            " ORDER BY   c.swid,   d.swid  ) sss  " +
+                            "GROUP BY  sss.swid);";
+                    sqlOverlap.add(updateOutsideOther);
+                } else if (type.equals("内部")) {
+                    String updateInside = String.format("update   + tablename +   as c set " +
+                            "合法性说明 = case when 合法性说明 is null then '' else 合法性说明 || ';' end || '符合%s用地'," +
+                            "面积 = case when 面积 is null then '' else 面积  end || round(ST_Area(ST_Intersection(c.geom,d.geom)), 2) || ';' " +
+                            "from %s d, idx_" + tablename + "_geom a, %s b where" +
+                            "(a.xmax >= b.xmin  and a.xmin <= b.xmax and a.ymax >= b.ymin and a.ymin <= b.ymax) " +
+                            " and  ( a.rowid = c.rowid AND b.rowid = d.rowid )  " +
+                            "and intersects(c.geom, d.geom) and st_within(c.geom, d.geom);", layerName, tableName, "idx_" + tableName + "_geom");
+                    sqlOverlap.add(updateInside);
+                }
+            }
+            for (String item : sqlOverlap) {
+                System.out.println(item);
+                Boolean b = statement.execute(item);
+                System.out.println(b);
+            }
+            String updateInlegal = "update " + tablename + "  set 合法性判断 = '疑似违法'  where 合法性说明 like '%疑似%'";
+            statement.execute(updateInlegal);
+            String updateLegal = "update " + tablename + " set 合法性判断 = '合法用地'  where 合法性判断 is null or 合法性判断 = ''";
+            statement.execute(updateLegal);
+//            statement.executeBatch();
+//            statement.clearBatch();
+            // 修改数据的分析状态和结束时间
+            updateSql = "update t_analyse_vector set fxzt = '2' , fxjssj = CURRENT_TIMESTAMP, fxrz = '分析正常结束' where tablename = '" + tablename + "'";
+            statement.execute(updateSql);
+            return RequestResult.success("分析完成!", 1);
+        } catch (Exception e) {
+            e.printStackTrace();
+            Connection connection = null;
+            try {
+                connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
+                Statement statement = connection.createStatement();
+                String updateSql = "update t_analyse_vector set fxzt = '3' , fxjssj = CURRENT_TIMESTAMP, fxrz = '" + e.toString() + "' where tablename = '" + tablename + "'";
+                statement.execute(updateSql);
+                connection.close();
+            } catch (Exception exception) {
+                exception.printStackTrace();
+            }
+        }
+        return RequestResult.error("分析失败!", 0);
+    }
+
+    @Override
+    public RequestResult exportReport(String modelname, String tablename, String layername, HttpServletRequest request, HttpServletResponse response) {
+        String folderPath = localFilePath + "/" + layername + "/" + "report";
+        File folder = new File(folderPath);
+        if (!folder.exists()) {
+            folder.mkdirs();
+        }
+        String excelpath = folderPath + "/" + layername + "report.xlsx";
+        String wordpath = folderPath + "/" + layername + "report.docx";
+        try {
+            String[] exportField = exportFields.split(",");
+            ExcelExport.export(dbpath, excelpath, tablename, modelname, exportField);
+            WordExport.export(dbpath, wordpath, tablename, modelname, exportField);
+            String[] filelist = {excelpath, wordpath};
+            FileToZipDownload.download(filelist, request, response);
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("导出失败", e.toString());
+        }
+        return RequestResult.success("导出成功", 1);
+    }
 
+    // 运行cmd
     public String ExecuteCMD(String command) {
         String res = "";
         try {
@@ -553,4 +740,23 @@ public class DataImp implements DataService {
         }
         return res;
     }
+
+    // 将ResultSet转换为List<Map<String, Object>>
+    public List<Map<String, Object>> resultSetToMap(ResultSet rs) throws Exception {
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        // 获取 ResultSet 的元数据(列名信息)
+        ResultSetMetaData metaData = rs.getMetaData();
+        int columnCount = metaData.getColumnCount();
+        // 处理每一行数据
+        while (rs.next()) {
+            Map<String, Object> rowMap = new HashMap<>();
+            for (int i = 1; i <= columnCount; i++) {
+                String columnName = metaData.getColumnLabel(i); // 获取列名
+                Object columnValue = rs.getObject(i); // 获取列值
+                rowMap.put(columnName, columnValue);
+            }
+            resultList.add(rowMap);
+        }
+        return resultList;
+    }
 }

+ 2 - 1
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/service/impl/SQLiteImp.java

@@ -59,7 +59,8 @@ public class SQLiteImp implements SQLiteService {
                                 "合法性说明 = case when 合法性说明 is null then '' else 合法性说明 || ';' end || '疑似%s内建设'," +
                                 "面积 = case when 面积 is null then '' else 面积 end || ST_Area(ST_Intersection(c.geom,d.geom)) || ';' " +
                                 "from %s d, idx_当前检查图斑_geom a, %s b " +
-                                "where intersects(c.geom, d.geom) and st_intersection(c.geom,d.geom)  is not null;", layerName, layerName, "idx_" + layerName + "_geom");
+                                "where (a.xmax >= b.xmin  and a.xmin <= b.xmax and a.ymax >= b.ymin and a.ymin <= b.ymax) " +
+                                " and (a.rowid = c.rowid  and b.rowid = d.rowid) and intersects(c.geom, d.geom) and st_intersection(c.geom,d.geom)  is not null;", layerName, layerName, "idx_" + layerName + "_geom");
                         sqlOverlap.add(updateOutside);
                     } else if (type.equals("内部")) {
                         String updateInside = String.format("update 当前检查图斑 as c set " +

+ 60 - 0
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/utils/ExcelExport.java

@@ -0,0 +1,60 @@
+package com.onemap.overlap.utils;
+
+import org.apache.poi.ss.usermodel.*;
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
+
+import java.sql.*;
+import java.io.FileOutputStream;
+import java.util.Arrays;
+
+public class ExcelExport {
+    public static Boolean export(String dbpath, String filepath, String tablename, String modelname, String[] exportField) throws Exception {
+        // SQLite数据库文件路径
+//        String dbFile = "D:\\temp\\mappatchcheck.sqlite";
+        // Excel文件输出路径
+//        String excelFile = "D:\\temp\\output.xlsx";
+        //Sqlite数据表
+//        String tablename = "sw_wuchuan0705_20241224175627";
+        //导出指定的字段
+//        String[] exportField = {"编号", "后类型", "合法性判断", "合法性说明", "面积"};
+        try {
+            // 连接SQLite数据库
+            Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbpath);
+            Statement statement = connection.createStatement();
+            ResultSet resultSet = statement.executeQuery("SELECT * FROM " + tablename + "  order by 合法性判断 desc");
+            // 创建Excel工作簿和工作表
+            Workbook workbook = new XSSFWorkbook();
+            Sheet sheet = workbook.createSheet("套合分析结果");
+            // 写入标题行
+            Row header = sheet.createRow(0);
+            ResultSetMetaData metaData = resultSet.getMetaData();
+            int columnCount = metaData.getColumnCount();
+            for (int i = 0; i < exportField.length; i++) {
+                String field = exportField[i];
+                header.createCell(i).setCellValue(field);
+            }
+            // 写入数据行
+            int rowCount = 1;
+            while (resultSet.next()) {
+                Row row = sheet.createRow(rowCount++);
+                for (int i = 0; i < exportField.length; i++) {
+                    String field = exportField[i];
+                    row.createCell(i).setCellValue(resultSet.getString(field));
+                }
+            }
+            // 关闭连接和写入Excel文件
+            resultSet.close();
+            statement.close();
+            connection.close();
+            // 写入Excel文件
+            FileOutputStream outputStream = new FileOutputStream(filepath);
+            workbook.write(outputStream);
+            outputStream.close();
+            System.out.println("Excel文件已导出");
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+}

+ 47 - 0
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/utils/FileToZipDownload.java

@@ -0,0 +1,47 @@
+package com.onemap.overlap.utils;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.*;
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.*;
+
+public class FileToZipDownload {
+    public static void download(String[] filelist ,HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+        List<File> files = new ArrayList<>();
+        for(int i = 0 ; i < filelist.length ; i ++){
+            files.add(new File(filelist[i]));
+        }
+        // 设置响应内容类型和头部,表示这是一个ZIP文件
+//        response.setContentType("application/zip");
+        response.setHeader("Content-Disposition", "attachment; filename=\"report.zip\"");
+        // 使用ByteArrayOutputStream将ZIP数据直接写入响应流
+        try (ZipOutputStream zipOut = new ZipOutputStream(response.getOutputStream())) {
+            for(int i = 0 ; i < files.size() ; i ++){
+                addFileToZip(zipOut, files.get(i));
+            }
+            // 完成ZIP文件的写入
+            zipOut.finish();
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+    }
+
+    public static void addFileToZip(ZipOutputStream zipOut, File file) throws IOException {
+        try (FileInputStream fileIn = new FileInputStream(file)) {
+            // 创建ZipEntry并添加到ZipOutputStream
+            ZipEntry zipEntry = new ZipEntry(file.getName());
+            zipOut.putNextEntry(zipEntry);
+
+            // 将文件内容写入到ZIP文件
+            byte[] buffer = new byte[1024];
+            int length;
+            while ((length = fileIn.read(buffer)) > 0) {
+                zipOut.write(buffer, 0, length);
+            }
+            // 完成当前文件的写入
+            zipOut.closeEntry();
+        }
+    }
+}

+ 2 - 2
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/utils/SpatialiteUtils.java

@@ -10,12 +10,12 @@ public class SpatialiteUtils {
     public static Connection getSpatialiteConnection(String dbFile) throws Exception {
         Class.forName("org.sqlite.JDBC");
         Connection conn = null;
-        System.out.println(org.sqlite.SQLiteJDBCLoader.getVersion());
+//        System.out.println(org.sqlite.SQLiteJDBCLoader.getVersion());
         SQLiteConfig config = new SQLiteConfig();
         config.enableLoadExtension(true);
         conn = config.createConnection("jdbc:sqlite:" + dbFile);
         Statement stmt = conn.createStatement();
-        stmt.setQueryTimeout(30);
+        stmt.setQueryTimeout(30000000);
         stmt.execute("SELECT load_extension('mod_spatialite')");
         return conn;
     }

+ 136 - 0
onemap-modules/onemap-overlap/src/main/java/com/onemap/overlap/utils/WordExport.java

@@ -0,0 +1,136 @@
+package com.onemap.overlap.utils;
+
+import org.apache.poi.xwpf.usermodel.*;
+import org.apache.poi.ss.usermodel.*;
+import org.apache.xmlbeans.XmlCursor;
+
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.sql.*;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class WordExport {
+    public static Boolean export(String dbpath, String filepath, String tablename, String modelname, String[] exportField) {
+        // SQLite数据库文件路径
+//        String dbpath = "D:\\temp\\mappatchcheck.sqlite";
+//        String wordFile = "D:\\temp\\output.docx";
+        //Sqlite数据表
+//        String tablename = "sw_wuchuan0705_20241224175627";
+//        String modelname = "监测图斑审查模型";
+        //导出指定的字段
+//        String[] exportField = {"编号", "后类型", "合法性判断", "合法性说明", "面积"};
+        try {
+            // 连接SQLite数据库
+            Connection connection = DriverManager.getConnection("jdbc:sqlite:" + dbpath);
+            Statement statement = connection.createStatement();
+            // 创建一个空的Word文档
+            XWPFDocument document = new XWPFDocument();
+            // 插入标题
+            ResultSet resultSet = statement.executeQuery("select layername from t_analyse_vector t where t.tablename = '" + tablename + "'");
+            XWPFParagraph titleParagraph = document.createParagraph();
+            titleParagraph.setAlignment(ParagraphAlignment.CENTER); // 标题居中
+            XWPFRun titleRun = titleParagraph.createRun();
+            titleRun.setText(resultSet.getString("layername") + "检查报告");
+            titleRun.setBold(true); // 设置加粗
+            titleRun.setFontSize(20); // 设置字体大小
+            // 分析总览段落
+            resultSet = statement.executeQuery("select count(1) as count , 合法性判断 as type  from " + tablename + " group by 合法性判断 ");
+            Integer totalcount = 0;
+            String str = "";
+            while (resultSet.next()) {
+                Integer count = resultSet.getInt("count");
+                String type = resultSet.getString("type");
+                totalcount += count;
+                str += count + "个" + type + "图斑,";
+            }
+            String totalstr = "本次检查共计" + totalcount + "个图斑,其中" + str.substring(0, str.length() - 1) + "。";
+            XWPFParagraph textParagraph = document.createParagraph();
+            textParagraph.setIndentationFirstLine(480); // 2个字符的首行缩进(1个字符约240的单位,480表示2个字符)
+            XWPFRun textRun = textParagraph.createRun();
+            textRun.setText(totalstr);
+            // 分析图斑详情介绍
+            String querySQL = "select t.type, t.layername,b.tablename from t_model t left join t_base_vector b on b.layername = t.layername  where t.modelname = '" + modelname + "' and t.isvalid = '有效' order by t.layername";
+            List<String> sqlOverlap = new ArrayList<>();
+            resultSet = statement.executeQuery(querySQL);
+            while (resultSet.next()) {
+                sqlOverlap.add(resultSet.getString("layername"));
+            }
+            querySQL = "select * from " + tablename + " t where t.合法性判断 = '疑似违法' order by swid";
+            resultSet = statement.executeQuery(querySQL);
+            List<Map<String, Object>> resultMap = resultSetToMap(resultSet);
+            String details = "其中";
+            // 根据每一项数据进行汇总分析
+            for (int i = 0; i < sqlOverlap.size(); i++) {
+                String curLayer = sqlOverlap.get(i);
+                Integer count = 0;
+                Double totalMj = 0.0;
+                for (int u = 0; u < resultMap.size(); u++) {
+                    Map<String, Object> curMap = resultMap.get(u);
+                    String hfxsm = String.valueOf(curMap.get("合法性说明"));
+                    String mj = String.valueOf(curMap.get("面积"));
+                    if (hfxsm.contains(curLayer)) {
+                        count += 1;
+                        totalMj += Double.valueOf(mj.split(";")[i]);
+                    }
+                }
+                totalMj = totalMj / 667;
+                String formattedValue = String.format("%.2f", totalMj);
+                details += curLayer + "内疑似违法图斑" + count + "个,疑似违法面积" + formattedValue + "亩。";
+            }
+            XWPFParagraph textParagraph2 = document.createParagraph();
+            textParagraph2.setIndentationFirstLine(480); // 2个字符的首行缩进(1个字符约240的单位,480表示2个字符)
+            XWPFRun textRun2 = textParagraph2.createRun();
+            textRun2.setText(details);
+            // 插入一个表格
+            XWPFTable table = document.createTable();
+            // 设置表格居中
+            table.setTableAlignment(TableRowAlign.CENTER); // 设置表格居中
+            // 设置表格宽度占满整页
+            table.setWidth(9000); // 设置表格宽度为10000个单位,最大为10000,占满页面
+            // 在表格中添加数据
+            XWPFTableRow row1 = table.getRow(0);
+            row1.getCell(0).setText(exportField[0]);
+            for (int i = 1; i < exportField.length; i++) {
+                row1.createCell().setText(exportField[i]);
+            }
+            for (int i = 0; i < resultMap.size(); i++) {
+                XWPFTableRow row2 = table.createRow();
+                Map<String, Object> curMap = resultMap.get(i);
+                for (int u = 0; u < exportField.length; u++) {
+                    row2.getCell(u).setText(String.valueOf(curMap.get(exportField[u])));
+                }
+            }
+            // 将文档保存到本地文件
+            try (FileOutputStream out = new FileOutputStream(filepath)) {
+                document.write(out);
+            }
+            System.out.println("Word文档已生成!");
+            return true;
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        return false;
+    }
+
+    // 将ResultSet转换为List<Map<String, Object>>
+    public static List<Map<String, Object>> resultSetToMap(ResultSet rs) throws Exception {
+        List<Map<String, Object>> resultList = new ArrayList<>();
+        // 获取 ResultSet 的元数据(列名信息)
+        ResultSetMetaData metaData = rs.getMetaData();
+        int columnCount = metaData.getColumnCount();
+        // 处理每一行数据
+        while (rs.next()) {
+            Map<String, Object> rowMap = new HashMap<>();
+            for (int i = 1; i <= columnCount; i++) {
+                String columnName = metaData.getColumnLabel(i); // 获取列名
+                Object columnValue = rs.getObject(i); // 获取列值
+                rowMap.put(columnName, columnValue);
+            }
+            resultList.add(rowMap);
+        }
+        return resultList;
+    }
+}

+ 2 - 1
onemap-modules/onemap-overlap/src/main/resources/application.yml

@@ -37,4 +37,5 @@ image:
   hsx: DDOM
 # 入库到SpatiaLite数据库中的唯一属性字段
 swid: swid
-qgis: D:\Program Files\QGIS 3.34.9\bin\
+qgis: D:\Program Files\QGIS 3.34.9\bin\
+exportFields: 编号,后类型,合法性判断,合法性说明,面积