|
@@ -53,9 +53,7 @@ import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.time.Duration;
|
|
import java.time.Duration;
|
|
|
-import java.time.Instant;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
-import java.time.ZoneOffset;
|
|
|
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -98,7 +96,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
private TblTenantService tblTenantService;
|
|
private TblTenantService tblTenantService;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- private MqttSend mqttSend;
|
|
|
|
|
|
|
+ private MqttSend mqttSend;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
private RedisUtil redisService;
|
|
private RedisUtil redisService;
|
|
@@ -144,12 +142,12 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
|
|
|
|
|
// 统计设备总数和告警数量
|
|
// 统计设备总数和告警数量
|
|
|
int totalDevices = 0;
|
|
int totalDevices = 0;
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
for (DevInfo devInfo : devInfos) {
|
|
for (DevInfo devInfo : devInfos) {
|
|
|
DeviceDTO dto = new DeviceDTO();
|
|
DeviceDTO dto = new DeviceDTO();
|
|
|
BeanUtils.copyProperties(devInfo, dto);
|
|
BeanUtils.copyProperties(devInfo, dto);
|
|
|
deviceDTOs.add(dto);
|
|
deviceDTOs.add(dto);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
// 统计设备数量
|
|
// 统计设备数量
|
|
|
totalDevices++;
|
|
totalDevices++;
|
|
|
|
|
|
|
@@ -161,7 +159,7 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
.collect(Collectors.toList());
|
|
.collect(Collectors.toList());
|
|
|
|
|
|
|
|
long warningNums = EventsService.countUserDevicesEvents(clientIds);
|
|
long warningNums = EventsService.countUserDevicesEvents(clientIds);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
homeInfoDTO.setDeviceList(deviceDTOs);
|
|
homeInfoDTO.setDeviceList(deviceDTOs);
|
|
|
// 设置设备总数
|
|
// 设置设备总数
|
|
|
homeInfoDTO.setDevNum(totalDevices);
|
|
homeInfoDTO.setDevNum(totalDevices);
|
|
@@ -194,55 +192,27 @@ public class DeviceGatewayImpl implements DeviceGateway {
|
|
|
public List<DeviceDTO> queryDeviceList(DeviceListParams request) {
|
|
public List<DeviceDTO> queryDeviceList(DeviceListParams request) {
|
|
|
|
|
|
|
|
log.info("查询设备列表 queryDeviceList");
|
|
log.info("查询设备列表 queryDeviceList");
|
|
|
- Optional<List<Long>> sharedDevIds = devShareService.queryDeviceIdByUserId(request.getUserId());
|
|
|
|
|
|
|
+ List<Long> sharedDevIds = devShareService.queryDeviceIdByUserId(request.getUserId())
|
|
|
|
|
+ .orElse(Collections.emptyList());
|
|
|
|
|
|
|
|
List<DeviceDTO> deviceDTOs = new ArrayList<>();
|
|
List<DeviceDTO> deviceDTOs = new ArrayList<>();
|
|
|
- List<DevInfo> devInfos = devInfoService.queryDeviceList(request.getUserId(), request.getKeyWord(),
|
|
|
|
|
- request.getStatus(), sharedDevIds.orElse(Collections.emptyList()));
|
|
|
|
|
|
|
+ List<DevInfo> devInfos = devInfoService.queryDeviceList(
|
|
|
|
|
+ request.getUserId(),
|
|
|
|
|
+ request.getKeyWord(),
|
|
|
|
|
+ request.getStatus(),
|
|
|
|
|
+ sharedDevIds
|
|
|
|
|
+ );
|
|
|
|
|
|
|
|
for (DevInfo devInfo : devInfos) {
|
|
for (DevInfo devInfo : devInfos) {
|
|
|
DeviceDTO dto = new DeviceDTO();
|
|
DeviceDTO dto = new DeviceDTO();
|
|
|
BeanUtils.copyProperties(devInfo, dto);
|
|
BeanUtils.copyProperties(devInfo, dto);
|
|
|
|
|
|
|
|
- //从Redis中获取目标最后离开时间
|
|
|
|
|
- String redisKey = "hfln:device:" + devInfo.getClientId(); //构建Redis的Key
|
|
|
|
|
- log.info("查询RedisKey: {}", redisKey);
|
|
|
|
|
- try {
|
|
|
|
|
- // 检查key是否存在
|
|
|
|
|
- if (!redisService.hasKey(redisKey)) {
|
|
|
|
|
- log.info("Redis中不存在key: {}", redisKey);
|
|
|
|
|
- deviceDTOs.add(dto);
|
|
|
|
|
- continue;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 直接从Hash中获取lastTargetTime字段
|
|
|
|
|
- Object lastTargetTimeObj = redisTemplate.opsForHash().get(redisKey, "lastTargetTime");
|
|
|
|
|
-
|
|
|
|
|
- // 处理获取到的数据
|
|
|
|
|
- if (lastTargetTimeObj != null) {
|
|
|
|
|
- try {
|
|
|
|
|
- //将时间戳转换为LocalDatetime
|
|
|
|
|
- long lastTargetTimeMillis = Long.parseLong(lastTargetTimeObj.toString());
|
|
|
|
|
- LocalDateTime lastTargetTime = Instant.ofEpochMilli(lastTargetTimeMillis)
|
|
|
|
|
- .atZone(ZoneOffset.systemDefault())
|
|
|
|
|
- .toLocalDateTime();
|
|
|
|
|
-
|
|
|
|
|
- dto.setLastTargetTime(lastTargetTime);
|
|
|
|
|
- log.info("成功设置lastTargetTime,clientId: {}, time: {}", devInfo.getClientId(), lastTargetTime);
|
|
|
|
|
- } catch (NumberFormatException e) {
|
|
|
|
|
- log.error("Redis中存储的时间戳格式错误,clientId: {}, value: {}", devInfo.getClientId(), lastTargetTimeObj, e);
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- log.info("未找到lastTargetTime数据,clientId: {}", devInfo.getClientId());
|
|
|
|
|
- }
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.error("获取Redis数据失败,clientId: {}", devInfo.getClientId(), e);
|
|
|
|
|
- // 如果获取失败,不设置lastTargetTime,继续处理其他设备
|
|
|
|
|
- }
|
|
|
|
|
deviceDTOs.add(dto);
|
|
deviceDTOs.add(dto);
|
|
|
}
|
|
}
|
|
|
- log.info("查询设备列表 queryDeviceList end list.size= {}", deviceDTOs.size());
|
|
|
|
|
- return deviceDTOs;
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ log.info("查询设备列表 queryDeviceList end list.size= {}", deviceDTOs.size());
|
|
|
|
|
+ return deviceDTOs;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|