高德地址转换

This commit is contained in:
2025-12-14 18:30:35 +08:00
parent 4d9051d5f9
commit 117d9185f4
9 changed files with 258 additions and 0 deletions
@@ -51,4 +51,5 @@ public interface WatchMonitorDataMapper extends BaseMapper<WatchMonitorData>, MP
List<MonitorDayStats> monitorDayStats(MonitorMonthStatsRequest request);
List<WatchMonitorData> getEmptyAddressList();
}
@@ -206,4 +206,14 @@
</if>
group by data_date order by date;
</select>
<select id="getEmptyAddressList" resultType="com.renkang.watch.entity.WatchMonitorData">
SELECT
*
FROM
watch_monitor_data
WHERE
lon_gd IS NOT NULL
AND lat_gd IS NOT NULL
AND ifnull(address_gd, '') = ''
</select>
</mapper>
@@ -54,4 +54,6 @@ public interface IWatchMonitorDataService extends IService<WatchMonitorData> {
* @return
*/
List<AbnormalEvent> listCustomForMap(AbnormalEventFilter filter);
List<WatchMonitorData> getEmptyAddressList();
}
@@ -36,6 +36,8 @@ import com.renkang.watch.vo.WatchNotifyVo;
import com.renkang.watch.websocket.WebSocket;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.bean.request.ListUser;
import org.jeecg.common.amap.service.AmapService;
import org.jeecg.common.amap.vo.AmapResultVo;
import org.jeecg.common.api.dto.message.BusTemplateMessageDTO;
import org.jeecg.common.export.PoiExportHandler;
import org.jeecg.common.system.api.ISysBaseAPI;
@@ -110,6 +112,8 @@ public class WatchMonitorDataServiceImpl extends ServiceImpl<WatchMonitorDataMap
private final MonitorExport exportInstance = new MonitorExport();
@Autowired
private SpeechUntil speechUntil;
@Autowired
private AmapService amapService;
public static Gps GPS84ToGCJ02(double lon, double lat) {
if (outOfChina(lon, lat)) {
@@ -274,6 +278,14 @@ public class WatchMonitorDataServiceImpl extends ServiceImpl<WatchMonitorDataMap
if (null != gps) {
monitorDataEntity.setLonGd(BigDecimal.valueOf(gps.getLongitude()));
monitorDataEntity.setLatGd(BigDecimal.valueOf(gps.getLatitude()));
//获取高德地址信息
AmapResultVo amapResultVo = amapService.getFormattedAddress(gps.getLongitude(), gps.getLatitude(),5000);
if (amapResultVo.isSuccess()) {
monitorDataEntity.setAddressGd(amapResultVo.getAddress());
monitorDataEntity.setAddress(amapResultVo.getAddress());
}else{
monitorDataEntity.setGpsErrorMsg(monitorDataEntity.getGpsErrorMsg() + "" +amapResultVo.getErrorMsg());
}
}
}
log.info("构建异常数据完成 => {}", JSONObject.toJSONString(monitorDataEntity));
@@ -962,6 +974,7 @@ public class WatchMonitorDataServiceImpl extends ServiceImpl<WatchMonitorDataMap
return new ArrayList<>();
}
public static class Gps {
private String id;
private double longitude;
@@ -1045,4 +1058,10 @@ public class WatchMonitorDataServiceImpl extends ServiceImpl<WatchMonitorDataMap
}
}
@Override
public List<WatchMonitorData> getEmptyAddressList() {
return watchMonitorDataMapper.getEmptyAddressList();
}
}
@@ -0,0 +1,58 @@
package com.renkang.watch.task;
import com.renkang.watch.entity.WatchMonitorData;
import com.renkang.watch.service.IWatchBindHisService;
import com.renkang.watch.service.IWatchDeviceService;
import com.renkang.watch.service.IWatchMonitorDataService;
import com.renkang.watch.util.WatchDataType;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.jeecg.common.amap.service.AmapService;
import org.jeecg.common.amap.vo.AmapResultVo;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.JobParametersInvalidException;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
import org.springframework.batch.core.repository.JobRestartException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
@Slf4j
public class SynWatchGeoJob {
@Autowired
private AmapService amapService;
@Autowired
private IWatchMonitorDataService watchMonitorDataService;
@XxlJob(value = "sync-watchgeo-data")
public ReturnT<String> syncWatchgeoData(){
log.info("开始处理高德逆地理编码");
//先查询地址为空的数据
List<WatchMonitorData> list = watchMonitorDataService.getEmptyAddressList();
if (!CollectionUtils.isEmpty( list)){
for (WatchMonitorData watchMonitorData : list) {
AmapResultVo resultVo = amapService.getFormattedAddress(watchMonitorData.getLonGd().doubleValue(), watchMonitorData.getLatGd().doubleValue());
if (resultVo.isSuccess()) {
watchMonitorData.setAddressGd(resultVo.getAddress());
watchMonitorData.setAddress(resultVo.getAddress());
watchMonitorDataService.updateById(watchMonitorData);
}else{
watchMonitorData.setGpsErrorMsg(resultVo.getErrorMsg());
watchMonitorDataService.updateById(watchMonitorData);
}
}
}
return ReturnT.SUCCESS;
}
}