Jelajahi Sumber

存储成相对路径

gushoubang 1 tahun lalu
induk
melakukan
c494f0f8c6

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

@@ -122,21 +122,21 @@ public class SysFileController {
         }
     }
 
-    /**
-     * shp压缩包文件上传****智慧选址
-     *
-     * @param file 文件
-     */
-    @PostMapping("/uploadZhxzZip")
-    public RequestResult uploadZhxzZip(MultipartFile file) {
-        try {
-            RequestResult res = sysFileService.uploadZhxzZip(file);
-            return res;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return RequestResult.error("上传失败!", null);
-        }
-    }
+    // /**
+    //  * shp压缩包文件上传****智慧选址
+    //  *
+    //  * @param file 文件
+    //  */
+    // @PostMapping("/uploadZhxzZip")
+    // public RequestResult uploadZhxzZip(MultipartFile file) {
+    //     try {
+    //         RequestResult res = sysFileService.uploadZhxzZip(file);
+    //         return res;
+    //     } catch (Exception e) {
+    //         e.printStackTrace();
+    //         return RequestResult.error("上传失败!", null);
+    //     }
+    // }
 
     /**
      * 压缩包文件上传
@@ -154,21 +154,21 @@ public class SysFileController {
         }
     }
 
-    /**
-     * shp压缩包文件上传
-     *
-     * @param file 文件
-     */
-    @PostMapping("/uploadTgcl")
-    public GhtgCl uploadTgcl(MultipartFile file, Integer type) {
-        try {
-            GhtgCl res = sysFileService.uploadTgcl(file, type);
-            return res;
-        } catch (Exception e) {
-            e.printStackTrace();
-            return null;
-        }
-    }
+    // /**
+    //  * shp压缩包文件上传
+    //  *
+    //  * @param file 文件
+    //  */
+    // @PostMapping("/uploadTgcl")
+    // public GhtgCl uploadTgcl(MultipartFile file, Integer type) {
+    //     try {
+    //         GhtgCl res = sysFileService.uploadTgcl(file, type);
+    //         return res;
+    //     } catch (Exception e) {
+    //         e.printStackTrace();
+    //         return null;
+    //     }
+    // }
 
     /**
      * 获取shp文件相应的geojson

+ 9 - 27
onemap-modules/onemap-file/src/main/java/com/onemap/file/domain/ShpFileDTO.java

@@ -1,31 +1,13 @@
 package com.onemap.file.domain;
 
-public class ShpFileDTO {
-    private String filepath ;
-    private String zippath ;
-    private String geojson;
-
-    public String getFilepath() {
-        return filepath;
-    }
-
-    public void setFilepath(String filepath) {
-        this.filepath = filepath;
-    }
-
-    public String getGeojson() {
-        return geojson;
-    }
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
 
-    public void setGeojson(String geojson) {
-        this.geojson = geojson;
-    }
-
-    public String getZippath() {
-        return zippath;
-    }
-
-    public void setZippath(String zippath) {
-        this.zippath = zippath;
-    }
+@TableName("t_fzss_zhxz_file")
+@Data
+public class ShpFileDTO {
+    private String id;
+    private String filepath;
+    private String zippath;
+    private String geom;
 }

+ 0 - 34
onemap-modules/onemap-file/src/main/java/com/onemap/file/domain/ZhxzFileDTO.java

@@ -1,34 +0,0 @@
-package com.onemap.file.domain;
-
-import com.baomidou.mybatisplus.annotation.TableName;
-
-@TableName("t_fzss_zhxz_file")
-public class ZhxzFileDTO {
-    private String bsm ;
-    private String wj ;
-    private String yswj ;
-
-    public String getBsm() {
-        return bsm;
-    }
-
-    public void setBsm(String bsm) {
-        this.bsm = bsm;
-    }
-
-    public String getWj() {
-        return wj;
-    }
-
-    public void setWj(String wj) {
-        this.wj = wj;
-    }
-
-    public String getYswj() {
-        return yswj;
-    }
-
-    public void setYswj(String yswj) {
-        this.yswj = yswj;
-    }
-}

+ 14 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/mapper/ShpFileMapper.java

@@ -0,0 +1,14 @@
+package com.onemap.file.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.onemap.file.domain.ShpFileDTO;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 数据层
+ *
+ * @author onemap
+ */
+public interface ShpFileMapper extends BaseMapper<ShpFileDTO> {
+    void saveGeom(ShpFileDTO shpFileDTO);
+}

