Commit 8d098b7d authored by Zheng Yi Fan's avatar Zheng Yi Fan

修改干线状态分布接口

- 修改了时间颗粒度的处理逻辑,支持 5、15、30、60 分钟的颗粒度
- 新增 TrunkLineOptTimeInfoVO 类用于返回优化时间信息
- 调整了 TrunkLineStatusDisInfoVO 类,移除了不必要的字段
- 重构了 TrunkLineStatusDisMapper 接口和 XML 文件,使用新的时间信息 VO 类
- 优化了 SQL 查询,使用 ROUND 函数对平均值进行四舍五入
parent dd2fd02a
......@@ -36,7 +36,7 @@ public class TrunkLineController {
@ApiImplicitParams({
@ApiImplicitParam(name = "greenID", value = "干线ID", required = true, dataType = "String",defaultValue = ""),
@ApiImplicitParam(name = "date", value = "日期", required = true, dataType = "String",defaultValue = ""),
@ApiImplicitParam(name = "timeGranule", value = "时间颗粒度", required = true, dataType = "String",defaultValue = ""),
@ApiImplicitParam(name = "timeGranule", value = "时间颗粒度 支持参数:5 15 30 60", required = true, dataType = "String",defaultValue = "5"),
})
@ApiResponses({
......
......@@ -2,6 +2,7 @@ package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.vo2.TrunkLineOptTimeInfoVO;
import net.wanji.opt.vo2.TrunkLineStatusDisInfoVO;
import java.util.List;
......@@ -22,5 +23,5 @@ public interface TrunkLineStatusDisMapper extends BaseMapper<GreenwaveHist> {
* @return
*/
List<TrunkLineStatusDisInfoVO> findStatusDistribution(Map<String, Object> params);
List<TrunkLineStatusDisInfoVO> findPlanTime(Map<String, Object> params);
List<TrunkLineOptTimeInfoVO> findPlanTime(Map<String, Object> params);
}
......@@ -5,6 +5,7 @@ import groovy.util.logging.Slf4j;
import net.wanji.opt.dao.mapper.TrunkLineStatusDisMapper;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.servicev2.TrunkLineStatusDisService;
import net.wanji.opt.vo2.TrunkLineOptTimeInfoVO;
import net.wanji.opt.vo2.TrunkLineStatusDisInfoVO;
import org.springframework.stereotype.Service;
......@@ -27,14 +28,28 @@ public class TrunkLineStatusDisImpl implements TrunkLineStatusDisService {
Map<String, Object> params = new HashMap<>();
params.put("greenID", greenID);
params.put("date", date);
params.put("timeGranule", timeGranule);
params.put("granule", getGranule(timeGranule));
List<TrunkLineStatusDisInfoVO> list= trunkLineStatusDisMapper.findStatusDistribution(params);
List<TrunkLineStatusDisInfoVO> list1= trunkLineStatusDisMapper.findPlanTime(params);
List<TrunkLineOptTimeInfoVO> list1= trunkLineStatusDisMapper.findPlanTime(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("dataList", list);
jsonObject.put("timeList", list1);
return jsonObject;
}
private Integer getGranule(String timeGranule) {
switch (timeGranule) {
case "5":
return 300;
case "15":
return 900;
case "30":
return 1800;
case "60":
return 3600;
}
return 300;
}
}
package net.wanji.opt.vo2;
import lombok.Data;
@Data
public class TrunkLineOptTimeInfoVO {
private String optStartTime;
private String optEndTime;
}
......@@ -23,8 +23,6 @@ public class TrunkLineStatusDisInfoVO {
private String direction;
@ApiModelProperty(value = "绿波id")
private String greenId;
@ApiModelProperty(value = "时间颗粒度")
@ApiModelProperty(value = "时间")
private String startTime;
@ApiModelProperty(value = "结束时间")
private String endTime;
}
......@@ -5,21 +5,46 @@
<!-- 绿波路口查询 -->
<select id="findStatusDistribution" parameterType="map" resultType="net.wanji.opt.vo2.TrunkLineStatusDisInfoVO">
select c.green_id as greenId,c.road_direction as direction, c.start_time as startTime , AVG(c.speed) AS speed ,AVG(c.trval_time) as travelTime, AVG(c.delay_time) as delayTime,AVG(c.stop_times) as stopTimes
select
c.green_id as greenId,
c.road_direction as direction,
c.start_time as startTime ,
ROUND(AVG(c.speed), 2) as speed ,
ROUND(AVG(c.trval_time), 2) as travelTime,
ROUND(AVG(c.delay_time), 2) as delayTime,
ROUND(AVG(c.stop_times), 2) as stopTimes
from
(select b.green_id,b.road_direction,b.speed ,b.trval_time, b.delay_time,b.stop_times,
DATE_FORMAT(FROM_UNIXTIME(CEIL(UNIX_TIMESTAMP(b.start_time) / #{timeGranule}) * #{timeGranule}), '%H:%i') as start_time
from
(select a.green_id,a.road_direction,IFNULL(a.speed,0) as speed,IFNULL(a.trval_time,0) as trval_time,a.delay_time,a.stop_times,
DATE_FORMAT(a.start_time,'%Y-%m-%d %H:%i:00') as start_time
from t_greenwave_hist a
where DATE_FORMAT(a.start_time,'%Y-%m-%d') = DATE_FORMAT(#{date},'%Y-%m-%d')
and a.green_id = #{greenID}) b ) c
group by c.green_id,c.road_direction, c.start_time
(
select
b.green_id,
b.road_direction,
b.speed ,
b.trval_time,
b.delay_time,
b.stop_times,
DATE_FORMAT(FROM_UNIXTIME(ceil(UNIX_TIMESTAMP(b.start_time) / #{granule}) * #{granule}), '%H:%i') as start_time
from
(
select
a.green_id,
a.road_direction,
IFNULL(a.speed, 0) as speed,
IFNULL(a.trval_time, 0) as trval_time,
a.delay_time,
a.stop_times,
DATE_FORMAT(a.start_time, '%Y-%m-%d %H:%i:00') as start_time
from
t_greenwave_hist a
where
DATE_FORMAT(a.start_time, '%Y-%m-%d') = DATE_FORMAT(#{date},'%Y-%m-%d')
and a.green_id = #{greenID}
) b
) c
group by c.green_id, c.road_direction, c.start_time
</select>
<select id="findPlanTime" parameterType="map" resultType="net.wanji.opt.vo2.TrunkLineStatusDisInfoVO">
select DISTINCT DATE_FORMAT(a.control_time,'%H:%i') as startTime ,DATE_FORMAT(DATE_ADD(a.control_time, INTERVAL a.duration SECOND),'%H:%i') as endTime
<select id="findPlanTime" parameterType="map" resultType="net.wanji.opt.vo2.TrunkLineOptTimeInfoVO">
select DISTINCT DATE_FORMAT(a.control_time,'%H:%i') as optStartTime ,DATE_FORMAT(DATE_ADD(a.control_time, INTERVAL a.duration SECOND),'%H:%i') as optEndTime
from t_strategy_green_opt_hist a where DATE_FORMAT(a.control_time,'%Y-%m-%d') = DATE_FORMAT(#{date},'%Y-%m-%d') and a.response_code = 200
and a.green_id = #{greenID}
</select>
......
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