diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java index 5daceb5..ab38308 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/app/AppController.java @@ -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]); + } + } diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java index 6f28965..e42effc 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/iot/receive/ReceiveController.java @@ -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()); } /** 超出运营区断电*/ diff --git a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java index 5e783ef..55f57be 100644 --- a/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java +++ b/electripper-admin/src/main/java/com/ruoyi/web/controller/system/AsDeviceController.java @@ -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; diff --git a/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java b/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java index 77668d4..b35ca5e 100644 --- a/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java +++ b/electripper-common/src/main/java/com/ruoyi/common/utils/CommonUtil.java @@ -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); diff --git a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java index 48c3627..9f73ba2 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java +++ b/electripper-system/src/main/java/com/ruoyi/system/service/impl/AsDeviceServiceImpl.java @@ -2968,10 +2968,12 @@ public class AsDeviceServiceImpl extends ServiceImpl 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 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)){ diff --git a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java index b712a72..2cb996e 100644 --- a/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java +++ b/electripper-system/src/main/java/com/ruoyi/system/task/EtTask.java @@ -589,16 +589,16 @@ public class EtTask { // 记录开始时间 long startTime = System.nanoTime(); Collection 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 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);