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

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.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.CommonUtil;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.AsDevice;
import com.ruoyi.system.domain.EtLocationLog;

View File

@ -185,6 +185,9 @@ public class CommonUtil {
public static double[] coordinateConvert(String lon1, String lat1) {
BigDecimal lon = new BigDecimal(lon1);
BigDecimal lat = new BigDecimal(lat1);
if(lon.compareTo(new BigDecimal(1000)) < 0 ){
return GpsCoordinateUtils.calWGS84toGCJ02(lat.doubleValue(), lon.doubleValue());
}
// log.info("WGS84经纬度未计算" + lon + "---" + lat);
// 除以100
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) {
device.setLatitude(lat.toString());
device.setLongitude(lon.toString());
Integer bat = locationVo.getBat();
BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10));
log.info("保存电压:" + divide);
device.setVoltage(divide.toString());//电压
BigDecimal bat = new BigDecimal(locationVo.getBat());
if(bat.compareTo(new BigDecimal(100)) > 0){
bat = bat.divide(new BigDecimal(10));
}
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
// 根据电压计算续航里程
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
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) {
Integer bat = locationVo.getBat();
BigDecimal divide = new BigDecimal(bat).divide(new BigDecimal(10));
log.info("保存电压:" + divide);
device.setVoltage(divide.toString());//电压
BigDecimal bat = new BigDecimal(locationVo.getBat());
if(bat.compareTo(new BigDecimal(100)) > 0){
bat = bat.divide(new BigDecimal(10));
}
log.info("保存电压:{}", bat);
device.setVoltage(bat.toString());//电压
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
// 根据电压计算续航里程
if(ObjectUtil.isNotNull(model)){

View File

@ -589,16 +589,16 @@ public class EtTask {
// 记录开始时间
long startTime = System.nanoTime();
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){
String msg = redisCache.getCacheObject(key);
log.info("redis缓存中的数据" + msg);
// log.info("redis缓存中的数据{}", msg);
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();
AsDevice device = asDeviceMapper.selectAsDeviceByMac(logEntry.getDevName());
if(!isRepeatMsg(msg,logEntry.getDevName())){
log.info("device: sn={},【{}】",device.getSn() , JSON.toJSONString(device));
if(ObjectUtil.isNotNull(device) && !isRepeatMsg(msg,logEntry.getDevName())){
// 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)){
updateLocationHandle(msg, logEntry, value, device);
}
@ -606,7 +606,7 @@ public class EtTask {
}
// 计算执行时间以毫秒为单位
long duration = (System.nanoTime() - startTime) / 1_000_000;
log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------"+duration+ " 毫秒");
// log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------{} 毫秒", duration);
}
private boolean isRepeatMsg(String msg,String mac){
@ -628,46 +628,51 @@ public class EtTask {
// 记录开始时间
long startTime = System.nanoTime();
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){
String msg = redisCache.getCacheObject(key);
log.info("redis缓存中的数据" + msg);
// log.info("redis缓存中的数据{}", msg);
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();
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);
}
}
// 计算执行时间以毫秒为单位
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) {
// 坐标转换 WGS84 GCJ02
double[] doubles = coordinateConvert(value);
BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP);
BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP);
BigDecimal lon = BigDecimal.valueOf(doubles[1]).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);
BigDecimal divide = new BigDecimal(value.getBat()).divide(new BigDecimal(10));
device.setVoltage(divide.toString());//电压
EtModel model = etModelService.selectEtModelByModelId(device.getModelId());
BigDecimal voltage = new BigDecimal(value.getBat());
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());
if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){
remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
}
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString());
}
}
device.setLastTime(DateUtils.getNowDate());
device.setSignalStrength(value.getCsq());
device.setQuality(value.getQ());
if(ObjectUtil.isNotNull(model)){
Integer remainingMileage = 0;
if(StrUtil.isNotBlank(device.getVoltage())){
remainingMileage = CommonUtil.getRemainingMileage(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage(), model.getFullEndurance());
}
Integer electricQuantity = CommonUtil.getElectricQuantity(device.getVoltage(), model.getFullVoltage(), model.getLowVoltage());//电量百分百
device.setRemainingMileage(remainingMileage);
device.setRemainingPower(electricQuantity.toString());
}
if(BigDecimal.ZERO.compareTo(lon) != 0 && BigDecimal.ZERO.compareTo(lat) != 0){
device.setLatitude(lat.toString());
device.setLongitude(lon.toString());
@ -681,7 +686,7 @@ public class EtTask {
}
int i = deviceService.updateLocation(device);
if(i>0){
log.info("===============更新设备信息成功===========>" + logEntry.getDevName());
log.info("===============更新设备信息成功===========>{}", logEntry.getDevName());
}
}
@ -709,6 +714,9 @@ public class EtTask {
private double[] coordinateConvert(LogEntry.LocationValue value) {
BigDecimal lon = new BigDecimal(value.getLon());
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);
// 除以100
lon = lon.divide(new BigDecimal(100), 10, RoundingMode.HALF_UP);