diff --git a/README.md b/README.md index 71008d1..ef0db2c 100644 --- a/README.md +++ b/README.md @@ -1 +1 @@ -### 体检预约项目 \ No newline at end of file +### 慢直播项目 \ No newline at end of file diff --git a/src/main/java/org/springblade/modules/business/controller/CommonApiController.java b/src/main/java/org/springblade/modules/business/controller/CommonApiController.java index f057a67..831636c 100644 --- a/src/main/java/org/springblade/modules/business/controller/CommonApiController.java +++ b/src/main/java/org/springblade/modules/business/controller/CommonApiController.java @@ -1,5 +1,6 @@ package org.springblade.modules.business.controller; +import com.baomidou.mybatisplus.core.toolkit.Wrappers; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import lombok.RequiredArgsConstructor; @@ -15,6 +16,8 @@ import org.springblade.core.tenant.annotation.TenantDS; import org.springblade.core.tool.api.R; import org.springblade.core.tool.utils.Func; import org.springblade.modules.business.entity.BusLine; +import org.springblade.modules.business.entity.CarAdmin; +import org.springblade.modules.business.service.ICarAdminService; import org.springblade.modules.business.service.ICarInfoService; import org.springblade.modules.business.service.IStationHintService; import org.springblade.modules.business.service.impl.PublishService; @@ -49,403 +52,420 @@ import java.util.concurrent.TimeUnit; @Api(value = "公共接口", tags = "公共接口") public class CommonApiController extends BladeController { - private final ICarInfoService carInfoService; - - private final RedisTemplate redisTemplate; - - private final PublishService publishService; - - private final CarInfoTask carInfoTask; - - private final IStationHintService stationHintService; - - - private final IProBusLineImgService proBusLineImgService; - - - /** - * 设置车牌号 - * - * @return - */ - @GetMapping("set-car-stat") - public R setCarStat(@RequestParam String carNo, @RequestParam String carStat) { - redisTemplate.opsForValue().set("set-current-Facility-stat" + carNo, carStat); - publishService.publishToWeb(carNo, carStat); - return R.status(true); - } - - /** - * 设置车牌号 - * - * @return - */ - @GetMapping("set-car-stat-v2") - public R setCarStatV2(@RequestParam String carNo, @RequestParam String carStat) { - redisTemplate.opsForValue().set("car-current-stat" + carNo, carStat); - return R.status(true); - } - - /** - * 设置车牌号 - * - * @return - */ - @GetMapping("set-car-no") - public R setCarNo(String carNo) { - redisTemplate.opsForValue().set("car-current-number", carNo); - return R.status(true); - } - - /** - * 获取车牌号 - * @return - */ - @GetMapping("get-car-no") - public R getCarNo() { - String carNo = (String) redisTemplate.opsForValue().get("car-current-number"); - if (Func.isBlank(carNo)) { - carNo = "鲁F08953D"; - } - - return R.data(carNo); - } - - /** - * 获取车速 - * - * @param carNo 车牌号 - * @return - */ - @GetMapping("get-car-speed") - public R getCarSpeed(@RequestParam String carNo) { - CarInfoVO info = carInfoService.getCarInfo(carNo); - carInfoTask.getCarSpeed(carNo); - if (Func.isEmpty(info)) { - return R.fail("未获取到车辆信息, 请检查车是否已掉线"); - } - - return R.data(info.getSpeed()); - } - - /** - * 获取早晚高峰时间 - * - * @return - */ - @GetMapping("get-rush-hour") - public R getRushHour() { - List> rushHourList = new ArrayList<>(); - Map morning = new ArrayMap<>(); - morning.put("name", "早高峰"); - morning.put("starttime", "7:30"); - morning.put("endtime", "8:30"); - rushHourList.add(morning); - - Map evening = new ArrayMap<>(); - evening.put("name", "晚高峰"); - evening.put("starttime", "17:30"); - evening.put("endtime", "18:30"); - rushHourList.add(evening); - - return R.data(rushHourList); - } - - /** - * 获取站点列表 - */ - @GetMapping("/get-site") - public R getSiteList(@RequestParam String carNo) { - CarInfoVO info = carInfoService.getCarInfo(carNo); - if (Func.isEmpty(info)) { - return R.fail("未获取到车辆信息, 请检查车是否已掉线"); - } - List siteList = SiteListCache.getSiteList(info.getLinename(), info.getUpordown()); - int nextSiteIdx = Integer.parseInt(info.getInorder()); - if (BusinessConstant.CAR_STAT_IN.toString().equals(info.getNowstate())) { - nextSiteIdx -= 1; - } - - // 下一站 - List> snameList = new ArrayList<>(); - SiteInfoVO nextSite = nextSiteIdx < siteList.size() ? siteList.get(nextSiteIdx) : null; - SiteInfoVO nextSite2 = (nextSiteIdx + 1) < siteList.size() ? siteList.get((nextSiteIdx) + 1) : null; - SiteInfoVO nextSite3 = (nextSiteIdx + 2) < siteList.size() ? siteList.get(nextSiteIdx + 2) : null; - // 上一站 - SiteInfoVO preSite = nextSiteIdx - 1 > 0 ? siteList.get(nextSiteIdx - 1) : null; - // 上两站 - SiteInfoVO preTwoSite = nextSiteIdx - 2 > 0 ? siteList.get(nextSiteIdx - 2) : null; - // 上三站 - SiteInfoVO preThreeSite = nextSiteIdx - 3 > 0 ? siteList.get(nextSiteIdx - 3) : null; - - Map siteMsgMap; - if (Func.isNotEmpty(preThreeSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", preThreeSite.getSname()); - siteMsgMap.put("type", "before"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(preTwoSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", preTwoSite.getSname()); - siteMsgMap.put("type", "before"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(preSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", preSite.getSname()); - siteMsgMap.put("type", "before"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(nextSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", nextSite.getSname()); - siteMsgMap.put("type", "after"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(nextSite2)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", nextSite2.getSname()); - siteMsgMap.put("type", "after"); - snameList.add(siteMsgMap); - } + private final ICarInfoService carInfoService; + + private final RedisTemplate redisTemplate; + + private final PublishService publishService; + + private final CarInfoTask carInfoTask; + + private final IStationHintService stationHintService; + + private final IProBusLineImgService proBusLineImgService; + + private final ICarAdminService carAdminService; + + /** + * 设置车牌号 + * + * @return + */ + @GetMapping("set-push-car-and-stat") + public R setPushCarAndStat(@RequestParam String clientId, @RequestParam String carStat) { + CarAdmin carAdmin = carAdminService.getOne(Wrappers.lambdaQuery().eq(CarAdmin::getReceiverId, clientId)); + String carNo = Func.isEmpty(carAdmin) ? "" : carAdmin.getName(); + + redisTemplate.opsForValue().set("car-current-number", carNo); + redisTemplate.opsForValue().set("set-current-Facility-stat" + carNo, carStat); + publishService.publishToWeb(carNo, carStat); + return R.status(true); + } + + /** + * 设置车牌号 + * + * @return + */ + @GetMapping("set-car-stat") + public R setCarStat(@RequestParam String carNo, @RequestParam String carStat) { + redisTemplate.opsForValue().set("set-current-Facility-stat" + carNo, carStat); + publishService.publishToWeb(carNo, carStat); + return R.status(true); + } + + /** + * 设置车牌号 + * + * @return + */ + @GetMapping("set-car-stat-v2") + public R setCarStatV2(@RequestParam String carNo, @RequestParam String carStat) { + redisTemplate.opsForValue().set("car-current-stat" + carNo, carStat); + return R.status(true); + } + + /** + * 设置车牌号 + * + * @return + */ + @GetMapping("set-car-no") + public R setCarNo(String carNo) { + redisTemplate.opsForValue().set("car-current-number", carNo); + return R.status(true); + } + + /** + * 获取车牌号 + * + * @return + */ + @GetMapping("get-car-no") + public R getCarNo() { + String carNo = (String) redisTemplate.opsForValue().get("car-current-number"); + if (Func.isBlank(carNo)) { + carNo = "鲁F08953D"; + } + + return R.data(carNo); + } + + /** + * 获取车速 + * + * @param carNo 车牌号 + * @return + */ + @GetMapping("get-car-speed") + public R getCarSpeed(@RequestParam String carNo) { + CarInfoVO info = carInfoService.getCarInfo(carNo); + carInfoTask.getCarSpeed(carNo); + if (Func.isEmpty(info)) { + return R.fail("未获取到车辆信息, 请检查车是否已掉线"); + } + + return R.data(info.getSpeed()); + } + + /** + * 获取早晚高峰时间 + * + * @return + */ + @GetMapping("get-rush-hour") + public R getRushHour() { + List> rushHourList = new ArrayList<>(); + Map morning = new ArrayMap<>(); + morning.put("name", "早高峰"); + morning.put("starttime", "7:30"); + morning.put("endtime", "8:30"); + rushHourList.add(morning); + + Map evening = new ArrayMap<>(); + evening.put("name", "晚高峰"); + evening.put("starttime", "17:30"); + evening.put("endtime", "18:30"); + rushHourList.add(evening); + + return R.data(rushHourList); + } + + /** + * 获取站点列表 + */ + @GetMapping("/get-site") + public R getSiteList(@RequestParam String carNo) { + CarInfoVO info = carInfoService.getCarInfo(carNo); + if (Func.isEmpty(info)) { + return R.fail("未获取到车辆信息, 请检查车是否已掉线"); + } + List siteList = SiteListCache.getSiteList(info.getLinename(), info.getUpordown()); + int nextSiteIdx = Integer.parseInt(info.getInorder()); + if (BusinessConstant.CAR_STAT_IN.toString().equals(info.getNowstate())) { + nextSiteIdx -= 1; + } + + // 下一站 + List> snameList = new ArrayList<>(); + SiteInfoVO nextSite = nextSiteIdx < siteList.size() ? siteList.get(nextSiteIdx) : null; + SiteInfoVO nextSite2 = (nextSiteIdx + 1) < siteList.size() ? siteList.get((nextSiteIdx) + 1) : null; + SiteInfoVO nextSite3 = (nextSiteIdx + 2) < siteList.size() ? siteList.get(nextSiteIdx + 2) : null; + // 上一站 + SiteInfoVO preSite = nextSiteIdx - 1 > 0 ? siteList.get(nextSiteIdx - 1) : null; + // 上两站 + SiteInfoVO preTwoSite = nextSiteIdx - 2 > 0 ? siteList.get(nextSiteIdx - 2) : null; + // 上三站 + SiteInfoVO preThreeSite = nextSiteIdx - 3 > 0 ? siteList.get(nextSiteIdx - 3) : null; + + Map siteMsgMap; + if (Func.isNotEmpty(preThreeSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", preThreeSite.getSname()); + siteMsgMap.put("type", "before"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(preTwoSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", preTwoSite.getSname()); + siteMsgMap.put("type", "before"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(preSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", preSite.getSname()); + siteMsgMap.put("type", "before"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(nextSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", nextSite.getSname()); + siteMsgMap.put("type", "after"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(nextSite2)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", nextSite2.getSname()); + siteMsgMap.put("type", "after"); + snameList.add(siteMsgMap); + } // if (Func.isNotEmpty(nextSite3)) { // snameList.add(nextSite3.getSname()); // } - // 计算当前车辆与前一站和后一站的距离 - double pass = 0; - if (Func.isNotEmpty(preSite)) { - pass = CommonUtil.calculateDistance(Double.parseDouble(preSite.getJingdu()), Double.parseDouble(preSite.getWeidu()), - Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); - } - double unpass = 0; - if (Func.isNotEmpty(nextSite)) { - unpass = CommonUtil.calculateDistance(Double.parseDouble(nextSite.getJingdu()), Double.parseDouble(nextSite.getWeidu()), - Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); - } - double runPercent = (pass + unpass) > 0 ? (pass / (pass + unpass)) * 100 : 0; - DecimalFormat df1 = new DecimalFormat("#"); - - // 先从缓存中获取上一次的运行百分比, 然后将本次的运行百分比更新到缓存中 - String runPercentStr = df1.format(runPercent > 100 ? 100 : runPercent); - String prePercentStr = (String) redisTemplate.opsForValue().get("car-run-percent"); - - log.error("____________________________________________"); - log.error("runPercentStr : " + runPercentStr); - log.error("prePercentStr : " + prePercentStr); - log.error("CarInfoVO: " + info.toString()); - - prePercentStr = Func.isBlank(prePercentStr) ? "0" : prePercentStr; - redisTemplate.opsForValue().set("car-run-percent", runPercentStr, 30, TimeUnit.SECONDS); - - Map siteMap = new HashMap<>(); - siteMap.put("startSite", siteList.get(0).getSname()); - siteMap.put("endSite", siteList.get(siteList.size() - 1).getSname()); - siteMap.put("siteList", snameList); - siteMap.put("prePercent", prePercentStr); - siteMap.put("runPercent", runPercentStr); - - if (Func.isEmpty(nextSite)) { - nextSite = preSite; - } - BusLine busLine = BusLineCache.getBusLine(info.getUpordown(), nextSite.getSname(), nextSite.getWeizhi()); - // 组织返回数据 - Map resultMap = new HashMap<>(); - resultMap.put("siteData", siteMap); - resultMap.put("catStat", redisTemplate.opsForValue().get("car-current-stat" + 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()); - 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); - } - } - } - - - return R.data(resultMap); - } - - /** - * 获取所有实时的车辆信息 - * - * @return - */ - @ApiOperation(value = "获取所有实时的车辆信息", notes = "传入id和busLine") - @GetMapping("/get-all-car-info") - public R getAllCarInfo() { - return R.data(carInfoService.getAllCarInfo()); - } - - - /** - * 获取实时车辆站点信息 - */ - @GetMapping("/get-current-info") - public R getCurrentInfo(@RequestParam String carNo) { - CarInfoVO info = carInfoService.getCarInfo(carNo); - if (Func.isEmpty(info)) { - return R.fail("未获取到车辆信息, 请检查车是否已掉线"); - } - List siteList = SiteListCache.getSiteList(info.getLinename(), info.getUpordown()); - int nextSiteIdx = Integer.parseInt(info.getInorder()); - if (BusinessConstant.CAR_STAT_IN.toString().equals(info.getNowstate())) { - nextSiteIdx -= 1; - } - - // 下一站 - List> snameList = new ArrayList<>(); - SiteInfoVO nextSite = nextSiteIdx < siteList.size() ? siteList.get(nextSiteIdx) : null; - SiteInfoVO nextSite2 = (nextSiteIdx + 1) < siteList.size() ? siteList.get((nextSiteIdx) + 1) : null; - SiteInfoVO nextSite3 = (nextSiteIdx + 2) < siteList.size() ? siteList.get(nextSiteIdx + 2) : null; - // 上一站 - SiteInfoVO preSite = nextSiteIdx - 1 > 0 ? siteList.get(nextSiteIdx - 1) : null; - // 上两站 - SiteInfoVO preTwoSite = nextSiteIdx - 2 > 0 ? siteList.get(nextSiteIdx - 2) : null; - // 上三站 - SiteInfoVO preThreeSite = nextSiteIdx - 3 > 0 ? siteList.get(nextSiteIdx - 3) : null; - - Map siteMsgMap; - if (Func.isNotEmpty(preThreeSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", preThreeSite.getSname()); - siteMsgMap.put("type", "before"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(preTwoSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", preTwoSite.getSname()); - siteMsgMap.put("type", "before"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(preSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", preSite.getSname()); - siteMsgMap.put("type", "before"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(nextSite)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", nextSite.getSname()); - siteMsgMap.put("type", "after"); - snameList.add(siteMsgMap); - } - if (Func.isNotEmpty(nextSite2)) { - siteMsgMap = new HashMap<>(); - siteMsgMap.put("siteName", nextSite2.getSname()); - siteMsgMap.put("type", "after"); - snameList.add(siteMsgMap); - } + // 计算当前车辆与前一站和后一站的距离 + double pass = 0; + if (Func.isNotEmpty(preSite)) { + pass = CommonUtil.calculateDistance(Double.parseDouble(preSite.getJingdu()), Double.parseDouble(preSite.getWeidu()), + Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); + } + double unpass = 0; + if (Func.isNotEmpty(nextSite)) { + unpass = CommonUtil.calculateDistance(Double.parseDouble(nextSite.getJingdu()), Double.parseDouble(nextSite.getWeidu()), + Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); + } + double runPercent = (pass + unpass) > 0 ? (pass / (pass + unpass)) * 100 : 0; + DecimalFormat df1 = new DecimalFormat("#"); + + // 先从缓存中获取上一次的运行百分比, 然后将本次的运行百分比更新到缓存中 + String runPercentStr = df1.format(runPercent > 100 ? 100 : runPercent); + String prePercentStr = (String) redisTemplate.opsForValue().get("car-run-percent"); + + log.error("____________________________________________"); + log.error("runPercentStr : " + runPercentStr); + log.error("prePercentStr : " + prePercentStr); + log.error("CarInfoVO: " + info.toString()); + + prePercentStr = Func.isBlank(prePercentStr) ? "0" : prePercentStr; + redisTemplate.opsForValue().set("car-run-percent", runPercentStr, 30, TimeUnit.SECONDS); + + Map siteMap = new HashMap<>(); + siteMap.put("startSite", siteList.get(0).getSname()); + siteMap.put("endSite", siteList.get(siteList.size() - 1).getSname()); + siteMap.put("siteList", snameList); + siteMap.put("prePercent", prePercentStr); + siteMap.put("runPercent", runPercentStr); + + if (Func.isEmpty(nextSite)) { + nextSite = preSite; + } + BusLine busLine = BusLineCache.getBusLine(info.getUpordown(), nextSite.getSname(), nextSite.getWeizhi()); + // 组织返回数据 + Map resultMap = new HashMap<>(); + resultMap.put("siteData", siteMap); + resultMap.put("catStat", redisTemplate.opsForValue().get("car-current-stat" + 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()); + 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); + } + } + } + + + return R.data(resultMap); + } + + /** + * 获取所有实时的车辆信息 + * + * @return + */ + @ApiOperation(value = "获取所有实时的车辆信息", notes = "传入id和busLine") + @GetMapping("/get-all-car-info") + public R getAllCarInfo() { + return R.data(carInfoService.getAllCarInfo()); + } + + + /** + * 获取实时车辆站点信息 + */ + @GetMapping("/get-current-info") + public R getCurrentInfo(@RequestParam String carNo) { + CarInfoVO info = carInfoService.getCarInfo(carNo); + if (Func.isEmpty(info)) { + return R.fail("未获取到车辆信息, 请检查车是否已掉线"); + } + List siteList = SiteListCache.getSiteList(info.getLinename(), info.getUpordown()); + int nextSiteIdx = Integer.parseInt(info.getInorder()); + if (BusinessConstant.CAR_STAT_IN.toString().equals(info.getNowstate())) { + nextSiteIdx -= 1; + } + + // 下一站 + List> snameList = new ArrayList<>(); + SiteInfoVO nextSite = nextSiteIdx < siteList.size() ? siteList.get(nextSiteIdx) : null; + SiteInfoVO nextSite2 = (nextSiteIdx + 1) < siteList.size() ? siteList.get((nextSiteIdx) + 1) : null; + SiteInfoVO nextSite3 = (nextSiteIdx + 2) < siteList.size() ? siteList.get(nextSiteIdx + 2) : null; + // 上一站 + SiteInfoVO preSite = nextSiteIdx - 1 > 0 ? siteList.get(nextSiteIdx - 1) : null; + // 上两站 + SiteInfoVO preTwoSite = nextSiteIdx - 2 > 0 ? siteList.get(nextSiteIdx - 2) : null; + // 上三站 + SiteInfoVO preThreeSite = nextSiteIdx - 3 > 0 ? siteList.get(nextSiteIdx - 3) : null; + + Map siteMsgMap; + if (Func.isNotEmpty(preThreeSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", preThreeSite.getSname()); + siteMsgMap.put("type", "before"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(preTwoSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", preTwoSite.getSname()); + siteMsgMap.put("type", "before"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(preSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", preSite.getSname()); + siteMsgMap.put("type", "before"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(nextSite)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", nextSite.getSname()); + siteMsgMap.put("type", "after"); + snameList.add(siteMsgMap); + } + if (Func.isNotEmpty(nextSite2)) { + siteMsgMap = new HashMap<>(); + siteMsgMap.put("siteName", nextSite2.getSname()); + siteMsgMap.put("type", "after"); + snameList.add(siteMsgMap); + } // if (Func.isNotEmpty(nextSite3)) { // snameList.add(nextSite3.getSname()); // } - // 计算当前车辆与前一站和后一站的距离 - double pass = 0; - if (Func.isNotEmpty(preSite)) { - pass = CommonUtil.calculateDistance(Double.parseDouble(preSite.getJingdu()), Double.parseDouble(preSite.getWeidu()), - Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); - } - double unpass = 0; - if (Func.isNotEmpty(nextSite)) { - unpass = CommonUtil.calculateDistance(Double.parseDouble(nextSite.getJingdu()), Double.parseDouble(nextSite.getWeidu()), - Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); - } - double runPercent = (pass + unpass) > 0 ? (pass / (pass + unpass)) * 100 : 0; - DecimalFormat df1 = new DecimalFormat("#"); - - // 先从缓存中获取上一次的运行百分比, 然后将本次的运行百分比更新到缓存中 - String runPercentStr = df1.format(runPercent > 100 ? 100 : runPercent); - String prePercentStr = (String) redisTemplate.opsForValue().get("car-run-percent-info"); - - log.error("____________________________________________"); - log.error("runPercentStr : " + runPercentStr); - log.error("prePercentStr : " + prePercentStr); - log.error("CarInfoVO: " + info.toString()); - - prePercentStr = Func.isBlank(prePercentStr) ? "0" : prePercentStr; - redisTemplate.opsForValue().set("car-run-percent-info", runPercentStr, 30, TimeUnit.SECONDS); - - Map siteMap = new HashMap<>(); - siteMap.put("startSite", siteList.get(0).getSname()); - siteMap.put("endSite", siteList.get(siteList.size() - 1).getSname()); - siteMap.put("siteList", snameList); - siteMap.put("prePercent", prePercentStr); - siteMap.put("runPercent", runPercentStr); - - if (Func.isEmpty(nextSite)) { - nextSite = preSite; - } - BusLine busLine = BusLineCache.getBusLine(info.getUpordown(), nextSite.getSname(), nextSite.getWeizhi()); - // 组织返回数据 - Map resultMap = new HashMap<>(); - resultMap.put("siteData", siteMap); - resultMap.put("catStat", redisTemplate.opsForValue().get("car-current-stat-info" + carNo)); - if (Func.isEmpty(busLine)) { - resultMap.put("siteTips", ""); - resultMap.put("articleData", ""); - resultMap.put("activityData", ""); - resultMap.put("scenicData", ""); - resultMap.put("imgData", ""); - resultMap.put("speed", ""); - } else { - resultMap.put("siteTips", busLine.getTips()); - resultMap.put("articleData", busLine.getActicle()); - resultMap.put("activityData", busLine.getActivity()); - resultMap.put("scenicData", busLine.getScenic()); - resultMap.put("speed",info.getSpeed()); - List busLineList = stationHintService.getBusLineByName(nextSite.getSname()); - Long busLineId = busLineList.get(0).getId(); - List imgList = proBusLineImgService.getImgByid(busLineId); - redisTemplate.opsForValue().set("imgList-info", imgList); - resultMap.put("imgData", imgList); - } - //定时任务缓存 - carInfoTask.setCarInfo(resultMap); - return R.data(resultMap); - } + // 计算当前车辆与前一站和后一站的距离 + double pass = 0; + if (Func.isNotEmpty(preSite)) { + pass = CommonUtil.calculateDistance(Double.parseDouble(preSite.getJingdu()), Double.parseDouble(preSite.getWeidu()), + Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); + } + double unpass = 0; + if (Func.isNotEmpty(nextSite)) { + unpass = CommonUtil.calculateDistance(Double.parseDouble(nextSite.getJingdu()), Double.parseDouble(nextSite.getWeidu()), + Double.parseDouble(info.getJingdu()), Double.parseDouble(info.getWeidu())); + } + double runPercent = (pass + unpass) > 0 ? (pass / (pass + unpass)) * 100 : 0; + DecimalFormat df1 = new DecimalFormat("#"); + + // 先从缓存中获取上一次的运行百分比, 然后将本次的运行百分比更新到缓存中 + String runPercentStr = df1.format(runPercent > 100 ? 100 : runPercent); + String prePercentStr = (String) redisTemplate.opsForValue().get("car-run-percent-info"); + + log.error("____________________________________________"); + log.error("runPercentStr : " + runPercentStr); + log.error("prePercentStr : " + prePercentStr); + log.error("CarInfoVO: " + info.toString()); + + prePercentStr = Func.isBlank(prePercentStr) ? "0" : prePercentStr; + redisTemplate.opsForValue().set("car-run-percent-info", runPercentStr, 30, TimeUnit.SECONDS); + + Map siteMap = new HashMap<>(); + siteMap.put("startSite", siteList.get(0).getSname()); + siteMap.put("endSite", siteList.get(siteList.size() - 1).getSname()); + siteMap.put("siteList", snameList); + siteMap.put("prePercent", prePercentStr); + siteMap.put("runPercent", runPercentStr); + + if (Func.isEmpty(nextSite)) { + nextSite = preSite; + } + BusLine busLine = BusLineCache.getBusLine(info.getUpordown(), nextSite.getSname(), nextSite.getWeizhi()); + // 组织返回数据 + Map resultMap = new HashMap<>(); + resultMap.put("siteData", siteMap); + resultMap.put("catStat", redisTemplate.opsForValue().get("car-current-stat-info" + carNo)); + if (Func.isEmpty(busLine)) { + resultMap.put("siteTips", ""); + resultMap.put("articleData", ""); + resultMap.put("activityData", ""); + resultMap.put("scenicData", ""); + resultMap.put("imgData", ""); + resultMap.put("speed", ""); + } else { + resultMap.put("siteTips", busLine.getTips()); + resultMap.put("articleData", busLine.getActicle()); + resultMap.put("activityData", busLine.getActivity()); + resultMap.put("scenicData", busLine.getScenic()); + resultMap.put("speed", info.getSpeed()); + List busLineList = stationHintService.getBusLineByName(nextSite.getSname()); + Long busLineId = busLineList.get(0).getId(); + List imgList = proBusLineImgService.getImgByid(busLineId); + redisTemplate.opsForValue().set("imgList-info", imgList); + resultMap.put("imgData", imgList); + } + //定时任务缓存 + carInfoTask.setCarInfo(resultMap); + return R.data(resultMap); + } }