Quellcode durchsuchen

三亚shp文件处理接口修改,file服务的pox文件替换

LAPTOP-BJJ3IV5R\SIWEI vor 7 Monaten
Ursprung
Commit
24ac1e80c6
18 geänderte Dateien mit 299 neuen und 195 gelöschten Zeilen
  1. 5 2
      onemap-api/onemap-api-system/src/main/java/com/onemap/system/api/SpatialService.java
  2. 5 0
      onemap-api/onemap-api-system/src/main/java/com/onemap/system/api/factory/SpatialFallbackFactory.java
  3. 106 161
      onemap-modules/onemap-file/pom.xml
  4. 0 2
      onemap-modules/onemap-file/src/main/java/com/onemap/file/OneMapFileApplication.java
  5. 27 0
      onemap-modules/onemap-file/src/main/java/com/onemap/file/controller/SysFileController.java
  6. 11 1
      onemap-modules/onemap-file/src/main/java/com/onemap/file/service/ISysFileService.java
  7. 14 0
      onemap-modules/onemap-file/src/main/java/com/onemap/file/service/SaveFileService.java
  8. 83 7
      onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/LocalSysFileServiceImpl.java
  9. 19 0
      onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/SaveFileImpl.java
  10. 1 1
      onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/JSON2Shape.java
  11. 1 3
      onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/ParsingShpFileUtils.java
  12. 2 2
      onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/WktUtils.java
  13. 4 3
      onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/controller/ShpController.java
  14. 1 1
      onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/IShpFileSaveService.java
  15. 15 8
      onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/impl/ShpFileSaveServiceImpl.java
  16. 2 1
      onemap-modules/onemap-system/src/main/java/com/onemap/system/controller/TTableFiledRelationController.java
  17. 1 1
      onemap-modules/onemap-system/src/main/java/com/onemap/system/service/ITTableFiledRelationService.java
  18. 2 2
      onemap-modules/onemap-system/src/main/java/com/onemap/system/service/impl/TTableFiledRelationServiceImpl.java

+ 5 - 2
onemap-api/onemap-api-system/src/main/java/com/onemap/system/api/SpatialService.java

@@ -5,8 +5,8 @@ import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.system.api.domain.WktsVo;
 import com.onemap.system.api.factory.SpatialFallbackFactory;
 import org.springframework.cloud.openfeign.FeignClient;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.cloud.openfeign.SpringQueryMap;
