|
@@ -7,11 +7,14 @@ 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.dms.DmsTools;
|
|
|
import com.skyversation.poiaddr.util.fileTools.ReadFileData;
|
|
|
import com.skyversation.poiaddr.util.geotools.GeoJsonIntersector;
|
|
|
import com.skyversation.poiaddr.util.geotools.GeoJsonPointInRegion;
|
|
|
import com.skyversation.poiaddr.util.status.AddressLevel;
|
|
|
+import com.skyversation.poiaddr.util.zipunit.DataExportUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.json.simple.JSONObject;
|
|
|
import org.locationtech.jts.io.ParseException;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -50,6 +53,20 @@ public class PoiAddressController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * (开发中)
|
|
|
+ * 定时器:每天都增量更新法人库的地名地址数据
|
|
|
+ * 1、获取数据库连接
|
|
|
+ * 2、查询数据
|
|
|
+ * 3、得到地名地址字段和值(清洗数据,并地名格式调整)
|
|
|
+ * 4、批量多任务处理查询结果并判断网格区划
|
|
|
+ * 5、将结果保存为ser文件
|
|
|
+ */
|
|
|
+ public Object updateDataBaseData() {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * (测试中)
|
|
|
* 地名查询任务接口
|
|
|
* * 参数:
|
|
|
* ** 必填:
|
|
@@ -63,17 +80,17 @@ public class PoiAddressController {
|
|
|
* *** outCoordinate: 输出坐标系(默认为wgs84)
|
|
|
* *** matchingLevel: 匹配等级,详情见xmind文件【1、2、3、4、5】
|
|
|
* *** regionalJudgment: 区域判断,geojson、shape文件[前端可以内置一些常用的区域文件,通过下拉框的方式进行选择]
|
|
|
- * *** outFileType: 输出文件类型【xlsx、csv、geojson、shape】
|
|
|
- *
|
|
|
+ * <p>
|
|
|
* JDK版本要规定为11(已完成)
|
|
|
- * 需要使用request获取参数,参数校验不能太严格。
|
|
|
- * 接口调用要使用oauth认证,添加拦截器验证headers里面的token。
|
|
|
- * 任务开始和结束要操作DMS(开始时间-创建时间,结束时间-修改时间,文件名,任务状态,备注)。
|
|
|
- * 注意传入的文件可能数据量过大,可能导致保存xlsx或者csv数据丢失,还要注意字段对应是否正确。
|
|
|
+ * 需要使用request获取参数,参数校验不能太严格。(通过拦截器的方式也实现了参数乱斗并对必传参数的非空判断以及错误提示)
|
|
|
+ * 接口调用要使用oauth认证,添加拦截器验证headers里面的token。(已完成,暂时使用的是121的Oauth系统,用户名:sj_test)
|
|
|
+ * 任务开始和结束要操作DMS(开始时间-创建时间,结束时间-修改时间,文件名,任务状态,备注)。根据token调用接口就可以(待测试)
|
|
|
+ * 注意传入的文件可能数据量过大,可能导致保存xlsx或者csv数据丢失,还要注意字段对应是否正确。(待开发测试)
|
|
|
+ *
|
|
|
* @return Object
|
|
|
*/
|
|
|
@RequestMapping(value = "/nameQueryTaskInterface", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
- public Object GeoCoordinate(HttpServletResponse response, HttpServletRequest request, @RequestParam(name = "file") MultipartFile file,
|
|
|
+ public Object GeoCoordinate(HttpServletResponse response, @RequestHeader(value = "token") String token, @RequestParam(name = "file") MultipartFile file,
|
|
|
@RequestParam(name = "addrColNames") String addrColNames,
|
|
|
@RequestParam(name = "inCoordinate", required = false) String inCoordinate,
|
|
|
@RequestParam(name = "latLonColName", required = false) String latLonColName,
|
|
@@ -82,252 +99,291 @@ public class PoiAddressController {
|
|
|
@RequestParam(name = "outCoordinate", required = false) String outCoordinate,
|
|
|
@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, ParseException {
|
|
|
+ @RequestParam(name = "outputFileName", required = false) String outputFileName) {
|
|
|
// 参数合法性判断
|
|
|
if ((file != null && !file.isEmpty()) && (addrColNames != null && !addrColNames.isEmpty())) {
|
|
|
- outputFileName += UUID.randomUUID();
|
|
|
-// 搜索地址key
|
|
|
- String addr1Key = "";
|
|
|
- String addr2Key = "";
|
|
|
-// 参考经纬度key
|
|
|
- String latKey = "";
|
|
|
- String lonKey = "";
|
|
|
- String latLonKey = "";
|
|
|
- String SplitStr = "";
|
|
|
-// 多地址的形式
|
|
|
- if (addrColNames.contains(",")) {
|
|
|
- String[] addrs = addrColNames.split(",");
|
|
|
- if (addrs.length > 2) {
|
|
|
- return "最多支持两个地址列查询,请检查addrColNames参数!";
|
|
|
- }
|
|
|
- addr1Key = addrs[0];
|
|
|
- addr2Key = addrs[1];
|
|
|
- } else {
|
|
|
- addr1Key = addrColNames;
|
|
|
+// 先更新一下token
|
|
|
+ DmsTools.DmsToken = token;
|
|
|
+ if (outputFileName == null) {
|
|
|
+ outputFileName = "";
|
|
|
}
|
|
|
-
|
|
|
- if (matchingLevel == null) {
|
|
|
- matchingLevel = 1;
|
|
|
- }
|
|
|
-// 匹配距离参数合法性判断
|
|
|
- if (matchingDistance != null) {
|
|
|
- if (latLonColName == null || latLonColName.isEmpty()) {
|
|
|
- return "当匹配距离参数不为空时,必须传入经纬度参数!";
|
|
|
- }
|
|
|
+ outputFileName += UUID.randomUUID();
|
|
|
+ org.json.JSONObject params = new org.json.JSONObject();
|
|
|
+ params.put("columnId", "1542");
|
|
|
+ params.put("modelId", "1445");
|
|
|
+ org.json.JSONObject paramsContent = new org.json.JSONObject();
|
|
|
+ paramsContent.put("title", outputFileName);
|
|
|
+ paramsContent.put("content", new Date().toString());
|
|
|
+ paramsContent.put("c_content", "任务初始化");
|
|
|
+// 0:任务初始化;1:开始处理;2:异常中断;3:任务完成
|
|
|
+ paramsContent.put("c_task_status", 0);
|
|
|
+ params.put("content", paramsContent);
|
|
|
+ JSONObject initDmsData = DmsTools.addContent(params);
|
|
|
+ if (initDmsData.get("message") == null || !"200".equals(initDmsData.get("code"))) {
|
|
|
+ return "任务初始化失败!DMS数据插入异常,请联系管理员!";
|
|
|
}
|
|
|
-// 经纬度合法性判断
|
|
|
- if (latLonColName != null) {
|
|
|
-// 两个key
|
|
|
- if (latLonColName.contains(",")) {
|
|
|
- String[] latLons = latLonColName.split(",");
|
|
|
- latKey = latLons[0];
|
|
|
- lonKey = latLons[1];
|
|
|
- } else if (latLonSplitStr != null && !latLonSplitStr.isEmpty()) {
|
|
|
-// 单个key分割,必须要分割符参数
|
|
|
- latLonKey = latLonColName;
|
|
|
- SplitStr = latLonSplitStr;
|
|
|
+ paramsContent.put("id", initDmsData.get("content"));
|
|
|
+ System.out.println("任务初始化:" + initDmsData.get("message"));
|
|
|
+ try {
|
|
|
+// 搜索地址key
|
|
|
+ String addr1Key = "";
|
|
|
+ String addr2Key = "";
|
|
|
+// 参考经纬度key
|
|
|
+ String latKey = "";
|
|
|
+ String lonKey = "";
|
|
|
+ String latLonKey = "";
|
|
|
+ String SplitStr = "";
|
|
|
+ paramsContent.put("c_task_status", 1);
|
|
|
+ paramsContent.put("c_content", "开始处理");
|
|
|
+ params.put("content", paramsContent);
|
|
|
+ DmsTools.updateContent(params);
|
|
|
+// 多地址的形式
|
|
|
+ if (addrColNames.contains(",")) {
|
|
|
+ String[] addrs = addrColNames.split(",");
|
|
|
+ if (addrs.length > 2) {
|
|
|
+ return "最多支持两个地址列查询,请检查addrColNames参数!";
|
|
|
+ }
|
|
|
+ addr1Key = addrs[0];
|
|
|
+ addr2Key = addrs[1];
|
|
|
} else {
|
|
|
- return "经纬度列名解析失败,请传入经度和纬度的列名以逗号分割或传入经纬度列名和分隔符参数!";
|
|
|
+ addr1Key = addrColNames;
|
|
|
}
|
|
|
- }
|
|
|
-// 封装解析文件的参数
|
|
|
-// TODO 文件数据解析
|
|
|
- List<FileDataDto> fileDataDtoList = ReadFileData.ReadMultipartFile(file);
|
|
|
- List<FileDataDto> regionalDataList = new ArrayList<>();
|
|
|
- if (regionalJudgment != null && !regionalJudgment.isEmpty()) {
|
|
|
-// 解析geojson文件得到区域
|
|
|
- regionalDataList = ReadFileData.ReadMultipartFile(regionalJudgment);
|
|
|
- }
|
|
|
-// TODO 补充FileDataDto中的搜索条件参数
|
|
|
- for (FileDataDto fileDataDto : fileDataDtoList) {
|
|
|
-// 搜索等级
|
|
|
- fileDataDto.setMatchingLevel(matchingLevel);
|
|
|
-// TODO 数据过滤
|
|
|
-// set地名地址搜索字段
|
|
|
- Map<String, Object> properties = fileDataDto.getProperties();
|
|
|
- try {
|
|
|
- if (properties != null && properties.get(addr1Key) != null && addr1Key != null && properties.get(addr1Key).toString().length() > 2 && ExcelReaderUtils.isOtherDistrictThanQingpu(properties.get(addr1Key).toString())) {
|
|
|
- String address = "上海市青浦区" + AddressQueryEngine.addressReplaceAll(properties.getOrDefault(addr1Key, "").toString());
|
|
|
- fileDataDto.setAddr1(address);
|
|
|
+
|
|
|
+ if (matchingLevel == null) {
|
|
|
+ matchingLevel = 1;
|
|
|
+ }
|
|
|
+// 匹配距离参数合法性判断
|
|
|
+ if (matchingDistance != null) {
|
|
|
+ if (latLonColName == null || latLonColName.isEmpty()) {
|
|
|
+ return "当匹配距离参数不为空时,必须传入经纬度参数!";
|
|
|
}
|
|
|
- if (properties != null && properties.get(addr1Key) != null && addr2Key != null && properties.get(addr2Key).toString().length() > 2 && ExcelReaderUtils.isOtherDistrictThanQingpu(properties.get(addr2Key).toString())) {
|
|
|
- String address = "上海市青浦区" + AddressQueryEngine.addressReplaceAll(properties.getOrDefault(addr2Key, "").toString());
|
|
|
- fileDataDto.setAddr2(address);
|
|
|
+ }
|
|
|
+// 经纬度合法性判断
|
|
|
+ if (latLonColName != null) {
|
|
|
+// 两个key
|
|
|
+ if (latLonColName.contains(",")) {
|
|
|
+ String[] latLons = latLonColName.split(",");
|
|
|
+ latKey = latLons[0];
|
|
|
+ lonKey = latLons[1];
|
|
|
+ } else if (latLonSplitStr != null && !latLonSplitStr.isEmpty()) {
|
|
|
+// 单个key分割,必须要分割符参数
|
|
|
+ latLonKey = latLonColName;
|
|
|
+ SplitStr = latLonSplitStr;
|
|
|
+ } else {
|
|
|
+ return "经纬度列名解析失败,请传入经度和纬度的列名以逗号分割或传入经纬度列名和分隔符参数!";
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- System.err.println(e);
|
|
|
}
|
|
|
-// 判断是否有参考经纬度字段
|
|
|
- if (properties != null && latKey != null && !latKey.isEmpty() && lonKey != null && !lonKey.isEmpty() && properties.get(latKey) != null && properties.get(lonKey) != null) {
|
|
|
- String latStr = properties.get(latKey).toString();
|
|
|
- String lonStr = properties.get(lonKey).toString();
|
|
|
- fileDataDto.setLat(Double.valueOf(latStr));
|
|
|
- fileDataDto.setLon(Double.valueOf(lonStr));
|
|
|
- } else if (!latLonKey.isEmpty()) {
|
|
|
- String[] latLonKeys = latLonKey.split(SplitStr);
|
|
|
- if (properties != null && properties.get(latLonKeys[0]) != null && properties.get(latLonKeys[1]) != null) {
|
|
|
- String latStr = properties.get(latLonKeys[0]).toString();
|
|
|
- String lonStr = properties.get(latLonKeys[1]).toString();
|
|
|
+// 封装解析文件的参数
|
|
|
+// TODO 文件数据解析
|
|
|
+ List<FileDataDto> fileDataDtoList = ReadFileData.ReadMultipartFile(file);
|
|
|
+ List<FileDataDto> regionalDataList = new ArrayList<>();
|
|
|
+ if (regionalJudgment != null && !regionalJudgment.isEmpty()) {
|
|
|
+// 解析geojson文件得到区域
|
|
|
+ regionalDataList = ReadFileData.ReadMultipartFile(regionalJudgment);
|
|
|
+ }
|
|
|
+// TODO 补充FileDataDto中的搜索条件参数
|
|
|
+ for (FileDataDto fileDataDto : fileDataDtoList) {
|
|
|
+// 搜索等级
|
|
|
+ fileDataDto.setMatchingLevel(matchingLevel);
|
|
|
+// TODO 数据过滤
|
|
|
+// set地名地址搜索字段
|
|
|
+ Map<String, Object> properties = fileDataDto.getProperties();
|
|
|
+ try {
|
|
|
+ if (properties != null && addr1Key != null && properties.get(addr1Key) != null && properties.get(addr1Key).toString().length() > 2 && ExcelReaderUtils.isOtherDistrictThanQingpu(properties.get(addr1Key).toString())) {
|
|
|
+ String address = "上海市青浦区" + AddressQueryEngine.addressReplaceAll(properties.getOrDefault(addr1Key, "").toString());
|
|
|
+ fileDataDto.setAddr1(address);
|
|
|
+ }
|
|
|
+ if (properties != null && addr2Key != null && properties.get(addr2Key) != null && properties.get(addr2Key).toString().length() > 2 && ExcelReaderUtils.isOtherDistrictThanQingpu(properties.get(addr2Key).toString())) {
|
|
|
+ String address = "上海市青浦区" + AddressQueryEngine.addressReplaceAll(properties.getOrDefault(addr2Key, "").toString());
|
|
|
+ fileDataDto.setAddr2(address);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println(e);
|
|
|
+ }
|
|
|
+// 判断是否有参考经纬度字段
|
|
|
+ if (properties != null && latKey != null && !latKey.isEmpty() && lonKey != null && !lonKey.isEmpty() && properties.get(latKey) != null && properties.get(lonKey) != null) {
|
|
|
+ String latStr = properties.get(latKey).toString();
|
|
|
+ String lonStr = properties.get(lonKey).toString();
|
|
|
fileDataDto.setLat(Double.valueOf(latStr));
|
|
|
fileDataDto.setLon(Double.valueOf(lonStr));
|
|
|
+ } else if (!latLonKey.isEmpty()) {
|
|
|
+ String[] latLonKeys = latLonKey.split(SplitStr);
|
|
|
+ if (properties != null && properties.get(latLonKeys[0]) != null && properties.get(latLonKeys[1]) != null) {
|
|
|
+ String latStr = properties.get(latLonKeys[0]).toString();
|
|
|
+ String lonStr = properties.get(latLonKeys[1]).toString();
|
|
|
+ fileDataDto.setLat(Double.valueOf(latStr));
|
|
|
+ fileDataDto.setLon(Double.valueOf(lonStr));
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-// 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);
|
|
|
- } 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) {
|
|
|
+// 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坐标系"}
|
|
|
- selectOptions.add("WGS84");
|
|
|
- selectOptions.add("GCJ02");
|
|
|
- selectOptions.add("BD09");
|
|
|
- selectOptions.add("SH2000");
|
|
|
- if (inCoordinate != null && !inCoordinate.isEmpty()) {
|
|
|
- if (!selectOptions.contains(inCoordinate)) {
|
|
|
- return "请传入正确的坐标系名称!可选坐标系名称:WGS84,GCJ02,BD09,SH2000";
|
|
|
+ // 等待所有任务完成
|
|
|
+ for (Future<?> future : futures) {
|
|
|
+ try {
|
|
|
+ future.get();
|
|
|
+ } catch (InterruptedException | ExecutionException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
}
|
|
|
- } else {
|
|
|
- inCoordinate = "WGS84";
|
|
|
- }
|
|
|
- List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
-// 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);
|
|
|
- fileDataDto.setLat(lonLat[1]);
|
|
|
- fileDataDto.setLon(lonLat[0]);
|
|
|
+ // 关闭线程池
|
|
|
+ executorService.shutdown();
|
|
|
+// TODO 转换坐标(根据输入坐标系将参考坐标统一转换成wgs84)
|
|
|
+ ArrayList<String> selectOptions = new ArrayList<>();
|
|
|
+// {"WGS84(国际通用)", "GCJ02(高德、QQ地图)", "BD09(百度地图)", "上海2000坐标系"}
|
|
|
+ selectOptions.add("WGS84");
|
|
|
+ selectOptions.add("GCJ02");
|
|
|
+ selectOptions.add("BD09");
|
|
|
+ selectOptions.add("SH2000");
|
|
|
+ if (inCoordinate != null && !inCoordinate.isEmpty()) {
|
|
|
+ if (!selectOptions.contains(inCoordinate)) {
|
|
|
+ return "请传入正确的坐标系名称!可选坐标系名称:WGS84,GCJ02,BD09,SH2000";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ inCoordinate = "WGS84";
|
|
|
}
|
|
|
-// TODO 距离计算
|
|
|
- if (matchingDistance != null) {
|
|
|
- if (fileDataDto.getResultLat() != null && fileDataDto.getResultLon() != null && fileDataDto.getLat() != null && fileDataDto.getLon() != null) {
|
|
|
- double distance = com.skyversation.poiaddr.util.Coordinate.calculateDistance(fileDataDto.getResultLat(), fileDataDto.getResultLon(), fileDataDto.getLat(), fileDataDto.getLon());
|
|
|
- fileDataDto.setMatchingDistance(distance);
|
|
|
- double matchingDistanceDb = Double.parseDouble(matchingDistance.toString());
|
|
|
- if (distance < matchingDistanceDb) {
|
|
|
- fileDataDto.setLtMatchingDistance("是");
|
|
|
- } else {
|
|
|
- fileDataDto.setLtMatchingDistance("否");
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+// 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);
|
|
|
+ fileDataDto.setLat(lonLat[1]);
|
|
|
+ fileDataDto.setLon(lonLat[0]);
|
|
|
+ }
|
|
|
+// TODO 距离计算
|
|
|
+ if (matchingDistance != null) {
|
|
|
+ if (fileDataDto.getResultLat() != null && fileDataDto.getResultLon() != null && fileDataDto.getLat() != null && fileDataDto.getLon() != null) {
|
|
|
+ double distance = com.skyversation.poiaddr.util.Coordinate.calculateDistance(fileDataDto.getResultLat(), fileDataDto.getResultLon(), fileDataDto.getLat(), fileDataDto.getLon());
|
|
|
+ fileDataDto.setMatchingDistance(distance);
|
|
|
+ double matchingDistanceDb = Double.parseDouble(matchingDistance.toString());
|
|
|
+ if (distance < matchingDistanceDb) {
|
|
|
+ fileDataDto.setLtMatchingDistance("是");
|
|
|
+ } else {
|
|
|
+ fileDataDto.setLtMatchingDistance("否");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-// TODO 区域判断(得到经纬度后,要判断得到的点是否在传入的geojson面内)
|
|
|
- if (regionalDataList != null && regionalDataList.size() > 0) {
|
|
|
+// TODO 区域判断(得到经纬度后,要判断得到的点是否在传入的geojson面内)
|
|
|
+ if (regionalDataList != null && regionalDataList.size() > 0) {
|
|
|
// 解析geojson文件得到区域
|
|
|
- boolean isArea= false;
|
|
|
- for(FileDataDto regionlItem: regionalDataList){
|
|
|
- if(GeoJsonPointInRegion.isPointInGeoJsonRegion(regionlItem.getGeometry().toString(),fileDataDto.getLat(),fileDataDto.getLon())){
|
|
|
- isArea = true;
|
|
|
- break;
|
|
|
- };
|
|
|
+ boolean isArea = false;
|
|
|
+ for (FileDataDto regionlItem : regionalDataList) {
|
|
|
+ if (GeoJsonPointInRegion.isPointInGeoJsonRegion(regionlItem.getGeometry().toString(), fileDataDto.getLat(), fileDataDto.getLon())) {
|
|
|
+ isArea = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ fileDataDto.getProperties().put("是否在区域内", isArea ? "是" : "否");
|
|
|
}
|
|
|
- fileDataDto.getProperties().put("是否在区域内",isArea ? "是" : "否");
|
|
|
+ dataList.add(fileDataDto.getProperties());
|
|
|
}
|
|
|
- dataList.add(fileDataDto.getProperties());
|
|
|
- }
|
|
|
-// TODO 结果输出 result[_匹配等级][_匹配距离][_区域名称][_坐标系].[文件类型]
|
|
|
- if (outFileType != null) {
|
|
|
- if (outFileType.contains("csv")) {
|
|
|
- outFileType = "csv";
|
|
|
- }
|
|
|
- if (outFileType.contains("xlsx")) {
|
|
|
- outFileType = "xlsx";
|
|
|
- }
|
|
|
-
|
|
|
- switch (outFileType) {
|
|
|
- case "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;
|
|
|
- }
|
|
|
- } else {
|
|
|
+// TODO 结果输出 result[_匹配等级][_匹配距离][_区域名称][_坐标系].[文件类型]
|
|
|
// 保存实体类到序列化文件
|
|
|
SerializationUtils.serialize(fileDataDtoList, "output/output" + outputFileName + ".ser");
|
|
|
+ System.out.println("处理完成!");
|
|
|
+ paramsContent.put("c_task_status", 3);
|
|
|
+ paramsContent.put("c_content", "处理完成!");
|
|
|
+ paramsContent.put("c_file_name", "output/output" + outputFileName + ".ser");
|
|
|
+ params.put("content", paramsContent);
|
|
|
+ DmsTools.updateContent(params);
|
|
|
+ return "文件解析完成,共" + fileDataDtoList.size() + "条数据!";
|
|
|
+ } catch (Exception e) {
|
|
|
+ paramsContent.put("c_task_status", 2);
|
|
|
+ paramsContent.put("c_content", "异常中断:" + e);
|
|
|
+ params.put("content", paramsContent);
|
|
|
+ DmsTools.updateContent(params);
|
|
|
+ return "异常中断:" + e;
|
|
|
}
|
|
|
- // 从文件中反序列化读取数据
|
|
|
- /*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 {
|
|
|
return "file或addrColName不能为空!";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * (开发中)
|
|
|
+ * 根据文件名和文件类型,下载对应文件类型的数据文件
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param outFileType: 输出文件类型【xlsx、csv、geojson(暂不支持)、shape(暂不支持)】
|
|
|
+ * @param fileName
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getFileByParams", produces = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
+ public void getFileByParams(HttpServletResponse response, @RequestParam(name = "outFileType", required = false) String outFileType, @RequestParam(name = "fileName", required = false) String fileName) throws IOException {
|
|
|
+ // 从文件中反序列化读取数据
|
|
|
+ List<FileDataDto> deserializedList = SerializationUtils.deserialize(fileName);
|
|
|
+ List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ if (deserializedList != null) {
|
|
|
+ for (FileDataDto person : deserializedList) {
|
|
|
+ dataList.add(person.getProperties());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (outFileType != null) {
|
|
|
+ if (outFileType.contains("csv")) {
|
|
|
+ outFileType = "csv";
|
|
|
+ }
|
|
|
+ if (outFileType.contains("xlsx")) {
|
|
|
+ outFileType = "xlsx";
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ outFileType = "csv";
|
|
|
+ }
|
|
|
+ DataExportUtil.exportDataToZip(dataList, fileName.replace(".ser", ""), response, outFileType);
|
|
|
+ }
|
|
|
}
|