DESKTOP-6LTVLN7\Liumouren 1 month ago
parent
commit
1b2a8fc648

+ 16 - 0
src/main/java/com/skyversation/poiaddr/addquery/Constant.java

@@ -32,4 +32,20 @@ public class Constant {
     @Value("${amap_city_code}")
     public static  String AMAP_CITY_CODE = "310118";
 
+//    oauth和dms搭建服务器地址
+    public static String ServerBaseUrl = "http://121.43.55.7:";
+//    DMS服务端口和路径
+    public static String Dms_Base_Url = ServerBaseUrl + ":2101/proxy_dms";
+//    Oauth服务端口和路径
+    public static String Oauth_Base_Url = ServerBaseUrl + "2101/proxy_oauth";
+
+//    Oauth登录接口(直接使用user001默认登录获取token)
+    public static String Oauth_login_URL = Oauth_Base_Url + "/user/login?userName=user001&password=1234567890&clientId=2";
+
+//    DMS添加数据接口
+    public static String DMS_addContent_URL = Dms_Base_Url + "/content/addContent";
+//    DMS修改数据接口
+    public static String DMS_updateContent_URL = Dms_Base_Url + "/content/updateContent";
+//    DMS查询接口
+    public static String DMS_selectContentList_URL = Dms_Base_Url + "/content/selectContentList";
 }

+ 5 - 93
src/main/java/com/skyversation/poiaddr/util/dms/DmsTools.java

@@ -1,5 +1,6 @@
 package com.skyversation.poiaddr.util.dms;
 
+import com.skyversation.poiaddr.addquery.Constant;
 import com.skyversation.poiaddr.util.RequestUtils;
 import org.json.JSONArray;
 import org.json.simple.JSONObject;