+import org.springframework.web.bind.annotation.*;
 
 /**
  * 分析服务
@@ -15,4 +15,7 @@ import org.springframework.web.bind.annotation.RequestBody;
 public interface SpatialService {
     @PostMapping("/image/sensing")
     RequestResult getImage(@RequestBody WktsVo wktsVo);
+
+    @GetMapping("/shp/read/file")
+    RequestResult shpReadFile(@RequestParam("filepath") String filepath);
 }

+ 5 - 0
onemap-api/onemap-api-system/src/main/java/com/onemap/system/api/factory/SpatialFallbackFactory.java

@@ -19,6 +19,11 @@ public class SpatialFallbackFactory implements FallbackFactory<SpatialService> {
             public RequestResult getImage(WktsVo wktsVo) {
                 return RequestResult.error("内部错误");
             }
+
+            @Override
+            public RequestResult shpReadFile(String filepath) {
+                return RequestResult.error("内部错误");
+            }
         };
     }
 }

+ 106 - 161
onemap-modules/onemap-file/pom.xml

@@ -9,6 +9,12 @@
         <version>3.6.1</version>
     </parent>
 
+    <properties>
+        <org.geotools.version>26.0</org.geotools.version>
+        <org.postgresql.version>42.3.6</org.postgresql.version>
+    </properties>
+
+
     <artifactId>onemap-modules-file</artifactId>
 
     <description>
@@ -16,228 +22,144 @@
     </description>
 
     <dependencies>
+        <!--common-->
         <!-- RuoYi Common DataSource -->
         <dependency>
             <groupId>com.onemap</groupId>
             <artifactId>onemap-common-datasource</artifactId>
         </dependency>
-
         <!-- RuoYi Common DataScope -->
         <dependency>
             <groupId>com.onemap</groupId>
             <artifactId>onemap-common-datascope</artifactId>
         </dependency>
-        <!-- SpringCloud Alibaba Nacos -->
-        <dependency>
-            <groupId>com.alibaba.cloud</groupId>
-            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
-        </dependency>
 
-        <!-- SpringCloud Alibaba Nacos Config -->
+        <!--spring-->
         <dependency>
-            <groupId>com.alibaba.cloud</groupId>
-            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
+            <groupId>org.springframework</groupId>
+            <artifactId>spring-web</artifactId>
         </dependency>
-
-        <!-- SpringCloud Alibaba Sentinel -->
         <dependency>
-            <groupId>com.alibaba.cloud</groupId>
-            <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId>
+            <groupId>org.projectlombok</groupId>
+            <artifactId>lombok</artifactId>
         </dependency>
-
-        <!-- SpringBoot Actuator -->
         <dependency>
             <groupId>org.springframework.boot</groupId>
-            <artifactId>spring-boot-starter-actuator</artifactId>
-        </dependency>
-
-        <!-- FastDFS -->
-        <dependency>
-            <groupId>com.github.tobato</groupId>
-            <artifactId>fastdfs-client</artifactId>
+            <artifactId>spring-boot-starter-web</artifactId>
         </dependency>
 
-        <!-- Minio -->
+        <!--pg库-->
         <dependency>
-            <groupId>io.minio</groupId>
-            <artifactId>minio</artifactId>
-            <version>${minio.version}</version>
+            <groupId>org.postgresql</groupId>
+            <artifactId>postgresql</artifactId>
+            <version>${org.postgresql.version}</version>
         </dependency>
 
-        <!-- 解压rar -->
+        <!--mybatis-plus-->
         <dependency>
-            <groupId>com.github.junrar</groupId>
-            <artifactId>junrar</artifactId>
-            <version>0.7</version>
-        </dependency>
-
-        <!-- 远程调用 -->
-        <dependency>
-            <groupId>org.springframework.cloud</groupId>
-            <artifactId>spring-cloud-starter-openfeign</artifactId>
-        </dependency>
-
-        <!--zip4j依赖,解压zip压缩-->
-        <dependency>
-            <groupId>net.lingala.zip4j</groupId>
-            <artifactId>zip4j</artifactId>
-            <version>1.3.2</version>
-        </dependency>
-        <dependency>
-            <groupId>org.apache.ant</groupId>
-            <artifactId>ant</artifactId>
-            <version>1.9.4</version>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-core</artifactId>
+            <version>3.5.2</version>
             <scope>compile</scope>
         </dependency>
-        <!--        <dependency>-->
-        <!--            <groupId>org.gdal</groupId>-->
-        <!--            <artifactId>gdal</artifactId>-->
-        <!--            <version>3.3.0</version>-->
-        <!--        </dependency>-->
-        <!--   ejml     -->
-        <dependency>
-            <groupId>ejml-core</groupId>
-            <artifactId>core</artifactId>
-            <scope>system</scope>
-            <version>0.39</version>
-            <systemPath>${project.basedir}/lib/ejml-core-0.39.jar</systemPath>
-        </dependency>
+
+        <!--geotools-->
         <dependency>
-            <groupId>ejml-ddense</groupId>
-            <artifactId>core</artifactId>
-            <scope>system</scope>
-            <version>0.32</version>
-            <systemPath>${project.basedir}/lib/ejml-ddense-0.32.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-main</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
-        <!--   geotools     -->
         <dependency>
-            <groupId>gt-api</groupId>
-            <artifactId>gt-api</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-api-19.2.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-cql</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-data</groupId>
-            <artifactId>gt-data</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-data-19.2.jar</systemPath>
+            <groupId>org.geotools.jdbc</groupId>
+            <artifactId>gt-jdbc-postgis</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-geotools</groupId>
-            <artifactId>geojson</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-geojson-19.2.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-coverage</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-main</groupId>
-            <artifactId>gt-main</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-main-19.2.jar</systemPath>
-        </dependency>
-        <dependency>
-            <groupId>gt-metadata</groupId>
-            <artifactId>gt-metadata</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-metadata-19.2.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-render</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-opengis</groupId>
+            <groupId>org.geotools</groupId>
             <artifactId>gt-opengis</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-opengis-19.2.jar</systemPath>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-referencing</groupId>
+            <groupId>org.geotools</groupId>
             <artifactId>gt-referencing</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-referencing-19.2.jar</systemPath>
-        </dependency>
-        <dependency>
-            <groupId>gt-render</groupId>
-            <artifactId>gt-render</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-render-19.2.jar</systemPath>
-        </dependency>
-        <dependency>
-            <groupId>gt-shapefile</groupId>
-            <artifactId>gt-shapefile</artifactId>
-            <scope>system</scope>
-            <version>19.2</version>
-            <systemPath>${project.basedir}/lib/gt-shapefile-19.2.jar</systemPath>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-jts</groupId>
-            <artifactId>gt-jts</artifactId>
-            <scope>system</scope>
-            <version>1.13</version>
-            <systemPath>${project.basedir}/lib/jts-1.13.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-geojson</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>gt-jsr</groupId>
-            <artifactId>gt-jsr</artifactId>
-            <scope>system</scope>
-            <version>1.0</version>
-            <systemPath>${project.basedir}/lib/jsr-275-1.0-beta-2.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-geotiff</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>json</groupId>
-            <artifactId>json</artifactId>
-            <scope>system</scope>
-            <version>1.1</version>
-            <systemPath>${project.basedir}/lib/json-simple-1.1.jar</systemPath>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-swing</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>org.apache.commons</groupId>
-            <artifactId>commons-lang3</artifactId>
-            <version>3.8.1</version>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-shapefile</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
-        <!--    解析shp    -->
         <dependency>
-            <groupId>com.google.code.gson</groupId>
-            <artifactId>gson</artifactId>
-            <version>2.8.5</version>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-tile-client</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>commons-lang</groupId>
-            <artifactId>commons-lang</artifactId>
-            <version>2.6</version>
+            <groupId>org.geotools</groupId>
+            <artifactId>gt-epsg-hsql</artifactId>
+            <version>${org.geotools.version}</version>
         </dependency>
         <dependency>
-            <groupId>com.alibaba</groupId>
-            <artifactId>fastjson</artifactId>
-            <version>1.2.7</version>
+            <groupId>org.locationtech.jts</groupId>
+            <artifactId>jts-core</artifactId>
+            <version>1.19.0</version>
         </dependency>
+
+        <!-- SpringCloud Alibaba Nacos -->
         <dependency>
-            <groupId>org.apache.tomcat.embed</groupId>
-            <artifactId>tomcat-embed-core</artifactId>
-            <version>9.0.56</version>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
         </dependency>
 
+        <!-- SpringCloud Alibaba Nacos Config -->
         <dependency>
-            <groupId>org.reflections</groupId>
-            <artifactId>reflections</artifactId>
-            <version>0.9.10</version>
+            <groupId>com.alibaba.cloud</groupId>
+            <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
         </dependency>
 
-        <!-- RuoYi Api System -->
+        <!-- Minio -->
         <dependency>
-            <groupId>com.onemap</groupId>
-            <artifactId>onemap-api-system</artifactId>
+            <groupId>io.minio</groupId>
+            <artifactId>minio</artifactId>
+            <version>${minio.version}</version>
         </dependency>
 
-        <!-- RuoYi Common Swagger -->
         <dependency>
-            <groupId>com.onemap</groupId>
-            <artifactId>onemap-common-swagger</artifactId>
+            <groupId>com.alibaba</groupId>
+            <artifactId>fastjson</artifactId>
+            <version>1.2.7</version>
         </dependency>
+
         <!--word转pdf-->
         <dependency>
             <groupId>e-iceblue</groupId>
@@ -246,18 +168,41 @@
             <version>5.2.0</version>
             <systemPath>${project.basedir}/lib/spire.doc.free-5.2.0.jar</systemPath>
         </dependency>
+
     </dependencies>
+
+    <repositories>
+        <repository>
+            <id>osgeo</id>
+            <name>OSGeo Release Repository</name>
+            <url>https://repo.osgeo.org/repository/release/</url>
+            <snapshots>
+                <enabled>false</enabled>
+            </snapshots>
+            <releases>
+                <enabled>true</enabled>
+            </releases>
+        </repository>
+        <repository>
+            <id>osgeo-snapshot</id>
+            <name>OSGeo Snapshot Repository</name>
+            <url>https://repo.osgeo.org/repository/snapshot/</url>
+            <snapshots>
+                <enabled>true</enabled>
+            </snapshots>
+            <releases>
+                <enabled>false</enabled>
+            </releases>
+        </repository>
+    </repositories>
+
     <build>
         <finalName>${project.artifactId}</finalName>
         <plugins>
             <plugin>
-                <configuration>
-                    <includeSystemScope>true</includeSystemScope>
-                    <fork>true</fork> <!--重要-->
-                </configuration>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
-                <version>2.7.1</version>
+                <version>2.6.2</version>
                 <executions>
                     <execution>
                         <goals>

+ 0 - 2
onemap-modules/onemap-file/src/main/java/com/onemap/file/OneMapFileApplication.java

@@ -19,8 +19,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
 @EnableCustomSwagger2
 @EnableRyFeignClients
 @SpringBootApplication
-@EnableFeignClients(basePackages = "com.onemap.file.controller")
-@MapperScan("com.onemap.file.mapper")
 public class OneMapFileApplication {
     public static void main(String[] args) {
         SpringApplication.run(OneMapFileApplication.class, args);

+ 27 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/controller/SysFileController.java

@@ -185,4 +185,31 @@ public class SysFileController {
             return null;
         }
     }
+
+
+    /**
+     * 根空间相关的上传出来
+     * 现支持shp的zip包,ewkt字符串
+     *
+     * @param file      shp的zip文件
+     * @param fromType  上传的类型 1 ewkt 2 shp的zip文件
+     * @param geom      wkt字符串(如果没设置srid,默认为4326)
+     * @param fromRoute 来源
+     */
+    @PostMapping("/upload/geom")
+    public RequestResult geomAdd(MultipartFile file, Integer fromType, String geom, String fromRoute) {
+        try {
+            RequestResult res = null;
+            if (fromType == 1) {
+                String id = saveFileService.saveDraw(geom, fromRoute);
+                res = RequestResult.success("上传成功", saveFileService.getById(id));
+            } else {
+                res = sysFileService.uploadAddShpFile(file, fromRoute);
+            }
+            return res;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RequestResult.error("上传失败!", null);
+        }
+    }
 }

