三检历史经纬度定位
This commit is contained in:
@@ -79,6 +79,16 @@ public class HotVehicleThreeInspectBo extends BaseEntity {
|
|||||||
*/
|
*/
|
||||||
private String inspectLocation;
|
private String inspectLocation;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 纬度
|
||||||
|
*/
|
||||||
|
private Double latitude;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 经度
|
||||||
|
*/
|
||||||
|
private Double longitude;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 审核人ID
|
* 审核人ID
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import cn.hutool.core.date.DateUtil;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.hotwj.platform.common.helper.DriverLoginContextHelper;
|
import com.hotwj.platform.common.helper.DriverLoginContextHelper;
|
||||||
import com.hotwj.platform.config.vehicleThreeInspect.domain.HotVehicleThreeInspect;
|
import com.hotwj.platform.config.vehicleThreeInspect.domain.HotVehicleThreeInspect;
|
||||||
@@ -38,9 +39,14 @@ import org.dromara.common.json.utils.JsonUtils;
|
|||||||
import org.dromara.common.mybatis.core.page.PageQuery;
|
import org.dromara.common.mybatis.core.page.PageQuery;
|
||||||
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
import org.dromara.common.mybatis.core.page.TableDataInfo;
|
||||||
import org.dromara.common.satoken.utils.LoginHelper;
|
import org.dromara.common.satoken.utils.LoginHelper;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@@ -70,6 +76,9 @@ public class HotVehicleThreeInspectServiceImpl implements IHotVehicleThreeInspec
|
|||||||
private final SignatureVerifyService signatureVerifyService;
|
private final SignatureVerifyService signatureVerifyService;
|
||||||
private final HotVehicleThreeInspectConfigMapper hotVehicleThreeInspectConfigMapper;
|
private final HotVehicleThreeInspectConfigMapper hotVehicleThreeInspectConfigMapper;
|
||||||
|
|
||||||
|
@Value("${map.gd.key:}")
|
||||||
|
private String gdKey;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询可进行三检的车辆列表(无历史记录或上一轮已完结)
|
* 查询可进行三检的车辆列表(无历史记录或上一轮已完结)
|
||||||
*
|
*
|
||||||
@@ -883,7 +892,9 @@ public class HotVehicleThreeInspectServiceImpl implements IHotVehicleThreeInspec
|
|||||||
if (bo == null) {
|
if (bo == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bo.setInspectLocation(StringUtils.trimToNull(bo.getInspectLocation()));
|
String inspectLocation = StringUtils.trimToNull(bo.getInspectLocation());
|
||||||
|
String reverseAddress = reverseGeocode(bo.getLatitude(), bo.getLongitude());
|
||||||
|
bo.setInspectLocation(StringUtils.defaultIfBlank(reverseAddress, inspectLocation));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareInspectIdentity(HotVehicleThreeInspectBo bo) {
|
private void prepareInspectIdentity(HotVehicleThreeInspectBo bo) {
|
||||||
@@ -965,4 +976,47 @@ public class HotVehicleThreeInspectServiceImpl implements IHotVehicleThreeInspec
|
|||||||
private String randomFourDigits() {
|
private String randomFourDigits() {
|
||||||
return String.format("%04d", ThreadLocalRandom.current().nextInt(1000, 10000));
|
return String.format("%04d", ThreadLocalRandom.current().nextInt(1000, 10000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String reverseGeocode(Double latitude, Double longitude) {
|
||||||
|
if (latitude == null || longitude == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (StringUtils.isBlank(gdKey)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String location = longitude + "," + latitude;
|
||||||
|
String url = "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location="
|
||||||
|
+ location + "&key=" + gdKey + "&radius=1000&extensions=base";
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
try {
|
||||||
|
URL u = new URL(url);
|
||||||
|
connection = (HttpURLConnection) u.openConnection();
|
||||||
|
connection.setConnectTimeout(3000);
|
||||||
|
connection.setReadTimeout(3000);
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
int code = connection.getResponseCode();
|
||||||
|
if (code != HttpURLConnection.HTTP_OK) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try (InputStream is = connection.getInputStream()) {
|
||||||
|
String body = new String(is.readAllBytes(), StandardCharsets.UTF_8);
|
||||||
|
JsonNode root = JsonUtils.getObjectMapper().readTree(body);
|
||||||
|
if (root == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!"1".equals(root.path("status").asText())) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String formatted = root.path("regeocode").path("formatted_address").asText();
|
||||||
|
return StringUtils.trimToNull(formatted);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.warn("车辆三检逆地理解析失败: {},{}", latitude, longitude);
|
||||||
|
return null;
|
||||||
|
} finally {
|
||||||
|
if (connection != null) {
|
||||||
|
connection.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user