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.

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