|
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
import org.apache.commons.lang3.RandomUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.cache.CacheManager;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.scheduling.annotation.Async;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
@@ -19,6 +20,7 @@ import org.thingsboard.server.domain.*;
|
|
import org.thingsboard.server.domain.dto.RealTimeDataObj;
|
|
import org.thingsboard.server.domain.dto.RealTimeDataObj;
|
|
import org.thingsboard.server.domain.dto.TriggerDataObj;
|
|
import org.thingsboard.server.domain.dto.TriggerDataObj;
|
|
import org.thingsboard.server.domain.vo.UserInfoViews;
|
|
import org.thingsboard.server.domain.vo.UserInfoViews;
|
|
|
|
+import org.thingsboard.server.glossary.constants.FastIotConstants;
|
|
import org.thingsboard.server.glossary.enums.YuntiTypeEnums;
|
|
import org.thingsboard.server.glossary.enums.YuntiTypeEnums;
|
|
import org.thingsboard.server.mapper.CommonMapper;
|
|
import org.thingsboard.server.mapper.CommonMapper;
|
|
import org.thingsboard.server.mapper.SysDicItemMapper;
|
|
import org.thingsboard.server.mapper.SysDicItemMapper;
|
|
@@ -27,6 +29,7 @@ import org.thingsboard.server.service.nanxi.*;
|
|
import org.thingsboard.server.utils.NumberUtils;
|
|
import org.thingsboard.server.utils.NumberUtils;
|
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
|
|
+import java.time.Duration;
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -53,6 +56,8 @@ public class YunTiAsyncServiceImpl implements IYunTiAsyncService {
|
|
private ScadaHistoryService scadaHistoryService;
|
|
private ScadaHistoryService scadaHistoryService;
|
|
@Autowired
|
|
@Autowired
|
|
private ScadaMonitorService scadaMonitorService;
|
|
private ScadaMonitorService scadaMonitorService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private CacheManager cacheManager;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Async("yunTiAsyncExecutor")
|
|
@Async("yunTiAsyncExecutor")
|
|
@@ -97,7 +102,10 @@ public class YunTiAsyncServiceImpl implements IYunTiAsyncService {
|
|
}
|
|
}
|
|
scadaHistoryList.add(scadaHistory);
|
|
scadaHistoryList.add(scadaHistory);
|
|
}
|
|
}
|
|
- scadaHistoryService.saveBatch(scadaHistoryList);
|
|
+ if(cacheManager.getCache(FastIotConstants.CacheConfigKey.CACHE_REAL_TIME_DATA_KEY).get(messageBody.getRegisterCode(), Long.class) == 0l || timestamp2Timestamp(json.getLong("timestamp"), cacheManager.getCache(FastIotConstants.CacheConfigKey.CACHE_REAL_TIME_DATA_KEY).get(messageBody.getRegisterCode(), Long.class))) {
|
|
|
|
+ cacheManager.getCache(FastIotConstants.CacheConfigKey.CACHE_REAL_TIME_DATA_KEY).put(messageBody.getRegisterCode(), json.getLong("timestamp"));
|
|
|
|
+ scadaHistoryService.saveBatch(scadaHistoryList);
|
|
|
|
+ }
|
|
if (CollUtil.isNotEmpty(scadaHistoryList)) {
|
|
if (CollUtil.isNotEmpty(scadaHistoryList)) {
|
|
|
|
|
|
|
|
|
|
@@ -156,7 +164,10 @@ public class YunTiAsyncServiceImpl implements IYunTiAsyncService {
|
|
}
|
|
}
|
|
scadaHistoryList.add(scadaHistory);
|
|
scadaHistoryList.add(scadaHistory);
|
|
}
|
|
}
|
|
- scadaHistoryService.saveBatch(scadaHistoryList);
|
|
+ if(cacheManager.getCache(FastIotConstants.CacheConfigKey.CACHE_TRIGGER_DATA_KEY).get(messageBody.getRegisterCode(), Long.class) == 0l || timestamp2Timestamp(json.getLong("timestamp"), cacheManager.getCache(FastIotConstants.CacheConfigKey.CACHE_TRIGGER_DATA_KEY).get(messageBody.getRegisterCode(), Long.class))){
|
|
|
|
+ cacheManager.getCache(FastIotConstants.CacheConfigKey.CACHE_TRIGGER_DATA_KEY).put(messageBody.getRegisterCode(), json.getLong("timestamp"));
|
|
|
|
+ scadaHistoryService.saveBatch(scadaHistoryList);
|
|
|
|
+ }
|
|
if (CollUtil.isNotEmpty(scadaHistoryList)) {
|
|
if (CollUtil.isNotEmpty(scadaHistoryList)) {
|
|
|
|
|
|
|
|
|
|
@@ -190,6 +201,10 @@ public class YunTiAsyncServiceImpl implements IYunTiAsyncService {
|
|
return history;
|
|
return history;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private boolean timestamp2Timestamp(Long nowTimestamp, Long oldTimestamp){
|
|
|
|
+ return Duration.ofMillis(nowTimestamp - oldTimestamp).toMinutes() > 5;
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|