From 3430a3dd889ba51d06cbdb77014aa63d0a070e48 Mon Sep 17 00:00:00 2001
From: rain <167982779@qq.com>
Date: Fri, 16 Aug 2024 16:38:08 +0800
Subject: [PATCH] 优化国土对接接口

---
 src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java |   84 +++++++++++++++++++++++++++++------------
 1 files changed, 59 insertions(+), 25 deletions(-)

diff --git a/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java b/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
index 5a13fba..2c5d384 100644
--- a/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
+++ b/src/main/java/com/dji/sample/patches/service/impl/ShpToDataSourceServiceImpl.java
@@ -3,12 +3,10 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.dji.sample.patches.config.pojo.PatchesConfigPojo;
 import com.dji.sample.patches.dao.ShpToDataSourceMapper;
+import com.dji.sample.patches.model.dto.ShpDTO;
 import com.dji.sample.patches.model.entity.LotInfo;
 import com.dji.sample.patches.service.ShpToDataSourceService;
-import com.dji.sample.patches.utils.FormatConversionUtil;
-import com.dji.sample.patches.utils.GeoToolsUtil;
-import com.dji.sample.patches.utils.MultipartFileTOFileUtil;
-import com.dji.sample.patches.utils.ShapeFileUtil;
+import com.dji.sample.patches.utils.*;
 import com.dji.sample.patches.xml.mode.XMLTemplateModel;
 import com.dji.sample.patches.xml.utils.CreateWaylineFileUtils;
 import com.dji.sample.territory.model.entity.TbDkjbxxEntity;
@@ -22,6 +20,7 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.UUID;
 
@@ -46,31 +45,27 @@
     private PatchesConfigPojo patchesConfigPojo;
 
     @Transactional
