|
|
|
@ -1,18 +1,21 @@ |
|
|
|
package org.springblade.modules.job; |
|
|
|
package org.springblade.modules.job; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
|
|
|
|
import org.springblade.core.tool.api.R; |
|
|
|
|
|
|
|
import org.springblade.core.tool.utils.Func; |
|
|
|
import org.springblade.modules.business.service.ICarInfoService; |
|
|
|
import org.springblade.modules.business.service.ICarInfoService; |
|
|
|
import org.springblade.modules.business.service.IStationHintService; |
|
|
|
import org.springblade.modules.business.service.IStationHintService; |
|
|
|
import org.springblade.modules.business.vo.CarInfoVO; |
|
|
|
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.service.WebsocketService; |
|
|
|
import org.springblade.modules.websocket.vo.WebSocketMessage; |
|
|
|
import org.springblade.modules.websocket.vo.WebSocketMessage; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.data.redis.core.RedisTemplate; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.scheduling.annotation.Scheduled; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
import org.springframework.stereotype.Component; |
|
|
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -23,6 +26,10 @@ import java.util.Map; |
|
|
|
@Slf4j |
|
|
|
@Slf4j |
|
|
|
public class CarInfoTask { |
|
|
|
public class CarInfoTask { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static final String WEB = "web"; |
|
|
|
|
|
|
|
private static final String CURRENT_CAR_INFO = "current_car_info"; |
|
|
|
|
|
|
|
private static final String PUSH_STATUS = "push_status"; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
@Autowired |
|
|
|
private ICarInfoService carInfoService; |
|
|
|
private ICarInfoService carInfoService; |
|
|
|
|
|
|
|
|
|
|
|
@ -36,28 +43,79 @@ public class CarInfoTask { |
|
|
|
private IStationHintService stationHintService; |
|
|
|
private IStationHintService stationHintService; |
|
|
|
|
|
|
|
|
|
|
|
//@Scheduled(cron = "0/1 * * * * ?")
|
|
|
|
//@Scheduled(cron = "0/1 * * * * ?")
|
|
|
|
public void setCarInfo(Map<String,Object> resultMap) { |
|
|
|
public void setCarInfo(Map<String, Object> resultMap) { |
|
|
|
redisTemplate.opsForValue().set("current_car_info", resultMap); |
|
|
|
redisTemplate.opsForValue().set("current_car_info", resultMap); |
|
|
|
System.out.println("======存入实时车辆信息到redis成功========="); |
|
|
|
System.out.println("======存入实时车辆信息到redis成功========="); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/1 * * * * ?") |
|
|
|
@Scheduled(cron = "0/1 * * * * ?") |
|
|
|
|
|
|
|
public void setCarInfo() { |
|
|
|
|
|
|
|
// redisTemplate.opsForValue().set("car-current-number", device);
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/10 * * * * ?") |
|
|
|
public void parseCarInfo() { |
|
|
|
public void parseCarInfo() { |
|
|
|
//从redis获取数据
|
|
|
|
//从redis获取数据
|
|
|
|
Map<String,Object> carInfoMap = (Map<String,Object> ) redisTemplate.opsForValue().get("current_car_info"); |
|
|
|
Map<String, Object> carInfoMap = (Map<String, Object>) redisTemplate.opsForValue().get("current_car_info"); |
|
|
|
if (carInfoMap.isEmpty()) { |
|
|
|
if (carInfoMap.isEmpty()) { |
|
|
|
log.info("======未从redis获取当前车辆实时数据======="); |
|
|
|
log.info("======未从redis获取当前车辆实时数据======="); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
// 解析车辆信息
|
|
|
|
// 解析车辆信息
|
|
|
|
|
|
|
|
HashMap<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put("msgType", CURRENT_CAR_INFO); |
|
|
|
|
|
|
|
map.put("data", carInfoMap); |
|
|
|
|
|
|
|
String messageJson = JSON.toJSONString(map); |
|
|
|
|
|
|
|
|
|
|
|
WebSocketMessage message = new WebSocketMessage(); |
|
|
|
WebSocketMessage message = new WebSocketMessage(); |
|
|
|
message.setTitle("current_car_info"); |
|
|
|
message.setTitle(WEB); |
|
|
|
message.setCode(200); |
|
|
|
message.setCode(200); |
|
|
|
message.setContent("车辆信息:" + carInfoMap.toString()); |
|
|
|
message.setContent(messageJson); |
|
|
|
log.info("解析车辆信息:{}", carInfoMap.toString()); |
|
|
|
//log.info("解析车辆信息:{}", carInfoMap.toString());
|
|
|
|
// 推送消息给web页面
|
|
|
|
// 推送消息给web页面
|
|
|
|
websocketService.broadcast(message); |
|
|
|
websocketService.broadcast(message); |
|
|
|
log.info("推送车辆信息:{}", carInfoMap.toString()); |
|
|
|
log.info("推送车辆信息:{}", carInfoMap.toString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/1 * * * * ?") |
|
|
|
|
|
|
|
public void parsePushStatus() { |
|
|
|
|
|
|
|
//从redis获取数据
|
|
|
|
|
|
|
|
String carNo = (String) redisTemplate.opsForValue().get("car-current-number"); |
|
|
|
|
|
|
|
String pushStatus = (String) redisTemplate.opsForValue().get("set-current-Facility-stat" + carNo); |
|
|
|
|
|
|
|
Map<String, String> resultData = new HashMap<>(); |
|
|
|
|
|
|
|
resultData.put("carNo", carNo); |
|
|
|
|
|
|
|
resultData.put("pushStatus", pushStatus); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 解析车辆信息
|
|
|
|
|
|
|
|
HashMap<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put("msgType", PUSH_STATUS); |
|
|
|
|
|
|
|
map.put("data", resultData); |
|
|
|
|
|
|
|
String messageJson = JSON.toJSONString(map); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WebSocketMessage message = new WebSocketMessage(); |
|
|
|
|
|
|
|
message.setTitle(WEB); |
|
|
|
|
|
|
|
message.setCode(200); |
|
|
|
|
|
|
|
message.setContent(messageJson); |
|
|
|
|
|
|
|
//log.info("解析车辆信息:{}", carInfoMap.toString());
|
|
|
|
|
|
|
|
// 推送消息给web页面
|
|
|
|
|
|
|
|
websocketService.broadcast(message); |
|
|
|
|
|
|
|
log.info("推送车辆信息:{}", map.toString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Scheduled(cron = "0/1 * * * * ?") |
|
|
|
|
|
|
|
public void getCarSpeed(String carNo) { |
|
|
|
|
|
|
|
CarInfoVO info = carInfoService.getCarInfo(carNo); |
|
|
|
|
|
|
|
if (Func.isEmpty(info)) { |
|
|
|
|
|
|
|
throw new RuntimeException("未获取到车辆信息, 请检查车是否已掉线"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
String speedJson = JSON.toJSONString(info.getSpeed()); |
|
|
|
|
|
|
|
WebSocketMessage message = new WebSocketMessage(); |
|
|
|
|
|
|
|
message.setTitle(WEB); |
|
|
|
|
|
|
|
message.setCode(200); |
|
|
|
|
|
|
|
message.setContent(speedJson); |
|
|
|
|
|
|
|
websocketService.broadcast(message); |
|
|
|
|
|
|
|
log.info("车辆实时车速:{}", message.getContent()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|