+ 11 - 1
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/ISysFileService.java

@@ -29,11 +29,21 @@ public interface ISysFileService {
      */
     String uploadAppendix(MultipartFile file) throws Exception;
 
-    RequestResult  uploadShpZip(MultipartFile file,String fromRoute) throws Exception;
+    RequestResult uploadShpZip(MultipartFile file, String fromRoute) throws Exception;
 
     String getShpGeoJson(String shppath);
 
     UploadZipDTO uploadZip(MultipartFile file);
 
     String splitFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("chunk") int chunk, @RequestParam("chunks") int chunks, @RequestParam("name") String name, @RequestParam("md5") String md5);
+
+    /**
+     * 将解析数据单独保存到表中
+     * @param file
+     * @param fromRoute
+     * @return
+     * @throws Exception
+     */
+    RequestResult uploadAddShpFile(MultipartFile file, String fromRoute) throws Exception;
+
 }

+ 14 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/SaveFileService.java

@@ -1,11 +1,25 @@
 package com.onemap.file.service;
 
+import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.file.domain.res.GeomRes;
+import org.springframework.web.multipart.MultipartFile;
 
 public interface SaveFileService {
     String saveShpFile(String shpPath, String zippath, String fromRoute) throws Exception;
 
+    String saveShpFileNew(String shpPath, String zippath, String fromRoute) throws Exception;
+
     String saveDraw(String geom, String fromRoute);
 
     GeomRes getById(String id);
+
+    /**
+     * 将解析数据单独保存到表中
+     *
+     * @param geom
+     * @param fromRoute
+     * @return
+     * @throws Exception
+     */
+//    RequestResult uploadAddShpGeom(String geom, String fromRoute) throws Exception;
 }

