소스 검색

新增空间上传数据接口

DESKTOP-2K9OVK9\siwei 4 달 전
부모
커밋
606a39f4c1

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

@@ -2,6 +2,7 @@ package com.onemap.file.controller;
 
 import com.onemap.common.core.domain.UploadZipDTO;
 import com.onemap.common.core.web.domain.RequestResult;
+import com.onemap.file.domain.TUploadGeomDTO;
 import com.onemap.file.service.ISpaceFileRecordService;
 import com.onemap.file.service.SaveFileService;
 import org.slf4j.Logger;
@@ -221,4 +222,43 @@ public class SysFileController {
     }
 
 
+    /**
+     * @param storeStats 是否入库 0入库 其他不入库
+     * @return
+     * @throws Exception
+     */
+    @PostMapping("/upload/geom/v1")
+    public RequestResult uploadGeomV1(MultipartFile file, Integer fromType, String geom, String fromRoute, String storeStats, Integer followup) {
+        try {
+            String id = null;
+            if (fromType == 1) {
+                id = spaceFileRecordService.uploadAddShpDrawV1(geom, fromRoute, fromType, storeStats);
+            } else {
+                id = spaceFileRecordService.uploadAddShpFileV1(file, fromRoute, fromType, storeStats);
+            }
+            TUploadGeomDTO dto = spaceFileRecordService.selectTUploadGeomById(id, 0);
+            if (!"0".equals(storeStats)) {
+                dto.setId(null);
+                spaceFileRecordService.deleteTUploadGeomById(id);
+            }
+            if (null != followup) {
+                spaceFileRecordService.handleUploadGeomFollowUp(id, followup);
+            }
+            return RequestResult.success(dto);
+        } catch (Exception e) {
+            return RequestResult.error("上传失败!", null);
+        }
+    }
+
+    @GetMapping("/upload/geom/v1/query")
+    public RequestResult uploadGeomQueryV1(String id, Integer isDetail) {
+        return RequestResult.success("执行成功!", spaceFileRecordService.selectTUploadGeomById(id, isDetail));
+    }
+
+    @GetMapping("/upload/geom/v1/query/details")
+    public RequestResult uploadGeomQueryV1(String id) {
+        return RequestResult.success("执行成功!", spaceFileRecordService.selectTUploadGeomDetailsById(id));
+    }
+
+
 }

+ 147 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/domain/TUploadGeomDTO.java

@@ -0,0 +1,147 @@
+package com.onemap.file.domain;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+import java.util.List;
+
+public class TUploadGeomDTO {
+    private String id;
+    private String name;
+    private String uploaduser;
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date uploadtime;
+    private String filepath;
+    private String shppath;
+    private String unzippath;
+    private String filetype;
+    private String geom;
+    private Integer spotsnumber;
+    private Double spotsarea;
+    private Integer sridarea;
+    private String fromroute;
+    private Integer fromtype;
+    private List<TUploadGeomDetailsDTO> tUploadGeomDetailsDTOList;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getName() {
+        return name;
+    }
+
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    public String getUploaduser() {
+        return uploaduser;
+    }
+
+    public void setUploaduser(String uploaduser) {
+        this.uploaduser = uploaduser;
+    }
+
+    public Date getUploadtime() {
+        return uploadtime;
+    }
+
+    public void setUploadtime(Date uploadtime) {
+        this.uploadtime = uploadtime;
+    }
+
+    public String getFilepath() {
+        return filepath;
+    }
+
+    public void setFilepath(String filepath) {
+        this.filepath = filepath;
+    }
+
+    public String getShppath() {
+        return shppath;
+    }
+
+    public void setShppath(String shppath) {
+        this.shppath = shppath;
+    }
+
+    public String getUnzippath() {
+        return unzippath;
+    }
+
+    public void setUnzippath(String unzippath) {
+        this.unzippath = unzippath;
+    }
+
+    public String getFiletype() {
+        return filetype;
+    }
+
+    public void setFiletype(String filetype) {
+        this.filetype = filetype;
+    }
+
+    public String getGeom() {
+        return geom;
+    }
+
+    public void setGeom(String geom) {
+        this.geom = geom;
+    }
+
+    public Integer getSpotsnumber() {
+        return spotsnumber;
+    }
+
+    public void setSpotsnumber(Integer spotsnumber) {
+        this.spotsnumber = spotsnumber;
+    }
+
+    public Double getSpotsarea() {
+        return spotsarea;
+    }
+
+    public void setSpotsarea(Double spotsarea) {
+        this.spotsarea = spotsarea;
+    }
+
+    public String getFromroute() {
+        return fromroute;
+    }
+
+    public void setFromroute(String fromroute) {
+        this.fromroute = fromroute;
+    }
+
+    public Integer getFromtype() {
+        return fromtype;
+    }
+
+    public void setFromtype(Integer fromtype) {
+        this.fromtype = fromtype;
+    }
+
+    public Integer getSridarea() {
+        return sridarea;
+    }
+
+    public void setSridarea(Integer sridarea) {
+        this.sridarea = sridarea;
+    }
+
+    public List<TUploadGeomDetailsDTO> gettUploadGeomDetailsDTOList() {
+        return tUploadGeomDetailsDTOList;
+    }
+
+    public void settUploadGeomDetailsDTOList(List<TUploadGeomDetailsDTO> tUploadGeomDetailsDTOList) {
+        this.tUploadGeomDetailsDTOList = tUploadGeomDetailsDTOList;
+    }
+}

