master
chents 3 years ago
parent 6684cd172c
commit 98c0039f8e
  1. 32
      src/main/java/org/springblade/modules/business/controller/CommonApiController.java
  2. 3
      src/main/java/org/springblade/modules/business/service/ICarInfoService.java
  3. 22
      src/main/java/org/springblade/modules/business/service/impl/CarInfoServiceImpl.java
  4. 8
      src/main/java/org/springblade/modules/business/service/impl/PublishService.java
  5. 13
      src/main/java/org/springblade/modules/business/vo/DeviceVo.java
  6. 72
      src/main/java/org/springblade/modules/job/CarInfoTask.java
  7. 7
      src/main/java/org/springblade/modules/websocket/vo/WebSocketMessage.java
  8. 2
      src/main/java/org/springblade/upload/service/IProBusLineImgService.java
  9. 6
      src/main/java/org/springblade/upload/service/impl/ProBusLineImgImpl.java

@ -1,19 +1,14 @@
package org.springblade.modules.business.controller; package org.springblade.modules.business.controller;
import com.alibaba.fastjson.JSON; import io.swagger.annotations.Api;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.beetl.core.util.ArrayMap; import org.beetl.core.util.ArrayMap;
import org.jetbrains.annotations.NotNull;
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STOleUpdate;
import org.springblade.common.cache.business.BusLineCache; import org.springblade.common.cache.business.BusLineCache;
import org.springblade.common.cache.business.SiteListCache; import org.springblade.common.cache.business.SiteListCache;
import org.springblade.common.constant.BusinessConstant; import org.springblade.common.constant.BusinessConstant;
import org.springblade.common.constant.CommonConstant; import org.springblade.common.constant.CommonConstant;
import org.springblade.common.utils.CommonDateUtil;
import org.springblade.common.utils.CommonUtil; import org.springblade.common.utils.CommonUtil;
import org.springblade.core.boot.ctrl.BladeController; import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tenant.annotation.TenantDS; import org.springblade.core.tenant.annotation.TenantDS;
@ -23,18 +18,22 @@ import org.springblade.modules.business.entity.BusLine;
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.service.impl.PublishService; import org.springblade.modules.business.service.impl.PublishService;
import org.springblade.modules.business.vo.*; import org.springblade.modules.business.vo.CarInfoVO;
import org.springblade.modules.business.vo.SiteInfoVO;
import org.springblade.modules.business.vo.imgVo;
import org.springblade.modules.job.CarInfoTask; import org.springblade.modules.job.CarInfoTask;
import org.springblade.upload.entity.PocBusLineImg;
import org.springblade.upload.mapper.ProBusLineImgMapper;
import org.springblade.upload.service.IProBusLineImgService; import org.springblade.upload.service.IProBusLineImgService;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.util.CollectionUtils; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.text.DecimalFormat; import java.text.DecimalFormat;
import java.util.*; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -121,7 +120,7 @@ public class CommonApiController extends BladeController {
@GetMapping("get-car-speed") @GetMapping("get-car-speed")
public R getCarSpeed(@RequestParam String carNo) { public R getCarSpeed(@RequestParam String carNo) {
CarInfoVO info = carInfoService.getCarInfo(carNo); CarInfoVO info = carInfoService.getCarInfo(carNo);
carInfoTask.getCarSpeed(carNo);
if (Func.isEmpty(info)) { if (Func.isEmpty(info)) {
return R.fail("未获取到车辆信息, 请检查车是否已掉线"); return R.fail("未获取到车辆信息, 请检查车是否已掉线");
} }
@ -438,7 +437,8 @@ public class CommonApiController extends BladeController {
resultMap.put("scenicData", busLine.getScenic()); resultMap.put("scenicData", busLine.getScenic());
resultMap.put("speed",info.getSpeed()); resultMap.put("speed",info.getSpeed());
List<BusLine> busLineList = stationHintService.getBusLineByName(nextSite.getSname()); List<BusLine> busLineList = stationHintService.getBusLineByName(nextSite.getSname());
List<imgVo> imgList = proBusLineImgService.getImgByid(busLineList.get(0).getId()); Long busLineId = busLineList.get(0).getId();
List<imgVo> imgList = proBusLineImgService.getImgByid(busLineId);
redisTemplate.opsForValue().set("imgList-info", imgList); redisTemplate.opsForValue().set("imgList-info", imgList);
resultMap.put("imgData", imgList); resultMap.put("imgData", imgList);
} }

@ -1,6 +1,7 @@
package org.springblade.modules.business.service; package org.springblade.modules.business.service;
import org.springblade.modules.business.vo.CarInfoVO; import org.springblade.modules.business.vo.CarInfoVO;
import org.springblade.modules.business.vo.DeviceVo;
import java.util.List; import java.util.List;
@ -20,4 +21,6 @@ public interface ICarInfoService {
CarInfoVO getCarInfo(String carNo); CarInfoVO getCarInfo(String carNo);
List<CarInfoVO> getAllCarInfo(); List<CarInfoVO> getAllCarInfo();
DeviceVo currentPush(String carNo);
} }

@ -5,9 +5,9 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springblade.common.utils.HttpClientUtils; import org.springblade.common.utils.HttpClientUtils;
import org.springblade.core.tool.utils.BeanUtil; import org.springblade.core.tool.utils.BeanUtil;
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.vo.CarInfoVO; import org.springblade.modules.business.vo.CarInfoVO;
import org.springblade.modules.business.vo.DeviceVo;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.ArrayList; import java.util.ArrayList;
@ -56,4 +56,24 @@ public class CarInfoServiceImpl implements ICarInfoService {
return carInfoList; return carInfoList;
} }
@Override
public DeviceVo currentPush(String carNo) {
DeviceVo vo = null;
String url = "http://42.192.165.208:8000/device/currentPush";
String res = HttpClientUtils.doGet(url);
JSONObject json = JSON.parseObject(res);
JSONArray deviceInfoList = json.getJSONArray("currentPush");
for (Object o : deviceInfoList) {
JSONObject deviceInfo = (JSONObject) o;
if (carNo.equals(deviceInfo.getString("currentPushno"))) {
vo = BeanUtil.copy(deviceInfo, DeviceVo.class);
}
}
return vo;
}
} }

