Commit 5d11325c authored by duanruiming's avatar duanruiming

[add] 态势检测雷达图功能提交

parent ca530bc3
package net.wanji.opt.controllerv2;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.servicev2.TrendServiceV2;
import net.wanji.opt.vo2.CrossOptInfoVO;
import net.wanji.opt.vo2.CrossGreenStatusTimeRateVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import java.util.Collections;
import java.util.List;
/**
* @author duanruiming
* @date 2025/03/06 18:33
*/
@Api(value = "TrendControllerV2", description = "态势监测v2")
@RequestMapping("/trendV2")
@RestController
@Slf4j
public class TrendControllerV2 {
@Resource
private TrendServiceV2 trendServiceV2;
@ApiOperation(value = "态势监测-区域体检-雷达图", notes = "态势监测-区域体检-雷达图", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/crossGreenStatusTimeRate")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = CrossGreenStatusTimeRateVO.class),
})
public JsonViewObject crossGreenStatusTimeRate() {
List<CrossGreenStatusTimeRateVO> list = Collections.emptyList();
try {
list = trendServiceV2.crossGreenStatusTimeRate();
} 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)
@GetMapping(value = "/crossOptInfoList")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = CrossOptInfoVO.class),
})
public JsonViewObject crossOptInfoList() throws Exception {
List<CrossOptInfoVO> list = Collections.emptyList();
try {
list = trendServiceV2.crossOptInfoList();
} catch (Exception e) {
JsonViewObject.newInstance().success(list);
}
return JsonViewObject.newInstance().success(list);
}
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.po.trend.EventInfoSimplePo;
import net.wanji.opt.po.trend.HoloEventInfoPO;
import net.wanji.opt.vo.CrossEventListPO;
import net.wanji.opt.vo2.CrossGreenStatusTimeRateVO;
import org.springframework.stereotype.Repository;
import java.util.Date;
......@@ -64,4 +65,10 @@ public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> {
*/
List<EventTypeTimeRateDTO> selectGreenEventTypeTimeRate(String greenId);
/**
* 态势监测-区域体检-雷达图 查询
* @return
*/
List<CrossGreenStatusTimeRateVO> selectCrossGreenStatusTimeRate();
}
......@@ -2,6 +2,7 @@ package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.synthesis.pojo.StrategyCrossResultEntity;
import net.wanji.opt.vo2.CrossOptInfoVO;
import java.util.Date;
import java.util.List;
......@@ -12,4 +13,6 @@ import java.util.List;
*/
public interface StrategyCrossResultMapper extends BaseMapper<StrategyCrossResultEntity> {
List<StrategyCrossResultEntity> selectAICrossList(Date date);
List<CrossOptInfoVO> selectAICrossListV2();
}
package net.wanji.opt.servicev2;
import net.wanji.opt.vo2.CrossGreenStatusTimeRateVO;
import net.wanji.opt.vo2.CrossOptInfoVO;
import java.util.List;
/**
* @author duanruiming
* @date 2025/03/06 18:37
*/
public interface TrendServiceV2 {
List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate();
List<CrossOptInfoVO> crossOptInfoList() throws Exception;
}
\ No newline at end of file
package net.wanji.opt.servicev2.implv2;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.dao.mapper.HoloEventMapper;
import net.wanji.opt.dao.mapper.StrategyCrossResultMapper;
import net.wanji.opt.servicev2.TrendServiceV2;
import net.wanji.opt.vo2.CrossGreenStatusTimeRateVO;
import net.wanji.opt.vo2.CrossOptInfoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.util.*;
/**
* @author duanruiming
* @date 2025/03/06 18:44
*/
@Service
@Slf4j
public class TrendServiceV2Impl implements TrendServiceV2 {
@Resource
private HoloEventMapper holoEventMapper;
@Resource
private StrategyCrossResultMapper strategyCrossResultMapper;
@Override
public List<CrossGreenStatusTimeRateVO> crossGreenStatusTimeRate() {
return holoEventMapper.selectCrossGreenStatusTimeRate();
}
@Override
public List<CrossOptInfoVO> crossOptInfoList() throws Exception {
List<CrossOptInfoVO> results = new ArrayList<>();
try {
results = new ArrayList<>();
List<CrossOptInfoVO> resultList = strategyCrossResultMapper.selectAICrossListV2();
if (!CollectionUtils.isEmpty(resultList)) {
for (CrossOptInfoVO entity : resultList) {
CrossOptInfoVO result = new CrossOptInfoVO();
BeanUtils.copyProperties(entity, result);
Integer currentAlgo = entity.getCurrentAlgo();
Date issueTime = entity.getIssueTime();
Date current = new Date();
Integer duration = Objects.nonNull(entity.getDuration()) ? entity.getDuration() : 0;
// 计算结束时间
if (Objects.nonNull(issueTime)) {
if (Objects.equals(2, currentAlgo) && current.getTime() - issueTime.getTime() <= duration * 1000) {
result.setOptStatus("优化中");
result.setOptMethod("均衡调控");
} else if (current.getTime() - issueTime.getTime() > 10 * 1000) {
currentAlgo = null;
}
}
// 0无策略
if (Objects.isNull(currentAlgo) || Objects.equals(0, currentAlgo)) {
result.setOptStatus("正常");
result.setOptMethod("畅通");
} else if (Objects.equals(2, currentAlgo)) {
result.setOptStatus("优化中");
result.setOptMethod("均衡调控");
} else {
result.setOptStatus("优化中");
result.setOptMethod("效率提升");
}
results.add(result);
}
}
} catch (Exception e) {
log.error("态势监测-区域体检-雷达图-查询失败:{}", e);
throw new Exception(e);
}
return results;
}
}
\ No newline at end of file
package net.wanji.opt.synthesis.pojo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
......@@ -9,6 +10,12 @@ import lombok.Data;
@Data
public class StrategyControlDataExt extends StrategyControlDataEntity{
private String strategyName;
@ApiModelProperty(value = "优化状态")
private String optStatus;
@ApiModelProperty(value = "策略类型")
private String optMethod;
@ApiModelProperty(value = "交通指数")
private Double trafficIndex;
@ApiModelProperty(value = "排队长度")
private int queueLength;
}
package net.wanji.opt.vo2;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author duanruiming
* @date 2025/03/06 16:55
*/
@Data
@ApiModel(value = "CrossGreenStatusTimeRateVO", description = "态势监测-区域体检-雷达图返回")
public class CrossGreenStatusTimeRateVO {
@ApiModelProperty(value = "事件类型")
private String type;
@ApiModelProperty(value = "事件次数")
private Integer count;
@ApiModelProperty(value = "持续时间")
private Integer time;
@ApiModelProperty(value = "当天时间秒数")
private Integer totalTime;
}
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;
import java.util.Date;
/**
* @author duanruiming
* @date 2025/03/06 18:22
*/
@Data
@ApiModel(value = "CrossOptInfoVO", description = "态势监测-区域体检-路口优化列表")
public class CrossOptInfoVO {
@ApiModelProperty(value = "路口编号")
private String crossId;
@ApiModelProperty(value = "路口名称")
private String crossName;
@ApiModelProperty(value = "优化时间")
private Date issueTime;
@ApiModelProperty(value = "事件类型")
private Integer currentAlgo;
@ApiModelProperty(value = "响应编码")
private Integer responseCode;
@ApiModelProperty(value = "响应状态")
private String responseContent;
@ApiModelProperty(value = "持续时长")
private Integer duration;
private String strategyName;
@ApiModelProperty(value = "优化状态")
private String optStatus;
@ApiModelProperty(value = "策略类型")
private String optMethod;
@ApiModelProperty(value = "交通指数")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double trafficIndex;
@ApiModelProperty(value = "排队长度")
private int queueLength;
}
\ No newline at end of file
......@@ -243,21 +243,14 @@
) t1 group by t1.type
</select>
<select id="selectGreenEventTypeTimeRate" parameterType="String" resultType="net.wanji.opt.dto.EventTypeTimeRateDTO">
select type, sum(duration) / totalTime as timeRate from (
<select id="selectCrossGreenStatusTimeRate" resultType="net.wanji.opt.vo2.CrossGreenStatusTimeRateVO">
select type, sum(duration) as time, count(*) count, totalTime from (
select cross_id, type,
TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time,now())) duration,
TIMESTAMPDIFF(SECOND, DATE_FORMAT(start_time, '%Y-%m-%d 00:00:00'), now()) as totalTime
from t_event_info
where type in ('705', '706') and start_time >= curdate() and green_id = #{greenId}
where type in ('701', '702', '703', '704', '705', '706', '707') and start_time > curdate()
) t1 group by t1.type
<!-- select type, sum(duration) / totalTime as timeRate from (-->
<!-- select cross_id, type,-->
<!-- TIMESTAMPDIFF(SECOND, start_time, ifnull(end_time,now())) duration,-->
<!-- TIMESTAMPDIFF(SECOND, DATE_FORMAT(start_time, '%Y-%m-%d 00:00:00'), '2025-03-03 00:00:00') as totalTime-->
<!-- from t_event_info-->
<!-- where type in ('705', '706') and dt= 20250302 and green_id = 1-->
<!-- ) t1 group by t1.type-->
</select>
......
......@@ -15,21 +15,21 @@
on t1.id = t2.cross_id
and t2.issue_time > CURDATE()
order by t2.issue_time desc
<!-- select t1.id as cross_id, t1.name as cross_name, t2.current_algo, t2.issue_time-->
<!-- from t_base_cross_info t1 left join-->
<!-- (-->
<!-- select cross_id, cross_name, max(issue_time) issue_time, current_algo-->
<!-- from t_strategy_cross_result-->
<!-- where issue_time > #{date} and response_code = 200-->
<!-- union-->
<!-- select cross_id, cross_name, max(issue_time) issue_time, current_algo-->
<!-- from t_strategy_cross_result-->
<!-- where issue_time > #{date} and response_code &lt; 0-->
<!-- group by cross_id-->
<!-- order by issue_time-->
<!-- ) t2 on t1.id = t2.cross_id-->
<!-- where t1.is_signal = 1-->
<!-- order by t2.issue_time desc;-->
</select>
<select id="selectAICrossListV2" resultType="net.wanji.opt.vo2.CrossOptInfoVO">
select t1.id crossId, t1.name crossName, t2.issue_time issueTime, t2.current_algo currentAlgo,
t2.response_code responseCode, t1.location as responseContent, t2.duration,
t3.queue_length queueLength, t3.traffic_index trafficIndex from
(select id, name, location from t_base_cross_info where is_signal = 1) t1
left join (select t1.cross_id, t1.issue_time, t1.current_algo, t1.response_code, t1.duration from t_strategy_cross_result t1
inner join (select cross_id, max(issue_time) issue_time from t_strategy_cross_result where issue_time > CURDATE() group by cross_id) t3
on t1.cross_id = t3.cross_id and t1.issue_time = t3.issue_time where t1.issue_time > CURDATE()) t2
on t1.id = t2.cross_id
and t2.issue_time > CURDATE()
left join t_cross_data_realtime t3 on t1.id = t3.cross_id
order by t2.issue_time desc
</select>
</mapper>
\ No newline at end of file
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