|
@@ -229,11 +229,40 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
|
|
|
|
|
|
public void searchLoadFileData(String fileRootPath, Integer startFileIndex, Integer endFileIndex, Integer sort) {
|
|
|
+
|
|
|
+
|
|
|
+ // 任务总数
|
|
|
+ int totalTasks = 412;
|
|
|
+ // 最大线程数
|
|
|
+ int maxThreads = 20;
|
|
|
+
|
|
|
+ // 创建一个固定大小的线程池
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(maxThreads);
|
|
|
+
|
|
|
+ // 提交任务到线程池
|
|
|
+ for (int i = 22; i < totalTasks; i++) {
|
|
|
+ final int taskId = i;
|
|
|
+ executorService.submit(() -> {
|
|
|
+ // 任务执行
|
|
|
+ System.out.println("<<<<<<------Executing task: " + taskId + " on thread: " + Thread.currentThread().getName() + "------>>>>>>>>");
|
|
|
+ startMutilExecutor(taskId, fileRootPath + "datas\\yysk_dmdz_address_standardization_200000_" + taskId + ".xlsx",
|
|
|
+ fileRootPath + "output\\yysk_dmdz_address_standardization_200000_result_" + taskId + ".xlsx");
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭线程池
|
|
|
+ executorService.shutdown();
|
|
|
+
|
|
|
+ System.out.println("<<<<<--- 任务完成!!!----->>>>>>>");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public void startMutilExecutor(int startFileIndex, String filePath, String outPath){
|
|
|
System.out.println("<<<<<<<<------searchLoadFileData{fileIndex:" + startFileIndex + "}");
|
|
|
long startTime = System.currentTimeMillis();
|
|
|
List<YyskAddressStandardization> listData = new ArrayList<>();
|
|
|
try {
|
|
|
- List<Map<String, Object>> fileData = ExcelReaderUtils.readExcel(fileRootPath + "datas\\yysk_dmdz_address_standardization_200000_" + startFileIndex + ".xlsx");
|
|
|
+ List<Map<String, Object>> fileData = ExcelReaderUtils.readExcel(filePath);
|
|
|
for (Map<String, Object> item : fileData) {
|
|
|
YyskAddressStandardization yyskAddressStandardization = new YyskAddressStandardization();
|
|
|
yyskAddressStandardization.setAddress(item.get("address").toString());
|
|
@@ -247,27 +276,31 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
// 批量更新处理后的数据
|
|
|
List<YyskAddressStandardization> resultDataList = runExecutorService(listData);
|
|
|
if (resultDataList.size() > 0) {
|
|
|
- ExcelReaderUtils.convertYYListToMapList(resultDataList, fileRootPath + "output\\yysk_dmdz_address_standardization_200000_result_" + startFileIndex + ".xlsx");
|
|
|
+ ExcelReaderUtils.convertYYListToMapList(resultDataList, outPath);
|
|
|
}
|
|
|
long endTime = System.currentTimeMillis();
|
|
|
System.out.println("处理单批次用时" + (endTime - startTime) / 1000 + "秒!");
|
|
|
- if (startFileIndex + sort != endFileIndex) {
|
|
|
- startFileIndex += sort;
|
|
|
- searchLoadFileData(fileRootPath, startFileIndex, endFileIndex, sort);
|
|
|
- } else {
|
|
|
- System.out.println("<<<<<<<<------任务处理完成!");
|
|
|
- }
|
|
|
+// if (startFileIndex + sort != endFileIndex) {
|
|
|
+// startFileIndex += sort;
|
|
|
+// searchLoadFileData(fileRootPath, startFileIndex, endFileIndex, sort);
|
|
|
+// } else {
|
|
|
+// System.out.println("<<<<<<<<------任务处理完成!");
|
|
|
+// }
|
|
|
} else {
|
|
|
- System.out.println("<<<<<<<<------任务处理完成!");
|
|
|
+ System.out.println("<<<<<<<<------ 第" + startFileIndex + "个文件 -----任务处理完成!结果为空。。。--->>>>" + outPath);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public List<YyskAddressStandardization> runExecutorService(List<YyskAddressStandardization> listData) {
|
|
|
// 创建线程池
|
|
|
- ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
|
|
- List<Future<?>> futures = new ArrayList<>();
|
|
|
+// ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
|
|
|
+// List<Future<?>> futures = new ArrayList<>();
|
|
|
+ int index = 1;
|
|
|
+ int total = listData.size();
|
|
|
for (YyskAddressStandardization item : listData) {
|
|
|
- futures.add(executorService.submit(() -> {
|
|
|
+ System.out.println("<<<---- 开始查询第: " + index + " 条数据。。。共:" + total + "条数据--->>>>>>>");
|
|
|
+ index ++;
|
|
|
+// futures.add(executorService.submit(() -> {
|
|
|
List<String> addrList = new ArrayList<>();
|
|
|
String[] addr = AddressMatcher.matchProvinceAndCity(item.getAddress());
|
|
|
if (addr != null && !addr[0].contains("上海")) {
|
|
@@ -289,6 +322,7 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
if (addrList.size() > 0) {
|
|
|
// TODO 开始查询
|
|
|
AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName(addrList);
|
|
|
+ System.out.println("<<<---- 第: " + index + " 条数据返回数据,数据为:!!!" + addressResult.getMessage() + " ----->>>>>");
|
|
|
if (addressResult == null || addressResult.getData() == null || addressResult.getData().size() < 1) {
|
|
|
item.setMatchLevel("异常");
|
|
|
item.setReturnAddress("未匹配到符合规则的结果");
|
|
@@ -335,7 +369,16 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
} else {
|
|
|
item.setResidentialCommittee("");
|
|
|
}
|
|
|
- String oldAddress = Objects.requireNonNull(AddressTools.parseAddressJZ(contentBean.getSearchAddress()))[3].replaceAll(item.getMarket(), "").replaceAll(item.getDistinguish(), "").replaceAll(item.getStreetTown(), "").replaceAll(item.getResidentialCommittee(), "");
|
|
|
+ String oldAddress = "";
|
|
|
+ try{
|
|
|
+ oldAddress = Objects.requireNonNull(AddressTools.parseAddressJZ(contentBean.getSearchAddress()))[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(), "");
|
|
|
+ } catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
item.setStandardAddress(item.getMarket() + item.getDistinguish() + item.getStreetTown() + AddressQueryEngine.townReplace_ct(oldAddress));
|
|
|
break;
|
|
|
} else {
|
|
@@ -351,19 +394,20 @@ public class YyskAddressStandardizationServiceImpl {
|
|
|
}
|
|
|
}
|
|
|
item.setUpdateTime(new Date());
|
|
|
- }));
|
|
|
+// }));
|
|
|
}
|
|
|
|
|
|
// 等待所有任务完成
|
|
|
- for (Future<?> future : futures) {
|
|
|
- try {
|
|
|
- future.get();
|
|
|
- } catch (InterruptedException | ExecutionException e) {
|
|
|
- System.err.println("线程异常:" + e);
|
|
|
- }
|
|
|
- }
|
|
|
- // 关闭线程池
|
|
|
- executorService.shutdown();
|
|
|
+// for (Future<?> future : futures) {
|
|
|
+// try {
|
|
|
+// future.get();
|
|
|
+// } catch (InterruptedException | ExecutionException e) {
|
|
|
+// System.err.println("线程异常:" + e);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// // 关闭线程池
|
|
|
+// executorService.shutdown();
|
|
|
return listData;
|
|
|
}
|
|
|
}
|
|
|
+
|