-    public MultipartFile insertGeo(MultipartFile file, String workspaceId, String waylineName, double airportLat, double airportLon) throws Exception {
+    public MultipartFile insertGeo(MultipartFile file, String workspaceId, String waylineName, double airportLat, double airportLon,String creator) throws Exception {
         List<LotInfo> list = new ArrayList<>();
         File file1 = MultipartFileTOFileUtil.multipartFile2File(file, patchesConfigPojo.getUnzip());
-        List<String> s = ShapeFileUtil.shpToGeoJson(file1);
-        String[] arr1 = FormatConversionUtil.formatConversion(s);
-        for (int i = 0; i < arr1.length; i++) {
+        List<ShpDTO> shpData = ShapeFileUtil.shpToGeoJson(file1);
+        for (ShpDTO shpDatum : shpData) {
             LotInfo lotInfo = new LotInfo();
-            String temp = arr1[i].trim();
-            temp = FormatConversionUtil.modifySpacesAndCommas(temp);
-            json = head + temp;
             String uuid = UUID.randomUUID().toString();
             String bsm = uuid.replaceAll("-", "");
             lotInfo.setBsm(bsm);
+            lotInfo.setUserName(creator);
             lotInfo.setWorkspaceId(workspaceId);
-            lotInfo.setDkfw(json);
-            lotInfo.setDkbh("dkbh" + i);
+            lotInfo.setDkfw(poylonCGCStoWGS(convertToWKT(shpDatum.getDKFW())));
+            lotInfo.setDkbh(shpDatum.getDKBH());
+            lotInfo.setXzb(shpDatum.getXZB());
+            lotInfo.setYzb(shpDatum.getYZB());
+            lotInfo.setXzqdm(shpDatum.getXZQDM());
+            lotInfo.setXmc(DistrictCodeUtils.codeToName(lotInfo.getXzqdm()));
             list.add(lotInfo);
-            String strs = getCentros(list);
-            String end = strs.replaceAll("\\(", "").replaceAll(", NaN\\)", "");
-            String[] points = end.split(",");
-            lotInfo.setXzb(Double.valueOf(points[0]));
-            lotInfo.setYzb(Double.valueOf(points[1]));
             shpToDataSourceMapper.insert(lotInfo);
         }
-        Coordinate[] coordinates = GeoToolsUtil.getRoutePointOrder(list, airportLat, airportLon);
+        List<PointPO> coordinates = GeoToolsUtil.getRoutePointOrder(list, airportLat, airportLon);
         XMLTemplateModel xmlModel = XMLTemplateModel.init(coordinates, list);
         CreateWaylineFileUtils.createWaylineFile(xmlModel, patchesConfigPojo.getTemplate(), patchesConfigPojo.getTargetTemplate(), patchesConfigPojo.getWaylines(), patchesConfigPojo.getTargetWaylines());
         // 压缩文件夹中的内容
@@ -82,11 +77,14 @@
     }
 
     @Transactional
-    public void savaInMysql(List<TbDkjbxxEntity> list, String workspaceId) {
+    public void savaInMysql(List<TbDkjbxxEntity> list, String workspaceId,String id,String name) {
         for (int i = 0; i < list.size(); i++) {
             LotInfo lotInfo = new LotInfo();
             lotInfo.setWorkspaceId(workspaceId);
-            lotInfo = dbConvertToEntity(list.get(i), workspaceId);
+            lotInfo.setTaskId(id);
+            lotInfo.setType(2);
+            lotInfo.setTaskName(name);
+            lotInfo = dbConvertToEntity(list.get(i), workspaceId, id, name);
             shpToDataSourceMapper.insert(lotInfo);
         }
     }
@@ -98,20 +96,56 @@
      * @param file 需要转换的DKJBXX对象。
      * @return 返回一个构建好的LotInfo对象,包含从数据库实体中转换来的信息。
      */
-    private LotInfo dbConvertToEntity(TbDkjbxxEntity file, String workspaceId) {
+    private LotInfo dbConvertToEntity(TbDkjbxxEntity file, String workspaceId,String id,String name) {
         LotInfo.LotInfoBuilder builder = LotInfo.builder();
         builder.bsm(file.getFId())
-                .xzqdm(file.getFXzqdmsys())
+                .xzqdm(file.getFXzqdm())
                 .dkbh(file.getFTbbh())
                 .dkfw(file.getFShape())
                 .workspaceId(workspaceId)
-                .isplan(0)
+                .isPlan(0)
+                .isPush(0)
+                .xmc(DistrictCodeUtils.nameToCode(file.getFXzqdm()))
+                .investigate(0)
+                .taskId(id)
+                .taskName(name)
                 .build();
         return builder.build();
     }
 
+//    private LotInfo shpDtoToLotInfo(ShpDTO shpDTO){
+//        LotInfo.LotInfoBuilder builder=LotInfo.builder();
+//        builder.
+//
+//    }
+
     public List<LotInfo> getNoPlan(){
-   return shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getIsplan,0));
+   return shpToDataSourceMapper.selectList(new LambdaQueryWrapper<LotInfo>().eq(LotInfo::getIsPlan,0));
+    }
+    public static String convertToWKT(String coordinates) {
+        // Remove outermost square brackets and split by comma
+        String cleanedCoordinates = coordinates.substring(4, coordinates.length() - 4);
+        String[] polygons = cleanedCoordinates.split("\\]\\],\\[\\[");
+        StringBuilder wkt = new StringBuilder("MULTIPOLYGON(");
+
+        for (String polygon : polygons) {
+            wkt.append("((");
+            String[] points = polygon.split("\\],\\[");
+            for (String point : points) {
+                String[] coords = point.split(",");
+                double x = Double.parseDouble(coords[0]);
+                double y = Double.parseDouble(coords[1]);
+                wkt.append(x).append(" ").append(y).append(", ");
+            }
+            // Remove the last comma and space
+            wkt.setLength(wkt.length() - 2);
+            wkt.append(")), ");
+        }
+        // Remove the last comma and space, and close the polygon
+        wkt.setLength(wkt.length() - 2);
+        wkt.append(")");
+
+        return wkt.toString();
     }
 }
 

--
Gitblit v1.9.3