|
@@ -20,16 +20,17 @@ import org.springframework.web.multipart.MultipartFile;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.awt.*;
|
|
import java.io.*;
|
|
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.nio.file.*;
|
|
|
|
+import java.nio.file.attribute.BasicFileAttributes;
|
|
import java.sql.*;
|
|
import java.sql.*;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
|
+import java.util.zip.ZipOutputStream;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class DataImp implements DataService {
|
|
public class DataImp implements DataService {
|
|
@@ -55,8 +56,19 @@ public class DataImp implements DataService {
|
|
String qgis;
|
|
String qgis;
|
|
@Value("${swid}")
|
|
@Value("${swid}")
|
|
String swid;
|
|
String swid;
|
|
|
|
+ @Value("${swarea}")
|
|
|
|
+ String swarea;
|
|
@Value("${exportFields}")
|
|
@Value("${exportFields}")
|
|
String exportFields;
|
|
String exportFields;
|
|
|
|
+ @Value("${mapExport.fixed}")
|
|
|
|
+ String mapExportFixed;
|
|
|
|
+ @Value("${mapExport.size}")
|
|
|
|
+ Integer mapExportSize;
|
|
|
|
+ @Value("${checkedstyle}")
|
|
|
|
+ String checkedstyle;
|
|
|
|
+ @Value("${spotstyle}")
|
|
|
|
+ String spotstyle;
|
|
|
|
+
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void start() {
|
|
public void start() {
|
|
@@ -66,7 +78,10 @@ public class DataImp implements DataService {
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
- public RequestResult importIn(MultipartFile file, String path, String type, String name, String ufield) {
|
|
|
|
|
|
+ public RequestResult importIn(MultipartFile file, String path, String type, String name, String ufield, String style) {
|
|
|
|
+ if (StringUtils.isEmpty(style)) {
|
|
|
|
+ style = spotstyle;
|
|
|
|
+ }
|
|
if (file == null && path == null) {
|
|
if (file == null && path == null) {
|
|
return RequestResult.error("参数未传递", null);
|
|
return RequestResult.error("参数未传递", null);
|
|
}
|
|
}
|
|
@@ -151,17 +166,40 @@ public class DataImp implements DataService {
|
|
Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
Statement statement = connection.createStatement();
|
|
Statement statement = connection.createStatement();
|
|
//增加swid字段
|
|
//增加swid字段
|
|
- String swidSql = "ALTER TABLE " + tablename + " ADD COLUMN swid TEXT";
|
|
|
|
|
|
+ String swidSql = "ALTER TABLE " + tablename + " ADD COLUMN " + swid + " TEXT";
|
|
statement.execute(swidSql);
|
|
statement.execute(swidSql);
|
|
- swidSql = "UPDATE " + tablename + " set swid = " + ufield;
|
|
|
|
|
|
+ swidSql = "UPDATE " + tablename + " set " + swid + " = " + ufield;
|
|
statement.execute(swidSql);
|
|
statement.execute(swidSql);
|
|
- //注册数据到属性表
|
|
|
|
|
|
+ //增加swarea字段
|
|
|
|
+ String swareaSql = "ALTER TABLE " + tablename + " ADD COLUMN " + swarea + " TEXT";
|
|
|
|
+ statement.execute(swareaSql);
|
|
|
|
+ swareaSql = "UPDATE " + tablename + " set " + swarea + " = round(st_area(geom), 2)";
|
|
|
|
+ statement.execute(swareaSql);
|
|
|
|
+
|
|
|
|
+ //TODO wanger 发布到geoserver
|
|
|
|
+ File shp = new File(shpPath);
|
|
|
|
+ String fileName = shp.getName();
|
|
|
|
+ int dotIndex = fileName.lastIndexOf('.');
|
|
|
|
+ String datasource = dotIndex != -1 ? fileName.substring(0, dotIndex) : fileName;
|
|
|
|
+ String querySQL = "select uri , username , password, workspace from t_geoserver ";
|
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
|
+ String geoserverurl = resultSet.getString("uri");
|
|
|
|
+ String geoserverusername = resultSet.getString("username");
|
|
|
|
+ String geoserverpassword = resultSet.getString("password");
|
|
|
|
+ String geoserverworkspace = resultSet.getString("workspace");
|
|
|
|
+ GeoServer.publishShp(geoserverurl, geoserverusername, geoserverpassword, geoserverworkspace, shpPath, style, datasource);
|
|
|
|
+ //注册数据到属性表 http://192.168.60.52:28085/geoserver/spot/wms spot:基本农田 EPSG:4525
|
|
|
|
+ String layerurl = geoserverurl + "/" + geoserverworkspace + "/wms";
|
|
|
|
+ String layername = geoserverworkspace + ":" + datasource;
|
|
|
|
+ String epsg = GeoServer.getShpEPSG(shpPath);
|
|
String insertSQL = "";
|
|
String insertSQL = "";
|
|
if ("base".equals(type)) {//管控数据
|
|
if ("base".equals(type)) {//管控数据
|
|
- insertSQL = "insert into t_base_vector (layername , tablename) values ('" + name + "', '" + tablename + "')";
|
|
|
|
|
|
+ insertSQL = "insert into t_base_vector (layername , tablename, serviceuri , servicetype, servicename, serviceproj) values ('" + name + "', '" + tablename + "', " +
|
|
|
|
+ "'" + layerurl + "', 'WMS', '" + layername + "', '" + epsg + "')";
|
|
} else if ("analyse".equals(type)) {//分析图斑
|
|
} else if ("analyse".equals(type)) {//分析图斑
|
|
// resourcesConfig.publishResourceMappingEvent(tablename, folderpath);
|
|
// resourcesConfig.publishResourceMappingEvent(tablename, folderpath);
|
|
- insertSQL = "insert into t_analyse_vector (layername , tablename, path) values ('" + name + "', '" + tablename + "', '" + folderpath + "')";
|
|
|
|
|
|
+ insertSQL = "insert into t_analyse_vector (layername , tablename, path, serviceuri , servicetype, servicename, serviceproj) values ('" + name + "', '" + tablename + "', '" + folderpath + "'," +
|
|
|
|
+ "'" + layerurl + "', 'WMS', '" + layername + "', '" + epsg + "')";
|
|
}
|
|
}
|
|
statement.execute(insertSQL);
|
|
statement.execute(insertSQL);
|
|
connection.close();
|
|
connection.close();
|
|
@@ -293,6 +331,27 @@ public class DataImp implements DataService {
|
|
return RequestResult.error("失败!", null);
|
|
return RequestResult.error("失败!", null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public RequestResult analysevectordelete(String tablename) {
|
|
|
|
+ try {
|
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
|
+ //删除主表
|
|
|
|
+ String deleteSQL = "delete from t_analyse_vector where tablename = '" + tablename + "'";
|
|
|
|
+ statement.execute(deleteSQL);
|
|
|
|
+ //删除矢量表
|
|
|
|
+ deleteSQL = "drop table " + tablename + "";
|
|
|
|
+ statement.execute(deleteSQL);
|
|
|
|
+ deleteSQL = "delete from geometry_columns where f_table_name = '" + tablename + "'";
|
|
|
|
+ statement.execute(deleteSQL);
|
|
|
|
+ connection.close();
|
|
|
|
+ return RequestResult.success("删除成功!", 1);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return RequestResult.error("失败!", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public RequestResult getShpFields(String path) {
|
|
public RequestResult getShpFields(String path) {
|
|
List<String> fields = ShpToSpatiaLite.getShpFields(path);
|
|
List<String> fields = ShpToSpatiaLite.getShpFields(path);
|
|
@@ -532,6 +591,10 @@ public class DataImp implements DataService {
|
|
cur.put("fxjssj", resultSet.getString("fxjssj"));
|
|
cur.put("fxjssj", resultSet.getString("fxjssj"));
|
|
cur.put("fxrz", resultSet.getString("fxrz"));
|
|
cur.put("fxrz", resultSet.getString("fxrz"));
|
|
cur.put("fxmodel", resultSet.getString("fxmodel"));
|
|
cur.put("fxmodel", resultSet.getString("fxmodel"));
|
|
|
|
+ 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);
|
|
res.add(cur);
|
|
}
|
|
}
|
|
connection.close();
|
|
connection.close();
|
|
@@ -564,6 +627,24 @@ public class DataImp implements DataService {
|
|
return RequestResult.error("查询失败!", null);
|
|
return RequestResult.error("查询失败!", null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public RequestResult getGeoServerStyles() {
|
|
|
|
+ try {
|
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
|
+ String querySQL = "select uri , username , password, workspace from t_geoserver ";
|
|
|
|
+ ResultSet resultSet = statement.executeQuery(querySQL);
|
|
|
|
+ List<String> styles = GeoServer.getStyles(resultSet.getString("uri"), resultSet.getString("username"),
|
|
|
|
+ resultSet.getString("password"), resultSet.getString("workspace"));
|
|
|
|
+ System.out.println(styles);
|
|
|
|
+ connection.close();
|
|
|
|
+ return RequestResult.success("查询成功!", styles);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return RequestResult.error("查询失败!", null);
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public RequestResult updateMapConfig(HttpServletRequest request) {
|
|
public RequestResult updateMapConfig(HttpServletRequest request) {
|
|
try {
|
|
try {
|
|
@@ -681,6 +762,22 @@ public class DataImp implements DataService {
|
|
// 修改数据的分析状态和结束时间
|
|
// 修改数据的分析状态和结束时间
|
|
updateSql = "update t_analyse_vector set fxzt = '2' , fxjssj = CURRENT_TIMESTAMP, fxrz = '分析正常结束' where tablename = '" + tablename + "'";
|
|
updateSql = "update t_analyse_vector set fxzt = '2' , fxjssj = CURRENT_TIMESTAMP, fxrz = '分析正常结束' where tablename = '" + tablename + "'";
|
|
statement.execute(updateSql);
|
|
statement.execute(updateSql);
|
|
|
|
+
|
|
|
|
+ //TODO 更新geoserver样式 为checkedstyle
|
|
|
|
+ querySQL = "select servicename from t_analyse_vector t where tablename = '" + tablename + "'";
|
|
|
|
+ resultSet = statement.executeQuery(querySQL);
|
|
|
|
+ String datasource = resultSet.getString("servicename");
|
|
|
|
+ querySQL = "select uri , username , password, workspace from t_geoserver ";
|
|
|
|
+ resultSet = statement.executeQuery(querySQL);
|
|
|
|
+ String geoserverurl = resultSet.getString("uri");
|
|
|
|
+ String geoserverusername = resultSet.getString("username");
|
|
|
|
+ String geoserverpassword = resultSet.getString("password");
|
|
|
|
+ String geoserverworkspace = resultSet.getString("workspace");
|
|
|
|
+ GeoServer.updateStyle(checkedstyle, geoserverurl, geoserverusername, geoserverpassword, datasource);
|
|
|
|
+
|
|
|
|
+ resultSet.close();
|
|
|
|
+ statement.close();
|
|
|
|
+ connection.close();
|
|
return RequestResult.success("分析完成!", 1);
|
|
return RequestResult.success("分析完成!", 1);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
@@ -720,6 +817,55 @@ public class DataImp implements DataService {
|
|
return RequestResult.success("导出成功", 1);
|
|
return RequestResult.success("导出成功", 1);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
+ public RequestResult exportAchievementPackage(String tablename, String layername, HttpServletRequest request, HttpServletResponse response) {
|
|
|
|
+ String folderPath = localFilePath + "" + layername + "\\" + "package";
|
|
|
|
+ String zippath = localFilePath + "" + layername + "\\package.zip";
|
|
|
|
+ File folder = new File(folderPath);
|
|
|
|
+ if (!folder.exists()) {
|
|
|
|
+ folder.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ if (Files.exists(Paths.get(zippath))) {
|
|
|
|
+ // TODO 系统打开文件夹
|
|
|
|
+ try {
|
|
|
|
+ Runtime.getRuntime().exec("explorer.exe " + folderPath);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ return RequestResult.success("导出成功", 1);
|
|
|
|
+ }
|
|
|
|
+ String excelpath = folderPath + "/" + layername + ".xlsx";
|
|
|
|
+ String shppath = folderPath + "/" + layername + ".shp";
|
|
|
|
+ try {
|
|
|
|
+ Connection connection = SpatialiteUtils.getSpatialiteConnection(dbpath);
|
|
|
|
+ Statement statement = connection.createStatement();
|
|
|
|
+ ResultSet resultSet = statement.executeQuery("select * from t_geoserver ");
|
|
|
|
+ String geoserverurl = "";
|
|
|
|
+ while (resultSet.next()) {
|
|
|
|
+ geoserverurl = resultSet.getString("uri") + "/" + resultSet.getString("workspace") + "/wms";
|
|
|
|
+ }
|
|
|
|
+ resultSet = statement.executeQuery("select path from t_analyse_vector t where tablename = '" + tablename + "' ");
|
|
|
|
+ String analysefolder = "";
|
|
|
|
+ while (resultSet.next()) {
|
|
|
|
+ analysefolder = resultSet.getString("path");
|
|
|
|
+ }
|
|
|
|
+ resultSet.close();
|
|
|
|
+ statement.close();
|
|
|
|
+ connection.close();
|
|
|
|
+ copyDirectory(Paths.get(analysefolder + "/" + qsx), Paths.get(folderPath + "/" + qsx));
|
|
|
|
+ copyDirectory(Paths.get(analysefolder + "/" + hsx), Paths.get(folderPath + "/" + hsx));
|
|
|
|
+ SpatiaLiteToShapefile.execute(dbpath, shppath, shpWkid, tablename);
|
|
|
|
+ AchievementPackage.exportAttributes(tablename, excelpath, dbpath, "EPSG:" + shpWkid, mapExportFixed, mapExportSize, geoserverurl);
|
|
|
|
+ zipDirectory(folderPath, zippath);
|
|
|
|
+ // TODO 系统打开文件夹
|
|
|
|
+ Runtime.getRuntime().exec("explorer.exe " + folderPath);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return RequestResult.error("导出失败", e.toString());
|
|
|
|
+ }
|
|
|
|
+ return RequestResult.success("导出成功", 1);
|
|
|
|
+ }
|
|
|
|
+
|
|
// 运行cmd
|
|
// 运行cmd
|
|
public String ExecuteCMD(String command) {
|
|
public String ExecuteCMD(String command) {
|
|
String res = "";
|
|
String res = "";
|
|
@@ -741,6 +887,73 @@ public class DataImp implements DataService {
|
|
return res;
|
|
return res;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void zipDirectory(String sourceDir, String zipFilePath) throws IOException {
|
|
|
|
+ Path sourcePath = Paths.get(sourceDir);
|
|
|
|
+ try (FileOutputStream fos = new FileOutputStream(zipFilePath);
|
|
|
|
+ ZipOutputStream zos = new ZipOutputStream(fos)) {
|
|
|
|
+
|
|
|
|
+ // 递归遍历目录
|
|
|
|
+ Files.walk(sourcePath).forEach(path -> {
|
|
|
|
+ // 计算文件或目录的相对路径
|
|
|
|
+ Path relativePath = sourcePath.relativize(path);
|
|
|
|
+ // 确保目录也被加入到ZIP文件中
|
|
|
|
+ if (Files.isDirectory(path)) {
|
|
|
|
+ try {
|
|
|
|
+ // 如果是目录,直接创建一个目录条目
|
|
|
|
+ zos.putNextEntry(new ZipEntry(relativePath.toString().replace("\\", "/") + "/"));
|
|
|
|
+ zos.closeEntry(); // 必须调用closeEntry(),即使只是目录
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ try (InputStream is = Files.newInputStream(path)) {
|
|
|
|
+ // 如果是文件,则创建文件条目
|
|
|
|
+ ZipEntry zipEntry = new ZipEntry(relativePath.toString().replace("\\", "/"));
|
|
|
|
+ zos.putNextEntry(zipEntry);
|
|
|
|
+
|
|
|
|
+ // 写入文件内容
|
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
|
+ int length;
|
|
|
|
+ while ((length = is.read(buffer)) > 0) {
|
|
|
|
+ zos.write(buffer, 0, length);
|
|
|
|
+ }
|
|
|
|
+ zos.closeEntry();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 递归拷贝文件夹及其内容
|
|
|
|
+ public void copyDirectory(Path sourceDir, Path targetDir) throws IOException {
|
|
|
|
+ // 如果目标目录不存在,创建目标目录
|
|
|
|
+ if (Files.notExists(targetDir)) {
|
|
|
|
+ Files.createDirectories(targetDir);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 遍历源目录的内容,并拷贝到目标目录
|
|
|
|
+ Files.walkFileTree(sourceDir, new SimpleFileVisitor<Path>() {
|
|
|
|
+ @Override
|
|
|
|
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
|
|
|
|
+ // 计算目标文件路径
|
|
|
|
+ Path targetFile = targetDir.resolve(sourceDir.relativize(file));
|
|
|
|
+ // 拷贝文件到目标目录,覆盖已存在的文件
|
|
|
|
+ Files.copy(file, targetFile, StandardCopyOption.REPLACE_EXISTING);
|
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
|
|
|
|
+ // 拷贝完目录内容后,拷贝该目录
|
|
|
|
+ Path targetDirForCurrentDir = targetDir.resolve(sourceDir.relativize(dir));
|
|
|
|
+ Files.createDirectories(targetDirForCurrentDir);
|
|
|
|
+ return FileVisitResult.CONTINUE;
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
// 将ResultSet转换为List<Map<String, Object>>
|
|
// 将ResultSet转换为List<Map<String, Object>>
|
|
public List<Map<String, Object>> resultSetToMap(ResultSet rs) throws Exception {
|
|
public List<Map<String, Object>> resultSetToMap(ResultSet rs) throws Exception {
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|