diff --git a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java index cb2eb3a4..ae1e0d1a 100644 --- a/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java +++ b/zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java @@ -179,6 +179,20 @@ public class DcTrafficStatisticsController { // 将查询结果封装为成功响应并返回 return AjaxResult.success(dcStatisticsData); } +/** + * 全路段双向实时车流量 + * @param startDate 时间 + * @param direction 方向 + * @param periodType 时间粒子 + */ +@ApiOperation("全路段双向实时车流量") +@GetMapping("/history/realTimeTrafficFlow") +public AjaxResult realTimeTrafficFlow(String startDate, String direction,String periodType ){ + List> mapList = dcGantryStatisticsDataService.realTimeTrafficFlow(startDate,direction,periodType); + // 将查询结果封装为成功响应并返回 + return AjaxResult.success(mapList); +} + /********************************************* 智慧高速平接口 **************************************************/ @@ -246,6 +260,26 @@ public class DcTrafficStatisticsController { // 将获取到的交通指标数据封装为成功的结果并返回 return AjaxResult.success(jsonArray); } +/** + * 断面小时车流量分车型 + */ +@ApiOperation("断面小时车流量分车型") +@GetMapping("/history/sectionHourlyTrafficFlow") +public AjaxResult sectionHourlyTrafficFlow(String startDate, String endDate) throws HttpException, IOException { + // 调用服务层方法,获取当前交通指标数据 + JSONArray jsonArray = dcTrafficStatisticsService.sectionHourlyTrafficFlow(startDate, endDate); + // 将获取到的交通指标数据封装为成功的结果并返回 + return AjaxResult.success(jsonArray); - +}/** + * 各收费站入口分车型小时车流量 + */ +@ApiOperation("各收费站入口分车型小时车流量") +@GetMapping("/history/trafficFlowAtTollStationEntrance") +public AjaxResult trafficFlowAtTollStationEntrance(String startDate, String endDate,String stationType) throws HttpException, IOException { + // 调用服务层方法,获取当前交通指标数据 + List> jsonArray = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(startDate, endDate, stationType); + // 将获取到的交通指标数据封装为成功的结果并返回 + return AjaxResult.success(jsonArray); +} } diff --git a/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java b/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java index b7eb758a..7dc79413 100644 --- a/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java +++ b/zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java @@ -3,8 +3,11 @@ package com.zc.business.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.zc.business.domain.DcGantryStatisticsData; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import java.util.Date; +import java.util.List; +import java.util.Map; /** * 这是一个接口的注释,用于描述门架数据统计的Mapper。 @@ -29,5 +32,9 @@ public interface DcGantryStatisticsDataMapper extends BaseMapper> realTimeTrafficFlow(@Param("startDate") String startDate, @Param("direction")String direction, @Param("periodType")String periodType ); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java b/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java index e6b95a43..850eac05 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java @@ -6,6 +6,7 @@ import com.zc.business.domain.DcStatisticsData; import com.zc.business.domain.DcTollStationStatisticsData; import java.util.List; +import java.util.Map; /** * 门架数据统计接口。该接口扩展了IService接口,用于对DcGantryStatisticsData类型的实体进行数据库操作。 @@ -34,4 +35,8 @@ public interface IDcGantryStatisticsDataService extends IService gantryData(DcGantryStatisticsData dcGantryStatisticsData); + /** + * 全路段双向实时车流量 + */ + List> realTimeTrafficFlow(String startDate, String direction,String periodType ); } diff --git a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java index cb272e49..9835ede1 100644 --- a/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java +++ b/zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java @@ -43,4 +43,12 @@ public interface IDcTrafficStatisticsService { * 获取车道占有率信息 */ JSONArray laneOccupancy(String startDate, String endDate) throws HttpException, IOException; + /** + * 断面小时车流量分车型 + */ + JSONArray sectionHourlyTrafficFlow(String startDate, String endDate) throws HttpException, IOException; + /** + * 各收费站入口分车型小时车流量 + */ + List>trafficFlowAtTollStationEntrance(String startDate, String endDate,String stationType) throws HttpException, IOException; } diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java index ed8d6d38..f38a8ae2 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java @@ -21,6 +21,7 @@ import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.util.Date; import java.util.List; +import java.util.Map; /** * 门架数据统计服务实现类 @@ -37,7 +38,8 @@ public class DcGantryStatisticsDataImpl extends ServiceImpl> realTimeTrafficFlow(String startDate, String direction,String periodType ) { + return dcGantryStatisticsDataMapper.realTimeTrafficFlow(startDate,direction,periodType); + } /** * 恢复日缓存数据的方法 diff --git a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java index af3b68d7..162560dc 100644 --- a/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java +++ b/zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java @@ -23,10 +23,7 @@ import org.springframework.stereotype.Service; import javax.annotation.PostConstruct; import javax.annotation.Resource; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @Service public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsService { @@ -509,5 +506,104 @@ public class DcTrafficStatisticsServiceImpl implements IDcTrafficStatisticsServi return new JSONArray(); } + /** + * 断面小时车流量分车型 + */ + @Override + public JSONArray sectionHourlyTrafficFlow(String startDate, String endDate) throws HttpException, IOException { + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + + requestParams.put("sysid", sysid); + + JSONObject parameters = new JSONObject() { + { + put("start_date", startDate); + put("end_date", endDate); + } + }; + + requestParams.put("parameters", parameters.toJSONString()); + + Map headers = new HashMap<>(); + headers.put("Authorization", getAccessToken()); + + Response response // 请求响应 + = okHttp + .headers(headers) + .url(baseUrl + "/api/dc/query/rd_jihe_d_vehtypeflowbydatesection") // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + ResponseBody body = response.body(); + if (body != null) { + return JSON.parseArray(body.string()); + } + + return new JSONArray(); + } +/** + * 各收费站入口分车型小时车流量 + */ + @Override + public List> trafficFlowAtTollStationEntrance(String startDate, String endDate,String stationType) throws HttpException, IOException { + OkHttp okHttp = new OkHttp(); + + RequestParams requestParams = new RequestParams(); + + requestParams.put("sysid", sysid); + + JSONObject parameters = new JSONObject() { + { + put("start_date", startDate); + put("end_date", endDate); + put("station_type", stationType); + } + }; + + requestParams.put("parameters", parameters.toJSONString()); + + Map headers = new HashMap<>(); + headers.put("Authorization", getAccessToken()); + + Response response // 请求响应 + = okHttp + .headers(headers) + .url(baseUrl + "/api/dc/query/ts_jihe_d_vehtypeflowbyhourstation") // 请求地址 + .data(requestParams) // 请求参数 + .post(); // 请求方法 + + ResponseBody body = response.body(); + if (body != null) { + JSONArray jsonArray = JSON.parseArray(body.string()); + +// 使用HashMap来分组并求和 + Map sumByName = new HashMap<>(); + List> list = new ArrayList(); + + for (Object item : jsonArray) { // 这里做了微调,直接遍历jsonArray的Object + JSONObject jsonObject = (JSONObject) item; + String name = jsonObject.getString("ts_name"); // 更安全的取值方式 + int totalFlow = jsonObject.getInteger("total_flow"); // 专门针对Integer类型 + sumByName.put(name, sumByName.getOrDefault(name, 0) + totalFlow); + + } + +// 输出结果 +// 输出结果 + // 正确创建新的映射对象并添加到list中 + for (Map.Entry entry : sumByName.entrySet()) { + Map singleResult = new HashMap<>(); // 每次循环都创建一个新的映射 + singleResult.put("name", entry.getKey()); + singleResult.put("value", entry.getValue().toString()); + list.add(singleResult); + System.out.println(entry.getKey() + " 的 total_flow 总和为: " + entry.getValue()); + } + return list; + } + + return new ArrayList(); + } } diff --git a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml index 851f7fe9..e8b420dd 100644 --- a/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml +++ b/zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml @@ -3,7 +3,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> - + + + + INSERT INTO @@ -87,5 +90,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" FROM dc_gantry_statistics_data +