Browse Source

各收费站入口分车型小时车流量,全路段双向实时车流量

develop
王兴琳 6 months ago
parent
commit
460cc5ee70
  1. 36
      zc-business/src/main/java/com/zc/business/controller/DcTrafficStatisticsController.java
  2. 7
      zc-business/src/main/java/com/zc/business/mapper/DcGantryStatisticsDataMapper.java
  3. 5
      zc-business/src/main/java/com/zc/business/service/IDcGantryStatisticsDataService.java
  4. 8
      zc-business/src/main/java/com/zc/business/service/IDcTrafficStatisticsService.java
  5. 11
      zc-business/src/main/java/com/zc/business/service/impl/DcGantryStatisticsDataImpl.java
  6. 104
      zc-business/src/main/java/com/zc/business/service/impl/DcTrafficStatisticsServiceImpl.java
  7. 43
      zc-business/src/main/resources/mapper/business/DcGantryStatisticsDataMapper.xml

36
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<Map<String,String>> 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<Map<String, String>> jsonArray = dcTrafficStatisticsService.trafficFlowAtTollStationEntrance(startDate, endDate, stationType);
// 将获取到的交通指标数据封装为成功的结果并返回
return AjaxResult.success(jsonArray);
}
}

7
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<DcGantryStatist
* @return 返回最大的统计日期
*/
Date getMaxStatisticalDate();
/**
* 全路段双向实时车流量
*/
List<Map<String, String>> realTimeTrafficFlow(@Param("startDate") String startDate, @Param("direction")String direction, @Param("periodType")String periodType );
}

5
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<DcGantryStatist
* @return 返回一个DcGantryStatisticsData对象的列表包含统计后的结果
*/
List<DcGantryStatisticsData> gantryData(DcGantryStatisticsData dcGantryStatisticsData);
/**
* 全路段双向实时车流量
*/
List<Map<String, String>> realTimeTrafficFlow(String startDate, String direction,String periodType );
}

8
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<Map<String, String>>trafficFlowAtTollStationEntrance(String startDate, String endDate,String stationType) throws HttpException, IOException;
}

11
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<DcGantryStatisticsDa
// 门架流水数据服务
@Resource
private IOdsTollEtctuDataService odsTollEtctuDataService;
@Resource
private DcGantryStatisticsDataMapper dcGantryStatisticsDataMapper;
/**
* 初始化方法用于在对象创建后恢复各种周期的交通门架缓存
@ -109,6 +111,13 @@ public class DcGantryStatisticsDataImpl extends ServiceImpl<DcGantryStatisticsDa
return list(queryWrapper);
}
/**
* 全路段双向实时车流量
*/
@Override
public List<Map<String, String>> realTimeTrafficFlow(String startDate, String direction,String periodType ) {
return dcGantryStatisticsDataMapper.realTimeTrafficFlow(startDate,direction,periodType);
}
/**
* 恢复日缓存数据的方法

104
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<String, String> 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<Map<String, String>> 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<String, String> 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<String, Integer> sumByName = new HashMap<>();
List<Map<String, String>> 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<String, Integer> entry : sumByName.entrySet()) {
Map<String, String> 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();
}
}

43
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">
<mapper namespace="com.zc.business.mapper.DcGantryStatisticsDataMapper">
<resultMap type="map" id="countMap">
<result property="volume" column="total_traffic_volume"/>
<result property="name" column="interval_name"/>
</resultMap>
<!-- 插入或更新交通路段数据 -->
<insert id="insertOrUpdate" parameterType="com.zc.business.domain.DcGantryStatisticsData">
INSERT INTO
@ -87,5 +90,43 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
FROM
dc_gantry_statistics_data
</select>
<select id="realTimeTrafficFlow" resultMap="countMap" resultType="map" >
SELECT
intervals.interval_name,
COALESCE(SUM(dgsd.traffic_volume), 0) AS total_traffic_volume
FROM
(
SELECT 'K054+394' AS start_stake, 'K059+289' AS end_stake, '殷家林枢纽' AS interval_name UNION ALL
SELECT 'K059+289', 'K072+847', '大学城立交' UNION ALL
SELECT 'K072+847', 'K083+835', '长清立交' UNION ALL
SELECT 'K083+835', 'K086+499', '松竹枢纽' UNION ALL
SELECT 'K086+499', 'K099+750', '孝里立交' UNION ALL
SELECT 'K099+750', 'K105+904', '平阴北立交' UNION ALL
SELECT 'K105+904', 'K117+878', '平阴立交' UNION ALL
SELECT 'K117+878', 'K126+233', '孔村枢纽' UNION ALL
SELECT 'K126+233', 'K145+933', '平阴南立交' UNION ALL
SELECT 'K145+933', 'K155+652', '东平立交' UNION ALL
SELECT 'K155+652', 'K173+950', '东平湖枢纽' UNION ALL
SELECT 'K173+950', 'K179+396', '梁山东立交' UNION ALL
SELECT 'K179+396', 'K190+495', '梁山立交' UNION ALL
SELECT 'K190+495', 'K202+979', '嘉祥西立交'
) AS intervals
LEFT JOIN (
SELECT
facility_code,
stake_mark,
facility_name,
direction
FROM
dc_facility
WHERE
direction = #{direction}
) AS ps ON ps.stake_mark BETWEEN CONCAT(intervals.start_stake, '+0') AND CONCAT(intervals.end_stake, '+0')
LEFT JOIN dc_gantry_statistics_data dgsd ON ps.facility_code = dgsd.gantry_code
AND dgsd.statistical_date =#{startDate}
AND dgsd.period_type =#{periodType}
GROUP BY
intervals.interval_name;
</select>
</mapper>

Loading…
Cancel
Save