|
|
@@ -2,6 +2,7 @@ package com.ruoyi.data.controller;
|
|
|
|
|
|
import java.time.Duration;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
@@ -10,14 +11,13 @@ import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.json.JSONArray;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
-import com.ruoyi.common.core.domain.entity.SysDictType;
|
|
|
+import com.ruoyi.common.utils.redis.CacheUtils;
|
|
|
import com.ruoyi.common.utils.redis.RedisUtils;
|
|
|
import com.ruoyi.data.domain.*;
|
|
|
import com.ruoyi.data.domain.bo.*;
|
|
|
import com.ruoyi.data.domain.vo.*;
|
|
|
import com.ruoyi.data.service.*;
|
|
|
import com.ruoyi.system.service.ISysDictTypeService;
|
|
|
-import lombok.Data;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
@@ -125,8 +125,25 @@ public class TblDataController extends BaseController {
|
|
|
a.put("code",tblSensorVo.getId());
|
|
|
a.put("state",1);
|
|
|
if(RedisUtils.getCacheObject("sensor_status_"+tblSensorVo.getId())!=null){
|
|
|
- Map<String,Integer> aa = RedisUtils.getCacheObject("sensor_status_"+tblSensorVo.getId());
|
|
|
- a.put("state",aa.get("12")>1?0:1);
|
|
|
+ Map<String,Object> aa = RedisUtils.getCacheObject("sensor_status_"+tblSensorVo.getId());
|
|
|
+ a.put("state",(int)(aa.get("12"))>1?0:1);
|
|
|
+ a.put("lasttime",aa.get("lasttime")==null?"":aa.get("lasttime"));
|
|
|
+
|
|
|
+ AtomicReference<Date> dataBo12Time = new AtomicReference<>();
|
|
|
+ try {
|
|
|
+ MqttSensorDataBo dataBo12 = CacheUtils.get("sensorData", tblSensorVo.getId().toString());
|
|
|
+ dataBo12.getData().forEach(bo -> {
|
|
|
+ if (dataBo12Time.get() == null) dataBo12Time.set(bo.getCreateTime());
|
|
|
+ if (bo.getCreateTime().getTime() > dataBo12Time.get().getTime()) {
|
|
|
+ dataBo12Time.set(bo.getCreateTime());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if(dataBo12Time.get()!=null){
|
|
|
+ a.put("lasttime", DateUtil.formatDateTime(dataBo12Time.get()));
|
|
|
+ }
|
|
|
+ }catch (Exception e){}
|
|
|
+
|
|
|
+
|
|
|
}else{
|
|
|
TblSensorRecordBo a1 =new TblSensorRecordBo();
|
|
|
Map<String, Object> t = new HashMap<>();
|
|
|
@@ -141,13 +158,34 @@ public class TblDataController extends BaseController {
|
|
|
a1.setParams(t);
|
|
|
|
|
|
List<TblSensorRecordVo> a12 = iTblSensorRecordService.queryList(a1);
|
|
|
- Map<String,Integer> temp = new HashMap<>();
|
|
|
+
|
|
|
+ AtomicReference<Date> dataBo12Time = new AtomicReference<>();
|
|
|
+ try {
|
|
|
+ MqttSensorDataBo dataBo12 = CacheUtils.get("sensorData", tblSensorVo.getId().toString());
|
|
|
+ dataBo12.getData().forEach(bo -> {
|
|
|
+ if (dataBo12Time.get() == null) dataBo12Time.set(bo.getCreateTime());
|
|
|
+ if (bo.getCreateTime().getTime() > dataBo12Time.get().getTime()) {
|
|
|
+ dataBo12Time.set(bo.getCreateTime());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }catch (Exception e){}
|
|
|
+ if(dataBo12Time.get()==null){
|
|
|
+ t = new HashMap<>();
|
|
|
+ t.put("limit", 1);
|
|
|
+ a1.setParams(t);
|
|
|
+ List<TblSensorRecordVo> a13 = iTblSensorRecordService.queryList(a1);
|
|
|
+ dataBo12Time.set(a13.size()>0?a13.get(0).getCreateTime():null);
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String,Object> temp = new HashMap<>();
|
|
|
temp.put("12",a11.size());
|
|
|
temp.put("24",a12.size());
|
|
|
- RedisUtils.setCacheObject("sensor_status_"+tblSensorVo.getId(),temp, Duration.ofSeconds(60*60));
|
|
|
+ temp.put("lasttime",dataBo12Time.get()==null?"-":DateUtil.formatDateTime(dataBo12Time.get()));
|
|
|
|
|
|
- Map<String,Integer> aa = RedisUtils.getCacheObject("sensor_status_"+tblSensorVo.getId());
|
|
|
- a.put("state",aa.get("12")>1?0:1);
|
|
|
+ RedisUtils.setCacheObject("sensor_status_"+tblSensorVo.getId(),temp, Duration.ofSeconds(60*60));
|
|
|
+ Map<String,Object> aa = RedisUtils.getCacheObject("sensor_status_"+tblSensorVo.getId());
|
|
|
+ a.put("state",(int)aa.get("12")>1?0:1);
|
|
|
+ a.put("lasttime",aa.get("lasttime")==null?"":aa.get("lasttime"));
|
|
|
}
|
|
|
list.add(a);
|
|
|
});
|