+ 0 - 20
onemap-modules/onemap-file/src/main/java/com/onemap/file/mapper/ZhxzFileMapper.java

@@ -1,20 +0,0 @@
-package com.onemap.file.mapper;
-
-import com.baomidou.mybatisplus.core.mapper.BaseMapper;
-import com.onemap.file.domain.ZhxzFileDTO;
-import org.apache.ibatis.annotations.Mapper;
-import org.apache.ibatis.annotations.Param;
-
-import java.util.List;
-import java.util.Map;
-
-/**
- * 数据层
- *
- * @author onemap
- */
-@Mapper
-public interface ZhxzFileMapper extends BaseMapper<ZhxzFileDTO>
-{
-
-}

+ 3 - 5
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/ISysFileService.java

@@ -30,17 +30,15 @@ public interface ISysFileService {
      */
     String uploadAppendix(MultipartFile file) throws Exception;
 
-    RequestResult uploadShpZip(MultipartFile file);
+    RequestResult uploadShpZip(MultipartFile file) throws Exception;
 
-    GhtgCl uploadTgcl(MultipartFile file, Integer type) throws Exception;
+    // GhtgCl uploadTgcl(MultipartFile file, Integer type) throws Exception;
 
     String getShpGeoJson(String shppath);
 
-    String getShpWkt(String shppath);
-
     UploadZipDTO uploadZip(MultipartFile file);
 
-    RequestResult uploadZhxzZip(MultipartFile file);
+    // RequestResult uploadZhxzZip(MultipartFile file);
 
     String splitFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("chunk") int chunk, @RequestParam("chunks") int chunks, @RequestParam("name") String name, @RequestParam("md5") String md5);
 }

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

@@ -0,0 +1,5 @@
+package com.onemap.file.service;
+
+public interface SaveFileService {
+    String saveShpFile(String shpPath, String zippath) throws Exception;
+}

+ 134 - 142
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/LocalSysFileServiceImpl.java

@@ -6,12 +6,10 @@ import com.onemap.common.core.domain.UploadZipDTO;
 import com.onemap.common.core.domain.WordToPdfDTO;
 import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.web.domain.RequestResult;
-import com.onemap.file.domain.ShpFileDTO;
-import com.onemap.file.domain.ZhxzFileDTO;
-import com.onemap.file.mapper.ZhxzFileMapper;
 import com.onemap.file.service.ISysFileService;
+import com.onemap.file.service.SaveFileService;
 import com.onemap.file.utils.*;
-import com.onemap.system.api.domain.GhtgCl;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.annotation.Primary;
 import org.springframework.http.ResponseEntity;
@@ -19,10 +17,12 @@ import org.springframework.stereotype.Service;
 import org.springframework.web.bind.annotation.RequestParam;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.annotation.Resource;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -39,11 +39,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     @Value("${file.prefix}")
     public String localFilePrefix;
     private TgclTypeDTO tgclTypeDTO = new TgclTypeDTO();
-    /**
-     * 智慧选址压缩包
-     */
-    @Resource
-    private ZhxzFileMapper zhxzFileMapper;
+
     /**
      * 域名或本机访问地址
      */
