Commit b77b94b0 authored by 黄伟铭's avatar 黄伟铭

新增干线状态分布趋势图接口

parent 93b72b6d
package net.wanji.opt.controllerv2;
import com.alibaba.fastjson.JSONObject;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.servicev2.TrendServiceV2;
import net.wanji.opt.servicev2.TrunkLineStatusDisService;
import net.wanji.opt.vo2.*;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author zhengyifan
* @date 2025/3/14
*/
@Api(value = "TrunkLineController", description = "监测详情-干线")
@RequestMapping("/trunkLine")
@RestController
@Slf4j
public class TrunkLineController {
@Resource
private TrunkLineStatusDisService trunkLineStatusDisService;
@GetMapping("/statusDisInfoList")
@ApiOperation(httpMethod="GET",value="干线数据", notes="")
@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 = ""),
})
@ApiResponses({
@ApiResponse(code = 200, message = "成功", response = EventStatisticPo.class,
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
})
public JsonViewObject statusDisInfoList(String greenID, String date, String timeGranule) {
try {
JsonViewObject object = JsonViewObject.newInstance();
JSONObject list = trunkLineStatusDisService.trunkLineStatusDisInfoList(greenID, date, timeGranule);
return object.success(list);
} catch (Exception e) {
log.error("监测详情-干线事件详情-干线交通状态分布趋势: ", e);
return JsonViewObject.newInstance().fail("请求失败");
}
}
}
package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.vo2.TrunkLineStatusDisInfoVO;
import java.util.List;
import java.util.Map;
/**
* <p>
* 监测详情-干线
* </p>
*
* @author zhengyifan
* @date 2025-3-14
*/
public interface TrunkLineStatusDisMapper extends BaseMapper<GreenwaveHist> {
/**
* 监测详情-干线事件-干线交通状态分布趋势
* @param params
* @return
*/
List<TrunkLineStatusDisInfoVO> findStatusDistribution(Map<String, Object> params);
List<TrunkLineStatusDisInfoVO> findPlanTime(Map<String, Object> params);
}
package net.wanji.opt.servicev2;
import com.alibaba.fastjson.JSONObject;
import java.util.*;
import net.wanji.opt.vo2.TrunkLineStatusDisInfoVO;
import java.util.List;
/**
* @author zhengyifan
* @date 2025/3/14
*/
public interface TrunkLineStatusDisService {
/**
* 监测详情-干线事件分布趋势
* @param greenID 绿波ID
* @param date 日期
* @param timeGranule 时间粒度 支持5min 15min 30min 60min
* @return
*/
JSONObject trunkLineStatusDisInfoList(String greenID, String date, String timeGranule);
}
package net.wanji.opt.servicev2.implv2;
import com.alibaba.fastjson.JSONObject;
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.TrunkLineStatusDisInfoVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.*;
/**
* @author zhengyifan
* @date 2025/3/14
*/
@Service
@Slf4j
public class TrunkLineStatusDisImpl implements TrunkLineStatusDisService {
@Resource
private TrunkLineStatusDisMapper trunkLineStatusDisMapper;
@Override
public JSONObject trunkLineStatusDisInfoList(String greenID, String date, String timeGranule) {
Map<String, Object> params = new HashMap<>();
params.put("greenID", greenID);
params.put("date", date);
params.put("timeGranule", timeGranule);
List<TrunkLineStatusDisInfoVO> list= trunkLineStatusDisMapper.findStatusDistribution(params);
List<TrunkLineStatusDisInfoVO> list1= trunkLineStatusDisMapper.findPlanTime(params);
JSONObject jsonObject = new JSONObject();
jsonObject.put("dataList", list);
jsonObject.put("timeList", list1);
return jsonObject;
}
}
package net.wanji.opt.vo2;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.math.BigDecimal;
@Data
@ApiModel(value = "TrunkLineStatusDisInfoVO", description = "监测详情-干线事件详情-干线交通状态分布趋势")
public class TrunkLineStatusDisInfoVO {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "行程速度")
private Double speed;
@ApiModelProperty(value = "行程时间")
private Double travelTime;
@ApiModelProperty(value = "平均延误")
private Double delayTime;
@ApiModelProperty(value = "停车次数")
private Double stopTimes;
@ApiModelProperty(value = "方向")
private String direction;
@ApiModelProperty(value = "绿波id")
private String greenId;
@ApiModelProperty(value = "时间颗粒度")
private String startTime;
@ApiModelProperty(value = "结束时间")
private String endTime;
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="net.wanji.opt.dao.mapper.TrunkLineStatusDisMapper">
<!-- 绿波路口查询 -->
<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
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>
<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
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>
</mapper>
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