|
|
|
|
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.business.vo.CurrentCarInfoVo;
|
|
|
|
|
import org.springblade.modules.websocket.service.WebsocketService;
|
|
|
|
|
import org.springblade.modules.websocket.vo.WebSocketMessage;
|
|
|
|
|
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;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @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 setCarInfo(Map<String,Object> resultMap) {
|
|
|
|
|
redisTemplate.opsForValue().set("current_car_info", resultMap);
|
|
|
|
|
System.out.println("======存入实时车辆信息到redis成功=========");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//@Scheduled(cron = "0/1 * * * * ?")
|
|
|
|
|
public void parseCarInfo() {
|
|
|
|
|
//从redis获取数据
|
|
|
|
|
Map<String,Object> carInfoMap = (Map<String,Object> ) redisTemplate.opsForValue().get("current_car_info");
|
|
|
|
|
if (carInfoMap.isEmpty()) {
|
|
|
|
|
log.info("======未从redis获取当前车辆实时数据=======");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 解析车辆信息
|
|
|
|
|
WebSocketMessage message = new WebSocketMessage();
|
|
|
|
|
message.setTitle("current_car_info");
|
|
|
|
|
message.setCode(200);
|
|
|
|
|
message.setContent("车辆信息:" + carInfoMap.toString());
|
|
|
|
|
log.info("解析车辆信息:{}", carInfoMap.toString());
|
|
|
|
|
// 推送消息给web页面
|
|
|
|
|
websocketService.broadcast(message);
|
|
|
|
|
log.info("推送车辆信息:{}", carInfoMap.toString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|