|
|
@@ -67,15 +67,21 @@ public class IotDeviceService {
|
|
|
List<IotDeviceVo> iotProductVos = iotDeviceMapper.pageQuery(devicePage);
|
|
|
PageInfo<IotDeviceVo> pageInfo = new PageInfo<>(iotProductVos);
|
|
|
iotProductVos.forEach(a -> {
|
|
|
+ Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, a.getGuid()))).ifPresent(t -> {
|
|
|
+ a.setOnlineTime(LocalDateTimeUtil.parse((String) t));
|
|
|
+ a.setStatus(1);
|
|
|
+ });
|
|
|
Optional.ofNullable(userApi.queryUser(a.getCreateBy())).ifPresent(userCache -> a.setCreateByLabel(userCache.getName()));
|
|
|
Optional.ofNullable(userApi.queryUser(a.getUpdateBy())).ifPresent(userCache -> a.setUpdateByLabel(userCache.getName()));
|
|
|
Optional.ofNullable(dictApi.query(DictType.NODE_TYPE, String.valueOf(a.getNodeType()))).ifPresent(dictCache -> a.setNodeTypeLabel(dictCache.getLabel()));
|
|
|
Optional.ofNullable(dictApi.query(DictType.STATUS_TYPE, String.valueOf(a.getStatus()))).ifPresent(dictCache -> a.setStatusName(dictCache.getLabel()));
|
|
|
Optional.ofNullable(dictApi.query(DictType.ENABLE_TYPE, String.valueOf(a.getEnableFlag()))).ifPresent(dictCache -> a.setEnableFlagName(dictCache.getLabel()));
|
|
|
- Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, a.getGuid()))).ifPresent(t -> {
|
|
|
- a.setOnlineTime(t);
|
|
|
- a.setStatus(1);
|
|
|
- });
|
|
|
+ });
|
|
|
+ //异步维护在线状态和在线时间
|
|
|
+ ThreadTask.addJob(() -> {
|
|
|
+ for (IotDeviceVo iotProductVo : iotProductVos) {
|
|
|
+ iotDeviceMapper.updateStatus(iotProductVo);
|
|
|
+ }
|
|
|
});
|
|
|
return new PageRes<>(pageInfo, iotProductVos);
|
|
|
}
|
|
|
@@ -190,6 +196,10 @@ public class IotDeviceService {
|
|
|
if (Objects.isNull(detail)) {
|
|
|
throw new BusinessException("设备不存在");
|
|
|
}
|
|
|
+ Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, detail.getGuid()))).ifPresent(t -> {
|
|
|
+ detail.setOnlineTime(LocalDateTimeUtil.parse((String) t));
|
|
|
+ detail.setStatus(1);
|
|
|
+ });
|
|
|
Optional.ofNullable(userApi.queryUser(detail.getCreateBy())).ifPresent(userCache -> detail.setCreateByLabel(userCache.getName()));
|
|
|
Optional.ofNullable(userApi.queryUser(detail.getUpdateBy())).ifPresent(userCache -> detail.setUpdateByLabel(userCache.getName()));
|
|
|
Optional.ofNullable(dictApi.query(DictType.AUTH_TYPE, String.valueOf(detail.getAuthType()))).ifPresent(cache -> detail.setAuthTypeLabel(cache.getLabel()));
|
|
|
@@ -200,9 +210,12 @@ public class IotDeviceService {
|
|
|
Optional.ofNullable(dictApi.query(DictType.REPORT_PROTOCOL_TYPE, String.valueOf(detail.getReportProtocol()))).ifPresent(cache -> detail.setReportProtocolLabel(cache.getLabel()));
|
|
|
Optional.ofNullable(dictApi.query(DictType.VENDORS_TYPE, String.valueOf(detail.getVendors()))).ifPresent(cache -> detail.setVendorsLabel(cache.getLabel()));
|
|
|
Optional.ofNullable(dictApi.query(DictType.DATA_FORMAT_TYPE, String.valueOf(detail.getDataFormat()))).ifPresent(cache -> detail.setDataFormatLabel(cache.getLabel()));
|
|
|
- Optional.ofNullable(cacheService.getKey(String.format(CacheConstant.ONLINE_CACHE, detail.getGuid()))).ifPresent(t -> {
|
|
|
- detail.setOnlineTime(LocalDateTimeUtil.parse((String) t));
|
|
|
- detail.setStatus(1);
|
|
|
+
|
|
|
+ ThreadTask.addJob(() -> {
|
|
|
+ IotDeviceVo iotDevice = new IotDeviceVo();
|
|
|
+ iotDevice.setStatus(detail.getStatus());
|
|
|
+ iotDevice.setOnlineTime(detail.getOnlineTime());
|
|
|
+ iotDeviceMapper.updateStatus(iotDevice);
|
|
|
});
|
|
|
return detail;
|
|
|
}
|