+ 67 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/domain/TUploadGeomDetailsDTO.java

@@ -0,0 +1,67 @@
+package com.onemap.file.domain;
+
+public class TUploadGeomDetailsDTO {
+    private String id;
+    private String uploadId;
+    private String geom;
+    private Double geomarea;
+    private String geomJson;
+    private Integer sort;
+    private Integer sridarea;
+
+    public String getId() {
+        return id;
+    }
+
+    public void setId(String id) {
+        this.id = id;
+    }
+
+    public String getUploadId() {
+        return uploadId;
+    }
+
+    public void setUploadId(String uploadId) {
+        this.uploadId = uploadId;
+    }
+
+    public String getGeom() {
+        return geom;
+    }
+
+    public void setGeom(String geom) {
+        this.geom = geom;
+    }
+
+    public String getGeomJson() {
+        return geomJson;
+    }
+
+    public void setGeomJson(String geomJson) {
+        this.geomJson = geomJson;
+    }
+
+    public Integer getSort() {
+        return sort;
+    }
+
+    public void setSort(Integer sort) {
+        this.sort = sort;
+    }
+
+    public Integer getSridarea() {
+        return sridarea;
+    }
+
+    public void setSridarea(Integer sridarea) {
+        this.sridarea = sridarea;
+    }
+
+    public Double getGeomarea() {
+        return geomarea;
+    }
+
+    public void setGeomarea(Double geomarea) {
+        this.geomarea = geomarea;
+    }
+}

+ 26 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/mapper/TUploadGeomDetailsMapper.java

@@ -0,0 +1,26 @@
+package com.onemap.file.mapper;
+
+import com.onemap.file.domain.TUploadGeomDTO;
+import com.onemap.file.domain.TUploadGeomDetailsDTO;
+import org.apache.ibatis.annotations.Mapper;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 数据层
+ *
+ * @author onemap
+ */
+@Mapper
+public interface TUploadGeomDetailsMapper {
+    int insertTUploadGeomDetails(TUploadGeomDetailsDTO uploadGeomDetailsDTO);
+
+    List<TUploadGeomDetailsDTO> selectTUploadGeomDetailsList(TUploadGeomDetailsDTO uploadGeomDetailsDTO);
+
+    TUploadGeomDetailsDTO selectTUploadGeomDetailsById(String id);
+
+    TUploadGeomDTO sumTUploadGeomDetailsByUploadId(String id);
+
+    int deleteTUploadGeomDetailsByUploadId(String id);
+}

+ 23 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/mapper/TUploadGeomMapper.java

@@ -0,0 +1,23 @@
+package com.onemap.file.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import com.onemap.file.domain.GeomResourceDTO;
+import com.onemap.file.domain.TUploadGeomDTO;
+import com.onemap.file.domain.res.GeomRes;
+import org.apache.ibatis.annotations.Mapper;
+
+/**
+ * 数据层
+ *
+ * @author onemap
+ */
+@Mapper
+public interface TUploadGeomMapper {
+
+    int insertTUploadGeom(TUploadGeomDTO uploadGeomDTO);
+
+    TUploadGeomDTO selectTUploadGeomById(String id);
+
+    int deleteTUploadGeomById(String id);
+
+}

