From e0ce16d8205c3bde0e4862d1d1b3524d6b16a4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E5=AE=87=E8=88=AA?= <653809315@qq.com> Date: Thu, 27 Aug 2026 16:20:08 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BA=BF=E8=B7=AF=E5=AE=A2=E6=B5=81=EF=BC=8C?= =?UTF-8?q?=E5=8D=95=E7=AB=99=E5=AE=A2=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ysdp/controller/TrafficApiController.java | 235 +++++++++++++++++- .../modules/ysdp/mapper/YsYunyingMapper.java | 33 +++ .../ysdp/mapper/xml/YsYunyingMapper.xml | 72 ++++++ .../ysdp/service/YsYunyingService.java | 29 +++ .../ysdp/service/dto/YsYunyingDTO.java | 11 + .../juntech/modules/ysdp/utils/Constant.java | 20 ++ 6 files changed, 396 insertions(+), 4 deletions(-) diff --git a/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/controller/TrafficApiController.java b/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/controller/TrafficApiController.java index b3c2124..b27bfbb 100644 --- a/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/controller/TrafficApiController.java +++ b/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/controller/TrafficApiController.java @@ -5,9 +5,12 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import com.jeeplus.aop.logging.annotation.ApiLog; import net.juntech.modules.ysdp.domain.YsOperateManager; +import net.juntech.modules.ysdp.domain.YsYunyingMax; import net.juntech.modules.ysdp.service.YsOperateManagerService; +import net.juntech.modules.ysdp.service.YsYunyingMaxService; import net.juntech.modules.ysdp.service.YsYunyingService; import net.juntech.modules.ysdp.service.dto.YsYunyingDTO; +import net.juntech.modules.ysdp.service.dto.YsYunyingMaxDTO; import net.juntech.modules.ysdp.utils.Constant; import net.juntech.modules.ysdp.utils.JSONUtil; import net.sf.json.JSONArray; @@ -19,7 +22,10 @@ import jakarta.servlet.http.HttpServletRequest; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Arrays; +import java.util.Collections; import java.util.List; +import java.util.Optional; @Tag(name = "客运页面API接口") @@ -33,6 +39,20 @@ public class TrafficApiController extends BaseApiController { @Autowired private YsOperateManagerService ysOperateManagerService; + @Autowired + private YsYunyingMaxService ysYunyingMaxService; + + /** + * 客运页面重点关注的线路列表 + */ + private static final List TARGET_LINES = Arrays.asList("03", "04", "07", "15"); + + private static final String[] LINE_YUNYING_EXCLUDE_FIELDS = new String[]{ + "id", "remarks", "createBy", "createDate", "updateBy", "updateDate", + "delFlag", "tenantId", "createTime", "createById", "updateTime", + "updateById", "updateByIdId", "createByIdId", "lineId", "tenantDTO" + }; + private static final String[] STATION_RANK_EXCLUDE_FIELDS = new String[]{ "id", "remarks", "createBy", "createDate", "updateBy", "updateDate", "delFlag", "tenantId", "createTime", "createById", "updateTime", @@ -44,8 +64,8 @@ public class TrafficApiController extends BaseApiController { * 获取进出站客流排名TOP10 * 规则:只统计单线路站点(lineId不含逗号) */ - @ApiLog("获取进出站客流排名TOP10") - @Operation(summary = "获取进出站客流排名TOP10") + @ApiLog("1、(排名)获取进出站客流排名TOP10") + @Operation(summary = "1、(排名)获取进出站客流排名TOP10") @PostMapping("getInOutStationRank/v1") public ResponseEntity getInOutStationRank(HttpServletRequest request) { if (!checkRequest(request)) { @@ -76,8 +96,8 @@ public class TrafficApiController extends BaseApiController { * 获取换乘站客流排名TOP10 * 规则:只统计多线路站点(lineId含逗号) */ - @ApiLog("获取换乘站客流排名TOP10") - @Operation(summary = "获取换乘站客流排名TOP10") + @ApiLog("1、(排名)获取换乘站客流排名TOP10") + @Operation(summary = "1、(排名)获取换乘站客流排名TOP10") @PostMapping("getTransferStationRank/v1") public ResponseEntity getTransferStationRank(HttpServletRequest request) { if (!checkRequest(request)) { @@ -104,6 +124,213 @@ public class TrafficApiController extends BaseApiController { return okJsonResponse(resultArray, cacheKey); } + /** + * 获取线路客流信息(客运页面专用) + * 返回3、4、7、15号线的今日客流、对比日客流、历史峰值数据 + */ + @ApiLog("2、(线路客流板块)获取线路客流信息") + @Operation(summary = "2、(线路客流板块)获取线路客流信息") + @PostMapping("getLinePassengerFlow/v1") + public ResponseEntity getLinePassengerFlow(HttpServletRequest request) { + if (!checkRequest(request)) { + return checkResult; + } + String cacheKey = Constant.API_CACHE_NAME_TRAFFIC_LINE_FLOW; + JSONArray resultArray = new JSONArray(); + + try { + // 缓存读取 + if (useCache(cacheKey, request)) { + return okJsonResponse(redisUtils.getJSONArray(cacheKey), cacheKey); + } + + // 获取日期 + LocalDate now = LocalDate.now(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + String today = now.format(formatter); + String compareDay = resolveCompareDay(); + + // 查询数据 + List todayList = ysYunyingService.getYunyingList(today); + List compareList = ysYunyingService.getYunyingList(compareDay); + List maxList = ysYunyingMaxService.getYunyinglist(); + + // 空值保护 + todayList = Optional.ofNullable(todayList).orElse(Collections.emptyList()); + compareList = Optional.ofNullable(compareList).orElse(Collections.emptyList()); + maxList = Optional.ofNullable(maxList).orElse(Collections.emptyList()); + + // 按线路聚合(3、4、7、15号线) + for (String lineId : TARGET_LINES) { + // 获取今天的完整对象(包含所有时间段字段:time1~time10 + totalSum) + YsYunyingMaxDTO todayData = todayList.stream() + .filter(dto -> lineId.equals(dto.getLineId())) + .findFirst() + .orElse(new YsYunyingMaxDTO()); + + YsYunyingMaxDTO compareData = compareList.stream() + .filter(dto -> lineId.equals(dto.getLineId())) + .findFirst() + .orElse(new YsYunyingMaxDTO()); + + YsYunyingMax maxData = maxList.stream() + .filter(dto -> lineId.equals(dto.getLineId())) + .findFirst() + .orElse(new YsYunyingMax()); + + // 组装结果 + JSONObject result = new JSONObject(); + result.put("line", lineId); + result.put("todayDate", today); + result.put("compareDate", compareDay); + result.put("today", todayData); + result.put("compareDay", compareData); + result.put("maxDay", maxData); + resultArray.add(result); + } + + // 过滤不需要的字段 + resultArray = JSONUtil.getJsonArrayFormList(resultArray, LINE_YUNYING_EXCLUDE_FIELDS); + } catch (Exception ex) { + return badJsonResponse("获取线路客流信息异常", ex); + } + + return okJsonResponse(resultArray, cacheKey); + } + + /** + * 获取所有线路列表 + */ + @ApiLog("3、(单站)获取所有线路列表") + @Operation(summary = "3、(单站)获取所有线路列表") + @PostMapping("getLineList/v1") + public ResponseEntity getLineList(HttpServletRequest request) { + if (!checkRequest(request)) { + return checkResult; + } + String cacheKey = Constant.API_CACHE_NAME_TRAFFIC_LINE_LIST; + JSONArray resultArray = new JSONArray(); + + try { + if (useCache(cacheKey, request)) { + resultArray = redisUtils.getJSONArray(cacheKey); + } else { + List lines = ysYunyingService.getLineList(); + String[] excludesFields = new String[]{ + "remarks", "createBy", "createDate", "updateBy", "updateDate", + "delFlag", "tenantId", "createTime", "createById", "updateTime", + "updateById", "updateByIdId", "createByIdId", "tenantDTO", + "stationId", "stationName", "total", "compareTotal", "sortNo", + "fileName", "pullNum", "departureNum", "endTime", "begTime", "crosslines" + }; + resultArray = JSONUtil.getJsonArrayFormList(lines, excludesFields); + } + } catch (Exception ex) { + return badJsonResponse("获取线路列表异常", ex); + } + return okJsonResponse(resultArray, cacheKey); + } + + /** + * 根据线路编号获取该线路下的所有车站 + */ + @ApiLog("3、(单站)根据线路获取车站列表") + @Operation(summary = "3、(单站)根据线路获取车站列表") + @PostMapping("getStationsByLine/v1") + public ResponseEntity getStationsByLine( + @RequestParam(value = "lineId", required = false, defaultValue = "") String lineId, + HttpServletRequest request) { + if (!checkRequest(request)) { + return checkResult; + } + if (lineId == null || lineId.trim().isEmpty()) { + return badJsonResponse("参数lineId不能为空"); + } + + String cacheKey = Constant.API_CACHE_NAME_TRAFFIC_STATIONS_BY_LINE + lineId; + JSONArray resultArray = new JSONArray(); + + try { + if (useCache(cacheKey, request)) { + resultArray = redisUtils.getJSONArray(cacheKey); + } else { + List stations = ysYunyingService.getStationsByLine(lineId); + String[] excludesFields = new String[]{ + "id", "remarks", "createBy", "createDate", "updateBy", "updateDate", + "delFlag", "tenantId", "createTime", "createById", "updateTime", + "updateById", "updateByIdId", "createByIdId", "fileName", "pullNum", + "tenantDTO", "departureNum", "endTime", "begTime", "total", "compareTotal", "sortNo", "name" + }; + resultArray = JSONUtil.getJsonArrayFormList(stations, excludesFields); + } + } catch (Exception ex) { + return badJsonResponse("获取线路车站列表异常", ex); + } + return okJsonResponse(resultArray, cacheKey); + } + + /** + * 获取指定车站的进出站客流 + 换乘客流(今日 + 对比日) + */ + @ApiLog("3、(单站)获取车站客流详情") + @Operation(summary = "3、(单站)获取车站客流详情") + @PostMapping("getStationPassengerFlow/v1") + public ResponseEntity getStationPassengerFlow( + @RequestParam(value = "stationId", required = false, defaultValue = "") String stationId, + HttpServletRequest request) { + if (!checkRequest(request)) { + return checkResult; + } + if (stationId == null || stationId.trim().isEmpty()) { + return badJsonResponse("参数stationId不能为空"); + } + + String cacheKey = Constant.API_CACHE_NAME_TRAFFIC_STATION_FLOW + stationId; + JSONObject resultObj = new JSONObject(); + + try { + if (useCache(cacheKey, request)) { + resultObj = redisUtils.getJSON(cacheKey); + } else { + String today = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); + String compareDay = resolveCompareDay(); + + // 进出站客流(今日 + 对比日) + YsYunyingMaxDTO inOutToday = Optional.ofNullable( + ysYunyingService.getStationInOutFlow(stationId, today)) + .orElse(new YsYunyingMaxDTO()); + YsYunyingMaxDTO inOutCompare = Optional.ofNullable( + ysYunyingService.getStationInOutFlow(stationId, compareDay)) + .orElse(new YsYunyingMaxDTO()); + + // 换乘客流(同名车站在其他线路,今日 + 对比日) + YsYunyingMaxDTO transferToday = Optional.ofNullable( + ysYunyingService.getStationTransferFlow(stationId, today)) + .orElse(new YsYunyingMaxDTO()); + YsYunyingMaxDTO transferCompare = Optional.ofNullable( + ysYunyingService.getStationTransferFlow(stationId, compareDay)) + .orElse(new YsYunyingMaxDTO()); + + resultObj.put("stationId", stationId); + resultObj.put("todayDate", today); + resultObj.put("compareDate", compareDay); + + JSONObject inOut = new JSONObject(); + inOut.put("today", inOutToday); + inOut.put("compareDay", inOutCompare); + resultObj.put("inOut", inOut); + + JSONObject transfer = new JSONObject(); + transfer.put("today", transferToday); + transfer.put("compareDay", transferCompare); + resultObj.put("transfer", transfer); + } + } catch (Exception ex) { + return badJsonResponse("获取车站客流详情异常", ex); + } + return okJsonResponse(resultObj, cacheKey); + } + /** * 清理客运页面所有接口缓存 */ diff --git a/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/YsYunyingMapper.java b/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/YsYunyingMapper.java index 88c13ba..f688876 100644 --- a/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/YsYunyingMapper.java +++ b/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/YsYunyingMapper.java @@ -59,6 +59,39 @@ public interface YsYunyingMapper extends BaseMapper { */ public List getTransferStationMaxList(String date); + /** + * 获取有客流数据的所有线路列表(数据源:ysdp) + * 数据来源:ys_yunying 表中实际存在数据的线路(DISTINCT line_id) + * 与常规页面客流排名接口 getStationMaxList 使用同源数据 + * @return 线路列表(仅 lineId 字段) + */ + public List getLineList(); + + /** + * 获取指定线路下的所有车站列表 + * @param lineId 线路编号(如 "03") + * @return 车站列表(含站名、所属所有线路) + */ + public List getStationsByLine(@Param("lineId") String lineId); + + /** + * 获取指定车站在指定日期各时段的进出站客流(当前车站本身) + * @param stationId 车站编号 + * @param date 日期 yyyy-MM-dd + * @return 各时段(time1~time10)的客流数据 + */ + public YsYunyingMaxDTO getStationInOutFlow(@Param("stationId") String stationId, + @Param("date") String date); + + /** + * 获取同名车站在其他线路的换乘客流(自动查同名车站,排除当前车站) + * @param stationId 当前车站编号 + * @param date 日期 yyyy-MM-dd + * @return 各时段(time1~time10)的换乘客流数据 + */ + public YsYunyingMaxDTO getStationTransferFlow(@Param("stationId") String stationId, + @Param("date") String date); + public String getStationCompareValue(String compareDay, String stationId); public YsInterfaceDTO getInterface(String type); diff --git a/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/xml/YsYunyingMapper.xml b/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/xml/YsYunyingMapper.xml index bffefb5..c164595 100644 --- a/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/xml/YsYunyingMapper.xml +++ b/be/jeeplus-modules/juntech-ysdp/src/main/java/net/juntech/modules/ysdp/mapper/xml/YsYunyingMapper.xml @@ -294,6 +294,78 @@ LIMIT 10 + + + + + + + +