|
|
@@ -4,25 +4,35 @@ 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.CustomUtils;
|
|
|
-import com.onemap.overlap.utils.ShpToSpatiaLite;
|
|
|
-import com.onemap.overlap.utils.SpatialiteUtils;
|
|
|
-import com.onemap.overlap.utils.UnPackageUtils;
|
|
|
+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;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+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.http.HttpServletRequest;
|
|
|
-import java.io.File;
|
|
|
-import java.io.IOException;
|
|
|
+import java.awt.image.RenderedImage;
|
|
|
+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.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
@@ -33,15 +43,36 @@ import java.util.Map;
|
|
|
public class DataImp implements DataService {
|
|
|
@Value("${file.temp}")
|
|
|
String localFilePath;
|
|
|
+ @Value("${file.proxy}")
|
|
|
+ String localFileProxy;
|
|
|
+ @Value("${server.port}")
|
|
|
+ String serverport;
|
|
|
+ @Value("${server.host}")
|
|
|
+ String serverhost;
|
|
|
@Value("${file.wkid}")
|
|
|
Integer shpWkid;
|
|
|
@Value("${spatialite.filepath}")
|
|
|
String dbpath;
|
|
|
@Value("${file.prefix}")
|
|
|
String prefix;
|
|
|
+ @Value("${image.qsx}")
|
|
|
+ String qsx;
|
|
|
+ @Value("${image.hsx}")
|
|
|
+ String hsx;
|
|
|
+ @Value("${qgis}")
|
|
|
+ String qgis;
|
|
|
+ @Value("${swid}")
|
|
|
+ String swid;
|
|
|
|
|
|
@Override
|
|
|
- public RequestResult importIn(MultipartFile file, String path, String type, String name) {
|
|
|
+ public void start() {
|
|
|
+ // 在后台启动 JavaFX 窗口
|
|
|
+ new Thread(() -> WebViewExample.launchApplication(new String[0])).start();
|
|
|
+ System.out.println("JavaFX 应用启动中...");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult importIn(MultipartFile file, String path, String type, String name, String ufield) {
|
|
|
if (file == null && path == null) {
|
|
|
return RequestResult.error("参数未传递", null);
|
|
|
}
|
|
|
@@ -108,7 +139,13 @@ public class DataImp implements DataService {
|
|
|
String filename = fileName.replace(filetype, "").replace(".", "");
|
|
|
tablename = prefix + filename + "_" + currentTime;
|
|
|
try {
|
|
|
- Boolean bool = ShpToSpatiaLite.ImportShpToSpatialite(dbpath, shpPath, shpWkid, tablename);
|
|
|
+ //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 msg = ExecuteCMD(command);
|
|
|
+ Boolean bool = msg.contains("...");
|
|
|
if (!bool) {
|
|
|
return RequestResult.error("shp数据入库失败!");
|
|
|
}
|
|
|
@@ -124,6 +161,7 @@ public class DataImp implements DataService {
|
|
|
if ("base".equals(type)) {//管控数据
|
|
|
insertSQL = "insert into t_base_vector (layername , tablename) values ('" + name + "', '" + tablename + "')";
|
|
|
} else if ("analyse".equals(type)) {//分析图斑
|
|
|
+// resourcesConfig.publishResourceMappingEvent(tablename, folderpath);
|
|
|
insertSQL = "insert into t_analyse_vector (layername , tablename, path) values ('" + name + "', '" + tablename + "', '" + folderpath + "')";
|
|
|
}
|
|
|
statement.execute(insertSQL);
|
|
|
@@ -214,7 +252,7 @@ public class DataImp implements DataService {
|
|
|
Statement statement = connection.createStatement();
|
|
|
String deleteSQL = "delete from t_model where modelname = '" + modelname + "'";
|
|
|
statement.execute(deleteSQL);
|
|
|
- for(int i = 0 ; i < details.size() ; i ++){
|
|
|
+ for (int i = 0; i < details.size(); i++) {
|
|
|
JSONObject curObj = (JSONObject) details.get(i);
|
|
|
String layername = (String) curObj.get("layername");
|
|
|
String isvalid = (String) curObj.get("isvalid");
|
|
|
@@ -256,6 +294,196 @@ public class DataImp implements DataService {
|
|
|
return RequestResult.error("失败!", null);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public RequestResult getShpFields(String path) {
|
|
|
+ List<String> fields = ShpToSpatiaLite.getShpFields(path);
|
|
|
+ return RequestResult.success("查询成功", fields);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseEntity<InputStreamResource> getTiff(String tiftype, String tableid, String uuid, String filetype) {
|
|
|
+ Connection connection = null;
|
|
|
+ String folderpath = "";
|
|
|
+ try {
|
|
|
+ connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String selectSQL = "select path from t_analyse_vector where id = '" + tableid + "'";
|
|
|
+ ResultSet resultSet = statement.executeQuery(selectSQL);
|
|
|
+ while (resultSet.next()) {
|
|
|
+ folderpath = resultSet.getString("path");
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ if (StringUtils.isEmpty(folderpath)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ String filepath = folderpath + "\\" + tiftype + "\\" + uuid + tiftype + "." + filetype;
|
|
|
+ File file = new File(filepath); // 文件路径
|
|
|
+ InputStream tiffInputStream = null;
|
|
|
+ try {
|
|
|
+ tiffInputStream = new FileInputStream(file);
|
|
|
+ } catch (FileNotFoundException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ // 返回 TIFF 数据流
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ if ("tif".equals(filetype)) {
|
|
|
+ headers.add(HttpHeaders.CONTENT_TYPE, "image/tiff");
|
|
|
+ } else if ("png".equals(filetype)) {
|
|
|
+ headers.add(HttpHeaders.CONTENT_TYPE, "image/png");
|
|
|
+ }
|
|
|
+ headers.add(HttpHeaders.CONTENT_LENGTH, String.valueOf(file.length()));
|
|
|
+ headers.add(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=image.tif");
|
|
|
+ return ResponseEntity.status(HttpStatus.PARTIAL_CONTENT)
|
|
|
+ .headers(headers)
|
|
|
+ .body(new InputStreamResource(tiffInputStream));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult getImageUrls(String tableid, String uuid) {
|
|
|
+ // 判读前时相数据有没有
|
|
|
+ String qsxfilepath = localFilePath + "\\" + tableid + "\\" + uuid + qsx + ".tif";
|
|
|
+ File file = new File(qsxfilepath);
|
|
|
+ if (!file.exists()) {
|
|
|
+ //执行文件拷贝
|
|
|
+ try {
|
|
|
+ // 指定要创建的目录路径
|
|
|
+ String directoryPath = localFilePath + "\\" + tableid;
|
|
|
+ // 创建File对象
|
|
|
+ File directory = new File(directoryPath);
|
|
|
+ // 如果目录不存在,则创建它
|
|
|
+ if (!directory.exists()) {
|
|
|
+ boolean result = directory.mkdirs();
|
|
|
+ if (result) {
|
|
|
+ System.out.println("目录创建成功:" + directoryPath);
|
|
|
+ } else {
|
|
|
+ System.out.println("目录创建失败:" + directoryPath);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("目录已存在:" + directoryPath);
|
|
|
+ }
|
|
|
+ Connection connection = null;
|
|
|
+ String folderpath = "";
|
|
|
+ connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String selectSQL = "select path from t_analyse_vector where id = '" + tableid + "'";
|
|
|
+ ResultSet resultSet = statement.executeQuery(selectSQL);
|
|
|
+ while (resultSet.next()) {
|
|
|
+ folderpath = resultSet.getString("path");
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ if (StringUtils.isEmpty(folderpath)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ // 前时相
|
|
|
+ Path qsxpath = Paths.get(folderpath + "\\" + qsx + "\\" + uuid + qsx + ".tif");
|
|
|
+ Path qsxtarget = Paths.get(qsxfilepath);
|
|
|
+ Files.copy(qsxpath, qsxtarget, StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ // 后时相
|
|
|
+ Path hsxpath = Paths.get(folderpath + "\\" + hsx + "\\" + uuid + hsx + ".tif");
|
|
|
+ Path hsxtarget = Paths.get(localFilePath + "\\" + tableid + "\\" + uuid + hsx + ".tif");
|
|
|
+ Files.copy(hsxpath, hsxtarget, StandardCopyOption.REPLACE_EXISTING);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Map res = new HashMap();
|
|
|
+ res.put("qsx", serverhost + ":" + serverport + "/" + localFileProxy + "/" + tableid + "/" + uuid + qsx + ".tif");
|
|
|
+ res.put("hsx", serverhost + ":" + serverport + "/" + localFileProxy + "/" + tableid + "/" + uuid + hsx + ".tif");
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult getTableGeoms(String tablename) {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select swid , astext(geom) as geom from " + tablename;
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ List<Map> res = new ArrayList<Map>();
|
|
|
+ while (resultSet.next()) {
|
|
|
+ Map cur = new HashMap();
|
|
|
+ cur.put("swid", resultSet.getString("swid"));
|
|
|
+ cur.put("geom", resultSet.getString("geom"));
|
|
|
+ res.add(cur);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult getFeatureBySwid(String tablename, String swid) {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select * from " + tablename + " where swid = '" + swid + "'";
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ ResultSetMetaData metaData = resultSet.getMetaData();
|
|
|
+ int columnCount = metaData.getColumnCount();
|
|
|
+ List<Map> res = new ArrayList<Map>();
|
|
|
+ while (resultSet.next()) {
|
|
|
+ Map cur = new HashMap();
|
|
|
+ for (int i = 1; i <= columnCount; i++) {
|
|
|
+ if (!"geom".equals(metaData.getColumnName(i))) {
|
|
|
+ cur.put(metaData.getColumnName(i), resultSet.getObject(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.add(cur);
|
|
|
+ }
|
|
|
+ connection.close();
|
|
|
+ return RequestResult.success("查询成功!", res);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public RequestResult getTableRecord(String tablename, Integer page, Integer limit) {
|
|
|
+ try {
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
+ String querySQL = "select * from " + tablename + " order by swid LIMIT " + limit + " OFFSET " + ((page - 1) * limit);
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
+ ResultSetMetaData metaData = resultSet.getMetaData();
|
|
|
+ int columnCount = metaData.getColumnCount();
|
|
|
+ List<Map> res = new ArrayList<Map>();
|
|
|
+ List<String> fields = new ArrayList<>();
|
|
|
+ for (int i = 1; i <= columnCount; i++) {
|
|
|
+ if (!"geom".equals(metaData.getColumnName(i))) {
|
|
|
+ fields.add(metaData.getColumnName(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ while (resultSet.next()) {
|
|
|
+ Map cur = new HashMap();
|
|
|
+ for (int i = 1; i <= columnCount; i++) {
|
|
|
+ if (!"geom".equals(metaData.getColumnName(i))) {
|
|
|
+ cur.put(metaData.getColumnName(i), resultSet.getObject(i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ res.add(cur);
|
|
|
+ }
|
|
|
+ String countSQL = "select count(1) as count from " + tablename;
|
|
|
+ ResultSet countSet = statement.executeQuery(countSQL);
|
|
|
+ Integer count = countSet.getInt("count");
|
|
|
+ connection.close();
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("count", count);
|
|
|
+ result.put("record", res);
|
|
|
+ result.put("fields", fields);
|
|
|
+ return RequestResult.success("查询成功!", result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public RequestResult basevector() {
|
|
|
try {
|
|
|
@@ -306,4 +534,23 @@ public class DataImp implements DataService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+ public String ExecuteCMD(String command) {
|
|
|
+ String res = "";
|
|
|
+ try {
|
|
|
+ // 执行命令
|
|
|
+ Process process = Runtime.getRuntime().exec(command);
|
|
|
+ // 获取命令输出
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
|
+ String line;
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ System.out.println(line); // 输出命令结果
|
|
|
+ res = line;
|
|
|
+ }
|
|
|
+ // 等待命令执行结束
|
|
|
+ process.waitFor();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return res;
|
|
|
+ }
|
|
|
}
|