1. 心跳的逻辑移到redis中
This commit is contained in:
parent
d2bc7617a6
commit
05af4cecba
|
@ -16,6 +16,7 @@ import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.common.utils.map.GeoUtils;
|
import com.ruoyi.common.utils.map.GeoUtils;
|
||||||
import com.ruoyi.common.utils.map.GpsCoordinateUtils;
|
import com.ruoyi.common.utils.map.GpsCoordinateUtils;
|
||||||
import com.ruoyi.common.utils.onenet.LogEntry;
|
import com.ruoyi.common.utils.onenet.LogEntry;
|
||||||
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
||||||
import com.ruoyi.common.utils.uuid.IdUtils;
|
import com.ruoyi.common.utils.uuid.IdUtils;
|
||||||
import com.ruoyi.system.domain.*;
|
import com.ruoyi.system.domain.*;
|
||||||
import com.ruoyi.system.mapper.*;
|
import com.ruoyi.system.mapper.*;
|
||||||
|
@ -33,10 +34,7 @@ import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Comparator;
|
import java.util.*;
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
@ -502,24 +500,56 @@ public class EtTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新设备的定位和电压 5秒一次
|
* 更新设备的定位和电压 10秒一次
|
||||||
* cron: 0 5 0 * * ?
|
* cron: 0 10 0 * * ?
|
||||||
*/
|
*/
|
||||||
public void updateLocation(){
|
public void updateLocation10(){
|
||||||
log.info("-------------------【定时任务】更新设备的定位和电压-------------------");
|
log.info("-------------------【定时任务10秒一次】更新设备的定位和电压-----开始--------------");
|
||||||
List<Object> cacheList = redisCache.getCacheList(CacheConstants.CACHE_DEVICE_KEY + "*");
|
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
|
||||||
for(Object object:cacheList){
|
log.info("redis缓存中的数据:" + JSON.toJSONString(keys));
|
||||||
String msg =(String)object;
|
for(String key:keys){
|
||||||
|
String msg = redisCache.getCacheObject(key);
|
||||||
|
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_OPEN.equals(device.getLockStatus())){
|
||||||
|
updateLocationHandle(msg, logEntry, value, device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("-------------------【定时任务10秒一次】更新设备的定位和电压----结束---------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 更新设备的定位和电压 5分钟一次
|
||||||
|
* cron: 0 20 0 * * ?
|
||||||
|
*/
|
||||||
|
public void updateLocation300(){
|
||||||
|
log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压-----开始--------------");
|
||||||
|
Collection<String> keys = redisCache.keys(CacheConstants.CACHE_DEVICE_KEY + "*");
|
||||||
|
log.info("redis缓存中的数据:" + JSON.toJSONString(keys));
|
||||||
|
for(String key:keys){
|
||||||
|
String msg = redisCache.getCacheObject(key);
|
||||||
|
log.info("redis缓存中的数据:" + msg);
|
||||||
|
LogEntry logEntry = JSONObject.parseObject(msg, LogEntry.class);
|
||||||
|
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())){
|
||||||
|
updateLocationHandle(msg, logEntry, value, device);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("-------------------【定时任务5分钟一次】更新设备的定位和电压----结束---------------");
|
||||||
|
}
|
||||||
|
|
||||||
|
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 lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP);
|
BigDecimal lat = new BigDecimal(doubles[0]).setScale(8, RoundingMode.HALF_UP);
|
||||||
BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP);
|
BigDecimal lon = new BigDecimal(doubles[1]).setScale(8, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
asynchronousSaveLog(msg,logEntry.getAt(),logEntry.getDevName(), lat, lon,device);
|
asynchronousSaveLog(msg, logEntry.getAt(), logEntry.getDevName(), lat, lon, device);
|
||||||
|
|
||||||
BigDecimal divide = new BigDecimal(value.getBat()).divide(new BigDecimal(10));
|
BigDecimal divide = new BigDecimal(value.getBat()).divide(new BigDecimal(10));
|
||||||
device.setVoltage(divide.toString());//电压
|
device.setVoltage(divide.toString());//电压
|
||||||
|
@ -549,8 +579,7 @@ public class EtTask {
|
||||||
}
|
}
|
||||||
int i = asDeviceService.updateLocation(device);
|
int i = asDeviceService.updateLocation(device);
|
||||||
if(i>0){
|
if(i>0){
|
||||||
log.info("到定位===============保存电压等数值成功===========>" + logEntry.getDevName());
|
log.info("===============更新设备信息成功===========>" + logEntry.getDevName());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user