You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.0 KiB
59 lines
2.0 KiB
|
3 years ago
|
package org.springblade.modules.job;
|
||
|
|
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.springblade.modules.business.service.ICarInfoService;
|
||
|
|
import org.springblade.modules.business.service.IStationHintService;
|
||
|
|
import org.springblade.modules.business.vo.CarInfoVO;
|
||
|
|
import org.springblade.modules.websocket.service.WebsocketService;
|
||
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
||
|
|
import org.springframework.data.redis.core.RedisTemplate;
|
||
|
|
import org.springframework.scheduling.annotation.Scheduled;
|
||
|
|
import org.springframework.stereotype.Component;
|
||
|
|
|
||
|
|
import java.util.List;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @Author: Chents
|
||
|
|
* @Create: 2023-05-09
|
||
|
|
*/
|
||
|
|
@Component
|
||
|
|
@Slf4j
|
||
|
|
public class CarInfoTask {
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private ICarInfoService carInfoService;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private RedisTemplate<String, Object> redisTemplate;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private WebsocketService websocketService;
|
||
|
|
|
||
|
|
@Autowired
|
||
|
|
private IStationHintService stationHintService;
|
||
|
|
|
||
|
|
//@Scheduled(cron = "0/1 * * * * ?")
|
||
|
|
public void getAllCarInfo() {
|
||
|
|
redisTemplate.opsForValue().set("car_info", carInfoService.getAllCarInfo());
|
||
|
|
System.out.println("======存入实时车辆信息到redis成功=========");
|
||
|
|
}
|
||
|
|
|
||
|
|
//@Scheduled(cron = "0/1 * * * * ?")
|
||
|
|
public void parseCarInfo() {
|
||
|
|
//从redis获取数据
|
||
|
|
List<CarInfoVO> carInfoList = (List<CarInfoVO>) redisTemplate.opsForValue().get("car_info");
|
||
|
|
if (carInfoList == null && carInfoList.isEmpty()) {
|
||
|
|
log.info("======未从redis获取车辆实时数据=======");
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
for (CarInfoVO carInfo : carInfoList) {
|
||
|
|
// 解析车辆信息
|
||
|
|
log.info("解析车辆信息:{}", carInfo.toString());
|
||
|
|
// 推送消息给web页面
|
||
|
|
websocketService.broadcast("car_info", "车辆信息:" + carInfo.toString());
|
||
|
|
log.info("推送车辆信息:{}", carInfo.toString());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|