Commit 52fe6646 authored by duanruiming's avatar duanruiming

[add] 交通体检-交通状态接口优化

parent 8122b65e
......@@ -3,6 +3,7 @@ package net.wanji.opt.dao.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.databus.dto.EventInfoTrafficStatusDTO;
import net.wanji.databus.po.EventInfoTrafficStatusPO;
import net.wanji.opt.dto.EventTypeTimeRateDTO;
import net.wanji.opt.entity.EventAlarmInfo;
import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.po.trend.EventInfoSimplePo;
......@@ -50,4 +51,11 @@ public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> {
*/
List<EventAlarmInfo> findNotFinishAlarmInfo();
/**
* 查询事件表,事件类型持续时间与当前时间的时间比例,对应交通体检-交通状态
* @param crossId
* @return
*/
List<EventTypeTimeRateDTO> selectEventTypeTimeRate(String crossId);
}
package net.wanji.opt.dto;
import lombok.Data;
/**
* @author duanruiming
* @date 2025/02/06 17:02
* @description 事件表事件类型与当前事件比例
*/
@Data
public class EventTypeTimeRateDTO {
private String type;
private Double timeRate;
}
......@@ -25,6 +25,7 @@ import net.wanji.opt.cache.BaseCrossInfoCache;
import net.wanji.opt.common.ExcelExportUtils;
import net.wanji.opt.common.KafkaConsumerUtil;
import net.wanji.opt.common.RedisUtils;
import net.wanji.opt.common.enums.EventInfoTypeEnum;
import net.wanji.opt.common.exception.OptServiceException;
import net.wanji.opt.config.DirectionMappingsConfig;
import net.wanji.opt.dao.mapper.CrossSchemeOptLogMapper;
......@@ -35,10 +36,7 @@ import net.wanji.opt.dao.mapper.strategy.SceneStrategyMapper;
import net.wanji.opt.dao.mapper.strategy.StrategyMapper;
import net.wanji.opt.dao.mapper.trend.AnalysisRidTurnIndicatorsMapper;
import net.wanji.opt.dao.mapper.trend.EventAlarmMapper;
import net.wanji.opt.dto.CrossEventDTO;
import net.wanji.opt.dto.CrossLaneSnapshotDataDTO;
import net.wanji.opt.dto.LineCongestion;
import net.wanji.opt.dto.LineSchemeDTO;
import net.wanji.opt.dto.*;
import net.wanji.opt.dto.trend.AbnormalCrossListDTO;
import net.wanji.opt.dto.trend.GreenwaveListDTO;
import net.wanji.opt.po.base.CrossSchemeOptLogPO;
......@@ -2020,30 +2018,20 @@ public class TrendServiceImpl implements TrendService {
CrossStatusTimeRateVO crossStatusTimeRateVO = new CrossStatusTimeRateVO();
try {
String crossId = commonCrossIdVO.getCrossId();
//Instant instant = Instant.ofEpochSecond(1705456500L);
Date date = new Date();
long time = date.getTime() / 1000;
Instant instant = Instant.ofEpochSecond(time);
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, ZoneId.of("+8"));
// 00:00
LocalDateTime startOfDay = localDateTime.withHour(0).withMinute(0).withSecond(0);
int startBatchTime = Long.valueOf(Date.from(startOfDay.atZone(ZoneId.of("+8")).toInstant()).getTime() / 1000).intValue();
// 23:59
LocalDateTime endOfDay = startOfDay.plus(1, ChronoUnit.DAYS).minus(1, ChronoUnit.SECONDS);
int endBatchTime = Long.valueOf(Date.from(endOfDay.atZone(ZoneId.of("+8")).toInstant()).getTime() / 1000).intValue();
List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectByCrossIdAndStartEnd(crossId, startBatchTime, endBatchTime);
if (!CollectionUtils.isEmpty(crossDataHistPOS)) {
Map<Integer, List<CrossDataHistPO>> statusMap = crossDataHistPOS.stream().collect(Collectors.groupingBy(CrossDataHistPO::getStatus));
crossStatusTimeRateVO.setCrossId(crossId);
for (Map.Entry<Integer, List<CrossDataHistPO>> entry : statusMap.entrySet()) {
Integer status = entry.getKey();
List<CrossDataHistPO> value = entry.getValue();
float temp = value.size() / (float) crossDataHistPOS.size() * 100;
List<EventTypeTimeRateDTO> eventTypeTimeRateDTOS = holoEventMapper.selectEventTypeTimeRate(crossId);
if (!CollectionUtils.isEmpty(eventTypeTimeRateDTOS)) {
int unblockedTimeRate = 0;
for (EventTypeTimeRateDTO eventTypeTimeRateDTO : eventTypeTimeRateDTOS) {
String type = eventTypeTimeRateDTO.getType();
Double timeRate = eventTypeTimeRateDTO.getTimeRate();
Double temp = timeRate * 100;
temp = temp < 1 ? 0 : temp;
int rate = Math.round(temp);
int rate = (int)Math.round(temp);
int status = EventInfoTypeEnum.getOptType(type);
setStatusTimeRate(crossStatusTimeRateVO, status, rate);
unblockedTimeRate += rate;
}
crossStatusTimeRateVO.setUnblockedTimeRate(100 - unblockedTimeRate);
}
} catch (Exception e) {
log.error("交通状态时间比例异常:", e);
......
......@@ -228,6 +228,16 @@
start_time
</select>
<select id="selectEventTypeTimeRate" parameterType="String" resultType="net.wanji.opt.dto.EventTypeTimeRateDTO">
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'), now()) as totalTime
from t_event_info
where type in ('701', '702', '703', '704', '707') and start_time >= curdate() and cross_id = '13N0C0B5P30'
) t1 group by t1.type;
</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