Commit 1894e009 authored by duanruiming's avatar duanruiming

[add] 态势检测-优化监测优化返回结果;

parent 86352175
......@@ -25,6 +25,7 @@ import org.springframework.web.bind.annotation.RestController;
import javax.validation.Valid;
import javax.ws.rs.core.MediaType;
import java.util.Date;
import java.util.List;
/**
......
......@@ -8,14 +8,12 @@ import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.servicev2.TrendServiceV2;
import net.wanji.opt.vo2.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author duanruiming
......@@ -86,17 +84,36 @@ public class TrendControllerV2 {
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/greenOptMonitoringList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = OptMonitoringVO.class),
@ApiResponse(code = 200, message = "OK", response = OptMonitoringResultVO.class),
})
public JsonViewObject greenOptMonitoringList() throws Exception {
List<OptMonitoringVO> list = Collections.emptyList();
OptMonitoringResultVO result = new OptMonitoringResultVO();
try {
list = trendServiceV2.greenOptMonitoringList();
List<OptMonitoringVO> list = trendServiceV2.greenOptMonitoringList();
countResult(result, list);
} catch (Exception e) {
log.error("态势监测-运行监测-干线优化监测-查询异常:", e);
JsonViewObject.newInstance().success(list);
JsonViewObject.newInstance().success(result);
}
return JsonViewObject.newInstance().success(list);
return JsonViewObject.newInstance().success(result);
}
private void countResult(OptMonitoringResultVO result, List<OptMonitoringVO> list) throws Exception {
Map<String, List<OptMonitoringVO>> listMap = list.stream().collect(Collectors.groupingBy(OptMonitoringVO::getType));
List<OptMonitoringResultVO.TypeCount> typeCounts = new ArrayList<>();
for (Map.Entry<String, List<OptMonitoringVO>> entry : listMap.entrySet()) {
String key = entry.getKey();
List<OptMonitoringVO> value = entry.getValue();
OptMonitoringResultVO.TypeCount typeCount = new OptMonitoringResultVO.TypeCount();
typeCount.setType(key);
typeCount.setEventCount(value.size());
List<OptMonitoringVO> optList = value.stream().filter(vo -> Objects.equals(1, vo.getOptStatus())).collect(Collectors.toList());
typeCount.setOptCount(optList.size());
typeCounts.add(typeCount);
}
result.setTypeCount(typeCounts);
result.setOptMonitoringVOList(list);
}
@ApiOperation(value = "态势监测-运行监测-路口优化监测", notes = "态势监测-运行监测-路口优化监测",
......@@ -104,17 +121,18 @@ public class TrendControllerV2 {
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossOptMonitoringList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = OptMonitoringVO.class),
@ApiResponse(code = 200, message = "OK", response = OptMonitoringResultVO.class),
})
public JsonViewObject crossOptMonitoringList() throws Exception {
List<OptMonitoringVO> list = Collections.emptyList();
OptMonitoringResultVO result = new OptMonitoringResultVO();
try {
list = trendServiceV2.crossOptMonitoringList();
List<OptMonitoringVO> list = trendServiceV2.crossOptMonitoringList();
countResult(result, list);
} catch (Exception e) {
log.error("态势监测-运行监测-路口优化监测:", e);
JsonViewObject.newInstance().success(list);
JsonViewObject.newInstance().success(result);
}
return JsonViewObject.newInstance().success(list);
return JsonViewObject.newInstance().success(result);
}
@ApiOperation(value = "态势监测-事件告警-实时列表", notes = "态势监测-事件告警-实时列表",
......@@ -134,4 +152,44 @@ public class TrendControllerV2 {
}
return JsonViewObject.newInstance().success(list);
}
@ApiOperation(value = "态势监测-区域体检-雷达图绿波事件事件类型过滤", notes = "态势监测-区域体检-雷达图绿波事件事件类型过滤",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/selectGreenEventTypeCountTimeList",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = OptMonitoringVO.class),
})
public JsonViewObject selectGreenEventTypeCountTimeList(@RequestBody EventTypeCountTimeVO vo) throws Exception {
List<StatisticsEventTypeCountTimeVO> list = Collections.emptyList();
try {
list = trendServiceV2.selectGreenEventTypeCountTimeList(vo);
} catch (Exception e) {
log.error("态势监测-事件告警-实时列表:", e);
JsonViewObject.newInstance().success(list);
}
return JsonViewObject.newInstance().success(list);
}
@ApiOperation(value = "态势监测-区域体检-雷达图路口事件事件类型过滤", notes = "态势监测-区域体检-雷达图路口事件事件类型过滤",
response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/selectCrossEventTypeCountTimeList",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = OptMonitoringVO.class),
})
public JsonViewObject selectCrossEventTypeCountTimeList(@RequestBody EventTypeCountTimeVO vo) throws Exception {
List<StatisticsEventTypeCountTimeVO> list = Collections.emptyList();
try {
list = trendServiceV2.selectCrossEventTypeCountTimeList(vo);
} catch (Exception e) {
log.error("态势监测-事件告警-实时列表:", e);
JsonViewObject.newInstance().success(list);
}
return JsonViewObject.newInstance().success(list);
}
}
\ No newline at end of file
......@@ -15,6 +15,7 @@ import net.wanji.opt.vo2.StatisticsEventTypeCountTimeVO;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.Map;
......@@ -84,11 +85,15 @@ public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> {
* 态势监测-区域体检-雷达图事件类型过滤
* @return
*/
List<StatisticsEventTypeCountTimeVO> selectGreenEventTypeCountTimeList(@Param("type") String type, @Param("date")Date date);
List<StatisticsEventTypeCountTimeVO> selectGreenEventTypeCountTimeList(@Param("type") String type,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);
/**
* 态势监测-区域体检-雷达图事件类型过滤
* @return
*/
List<StatisticsEventTypeCountTimeVO> selectCrossEventTypeCountTimeList(@Param("type") String type, @Param("date")Date date);
List<StatisticsEventTypeCountTimeVO> selectCrossEventTypeCountTimeList(@Param("type") String type,
@Param("startTime") LocalDateTime startTime,
@Param("endTime") LocalDateTime endTime);
}
package net.wanji.opt.servicev2;
import net.wanji.opt.vo2.CrossGreenStatusTimeRateVO;
import net.wanji.opt.vo2.CrossOptInfoVO;
import net.wanji.opt.vo2.GreenOptInfoVO;
import net.wanji.opt.vo2.OptMonitoringVO;
import net.wanji.opt.vo2.*;
import java.util.List;
......@@ -24,4 +21,8 @@ public interface TrendServiceV2 {
List<OptMonitoringVO> crossOptMonitoringList() throws Exception;
List<OptMonitoringVO> eventAlarmRealTimeList() throws Exception;
List<StatisticsEventTypeCountTimeVO> selectGreenEventTypeCountTimeList(EventTypeCountTimeVO vo) throws Exception;
List<StatisticsEventTypeCountTimeVO> selectCrossEventTypeCountTimeList(EventTypeCountTimeVO vo) throws Exception;
}
\ No newline at end of file
package net.wanji.opt.servicev2.implv2;
import com.alibaba.nacos.api.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.DateUtil;
......@@ -22,8 +21,10 @@ import net.wanji.opt.vo2.dto.GreenOptDTO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
......@@ -92,7 +93,7 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
String lastWeekCrossId = crossDataHistPO.getCrossId();
Double lastWeekTrafficIndex = crossDataHistPO.getTrafficIndex();
Double lastWeekQueueLength = crossDataHistPO.getQueueLength();
if (StringUtils.equals(crossId, lastWeekCrossId)) {
if (StringUtils.endsWithIgnoreCase(crossId, lastWeekCrossId)) {
if (trafficIndex > lastWeekTrafficIndex) {
result.setTrafficIndexUpDown(1);
} else {
......@@ -139,7 +140,7 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
Double curTrafficIndex = greenwaveHistPO.getTrafficIndex();
Double curSpeed = Objects.nonNull(greenwaveHistPO.getSpeed()) ? greenwaveHistPO.getSpeed() : 0;
Integer curTravelTime = greenwaveHistPO.getTrvalTime();
if (Objects.equals(greenId, curGreenId) && StringUtils.equals(roadDirection, curDirection)) {
if (Objects.equals(greenId, curGreenId) && StringUtils.endsWithIgnoreCase(roadDirection, curDirection)) {
if (trafficIndex > curTrafficIndex) {
greenOptDTO.setTrafficIndexUpDown(1);
......@@ -213,12 +214,13 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
String crossId = optMonitoringVO.getId();
for (CrossLastOptResultDTO optResultDTO : optResultDTOS) {
String id = optResultDTO.getId();
if (StringUtils.equals(id, crossId)) {
if (StringUtils.endsWithIgnoreCase(id, crossId)) {
Date optTime = optResultDTO.getOptTime();
Integer duration = optResultDTO.getDuration();
String type = optResultDTO.getType();
// 优化时间计算
optMonitoringVO.setOptTime(optTime);
optMonitoringVO.setOptStatus(0);
optMonitoringVO.setTypeDesc(EventInfoTypeEnum.getOptDesc(type));
if (Objects.nonNull(optTime)) {
// 空放优化中,6秒钟结束,当前时间小于开始时间+持续时间
......@@ -247,4 +249,49 @@ public class TrendServiceV2Impl implements TrendServiceV2 {
List<OptMonitoringVO> sort = results.stream().sorted(Comparator.comparing(OptMonitoringVO::getStartTime).reversed()).collect(Collectors.toList());
return sort;
}
@Override
public List<StatisticsEventTypeCountTimeVO> selectGreenEventTypeCountTimeList(EventTypeCountTimeVO vo) throws Exception {
String type = vo.getType();
LocalDateTime current = vo.getDate();
LocalDateTime curDayStart = DateUtil.getLastDayMidNight(current, 0);
LocalDateTime latDayStart = DateUtil.getLastDayMidNight(current, -7);
LocalDateTime lastDayEnd = current.plusDays(-1);
List<StatisticsEventTypeCountTimeVO> currentList = holoEventMapper.selectGreenEventTypeCountTimeList(type, curDayStart, current);
List<StatisticsEventTypeCountTimeVO> lastDayList = holoEventMapper.selectGreenEventTypeCountTimeList(type, latDayStart, lastDayEnd);
setCountDurationRate(currentList, lastDayList);
return currentList;
}
private static void setCountDurationRate(List<StatisticsEventTypeCountTimeVO> currentList, List<StatisticsEventTypeCountTimeVO> lastDayList) {
currentList.forEach(result -> {
for (StatisticsEventTypeCountTimeVO last : lastDayList) {
String id = result.getId();
String lastId = last.getId();
if (StringUtils.endsWithIgnoreCase(id, lastId)) {
if (last.getCount() == 0 || last.getDuration() == 0) {
continue;
}
double countRate = (result.getCount() - last.getCount()) / last.getCount() * 100;
double durationRate = (result.getDuration() - last.getDuration()) / last.getCount() * 100;
result.setCountRate((int) countRate);
result.setDurationRate((int) durationRate);
}
}
});
}
@Override
public List<StatisticsEventTypeCountTimeVO> selectCrossEventTypeCountTimeList(EventTypeCountTimeVO vo) throws Exception {
String type = vo.getType();
LocalDateTime current = vo.getDate();
LocalDateTime curDayStart = DateUtil.getLastDayMidNight(current, 0);
LocalDateTime latDayStart = DateUtil.getLastDayMidNight(current, -1);
LocalDateTime lastDayEnd = current.plusDays(-1);
List<StatisticsEventTypeCountTimeVO> currentList = holoEventMapper.selectCrossEventTypeCountTimeList(type, curDayStart, current);
List<StatisticsEventTypeCountTimeVO> lastDayList = holoEventMapper.selectCrossEventTypeCountTimeList(type, latDayStart, lastDayEnd);
setCountDurationRate(currentList, lastDayList);
return currentList;
}
}
\ No newline at end of file
package net.wanji.opt.vo2;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author duanruiming
* @date 2025/03/13 17:07
*/
@Data
@ApiModel(value = "EventTypeCountTimeVO", description = "态势监测-区域体检-雷达图路口事件请求")
public class EventTypeCountTimeVO {
@ApiModelProperty(value = "事件类型")
private String type;
@ApiModelProperty(value = "日期")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime date;
}
package net.wanji.opt.vo2;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer;
/**
* @author duanruiming
* @date 2025/03/10 16:14
*/
@Data
@ApiModel(value = "GreenOptInfoDTO", description = "态势监测-区域体检-绿波优化列表")
public class GreenOptInfoDTO {
@ApiModelProperty(value = "绿波编号")
private Integer greenId;
@ApiModelProperty(value = "绿波名称")
private String greenName;
@ApiModelProperty(value = "绿波方向")
private String roadDirection;
@ApiModelProperty(value = "绿波名称")
private String directionName;
@ApiModelProperty(value = "经纬度")
private String wkt;
@ApiModelProperty(value = "策略名称")
private String strategyName;
@ApiModelProperty(value = "交通指数")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double trafficIndex;
@ApiModelProperty(value = "运行速度")
private Integer speed;
@ApiModelProperty(value = "行程速度")
private Integer travelTime;
@ApiModelProperty(value = "同比交通指数,0-向下, 1向上")
private Integer trafficIndexUpDown;
@ApiModelProperty(value = "同比运行速度,0-向下, 1向上")
private Integer speedUpDown;
@ApiModelProperty(value = "同比行程时间,0-向下, 1向上")
private Integer travelUpDown;
}
package net.wanji.opt.vo2;
import io.swagger.annotations.ApiModel;
import lombok.Data;
import java.util.List;
/**
* @author duanruiming
* @date 2025/03/13 14:26
*/
@Data
@ApiModel(value = "OptMonitoringVO", description = "态势监测-运行监测-优化监测返回实体")
public class OptMonitoringResultVO {
private List<TypeCount> typeCount;
private List<OptMonitoringVO> optMonitoringVOList;
@Data
public static class TypeCount{
private String type;
private Integer eventCount;
private Integer optCount;
}
}
......@@ -25,4 +25,9 @@ public class StatisticsEventTypeCountTimeVO {
private Integer count;
@ApiModelProperty(value = "持续时间")
private Integer duration;
@ApiModelProperty(value = "同比比例,上一周同一时间次数比例")
private Integer countRate;
@ApiModelProperty(value = "同比比例,上一周同一持续时间次数比例")
private Integer durationRate;
}
......@@ -277,9 +277,9 @@
order by t2.start_time desc
</select>
<!-- 态势监测-区域体检-雷达图事件类型过滤 -->
<!-- 态势监测-区域体检-雷达图绿波事件事件类型过滤 -->
<select id="selectGreenEventTypeCountTimeList" resultType="net.wanji.opt.vo2.StatisticsEventTypeCountTimeVO">
select t1.id, t1.name, t1.wkt, t2.type, ifnull(t2.count, 0), ifnull(t2.duration, 0),
select t1.id, t1.name, t1.wkt, t2.type, ifnull(t2.count, 0) as count, ifnull(t2.duration, 0) as duration,
case when t2.type = '705' then '缓行次数'
when t2.type = '706' then '拥堵次数'
end as typeDesc
......@@ -289,14 +289,17 @@
select type, green_id,
count(*) as count,
SUM(TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time, now()))) as duration
from t_event_info where type = #{type} and dt = #{date} group by green_id) t2
from t_event_info where type = #{type}
and start_time between #{startTime} and #{endTime}
group by cross_id) t2
on t1.id = t2.green_id
order by duration desc
</select>
<!-- 态势监测-区域体检-雷达图事件类型过滤 -->
<select id="selectGreenEventTypeCountTimeList" resultType="net.wanji.opt.vo2.StatisticsEventTypeCountTimeVO">
<!-- 态势监测-区域体检-雷达图路口事件类型过滤 -->
<select id="selectCrossEventTypeCountTimeList" resultType="net.wanji.opt.vo2.StatisticsEventTypeCountTimeVO">
select t1.id, t1.name, REPLACE(SUBSTRING(location, 7, 18), ' ', ',') as wkt,
t2.type, ifnull(t2.count, 0), ifnull(t2.duration, 0),
t2.type, ifnull(t2.count, 0) as count, ifnull(t2.duration, 0) as duration,
case when t2.type = '701' then '空放次数'
when t2.type = '702' then '失衡次数'
when t2.type = '703' then '溢出次数'
......@@ -308,9 +311,12 @@
select type, cross_id,
ifnull(count(*), 0) as count,
SUM(TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time, now()))) as duration
from t_event_info where type = '701' and dt = curdate() group by cross_id) t2
from t_event_info where type = #{type}
and start_time between #{startTime} and #{endTime}
group by cross_id) t2
on t1.id = t2.cross_id
where t1.is_signal = 1
order by duration desc
</select>
</mapper>
\ No newline at end of file
......@@ -561,6 +561,25 @@ public class DateUtil {
return midNight;
}
/**
* 将当前日期转化为00点
* @param date
* @param offset
* @return
*/
public static LocalDateTime getLastDayMidNight(LocalDateTime date, Integer offset) {
LocalDateTime localDateTime = date.plusDays(offset);
LocalDate localDate = localDateTime.toLocalDate();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime midNight = LocalDateTime.of(localDate, startTime);
return midNight;
}
public static void main(String[] args) {
LocalDateTime lastDayMidNight = getLastDayMidNight(LocalDateTime.now(), -7);
System.err.println(lastDayMidNight);
}
/**
* 对当前日期进行加减小时返回日期
* @param offset
......
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