|
@@ -1,18 +1,20 @@
|
|
|
package com.skyversation.poiaddr.service.impl;
|
|
|
|
|
|
+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.config.DbConnection;
|
|
|
import com.skyversation.poiaddr.entity.AmapAddressV3;
|
|
|
+import com.skyversation.poiaddr.entity.FusionKjdlTydzWf;
|
|
|
import com.skyversation.poiaddr.entity.YyskAddressStandardization;
|
|
|
+import com.skyversation.poiaddr.entity.YyskDmdzAddressStandardization;
|
|
|
import com.skyversation.poiaddr.service.AreaService;
|
|
|
-import com.skyversation.poiaddr.util.AddressMatcher;
|
|
|
-import com.skyversation.poiaddr.util.AddressTools;
|
|
|
-import com.skyversation.poiaddr.util.Coordinate;
|
|
|
-import com.skyversation.poiaddr.util.ExcelReaderUtils;
|
|
|
+import com.skyversation.poiaddr.util.*;
|
|
|
import com.skyversation.poiaddr.util.tasks.ScheduledTasks;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
|
import java.sql.Types;
|
|
@@ -59,13 +61,13 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
}
|
|
|
|
|
|
// 分页查询地址表
|
|
|
- public List<YyskAddressStandardization> getAllDataPage(int size, int pageNum, String tableName, String whereStr) {
|
|
|
+ public List<YyskDmdzAddressStandardization> getAllDataPage(int size, int pageNum, String tableName, String whereStr) {
|
|
|
try {
|
|
|
- List<YyskAddressStandardization> requestData = new ArrayList<>();
|
|
|
+ List<YyskDmdzAddressStandardization> requestData = new ArrayList<>();
|
|
|
String sql = "SELECT * FROM " + tableName + " WHERE " + whereStr + " limit " + size * pageNum + "," + size;
|
|
|
List<Map<String, Object>> dbData = DbConnection.getInstance().runSqlStr(sql);
|
|
|
for (Map<String, Object> item : dbData) {
|
|
|
- YyskAddressStandardization YyskAddressStandardization = new YyskAddressStandardization();
|
|
|
+ YyskDmdzAddressStandardization YyskAddressStandardization = new YyskDmdzAddressStandardization();
|
|
|
if (item.get("address") != null) {
|
|
|
YyskAddressStandardization.setAddress(item.getOrDefault("address", "").toString());
|
|
|
}
|
|
@@ -79,11 +81,11 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
}
|
|
|
|
|
|
// 批量修改地址表
|
|
|
- public void updateDatas(List<YyskAddressStandardization> sjArrDzbzhSjWcbryDzxxList, String tableName) {
|
|
|
+ public void updateDatas(List<YyskDmdzAddressStandardization> sjArrDzbzhSjWcbryDzxxList, String tableName) {
|
|
|
String sqls = "update " + tableName + " set lat = ?,lon = ?,market = ?, distinguish = ?, street_town = ?, residential_committee = ?" +
|
|
|
", return_address = ? , standard_address = ? ,match_level = ? , update_time = ? where address = ?";
|
|
|
try (PreparedStatement preparedStatement = DbConnection.getInstance().connection.prepareStatement(sqls)) {
|
|
|
- for (YyskAddressStandardization entity : sjArrDzbzhSjWcbryDzxxList) {
|
|
|
+ for (YyskDmdzAddressStandardization entity : sjArrDzbzhSjWcbryDzxxList) {
|
|
|
if (entity.getAddress() != null) {
|
|
|
if (entity.getLat() == null) {
|
|
|
preparedStatement.setNull(1, Types.VARCHAR);
|
|
@@ -190,13 +192,13 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
System.out.println("<<<<<<<<------iterativeProcessing{pageSize:" + pageSize + ",pageNum:" + pageNum + "}");
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
if (init == 0) {
|
|
|
- List<YyskAddressStandardization> listData = getAllDataPage(pageSize, pageNum, tableName, whereStr);
|
|
|
+ List<YyskDmdzAddressStandardization> listData = getAllDataPage(pageSize, pageNum, tableName, whereStr);
|
|
|
if (listData != null && listData.size() > 0) {
|
|
|
// 批量更新处理后的数据
|
|
|
if (updateToDataBase == 1) {
|
|
|
updateDatas(runExecutorService(listData), tableName);
|
|
|
} else if (updateToDataBase == 0) {
|
|
|
- List<YyskAddressStandardization> resultDataList = runExecutorService(listData);
|
|
|
+ List<YyskDmdzAddressStandardization> resultDataList = runExecutorService(listData);
|
|
|
if (resultDataList.size() > 0) {
|
|
|
ExcelReaderUtils.convertYYListToMapList(resultDataList, "output/yysk_dmdz_address_standardization_" + pageSize + "_" + pageNum + ".xlsx");
|
|
|
}
|
|
@@ -316,10 +318,8 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
int taskId = sort * i + startFileIndex;
|
|
|
// 任务执行
|
|
|
- startMutilExecutor(taskId, fileRootPath + "output5\\yysk_dmdz_address_standardization_200000_" + taskId + ".xlsx",
|
|
|
- fileRootPath + "output6\\yysk_dmdz_address_standardization_200000_" + taskId + ".xlsx");
|
|
|
- /*startMutilExecutor(taskId, fileRootPath + "ziranren\\yysk_dmdz_address_standardization_10000_" + taskId + ".xlsx",
|
|
|
- fileRootPath + "ziranrenOutput\\yysk_dmdz_address_standardization_10000_" + taskId + ".xlsx");*/
|
|
|
+ startMutilExecutor(taskId, fileRootPath + "output8\\yysk_dmdz_address_standardization_200000_" + taskId + ".xlsx",
|
|
|
+ fileRootPath + "output9\\yysk_dmdz_address_standardization_200000_" + taskId + ".xlsx");
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
ScheduledTasks.taskRunStatus = false;
|
|
|
System.out.println("单个文件处理完成!用时" + (endTime - startTime) / 1000 + "秒!");
|
|
@@ -329,11 +329,12 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
public void startMutilExecutor(int startFileIndex, String filePath, String outPath) {
|
|
|
System.out.println("<<<<<<<<------searchLoadFileData{fileIndex:" + startFileIndex + "}");
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
- List<YyskAddressStandardization> listData = new ArrayList<>();
|
|
|
+ List<YyskDmdzAddressStandardization> listData = new ArrayList<>();
|
|
|
+// List<YyskDmdzAddressStandardization> errorDatas = new ArrayList<>();
|
|
|
try {
|
|
|
List<Map<String, Object>> fileData = ExcelReaderUtils.readExcel(filePath);
|
|
|
for (Map<String, Object> item : fileData) {
|
|
|
- YyskAddressStandardization yyskAddressStandardization = new YyskAddressStandardization();
|
|
|
+ YyskDmdzAddressStandardization yyskAddressStandardization = new YyskDmdzAddressStandardization();
|
|
|
yyskAddressStandardization.setAddress(item.getOrDefault("address", "").toString());
|
|
|
yyskAddressStandardization.setDataTag(item.getOrDefault("dataTag", "").toString());
|
|
|
yyskAddressStandardization.setMatchLevel(item.getOrDefault("matchLevel", "").toString());
|
|
@@ -346,32 +347,86 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
yyskAddressStandardization.setResidentialCommittee(item.getOrDefault("residentialCommittee", "").toString());
|
|
|
yyskAddressStandardization.setLon(item.getOrDefault("lat", "").toString());
|
|
|
yyskAddressStandardization.setLat(item.getOrDefault("lon", "").toString());
|
|
|
- listData.add(yyskAddressStandardization);
|
|
|
+ if (!yyskAddressStandardization.getMatchLevel().contains("rule_0") && !yyskAddressStandardization.getMatchLevel().contains("异常") && !yyskAddressStandardization.getDistinguish().contains("[]")) {
|
|
|
+ listData.add(yyskAddressStandardization);
|
|
|
+ }
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
listData = null;
|
|
|
}
|
|
|
if (listData != null && listData.size() > 0) {
|
|
|
// 批量更新处理后的数据
|
|
|
- List<YyskAddressStandardization> resultDataList = runExecutorService(listData);
|
|
|
+ /*List<YyskAddressStandardization> resultDataList = runExecutorService(listData);
|
|
|
if (resultDataList.size() > 0) {
|
|
|
ExcelReaderUtils.convertYYListToMapList(resultDataList, outPath);
|
|
|
+ }*/
|
|
|
+// TODO 数据转换
|
|
|
+ List<FusionKjdlTydzWf> returnDatas = YyskDmdzAddressStandardizationToFusionKjdlTydzWf(listData);
|
|
|
+ try {
|
|
|
+ AreaService.getInstance().saveFktws(returnDatas);
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("第" + startFileIndex + "个文件入库异常:" + e);
|
|
|
}
|
|
|
+
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
System.out.println("处理单批次用时" + (endTime - startTime) / 1000 + "秒!已调用市中心接口个数" + ScheduledTasks.szxRequestSize + ";已調用高德接口个数:" + ScheduledTasks.gdRequestSize);
|
|
|
} else {
|
|
|
System.out.println("<<<<<<<<------ 第" + startFileIndex + "个文件 -----任务处理完成!结果为空。。。--->>>>" + outPath);
|
|
|
}
|
|
|
+// if (errorDatas.size() > 0) {
|
|
|
+// ExcelReaderUtils.convertYYListToMapList(errorDatas, outPath);
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
- public List<YyskAddressStandardization> runExecutorService(List<YyskAddressStandardization> listData) {
|
|
|
+ public List<FusionKjdlTydzWf> YyskDmdzAddressStandardizationToFusionKjdlTydzWf(List<YyskDmdzAddressStandardization> datas) {
|
|
|
+ List<FusionKjdlTydzWf> returnDatas = new ArrayList<>();
|
|
|
+ for (YyskDmdzAddressStandardization item : datas) {
|
|
|
+ FusionKjdlTydzWf fusionKjdlTydzWf = new FusionKjdlTydzWf();
|
|
|
+ fusionKjdlTydzWf.setOid(ScheduledTasks.OID_TAG);
|
|
|
+ ScheduledTasks.OID_TAG++;
|
|
|
+ fusionKjdlTydzWf.setSourceaddress(item.getStandardAddress());
|
|
|
+ fusionKjdlTydzWf.setCity(item.getMarket());
|
|
|
+ fusionKjdlTydzWf.setCounty(item.getDistinguish());
|
|
|
+ fusionKjdlTydzWf.setCityCode("3101");
|
|
|
+// 需要查询
|
|
|
+ fusionKjdlTydzWf.setCountyCode("");
|
|
|
+ fusionKjdlTydzWf.setTown(item.getStreetTown());
|
|
|
+// 需要查询
|
|
|
+ fusionKjdlTydzWf.setTownCode("");
|
|
|
+ fusionKjdlTydzWf.setCommunity(item.getResidentialCommittee());
|
|
|
+// 需要查询
|
|
|
+ fusionKjdlTydzWf.setCommunityCode("");
|
|
|
+// 需要转换成wgs84
|
|
|
+ double[] points = CoordTransform2.getInstance().shcj_to_wgs84(
|
|
|
+ Double.parseDouble(item.getLon()), Double.parseDouble(item.getLat()));
|
|
|
+ fusionKjdlTydzWf.setLon(BigDecimal.valueOf(points[0]));
|
|
|
+// 需要转换成wgs84
|
|
|
+ fusionKjdlTydzWf.setLat(BigDecimal.valueOf(points[1]));
|
|
|
+ fusionKjdlTydzWf.setSource("标准化地址");
|
|
|
+ fusionKjdlTydzWf.setCreatetime(new Date());
|
|
|
+// 需要根据定位查询责任网格
|
|
|
+ fusionKjdlTydzWf.setGridName("");
|
|
|
+// 同上
|
|
|
+ fusionKjdlTydzWf.setGridCode("");
|
|
|
+ fusionKjdlTydzWf.setX(item.getLon());
|
|
|
+ fusionKjdlTydzWf.setY(item.getLat());
|
|
|
+ fusionKjdlTydzWf.setIsHistory(0L);
|
|
|
+ fusionKjdlTydzWf.setAddress(item.getAddress());
|
|
|
+ returnDatas.add(fusionKjdlTydzWf);
|
|
|
+ }
|
|
|
+ datas.clear();
|
|
|
+ return returnDatas;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<YyskDmdzAddressStandardization> runExecutorService(List<YyskDmdzAddressStandardization> listData) {
|
|
|
// 创建线程池
|
|
|
int executorSize = Runtime.getRuntime().availableProcessors() / 2;
|
|
|
System.out.println("创建线程池个数:" + executorSize);
|
|
|
ExecutorService executorService = Executors.newFixedThreadPool(executorSize);
|
|
|
+ AreaService areaService = AreaService.getInstance();
|
|
|
List<Future<?>> futures = new ArrayList<>();
|
|
|
for (int i = 0; i < listData.size(); i++) {
|
|
|
- YyskAddressStandardization item = listData.get(i);
|
|
|
+ YyskDmdzAddressStandardization item = listData.get(i);
|
|
|
int finalI = i;
|
|
|
futures.add(executorService.submit(() -> {
|
|
|
System.out.print(finalI + ">");
|
|
@@ -382,54 +437,40 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
// 默认不查询
|
|
|
boolean ifSearch = false;
|
|
|
// 首先过滤rule_0
|
|
|
- if (item.getMatchLevel().contains("rule_0")) {
|
|
|
- String[] addr = AddressMatcher.matchProvinceAndCity(item.getAddress());
|
|
|
-// 然后
|
|
|
- if(addr == null){
|
|
|
- ifSearch = true;
|
|
|
- }else if (!addr[0].contains("上海")) {
|
|
|
-// 如果查询的地址完全包含省份和市名就不从新擦寻
|
|
|
- if ((!addr[0].isEmpty() && (item.getAddress().contains(addr[0]) || addr[0].contains(item.getAddress()))) || (!addr[1].isEmpty() && (item.getAddress().contains(addr[1]) || addr[1].contains(item.getAddress())))) {
|
|
|
- ifSearch = false;
|
|
|
- }else{
|
|
|
- ifSearch = true;
|
|
|
+ if (!item.getMatchLevel().contains("rule_0") && !item.getMatchLevel().contains("异常")) {
|
|
|
+ String[] addr = new String[]{};
|
|
|
+ if (item.getDistinguish() == null || item.getDistinguish().isEmpty() || item.getDistinguish().trim().length() == 0) {
|
|
|
+ addr = AddressTools.parseAddressJZ(item.getStandardAddress());
|
|
|
+ } else if (item.getDistinguish().equals("[]")) {
|
|
|
+ addr = AddressTools.parseAddressJZ(item.getAddress());
|
|
|
+ }
|
|
|
+ if (addr != null && addr[1] != null && !addr[1].equals("[]")) {
|
|
|
+ item.setDistinguish(addr[1]);
|
|
|
+ } else {
|
|
|
+// 根据经纬度判断落点在哪儿个区
|
|
|
+ String lon = item.getLon();
|
|
|
+ String lat = item.getLat();
|
|
|
+ double[] points = CoordTransform2.getInstance().shcj_to_wgs84(
|
|
|
+ Double.parseDouble(lon), Double.parseDouble(lat));
|
|
|
+ GeoJsonBean adBean = areaService.isInadPolygon(points[0], points[1]);
|
|
|
+ JSONObject properties = adBean.getProperties();
|
|
|
+ if (properties != null && properties.containsKey("name")) {
|
|
|
+ item.setDistinguish(properties.getString("name"));
|
|
|
+ } else {
|
|
|
+ item.setStandardAddress(null);
|
|
|
}
|
|
|
}
|
|
|
- }else if(item.getMatchLevel().contains("异常") && (item.getDistinguish() == null || item.getDistinguish().isEmpty() || item.getDistinguish().contains("[]"))){
|
|
|
- ifSearch = true;
|
|
|
- }else if(item.getStandardAddress().contains("[]")){
|
|
|
- ifSearch = true;
|
|
|
- }
|
|
|
-// 匹配全国省名
|
|
|
-// 遍历全国城市名称匹配搜索地址市名
|
|
|
- /*
|
|
|
- if (addr != null && !addr[0].contains("上海")) {
|
|
|
- addrList.add(item.getAddress());
|
|
|
- item.setMatchLevel("rule_0");
|
|
|
-// 如果查询地址不是完全包含省和市的关键字且属于rule_0,那么就需要重新跑一遍
|
|
|
- if ((!addr[0].isEmpty() && item.getAddress().contains(addr[0])) || (!addr[1].isEmpty() && item.getAddress().contains(addr[1]))) {
|
|
|
- item.setProvinces(addr[0]);
|
|
|
- item.setMarket(addr[1]);
|
|
|
- ifSearch = false;
|
|
|
+ try {
|
|
|
+ String oldAddress = Objects.requireNonNull(AddressTools.parseAddressJZ(item.getStandardAddress()))[3].
|
|
|
+ replaceAll(item.getMarket().equals("[]") ? "" : item.getMarket(), "").
|
|
|
+ replaceAll(item.getDistinguish().equals("[]") ? "" : item.getDistinguish(), "").
|
|
|
+ replaceAll(item.getStreetTown().equals("[]") ? "" : item.getStreetTown(), "").
|
|
|
+ replaceAll(item.getResidentialCommittee().equals("[]") ? "" : item.getResidentialCommittee(), "");
|
|
|
+ item.setStandardAddress(item.getMarket() + item.getDistinguish() + item.getStreetTown() + AddressQueryEngine.townReplace_ct(oldAddress));
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
- } else {
|
|
|
- addrList.add(item.getAddress());
|
|
|
- ifSearch = false;
|
|
|
- String[] strs = AddressTools.parseAddressJZ(item.getAddress());
|
|
|
-// if (strs != null) {
|
|
|
-// item.setProvinces(strs[0] == null ? "" : strs[0]);
|
|
|
-// item.setMarket(strs[0] == null ? "" : strs[0]);
|
|
|
-// item.setDistinguish(strs[1] == null ? "" : strs[1]);
|
|
|
-// item.setStreetTown(strs[2] == null ? "" : strs[2]);
|
|
|
-// }
|
|
|
}
|
|
|
- try {
|
|
|
- if (item.getMatchLevel().contains("异常") || item.getDistinguish() == null || item.getDistinguish().isEmpty() || item.getDistinguish().equals("[]")|| item.getStreetTown() == null || item.getStreetTown().isEmpty()) {
|
|
|
- ifSearch = true;
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }*/
|
|
|
if (ifSearch && addrList.size() > 0) {
|
|
|
// TODO 开始查询
|
|
|
AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName(addrList);
|
|
@@ -522,9 +563,9 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
}
|
|
|
// 关闭线程池
|
|
|
executorService.shutdown();
|
|
|
- List<YyskAddressStandardization> dataList = new ArrayList<>();
|
|
|
- List<YyskAddressStandardization> errData = new ArrayList<>();
|
|
|
- for (YyskAddressStandardization item : listData) {
|
|
|
+ List<YyskDmdzAddressStandardization> dataList = new ArrayList<>();
|
|
|
+ List<YyskDmdzAddressStandardization> errData = new ArrayList<>();
|
|
|
+ for (YyskDmdzAddressStandardization item : listData) {
|
|
|
if (item.getMatchLevel() == null || item.getMatchLevel().isEmpty()) {
|
|
|
errData.add(item);
|
|
|
} else {
|