|
@@ -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;
|
|
|
+ }
|
|
|
}
|