20260409:根据经纬度获取详细地址bug修复
This commit is contained in:
parent
676215eca8
commit
c9e0766677
@ -89,6 +89,7 @@ public class DeviceStatusConsumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*更新设备状态*/
|
/*更新设备状态*/
|
||||||
|
device.setProtocolCode(product.getProtocolCode());
|
||||||
deviceCache.updateDeviceStatusCache(statusBo, device);
|
deviceCache.updateDeviceStatusCache(statusBo, device);
|
||||||
//处理影子模式值
|
//处理影子模式值
|
||||||
this.handlerShadow(device, status);
|
this.handlerShadow(device, status);
|
||||||
|
|||||||
@ -135,7 +135,7 @@ public class GaodeLocationService implements ILocationService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(gaodeAK)) {
|
if (StringUtils.isBlank(gaodeAK)) {
|
||||||
log.warn("高德逆地理编码:未配置 map.gaode_key");
|
log.warn("高德逆地理编码:未配置 map.gaode_ak");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
double lng = coordinate.getLongitude().doubleValue();
|
double lng = coordinate.getLongitude().doubleValue();
|
||||||
@ -172,18 +172,60 @@ public class GaodeLocationService implements ILocationService {
|
|||||||
info.setTown(ac.getString("township"));
|
info.setTown(ac.getString("township"));
|
||||||
JSONObject streetNumber = ac.getJSONObject("streetNumber");
|
JSONObject streetNumber = ac.getJSONObject("streetNumber");
|
||||||
if (streetNumber != null) {
|
if (streetNumber != null) {
|
||||||
info.setStreet(streetNumber.getString("street"));
|
info.setStreet(gaodeTextField(streetNumber, "street"));
|
||||||
info.setStreetNumber(streetNumber.getString("number"));
|
info.setStreetNumber(gaodeTextField(streetNumber, "number"));
|
||||||
}
|
}
|
||||||
JSONObject building = ac.getJSONObject("building");
|
JSONObject building = ac.getJSONObject("building");
|
||||||
if (building != null) {
|
if (building != null) {
|
||||||
info.setBuilding(building.getString("name"));
|
info.setBuilding(gaodeTextField(building, "name"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 高德部分字段在数据缺失时为 JSON 数组(含空数组 {@code []}),直接 {@link JSONObject#getString(String)} 会得到字面量 {@code "[]"}。
|
||||||
|
* 本方法仅返回有意义的非空文本,否则返回 {@code null}。
|
||||||
|
*/
|
||||||
|
private static String gaodeTextField(JSONObject obj, String key) {
|
||||||
|
if (obj == null || key == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return gaodeTextValue(obj.get(key));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String gaodeTextValue(Object v) {
|
||||||
|
if (v == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (v instanceof String) {
|
||||||
|
String s = (String) v;
|
||||||
|
return StringUtils.isNotBlank(s) && !"[]".equals(s.trim()) ? s : "";
|
||||||
|
}
|
||||||
|
if (v instanceof JSONArray) {
|
||||||
|
JSONArray arr = (JSONArray) v;
|
||||||
|
if (arr.isEmpty()) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
for (Object el : arr) {
|
||||||
|
if (el instanceof String) {
|
||||||
|
String part = (String) el;
|
||||||
|
if (StringUtils.isNotBlank(part)) {
|
||||||
|
if (sb.length() > 0) {
|
||||||
|
sb.append(',');
|
||||||
|
}
|
||||||
|
sb.append(part);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sb.length() > 0 ? sb.toString() : "";
|
||||||
|
}
|
||||||
|
String s = String.valueOf(v);
|
||||||
|
return StringUtils.isNotBlank(s) && !"[]".equals(s) ? s : "";
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 直辖市等场景下 city 可能为空数组,需回退到省名等。
|
* 直辖市等场景下 city 可能为空数组,需回退到省名等。
|
||||||
*/
|
*/
|
||||||
@ -200,8 +242,7 @@ public class GaodeLocationService implements ILocationService {
|
|||||||
return arr.getString(0);
|
return arr.getString(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String province = ac.getString("province");
|
return gaodeTextField(ac, "province");
|
||||||
return StringUtils.isNotBlank(province) ? province : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1100,7 +1100,7 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
// 随机经纬度和地址
|
// 随机经纬度和地址
|
||||||
//SysUser user = getLoginUser().getUser();
|
//SysUser user = getLoginUser().getUser();
|
||||||
device.setNetworkIp(sysUser.getLoginIp());
|
device.setNetworkIp(sysUser.getLoginIp());
|
||||||
device.setTransport(product.getTransport()); // 便于Modbus设备LBS定位
|
//device.setProtocolCode(product.getProtocolCode()); // 新建时无经纬度
|
||||||
setLocation(sysUser.getLoginIp(), device);
|
setLocation(sysUser.getLoginIp(), device);
|
||||||
deviceMapper.insertDevice(device);
|
deviceMapper.insertDevice(device);
|
||||||
// 处理modbus产品
|
// 处理modbus产品
|
||||||
@ -1639,10 +1639,11 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
ILocationService service = locationServiceFactory.getLocationService();
|
ILocationService service = locationServiceFactory.getLocationService();
|
||||||
|
|
||||||
// Modbus设备采用LBS定位(从设备获取经纬度)
|
// Modbus设备采用LBS定位(从设备获取经纬度)
|
||||||
if (/*Objects.equals(1, device.getLocationWay()) && */FastBeeConstant.PROTOCOL.ModbusRtu.equals(device.getTransport())) {
|
if (/*Objects.equals(1, device.getLocationWay()) && */FastBeeConstant.PROTOCOL.ModbusRtu.equals(device.getProtocolCode())) {
|
||||||
log.info("Modbus设备采用LBS定位{}", device.getSerialNumber());
|
log.info("Modbus设备采用LBS定位{}", device.getSerialNumber());
|
||||||
// 将经纬度转换为地址编码 networkAddress
|
// 将经纬度转换为地址编码 networkAddress
|
||||||
if (StringUtils.isEmpty(device.getNetworkAddress()) && device.getLongitude() != null && device.getLatitude() != null) {
|
if ((StringUtils.isEmpty(device.getNetworkAddress()) || "未知地址".equals(device.getNetworkAddress())) &&
|
||||||
|
device.getLongitude() != null && device.getLatitude() != null) {
|
||||||
Coordinate platformCoordinate = service.convertPlatformCoordinateFromWgs84(new Coordinate(device.getLongitude(), device.getLatitude()));
|
Coordinate platformCoordinate = service.convertPlatformCoordinateFromWgs84(new Coordinate(device.getLongitude(), device.getLatitude()));
|
||||||
AddressInfo addressInfo = service.getAddressByCoordinate(platformCoordinate);
|
AddressInfo addressInfo = service.getAddressByCoordinate(platformCoordinate);
|
||||||
String networkAddress = StringUtils.isEmpty(addressInfo.getBuilding()) ? addressInfo.getFormattedAddress() : addressInfo.getBuilding();
|
String networkAddress = StringUtils.isEmpty(addressInfo.getBuilding()) ? addressInfo.getFormattedAddress() : addressInfo.getBuilding();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user