Commit 3a2c806f authored by zhoushiguang's avatar zhoushiguang
parents e7dd5256 d4d3e8d1
package net.wanji.opt.common;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.dto.CrossEventDTO;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
......@@ -17,6 +17,7 @@ import java.util.Set;
* Created on 2019/4/29 20:34
*/
@Component
@Slf4j
public class RedisUtils {
@Resource
......@@ -25,19 +26,24 @@ public class RedisUtils {
/**
* 7号库获取最大 score zset 元素
*/
public Object getMaxScoreElement(String redisKey) throws JsonProcessingException {
ObjectMapper objectMapper = new ObjectMapper();
ZSetOperations<String, Object> zSetOps = redis7Template.opsForZSet();
Set<Object> result = zSetOps.reverseRange(redisKey, 0, -1);
public Object getMaxScoreElement(String redisKey) throws Exception {
try {
ObjectMapper objectMapper = new ObjectMapper();
ZSetOperations<String, Object> zSetOps = redis7Template.opsForZSet();
Set<Object> result = zSetOps.reverseRange(redisKey, 0, -1);
if (result != null && !result.isEmpty()) {
for (Object o : result) {
CrossEventDTO dto = objectMapper.readValue(o.toString(), CrossEventDTO.class);
String msgType = dto.getMsgType();
if (msgType.startsWith("50")) {
return o;
if (result != null && !result.isEmpty()) {
for (Object o : result) {
CrossEventDTO dto = objectMapper.readValue(o.toString(), CrossEventDTO.class);
String msgType = dto.getMsgType();
if (msgType.startsWith("50")) {
return o;
}
}
}
log.error("redis获取数据key:{}, 获取value:{}", redisKey, result);
} catch (Exception e) {
//throw new RuntimeException(e);
}
return null;
}
......
package net.wanji.opt.controller;
import com.fasterxml.jackson.core.JsonProcessingException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
......@@ -73,7 +72,7 @@ public class TrendController {
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = GreenwaveDetailVO.class),
})
public JsonViewObject greenwaveDetail(@RequestBody GreenwaveDetailBO bo) {
public JsonViewObject greenwaveDetail(@RequestBody GreenwaveDetailBO bo) throws Exception {
GreenwaveDetailVO res = trendService.greenwaveDetail(bo);
return JsonViewObject.newInstance().success(res);
}
......@@ -109,8 +108,7 @@ public class TrendController {
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = GreenwaveCrossMetricsVO.class),
})
public JsonViewObject greenwaveCrossMetrics(@RequestBody GreenwaveIdAndTimeStampBO greenwaveIdAndTimeStampBO)
throws JsonProcessingException {
public JsonViewObject greenwaveCrossMetrics(@RequestBody GreenwaveIdAndTimeStampBO greenwaveIdAndTimeStampBO) throws Exception {
List<GreenwaveCrossMetricsVO> res = trendService.greenwaveCrossMetrics(greenwaveIdAndTimeStampBO);
return JsonViewObject.newInstance().success(res);
}
......
......@@ -95,8 +95,10 @@ public class CrossLaneSnapshotDataDTO {
private double endV;
/**
* 是否溢出状态
* 0=未溢出,1=溢出
*/
private String overflow;
private boolean overflow;
/**
* 溢出区车辆数
*/
private String overflowNums;
}
package net.wanji.opt.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.vo.GreenwaveListVO;
import net.wanji.opt.bo.*;
......@@ -35,9 +34,9 @@ public interface TrendService {
List<GreenwaveRunMonitorVO> greenwaveRunMonitor(GreenwaveIdBO greenwaveIdBO);
GreenwaveDetailVO greenwaveDetail(GreenwaveDetailBO greenwaveDetailBO);
GreenwaveDetailVO greenwaveDetail(GreenwaveDetailBO greenwaveDetailBO) throws Exception;
List<GreenwaveCrossMetricsVO> greenwaveCrossMetrics(GreenwaveIdAndTimeStampBO greenwaveIdAndTimeStampBO) throws JsonProcessingException;
List<GreenwaveCrossMetricsVO> greenwaveCrossMetrics(GreenwaveIdAndTimeStampBO greenwaveIdAndTimeStampBO) throws Exception;
void saveGreenwaveStrategy(SaveGreenwaveStrategyBO saveGreenwaveStrategyBO);
......
......@@ -37,7 +37,7 @@ public class LaneSnapshotDataQueryService implements LaneSnapshotService {
@Override
public List<CrossLaneSnapshotDataDTO> queryByCrossIdAndTimeSpan(
String crossId, int startTimeStamp, int endTimeStamp, int pageNum, String laneId)
String crossId, int startTimeStamp, int endTimeStamp, int pageNum, String laneId, boolean overFlow)
throws Exception {
List<CrossLaneSnapshotDataDTO> result = new ArrayList<>();
......@@ -50,10 +50,20 @@ public class LaneSnapshotDataQueryService implements LaneSnapshotService {
.gte(startTimeStamp)
.lte(endTimeStamp);
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(matchQuery)
.must(rangeQuery);
// 是否是溢出事件
MatchQueryBuilder overFlowQuery = null;
if (overFlow) {
overFlowQuery = QueryBuilders.matchQuery("overflow", true);
boolQuery.must(overFlowQuery);
}
// 车道号筛选
String[] split = null;
if (StringUtils.isNotBlank(laneId)) {
split = laneId.split(",");
......
......@@ -11,7 +11,8 @@ import java.util.List;
*/
public interface LaneSnapshotService {
List<CrossLaneSnapshotDataDTO> queryByCrossIdAndTimeSpan(String crossId, int startTimeStamp,
int endTimeStamp, int pageNum, String laneId) throws Exception;
int endTimeStamp, int pageNum,
String laneId, boolean overFlow) throws Exception;
int queryCountsByCrossIdAndTimeSpan(String crossId, int startTimeStamp, int endTimeStamp) throws Exception;
}
......@@ -7,7 +7,6 @@ import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.excel.util.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.*;
......@@ -498,7 +497,7 @@ public class TrendServiceImpl implements TrendService {
}
@Override
public GreenwaveDetailVO greenwaveDetail(GreenwaveDetailBO greenwaveDetailBO) {
public GreenwaveDetailVO greenwaveDetail(GreenwaveDetailBO greenwaveDetailBO) throws Exception {
String greenwaveName = greenwaveDetailBO.getGreenwaveName();
String startDate = greenwaveDetailBO.getStartDate();
String endDate = greenwaveDetailBO.getEndDate();
......@@ -796,7 +795,7 @@ public class TrendServiceImpl implements TrendService {
}
private List<GreenwaveDetailVO.GreenwaveCross> buildGreenwaveCrossList(
Integer greenwaveId, String greenwaveName, String startDate, String endDate) {
Integer greenwaveId, String greenwaveName, String startDate, String endDate) throws Exception {
String[] split = greenwaveName.split(" "); // 旅游路 东向西 转山西路至霞景路路段:正向绿波 工作日 19:00-20:00
String s = split[4]; // 19:00-20:00
......@@ -965,7 +964,7 @@ public class TrendServiceImpl implements TrendService {
}
private Double calcSpeed(String greenwaveName, String crossId,
String startTime, String endTime, String startDate, String endDate) {
String startTime, String endTime, String startDate, String endDate) throws Exception{
// 确定协调方向
String[] split = greenwaveName.split(" ");
String dirStr = split[1];
......@@ -1013,9 +1012,7 @@ public class TrendServiceImpl implements TrendService {
}
@Override
public List<GreenwaveCrossMetricsVO> greenwaveCrossMetrics(GreenwaveIdAndTimeStampBO greenwaveIdAndTimeStampBO)
throws JsonProcessingException {
public List<GreenwaveCrossMetricsVO> greenwaveCrossMetrics(GreenwaveIdAndTimeStampBO greenwaveIdAndTimeStampBO) throws Exception {
List<GreenwaveCrossMetricsVO> res = new ArrayList<>();
Long timeStamp = greenwaveIdAndTimeStampBO.getTimeStamp();
......@@ -1081,14 +1078,19 @@ public class TrendServiceImpl implements TrendService {
return res;
}
private Integer calcTravelTime(String crossId, Integer inDir) throws JsonProcessingException {
// 从 Redis 中获取路段行程时间
String redisKey = crossId + ":" + inDir;
Object element = redisUtils.getMaxScoreElement(redisKey);
ObjectMapper objectMapper = new ObjectMapper();
if (element != null) {
CrossEventDTO dto = objectMapper.readValue(element.toString(), CrossEventDTO.class);
return dto.getTransitTime().intValue();
private Integer calcTravelTime(String crossId, Integer inDir) throws Exception {
try {
// 从 Redis 中获取路段行程时间
String redisKey = crossId + ":" + inDir;
Object element = redisUtils.getMaxScoreElement(redisKey);
ObjectMapper objectMapper = new ObjectMapper();
if (element != null) {
CrossEventDTO dto = objectMapper.readValue(element.toString(), CrossEventDTO.class);
return dto.getTransitTime().intValue();
}
} catch (Exception e) {
log.error("获取绿波旅行时间异常:", e);
throw new RuntimeException(e);
}
return 0;
}
......@@ -1290,7 +1292,8 @@ public class TrendServiceImpl implements TrendService {
element.setMailSpeed(Math.round(dto.getEndV() * 100.0) / 100.0);
element.setTeamHeadDistance(Math.round(dto.getTeamHeadDistance() * 100.0) / 100.0);
element.setTeamTailDistance(Math.round(dto.getTeamTailDistance() * 100.0) / 100.0);
element.setStdSpaceHeadway(Math.round(dto.getStdSpaceHeadway() * 100.0) / 100.0);
element.setStdSpaceHeadway(Math.round(dto.getVehicleLengthRatio() * 100.0));
element.setOverflowNums(dto.getOverflowNums());
res.add(element);
}
......@@ -1324,7 +1327,7 @@ public class TrendServiceImpl implements TrendService {
// 查询秒级数据
List<CrossLaneSnapshotDataDTO> dtoList =
laneSnapshotDataQueryService.queryByCrossIdAndTimeSpan(crossId, realTimeStartTimeStamp,
endTimeStamp, 0, null);
endTimeStamp, 0, null, false);
tableQueryVO.setRealTimeData(buildRealTimeList(dtoList));
// 查询周期数据
......@@ -1396,9 +1399,9 @@ public class TrendServiceImpl implements TrendService {
vo.setTimeOccupancy((int) Math.round(timeOccupancyDouble * 100));
}
Double vehicleNumsRatioMeanDoulbe = po.getVehicleNumsRatioMean();
if (vehicleNumsRatioMeanDoulbe != null) {
vo.setVehicleNumsRatioMean((int) Math.round(vehicleNumsRatioMeanDoulbe * 100));
Double vehicleLengthRatioMean = po.getVehicleLengthRatioMean();
if (vehicleLengthRatioMean != null) {
vo.setVehicleNumsRatioMean((int) Math.round(vehicleLengthRatioMean * 100));
}
vo.setVehheadDist(po.getVehheadDist());
......@@ -1947,9 +1950,11 @@ public class TrendServiceImpl implements TrendService {
int end = (int) (laneSnapshotIndexVO.getEnd().getTime() / 1000);
int pageNum = laneSnapshotIndexVO.getPageNum();
String laneId = laneSnapshotIndexVO.getLaneId();
boolean overFlow = laneSnapshotIndexVO.isOverFlow();
// 查询秒级数据
List<CrossLaneSnapshotDataDTO> dtoList =
laneSnapshotDataQueryService.queryByCrossIdAndTimeSpan(crossId, start, end, pageNum, laneId);
laneSnapshotDataQueryService.queryByCrossIdAndTimeSpan(crossId, start, end, pageNum, laneId, overFlow);
List<TableQueryVO.RealTimeDataElement> result = buildRealTimeList(dtoList);
List<TableQueryVO.RealTimeDataElement> sorts = new ArrayList<>();
if (!CollectionUtils.isEmpty(result)) {
......@@ -2005,8 +2010,16 @@ public class TrendServiceImpl implements TrendService {
results.add(holoEventInfoPO);
}
}
} else {
results = holoEventInfoPOS;
}
results = holoEventInfoPOS;
String crossName = crossInfoCache.getCrossName(crossId);
results.forEach(holoEventInfoPO -> {
if (Objects.isNull(holoEventInfoPO.getPlaceDesc())) {
holoEventInfoPO.setPlaceDesc(crossName);
}
});
return results;
} catch (Exception e) {
log.error("全息事件查询异常:", e);
......@@ -2179,7 +2192,7 @@ public class TrendServiceImpl implements TrendService {
String laneId = laneSnapshotIndexVO.getLaneId();
// 查询秒级数据
List<CrossLaneSnapshotDataDTO> dtoList =
laneSnapshotDataQueryService.queryByCrossIdAndTimeSpan(crossId, start, end, -1, laneId);
laneSnapshotDataQueryService.queryByCrossIdAndTimeSpan(crossId, start, end, -1, laneId, false);
List<TableQueryVO.RealTimeDataElement> result = buildRealTimeList(dtoList);
List<TableQueryVO.RealTimeDataElement> dataList = new ArrayList<>();
if (!CollectionUtils.isEmpty(result)) {
......
......@@ -27,4 +27,6 @@ public class LaneSnapshotIndexVO extends PageNumVO {
@NotNull(message = "结束时间不能为空")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date end;
@ApiModelProperty(value = "溢出数据")
private boolean overFlow;
}
......@@ -96,9 +96,14 @@ public class TableQueryVO {
@ExcelProperty("队尾距离")
private double teamTailDistance;
@ApiModelProperty(value = "车头间距方差>车道内空间占有率")
@ExcelProperty("空间占有率")
@ApiModelProperty(value = "空间长度占比>车道内空间占有率")
@ExcelProperty("空间占有率%")
private double stdSpaceHeadway;
@ApiModelProperty(value = "溢出区车辆数")
@ExcelProperty("溢出区车辆数")
private String overflowNums;
}
@NoArgsConstructor
......@@ -149,12 +154,12 @@ public class TableQueryVO {
private Double vehheadDist;
@ApiModelProperty(value = "时间占有率")
@ExcelProperty("平均时间占有率")
@ExcelProperty("平均时间占有率%")
private Integer timeOccupancy;
@ApiModelProperty(value = "空间占有率")
// 空间占有率即车辆负荷比
@ExcelProperty("平均空间占有率")
// 空间长度占比 todo字段名称展示先不改了
@ExcelProperty("平均空间占有率%")
private Integer vehicleNumsRatioMean;
@ExcelProperty("85位速度")
private double v85;
......
......@@ -67,6 +67,8 @@ public class CrossLaneDataRealTimePO {
private Double greenLightEfficiency;
@ApiModelProperty(value = "车辆负荷比", notes = "")
private Double vehicleNumsRatioMean;
@ApiModelProperty(value = "空间长度占比", notes = "")
private Double vehicleLengthRatioMean;
@ApiModelProperty(value = "时间占有率", notes = "")
private Double timeOccupancy;
......
......@@ -28,6 +28,7 @@
<result column="effusion_rate" property="effusionRate"></result>
<result column="green_light_efficiency" property="greenLightEfficiency"></result>
<result column="vehicle_nums_ratio_mean" property="vehicleNumsRatioMean"></result>
<result column="vehicle_length_ratio_mean" property="vehicleLengthRatioMean"></result>
<result column="time_occupancy" property="timeOccupancy"></result>
<result column="non_motor_flow" property="nonMotorFlow"></result>
<result column="v_85" property="v85"></result>
......@@ -40,7 +41,7 @@
id, cross_id, flow, speed, in_speed, out_speed, queue_length, stop_times, delay_time, capacity, sturation,
vehhead_dist, vehhead_time, quality, batch_time, gmt_create, gmt_modified,
no_stop_rate,one_stop_rate,two_stop_rate,three_stop_rate,start_time,effusion_rate,green_light_efficiency,
vehicle_nums_ratio_mean,time_occupancy,non_motor_flow,v_85,traffic_flow_A,traffic_flow_B,traffic_flow_C
vehicle_nums_ratio_mean,vehicle_length_ratio_mean,time_occupancy,non_motor_flow,v_85,traffic_flow_A,traffic_flow_B,traffic_flow_C
</sql>
<insert id="insertBatch" parameterType="net.wanji.databus.po.CrossLaneDataHistPO">
......@@ -51,7 +52,7 @@
(#{entity.id},#{entity.crossId},#{entity.flow},#{entity.speed},#{entity.inSpeed},#{entity.outSpeed},#{entity.queueLength},#{entity.stopTimes},#{entity.delayTime},#{entity.capacity},#{entity.sturation},
#{entity.vehheadDist},#{entity.vehheadTime},#{entity.quality},#{entity.batchTime},#{entity.gmtCreate},#{entity.gmtModified},
#{entity.noStopRate},#{entity.oneStopRate},#{entity.twoStopRate},#{entity.threeStopRate},#{entity.startTime},
#{entity.effusionRate},#{entity.greenLightEfficiency},#{entity.vehicleNumsRatioMean},#{entity.timeOccupancy},
#{entity.effusionRate},#{entity.greenLightEfficiency},#{entity.vehicleNumsRatioMean},#{entity.vehicleLengthRatioMean},#{entity.timeOccupancy},
#{entity.nonMotorFlow},#{entity.v85},#{entity.trafficFlowA},#{entity.trafficFlowB},#{entity.trafficFlowC})
</foreach>
</insert>
......@@ -105,7 +106,8 @@
<select id="selectByCrossIdAndTimeSpan" resultType="net.wanji.databus.po.CrossLaneDataHistPOExt">
SELECT t1.id, t2.dir,t2.turn, t2.sort, t1.flow, t1.speed, t1.queue_length, t1.delay_time, t1.stop_times,
t1.vehhead_time,t1.vehhead_dist, t1.batch_time, t1.time_occupancy, t1.vehicle_nums_ratio_mean, t1.start_time,
t1.traffic_flow_A, t1.traffic_flow_B, t1.traffic_flow_C,t1.v_85, t1.non_motor_flow, t1.time_occupancy
t1.traffic_flow_A, t1.traffic_flow_B, t1.traffic_flow_C,t1.v_85, t1.non_motor_flow,
t1.time_occupancy, t1.vehicle_length_ratio_mean
FROM t_lane_data_hist t1 JOIN t_base_lane_info t2 ON t1.id = t2.id
where t1.cross_id = #{crossId}
and batch_time <![CDATA[ >= ]]> #{startTimeStamp}
......
......@@ -27,6 +27,7 @@
<result column="start_time" property="startTime"></result>
<result column="effusion_rate" property="effusionRate"></result>
<result column="vehicle_nums_ratio_mean" property="vehicleNumsRatioMean"></result>
<result column="vehicle_length_ratio_mean" property="vehicleLengthRatioMean"></result>
<result column="time_occupancy" property="timeOccupancy"></result>
<result column="non_motor_flow" property="nonMotorFlow"></result>
<result column="v_85" property="v85"></result>
......@@ -39,7 +40,7 @@
id, cross_id, flow, speed, in_speed, out_speed, queue_length, stop_times, delay_time, capacity, sturation,
vehhead_dist, vehhead_time, quality, batch_time, gmt_create, gmt_modified,
no_stop_rate,one_stop_rate,two_stop_rate,three_stop_rate,start_time,effusion_rate,green_light_efficiency,
vehicle_nums_ratio_mean,time_occupancy,non_motor_flow,v_85,traffic_flow_A,traffic_flow_B,traffic_flow_C
vehicle_nums_ratio_mean,vehicle_length_ratio_mean,time_occupancy,non_motor_flow,v_85,traffic_flow_A,traffic_flow_B,traffic_flow_C
</sql>
<insert id="insertBatch" parameterType="net.wanji.databus.po.CrossLaneDataRealTimePO">
......@@ -50,7 +51,7 @@
(#{entity.id},#{entity.crossId},#{entity.flow},#{entity.speed},#{entity.inSpeed},#{entity.outSpeed},#{entity.queueLength},#{entity.stopTimes},#{entity.delayTime},#{entity.capacity},#{entity.sturation},
#{entity.vehheadDist},#{entity.vehheadTime},#{entity.quality},#{entity.batchTime},#{entity.gmtCreate},#{entity.gmtModified},
#{entity.noStopRate},#{entity.oneStopRate},#{entity.twoStopRate},#{entity.threeStopRate},#{entity.startTime},
#{entity.effusionRate},#{entity.greenLightEfficiency},#{entity.vehicleNumsRatioMean},#{entity.timeOccupancy},
#{entity.effusionRate},#{entity.greenLightEfficiency},#{entity.vehicleNumsRatioMean},#{entity.vehicleLengthRatioMean},#{entity.timeOccupancy},
#{entity.nonMotorFlow},#{entity.v85},#{entity.trafficFlowA},#{entity.trafficFlowB},#{entity.trafficFlowC})
</foreach>
</insert>
......
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