|
@@ -8,8 +8,10 @@ import com.skyversation.poiaddr.bean.AddressResult;
|
|
|
import com.skyversation.poiaddr.entity.FileDataDto;
|
|
|
import com.skyversation.poiaddr.entity.PoiAddress;
|
|
|
import com.skyversation.poiaddr.service.PoiAddressService;
|
|
|
+import com.skyversation.poiaddr.util.CsvWriter;
|
|
|
import com.skyversation.poiaddr.util.ExcelReaderUtils;
|
|
|
import com.skyversation.poiaddr.util.RequestUtils;
|
|
|
+import com.skyversation.poiaddr.util.SerializationUtils;
|
|
|
import com.skyversation.poiaddr.util.fileTools.ReadFileData;
|
|
|
import com.skyversation.poiaddr.util.net.AddressNetTools;
|
|
|
import com.skyversation.poiaddr.util.status.AddressLevel;
|
|
@@ -28,6 +30,10 @@ import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
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;
|
|
|
|
|
|
@Slf4j
|
|
|
@Validated
|
|
@@ -97,7 +103,7 @@ public class PoiAddressController {
|
|
|
@RequestParam(name = "latLonSplitStr", required = false) String latLonSplitStr,
|
|
|
@RequestParam(name = "matchingDistance", required = false) Long matchingDistance,
|
|
|
@RequestParam(name = "outCoordinate", required = false) String outCoordinate,
|
|
|
- @RequestParam(name = "matchingLevel", required = false) String matchingLevel,
|
|
|
+ @RequestParam(name = "matchingLevel", required = false) Integer matchingLevel,
|
|
|
@RequestParam(name = "regionalJudgment", required = false) MultipartFile regionalJudgment,
|
|
|
@RequestParam(name = "outFileType", required = false) String outFileType,
|
|
|
@RequestParam(name = "outputFileName", required = false) String outputFileName) throws IOException {
|
|
@@ -123,8 +129,8 @@ public class PoiAddressController {
|
|
|
addr1Key = addrColNames;
|
|
|
}
|
|
|
|
|
|
- if (matchingLevel == null || matchingLevel.isEmpty()) {
|
|
|
- return "请传入搜索等级参数,matchingLevel参数不能为空!";
|
|
|
+ if (matchingLevel == null) {
|
|
|
+ matchingLevel = 1;
|
|
|
}
|
|
|
// 匹配距离参数合法性判断
|
|
|
if (matchingDistance != null) {
|
|
@@ -132,15 +138,15 @@ public class PoiAddressController {
|
|
|
return "当匹配距离参数不为空时,必须传入经纬度参数!";
|
|
|
}
|
|
|
}
|
|
|
- if(outFileType != null){
|
|
|
- if(outFileType.contains("csv")){
|
|
|
+ if (outFileType != null) {
|
|
|
+ if (outFileType.contains("csv")) {
|
|
|
outFileType = "csv";
|
|
|
}
|
|
|
- if(outFileType.contains("xlsx")){
|
|
|
+ if (outFileType.contains("xlsx")) {
|
|
|
outFileType = "xlsx";
|
|
|
}
|
|
|
- }else{
|
|
|
- outFileType = "csv";
|
|
|
+ } else {
|
|
|
+ outFileType = "xlsx";
|
|
|
}
|
|
|
// 经纬度合法性判断
|
|
|
if (latLonColName != null) {
|
|
@@ -160,11 +166,8 @@ public class PoiAddressController {
|
|
|
// 封装解析文件的参数
|
|
|
// TODO 文件数据解析
|
|
|
List<FileDataDto> fileDataDtoList = ReadFileData.ReadMultipartFile(file);
|
|
|
- int index = 0;
|
|
|
// TODO 补充FileDataDto中的搜索条件参数
|
|
|
for (FileDataDto fileDataDto : fileDataDtoList) {
|
|
|
- index++;
|
|
|
- System.out.println("处理进度:" + index + "/" + fileDataDtoList.size());
|
|
|
// 搜索等级
|
|
|
fileDataDto.setMatchingLevel(matchingLevel);
|
|
|
// TODO 数据过滤
|
|
@@ -199,57 +202,75 @@ public class PoiAddressController {
|
|
|
fileDataDto.setLon(Double.valueOf(lonStr));
|
|
|
}
|
|
|
}
|
|
|
-// TODO 地名查询
|
|
|
- if ((fileDataDto.getAddr1() != null || fileDataDto.getAddr2() != null) && (fileDataDto.getProperties().get("户籍街镇") == null || fileDataDto.getProperties().get("户籍街镇").toString().trim().isEmpty() || "".equals(fileDataDto.getProperties().get("户籍街镇").toString()))) {
|
|
|
- System.out.println("开始搜索:" + index + "/" + fileDataDtoList.size());
|
|
|
- AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName(new String[]{fileDataDto.getAddr1().isEmpty() ? fileDataDto.getAddr2() : fileDataDto.getAddr1()}, AddressLevel.values()[1]);
|
|
|
- if (addressResult != null) {
|
|
|
- if (addressResult.getData() == null || addressResult.getData().size() < 1) {
|
|
|
- fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
- fileDataDto.getProperties().put("户籍居委", null);
|
|
|
- fileDataDto.getProperties().put("纬度", null);
|
|
|
- fileDataDto.getProperties().put("经度", null);
|
|
|
- fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
- } else {
|
|
|
- try {
|
|
|
- for (AddressResult.ContentBean contentBean : addressResult.getData()) {
|
|
|
- String resultAddrKey = contentBean.getAddress();
|
|
|
- if (resultAddrKey != null && contentBean.getLon() != null && contentBean.getLat() != null && contentBean.getAdname() != null && contentBean.getCjJson() != null) {
|
|
|
- String lng = contentBean.getLat() + "";
|
|
|
- String lat = contentBean.getLon() + "";
|
|
|
- fileDataDto.getProperties().put("户籍街镇", contentBean.getAdname());
|
|
|
- fileDataDto.getProperties().put("户籍居委", contentBean.getCjJson().getString("所属居委"));
|
|
|
- fileDataDto.getProperties().put("纬度", lng);
|
|
|
- fileDataDto.getProperties().put("经度", lat);
|
|
|
- fileDataDto.getProperties().put("搜索结果地址", resultAddrKey);
|
|
|
- System.out.println("成功:" + lat + "," + lng);
|
|
|
- break;
|
|
|
- } else {
|
|
|
- fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
- fileDataDto.getProperties().put("户籍居委", null);
|
|
|
- fileDataDto.getProperties().put("纬度", null);
|
|
|
- fileDataDto.getProperties().put("经度", null);
|
|
|
- fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
- }
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
+ }
|
|
|
+// TODO 地名查询
|
|
|
+ // 创建线程池
|
|
|
+ int threadCount = Runtime.getRuntime().availableProcessors();
|
|
|
+ ExecutorService executorService = Executors.newFixedThreadPool(threadCount);
|
|
|
+ List<Future<?>> futures = new ArrayList<>();
|
|
|
+ // 为每个元素提交任务
|
|
|
+ for (FileDataDto fileDataDto : fileDataDtoList) {
|
|
|
+ futures.add(executorService.submit(() -> {
|
|
|
+ if (fileDataDto.getAddr1() != null || fileDataDto.getAddr2() != null) {
|
|
|
+ AddressResult addressResult = AddressQueryEngine.getInstance().commonSearchByName(new String[]{fileDataDto.getAddr1().isEmpty() ? fileDataDto.getAddr2() : fileDataDto.getAddr1()}, AddressLevel.values()[fileDataDto.getMatchingLevel() - 1]);
|
|
|
+ if (addressResult != null) {
|
|
|
+ if (addressResult.getData() == null || addressResult.getData().size() < 1) {
|
|
|
fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
fileDataDto.getProperties().put("户籍居委", null);
|
|
|
fileDataDto.getProperties().put("纬度", null);
|
|
|
fileDataDto.getProperties().put("经度", null);
|
|
|
fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
- System.err.println(e);
|
|
|
+ } else {
|
|
|
+ try {
|
|
|
+ for (AddressResult.ContentBean contentBean : addressResult.getData()) {
|
|
|
+ String resultAddrKey = contentBean.getAddress();
|
|
|
+ if (resultAddrKey != null && contentBean.getLon() != null && contentBean.getLat() != null && contentBean.getCjJson() != null) {
|
|
|
+ String lng = contentBean.getLat() + "";
|
|
|
+ String lat = contentBean.getLon() + "";
|
|
|
+ fileDataDto.getProperties().put("所属街道", contentBean.getCjJson().getString("所属街镇"));
|
|
|
+ fileDataDto.getProperties().put("所属居委", contentBean.getCjJson().getString("所属居委"));
|
|
|
+ fileDataDto.getProperties().put("纬度", lng);
|
|
|
+ fileDataDto.getProperties().put("经度", lat);
|
|
|
+ fileDataDto.getProperties().put("搜索结果地址", resultAddrKey);
|
|
|
+ System.out.println("成功:" + lat + "," + lng);
|
|
|
+ break;
|
|
|
+ } else if (resultAddrKey != null && contentBean.getLon() != null && contentBean.getLat() != null) {
|
|
|
+ fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
+ fileDataDto.getProperties().put("户籍居委", null);
|
|
|
+ fileDataDto.getProperties().put("纬度", null);
|
|
|
+ fileDataDto.getProperties().put("经度", null);
|
|
|
+ fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
+ fileDataDto.getProperties().put("户籍居委", null);
|
|
|
+ fileDataDto.getProperties().put("纬度", null);
|
|
|
+ fileDataDto.getProperties().put("经度", null);
|
|
|
+ fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
+ System.err.println(e);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ } else {
|
|
|
+ fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
+ fileDataDto.getProperties().put("户籍居委", null);
|
|
|
+ fileDataDto.getProperties().put("纬度", null);
|
|
|
+ fileDataDto.getProperties().put("经度", null);
|
|
|
+ fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
}
|
|
|
- } else {
|
|
|
- fileDataDto.getProperties().put("户籍街镇", null);
|
|
|
- fileDataDto.getProperties().put("户籍居委", null);
|
|
|
- fileDataDto.getProperties().put("纬度", null);
|
|
|
- fileDataDto.getProperties().put("经度", null);
|
|
|
- fileDataDto.getProperties().put("搜索结果地址", null);
|
|
|
+ }));
|
|
|
+ }
|
|
|
+ // 等待所有任务完成
|
|
|
+ for (Future<?> future : futures) {
|
|
|
+ try {
|
|
|
+ future.get();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+ // 关闭线程池
|
|
|
+ executorService.shutdown();
|
|
|
// TODO 转换坐标(根据输入坐标系将参考坐标统一转换成wgs84)
|
|
|
ArrayList<String> selectOptions = new ArrayList<>();
|
|
|
// {"WGS84(国际通用)", "GCJ02(高德、QQ地图)", "BD09(百度地图)", "上海2000坐标系"}
|
|
@@ -265,7 +286,7 @@ public class PoiAddressController {
|
|
|
inCoordinate = "WGS84";
|
|
|
}
|
|
|
List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
- // TODO 距离计算和区域判断
|
|
|
+ // TODO 距离计算和区域判断和转换坐标
|
|
|
for (FileDataDto fileDataDto : fileDataDtoList) {
|
|
|
if (fileDataDto.getLat() != null && fileDataDto.getLon() != null) {
|
|
|
double[] lonLat = com.skyversation.poiaddr.util.Coordinate.transformationCoordinateByCoordinate(fileDataDto.getLat(), fileDataDto.getLon(), inCoordinate, outCoordinate);
|
|
@@ -291,15 +312,28 @@ public class PoiAddressController {
|
|
|
}
|
|
|
dataList.add(fileDataDto.getProperties());
|
|
|
}
|
|
|
-// TODO 转换坐标
|
|
|
// TODO 结果输出 result[_匹配等级][_匹配距离][_区域名称][_坐标系].[文件类型]
|
|
|
- switch (outFileType){
|
|
|
+// 保存实体类到序列化文件
|
|
|
+ SerializationUtils.serialize(fileDataDtoList, "output/output" + outputFileName + ".ser");
|
|
|
+ /*switch (outFileType) {
|
|
|
case "xlsx":
|
|
|
- ExcelReaderUtils.writeToExcel(dataList, "C:\\Users\\Liumouren\\Desktop\\output" + outputFileName + ".xlsx");
|
|
|
+ ExcelReaderUtils.writeToExcel(dataList, "output/output" + outputFileName + ".xlsx");
|
|
|
+ ReadFileData.outputFile("output/output" + outputFileName + ".xlsx", response);
|
|
|
break;
|
|
|
case "csv":
|
|
|
+ CsvWriter.writeToCsv(dataList, "output/output" + outputFileName + ".csv");
|
|
|
+ ReadFileData.outputFile("output/output" + outputFileName + ".csv", response);
|
|
|
break;
|
|
|
- }
|
|
|
+ case "geojson":
|
|
|
+ break;
|
|
|
+ }*/
|
|
|
+ // 从文件中反序列化读取数据
|
|
|
+ /*List<FileDataDto> deserializedList = SerializationUtils.deserialize("output/output" + outputFileName + ".ser");
|
|
|
+ if (deserializedList != null) {
|
|
|
+ for (FileDataDto person : deserializedList) {
|
|
|
+ System.out.println(person);
|
|
|
+ }
|
|
|
+ }*/
|
|
|
System.out.println("处理完成!");
|
|
|
return "文件解析完成,共" + fileDataDtoList.size() + "条数据!";
|
|
|
} else {
|