+ 83 - 7
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/LocalSysFileServiceImpl.java

@@ -9,6 +9,7 @@ import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.file.service.ISysFileService;
 import com.onemap.file.service.SaveFileService;
 import com.onemap.file.utils.*;
+import com.onemap.system.api.SpatialService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Primary;
@@ -17,9 +18,11 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
 
+import javax.annotation.processing.FilerException;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -73,6 +76,9 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     @Autowired
     private SaveFileService saveFileService;
 
+    @Autowired
+    private SpatialService spatialService;
+
     /**
      * 本地文件上传接口
      *
@@ -190,7 +196,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     }
 
     @Override
-    public RequestResult uploadShpZip(MultipartFile file,String fromRoute) throws Exception {
+    public RequestResult uploadShpZip(MultipartFile file, String fromRoute) throws Exception {
         // 获得文件名称
         String fileName = file.getOriginalFilename();
         // 获得文件后缀名
@@ -220,6 +226,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
             // 解压rar格式
             new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
         }
+
         File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
         for (File file1 : files) {
             List<File> shpFiles = new ArrayList<>();
@@ -228,12 +235,13 @@ public class LocalSysFileServiceImpl implements ISysFileService {
                 shpPath = shpFiles.get(0).getPath();
             }
         }
-        if (!"".equals(shpPath)) {
-            String id = saveFileService.saveShpFile(shpPath, dest.getPath(),fromRoute);
-            return RequestResult.success("上传成功", saveFileService.getById(id));
-        } else {
-            return RequestResult.error("未检索到shp文件");
-        }
+//        if (!"".equals(shpPath)) {
+//            String id = saveFileService.saveShpFile(shpPath, dest.getPath(), fromRoute);
+//            return RequestResult.success("上传成功", saveFileService.getById(id));
+//        } else {
+//            return RequestResult.error("未检索到shp文件");
+//        }
+        return RequestResult.success("上传成功", 0);
     }
 
     /**
@@ -314,4 +322,72 @@ public class LocalSysFileServiceImpl implements ISysFileService {
         }
         return null;
     }
+
+    private void uploadDestMultipartFile(MultipartFile file, String destPath) throws IOException {
+        String fileName = file.getOriginalFilename();
+        // 获得文件后缀名
+        String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
+        // 判断上传的是否是压缩包
+        if (!type.equals("zip") && !type.equals("rar")) {
+            throw new FilerException("请上传压缩包");
+        }
+        //新文件
+        File newFile = new File(destPath + "/" + fileName);
+        //新文件的上级目录
+        File dir = newFile.getParentFile();
+        // 判断是否,并创建文件夹
+        if (!dir.exists()) {
+            dir.mkdirs();
+        }
+
+        //将文件复制到新文件
+//        file.transferTo(newFile);
+        Files.copy(file.getInputStream(), newFile.toPath());
+
+        // 解压zip格式
+        if (type.equals("zip")) {
+            new UnPackageUtils().unPackZip(newFile, destPath);
+        } else {
+            // 解压rar格式
+            new UnPackageUtils().unPackRar(newFile, destPath);
+        }
+    }
+
+    public RequestResult uploadAddShpFile(MultipartFile file, String fromRoute) throws Exception {
+        // 获取当前时间的时间戳
+        long timeMillis = System.currentTimeMillis();
+        //生成SHP解压文件路径
+        String shpPath = shpLocalFilePath + "/temp" + "/" + timeMillis;
+        //解压文件
+        uploadDestMultipartFile(file, shpPath);
+
+        String newShpPath = null;
+        File[] files = new File(shpPath).listFiles();
+        for (File file1 : files) {
+            List<File> shpFiles = new ArrayList<>();
+            FileUtils.findShpFiles(file1, shpFiles);
+            if (shpFiles.size() != 0) {
+                newShpPath = shpFiles.get(0).getPath();
+            }
+        }
+        if (StringUtils.isEmpty(newShpPath)) {
+            return RequestResult.error("未读取到SHP文件");
+        }
+        RequestResult res = spatialService.shpReadFile(shpPath);
+        if (!res.isSuccess()) {
+            return res;
+        }
+        String tableID = (String) res.get(RequestResult.DATA_TAG);
+        String id = saveFileService.saveShpFile(shpPath, tableID, fromRoute);
+
+
+//        if (!"".equals(shpPath)) {
+//            String id = saveFileService.saveShpFile(shpPath, dest.getPath(), fromRoute);
+//            return RequestResult.success("上传成功", saveFileService.getById(id));
+//        } else {
+//            return RequestResult.error("未检索到shp文件");
+//        }
+        return null;
+    }
+
 }

+ 19 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/SaveFileImpl.java

@@ -38,6 +38,25 @@ public class SaveFileImpl implements SaveFileService {
         return uuid;
     }
 
+    @Override
+    @Master
+    public String saveShpFile(String shpPath, String zippath, String fromRoute) throws Exception {
+        String ewkt = WktUtils.getShpWkt(shpPath);
+
+        GeomResourceDTO geomResourceDTO = new GeomResourceDTO();
+
+        String uuid = StringUtils.getUUID();
+        geomResourceDTO.setId(uuid);
+        geomResourceDTO.setZippath(zippath);
+        geomResourceDTO.setFilepath(shpPath);
+        geomResourceDTO.setGeom(ewkt);
+        geomResourceDTO.setFromType(2);
+        geomResourceDTO.setFromRoute(fromRoute);
+
+        zhxzFileMapper.saveGeom(geomResourceDTO);
+        return uuid;
+    }
+
     @Override
     @Master
     public String saveDraw(String geom, String fromRoute) {

+ 1 - 1
onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/JSON2Shape.java

@@ -1,7 +1,6 @@
 package com.onemap.file.utils;
 
 import com.alibaba.fastjson.JSONObject;
-import com.vividsolutions.jts.geom.*;
 import org.geotools.data.FeatureWriter;
 import org.geotools.data.Transaction;
 import org.geotools.data.shapefile.ShapefileDataStore;
@@ -9,6 +8,7 @@ import org.geotools.data.shapefile.ShapefileDataStoreFactory;
 import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
 import org.geotools.geojson.geom.GeometryJSON;
 import org.geotools.referencing.crs.DefaultGeographicCRS;
+import org.locationtech.jts.geom.*;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 

+ 1 - 3
onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/ParsingShpFileUtils.java

@@ -2,9 +2,6 @@ package com.onemap.file.utils;
 
 import com.alibaba.fastjson.JSONObject;
 import com.onemap.common.core.utils.StringUtils;
-import com.vividsolutions.jts.geom.Coordinate;
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.geom.Point;
 import org.geotools.data.FileDataStore;
 import org.geotools.data.FileDataStoreFinder;
 import org.geotools.data.shapefile.ShapefileDataStore;
@@ -15,6 +12,7 @@ import org.geotools.geojson.GeoJSONUtil;
 import org.geotools.geojson.feature.FeatureJSON;
 import org.geotools.geometry.jts.ReferencedEnvelope;
 import org.json.simple.JSONArray;
+import org.locationtech.jts.geom.*;
 import org.opengis.feature.Property;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;

+ 2 - 2
onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/WktUtils.java

@@ -1,13 +1,13 @@
 package com.onemap.file.utils;
 
-import com.vividsolutions.jts.geom.Geometry;
-import com.vividsolutions.jts.io.WKTWriter;
 import org.geotools.data.FileDataStore;
 import org.geotools.data.FileDataStoreFinder;
 import org.geotools.data.simple.SimpleFeatureCollection;
 import org.geotools.data.simple.SimpleFeatureSource;
 import org.geotools.feature.FeatureIterator;
 import org.geotools.referencing.CRS;
+import org.locationtech.jts.geom.Geometry;
+import org.locationtech.jts.io.WKTWriter;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 

+ 4 - 3
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/controller/ShpController.java

@@ -40,11 +40,12 @@ public class ShpController {
     }
 
     @GetMapping("/read/file")
-    public RequestResult readFile(String filepath) {
+    public RequestResult readFile(@RequestParam("filepath") String filepath) {
         if (StringUtils.isEmpty(filepath)) {
             return RequestResult.error("filepath is null");
         }
-        shpFileSaveService.readFile(filepath);
-        return RequestResult.success(0);
+        return RequestResult.success(shpFileSaveService.readFile(filepath));
     }
+
+
 }

+ 1 - 1
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/IShpFileSaveService.java

@@ -1,5 +1,5 @@
 package com.onemap.spatial.service;
 
 public interface IShpFileSaveService {
-    public void readFile(String filepath);
+    public String readFile(String filepath);
 }

+ 15 - 8
onemap-modules/onemap-spatial/src/main/java/com/onemap/spatial/service/impl/ShpFileSaveServiceImpl.java

@@ -1,6 +1,7 @@
 package com.onemap.spatial.service.impl;
 
 import com.onemap.common.core.utils.StringUtils;
+import com.onemap.common.core.web.domain.AjaxResult;
 import com.onemap.spatial.mapper.ShpFileMapper;
 import com.onemap.spatial.service.IShpFileSaveService;
 import com.onemap.system.api.TableFiledRelationService;
@@ -33,8 +34,8 @@ public class ShpFileSaveServiceImpl implements IShpFileSaveService {
     private TableFiledRelationService tableFiledRelationService;
 
     @Override
-    public void readFile(String filepath) {
-        readShapeFile(new File(filepath));
+    public String readFile(String filepath) {
+        return readShapeFile(new File(filepath));
 //        readShapeFile(new File("D:\\02DATA\\三亚\\甲方数据\\权属\\SHP\\国有使用权去掉.shp"));
     }
 
@@ -65,13 +66,14 @@ public class ShpFileSaveServiceImpl implements IShpFileSaveService {
     /**
      * @param shpFile 传递的是shape文件中的.shp文件
      */
