| | |
| | | import com.dji.sample.manage.model.dto.DeviceDTO; |
| | | import com.dji.sample.manage.model.enums.DeviceDomainEnum; |
| | | import com.dji.sample.manage.service.IDeviceService; |
| | | import com.dji.sample.wayline.service.IWaylineJobService; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | private IDeviceService deviceService; |
| | | |
| | | @Autowired |
| | | private RedisOpsUtils redisOps; |
| | | |
| | | @Autowired |
| | | private IMqttTopicService topicService; |
| | | |
| | | @Autowired |
| | | private IWaylineJobService waylineJobService; |
| | | @Autowired |
| | | private ObjectMapper mapper; |
| | | /** |
| | | * Check the status of the devices every 30 seconds. It is recommended to use cache. |
| | | */ |
| | | @Scheduled(initialDelay = 30, fixedRate = 30, timeUnit = TimeUnit.SECONDS) |
| | | @Scheduled(initialDelay = 10, fixedRate = 30, timeUnit = TimeUnit.SECONDS) |
| | | private void deviceStatusListen() { |
| | | int start = RedisConst.DEVICE_ONLINE_PREFIX.length(); |
| | | |
| | | redisOps.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*").forEach(key -> { |
| | | long expire = redisOps.getExpire(key); |
| | | RedisOpsUtils.getAllKeys(RedisConst.DEVICE_ONLINE_PREFIX + "*").forEach(key -> { |
| | | long expire = RedisOpsUtils.getExpire(key); |
| | | if (expire <= 30) { |
| | | DeviceDTO device = (DeviceDTO) redisOps.get(key); |
| | | if (device.getDomain().equals(DeviceDomainEnum.SUB_DEVICE.getDesc())) { |
| | | DeviceDTO device = (DeviceDTO) RedisOpsUtils.get(key); |
| | | if (DeviceDomainEnum.SUB_DEVICE.getVal() == device.getDomain()) { |
| | | deviceService.subDeviceOffline(key.substring(start)); |
| | | } else { |
| | | deviceService.unsubscribeTopicOffline(key.substring(start)); |
| | | deviceService.pushDeviceOfflineTopo(device.getWorkspaceId(), device.getDeviceSn()); |
| | | RedisOpsUtils.hashDel(RedisConst.LIVE_CAPACITY, new String[]{device.getDeviceSn()}); |
| | | RedisOpsUtils.del(RedisConst.HMS_PREFIX + device.getDeviceSn()); |
| | | RedisOpsUtils.del(RedisConst.OSD_PREFIX + device.getDeviceSn()); |
| | | } |
| | | redisOps.del(key); |
| | | RedisOpsUtils.del(key); |
| | | } |
| | | }); |
| | | |