@@ -71,9 +67,12 @@ public class LocalSysFileServiceImpl implements ISysFileService {
      */
     @Value("${businessType.shp}")
     private String shpLocalFilePath;
-    //文件上传后的转发路径配置
+    // 文件上传后的转发路径配置
     private Map<String, String> businessFilter = ImmutableMap.of("tgcl", "调规");
 
+    @Autowired
+    private SaveFileService saveFileService;
+
     /**
      * 本地文件上传接口
      *
@@ -108,11 +107,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
      * @throws IOException ioexception
      */
     @Override
-    public String splitFileUpload(@RequestParam("file") MultipartFile file,
-                                  @RequestParam("chunk") int chunk,
-                                  @RequestParam("chunks") int chunks,
-                                  @RequestParam("name") String name,
-                                  @RequestParam("md5") String md5) {
+    public String splitFileUpload(@RequestParam("file") MultipartFile file, @RequestParam("chunk") int chunk, @RequestParam("chunks") int chunks, @RequestParam("name") String name, @RequestParam("md5") String md5) {
         String folder = localFilePath + "\\" + md5 + "\\";
         File dir = new File(folder);
         if (!dir.exists()) {
@@ -171,7 +166,7 @@ public class LocalSysFileServiceImpl implements ISysFileService {
      */
     public WordToPdfDTO uploadWordFileToPdf(MultipartFile file, String businessType) throws Exception {
         WordToPdfDTO pdf = new WordToPdfDTO();
-        String filepath = localFilePath;//9082打开
+        String filepath = localFilePath;// 9082打开
         if ("tgcl".equals(businessType)) {
             filepath = tgclLocalFilePath;
         }
@@ -195,137 +190,139 @@ public class LocalSysFileServiceImpl implements ISysFileService {
     }
 
     @Override
-    public RequestResult uploadShpZip(MultipartFile file) {
-        //获得文件名称
+    public RequestResult uploadShpZip(MultipartFile file) throws Exception {
+        // 获得文件名称
         String fileName = file.getOriginalFilename();
-        //获得文件后缀名
+        // 获得文件后缀名
         String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
-        //判断上传的是否是压缩包
+        // 判断上传的是否是压缩包
         if (!type.equals("zip") && !type.equals("rar")) {
             return RequestResult.error("请上传压缩包", null);
         }
+
         File dest = new File(shpLocalFilePath + "/" + fileName);
-        //获得上级目录
+        // 获得上级目录
         File dir = dest.getParentFile();
         if (!dir.exists()) {
             dir.mkdirs();
         }
-        //获取当前时间的时间戳
+        // 获取当前时间的时间戳
         long timeMillis = System.currentTimeMillis();
         String shpPath = "";
-        try {
-            //上传文件
-            file.transferTo(dest);
-            //解压zip格式
-            if (type.equals("zip")) {
-                new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
-            } else {
-                //解压rar格式
-                new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
-            }
-            File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
-            for (File file1 : files) {
-                if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
-                    shpPath = file1.getAbsolutePath();
-                    break;
-                }
-            }
-            if (!"".equals(shpPath)) {
-                ShpFileDTO res = new ShpFileDTO();
-                res.setFilepath(shpPath);
-                res.setGeojson(getShpGeoJson(shpPath));
-                res.setZippath(dest.getAbsolutePath());
-                return RequestResult.success("上传成功", res);
-            } else {
-                return RequestResult.error("未检索到shp文件");
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-            return RequestResult.error("上传失败");
-        }
-    }
 
-    @Override
-    public RequestResult uploadZhxzZip(MultipartFile file) {
-        //获得文件名称
-        String fileName = file.getOriginalFilename();
-        //获得文件后缀名
-        String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
-        //判断上传的是否是压缩包
-        if (!type.equals("zip") && !type.equals("rar")) {
-            return RequestResult.error("请上传压缩包", null);
-        }
-        File dest = new File(shpLocalFilePath + "/" + fileName);
-        //获得上级目录
-        File dir = dest.getParentFile();
-        if (!dir.exists()) {
-            dir.mkdirs();
+        // 上传文件
+        File newFile = new File(dest.getAbsolutePath());
+        file.transferTo(newFile);
+        // 解压zip格式
+        if (type.equals("zip")) {
+            new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
+        } else {
+            // 解压rar格式
+            new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
         }
-        //获取当前时间的时间戳
-        long timeMillis = System.currentTimeMillis();
-        String shpPath = "";
-        try {
-            //上传文件
-            file.transferTo(dest);
-            //解压zip格式
-            if (type.equals("zip")) {
-                new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
-            } else {
-                //解压rar格式
-                new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
-            }
-            File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
-            for (File file1 : files) {
-                if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
-                    shpPath = file1.getAbsolutePath();
-                    break;
-                }
+        File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
+        for (File file1 : files) {
+            List<File> shpFiles = new ArrayList<>();
+            FileUtils.findShpFiles(file1, shpFiles);
+            if (shpFiles.size() != 0) {
+                shpPath = shpFiles.get(0).getPath();
             }
-            if (!"".equals(shpPath)) {
-                String uuid = StringUtils.getUUID();
-                ZhxzFileDTO insertDto = new ZhxzFileDTO();
-                insertDto.setBsm(uuid);
-                insertDto.setWj(shpPath);
-                insertDto.setYswj(dest.getAbsolutePath());
-                zhxzFileMapper.insert(insertDto);
-                return RequestResult.success("上传成功", uuid);
-            } else {
-                return RequestResult.error("未检索到shp文件");
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-            return RequestResult.error("上传失败");
         }
-    }
-
-    @Override
-    public GhtgCl uploadTgcl(MultipartFile file, Integer type) throws Exception {
-        GhtgCl cl = new GhtgCl();
-        cl.setBsm(StringUtils.getUUID());
-        cl.setWjdx((double) file.getSize());
-        String filename = file.getOriginalFilename();
-        cl.setFjmc(filename);
-        String kzmc = PublicTools.getFileKzmx(filename);
-        cl.setFjlx(type);
-        if (type == tgclTypeDTO.getShp()) {
-            RequestResult shpzip = uploadShpZip(file);
-            ShpFileDTO shpzipinfo = (ShpFileDTO) shpzip.get("data");
-            cl.setWjlj(shpzipinfo.getZippath());
-            cl.setYshp(shpzipinfo.getFilepath());
-            cl.setGeojson(shpzipinfo.getGeojson());
-            cl.setKzmc(kzmc);
-            cl.setYwj(shpzipinfo.getZippath());
-            return cl;
-        } else if (type == tgclTypeDTO.getTgcl()) {
-            WordToPdfDTO pdf = uploadWordFileToPdf(file, "tgcl");
-            cl.setWjlj(pdf.getPdfpath());
-            cl.setKzmc(pdf.getKzmc());
-            cl.setYwj(pdf.getFilepath());
-            return cl;
+        if (!"".equals(shpPath)) {
+            String id = saveFileService.saveShpFile(shpPath, dest.getPath());
+            // ShpFileDTO res = new ShpFileDTO();
+            // res.setFilepath(shpPath);
+            // res.setGeojson(getShpGeoJson(shpPath));
+            // res.setZippath(dest.getAbsolutePath());
+            Map<String, String> res = new HashMap<>();
+            res.put("id", id);
+            return RequestResult.success("上传成功", res);
+        } else {
+            return RequestResult.error("未检索到shp文件");
         }
-        return null;
     }
 
+    // @Override
+    // public RequestResult uploadZhxzZip(MultipartFile file) {
+    //     // 获得文件名称
+    //     String fileName = file.getOriginalFilename();
+    //     // 获得文件后缀名
+    //     String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
+    //     // 判断上传的是否是压缩包
+    //     if (!type.equals("zip") && !type.equals("rar")) {
+    //         return RequestResult.error("请上传压缩包", null);
+    //     }
+    //     File dest = new File(shpLocalFilePath + "/" + fileName);
+    //     // 获得上级目录
+    //     File dir = dest.getParentFile();
+    //     if (!dir.exists()) {
+    //         dir.mkdirs();
+    //     }
+    //     // 获取当前时间的时间戳
+    //     long timeMillis = System.currentTimeMillis();
+    //     String shpPath = "";
+    //     try {
+    //         // 上传文件
+    //         file.transferTo(dest);
+    //         // 解压zip格式
+    //         if (type.equals("zip")) {
+    //             new UnPackageUtils().unPackZip(dest, shpLocalFilePath + "/" + timeMillis);
+    //         } else {
+    //             // 解压rar格式
+    //             new UnPackageUtils().unPackRar(dest, shpLocalFilePath + "/" + timeMillis);
+    //         }
+    //         File[] files = new File(shpLocalFilePath + "/" + timeMillis).listFiles();
+    //         for (File file1 : files) {
+    //             if (file1.getAbsolutePath().substring(file1.getAbsolutePath().lastIndexOf(".") + 1).equals("shp")) {
+    //                 shpPath = file1.getAbsolutePath();
+    //                 break;
+    //             }
+    //         }
+    //         if (!"".equals(shpPath)) {
+    //             String uuid = StringUtils.getUUID();
+    //             ZhxzFileDTO insertDto = new ZhxzFileDTO();
+    //             insertDto.setBsm(uuid);
+    //             insertDto.setWj(shpPath);
+    //             insertDto.setYswj(dest.getAbsolutePath());
+    //             zhxzFileMapper.insert(insertDto);
+    //             return RequestResult.success("上传成功", uuid);
+    //         } else {
+    //             return RequestResult.error("未检索到shp文件");
+    //         }
+    //     } catch (IOException e) {
+    //         e.printStackTrace();
+    //         return RequestResult.error("上传失败");
+    //     }
+    // }
+
+    // @Override
+    // public GhtgCl uploadTgcl(MultipartFile file, Integer type) throws Exception {
+    //     GhtgCl cl = new GhtgCl();
+    //     cl.setBsm(StringUtils.getUUID());
+    //     cl.setWjdx((double) file.getSize());
+    //     String filename = file.getOriginalFilename();
+    //     cl.setFjmc(filename);
+    //     String kzmc = PublicTools.getFileKzmx(filename);
+    //     cl.setFjlx(type);
+    //     if (type == tgclTypeDTO.getShp()) {
+    //         RequestResult shpzip = uploadShpZip(file);
+    //         ShpFileDTO shpzipinfo = (ShpFileDTO) shpzip.get("data");
+    //         cl.setWjlj(shpzipinfo.getZippath());
+    //         cl.setYshp(shpzipinfo.getFilepath());
+    //         cl.setGeojson(shpzipinfo.getGeojson());
+    //         cl.setKzmc(kzmc);
+    //         cl.setYwj(shpzipinfo.getZippath());
+    //         return cl;
+    //     } else if (type == tgclTypeDTO.getTgcl()) {
+    //         WordToPdfDTO pdf = uploadWordFileToPdf(file, "tgcl");
+    //         cl.setWjlj(pdf.getPdfpath());
+    //         cl.setKzmc(pdf.getKzmc());
+    //         cl.setYwj(pdf.getFilepath());
+    //         return cl;
+    //     }
+    //     return null;
+    // }
+
     /**
      * 通过shp路径转换esrijson并返回相应json文件路径
      *
@@ -340,11 +337,11 @@ public class LocalSysFileServiceImpl implements ISysFileService {
         String geojsonPath = publicpath + "_" + uuid + "_" + "geojson.json";
         String geojson = ParsingShpFileUtils.shape2Geojson(shppath, geojsonPath);
         String esrijson = EsriGeoJsonJsUtils.geo2ersi(geojson, "", shppath);
-        //写入文件
+        // 写入文件
         FileOutputStream fos = null;
         try {
             fos = new FileOutputStream(esrijsonpath, false);
-            //true表示在文件末尾追加
+            // true表示在文件末尾追加
             fos.write(esrijson.toString().getBytes());
             fos.close();
         } catch (IOException e) {
@@ -369,34 +366,29 @@ public class LocalSysFileServiceImpl implements ISysFileService {
         return geojson;
     }
 
-    @Override
-    public String getShpWkt(String shppath) {
-        return "";
-    }
-
     @Override
     public UploadZipDTO uploadZip(MultipartFile file) {
-        //获得文件名称
+        // 获得文件名称
         String fileName = file.getOriginalFilename();
-        //获得文件后缀名
+        // 获得文件后缀名
         String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
         String path = shpLocalFilePath + "/" + fileName;
         File dest = new File(path);
-        //获得上级目录
+        // 获得上级目录
         File dir = dest.getParentFile();
         if (!dir.exists()) {
             dir.mkdirs();
         }
-        //获取当前时间的时间戳
+        // 获取当前时间的时间戳
         long timeMillis = System.currentTimeMillis();
         String unzippath = shpLocalFilePath + "/" + timeMillis;
         try {
-            //上传文件
+            // 上传文件
             file.transferTo(dest);
             if (type.equals("zip")) {
                 new UnPackageUtils().unPackZip(dest, unzippath);
             } else if (type.equals("rar")) {
-                //解压rar格式
+                // 解压rar格式
                 new UnPackageUtils().unPackRar(dest, unzippath);
             }
             UploadZipDTO dto = new UploadZipDTO();

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

@@ -0,0 +1,38 @@
+package com.onemap.file.service.impl;
+
+import com.onemap.common.core.utils.StringUtils;
+import com.onemap.common.datasource.annotation.Master;
+import com.onemap.common.datasource.annotation.Slave;
+import com.onemap.file.domain.ShpFileDTO;
+import com.onemap.file.mapper.ShpFileMapper;
+import com.onemap.file.service.SaveFileService;
+import com.onemap.file.utils.WktUtils;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+
+@Service
+public class SaveFileImpl implements SaveFileService {
+    /**
+     * 智慧选址压缩包
+     */
+    @Resource
+    private ShpFileMapper zhxzFileMapper;
+
+    @Override
+    @Master
+    public String saveShpFile(String shpPath, String zippath) throws Exception {
+        String ewkt = WktUtils.getShpWkt(shpPath);
+
+        ShpFileDTO shpFileDTO = new ShpFileDTO();
+
+        String uuid = StringUtils.getUUID();
+        shpFileDTO.setId(uuid);
+        shpFileDTO.setZippath(zippath);
+        shpFileDTO.setFilepath(shpPath);
+        shpFileDTO.setGeom(ewkt);
+
+        zhxzFileMapper.saveGeom(shpFileDTO);
+        return uuid;
+    }
+}

+ 19 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/utils/FileUtils.java

@@ -171,4 +171,23 @@ public class FileUtils {
             return false;
         }
     }
+
+    public static void findShpFiles(File directory, List<File> shpFiles) {
+        // 确保目录存在且是一个目录
+        if (directory.exists() && directory.isDirectory()) {
+            // 获取目录中的所有文件和子目录
+            File[] files = directory.listFiles();
+            if (files != null) {
+                for (File file : files) {
+                    if (file.isDirectory()) {
+                        // 递归查找子目录
+                        findShpFiles(file, shpFiles);
+                    } else if (file.isFile() && file.getName().endsWith(".shp")) {
+                        // 找到 .shp 文件,添加到列表中
+                        shpFiles.add(file);
+                    }
+                }
+            }
+        }
+    }
 }

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

@@ -0,0 +1,53 @@
+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.opengis.feature.simple.SimpleFeature;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+
+import java.io.File;
+
+public class WktUtils {
+    public static String getShpWkt(String shpPath) throws Exception {
+        // 读取shp文件
+        FileDataStore store = FileDataStoreFinder.getDataStore(new File(shpPath));
+        SimpleFeatureSource featureSource = store.getFeatureSource();
+        SimpleFeatureCollection featureCollection = featureSource.getFeatures();
+        CoordinateReferenceSystem crs = featureSource.getSchema().getCoordinateReferenceSystem();
+
+        // 合并几何图形
+        Geometry combinedGeometry = null;
+        try (FeatureIterator<SimpleFeature> features = featureCollection.features()) {
+            while (features.hasNext()) {
+                SimpleFeature feature = features.next();
+                Geometry geometry = (Geometry) feature.getDefaultGeometry();
+                if (combinedGeometry == null) {
+                    combinedGeometry = geometry;
+                } else {
+                    combinedGeometry = combinedGeometry.union(geometry);
+                }
+            }
+        }
+        String ewkt = geometryToEWKT(combinedGeometry, crs);
+        return ewkt;
+    }
+
+
+    public static String geometryToEWKT(Geometry geometry, CoordinateReferenceSystem crs) throws Exception {
+        WKTWriter writer = new WKTWriter();
+        String wkt = writer.write(geometry);
+        Integer srid = CRS.lookupEpsgCode(crs, true);
+        if (srid == null) {
+            srid=4326;
+        } else if (srid == -1) {
+            srid=4326;
+        }
+        return "SRID=" + srid + ";" + wkt;
+    }
+}

+ 18 - 0
onemap-modules/onemap-file/src/main/resources/mapper/postgresql/ShpFileMapper.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+
+<mapper namespace="com.onemap.file.mapper.ShpFileMapper">
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="com.onemap.file.domain.ShpFileDTO" id="shpFileMap">
+
+    </resultMap>
+
+    <insert id="saveGeom">
+        INSERT INTO t_fzss_zhxz_file (id, filepath, zippath, geom)
+        VALUES (#{id},
+                #{filepath},
+                #{zippath},
+                public.st_transform(public.st_geomfromewkt(#{geom,jdbcType=OTHER}), 4326))
+    </insert>
+</mapper>