-    private void readShapeFile(File shpFile) {
+    private String readShapeFile(File shpFile) {
         /**
          * 直接使用shapefileDatastore,如果不知道,也可以使用工厂模式(见下个方法)
          * 建议,如果确定是shape文件,就直使用shapefileDatastore
          */
         ShapefileDataStore shapefileDataStore = null;
         SimpleFeatureIterator simpleFeatureIterator = null;
+        String tableId = null;
         try {
             shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
             shapefileDataStore.setCharset(Charset.forName("UTF-8"));
@@ -88,7 +90,7 @@ public class ShpFileSaveServiceImpl implements IShpFileSaveService {
 
             //获取当前数据的geometry类型(点、线、面)
             GeometryType geometryType = featuresource.getSchema().getGeometryDescriptor().getType();
-            System.out.println(geometryType.getName());
+//            System.out.println(geometryType.getName());
 //            if ("Polygon".equals(geometryType.get) {
 //                tb.add("the_geom", Polygon.class);
 //            } else if ("MultiPolygon".equals(geomTypeData.getGeometryType())) {
@@ -129,13 +131,18 @@ public class ShpFileSaveServiceImpl implements IShpFileSaveService {
 
             String tableName = "z_shp" + "_" + System.currentTimeMillis() + "_" + StringUtils.getUUID();
             shpFileMapper.createTable(tableCommsList, tableName);
-            
             Map<String, Object> table_data_0 = new HashMap<>();
             table_data_0.put("tableName", tableName);
             table_data_0.put("tableDescribe", "shp解析表" + tableName);
             table_data_0.put("tableColumns", tableCommsList);
-            tableFiledRelationService.AddTableFiledRelation(table_data_0);
-
+            AjaxResult Ajax = tableFiledRelationService.AddTableFiledRelation(table_data_0);
+            if (Ajax.isSuccess()) {
+                Object t_data = Ajax.get(AjaxResult.DATA_TAG);
+                if (StringUtils.isNull(t_data)) {
+                    throw new Exception("SHP文件入库失败");
+                }
+                tableId = (String) t_data;
+            }
             //获取属性
             simpleFeatureIterator = simpleFeatureCollection.features();
             while (simpleFeatureIterator.hasNext()) {
@@ -174,7 +181,7 @@ public class ShpFileSaveServiceImpl implements IShpFileSaveService {
                 shapefileDataStore.dispose();
             }
         }
-
+        return tableId;
     }
 
 

+ 2 - 1
onemap-modules/onemap-system/src/main/java/com/onemap/system/controller/TTableFiledRelationController.java

@@ -108,6 +108,7 @@ public class TTableFiledRelationController extends BaseController {
     @Log(title = "添加表和字段", businessType = BusinessType.UPDATE)
     @PostMapping("/add")
     public AjaxResult AddTableFiledRelation(@RequestBody Map<String, Object> tTableFiledRelation) {
-        return toAjax(tTableFiledRelationService.addTableFiledRelation(tTableFiledRelation));
+        String id = tTableFiledRelationService.addTableFiledRelation(tTableFiledRelation);
+        return AjaxResult.success("操作成功", id);
     }
 }

+ 1 - 1
onemap-modules/onemap-system/src/main/java/com/onemap/system/service/ITTableFiledRelationService.java

@@ -61,5 +61,5 @@ public interface ITTableFiledRelationService
      */
     public int deleteTTableFiledRelationById(String id);
 
-    public int addTableFiledRelation(Map<String, Object> tTableFiledRelation);
+    public String addTableFiledRelation(Map<String, Object> tTableFiledRelation);
 }

+ 2 - 2
onemap-modules/onemap-system/src/main/java/com/onemap/system/service/impl/TTableFiledRelationServiceImpl.java

@@ -102,7 +102,7 @@ public class TTableFiledRelationServiceImpl implements ITTableFiledRelationServi
     }
 
     @Override
-    public int addTableFiledRelation(Map<String, Object> tTableFiledRelation) {
+    public String addTableFiledRelation(Map<String, Object> tTableFiledRelation) {
         String tableName = (String) tTableFiledRelation.get("tableName");
         String tableDescribe = (String) tTableFiledRelation.get("tableDescribe");
         List<Map<String, String>> tableCommsList = (List<Map<String, String>>) tTableFiledRelation.get("tableColumns");
@@ -145,6 +145,6 @@ public class TTableFiledRelationServiceImpl implements ITTableFiledRelationServi
         }
 
 
-        return 0;
+        return tableId;
     }
 }