This commit is contained in:
邱贞招 2024-12-13 17:07:36 +08:00
parent 33b7e15b09
commit 45e8c906f3
6 changed files with 69 additions and 40 deletions

View File

@ -808,4 +808,15 @@ public class AppController extends BaseController
return success(orders); return success(orders);
} }
/**
* 坐标转换
*/
@GetMapping("/coordinateTransformation/{lon}/{lat}")
public AjaxResult coordinateTransformation(@PathVariable("lon") String lon, @PathVariable("lat") String lat)
{
logger.info("【坐标转换】经纬度:{}---{}", lon, lat);
double[] doubles = CommonUtil.coordinateConvert(lon, lat);
return success(doubles[1]+","+doubles[0]);
}
} }

View File

@ -167,13 +167,13 @@ public class ReceiveController {
if(ObjectUtil.isNotNull(asDevice)){ if(ObjectUtil.isNotNull(asDevice)){
// 将msg的定位信息保存到redis中 // 将msg的定位信息保存到redis中
redisCache.setCacheObject(CacheConstants.CACHE_DEVICE_KEY+asDevice.getMac(),msg); redisCache.setCacheObject(CacheConstants.CACHE_DEVICE_KEY+asDevice.getMac(),msg);
log.info("reids更新定位成功==========================>" +asDevice.getSn()); log.info("reids更新定位成功==========================>{}", asDevice.getSn());
// 坐标转换 WGS84 GCJ02 // 坐标转换 WGS84 GCJ02
double[] doubles = coordinateConvert(value); double[] doubles = coordinateConvert(value);
BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP); BigDecimal lat = BigDecimal.valueOf(doubles[0]).setScale(8, RoundingMode.HALF_UP);
BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP); BigDecimal lon = BigDecimal.valueOf(doubles[1]).setScale(8, RoundingMode.HALF_UP);
log.info("转换后的GCJ02经纬度" + lon + "---" + lat); log.info("转换后的GCJ02经纬度{}---{}", lon, lat);
EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(asDevice.getAreaId()); EtOperatingArea area = etOperatingAreaService.selectEtOperatingAreaByAreaId(asDevice.getAreaId());
// 相差一分钟以上的消息不做处理 // 相差一分钟以上的消息不做处理
@ -292,6 +292,9 @@ public class ReceiveController {
private double[] coordinateConvert(LogEntry.LocationValue value) { private double[] coordinateConvert(LogEntry.LocationValue value) {
BigDecimal lon = new BigDecimal(value.getLon()); BigDecimal lon = new BigDecimal(value.getLon());
BigDecimal lat = new BigDecimal(value.getLat()); BigDecimal lat = new BigDecimal(value.getLat());
if(lon.compareTo(new BigDecimal(1000)) < 0 ){
return GpsCoordinateUtils.calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
}
// log.info("WGS84经纬度未计算" + lon + "---" + lat); // log.info("WGS84经纬度未计算" + lon + "---" + lat);
// 除以100 // 除以100
lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP); lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);
@ -312,8 +315,7 @@ public class ReceiveController {
lo = lo.setScale(8, RoundingMode.HALF_UP); lo = lo.setScale(8, RoundingMode.HALF_UP);
la = la.setScale(8, RoundingMode.HALF_UP); la = la.setScale(8, RoundingMode.HALF_UP);
// log.info("WGS84经纬度保留8为小数" + lo + "---" + la); // log.info("WGS84经纬度保留8为小数" + lo + "---" + la);
double[] doubles = GpsCoordinateUtils.calWGS84toGCJ02(la.doubleValue(), lo.doubleValue()); return GpsCoordinateUtils.calWGS84toGCJ02(la.doubleValue(), lo.doubleValue());
return doubles;
} }
/** 超出运营区断电*/ /** 超出运营区断电*/

View File

@ -7,6 +7,7 @@ import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType; import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AsDevice; import com.ruoyi.system.domain.AsDevice;
import com.ruoyi.system.domain.EtLocationLog; import com.ruoyi.system.domain.EtLocationLog;

View File

@ -185,6 +185,9 @@ public class CommonUtil {
public static double[] coordinateConvert(String lon1, String lat1) { public static double[] coordinateConvert(String lon1, String lat1) {
BigDecimal lon = new BigDecimal(lon1); BigDecimal lon = new BigDecimal(lon1);
BigDecimal lat = new BigDecimal(lat1); BigDecimal lat = new BigDecimal(lat1);
if(lon.compareTo(new BigDecimal(1000)) < 0 ){
return GpsCoordinateUtils.calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
}
// log.info("WGS84经纬度未计算" + lon + "---" + lat); // log.info("WGS84经纬度未计算" + lon + "---" + lat);
// 除以100 // 除以100
lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP); lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);

View File

@ -2968,10 +2968,12 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
public int updateDevice(String at,LocationVo locationVo, AsDevice device, BigDecimal lon, BigDecimal lat) { public int updateDevice(String at,LocationVo locationVo, AsDevice device, BigDecimal lon, BigDecimal lat) {
device.setLatitude(lat.toString()); device.setLatitude(lat.toString());
device.setLongitude(lon.toString()); device.setLongitude(lon.toString());
Integer bat = locationVo.getBat(); BigDecimal bat = new BigDecimal(locationVo.getBat());
BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10)); if(bat.compareTo(new BigDecimal(100)) > 0){
log.info("保存电压:" + divide); bat = bat.divide(new BigDecimal(10));
device.setVoltage(divide.toString());//电压 }
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
// 根据电压计算续航里程 // 根据电压计算续航里程
EtModel model = etModelService.selectEtModelByModelId(device.getModelId()); EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
if(ObjectUtil.isNotNull(model)){ if(ObjectUtil.isNotNull(model)){
@ -2996,10 +2998,12 @@ public class AsDeviceServiceImpl extends ServiceImpl<AsDeviceMapper, AsDevice> i
/** 无定位更新设备 */ /** 无定位更新设备 */
private void noLocationUpdateDevice(String at,LocationVo locationVo, AsDevice device) { private void noLocationUpdateDevice(String at,LocationVo locationVo, AsDevice device) {
Integer bat = locationVo.getBat(); BigDecimal bat = new BigDecimal(locationVo.getBat());
BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10)); if(bat.compareTo(new BigDecimal(100)) > 0){
log.info("保存电压:" + divide); bat = bat.divide(new BigDecimal(10));
device.setVoltage(divide.toString());//电压 }
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
EtModel model = etModelService.selectEtModelByModelId(device.getModelId()); EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
// 根据电压计算续航里程 // 根据电压计算续航里程
if(ObjectUtil.isNotNull(model)){ if(ObjectUtil.isNotNull(model)){

View File

@ -589,16 +589,16 @@ public class EtTask {
// 记录开始时间 // 记录开始时间
long startTime = System.nanoTime(); long startTime = System.nanoTime();
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*"); Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
log.info("redis缓存中的数据" + JSON.toJSONString(keys)); // log.info("redis缓存中的数据" + JSON.toJSONString(keys));
for(String key:keys){ for(String key:keys){
String msg = redisCache.getCacheObject(key); String msg = redisCache.getCacheObject(key);
log.info("redis缓存中的数据" + msg); // log.info("redis缓存中的数据{}", msg);
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class); LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry)); // log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry));
LogEntry.LocationValue value = logEntry.getValue(); LogEntry.LocationValue value = logEntry.getValue();
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName()); AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
if(!isRepeatMsg(msg,logEntry.getDevName())){ if(ObjectUtil.isNotNull(device) && !isRepeatMsg(msg,logEntry.getDevName())){
log.info("device: sn={},【{}】",device.getSn() , JSON.toJSONString(device)); // log.info("device: sn={},【{}】",device.getSn() , JSON.toJSONString(device));
if(ServiceConstants.LOCK_STATUS_OPEN.equals(device.getLockStatus()) && device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_USING)){ if(ServiceConstants.LOCK_STATUS_OPEN.equals(device.getLockStatus()) && device.getStatus().equals(ServiceConstants.VEHICLE_STATUS_IN_USING)){
updateLocationHandle(msg, logEntry, value, device); updateLocationHandle(msg, logEntry, value, device);
} }
@ -606,7 +606,7 @@ public class EtTask {
} }
// 计算执行时间以毫秒为单位 // 计算执行时间以毫秒为单位
long duration = (System.nanoTime() - startTime) / 1_000_000; long duration = (System.nanoTime() - startTime) / 1_000_000;
log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------"+duration+ " 毫秒"); // log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
} }
private boolean isRepeatMsg(String msg,String mac){ private boolean isRepeatMsg(String msg,String mac){
@ -628,37 +628,38 @@ public class EtTask {
// 记录开始时间 // 记录开始时间
long startTime = System.nanoTime(); long startTime = System.nanoTime();
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*"); Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
log.info("redis缓存中的数据" + JSON.toJSONString(keys)); // log.info("redis缓存中的数据{}", JSON.toJSONString(keys));
for(String key:keys){ for(String key:keys){
String msg = redisCache.getCacheObject(key); String msg = redisCache.getCacheObject(key);
log.info("redis缓存中的数据" + msg); // log.info("redis缓存中的数据{}", msg);
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class); LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry)); // log.info("logEntry转换后的对象: logEntry---【{}】" , JSON.toJSONString(logEntry));
LogEntry.LocationValue value = logEntry.getValue(); LogEntry.LocationValue value = logEntry.getValue();
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName()); AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
if(ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())){ if(ObjectUtil.isNotNull(device) && ServiceConstants.LOCK_STATUS_CLOSE.equals(device.getLockStatus())){
updateLocationHandle(msg, logEntry, value, device); updateLocationHandle(msg, logEntry, value, device);
} }
} }
// 计算执行时间以毫秒为单位 // 计算执行时间以毫秒为单位
long duration = (System.nanoTime() - startTime) / 1_000_000; long duration = (System.nanoTime() - startTime) / 1_000_000;
log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压----结束---------------"+duration+ " 毫秒"); // log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
} }
private void updateLocationHandle(String msg, LogEntry logEntry, LogEntry.LocationValue value, AsDevice device) { private void updateLocationHandle(String msg, LogEntry logEntry, LogEntry.LocationValue value, AsDevice device) {
// 坐标转换 WGS84 GCJ02 // 坐标转换 WGS84 GCJ02
double[] doubles = coordinateConvert(value); double[] doubles = coordinateConvert(value);
BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP); BigDecimal lon = BigDecimal.valueOf(doubles[1]).setScale(8, RoundingMode.HALF_UP);
BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP); BigDecimal lat = BigDecimal.valueOf(doubles[0]).setScale(8, RoundingMode.HALF_UP);
asynchronousSaveLog(msg, logEntry.getAt(), logEntry.getDevName(), lon, lat, device); asynchronousSaveLog(msg, logEntry.getAt(), logEntry.getDevName(), lon, lat, device);
BigDecimal divide = new BigDecimal(value.getBat()).divide(new BigDecimal(10)); BigDecimal voltage = new BigDecimal(value.getBat());
device.setVoltage(divide.toString());//电压 if(voltage.compareTo(new BigDecimal(100)) > 0){
voltage = voltage.divide(new BigDecimal(10));
}
device.setVoltage(voltage.toString());//电压
if(ObjectUtil.isNotNull(device.getModelId())){
EtModel model = etModelService.selectEtModelByModelId(device.getModelId()); EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
device.setLastTime(DateUtils.getNowDate());
device.setSignalStrength(value.getCsq());
device.setQuality(value.getQ());
if(ObjectUtil.isNotNull(model)){ if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0; Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){ if(StrUtil.isNotBlank(device.getVoltage())){
@ -668,6 +669,10 @@ public class EtTask {
device.setRemainingMileage(remainingMileage); device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString()); device.setRemainingPower(electricQuantity.toString());
} }
}
device.setLastTime(DateUtils.getNowDate());
device.setSignalStrength(value.getCsq());
device.setQuality(value.getQ());
if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){ if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){
device.setLatitude(lat.toString()); device.setLatitude(lat.toString());
device.setLongitude(lon.toString()); device.setLongitude(lon.toString());
@ -681,7 +686,7 @@ public class EtTask {
} }
int i = deviceService.updateLocation(device); int i = deviceService.updateLocation(device);
if(i>0){ if(i>0){
log.info("===============更新设备信息成功===========>" + logEntry.getDevName()); log.info("===============更新设备信息成功===========>{}", logEntry.getDevName());
} }
} }
@ -709,6 +714,9 @@ public class EtTask {
private double[] coordinateConvert(LogEntry.LocationValue value) { private double[] coordinateConvert(LogEntry.LocationValue value) {
BigDecimal lon = new BigDecimal(value.getLon()); BigDecimal lon = new BigDecimal(value.getLon());
BigDecimal lat = new BigDecimal(value.getLat()); BigDecimal lat = new BigDecimal(value.getLat());
if(lon.compareTo(new BigDecimal(1000)) < 0 ){
return GpsCoordinateUtils.calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
}
// log.info("WGS84经纬度未计算" + lon + "---" + lat); // log.info("WGS84经纬度未计算" + lon + "---" + lat);
// 除以100 // 除以100
lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP); lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);