| | |
| | | package com.ruoyi.system.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.common.core.web.page.PageInfo; |
| | | import com.ruoyi.dataInterchange.api.feignClient.UPExgMsgRegisterClient; |
| | |
| | | public void taskUpdateCarStatus() { |
| | | List<Car> list = this.list(); |
| | | for (Car car : list) { |
| | | LambdaUpdateWrapper<Car> updateWrapper = new LambdaUpdateWrapper<>(); |
| | | GnssDataVo gnssDataVo = (GnssDataVo) redisTemplate.opsForValue().get("location:" + car.getVehicleNumber()); |
| | | if (null == gnssDataVo) { |
| | | car.setStatus(1); |
| | | if (car.getStatus() == 1) { |
| | | updateWrapper.set(Car::getDownlineTime, LocalDateTime.now()); |
| | | } |
| | | updateWrapper.set(Car::getStatus, 4); |
| | | this.update(updateWrapper); |
| | | } else { |
| | | String dateTime = gnssDataVo.getDate() + " " + gnssDataVo.getTime(); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(dateTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | long second = localDateTime.toEpochSecond(ZoneOffset.ofHours(8)); |
| | | if (System.currentTimeMillis() / 1000 > second + 60) { |
| | | car.setStatus(4); |
| | | if (car.getStatus() == 1) { |
| | | updateWrapper.set(Car::getDownlineTime, LocalDateTime.now()); |
| | | } |
| | | updateWrapper.set(Car::getStatus, 4); |
| | | this.update(updateWrapper); |
| | | } else { |
| | | car.setStatus(1); |
| | | if (car.getStatus() != 1) { |
| | | updateWrapper.set(Car::getDownlineTime, null); |
| | | updateWrapper.set(Car::getOnlineTime, LocalDateTime.now()); |
| | | } |
| | | updateWrapper.set(Car::getStatus, 1); |
| | | this.update(updateWrapper); |
| | | } |
| | | } |
| | | } |
| | | if (list.size() > 0) { |
| | | this.updateBatchById(list); |
| | | } |
| | | } |
| | | } |