|
@@ -4,12 +4,13 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.skyversation.poiaddr.addquery.AddressQueryEngine;
|
|
|
import com.skyversation.poiaddr.addquery.Constant;
|
|
|
-import com.skyversation.poiaddr.bean.Address;
|
|
|
-import com.skyversation.poiaddr.bean.AddressResult;
|
|
|
-import com.skyversation.poiaddr.bean.GeoJsonBean;
|
|
|
+import com.skyversation.poiaddr.bean.*;
|
|
|
import com.skyversation.poiaddr.config.DbConnection;
|
|
|
+import com.skyversation.poiaddr.service.impl.YyszAddressRepository;
|
|
|
+import com.skyversation.poiaddr.service.impl.ZrrCallBackRepository;
|
|
|
import com.skyversation.poiaddr.util.ShanghaiAddressSplitUtil;
|
|
|
import com.skyversation.poiaddr.util.SplitAddress;
|
|
|
+import com.skyversation.poiaddr.util.status.AddressResultEnum;
|
|
|
import com.skyversation.poiaddr.util.tasks.ScheduledTasks;
|
|
|
import org.geotools.geojson.geom.GeometryJSON;
|
|
|
import org.geotools.geometry.jts.JTSFactoryFinder;
|
|
@@ -23,14 +24,26 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.ExecutionException;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+import java.util.concurrent.Future;
|
|
|
|
|
|
@Service
|
|
|
public class AreaService {
|
|
|
|
|
|
private static AreaService instance;
|
|
|
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private YyszAddressRepository yyszAddressRepository;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private ZrrCallBackRepository zrrCallBackRepository;
|
|
|
+
|
|
|
public static AreaService getInstance() {
|
|
|
if (instance == null) {
|
|
|
return new AreaService();
|
|
@@ -90,6 +103,7 @@ public class AreaService {
|
|
|
try {
|
|
|
System.out.println("<<<<<<<<------开始数据库连通性测试");
|
|
|
System.out.println("------数据库连通性测试结果:" + DbConnection.getInstance().runSqlStr("select count(*) from " + searchTableName));
|
|
|
+ initScheduledTasksSetAddress();
|
|
|
} catch (Exception e) {
|
|
|
System.err.println(">>>>>>>>------数据库连通性测试结果:" + e);
|
|
|
}
|
|
@@ -160,6 +174,121 @@ public class AreaService {
|
|
|
System.out.println("<<<<<<<<------run geo data complete------>>>>>>>>>");
|
|
|
}
|
|
|
|
|
|
+ public void initScheduledTasksSetAddress() {
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ List<ZrrCallback20250609> zrrCallback20250609s = zrrCallBackRepository.findAll();
|
|
|
+ if (zrrCallback20250609s.size() > 0) {
|
|
|
+ for (ZrrCallback20250609 zrrCallback20250609 : zrrCallback20250609s) {
|
|
|
+ ScheduledTasks.setAddress.add(zrrCallback20250609.getSearchAddress());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ System.out.println("ScheduledTasks.setAddress初始化完成,共" + ScheduledTasks.setAddress.size() + "条,查询用时:" + (System.currentTimeMillis() - startTime) / 1000 + "秒!");
|
|
|
+ }
|
|
|
+
|
|
|
+ public void selectLimitData(int page, int pageSize, int endPage) {
|
|
|
+ Map<String, Object> loginfoMap = new HashMap<>();
|
|
|
+ loginfoMap.put("page", page);
|
|
|
+ loginfoMap.put("pageSize", pageSize);
|
|
|
+ try {
|
|
|
+ long startTime = System.currentTimeMillis();
|
|
|
+ loginfoMap.put("startTime", startTime);
|
|
|
+ List<Map<String, Object>> callBackDatas = DbConnection.getInstance().runSqlStr("select roomdetailedaddress,hjdz from dws.dws_sjqdsjzx_zrr_hjjzxx_arrange order by ryid limit " + (page * pageSize) + "," + pageSize);
|
|
|
+ System.out.println("数据库查询page:" + page + ",pageSize:" + pageSize + "完成,用时:" + (System.currentTimeMillis() - startTime) / 1000 + "秒!");
|
|
|
+ if (callBackDatas != null && callBackDatas.size() > 0 && page < endPage) {
|
|
|
+ Set<String> address = new HashSet<>();
|
|
|
+ for (Map<String, Object> dataI : callBackDatas) {
|
|
|
+ if (dataI.get("roomdetailedaddress") != null && StringUtils.hasText(dataI.get("roomdetailedaddress") + "") && !ScheduledTasks.setAddress.contains(dataI.get("roomdetailedaddress") + "")) {
|
|
|
+ address.add(dataI.get("roomdetailedaddress") + "");
|
|
|
+ ScheduledTasks.setAddress.add(dataI.get("roomdetailedaddress") + "");
|
|
|
+ }
|
|
|
+ if (dataI.get("hjdz") != null && StringUtils.hasText(dataI.get("hjdz") + "") && !ScheduledTasks.setAddress.contains(dataI.get("hjdz") + "")) {
|
|
|
+ address.add(dataI.get("hjdz") + "");
|
|
|
+ ScheduledTasks.setAddress.add(dataI.get("hjdz") + "");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ callBackDatas.clear();
|
|
|
+ List<ZrrCallback20250609> outDatas = new ArrayList<>();
|
|
|
+ int MaxTnumber = Runtime.getRuntime().availableProcessors();
|
|
|
+ System.out.println("共:《" + address.size() + "》条数据!最大可用线程数:" + MaxTnumber);
|
|
|
+ int index = 0;
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(MaxTnumber / 2);
|
|
|
+ List<Future<?>> futures = new ArrayList<>();
|
|
|
+ for (String addrStr : address) {
|
|
|
+ index++;
|
|
|
+ int finalIndex = index;
|
|
|
+ futures.add(executorService.submit(() -> {
|
|
|
+ System.out.print(">" + finalIndex);
|
|
|
+ ZrrCallback20250609 zrrCallback20250609 = new ZrrCallback20250609();
|
|
|
+ zrrCallback20250609.setSearchAddress(addrStr);
|
|
|
+ AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName_nw(addrStr);
|
|
|
+ AddressResult.ContentBean contentBean = new AddressResult.ContentBean();
|
|
|
+ if (addressResult != null && addressResult.getCode() == AddressResultEnum.DB_SUCCESS && addressResult.getData() != null && addressResult.getData().size() > 0) {
|
|
|
+ contentBean = addressResult.getData().get(0);
|
|
|
+ }
|
|
|
+ if (contentBean != null && contentBean.getLon() != null) {
|
|
|
+ AddressQueryEngine.getInstance().getCjWgWgwByLoc(addressResult);
|
|
|
+ zrrCallback20250609.setLat(contentBean.getLat() + "");
|
|
|
+ zrrCallback20250609.setLon(contentBean.getLon() + "");
|
|
|
+ zrrCallback20250609.setPname(contentBean.getPname());
|
|
|
+ zrrCallback20250609.setCounty(contentBean.getCityname());
|
|
|
+ zrrCallback20250609.setCankaoAddress(contentBean.getAddress());
|
|
|
+ zrrCallback20250609.setStreetTownName(contentBean.getAdname());
|
|
|
+ zrrCallback20250609.setCommunity(contentBean.getCommunity());
|
|
|
+ zrrCallback20250609.setStandardAddress(contentBean.getStandAddr());
|
|
|
+ SplitAddress splitAddress = ShanghaiAddressSplitUtil.splitBestAddress(addrStr);
|
|
|
+ if (!StringUtils.hasText(contentBean.getPname())) {
|
|
|
+ contentBean.setPname(splitAddress.getCity());
|
|
|
+ zrrCallback20250609.setPname(splitAddress.getCity());
|
|
|
+ }
|
|
|
+ if (!StringUtils.hasText(contentBean.getPname())) {
|
|
|
+ contentBean.setPname("上海市");
|
|
|
+ zrrCallback20250609.setPname("上海市");
|
|
|
+ }
|
|
|
+ zrrCallback20250609.setStandardAddress(contentBean.getPname() + contentBean.getCityname() +
|
|
|
+ contentBean.getAdname() + contentBean.getCommunity() + splitAddress.getAddr());
|
|
|
+ }
|
|
|
+ if (zrrCallback20250609.getSearchAddress() != null) {
|
|
|
+ outDatas.add(zrrCallback20250609);
|
|
|
+ }
|
|
|
+ }));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 等待所有任务完成
|
|
|
+ for (Future<?> future : futures) {
|
|
|
+ try {
|
|
|
+ future.get();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ System.err.println("线程异常:" + e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 关闭线程池
|
|
|
+ executorService.shutdown();
|
|
|
+ zrrCallBackRepository.saveAll(outDatas);
|
|
|
+ long endTime = System.currentTimeMillis();
|
|
|
+ System.out.println("处理完成!用时" + (endTime - startTime) / 1000 + "秒!");
|
|
|
+ loginfoMap.put("endTime", endTime);
|
|
|
+ loginfoMap.put("message", "成功");
|
|
|
+ page++;
|
|
|
+ selectLimitData(page, pageSize, endPage);
|
|
|
+ } else if (page < endPage) {
|
|
|
+ loginfoMap.put("endTime", System.currentTimeMillis());
|
|
|
+ loginfoMap.put("message", "当前页数据已处理!");
|
|
|
+ page++;
|
|
|
+ selectLimitData(page, pageSize, endPage);
|
|
|
+ } else {
|
|
|
+ System.out.println("所有数据处理完成");
|
|
|
+ loginfoMap.put("endTime", System.currentTimeMillis());
|
|
|
+ loginfoMap.put("message", "所有数据处理完成!");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ loginfoMap.put("endTime", System.currentTimeMillis());
|
|
|
+ loginfoMap.put("message", "异常页码:" + page + ",error:" + e);
|
|
|
+ } finally {
|
|
|
+ ScheduledTasks.logInfos.add(loginfoMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 批量插入数据到callback表
|
|
|
*/
|
|
@@ -180,13 +309,6 @@ public class AreaService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- *
|
|
|
- */
|
|
|
- public void getCallBackDatas(){
|
|
|
- String Sql = "";
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 是否进入callBack表判断
|
|
|
*
|
|
@@ -216,7 +338,7 @@ public class AreaService {
|
|
|
* @param splitAddress
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Address> getRecommendAddress(SplitAddress splitAddress) {
|
|
|
+ /*public List<Address> getRecommendAddress(SplitAddress splitAddress) {
|
|
|
if (splitAddress.getCity() == null) {
|
|
|
splitAddress.setCity("");
|
|
|
}
|
|
@@ -237,10 +359,10 @@ public class AreaService {
|
|
|
} catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
// 进行数据库查询
|
|
|
- public List<Address> getAddressPoisByAddr(SplitAddress splitAddress) {
|
|
|
+ /*public List<Address> getAddressPoisByAddr(SplitAddress splitAddress) {
|
|
|
if (splitAddress.getAddr().contains("号")) {
|
|
|
splitAddress.setSearchAddr(splitAddress.getAddr().substring(0, splitAddress.getAddr().lastIndexOf("号")));
|
|
|
}
|
|
@@ -272,23 +394,64 @@ public class AreaService {
|
|
|
}
|
|
|
|
|
|
return list;
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
/**
|
|
|
* 根据地址关键字查询数据库结果
|
|
|
*
|
|
|
- * @param addr
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Address> getAddressPoiOnlyDB(String addr) {
|
|
|
+ /*public List<Address> getAddressPoiOnlyDB(String addr) {
|
|
|
try {
|
|
|
return odsToAddr(DbConnection.getInstance().runSqlStr("select * from " + Constant.getSearchTableName() + " WHERE sourceaddress LIKE '%" + addr + "%' or address LIKE '%" + addr + "%' order by updatetime desc LIMIT 20"));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
return null;
|
|
|
+ }*/
|
|
|
+ public List<yyskDmdzAddressStandardization> getAddressPoisByAddr(SplitAddress splitAddress) {
|
|
|
+ if (splitAddress.getAddr().contains("号")) {
|
|
|
+ splitAddress.setSearchAddr(splitAddress.getAddr().substring(0, splitAddress.getAddr().indexOf("号")));
|
|
|
+ }
|
|
|
+ if (splitAddress.getAddr().contains("弄")) {
|
|
|
+ splitAddress.setSearchAddr(splitAddress.getAddr().substring(0, splitAddress.getAddr().indexOf("弄")));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (splitAddress.getSearchAddr() == null) {
|
|
|
+ splitAddress.setSearchAddr(splitAddress.getAddr());
|
|
|
+ }
|
|
|
+ List<yyskDmdzAddressStandardization> list = null;
|
|
|
+ if (StringUtils.hasText(splitAddress.getDistrict())) {
|
|
|
+ list = yyszAddressRepository.getAddressPoisByAddrAQX(splitAddress.getDistrict(), splitAddress.getSearchAddr());
|
|
|
+ }
|
|
|
+ if (list == null) {
|
|
|
+ list = yyszAddressRepository.getAddressPoisByAddr(splitAddress.getSearchAddr());
|
|
|
+ }
|
|
|
+
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<yyskDmdzAddressStandardization> getAddressPoiOnlyDB(String addr) {
|
|
|
+ return yyszAddressRepository.getAddressPoisByAddr(addr);
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<yyskDmdzAddressStandardization> getRecommendAddress(SplitAddress splitAddress) {
|
|
|
+ if (splitAddress.getCity() == null) {
|
|
|
+ splitAddress.setCity("");
|
|
|
+ }
|
|
|
+ if (splitAddress.getDistrict() == null) {
|
|
|
+ splitAddress.setDistrict("");
|
|
|
+ }
|
|
|
+ if (splitAddress.getStreet() == null) {
|
|
|
+ splitAddress.setStreet("");
|
|
|
+ }
|
|
|
+ if (splitAddress.getCommunity() == null) {
|
|
|
+ splitAddress.setCommunity("");
|
|
|
+ }
|
|
|
+ return yyszAddressRepository.getAddressPoisByDivisions(splitAddress.getCity(), splitAddress.getDistrict(), splitAddress.getStreet(), splitAddress.getCommunity());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public List<Map<String, Object>> getUniScDatas() {
|
|
|
try {
|
|
|
return DbConnection.getInstance().runSqlStr("select * from songjiang_uni_sc_id_v1"); // where real_address is not null and street_town_name is null
|