|
@@ -3,20 +3,25 @@ package com.skyversation.poiaddr.service;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.skyversation.poiaddr.addquery.AddressQueryEngine;
|
|
|
+import com.skyversation.poiaddr.bean.AddressResult;
|
|
|
import com.skyversation.poiaddr.bean.GeoJsonBean;
|
|
|
import com.skyversation.poiaddr.bean.Village;
|
|
|
import com.skyversation.poiaddr.bean.Zerenwangluo;
|
|
|
+import com.skyversation.poiaddr.service.impl.LegalPersonServiceImpl;
|
|
|
import com.skyversation.poiaddr.util.CoordTransform;
|
|
|
+import com.skyversation.poiaddr.util.status.AddressLevel;
|
|
|
import org.geotools.geojson.geom.GeometryJSON;
|
|
|
import org.geotools.geometry.jts.JTSFactoryFinder;
|
|
|
import org.locationtech.jts.geom.Geometry;
|
|
|
import org.locationtech.jts.geom.MultiPolygon;
|
|
|
import org.locationtech.jts.io.ParseException;
|
|
|
import org.locationtech.jts.io.WKTReader;
|
|
|
+import org.springframework.core.io.ClassPathResource;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import org.springframework.util.ResourceUtils;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
@@ -24,6 +29,9 @@ import java.util.List;
|
|
|
@Service
|
|
|
public class AreaService {
|
|
|
|
|
|
+ @Resource
|
|
|
+ private LegalPersonServiceImpl legalPersonServiceimpl;
|
|
|
+
|
|
|
private static AreaService instance;
|
|
|
|
|
|
public static AreaService getInstance() {
|
|
@@ -51,9 +59,38 @@ public class AreaService {
|
|
|
public void initGeoData() {
|
|
|
System.out.println("<<<<<<<<------AreaService>initGeoData------>>>>>>>>>");
|
|
|
instance = this;
|
|
|
- new Thread(() -> runGeoData()).start();
|
|
|
- new Thread(() -> runZEWLData()).start();
|
|
|
- new Thread(() -> initPolygons()).start();
|
|
|
+ Thread thread1 = new Thread(this::runGeoData);
|
|
|
+ Thread thread2 = new Thread(this::runZEWLData);
|
|
|
+ Thread thread3 = new Thread(this::initPolygons);
|
|
|
+
|
|
|
+ // 启动三个线程
|
|
|
+ thread1.start();
|
|
|
+ thread2.start();
|
|
|
+ thread3.start();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 等待三个线程执行完毕
|
|
|
+ thread1.join();
|
|
|
+ thread2.join();
|
|
|
+ thread3.join();
|
|
|
+ } catch (InterruptedException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+// TODO 网络连通性测试,可以请求一下测试的市中心地址
|
|
|
+ try {
|
|
|
+ AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName(new String[]{"上海市青浦区馨浦苑西区2号楼1201"}, AddressLevel.values()[0]);
|
|
|
+ System.out.println("<<<<<<<<------网络连通性测试结果:" + addressResult);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("<<<<<<<<------网络连通性测试结果:" + e);
|
|
|
+ }
|
|
|
+
|
|
|
+// TODO 数据库连接测试,可以查询表数据
|
|
|
+ try {
|
|
|
+ legalPersonServiceimpl.iterativeProcessing(1, 100);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("<<<<<<<<------数据库连接测试异常:" + e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public void initPolygons() {
|
|
@@ -61,22 +98,22 @@ public class AreaService {
|
|
|
lis.add(cjPolygonList);
|
|
|
lis.add(wGridPolygonList);
|
|
|
lis.add(gridPolygonList);
|
|
|
- String[] path = new String[]{"classpath:geojson/qp_cunju.geojson", "classpath:geojson/青浦区微网格-wgs84.geojson",
|
|
|
- "classpath:geojson/责任网格-wgs84.geojson"};
|
|
|
-// String[] path = new String[]{"D:/geojson/qp_cunju.geojson", "D:/geojson/青浦区微网格-wgs84.geojson",
|
|
|
-// "D:/geojson/责任网格-wgs84.geojson"};
|
|
|
+ String[] path = new String[]{"geojson/qp_cunju.geojson", "geojson/青浦区微网格-wgs84.geojson",
|
|
|
+ "geojson/责任网格-wgs84.geojson"};
|
|
|
|
|
|
for (int j = 0; j < path.length; j++) {
|
|
|
- BufferedReader br = null;
|
|
|
+ BufferedReader reader = null;
|
|
|
try {
|
|
|
- File file = ResourceUtils.getFile(path[j]);
|
|
|
- br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
|
|
- String line = br.readLine();
|
|
|
+ // 创建 ClassPathResource 对象,指定静态文件的路径
|
|
|
+ ClassPathResource resource = new ClassPathResource(path[j]);
|
|
|
+ // 获取文件的输入流
|
|
|
+ reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
|
|
|
+ String line;
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- while (line != null) {
|
|
|
- sb.append(line + "\r\n");
|
|
|
- line = br.readLine();
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ sb.append(line).append("\r\n");
|
|
|
}
|
|
|
+ reader.close();
|
|
|
JSONObject json = JSONObject.parseObject(sb.toString());
|
|
|
|
|
|
JSONArray featrues = json.getJSONArray("features");
|
|
@@ -91,7 +128,7 @@ public class AreaService {
|
|
|
GeometryJSON geometryJSON = new GeometryJSON();
|
|
|
MultiPolygon multiPolygon = geometryJSON.readMultiPolygon(geoJson.toJSONString());
|
|
|
GeoJsonBean geoJsonBean = new GeoJsonBean();
|
|
|
- if (file.getName().contains("cunju")) {
|
|
|
+ if (path[j].contains("cunju")) {
|
|
|
JSONObject resultProp = new JSONObject();
|
|
|
resultProp.put("网格名称", properties.getString("__10"));
|
|
|
resultProp.put("shape_leng", properties.getString("shape__length"));
|
|
@@ -106,7 +143,7 @@ public class AreaService {
|
|
|
resultProp.put("面积", properties.getString("__1"));
|
|
|
resultProp.put("objectid", properties.getString("objectid"));
|
|
|
geoJsonBean.setProperties(resultProp);
|
|
|
- } else if (file.getName().contains("微网格")) {
|
|
|
+ } else if (path[j].contains("微网格")) {
|
|
|
JSONObject resultProp = new JSONObject();
|
|
|
resultProp.put("objectid", properties.getString("OBJECTID"));
|
|
|
resultProp.put("所属街道", properties.getString("æ\u0089\u0080å±\u009Eè¡\u0097"));
|
|
@@ -116,7 +153,7 @@ public class AreaService {
|
|
|
resultProp.put("Shape_Area", properties.getString("Shape_Area"));
|
|
|
resultProp.put("微格网名称", properties.getString("å¾®ç½\u0091_1"));
|
|
|
geoJsonBean.setProperties(resultProp);
|
|
|
- } else if (file.getName().contains("责任网格")) {
|
|
|
+ } else if (path[j].contains("责任网格")) {
|
|
|
geoJsonBean.setProperties(properties);
|
|
|
}
|
|
|
geoJsonBean.setMultiPolygon(multiPolygon);
|
|
@@ -189,17 +226,17 @@ public class AreaService {
|
|
|
* 初始化责任网络数据
|
|
|
**/
|
|
|
public void runZEWLData() {
|
|
|
- JSONArray jsonArray = new JSONArray();
|
|
|
- BufferedReader br = null;
|
|
|
try {
|
|
|
- File file = ResourceUtils.getFile("classpath:geojson/zerenwangluo.json");
|
|
|
- br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
|
|
- String line = br.readLine();
|
|
|
+ // 创建 ClassPathResource 对象,指定静态文件的路径
|
|
|
+ ClassPathResource resource = new ClassPathResource("geojson/zerenwangluo.json");
|
|
|
+ // 获取文件的输入流
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
|
|
|
+ String line;
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- while (line != null) {
|
|
|
- sb.append(line + "\r\n");
|
|
|
- line = br.readLine();
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ sb.append(line).append("\r\n");
|
|
|
}
|
|
|
+ reader.close();
|
|
|
zrwl = JSONObject.parseObject(sb.toString(), Zerenwangluo.class);
|
|
|
zrwlFeatures = zrwl.getFeatures();
|
|
|
for (int i = 0; i < zrwlFeatures.size(); i++) {
|
|
@@ -300,17 +337,17 @@ public class AreaService {
|
|
|
* 初始化村居数据
|
|
|
**/
|
|
|
public void runGeoData() {
|
|
|
- BufferedReader br = null;
|
|
|
try {
|
|
|
- File file = ResourceUtils.getFile("classpath:geojson/qp_cunju.geojson");
|
|
|
- br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
|
|
|
- String line = br.readLine();
|
|
|
+ // 创建 ClassPathResource 对象,指定静态文件的路径
|
|
|
+ ClassPathResource resource = new ClassPathResource("geojson/qp_cunju.json");
|
|
|
+ // 获取文件的输入流
|
|
|
+ BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()));
|
|
|
+ String line;
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
- while (line != null) {
|
|
|
- sb.append(line + "\r\n");
|
|
|
- line = br.readLine();
|
|
|
+ while ((line = reader.readLine()) != null) {
|
|
|
+ sb.append(line).append("\r\n");
|
|
|
}
|
|
|
-
|
|
|
+ reader.close();
|
|
|
JSONObject json = JSONObject.parseObject(sb.toString());
|
|
|
JSONArray features = json.getJSONArray("features");
|
|
|
for (int i = 0; i < features.size(); i++) {
|
|
@@ -324,9 +361,7 @@ public class AreaService {
|
|
|
featureList.add(feature);
|
|
|
propertiList.add(JSONObject.parseObject(feature.getJSONObject("properties").toJSONString(), Village.class));
|
|
|
mulPolygonList.add(multiPolygon);
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
} catch (FileNotFoundException e) {
|
|
|
e.printStackTrace();
|
|
|
System.out.println("<<<<<<<<------run geo data error------>>>>>>>>>");
|