添加推送景点信息

master
chents 3 years ago
parent 53f71307e2
commit 816e1f81e6
  1. 54
      src/main/java/org/springblade/modules/business/controller/CommonApiController.java

@ -335,6 +335,59 @@ public class CommonApiController extends BladeController {
Double.parseDouble(carInfo.getJingdu()), Double.parseDouble(carInfo.getWeidu()));
}
double runPercent = (pass + unpass) > 0 ? (pass / (pass + unpass)) * 100 : 0;
BusLine busLine = BusLineCache.getBusLine(carInfo.getUpordown(), downStation.getSname(), downStation.getWeizhi());
Map<String, Object> resultMap = new HashMap<>();
resultMap.put("catInfo", redisTemplate.opsForValue().get("car-current-Info" + carNo));
if (Func.isEmpty(busLine)) {
resultMap.put("siteTips", "");
resultMap.put("articleData", "");
resultMap.put("activityData", "");
resultMap.put("scenicData", "");
resultMap.put("imgData", "");
} else {
resultMap.put("siteTips", busLine.getTips());
resultMap.put("articleData", busLine.getActicle());
resultMap.put("activityData", busLine.getActivity());
resultMap.put("scenicData", busLine.getScenic());
// redis缓存控制显示景区图片还是地图图片, 每10s切换一次, 若无景区图片, 显示地图图片
if (Func.isBlank(busLine.getImgScenic())) {
resultMap.put("imgData", busLine.getImgMap());
} else {
// 图片类型 1: 地图, 2:景点
Integer imgType = (Integer) redisTemplate.opsForValue().get("site-img-type");
if (Func.isEmpty(imgType)) {
imgType = 2;
redisTemplate.opsForValue().set("site-img-type", imgType, 30, TimeUnit.SECONDS);
}
// 上一次放入地图的时间
Long prePutImgTime = (Long) redisTemplate.opsForValue().get("site-img-time");
if (Func.isEmpty(prePutImgTime)) {
prePutImgTime = System.currentTimeMillis();
redisTemplate.opsForValue().set("site-img-time", prePutImgTime, 30, TimeUnit.DAYS);
}
// 若距离上一次更新图片<10s, 不修改放入的地图类型
if (System.currentTimeMillis() - prePutImgTime < 10000) {
if (1 == imgType) {
resultMap.put("imgData", busLine.getImgMap());
} else {
resultMap.put("imgData", busLine.getImgScenic());
}
} else {
// 否则, 修改返回的图片类型, 并更新缓存
if (1 == imgType) {
imgType = 2;
resultMap.put("imgData", busLine.getImgScenic());
} else {
imgType = 1;
resultMap.put("imgData", busLine.getImgMap());
}
redisTemplate.opsForValue().set("site-img-type", imgType, 30, TimeUnit.SECONDS);
}
}
}
//组装返回对象
CurrentCarInfoVo currentCarInfoVo = new CurrentCarInfoVo();
currentCarInfoVo.setBusno(carInfo.getBusno());
@ -344,6 +397,7 @@ public class CommonApiController extends BladeController {
currentCarInfoVo.setUpStation(upStation.getSname());
currentCarInfoVo.setDownStation(downStation.getSname());
currentCarInfoVo.setPercentage(runPercent);
currentCarInfoVo.setInfoMap(resultMap);
//定时任务缓存
carInfoTask.setCarInfo(currentCarInfoVo);
return R.data(currentCarInfoVo);

Loading…
Cancel
Save