@@ -15,10 +16,9 @@ import java.util.Map;
 public class DmsTools {
     public static String DmsToken;
 
-
     //  登录操作,请求token
     public static String getDmsToken() {
-        JSONObject resultObject = RequestUtils.requestPost("http://121.43.55.7:2101/proxy_oauth/user/login?userName=user001&password=1234567890&clientId=2", null, null);
+        JSONObject resultObject = RequestUtils.requestPost(Constant.Oauth_login_URL, null, null);
         if (resultObject != null && resultObject.containsKey("message") && resultObject.get("message") != null) {
             DmsToken = resultObject.get("message").toString();
         }
@@ -37,7 +37,7 @@ public class DmsTools {
         formDatas.put("states", "0");
         formDatas.put("pageSize", "9999");
         formDatas.put("page", "0");
-        return RequestUtils.requestPost("http://121.43.55.7:2101/proxy_dms/content/selectContentList", headers, formDatas);
+        return RequestUtils.requestPost(Constant.DMS_selectContentList_URL, headers, formDatas);
     }
 
     public static JSONObject addContent(org.json.JSONObject formDatas) {
@@ -47,7 +47,7 @@ public class DmsTools {
         } else {
             headers.put("Token", getDmsToken());
         }
-        return RequestUtils.requestPost2("http://121.43.55.7:2101/proxy_dms/content/addContent", headers, formDatas);
+        return RequestUtils.requestPost2(Constant.DMS_addContent_URL, headers, formDatas);
     }
 
     public static JSONObject updateContent(org.json.JSONObject formDatas) {
@@ -57,94 +57,6 @@ public class DmsTools {
         } else {
             headers.put("Token", getDmsToken());
         }
-        return RequestUtils.requestPost2("http://121.43.55.7:2101/proxy_dms/content/updateContent", headers, formDatas);
-    }
-
-    public static void main(String[] args) {
-//      解析geojson文件并将学校名称和招生区域保存为一个Map<String(学校名称),String(招生区域geojson)>
-//      是否检查数据(true:不更新DMS只检查文件数据,false:数据正确的前提下执行DMS更新操作)
-        Boolean ifDatas = false;
-        Map<String, org.json.JSONObject> fileDatas = new HashMap<>();
-        String filePath = "C:\\Users\\Liumouren\\Desktop\\临时文件\\元以科技\\青浦\\教育局\\geojsonUpdate\\幼儿园更新.json";
-        try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
-            StringBuilder stringBuilder = new StringBuilder();
-            String line;
-            while ((line = reader.readLine()) != null) {
-                stringBuilder.append(line);
-            }
-            String jsonString = stringBuilder.toString();
-            org.json.JSONObject jsonObject1 = new org.json.JSONObject(jsonString);
-            JSONArray features = jsonObject1.getJSONArray("features");
-//            System.out.println(features);
-            for (int i = 0; i < features.length(); i++) {
-                if (features.getJSONObject(i).getJSONObject("properties").has("name") && features.getJSONObject(i).getJSONObject("geometry").getJSONArray("coordinates").length() > 0) {
-                    String schoolName = features.getJSONObject(i).getJSONObject("properties").getString("name");
-                    features.getJSONObject(i).remove("properties");
-                    fileDatas.put(schoolName, features.getJSONObject(i));
-                }
-            }
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-//      查询columnId为1477的所有数据
-        JSONObject dmsDatas1 = selectDms("1477");
-//      遍历数据
-//        System.out.println(dmsDatas1);
-        List<String> hasName = new ArrayList<>();
-        Map<String, org.json.JSONObject> newSchoolGeojson = new HashMap<>();
-        if ("200".equals(dmsDatas1.get("code").toString())) {
-//          请求成功,遍历数据
-            org.json.JSONObject dmsDataContents = new org.json.JSONObject(dmsDatas1.get("content").toString());
-            JSONArray dmsDataList = dmsDataContents.getJSONArray("data");
-            for (int i = 0; i < dmsDataList.length(); i++) {
-                org.json.JSONObject item = dmsDataList.getJSONObject(i);
-                if (fileDatas.containsKey(item.getString("title"))) {
-//                  是否名字能匹配上,能的话记录一下id
-                    hasName.add(item.getString("title"));
-                    String id = item.getString("id");
-                    if (ifDatas) {
-                        newSchoolGeojson.put(item.getString("title"), fileDatas.get(item.getString("title")));
-                    } else {
-                        newSchoolGeojson.put(item.getString("title") + "_" + id, fileDatas.get(item.getString("title")));
-                    }
-                    if (item.has("c_geojson") && item.getString("c_geojson").length() > 2) {
-                        System.out.println("替换geojson的学校名称:" + item.getString("title"));
-                    } else {
-                        System.out.println("新增geojson的学校名称:" + item.getString("title"));
-                    }
-                }
-            }
-        }
-        if(ifDatas){
-            System.out.println("解析到的文件数据:" + fileDatas.size());
-            System.out.println(newSchoolGeojson);
-            for (String schoolName : fileDatas.keySet()) {
-                if (!newSchoolGeojson.containsKey(schoolName)) {
-                    System.err.println("DMS中不存在学校:" + schoolName);
-                }
-            }
-        }else{
-//      准备更新数据
-//      首先得到关键数据(id\columnId\modelId) 1542\1445
-            org.json.JSONObject params = new org.json.JSONObject();
-            params.put("columnId", "1542");
-            params.put("modelId", "1445");
-            for (String schoolNameAndId : newSchoolGeojson.keySet()) {
-                String schoolName = schoolNameAndId.split("_")[0];
-                String id = schoolNameAndId.split("_")[1];
-                org.json.JSONObject paramsContent = new org.json.JSONObject();
-                paramsContent.put("id", id);
-                org.json.JSONObject cGeojson = new org.json.JSONObject();
-                cGeojson.put("type", "FeatureCollection");
-                JSONArray coordinates = new JSONArray();
-                coordinates.put(newSchoolGeojson.get(schoolNameAndId));
-                cGeojson.put("features", coordinates);
-                paramsContent.put("c_geojson", cGeojson.toString());
-                params.put("content", paramsContent);
-                System.out.println("更新" + schoolName + updateContent(params));
-            }
-//      更新结束
-        }
-
+        return RequestUtils.requestPost2(Constant.DMS_updateContent_URL, headers, formDatas);
     }
 }

+ 2 - 2
src/main/java/com/skyversation/poiaddr/util/geotools/GeoJsonIntersector.java

@@ -13,7 +13,7 @@ import java.util.List;
  * 根据街道名称和村名得到青浦匹配的村庄geojson合集
  */
 public class GeoJsonIntersector {
-    public static void main(String[] args) throws Exception {
+    /*public static void main(String[] args) throws Exception {
         run("香花桥街道", "向阳村,爱星村,大联村,东方村,金米村,东斜村,新姚村,新桥村,民惠第三居委会,燕南村,泾阳村,胜利村,天一村,曹泾村,香花桥居委会,朝阳村,金星村,都汇华庭居委会,陈桥村,盈中村,石西村,杨元村,袁家村,七汇村,郏一村,青山居委会,金巷居委会", "博文中学");
 //        run("香花桥街道", "燕南村,泾阳村,东方村,大联村,金米村,新桥村,爱星村,大盈居委会,民惠居委会,民惠第二居委会,民惠第三居委会,新姚村,友爱居委会,胜利村,天一村,向阳村,曹泾村,东斜村", "博文小学");
 //        run("香花桥街道","香花桥居委会,朝阳村,金星村,都汇华庭居委会,盈中村,石西村,杨元村,七汇村,袁家村,郏一村,青山居委会,金巷居委会","香花桥小学");
@@ -22,7 +22,7 @@ public class GeoJsonIntersector {
 //        run("盈浦街道", "南横村", "思源中学");
 //        run("夏阳街道","仓桥村","仓桥村");
 
-    }
+    }*/
 
     public static void run(String jdNameStr, String czNameStr, String fileName) throws Exception {
         List<String> jdNameList = new ArrayList<>(Arrays.asList(jdNameStr.split(",")));

+ 2 - 2
src/main/java/com/skyversation/poiaddr/util/geotools/GeoJsonPointInRegion.java

@@ -24,7 +24,7 @@ public class GeoJsonPointInRegion {
         return geo.contains(pointGeom);
     }
 
-    public static void main(String[] args) {
+    /*public static void main(String[] args) {
         String sampleGeoJson = "{\"type\":\"Polygon\",\"coordinates\":[[[116.3,39.9],[116.4,39.9],[116.4,40.0],[116.3,40.0],[116.3,39.9]]]}";
         double lon = 116.35;
         double lat = 39.95;
@@ -38,5 +38,5 @@ public class GeoJsonPointInRegion {
         } catch (IOException | ParseException e) {
             e.printStackTrace();
         }
-    }
+    }*/
 }

+ 2 - 2
src/main/java/com/skyversation/poiaddr/util/geotools/GeometryIntersectionAndDisjoint.java

@@ -21,7 +21,7 @@ import org.locationtech.jts.io.WKTReader;
  */
 public class GeometryIntersectionAndDisjoint {
 
-    public static void main(String[] args) {
+    /*public static void main(String[] args) {
         GeometryFactory geometryFactory = new GeometryFactory();
         WKTReader wktReader = new WKTReader(geometryFactory);
 
@@ -52,5 +52,5 @@ public class GeometryIntersectionAndDisjoint {
         } catch (ParseException e) {
             e.printStackTrace();
         }
-    }
+    }*/
 }