|
|
@@ -3,22 +3,24 @@ package com.skyversation.poiaddr.service.impl;
|
|
|
import com.skyversation.poiaddr.addquery.AddressQueryEngine;
|
|
|
import com.skyversation.poiaddr.addquery.Constant;
|
|
|
import com.skyversation.poiaddr.bean.AddressResult;
|
|
|
+import com.skyversation.poiaddr.bean.TAddressCallback;
|
|
|
import com.skyversation.poiaddr.config.DbConnection;
|
|
|
import com.skyversation.poiaddr.entity.TmpSongjiangEntity;
|
|
|
import com.skyversation.poiaddr.entity.YyskAddressStandardization;
|
|
|
import com.skyversation.poiaddr.util.AddressTools;
|
|
|
+import com.skyversation.poiaddr.util.Coordinate;
|
|
|
import com.skyversation.poiaddr.util.ExcelReaderUtils;
|
|
|
import com.skyversation.poiaddr.util.tasks.ScheduledTasks;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
import java.sql.SQLException;
|
|
|
import java.sql.Types;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.ExecutionException;
|
|
|
-import java.util.concurrent.ExecutorService;
|
|
|
-import java.util.concurrent.Executors;
|
|
|
-import java.util.concurrent.Future;
|
|
|
+import java.util.concurrent.*;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
@@ -69,33 +71,33 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public List<TmpSongjiangEntity> selectBydzName(List<TmpSongjiangEntity> dataList){
|
|
|
- for(TmpSongjiangEntity tmpSongjiangEntity : dataList){
|
|
|
- try{
|
|
|
+ public List<TmpSongjiangEntity> selectBydzName(List<TmpSongjiangEntity> dataList) {
|
|
|
+ for (TmpSongjiangEntity tmpSongjiangEntity : dataList) {
|
|
|
+ try {
|
|
|
String hjdz = tmpSongjiangEntity.getHjdz();
|
|
|
- hjdz.replace("工业区","");
|
|
|
+ hjdz.replace("工业区", "");
|
|
|
Pattern pattern = Pattern.compile("\\d");
|
|
|
Matcher matcher = pattern.matcher(hjdz);
|
|
|
String likeStr = "";
|
|
|
- if(matcher.find()){
|
|
|
- likeStr = hjdz.substring(0,matcher.start());
|
|
|
+ if (matcher.find()) {
|
|
|
+ likeStr = hjdz.substring(0, matcher.start());
|
|
|
}
|
|
|
String sql = "select sourceaddress,city,county,town,community from \n" + Constant.getSearchTableName() +
|
|
|
- " where county = '松江区' and town is not null and sourceaddress like '%"+likeStr+"%' limit 1";
|
|
|
+ " where county = '松江区' and town is not null and sourceaddress like '%" + likeStr + "%' limit 1";
|
|
|
|
|
|
List<Map<String, Object>> dbData = DbConnection.getInstance().runSqlStr(sql);
|
|
|
- if(dbData != null && dbData.size() == 1){
|
|
|
+ if (dbData != null && dbData.size() == 1) {
|
|
|
Map<String, Object> sqlData = dbData.get(0);
|
|
|
tmpSongjiangEntity.setHjdbzjw(sqlData.get("community") != null ? sqlData.get("community").toString() : null);
|
|
|
tmpSongjiangEntity.setHjdbzjd(sqlData.get("town") != null ? sqlData.get("town").toString() : null);
|
|
|
tmpSongjiangEntity.setHjdbzqh(sqlData.get("county") != null ? sqlData.get("county").toString() : null);
|
|
|
- tmpSongjiangEntity.setHjdzdz("上海市"+tmpSongjiangEntity.getHjdbzqh()+tmpSongjiangEntity.getHjdbzjd()+tmpSongjiangEntity.getHjdbzjw()+hjdz.replace(tmpSongjiangEntity.getHjdbzjd(),""));
|
|
|
+ tmpSongjiangEntity.setHjdzdz("上海市" + tmpSongjiangEntity.getHjdbzqh() + tmpSongjiangEntity.getHjdbzjd() + tmpSongjiangEntity.getHjdbzjw() + hjdz.replace(tmpSongjiangEntity.getHjdbzjd(), ""));
|
|
|
}
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
- return dataList;
|
|
|
+ return dataList;
|
|
|
}
|
|
|
|
|
|
// 分页查询地址表
|
|
|
@@ -121,93 +123,71 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // 批量修改地址表
|
|
|
- /*public void updateDatas(List<YyskAddressStandardization> 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) {
|
|
|
- if (entity.getAddress() != null) {
|
|
|
- if (entity.getLat() == null) {
|
|
|
- preparedStatement.setNull(1, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(1, entity.getLat());
|
|
|
- }
|
|
|
- if (entity.getLon() == null) {
|
|
|
- preparedStatement.setNull(2, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(2, entity.getLon());
|
|
|
- }
|
|
|
- if (entity.getMarket() == null) {
|
|
|
- preparedStatement.setNull(3, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(3, entity.getMarket());
|
|
|
- }
|
|
|
- if (entity.getDistinguish() == null) {
|
|
|
- preparedStatement.setNull(4, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(4, entity.getDistinguish());
|
|
|
- }
|
|
|
- if (entity.getStreetTown() == null) {
|
|
|
- preparedStatement.setNull(5, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(5, entity.getStreetTown());
|
|
|
- }
|
|
|
- if (entity.getResidentialCommittee() == null) {
|
|
|
- preparedStatement.setNull(6, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(6, entity.getResidentialCommittee());
|
|
|
- }
|
|
|
- if (entity.getReturnAddress() == null) {
|
|
|
- preparedStatement.setNull(7, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(7, entity.getReturnAddress());
|
|
|
- }
|
|
|
- if (entity.getStandardAddress() == null) {
|
|
|
- preparedStatement.setNull(8, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(8, entity.getStandardAddress());
|
|
|
- }
|
|
|
- if (entity.getMatchLevel() == null) {
|
|
|
- preparedStatement.setNull(9, Types.VARCHAR);
|
|
|
- } else {
|
|
|
- preparedStatement.setString(9, entity.getMatchLevel());
|
|
|
- }
|
|
|
- if (entity.getUpdateTime() == null) {
|
|
|
- preparedStatement.setNull(10, Types.DATE);
|
|
|
- } else {
|
|
|
- preparedStatement.setLong(10, entity.getUpdateTime().getTime());
|
|
|
- }
|
|
|
- preparedStatement.setString(11, entity.getAddress());
|
|
|
- // 将当前的 SQL 语句添加到批量操作中
|
|
|
- preparedStatement.addBatch();
|
|
|
+ /**
|
|
|
+ * 生成当前时间的字符串,格式为:年-月-日 时:分:秒
|
|
|
+ *
|
|
|
+ * @return 格式化后的时间字符串
|
|
|
+ */
|
|
|
+ public static String getCurrentTimeString() {
|
|
|
+ // 获取当前日期时间
|
|
|
+ LocalDateTime now = LocalDateTime.now();
|
|
|
+ // 定义时间格式器
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
|
+ // 格式化并返回
|
|
|
+ return now.format(formatter);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前时间戳(精确到毫秒)加4位随机自然数的字符串
|
|
|
+ * 格式示例:1730289600123 + 4567 → "17302896001234567"
|
|
|
+ *
|
|
|
+ * @return 组合后的字符串
|
|
|
+ */
|
|
|
+ public static String getTimestampWithRandom() {
|
|
|
+ long timestamp = System.currentTimeMillis();
|
|
|
+ // 高并发场景推荐使用ThreadLocalRandom
|
|
|
+ int randomNum = 1000 + ThreadLocalRandom.current().nextInt(9000);
|
|
|
+ return timestamp + String.valueOf(randomNum);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void insertIntoSjAddressGovernanceResultsTableFinal(List<TAddressCallback> datas) {
|
|
|
+ StringBuilder sqls = new StringBuilder("INSERT INTO kjyy_dev.sj_address_governance_results_table_final (abbreviated_address,batch_number," +
|
|
|
+ "city,community,county,data_table,field,in_data,lat,lon,match_level,original_address,row_id,standard_address,town,x,y) values ");
|
|
|
+ Set<String> rowIds = new HashSet<>();
|
|
|
+ String rowId = getTimestampWithRandom();
|
|
|
+ for (TAddressCallback item : datas) {
|
|
|
+ if (item.getStatusTag() == 2 && StringUtils.isNotEmpty(item.getLon()) && StringUtils.isNotEmpty(item.getLat())) {
|
|
|
+ sqls.append("('").append(item.getCankaoAddress()).append("',");
|
|
|
+ sqls.append("'").append("diyBatchNumber").append("',");
|
|
|
+ sqls.append("'").append(item.getPname()).append("',");
|
|
|
+ sqls.append("'").append(item.getCommunity()).append("',");
|
|
|
+ sqls.append("'").append(item.getCounty()).append("',");
|
|
|
+ sqls.append("'").append("callBack").append("',");
|
|
|
+ sqls.append("'").append("callBack").append("',");
|
|
|
+// 当前时间字符串
|
|
|
+ sqls.append("'").append(getCurrentTimeString()).append("',");
|
|
|
+ sqls.append("'").append(item.getLat()).append("',");
|
|
|
+ sqls.append("'").append(item.getLon()).append("',");
|
|
|
+ sqls.append("'").append("回流").append("',");
|
|
|
+ sqls.append("'").append(item.getSearchAddress()).append("',");
|
|
|
+// rowId:时间戳加随机4位自然数
|
|
|
+ while (rowIds.contains(rowId)) {
|
|
|
+ rowId = getTimestampWithRandom();
|
|
|
}
|
|
|
+ rowIds.add(rowId);
|
|
|
+ sqls.append("'").append(rowId).append("',");
|
|
|
+ sqls.append("'").append(item.getStandardAddress()).append("',");
|
|
|
+ sqls.append("'").append(item.getStreetTownName()).append("',");
|
|
|
+// x,y:使用经纬度转换
|
|
|
+ double[] xy = Coordinate.wgs84_to_shcj(Double.parseDouble(item.getLon()), Double.parseDouble(item.getLat()));
|
|
|
+ sqls.append("'").append(xy[0]).append("',");
|
|
|
+ sqls.append("'").append(xy[1]).append("') ,");
|
|
|
}
|
|
|
- // 执行批量操作
|
|
|
- int[] updateCounts = preparedStatement.executeBatch();
|
|
|
- System.out.println("总条数:" + sjArrDzbzhSjWcbryDzxxList.size() + ";更新的记录数: " + updateCounts.length);
|
|
|
- } catch (SQLException throwables) {
|
|
|
- System.err.println("------updateError--------------------------------------" + sqls + "更新异常!");
|
|
|
- throwables.printStackTrace();
|
|
|
- System.err.println("更新异常" + throwables);
|
|
|
- }
|
|
|
- }*/
|
|
|
-
|
|
|
- public void updateSDDatas(List<Map<String,Object>> datas){
|
|
|
- StringBuffer sqls = new StringBuffer("INSERT INTO songjiang_uni_sc_id_v1 (uni_sc_id,real_address,street_town_name,standard_address,county,town) values ");
|
|
|
- for(Map<String,Object> item:datas){
|
|
|
- sqls.append("('").append(item.get("uni_sc_id")).append("',");
|
|
|
- sqls.append("'").append(item.get("real_address")).append("',");
|
|
|
- sqls.append("'").append(item.get("street_town_name")).append("',");
|
|
|
- sqls.append("'").append(item.get("standard_address")).append("',");
|
|
|
- sqls.append("'").append(item.get("county")).append("',");
|
|
|
- sqls.append("'").append(item.get("street_town_name")).append("') ,");
|
|
|
}
|
|
|
- String runSqlStr = sqls.toString().substring(0,sqls.toString().length() - 2);
|
|
|
- try{
|
|
|
- System.out.println(runSqlStr);
|
|
|
+ String runSqlStr = sqls.substring(0, sqls.toString().length() - 2);
|
|
|
+ try {
|
|
|
DbConnection.getInstance().updateSql(runSqlStr);
|
|
|
- }catch (Exception e){
|
|
|
+ } catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
@@ -327,8 +307,9 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
System.out.println("跳出迭代!");
|
|
|
}
|
|
|
}
|
|
|
- public List<TmpSongjiangEntity> selectBydz(List<TmpSongjiangEntity> listData){
|
|
|
- for(TmpSongjiangEntity tmpSongjiangEntity:listData){
|
|
|
+
|
|
|
+ public List<TmpSongjiangEntity> selectBydz(List<TmpSongjiangEntity> listData) {
|
|
|
+ for (TmpSongjiangEntity tmpSongjiangEntity : listData) {
|
|
|
|
|
|
}
|
|
|
return listData;
|