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.
62 lines
2.1 KiB
62 lines
2.1 KiB
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; |
|
|
|
/** |
|
* @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(CurrentCarInfoVo currentCarInfoVo) { |
|
redisTemplate.opsForValue().set("current_car_info", currentCarInfoVo); |
|
System.out.println("======存入实时车辆信息到redis成功========="); |
|
} |
|
|
|
//@Scheduled(cron = "0/1 * * * * ?") |
|
public void parseCarInfo() { |
|
//从redis获取数据 |
|
CurrentCarInfoVo carInfo = (CurrentCarInfoVo) redisTemplate.opsForValue().get("current_car_info"); |
|
if (carInfo == null) { |
|
log.info("======未从redis获取当前车辆实时数据======="); |
|
return; |
|
} |
|
// 解析车辆信息 |
|
WebSocketMessage message = new WebSocketMessage(); |
|
message.setTitle("current_car_info"); |
|
message.setCode(200); |
|
message.setContent("车辆信息:" + carInfo.toString()); |
|
log.info("解析车辆信息:{}", carInfo.toString()); |
|
// 推送消息给web页面 |
|
websocketService.broadcast(message); |
|
log.info("推送车辆信息:{}", carInfo.toString()); |
|
} |
|
|
|
}
|
|
|