| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | public void judgeOffLineDevice() { |
| | | QueryWrapper<Device> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.ne("state", Constants.DEVICE_STATE_OFFLINE); |
| | | queryWrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | //获取所有在线设备 |
| | | List<Device> devices = deviceMapper.selectList(queryWrapper); |
| | | for (Device device : devices) { |
| | | Map<String, Object> data = (Map<String, Object>) redisTemplate.opsForValue().get(RedisConstants.DEVICE_DATA + device.getMac());; |
| | | Map<String, Object> data = (Map<String, Object>) redisTemplate.opsForHash().get(RedisConstants.DATA_SECOND, device.getMac()); |
| | | device.setState(Constants.DEVICE_STATE_OFFLINE); |
| | | if (data != null && data.containsKey("DataTime")) { |
| | | Date time = DateUtils.getDate((String) data.get("DataTime"), DateUtils.yyyyMMddHHmmss_EN); |
| | |
| | | } |
| | | |
| | | @Override |
| | | @Transactional |
| | | public void updateDeviceState(Device device) { |
| | | UpdateWrapper<Device> updateWrapper = new UpdateWrapper<>(); |
| | | updateWrapper.eq("id", device.getId()).set("state", device.getState()); |
| | | deviceMapper.update(null, updateWrapper); |
| | | } |
| | | } |
| | | } |