@ -1,5 +1,6 @@
package org.springblade.modules.business.service.impl; package org.springblade.modules.business.service.impl;
import com.alibaba.fastjson.JSON;
import org.springblade.core.tool.utils.Func; import org.springblade.core.tool.utils.Func;
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;
@ -7,6 +8,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
/** /**
@ -49,7 +51,11 @@ public class PublishService {
WebSocketMessage message = new WebSocketMessage(); WebSocketMessage message = new WebSocketMessage();
message.setTitle(CURRENT_FACILITY_STAT); message.setTitle(CURRENT_FACILITY_STAT);
message.setCode(200); message.setCode(200);
message.setContent("设备信息:"+currentFacility); HashMap<String, Object> map = new HashMap<>();
map.put("msgType", CURRENT_FACILITY_STAT);
map.put("data", currentFacility);
String messageJson = JSON.toJSONString(map);
message.setContent(messageJson);
websocketService.broadcast(message); websocketService.broadcast(message);
// 3. 查看websocket的返回结果 // 3. 查看websocket的返回结果
String result = (String) redisTemplate.opsForValue().get(CURRENT_FACILITY_RETURN); String result = (String) redisTemplate.opsForValue().get(CURRENT_FACILITY_RETURN);

@ -0,0 +1,13 @@
package org.springblade.modules.business.vo;
import lombok.Data;
/**
* @Author: Chents
* @Create: 2023-05-11
*/
@Data
public class DeviceVo {
private String pushStatus;
private String deviceId;
}

@ -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());
}
} }

@ -1,6 +1,11 @@
package org.springblade.modules.websocket.vo; package org.springblade.modules.websocket.vo;
import lombok.Data; import lombok.Data;
import org.apache.poi.ss.formula.functions.T;
import org.json.JSONObject;
import java.util.List;
import java.util.Map;
/** /**
* @Author: Chents * @Author: Chents
@ -16,5 +21,5 @@ public class WebSocketMessage {
private int code; private int code;
//返回对象 //返回对象
private Object content; private String content;
} }

@ -23,6 +23,6 @@ public interface IProBusLineImgService {
R queryList(Long id); R queryList(Long id);
List<imgVo> getImgByid(Long id); List<imgVo> getImgByid(Long busLineId);
} }

@ -70,17 +70,17 @@ public class ProBusLineImgImpl implements IProBusLineImgService {
@Override @Override
public List<imgVo> getImgByid(Long id) { public List<imgVo> getImgByid(Long busLineId) {
QueryWrapper<PocBusLineImg> queryWrapper = new QueryWrapper<>(); QueryWrapper<PocBusLineImg> queryWrapper = new QueryWrapper<>();
queryWrapper.select("img_url","img_type"); queryWrapper.select("img_url","img_type");
queryWrapper.eq("bus_line_id",id); queryWrapper.eq("bus_line_id",busLineId);
queryWrapper.isNotNull("img_url");
List<PocBusLineImg> pocBusLineImgs = pocBusLineImgMapper.selectList(queryWrapper); List<PocBusLineImg> pocBusLineImgs = pocBusLineImgMapper.selectList(queryWrapper);
ArrayList<imgVo> imgList = new ArrayList<>(); ArrayList<imgVo> imgList = new ArrayList<>();
for(PocBusLineImg pocBusLineImg : pocBusLineImgs){ for(PocBusLineImg pocBusLineImg : pocBusLineImgs){
imgVo img = new imgVo(); imgVo img = new imgVo();
img.setImgUrl(pocBusLineImg.getImgUrl()); img.setImgUrl(pocBusLineImg.getImgUrl());
img.setImgType(pocBusLineImg.getImgType()); img.setImgType(pocBusLineImg.getImgType());
img.setBusLineId(pocBusLineImg.getBusLineId());
imgList.add(img); imgList.add(img);
} }
return imgList; return imgList;

Loading…
Cancel
Save