Commit 02eed355 authored by zhoushiguang's avatar zhoushiguang

干线关联路口指标计算

parent 4590ca1b
......@@ -140,6 +140,13 @@
<artifactId>commons-net</artifactId>
<version>3.7</version>
</dependency>
<!--swagger -start-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>2.0.4</version>
</dependency>
</dependencies>
<build>
......
......@@ -101,7 +101,7 @@ public class GreenwaveHistRestServer {
}
@GetMapping("/findUnCoordinateDirIndex")
@ApiOperation(httpMethod="GET",value="绿波非协调方向指标趋势", notes="")
@ApiOperation(httpMethod="GET",value="绿波非协调方向->指标趋势", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "String",defaultValue = "13MOD0B5SI0"),
@ApiImplicitParam(name = "greenDir", value = "绿波协调方向,多个逗号分隔", required = true, dataType = "String",defaultValue = "5,7"),
......@@ -126,4 +126,60 @@ public class GreenwaveHistRestServer {
return jsonView;
}
@GetMapping("/findGreenWaveCrossDirIndex")
@ApiOperation(httpMethod="GET",value="绿波路口方向级->分粒度指标趋势", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "String",defaultValue = "13MOD0B5SI0"),
@ApiImplicitParam(name = "groupType", value = "时间粒度类型 1:15分钟粒度 2:30分钟粒度 3:小时粒度", required = true, dataType = "Integer",defaultValue = "1"),
@ApiImplicitParam(name = "startTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2024-12-04 00:00:00"),
@ApiImplicitParam(name = "endTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2024-12-05 00:00:00")
})
@ApiResponses({
@ApiResponse(code = 200, message = "成功", response = GreenwaveHist.class,
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
})
public JsonViewObject findGreenWaveCrossDirIndex(String crossId, String startTime, String endTime,String groupType) {
JsonViewObject jsonView = JsonViewObject.newInstance();
try {
JSONObject list = greenwaveHistProvider.findGreenWaveCrossDirIndex(crossId,startTime,endTime,groupType);
jsonView.success(list);
} catch (DubboProviderException e) {
jsonView.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG"));
log.error("{} getAll error", this.getClass().getSimpleName(), e);
}
return jsonView;
}
@GetMapping("/findGreenWaveCrossIndex")
@ApiOperation(httpMethod="GET",value="绿波路口级->分粒度指标趋势", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "String",defaultValue = "13MOD0B5SI0"),
@ApiImplicitParam(name = "groupType", value = "时间粒度类型 1:15分钟粒度 2:30分钟粒度 3:小时粒度", required = true, dataType = "Integer",defaultValue = "1"),
@ApiImplicitParam(name = "startTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2024-12-04 00:00:00"),
@ApiImplicitParam(name = "endTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2024-12-05 00:00:00")
})
@ApiResponses({
@ApiResponse(code = 200, message = "成功", response = GreenwaveHist.class,
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
})
public JsonViewObject findGreenWaveCrossIndex(String crossId, String startTime, String endTime,String groupType) {
JsonViewObject jsonView = JsonViewObject.newInstance();
try {
JSONObject list = greenwaveHistProvider.findGreenWaveCrossIndex(crossId,startTime,endTime,groupType);
jsonView.success(list);
} catch (DubboProviderException e) {
jsonView.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG"));
log.error("{} getAll error", this.getClass().getSimpleName(), e);
}
return jsonView;
}
}
......@@ -2,6 +2,8 @@ package net.wanji.opt.dao.mapper;
import net.wanji.common.framework.mapper.BaseInterfaceMapper;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.opt.entity.GreenwaveHist;
import java.util.List;
......@@ -37,5 +39,19 @@ public interface GreenwaveHistoryMapper extends BaseInterfaceMapper<GreenwaveHis
*/
List<GreenwaveHist> findUnCoordinateCrossIndex(Map<String,Object> params);
/**
* 绿波路口方向级指标查询
* @param params
* @return
*/
List<CrossDirDataHistPO> findGreenWaveCrossDirIndex(Map<String,Object> params);
/**
* 绿波路口级指标查询
* @param params
* @return
*/
List<CrossDataHistPO> findGreenWaveCrossIndex(Map<String,Object> params);
}
......@@ -3,6 +3,7 @@ package net.wanji.opt.service;
import com.alibaba.fastjson.JSONObject;
import net.wanji.common.framework.dubbointerface.BaseDubboInterface;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.opt.entity.GreenwaveHist;
import java.util.List;
......@@ -18,7 +19,6 @@ import java.util.Map;
*/
public interface GreenwaveHistProvider extends BaseDubboInterface<GreenwaveHist> {
/**
*
* @param greenId
* @param startTime
* @param endTime
......@@ -30,6 +30,7 @@ public interface GreenwaveHistProvider extends BaseDubboInterface<GreenwaveHist>
/**
* 干线路口信息
*
* @param greenId
* @return
* @throws DubboProviderException
......@@ -38,13 +39,35 @@ public interface GreenwaveHistProvider extends BaseDubboInterface<GreenwaveHist>
/**
* 非协调方向路口指标统计
*
* @param crossId 路口ID
* @param greenDir 协调方向
* @param startTime 开始时间
* @param endTime 截止时间
* @return
*/
JSONObject findUnCoordinateCrossIndex(String crossId,String greenDir, String startTime, String endTime) throws DubboProviderException;
JSONObject findUnCoordinateCrossIndex(String crossId, String greenDir, String startTime, String endTime) throws DubboProviderException;
/**
* 路口方向级不同时间粒度指标分析
* @param crossId
* @param startTime
* @param endTime
* @param groupType
* @return
* @throws DubboProviderException
*/
JSONObject findGreenWaveCrossDirIndex(String crossId, String startTime, String endTime, String groupType) throws DubboProviderException;
/**
* 路口级不同时间粒度指标分析
* @param crossId
* @param startTime
* @param endTime
* @param groupType
* @return
* @throws DubboProviderException
*/
JSONObject findGreenWaveCrossIndex(String crossId, String startTime, String endTime, String groupType) throws DubboProviderException;
}
......@@ -7,6 +7,8 @@ import net.wanji.common.framework.dubbointerface.impl.BaseDubboInterfaceImpl;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.common.framework.mapper.BaseInterfaceMapper;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.opt.dao.mapper.GreenwaveHistoryMapper;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.service.GreenwaveHistProvider;
......@@ -163,4 +165,85 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
}
@Override
public JSONObject findGreenWaveCrossDirIndex(String crossId, String startTime, String endTime,String groupType) {
Map<String,Object> params = new HashMap<>();
params.put("crossId",crossId);
params.put("startDate",startTime);
params.put("endDate",endTime);
params.put("groupType",groupType);
List<CrossDirDataHistPO> list = greenwaveHistoryMapper.findGreenWaveCrossDirIndex(params);
list = list.stream().sorted(Comparator.comparing(o -> o.getStartTime())).collect(Collectors.toList());
//存放时段
Set<String> sortedSet = new TreeSet<>();
//存放所有进口数据
List<Map<String, Object>> allList = new ArrayList<>();
//按时间分组分组
Map<Integer, List<CrossDirDataHistPO>> groupByDir = list.stream().collect(Collectors.groupingBy(o -> o.getDirType(), TreeMap::new, Collectors.toList()));
List<Map<String, Object>> turnList = new ArrayList<>();
for (Map.Entry<Integer, List<CrossDirDataHistPO>> entry : groupByDir.entrySet()) {
Integer key = entry.getKey();
//按方向排序
List<CrossDirDataHistPO> value = entry.getValue().stream().sorted(Comparator.comparing(o -> o.getStartTime())).collect(Collectors.toList());
Map<String, Object> mapList = new HashMap<>();
mapList.put("direction", key);
mapList.put("list", value);
allList.add(mapList);
for (CrossDirDataHistPO po : value) {
Map<String, Object> turnMap = new HashMap<>();
turnMap.put("direction", po.getDirType());
if (!turnList.contains(turnMap)) {
turnList.add(turnMap);
}
//提取时间
sortedSet.add(DateUtil.formatDate(po.getStartTime(), "HH:mm"));
}
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("timeList", sortedSet);
jsonObject.put("dataList", allList);
jsonObject.put("dirList", groupByDir.keySet());
return jsonObject;
}
@Override
public JSONObject findGreenWaveCrossIndex(String crossId, String startTime, String endTime,String groupType) {
Map<String,Object> params = new HashMap<>();
params.put("crossId",crossId);
params.put("startDate",startTime);
params.put("endDate",endTime);
params.put("groupType",groupType);
List<CrossDataHistPO> list = greenwaveHistoryMapper.findGreenWaveCrossIndex(params);
list = list.stream().sorted(Comparator.comparing(o -> o.getStartTime())).collect(Collectors.toList());
//存放时段
Set<String> sortedSet = new TreeSet<>();
for (CrossDataHistPO po : list) {
//提取时间
sortedSet.add(DateUtil.formatDate(po.getStartTime(), "HH:mm"));
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("timeList", sortedSet);
jsonObject.put("dataList", list);
return jsonObject;
}
}
......@@ -39,7 +39,7 @@
</sql>
<!-- 绿波路口查询 -->
<select id="findGreenCross" resultType="map">
select a.green_id greenId, a.cross_id crossId, b.`name` crossName,a.in_dir inDir
select a.green_id greenId, a.cross_id crossId, b.`name` crossName, a.in_dir inDir
from t_greenwave_cross a
join t_base_cross_info b on a.cross_id = b.id
where green_id = #{greenId}
......@@ -68,27 +68,109 @@
<!-- 查看非协调方向路口指标 -->
<select id="findUnCoordinateCrossIndex" resultMap="BaseResultMap">
SELECT
t.cross_id ,t.direction, MAX(t.queue_length) queue_length,round(avg(stop_times),2) stop_times,DATE_FORMAT(t.start_time,'%Y-%m-%d %H:%i:00') start_time
FROM
(
SELECT
cross_id,
SELECT t.cross_id,
t.direction,
MAX(t.queue_length) queue_length,
round(avg(stop_times), 2) stop_times,
DATE_FORMAT(t.start_time, '%Y-%m-%d %H:%i:00') start_time
FROM (
SELECT cross_id,
dir_type direction,
queue_length,
stop_times,
start_time
FROM
t_cross_dir_data_hist a
WHERE
cross_id = #{crossId}
FROM t_cross_dir_data_hist a
WHERE cross_id = #{crossId}
AND dir_type not in (#{greenDir})
AND start_time BETWEEN #{startDate}
AND #{endDate}
) t
GROUP BY t.cross_id,DATE_FORMAT(start_time,'%Y-%m-%d %H:%i:00')
GROUP BY t.cross_id, DATE_FORMAT(start_time, '%Y-%m-%d %H:%i:00')
;
</select>
<!-- 绿波路口方向级指标趋势,支持按15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findGreenWaveCrossDirIndex"
resultMap="net.wanji.databus.dao.mapper.CrossDirDataHistMapper.BaseResultMap">
SELECT MIN(start_time) start_time,
cross_id,
dir_type,
round(AVG(traffic_index),2),
SUM(flow) flow,
round(AVG(speed),2) speed,
MAX(queue_length) queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),2) delay_time,
round(AVG(sturation),4) sturation
FROM
(
SELECT start_time,
(case
when #{groupType}=1 then CEIL(UNIX_TIMESTAMP(DATE_ADD(t.start_time,INTERVAL 5 MINUTE)) / 900)
when #{groupType}=2 then CEIL(UNIX_TIMESTAMP(DATE_ADD(t.start_time,INTERVAL 5 MINUTE)) / 1800)
when #{groupType}=3 then CEIL(UNIX_TIMESTAMP(DATE_ADD(t.start_time,INTERVAL 5 MINUTE)) / 3600)
end
) unit_time,
cross_id,
dir_type,
(traffic_index) traffic_index,
(flow) flow,
(speed) speed,
(queue_length) queue_length,
(stop_times) stop_times,
(delay_time) delay_time,
(sturation) sturation
FROM t_cross_dir_data_hist t
where 1=1
<if test="crossId!=null and crossId !=''">
and cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
AND start_time >= #{startDate} and start_time &lt; #{endDate}
</if>
) t
GROUP BY t.cross_id,t.dir_type,unit_time
</select>
<!-- 绿波路口级指标趋势,支持按15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findGreenWaveCrossIndex" resultMap="net.wanji.databus.dao.mapper.CrossDataHistMapper.BaseResultMap">
SELECT MIN(start_time) start_time,
cross_id,
AVG(traffic_index),
SUM(flow) flow,
round(AVG(speed),2) speed,
MAX(queue_length) queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),0) delay_time,
round(AVG(sturation),4) sturation
FROM
(
SELECT start_time,
(case
when #{groupType}=1 then CEIL(UNIX_TIMESTAMP(DATE_ADD(t.start_time,INTERVAL 5 MINUTE)) / 900)
when #{groupType}=2 then CEIL(UNIX_TIMESTAMP(DATE_ADD(t.start_time,INTERVAL 5 MINUTE)) / 1800)
when #{groupType}=3 then CEIL(UNIX_TIMESTAMP(DATE_ADD(t.start_time,INTERVAL 5 MINUTE)) / 3600)
end
) unit_time,
cross_id,
(traffic_index) traffic_index,
(flow) flow,
(speed) speed,
(queue_length) queue_length,
(stop_times) stop_times,
(delay_time) delay_time,
(sturation) sturation
FROM t_cross_data_hist t
where 1=1
<if test="crossId!=null and crossId !=''">
and cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
AND start_time >= #{startDate} and start_time &lt; #{endDate}
</if>
) t
GROUP BY t.cross_id,unit_time
</select>
<!--新增操作 -->
<insert id="save" parameterType="net.wanji.opt.entity.GreenwaveHist">
......
package net.wanji.databus.po;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
......@@ -42,6 +44,8 @@ public class CrossDataRealtimePO {
* 开始时间:yyyy-MM-dd HH;mm:ss
*/
@ApiModelProperty(value = "开始时间:yyyy-MM-dd HH:mm:ss", notes = "")
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
private Date startTime;
@ApiModelProperty(value = "结束时间:yyyy-MM-dd HH:mm:ss", notes = "")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment