Commit d21b45a8 authored by hanbing's avatar hanbing

信控优化-态势监测,问题路口列表

parent b3ef37c8
......@@ -5,8 +5,10 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.dto.trend.AbnormalCrossListDTO;
import net.wanji.opt.dto.trend.GreenwaveListDTO;
import net.wanji.opt.service.impl.TrendServiceImpl;
import net.wanji.opt.vo.AbnormalCrossVO;
import net.wanji.opt.vo.GreenwaveListVO;
import net.wanji.opt.vo.GreenwaveStats;
import net.wanji.opt.vo.GreenwaveVO;
......@@ -45,10 +47,26 @@ public class TrendController {
List<GreenwaveListVO> greenwaveListVOList = trendService.greenwaveList(greenwaveListDTO);
greenwaveVO.setGreenwaveList(greenwaveListVOList);
// 绿波统计信息
GreenwaveStats greenwaveStats = trendService.buildGreenwaveStats(greenwaveListVOList);
GreenwaveListDTO forStats = new GreenwaveListDTO();
List<GreenwaveListVO> greenwaveListForStats = trendService.greenwaveList(forStats);
GreenwaveStats greenwaveStats = trendService.buildGreenwaveStats(greenwaveListForStats);
greenwaveVO.setGreenwaveStats(greenwaveStats);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(greenwaveVO);
}
@ApiOperation(value = "问题路口列表", notes = "问题路口列表", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/abnormalCrossList",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = GreenwaveVO.class),
})
public JsonViewObject abnormalCrossList(@RequestBody AbnormalCrossListDTO abnormalCrossListDTO) {
AbnormalCrossVO abnormalCrossVO = trendService.abnormalCrossList(abnormalCrossListDTO);
JsonViewObject jsonViewObject = JsonViewObject.newInstance();
return jsonViewObject.success(abnormalCrossVO);
}
}
\ No newline at end of file
package net.wanji.opt.dao.mapper.trend;
import net.wanji.opt.vo.AbnormalCrossListVO;
import org.springframework.stereotype.Repository;
import java.util.List;
/**
* 态势监测-问题路口基础信息
*
* @author Kent HAN
* @date 2023/2/8 9:22
*/
@Repository
public interface CrossDataRealtimeMapper {
List<AbnormalCrossListVO> selectAbnormalCross(Integer status, String name, Integer type);
}
package net.wanji.opt.dto.trend;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "AbnormalCrossListDTO", description = "问题路口列表输入参数")
public class AbnormalCrossListDTO {
@ApiModelProperty(value = "路口状态 1失衡 2拥堵 3溢出", notes = "", required = false)
private Integer status;
@ApiModelProperty(value = "路口名称", notes = "", required = false)
private String name;
@ApiModelProperty(value = "拥堵类型:1常发性;2偶发性", notes = "", required = false)
private Integer type;
}
......@@ -5,9 +5,9 @@ import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "GreenwaveListDTO", description = "问题子区列表")
@ApiModel(value = "GreenwaveListDTO", description = "问题子区列表输入参数")
public class GreenwaveListDTO {
@ApiModelProperty(value = "交通状态 0畅通 1缓行 2拥堵", notes = "", required = false)
@ApiModelProperty(value = "交通状态 1畅通 2缓行 3拥堵", notes = "", required = false)
private Integer status;
@ApiModelProperty(value = "子区名称", notes = "", required = false)
private String name;
......
package net.wanji.opt.po.trend;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* @author hfx
* @date 2023/1/10 16:36
* @desc CrossDataRealtimePO
*/
@Data
public class CrossDataRealtimePO {
/** 路口编号 */
@ApiModelProperty(name = "路口编号",notes = "")
private String crossId ;
/** 路口状态:0正常;1失衡;2拥堵;3溢出;4死锁 */
@ApiModelProperty(name = "路口状态:0正常;1失衡;2拥堵;3溢出;4死锁",notes = "")
private Integer status ;
/** 拥堵类型:1常规;2异常 */
@ApiModelProperty(name = "拥堵类型:1常规;2异常",notes = "")
private Integer type ;
/** 交通指数(1~10) */
@ApiModelProperty(name = "交通指数(1~10)",notes = "")
private Double trafficIndex ;
/** 开始时间:yyyy-MM-dd HH;mm:ss */
@ApiModelProperty(name = "开始时间:yyyy-MM-dd HH",notes = "mm:ss")
private Date startTime ;
/** 持续时间(单位:分钟) */
@ApiModelProperty(name = "持续时间(单位:分钟)",notes = "")
private Integer duration ;
/** 是否失衡:0否;1是 */
@ApiModelProperty(name = "是否失衡:0否;1是",notes = "")
private Integer isUnbalance ;
/** 是否溢出:0否;1是 */
@ApiModelProperty(name = "是否溢出:0否;1是",notes = "")
private Integer isSpillover ;
/** 是否拥堵:0否;1是 */
@ApiModelProperty(name = "是否拥堵:0否;1是",notes = "")
private Integer isCongestion ;
/** 失衡指数 */
@ApiModelProperty(name = "失衡指数",notes = "")
private Double unbalanceIndex ;
/** 溢出指数 */
@ApiModelProperty(name = "溢出指数",notes = "")
private Double spilloverIndex ;
/** 拥堵指数 */
@ApiModelProperty(name = "拥堵指数",notes = "")
private Double congestionIndex ;
/** 路口失衡方向:1,2,3... */
@ApiModelProperty(name = "路口失衡方向:1,2,3...",notes = "")
private String unbalanceDirs ;
/** 路口溢出方向:1,2,3... */
@ApiModelProperty(name = "路口溢出方向:1,2,3...",notes = "")
private String spilloverDirs ;
/** 路口拥堵方向:1,2,3... */
@ApiModelProperty(name = "路口拥堵方向:1,2,3...",notes = "")
private String congestionDirs ;
/** 交通流量(辆) */
@ApiModelProperty(name = "交通流量(辆)",notes = "")
private Integer flow ;
/** 交通流率/h */
@ApiModelProperty(name = "交通流率/h",notes = "")
private Double flowRate ;
/** 平均速度(km/h) */
@ApiModelProperty(name = "平均速度(km/h)",notes = "")
private Double speed ;
/** 最大排队(米) */
@ApiModelProperty(name = "最大排队(米)",notes = "")
private Double queueLength ;
/** 停车次数(次) */
@ApiModelProperty(name = "停车次数(次)",notes = "")
private Double stopTimes ;
/** 延误时间(秒) */
@ApiModelProperty(name = "延误时间(秒)",notes = "")
private Integer delayTime ;
/** 饱和度 */
@ApiModelProperty(name = "饱和度",notes = "")
private Double sturation ;
/** 采集时间(10位时间戳) */
@ApiModelProperty(name = "采集时间(10位时间戳)",notes = "")
private Integer batchTime ;
/** 创建时间 */
@ApiModelProperty(name = "创建时间",notes = "")
private Date gmtCreate ;
/** 修改时间 */
@ApiModelProperty(name = "修改时间",notes = "")
private Date gmtModified ;
}
package net.wanji.opt.service;
import net.wanji.opt.dto.trend.AbnormalCrossListDTO;
import net.wanji.opt.dto.trend.GreenwaveListDTO;
import net.wanji.opt.vo.AbnormalCrossVO;
import net.wanji.opt.vo.GreenwaveListVO;
import net.wanji.opt.vo.GreenwaveStats;
......@@ -15,4 +17,6 @@ public interface TrendService {
List<GreenwaveListVO> greenwaveList(GreenwaveListDTO greenwaveListDTO);
GreenwaveStats buildGreenwaveStats(List<GreenwaveListVO> greenwaveListVOList);
AbnormalCrossVO abnormalCrossList(AbnormalCrossListDTO abnormalCrossListDTO);
}
package net.wanji.opt.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import net.wanji.common.utils.tool.CrossUtil;
import net.wanji.opt.dao.mapper.CrossInfoMapper;
import net.wanji.opt.dao.mapper.trend.CrossDataRealtimeMapper;
import net.wanji.opt.dao.mapper.trend.GreenwaveInfoMapper;
import net.wanji.opt.dto.trend.AbnormalCrossListDTO;
import net.wanji.opt.dto.trend.GreenwaveListDTO;
import net.wanji.opt.po.base.CrossInfoPO;
import net.wanji.opt.service.TrendService;
import net.wanji.opt.vo.AbnormalCrossListVO;
import net.wanji.opt.vo.AbnormalCrossStats;
import net.wanji.opt.vo.AbnormalCrossVO;
import net.wanji.opt.vo.GreenwaveListVO;
import net.wanji.opt.vo.GreenwaveStats;
import org.springframework.stereotype.Service;
......@@ -24,10 +30,12 @@ import java.util.List;
public class TrendServiceImpl implements TrendService {
private final GreenwaveInfoMapper greenwaveInfoMapper;
private final CrossInfoMapper crossInfoMapper;
private final CrossDataRealtimeMapper crossDataRealtimeMapper;
public TrendServiceImpl(GreenwaveInfoMapper greenwaveInfoMapper, CrossInfoMapper crossInfoMapper) {
public TrendServiceImpl(GreenwaveInfoMapper greenwaveInfoMapper, CrossInfoMapper crossInfoMapper, CrossDataRealtimeMapper crossDataRealtimeMapper) {
this.greenwaveInfoMapper = greenwaveInfoMapper;
this.crossInfoMapper = crossInfoMapper;
this.crossDataRealtimeMapper = crossDataRealtimeMapper;
}
@Override
......@@ -36,15 +44,12 @@ public class TrendServiceImpl implements TrendService {
String name = greenwaveListDTO.getName();
Integer type = greenwaveListDTO.getType();
List<GreenwaveListVO> greenwaveListVOList = greenwaveInfoMapper.listGreenwave(status, name, type);
// 2以上都算拥堵
if (status != null && status == 2) {
List<GreenwaveListVO> extraList1 = greenwaveInfoMapper.listGreenwave(3, name, type);
changeStatus(extraList1);
List<GreenwaveListVO> extraList2 = greenwaveInfoMapper.listGreenwave(4, name, type);
changeStatus(extraList2);
greenwaveListVOList.addAll(extraList1);
greenwaveListVOList.addAll(extraList2);
// 3以上都算拥堵
if (status != null && status == 3) {
List<GreenwaveListVO> extraList = greenwaveInfoMapper.listGreenwave(4, name, type);
greenwaveListVOList.addAll(extraList);
}
changeStatus(greenwaveListVOList);
for (GreenwaveListVO greenwaveListVO : greenwaveListVOList) {
// 计算持续时间
buildDuration(greenwaveListVO);
......@@ -64,11 +69,11 @@ public class TrendServiceImpl implements TrendService {
Integer congestion = greenwaveStats.getCongestion();
for (GreenwaveListVO greenwaveListVO : greenwaveListVOList) {
Integer realtimeStatus = greenwaveListVO.getRealtimeStatus();
if (realtimeStatus == 0) {
if (realtimeStatus == 1) {
smooth += 1;
} else if (realtimeStatus == 1) {
slow += 1;
} else if (realtimeStatus == 2) {
slow += 1;
} else if (realtimeStatus == 3) {
congestion += 1;
}
}
......@@ -78,10 +83,70 @@ public class TrendServiceImpl implements TrendService {
return greenwaveStats;
}
private static void changeStatus(List<GreenwaveListVO> extraList1) {
if (extraList1 != null) {
for (GreenwaveListVO greenwaveListVO : extraList1) {
greenwaveListVO.setRealtimeStatus(2);
@Override
public AbnormalCrossVO abnormalCrossList(AbnormalCrossListDTO abnormalCrossListDTO) {
AbnormalCrossVO abnormalCrossVO = new AbnormalCrossVO();
// 构建问题路口列表
Integer status = abnormalCrossListDTO.getStatus();
String name = abnormalCrossListDTO.getName();
Integer type = abnormalCrossListDTO.getType();
List<AbnormalCrossListVO> abnormalCrossListVOList =
crossDataRealtimeMapper.selectAbnormalCross(status, name, type);
// 坐标格式转换
for (AbnormalCrossListVO abnormalCrossListVO : abnormalCrossListVOList) {
String locationStr = abnormalCrossListVO.getLocationStr();
double[] lonLat = CrossUtil.getLonLat(locationStr);
List<Double> location = new ArrayList<>();
location.add(lonLat[0]);
location.add(lonLat[1]);
abnormalCrossListVO.setLocation(location);
}
abnormalCrossVO.setAbnormalCrossList(abnormalCrossListVOList);
// 构造统计信息
List<AbnormalCrossListVO> listForStats =
crossDataRealtimeMapper.selectAbnormalCross(null, null, null);
buildAbnormalCrossStats(abnormalCrossVO, listForStats);
return abnormalCrossVO;
}
private static void buildAbnormalCrossStats(AbnormalCrossVO abnormalCrossVO,
List<AbnormalCrossListVO> abnormalCrossListVOList) {
AbnormalCrossStats abnormalCrossStats = new AbnormalCrossStats();
Integer unbalance = abnormalCrossStats.getUnbalance();
Integer congestion = abnormalCrossStats.getCongestion();
Integer spillover = abnormalCrossStats.getSpillover();
for (AbnormalCrossListVO abnormalCrossListVO : abnormalCrossListVOList) {
Integer realtimeStatus = abnormalCrossListVO.getRealtimeStatus();
if (realtimeStatus == 1) {
unbalance += 1;
} else if (realtimeStatus == 2) {
congestion += 1;
} else if (realtimeStatus == 3) {
spillover += 1;
}
if (abnormalCrossListVO.getIsUnbalance() == 1) {
unbalance += 1;
}
if (abnormalCrossListVO.getIsCongestion() ==1) {
congestion += 1;
}
if (abnormalCrossListVO.getIsSpillover() == 1) {
spillover += 1;
}
}
abnormalCrossStats.setUnbalance(unbalance);
abnormalCrossStats.setCongestion(congestion);
abnormalCrossStats.setSpillover(spillover);
abnormalCrossVO.setAbnormalCrossStats(abnormalCrossStats);
}
private static void changeStatus(List<GreenwaveListVO> greenwaveListVOList) {
if (greenwaveListVOList != null) {
for (GreenwaveListVO greenwaveListVO : greenwaveListVOList) {
if (greenwaveListVO.getRealtimeStatus() == 4) {
greenwaveListVO.setRealtimeStatus(3);
}
}
}
}
......@@ -89,7 +154,7 @@ public class TrendServiceImpl implements TrendService {
private List<GreenwaveListVO.CrossListElement> buildCrossList(String greenwaveId) {
List<GreenwaveListVO.CrossListElement> crossList = new ArrayList<>();
List<String> crossIdList = greenwaveInfoMapper.selectCrossIdsById(greenwaveId);
if (crossIdList != null) {
if (CollectionUtil.isNotEmpty(crossIdList)) {
List<CrossInfoPO> crossInfoPOList = crossInfoMapper.selectByCrossIds(crossIdList);
for (CrossInfoPO crossInfoPO : crossInfoPOList) {
GreenwaveListVO.CrossListElement crossListElement = new GreenwaveListVO.CrossListElement();
......
package net.wanji.opt.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
@NoArgsConstructor
@Data
@ApiModel(value = "AbnormalCrossListVO", description = "问题路口列表元素")
public class AbnormalCrossListVO {
@ApiModelProperty(value = "路口ID")
private String id;
@ApiModelProperty(value = "路口名称")
private String name;
@ApiModelProperty(value = "失衡方向 如 1,2,3")
private String unbalanceDirs;
@ApiModelProperty(value = "拥堵方向 如 1,2,3")
private String congestionDirs;
@ApiModelProperty(value = "溢出方向 如 1,2,3")
private String spilloverDirs;
@ApiModelProperty(value = "路口状态 1失衡 2拥堵 3溢出")
private Integer realtimeStatus;
@ApiModelProperty(value = "开始时间 格式 08:20:23")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
private Date startTime;
@ApiModelProperty(value = "持续时长 分钟")
private Long duration;
@JsonIgnore
// 路口坐标字符串
private String locationStr;
@ApiModelProperty(value = "路口坐标")
private List<Double> location;
@JsonIgnore
// 是否失衡:0否;1是
private Integer isUnbalance;
@JsonIgnore
// 是否溢出:0否;1是
private Integer isSpillover;
@JsonIgnore
// 是否拥堵:0否;1是
private Integer isCongestion;
}
package net.wanji.opt.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* @author Kent HAN
* @date 2023/2/8 13:47
*/
@NoArgsConstructor
@Data
@ApiModel(value = "AbnormalCrossStats", description = "问题路口统计信息")
public class AbnormalCrossStats {
@ApiModelProperty(value = "失衡数量")
private Integer unbalance = 0;
@ApiModelProperty(value = "拥堵数量")
private Integer congestion = 0;
@ApiModelProperty(value = "溢出数量")
private Integer spillover = 0;
}
package net.wanji.opt.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@NoArgsConstructor
@Data
@ApiModel(value = "AbnormalCrossVO", description = "查询问题路口返回值")
public class AbnormalCrossVO {
@ApiModelProperty(value = "问题路口统计信息")
private AbnormalCrossStats abnormalCrossStats;
@ApiModelProperty(value = "问题路口列表")
private List<AbnormalCrossListVO> abnormalCrossList;
}
......@@ -19,20 +19,22 @@ public class GreenwaveListVO {
private String name;
@ApiModelProperty(value = "协调方式")
private Integer infoStatus;
@ApiModelProperty(value = "路口状态:0畅通;1缓行;2拥堵")
@ApiModelProperty(value = "路口状态:1畅通;2缓行;3拥堵")
private Integer realtimeStatus;
@ApiModelProperty(value = "拥堵指数")
private Double trafficIndex;
@ApiModelProperty(value = "开始时间 格式 08:20:23")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
private Date startTime;
@ApiModelProperty(value = "开始时间 格式 08:20:23")
@ApiModelProperty(value = "结束时间 格式 08:20:23")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss")
private Date endTime;
@ApiModelProperty(value = "持续时长 分钟")
private Long duration;
@ApiModelProperty(value = "区域边界")
private String polylines;
@ApiModelProperty(value = "wkt坐标")
private String wkt;
@ApiModelProperty(value = "路口列表")
private List<CrossListElement> crossList;
......
<?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.trend.CrossDataRealtimeMapper">
<select id="selectAbnormalCross" resultType="net.wanji.opt.vo.AbnormalCrossListVO">
select
t2.id, t2.name, t1.unbalance_dirs, t1.congestion_dirs, t1.spillover_dirs, t1.status as realtimeStatus,
t1.start_time, t1.duration, t2.location as locationStr, t1.is_unbalance, t1.is_spillover, t1.is_congestion
from t_cross_data_realtime t1 JOIN t_base_cross_info t2
ON t1.cross_id = t2.id
<where>
<if test="status != null">
and t1.status = #{status} or
<if test="status == 1">t1.is_unbalance = 1 </if>
<if test="status == 2">t1.is_congestion = 1 </if>
<if test="status == 3">t1.is_spillover = 1 </if>
</if>
<if test="name != null and name != ''">
and t2.name like concat('%',#{name},'%')
</if>
<if test="type != null">
and t1.type = #{type}
</if>
</where>
</select>
</mapper>
......@@ -5,14 +5,14 @@
<select id="listGreenwave" resultType="net.wanji.opt.vo.GreenwaveListVO">
select
t1.id, t1.name, t1.status as infoStatus, t2.status as realtimeStatus,
t2.traffic_index, t1.start_time, t1.end_time, t1.polylines
t2.traffic_index, t1.start_time, t1.end_time, t1.polylines, t2.wkt
from t_greenwave_info t1 join t_greenwave_realtime t2 on t1.id = t2.id
<where>
<if test="status != null">
and t2.status = #{status}
</if>
<if test="name != null and name != ''">
and t1.name = like concat('%',#{name},'%')
and t1.name like concat('%',#{name},'%')
</if>
<if test="type != null">
and t2.type = #{type}
......@@ -24,6 +24,7 @@
SELECT DISTINCT cross_id
FROM t_greenwave_info t1 JOIN t_greenwave_cross t2
ON t1.id = t2.green_id
WHERE t2.green_id = #{greenwaveId}
</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