ソースを参照

geo 数据处理

reghao 1 年間 前
コミット
0993a3e230

+ 115 - 1
content/content-service/src/test/java/cn/reghao/tnb/content/app/vod/service/GeoTest.java

@@ -1,9 +1,20 @@
 package cn.reghao.tnb.content.app.vod.service;
 
 import cn.reghao.jutil.jdk.serializer.JsonConverter;
+import cn.reghao.jutil.jdk.text.TextFile;
 import cn.reghao.tnb.content.app.ContentApplication;
+import cn.reghao.tnb.content.app.geo.db.mapper.GeoChinaMapper;
+import cn.reghao.tnb.content.app.geo.db.mapper.GeoPointMapper;
+import cn.reghao.tnb.content.app.geo.db.mapper.GeoPolygonMapper;
 import cn.reghao.tnb.content.app.geo.db.mapper.MallReplyMapper;
+import cn.reghao.tnb.content.app.geo.model.po.GeoChina;
+import cn.reghao.tnb.content.app.geo.model.po.GeoPoint;
+import cn.reghao.tnb.content.app.geo.model.po.GeoPolygon;
 import cn.reghao.tnb.content.app.geo.model.po.MallReply;
+import cn.reghao.tnb.content.app.geo.model.vo.GeoData;
+import cn.reghao.tnb.content.app.geo.model.vo.MapPoint;
+import cn.reghao.tnb.content.app.geo.service.GeoService;
+import cn.reghao.tnb.content.app.geo.service.MapService;
 import com.google.gson.JsonObject;
 import lombok.extern.slf4j.Slf4j;
 import org.junit.Test;
@@ -12,8 +23,13 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
+import org.springframework.transaction.interceptor.TransactionAspectSupport;
 
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 /**
  * @author reghao
@@ -25,8 +41,106 @@ import java.util.List;
 @RunWith(SpringRunner.class)
 public class GeoTest {
     @Autowired
-    MallReplyMapper mallReplyMapper;
+    MapService mapService;
+    @Autowired
+    GeoPointMapper geoPointMapper;
+    @Test
+    public void geoPointTest() {
+        String lngN = "123.266667";
+        String latN = "53.55";
+
+        String lngS = "112.283333";
+        String latS = "3.966667";
+
+        String lngE = "134.7738";
+        String latE = "47.7738";
+
+        String lngW = "73.5";
+        String latW = "39.38";
+
+        MapPoint mapPointN = new MapPoint(lngN, latN);
+        MapPoint mapPointS = new MapPoint(lngS, latS);
+        MapPoint mapPointE = new MapPoint(lngE, latE);
+        MapPoint mapPointW = new MapPoint(lngW, latW);
+
+        List<GeoPoint> list = new ArrayList<>();
+        list.add(new GeoPoint(mapPointN, "最北"));
+        list.add(new GeoPoint(mapPointS, "最南"));
+        list.add(new GeoPoint(mapPointE, "最东"));
+        list.add(new GeoPoint(mapPointW, "最西"));
+        geoPointMapper.saveAll(list);
+    }
+
+    @Autowired
+    GeoChinaMapper geoChinaMapper;
+    @Autowired
+    GeoPolygonMapper geoPolygonMapper;
+    @Autowired
+    GeoService geoService;
+    @Test
+    public void geoPolygonTest() {
+        TextFile textFile = new TextFile();
+
+        String filePath = "/home/reghao/Downloads/geo/ok_geo.csv";
+        List<String> list = textFile.read(filePath);
+        Map<Integer, GeoData> map  = new HashMap<>();
+        for (int i = 1; i < list.size(); i++) {
+            String line = list.get(i);
+            String[] arr = line.split(",\"");
+            String[] arr1 = arr[0].split(",");
+
+            if (arr1[0].startsWith("71")) {
+                continue;
+            }
+
+            Integer id = Integer.parseInt(arr1[0]);
+            Integer pid = Integer.parseInt(arr1[1]);
+            Integer deep = Integer.parseInt(arr1[2]);
+            String name = arr[1].replace("\"", "");;
+            String extPath = arr[2].replace("\"", "");;
+            String geo = arr[3];
+            String[] geoArr = geo.replace("\"", "").split(" ");
+            BigDecimal lat = BigDecimal.valueOf(Double.parseDouble(geoArr[0]));
+            BigDecimal lng = BigDecimal.valueOf(Double.parseDouble(geoArr[1]));
+            String polygon = arr[4].replace("\"", "");
+            String first = polygon.split(",")[0];
+            polygon += "," + first;
+
+            GeoPolygon geoPolygon = new GeoPolygon(id, polygon);
+            GeoChina geoChina = new GeoChina(id, pid, deep, name, extPath, lat, lng);
+            GeoData geoData = new GeoData(geoChina, geoPolygon);
+            map.put(id, geoData);
+        }
+
+        map.forEach((id, geoData) -> {
+            GeoPolygon geoPolygon = geoData.getGeoPolygon();
+            GeoChina geoChina = geoData.getGeoChina();
+            GeoChina geoChina1 = geoChinaMapper.findById(id);
+            if (geoChina1 == null) {
+                geoChina1 = geoChina;
+                geoService.add(geoChina1, geoPolygon);
+            }
+        });
+    }
 
+    private String getEarthPolygon(String polygon) {
+        List<String> list1 = new ArrayList<>();
+        String[] polygonArr = polygon.split(",");
+        for (String point : polygonArr) {
+            String[] pointArr = point.split(" ");
+            list1.add(pointArr[0] + "," + pointArr[1] + ",0");
+        }
+
+        StringBuilder sb = new StringBuilder();
+        for (String str : list1) {
+            sb.append(str).append(" ");
+        }
+
+        return sb.toString().trim();
+    }
+
+    @Autowired
+    MallReplyMapper mallReplyMapper;
     @Test
     public void test() {
         List<MallReply> list = mallReplyMapper.findAll();