+ 49 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/ISpaceFileRecordService.java

@@ -2,6 +2,8 @@ package com.onemap.file.service;
 
 import com.onemap.common.core.web.domain.RequestResult;
 import com.onemap.file.domain.SpaceFileRecordDTO;
+import com.onemap.file.domain.TUploadGeomDTO;
+import com.onemap.file.domain.TUploadGeomDetailsDTO;
 import org.springframework.web.multipart.MultipartFile;
 
 public interface ISpaceFileRecordService {
@@ -18,6 +20,17 @@ public interface ISpaceFileRecordService {
 
     RequestResult uploadAddShpDraw(String geom, String fromRoute) throws Exception;
 
+    /**
+     * @param geom
+     * @param fromRoute
+     * @param storeStats 是否入库 0入库 其他不入库
+     * @return
+     * @throws Exception
+     */
+    String uploadAddShpDrawV1(String geom, String fromRoute, Integer fromtype, String storeStats) throws Exception;
+
+    String uploadAddShpFileV1(MultipartFile file, String fromRoute, Integer fromtype, String storeStats) throws Exception;
+
     String saveSpaceFileRecord(SpaceFileRecordDTO spaceFileRecordDTO) throws Exception;
 
     /**
@@ -30,4 +43,40 @@ public interface ISpaceFileRecordService {
      */
     SpaceFileRecordDTO querySpaceFileRecord(String id, int isDetail);
 
+    /**
+     * 根据ID查询空间信息,
+     *
+     * @param id
+     * @param isDetail 是否查询详情,1是 其他否
+     * @return
+     * @throws Exception
+     */
+    TUploadGeomDTO selectTUploadGeomById(String id, Integer isDetail);
+
+    /**
+     * 根据ID删除空间信息,
+     *
+     * @param id
+     * @return
+     * @throws Exception
+     */
+    int deleteTUploadGeomById(String id);
+
+    /**
+     * 根据ID查询空间信息,
+     *
+     * @param id
+     * @return
+     * @throws Exception
+     */
+    public TUploadGeomDetailsDTO selectTUploadGeomDetailsById(String id);
+
+    /**
+     * 执行完上传后,后续操作
+     *
+     * @param id
+     * @param followup
+     */
+    public void handleUploadGeomFollowUp(String id, Integer followup);
+
 }

+ 217 - 0
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/ShpFileSaveService.java

@@ -0,0 +1,217 @@
+package com.onemap.file.service.impl;
+
+import org.geotools.data.FeatureSource;
+import org.geotools.data.shapefile.ShapefileDataStore;
+import org.geotools.data.simple.SimpleFeatureCollection;
+import org.geotools.data.simple.SimpleFeatureIterator;
+import org.geotools.referencing.CRS;
+import org.locationtech.jts.geom.Geometry;
+import org.opengis.feature.simple.SimpleFeature;
+import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.referencing.crs.CoordinateReferenceSystem;
+import org.springframework.stereotype.Service;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.*;
+
+@Service
+public class ShpFileSaveService {
+
+    private String convertShpFieldType2H2GISOrPG(Class value) throws Exception {
+        if (value == String.class) {//文本
+            return "varchar";
+        }
+        if (value == Integer.class) {//短整型
+            return "int";
+        }
+        if (value == Long.class) {//长整型
+            return "bigint";
+        }
+        if (value == Double.class || value == Float.class) {//浮点型 双精度 保留精度,比如在金币上运算更安全
+            return "numeric";
+        }
+        if (value == Date.class) {
+            return "timestamp without time zone";//日期, 使用包含时区的来处理
+        }
+        if (Geometry.class.isAssignableFrom(value)) {
+            return "public.geometry";
+        }
+        //除了上述,真不知道还会有啥了。除非arcgis的shp又增加了新类型?!那无能为力了,抛出异常吧
+        throw new Exception("不支持的类型!" + value.getName());
+    }
+
+    public List<Map<String, Object>> readShapeFile(String shpFile) {
+        return readShapeFile(new File(shpFile));
+    }
+
+    /**
+     * @param shpFile 传递的是shape文件中的.shp文件
+     */
+    public List<Map<String, Object>> readShapeFile(File shpFile) {
+        /**
+         * 直接使用shapefileDatastore,如果不知道,也可以使用工厂模式(见下个方法)
+         * 建议,如果确定是shape文件,就直使用shapefileDatastore
+         */
+        ShapefileDataStore shapefileDataStore = null;
+        SimpleFeatureIterator simpleFeatureIterator = null;
+        List<Map<String, Object>> retFeatureList = new ArrayList<>();
+        String tableId = null;
+        try {
+            shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
+            shapefileDataStore.setCharset(Charset.forName(readShpBM(shpFile.getAbsolutePath())));
+            //这个typeNamae不传递,默认是文件名称
+            FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
+
+            // 获取 srid
+            CoordinateReferenceSystem crs = featuresource.getSchema().getCoordinateReferenceSystem();
+            Integer srid = CRS.lookupEpsgCode(crs, true);
+            if (srid == null) {
+                throw new Exception("SHP文件坐标系未查到");
+            }
+
+            //获取当前数据的geometry类型(点、线、面)
+//            GeometryType geometryType = featuresource.getSchema().getGeometryDescriptor().getType();
+//            System.out.println(geometryType.getName());
+//            if ("Polygon".equals(geometryType.get) {
+//                tb.add("the_geom", Polygon.class);
+//            } else if ("MultiPolygon".equals(geomTypeData.getGeometryType())) {
+//                tb.add("the_geom", MultiPolygon.class);
+//            }
+            //读取要素
+            SimpleFeatureCollection simpleFeatureCollection = (SimpleFeatureCollection) featuresource.getFeatures();
+            //获取当前矢量数据有哪些属性字段值
+
+            //获取字段列表
+            List<String> attributesList = new ArrayList<>();
+            List<Map<String, String>> tableCommsList = new ArrayList<>();
+            List<AttributeDescriptor> attributes = simpleFeatureCollection.getSchema().getAttributeDescriptors();
+            for (AttributeDescriptor h : attributes) {
+                attributesList.add(h.getLocalName());
+//                String type = convertShpFieldType2H2GISOrPG(h.getType().getBinding());
+//                Map<String, String> attributesMap = new LinkedHashMap<>();
+//                if (!h.getLocalName().toLowerCase().equals("the_geom")) {
+//                    attributesMap.put("key", h.getLocalName().toLowerCase());
+//                    attributesMap.put("value", type);
+//                    tableCommsList.add(attributesMap);
+//                }
+            }
+
+            //获取属性
+            simpleFeatureIterator = simpleFeatureCollection.features();
+            while (simpleFeatureIterator.hasNext()) {
+                Map<String, Object> pg_rk = new LinkedHashMap<>();
+                SimpleFeature simpleFeature = simpleFeatureIterator.next();
+                int f_i = 0;
+                for (; f_i < attributesList.size(); f_i++) {
+                    if ("the_geom".equals(attributesList.get(f_i))) {
+                        Geometry geometry = (Geometry) simpleFeature.getAttribute(attributesList.get(f_i));
+                        String geom = geometry.toText();
+                        String ewkt = "SRID=" + srid + ";" + geom;
+                        pg_rk.put(attributesList.get(f_i), ewkt);
+                    } else {
+                        pg_rk.put(attributesList.get(f_i), simpleFeature.getAttribute(attributesList.get(f_i)));
+                    }
+
+                }
+                retFeatureList.add(pg_rk);
+            }
+
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        } finally {
+            if (simpleFeatureIterator != null) {
+                simpleFeatureIterator.close();
+            }
+            if (shapefileDataStore != null) {
+                shapefileDataStore.dispose();
+            }
+        }
+        return retFeatureList;
+    }
+
+
+//    private static void readShapeFile(File shpFile) {
+//        /**
+//         * 直接使用shapefileDatastore,如果不知道,也可以使用工厂模式(见下个方法)
+//         * 建议,如果确定是shape文件,就直使用shapefileDatastore
+//         */
+//        try {
+//            ShapefileDataStore shapefileDataStore = new ShapefileDataStore(shpFile.toURI().toURL());
+//            shapefileDataStore.setCharset(Charset.forName("UTF-8"));
+//            //这个typeNamae不传递,默认是文件名称
+//            FeatureSource featuresource = shapefileDataStore.getFeatureSource(shapefileDataStore.getTypeNames()[0]);
+//            //读取bbox
+//            ReferencedEnvelope bbox = featuresource.getBounds();
+//            System.out.println(String.valueOf(bbox.getMaxX()) + ":" + String.valueOf(bbox.getMaxY()));
+//            //读取投影
+//            CoordinateReferenceSystem crs = featuresource.getSchema().getCoordinateReferenceSystem();
+//            System.out.println(crs.toWKT());
+//            //特征总数
+//            int count = featuresource.getCount(Query.ALL);
+//            System.out.println(count);
+//            //获取当前数据的geometry类型(点、线、面)
+//            GeometryType geometryType = featuresource.getSchema().getGeometryDescriptor().getType();
+//            System.out.println(geometryType);
+//            //读取要素
+//            SimpleFeatureCollection simpleFeatureCollection = (SimpleFeatureCollection) featuresource.getFeatures();
+//            //获取当前矢量数据有哪些属性字段值
+//            List<AttributeDescriptor> attributes = simpleFeatureCollection.getSchema().getAttributeDescriptors();
+//            for (AttributeDescriptor h:attributes){
+//                String g = convertShpFieldType2H2GISOrPG(h.getType().getBinding());
+//                System.out.println(g);
+////                System.out.println(h.getLocalName()+"  "+h.getType().getBinding()+"  "+h.getDefaultValue());
+//            }
+////            System.out.println(attributes);
+//
+//            SimpleFeatureIterator simpleFeatureIterator = simpleFeatureCollection.features();
+//
+//            while(simpleFeatureIterator.hasNext()) {
+//                SimpleFeature simpleFeature = simpleFeatureIterator.next();
+//                attributes.stream().forEach((a) -> {
+//                    //依次读取这个shape中每一个属性值,当然这个属性值,可以处理其它业务
+//                    System.out.println(simpleFeature.getAttribute(a.getLocalName()));
+//                });
+//            }
+//        } catch (IOException e) {
+//            e.printStackTrace();
+//        } catch (Exception e) {
+//            throw new RuntimeException(e);
+//        }
+//
+//    }
+
+    private String readShpBM(String shpPath) {
+        String dbfPath = shpPath.substring(0, shpPath.length() - 4) + ".dbf";
+        try (FileInputStream fis = new FileInputStream(dbfPath)) {
+            // 跳过到第29字节
+            fis.skip(29);
+            int languageDriverId = fis.read();
+            System.out.println(languageDriverId);
+
+            // 根据语言驱动器ID判断编码
+            String encoding = detectEncodingByLanguageDriver(languageDriverId);
+            System.out.println("根据语言驱动器 ID 判断编码为: " + encoding);
+            return encoding;
+        } catch (IOException e) {
+            System.err.println("读取 .dbf 文件失败: " + e.getMessage());
+            return "GBK";
+        }
+    }
+
+    private String detectEncodingByLanguageDriver(int id) {
+        switch (id) {
+            case 0:
+                return "UTF-8";
+            case 77:
+                return "GBK";
+            // 添加更多语言驱动器ID对应关系
+            default:
+                return "GBK";
+        }
+    }
+}

+ 137 - 8
onemap-modules/onemap-file/src/main/java/com/onemap/file/service/impl/SpaceFileRecordServiceImpl.java

@@ -1,16 +1,18 @@
 package com.onemap.file.service.impl;
 
 import com.alibaba.fastjson.JSON;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.onemap.common.core.constant.ServiceConstants;
 import com.onemap.common.core.utils.StringUtils;
 import com.onemap.common.core.web.domain.AjaxResult;
 import com.onemap.common.core.web.domain.RequestResult;
+import com.onemap.common.security.utils.SecurityUtils;
 import com.onemap.file.domain.SpaceFileRecordDTO;
+import com.onemap.file.domain.TUploadGeomDTO;
+import com.onemap.file.domain.TUploadGeomDetailsDTO;
 import com.onemap.file.mapper.SpaceFileRecordMapper;
+import com.onemap.file.mapper.TUploadGeomDetailsMapper;
+import com.onemap.file.mapper.TUploadGeomMapper;
 import com.onemap.file.service.ISpaceFileRecordService;
-import com.onemap.file.service.SaveFileService;
 import com.onemap.file.utils.FileUtils;
 import com.onemap.file.utils.UnPackageUtils;
 import com.onemap.system.api.AnalyseService;
@@ -21,14 +23,15 @@ import com.onemap.system.api.domain.RawTableVo;
 import com.onemap.file.domain.res.ApiTTable;
 import com.onemap.file.domain.res.ApiTTableFiled;
 import com.onemap.file.domain.res.TableDataVo;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.annotation.processing.FilerException;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -39,10 +42,14 @@ import java.util.Map;
 
 @Service
 public class SpaceFileRecordServiceImpl implements ISpaceFileRecordService {
+    @Resource
+    private TUploadGeomMapper tUploadGeomMapper;
+    @Resource
+    private TUploadGeomDetailsMapper tUploadGeomDetailsMapper;
+    @Resource
+    private ShpFileSaveService shpFileSaveService;
 
-    @Autowired
-    private SaveFileService saveFileService;
-    @Autowired
+    @Resource
     private SpatialService spatialService;
     @Value("${businessType.shp}")
     private String shpLocalFilePath;
@@ -52,9 +59,10 @@ public class SpaceFileRecordServiceImpl implements ISpaceFileRecordService {
     private TableFiledRelationService tableFiledRelationService;
     @Resource
     private AnalyseService analyseService;
+    private final int sridArea = 4525;
 
     @Override
-    public String saveSpaceFileRecord(SpaceFileRecordDTO spaceFileRecordDTO) throws Exception {
+    public String saveSpaceFileRecord(SpaceFileRecordDTO spaceFileRecordDTO) {
         if (StringUtils.isEmpty(spaceFileRecordDTO.getId())) {
             spaceFileRecordDTO.setId(StringUtils.getUUID());
         }
@@ -235,4 +243,125 @@ public class SpaceFileRecordServiceImpl implements ISpaceFileRecordService {
         }
         return retList;
     }
+
+    public String uploadAddShpFileV1(MultipartFile file, String fromRoute, Integer fromtype, String storeStats) throws Exception {
+        //获得文件名称
+        String fileName = file.getOriginalFilename();
+        //获得文件后缀名
+        String type = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
+        //判断上传的是否是压缩包
+        if (!type.equals("zip")) {
+            throw new Exception("请上传压缩包");
+        }
+        // 获取当前时间的时间戳
+        long timeMillis = System.currentTimeMillis();
+        //生成SHP解压文件路径
+        String unzipPath = shpLocalFilePath + "/temp" + "/" + timeMillis;
+        //解压文件
+        uploadDestMultipartFile(file, unzipPath);
+
+        String newShpPath = null;
+        List<File> shpFiles = new ArrayList<>();
+        FileUtils.findShpFiles(new File(unzipPath), shpFiles);
+        if (shpFiles.size() > 0) {
+            newShpPath = shpFiles.get(0).getPath();
+        }
+        if (StringUtils.isEmpty(newShpPath)) {
+            throw new Exception("未读取到SHP文件");
+        }
+//        File newShpFile = new File(newShpPath);
+        TUploadGeomDTO dto = new TUploadGeomDTO();
+        dto.setId(StringUtils.getUUID());
+        dto.setUploaduser(SecurityUtils.getUsername());
+        dto.setSridarea(sridArea);
+        dto.setFromtype(fromtype);
+        dto.setFromroute(fromRoute);
+        dto.setName(fileName);
+        dto.setFiletype(type);
+        dto.setUnzippath(unzipPath.replace("\\", "/"));
+        if (newShpPath != null) {
+            dto.setShppath(newShpPath.replace("\\", "/"));
+        }
+
+        List<Map<String, Object>> shpFeaturesList = shpFileSaveService.readShapeFile(newShpPath);
+        int sort = 0;
+        for (Map<String, Object> shpFeatures : shpFeaturesList) {
+            TUploadGeomDetailsDTO detailsDTO = new TUploadGeomDetailsDTO();
+            detailsDTO.setId(StringUtils.getUUID());
+            detailsDTO.setUploadId(dto.getId());
+            detailsDTO.setGeom((String) shpFeatures.get("the_geom"));
+            shpFeatures.remove("the_geom");
+            detailsDTO.setSridarea(sridArea);
+            detailsDTO.setSort(sort);
+            detailsDTO.setGeomJson(JSON.toJSONString(shpFeatures));
+            tUploadGeomDetailsMapper.insertTUploadGeomDetails(detailsDTO);
+            sort++;
+        }
+
+        TUploadGeomDTO retDto = tUploadGeomDetailsMapper.sumTUploadGeomDetailsByUploadId(dto.getId());
+        dto.setGeom(retDto.getGeom());
+        dto.setSpotsnumber(retDto.getSpotsnumber());
+        tUploadGeomMapper.insertTUploadGeom(dto);
+        return dto.getId();
+    }
+
+    public String uploadAddShpDrawV1(String geom, String fromRoute, Integer fromtype, String storeStats) {
+        String ewkt = "SRID=4326;" + geom;
+        if (geom.toLowerCase().indexOf("srid") >= 0) {
+            ewkt = geom;
+        }
+        TUploadGeomDTO dto = new TUploadGeomDTO();
+        dto.setId(StringUtils.getUUID());
+        dto.setUploaduser(SecurityUtils.getUsername());
+        dto.setGeom(ewkt);
+        dto.setSpotsnumber(1);
+        dto.setSridarea(sridArea);
+        dto.setFromtype(fromtype);
+        dto.setFromroute(fromRoute);
+        tUploadGeomMapper.insertTUploadGeom(dto);
+
+        TUploadGeomDetailsDTO detailsDTO = new TUploadGeomDetailsDTO();
+        detailsDTO.setId(StringUtils.getUUID());
+        detailsDTO.setUploadId(dto.getId());
+        detailsDTO.setGeom(ewkt);
+        detailsDTO.setGeom(ewkt);
+        detailsDTO.setSridarea(sridArea);
+        detailsDTO.setGeomJson("{\"id\":\"" + detailsDTO.getId() + "\"}");
+        tUploadGeomDetailsMapper.insertTUploadGeomDetails(detailsDTO);
+        return dto.getId();
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public int deleteTUploadGeomById(String id) {
+        tUploadGeomDetailsMapper.deleteTUploadGeomDetailsByUploadId(id);
+        return tUploadGeomMapper.deleteTUploadGeomById(id);
+    }
+
+
+    @Override
+    public TUploadGeomDTO selectTUploadGeomById(String id, Integer isDetail) {
+        TUploadGeomDTO dto = tUploadGeomMapper.selectTUploadGeomById(id);
+        if (dto == null) {
+            return null;
+        }
+        if (isDetail != null && isDetail == 1) {
+            TUploadGeomDetailsDTO uploadGeomDetailsDTO = new TUploadGeomDetailsDTO();
+            uploadGeomDetailsDTO.setUploadId(dto.getId());
+            List<TUploadGeomDetailsDTO> dataList = tUploadGeomDetailsMapper.selectTUploadGeomDetailsList(uploadGeomDetailsDTO);
+            dto.settUploadGeomDetailsDTOList(dataList);
+        }
+        return dto;
+    }
+
+    @Override
+    public TUploadGeomDetailsDTO selectTUploadGeomDetailsById(String id) {
+        return tUploadGeomDetailsMapper.selectTUploadGeomDetailsById(id);
+    }
+
+    @Override
+    public void handleUploadGeomFollowUp(String id, Integer followup) {
+        System.out.println("handleUploadGeomFollowUp!!!!!!!");
+    }
+
 }

+ 68 - 0
onemap-modules/onemap-file/src/main/resources/mapper/postgresql/TUploadGeomDetailsMapper.xml

@@ -0,0 +1,68 @@
+<?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.TUploadGeomDetailsMapper">
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="TUploadGeomDetailsDTO" id="TUploadGeomDetailsDTOResult">
+        <result property="id" column="id"/>
+        <result property="geom" column="geom"/>
+        <result property="geomarea" column="geomarea"/>
+        <result property="uploadId" column="upload_id"/>
+        <result property="geomJson" column="geom_json"/>
+        <result property="sort" column="sort"/>
+    </resultMap>
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="TUploadGeomDTO" id="TUploadGeomDTOResult">
+        <result property="uploaduser" column="uploaduser"/>
+        <result property="uploadtime" column="uploadtime"/>
+        <result property="unzippath" column="unzippath"/>
+        <result property="spotsnumber" column="spotsnumber"/>
+        <result property="spotsarea" column="spotsarea"/>
+        <result property="shppath" column="shppath"/>
+        <result property="name" column="name"/>
+        <result property="id" column="id"/>
+        <result property="geom" column="geom"/>
+        <result property="fromtype" column="fromtype"/>
+        <result property="fromroute" column="fromroute"/>
+        <result property="filetype" column="filetype"/>
+        <result property="filepath" column="filepath"/>
+    </resultMap>
+
+
+    <sql id="selectTUploadGeomDetailsVo">
+        select id,public.st_asewkt(geom) AS  geom,round(geomarea,2) geomarea,upload_id,geom_json,sort
+        from t_upload_geom_details
+    </sql>
+
+    <insert id="insertTUploadGeomDetails" parameterType="TUploadGeomDetailsDTO">
+        INSERT INTO t_upload_geom_details (id,geom,geomarea,upload_id,geom_json,sort)
+        VALUES (#{id}, public.st_transform(public.st_geomfromewkt(#{geom}), 4326),
+        public.st_area(public.st_transform(public.st_geomfromewkt(#{geom}), #{sridarea})),#{uploadId},#{geomJson},#{sort})
+    </insert>
+
+    <select id="selectTUploadGeomDetailsList" parameterType="TUploadGeomDetailsDTO" resultMap="TUploadGeomDetailsDTOResult">
+        <include refid="selectTUploadGeomDetailsVo"/>
+        <where>
+            <if test="id!=null and id !='' " >and id = #{id}</if>
+            <if test="uploadId!=null and uploadId !='' " >and upload_id = #{uploadId}</if>
+        </where>
+        order by sort asc
+    </select>
+
+    <select id="selectTUploadGeomDetailsById" parameterType="String" resultMap="TUploadGeomDetailsDTOResult" >
+        <include refid="selectTUploadGeomDetailsVo"/>
+        where id = #{id}
+    </select>
+
+    <select id="sumTUploadGeomDetailsByUploadId" parameterType="String" resultMap="TUploadGeomDTOResult" >
+        select public.st_asewkt(public.st_union(geom)) AS  geom, count(*) spotsnumber
+        from t_upload_geom_details where upload_id = #{id}
+    </select>
+    
+    <delete id="deleteTUploadGeomDetailsByUploadId" parameterType="String">
+        delete from t_upload_geom_details where upload_id = #{id}
+    </delete>
+
+</mapper>

+ 39 - 0
onemap-modules/onemap-file/src/main/resources/mapper/postgresql/TUploadGeomMapper.xml

@@ -0,0 +1,39 @@
+<?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.TUploadGeomMapper">
+
+    <!-- 可根据自己的需求,是否要使用 -->
+    <resultMap type="TUploadGeomDTO" id="TUploadGeomDTOResult">
+        <result property="uploaduser" column="uploaduser"/>
+        <result property="uploadtime" column="uploadtime"/>
+        <result property="unzippath" column="unzippath"/>
+        <result property="spotsnumber" column="spotsnumber"/>
+        <result property="spotsarea" column="spotsarea"/>
+        <result property="shppath" column="shppath"/>
+        <result property="name" column="name"/>
+        <result property="id" column="id"/>
+        <result property="geom" column="geom"/>
+        <result property="fromtype" column="fromtype"/>
+        <result property="fromroute" column="fromroute"/>
+        <result property="filetype" column="filetype"/>
+        <result property="filepath" column="filepath"/>
+    </resultMap>
+
+    <insert id="insertTUploadGeom" parameterType="TUploadGeomDTO">
+        INSERT INTO t_upload_geom (id,name,uploaduser,uploadtime,unzippath,spotsnumber,spotsarea,shppath,geom,fromtype,fromroute,filetype,filepath)
+        VALUES (#{id},#{name},#{uploaduser},now(), #{unzippath}, #{spotsnumber}, public.st_area(public.st_transform(public.st_geomfromewkt(#{geom}), #{sridarea})),#{shppath},
+         public.st_transform(public.st_geomfromewkt(#{geom}), 4326),#{fromtype},#{fromroute},#{filetype},#{filepath})
+    </insert>
+
+    <select id="selectTUploadGeomById" parameterType="String" resultMap="TUploadGeomDTOResult">
+        select id,name,uploaduser,uploadtime,unzippath,spotsnumber,round(spotsarea,2) spotsarea,shppath,public.st_asewkt(geom) AS geom,fromtype,fromroute,filetype,filepath
+        from t_upload_geom
+        where id = #{id}
+    </select>
+    
+    <delete id="deleteTUploadGeomById"  parameterType="String">
+        delete from t_upload_geom where id = #{id}
+    </delete>
+
+</mapper>