Commit a8a4aaf9 authored by 黄伟铭's avatar 黄伟铭

Merge remote-tracking branch 'origin/master'

parents 09caeedf b6b4ddc0
package net.wanji.opt.controllerv2.report.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
@Data
class GreenReportRunStateResponseDTO {
@ApiModelProperty(value = "干线ID", example = "")
private String greenId;
@ApiModelProperty(value = "干线名称", example = "经十路(舜耕路-山大路)")
private String greenName;
@ApiModelProperty(value = "本周早高峰时段集中情况", example = "7:30~8:30")
private String weekAmPeakSpan;
@ApiModelProperty(value = "本周早高峰时段开始时间同比(上周)情况", example = "提前20分钟")
private String amStartSameRatioSituation;
@ApiModelProperty(value = "本周早高峰时段截止时间同比(上周)情况", example = "延后20分钟")
private String amEndSameRatioSituation;
@ApiModelProperty(value = "本周早高峰时段持续时长", example = "45分钟")
private String amDuration;
@ApiModelProperty(value = "本周早高峰时段持续时长同比(上周)情况", example = "增加5分钟")
private String amDurationSameRatioSituation;
@ApiModelProperty(value = "本周早高峰最大行程时间", example = "30分钟")
private String amMaxTravelTime;
@ApiModelProperty(value = "本周早高峰最大行程时间同比(上周)情况", example = "减少6分钟")
private String amMaxTravelTimeSameRatioSituation;
@ApiModelProperty(value = "平均拥堵指数", example = "4.5")
private String amAvgContestIndex;
@ApiModelProperty(value = "平均拥堵指数同比(上周)情况", example = "减少0.5")
private String amAvgContestIndexSameRatioSituation;
@ApiModelProperty(value = "本周早高峰时段集中情况", example = "7:30~8:30")
private String weekPmPeakSpan;
@ApiModelProperty(value = "本周早高峰时段开始时间同比(上周)情况", example = "提前20分钟")
private String pmStartSameRatioSituation;
@ApiModelProperty(value = "本周早高峰时段截止时间同比(上周)情况", example = "延后20分钟")
private String pmEndSameRatioSituation;
@ApiModelProperty(value = "本周早高峰时段持续时长", example = "45分钟")
private String pmDuration;
@ApiModelProperty(value = "本周早高峰时段持续时长同比(上周)情况", example = "增加5分钟")
private String pmDurationSameRatioSituation;
@ApiModelProperty(value = "本周早高峰最大行程时间", example = "30分钟")
private String pmMaxTravelTime;
@ApiModelProperty(value = "本周早高峰最大行程时间同比(上周)情况", example = "减少6分钟")
private String pmMaxTravelTimeSameRatioSituation;
@ApiModelProperty(value = "平均拥堵指数", example = "4.5")
private String pmAvgContestIndex;
@ApiModelProperty(value = "平均拥堵指数同比(上周)情况", example = "减少0.5")
private String pmAvgContestIndexSameRatioSituation;
private List<GreenReportRunStatedDataDTO> dataList = new ArrayList<>();
}
package net.wanji.opt.controllerv2.report.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
class GreenReportRunStatedDataDTO {
@ApiModelProperty(value = "星期", example = "星期一")
private String weekName;
@ApiModelProperty(value = "峰期类型 早高峰、晚高峰、全天", example = "早高峰")
private String peakName;
@ApiModelProperty(value = "本周拥堵时段", example = "7:35~8:40")
private String thisWeekCongestSpan;
@ApiModelProperty(value = "上周拥堵时段", example = "7:50~8:40")
private String lastWeekCongestSpan;
@ApiModelProperty(value = "本周拥堵指数", example = "3.5")
private Double thisWeekCongestIndex;
@ApiModelProperty(value = "上周拥堵指数", example = "3.0")
private Double lastWeekCongestIndex;
@ApiModelProperty(value = "本周平均车速km/h", example = "30.5")
private Double thisWeekAvgSpeed;
@ApiModelProperty(value = "上周平均车速km", example = "30.2")
private Double lastWeekAvgSpeed;
@ApiModelProperty(value = "本周行程时间(分钟)", example = "6.5")
private Double thisWeekTravelTime;
@ApiModelProperty(value = "上周行程时间(分钟)", example = "-1.5%")
private Double lastWeekTravelTime;
}
......@@ -6,6 +6,7 @@ import net.wanji.databus.dao.entity.GreenwaveHistPOExt;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.databus.po.CrossTurnDataHistPO;
import net.wanji.opt.dto.report.GreenHistIndexDTO;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.po.base.CrossLaneDataHistPoExtend;
import net.wanji.opt.vo.GreenWaveRunStateVO;
......@@ -126,5 +127,15 @@ public interface GreenwaveHistoryMapper extends BaseInterfaceMapper<GreenwaveHis
*/
List<GreenwaveHistPOExt> selectRunMonitorV2(@Param("greenId") Integer greenId, @Param("date") Date date);
/**
* 按时间范围统计干线指标
* @param greenId
* @param startDate
* @param endData
* @return
*/
List<GreenHistIndexDTO> findGreenIndexByDateScope(@Param("greenId") Integer greenId, @Param("startDate")String startDate, @Param("endDate")String endData);
}
package net.wanji.opt.dao.mapper.report;
import net.wanji.opt.dto.report.GreenHistIndexDTO;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.entity.report.AnalysisGreenWaveOptimizeWeek;
import java.util.List;
import org.apache.ibatis.annotations.Param;
......@@ -41,6 +43,11 @@ public interface AnalysisGreenWaveOptimizeWeekMapper extends BaseMapper<Analysis
* @param analysisGreenWaveOptimizeWeek
*/
Integer addAnalysisGreenWaveOptimizeWeek(AnalysisGreenWaveOptimizeWeek analysisGreenWaveOptimizeWeek);
/**
* 批量插入
* @param list
*/
void insertBatch(List<AnalysisGreenWaveOptimizeWeek> list);
}
package net.wanji.opt.dto.report;
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;
@Data
public class GreenHistIndexDTO {
@ApiModelProperty(value = "绿波编号")
private Integer greenId;
@ApiModelProperty(value = "绿波名称")
private String greenName;
@ApiModelProperty(value = "绿波方向")
private String roadDirection;
@ApiModelProperty(value = "流量")
private Integer flow;
@ApiModelProperty(value = "交通拥堵指数")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double trafficIndex;
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
@ApiModelProperty(value = "平均速度 km/h")
private Double speed;
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
@ApiModelProperty(value = "平均行程时间")
private Integer travelTime;
@ApiModelProperty(value = "平均延误时长,单位秒")
private Double delayTime;
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
@ApiModelProperty(value = "平均停车次数")
private Double stopTimes;
@ApiModelProperty(value = "通行能力")
private Integer capacity;
private String flowAll;
}
......@@ -18,6 +18,9 @@ public class StrategyGreenOptHistDTO {
@TableField("green_id")
private Integer greenId;
@TableField("dir")
private String roadDirection;
@TableField("length")
private Double length;
......@@ -25,7 +28,8 @@ public class StrategyGreenOptHistDTO {
private Integer cycle;
@TableField("control_time")
private String controlTime;
private Date controlTime;
@TableField("control_duration")
private Integer controlDuration;
......@@ -42,8 +46,6 @@ public class StrategyGreenOptHistDTO {
@TableField("dir_type")
private Integer dirType;
@TableField("dir")
private String dir;
@TableField("max_speed")
private Double maxSpeed;
......@@ -68,4 +70,20 @@ public class StrategyGreenOptHistDTO {
@TableField("duration")
private Integer duration;
@TableField("week_start_day")
private Date weekStartDay;
@TableField("week_end_day")
private Date weekEndDay;
@TableField("year_week")
private Integer yearWeek;
@TableField("week_day")
private Integer weekDay;
@TableField("stragety_id")
private Integer stragetyId;
}
......@@ -28,6 +28,10 @@ public class AnalysisGreenWaveOptimizeWeek implements Serializable {
* 星期几:1~7代表周一至周日
*/
private Integer weekDay;
/**
* 拥堵指数
*/
private Double congestIndex;
/**
* 优化时段开始时间
......
......@@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSONObject;
import net.wanji.common.framework.dubbointerface.BaseDubboInterface;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.opt.dto.report.GreenHistIndexDTO;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.po.base.CrossLaneDataHistPoExtend;
import net.wanji.opt.vo.GreenWaveRunStateVO;
import org.apache.ibatis.annotations.Param;
import java.util.List;
import java.util.Map;
......@@ -140,4 +142,15 @@ public interface GreenwaveHistProvider extends BaseDubboInterface<GreenwaveHist>
* @throws DubboProviderException
*/
JSONObject findCrossAvgIndex(String crossId, String startTime, String endTime, String groupType, Integer objectType) throws DubboProviderException;
/**
* 按时间范围统计干线指标
* @param greenId
* @param startDate
* @param endData
* @return
*/
GreenHistIndexDTO findGreenIndexByDateScope(Integer greenId, String startDate, String endData);
}
......@@ -25,6 +25,7 @@ import net.wanji.opt.common.EsDateIndexUtil;
import net.wanji.opt.common.enums.TimeGranularityEnum;
import net.wanji.opt.constant.ServiceLevelEnum;
import net.wanji.opt.dao.mapper.GreenwaveHistoryMapper;
import net.wanji.opt.dto.report.GreenHistIndexDTO;
import net.wanji.opt.entity.GreenwaveHist;
import net.wanji.opt.po.base.CrossLaneDataHistPoExtend;
import net.wanji.opt.po.trend.GreenwaveCrossTrendPo;
......@@ -60,6 +61,7 @@ import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
......@@ -757,6 +759,29 @@ public class GreenwaveHistProviderImpl extends BaseDubboInterfaceImpl<GreenwaveH
return jsonObject;
}
@Override
public GreenHistIndexDTO findGreenIndexByDateScope(Integer greenId, String startDate, String endDate) {
List<GreenHistIndexDTO> list = greenwaveHistoryMapper.findGreenIndexByDateScope(greenId,startDate,endDate);
if (!list.isEmpty()) {
GreenHistIndexDTO dto = list.get(0);
String flowAll = dto.getFlowAll();
if (Objects.nonNull(flowAll)) {
List<Integer> flowList = Stream.of(flowAll.split(",")).map(Integer::parseInt).collect(Collectors.toList());
int capacity = 0;
//每3个连续5分钟流量和*4规约为小时流量
for (int i = 0; i <= flowList.size() - 3; i++) {
int sum = flowList.get(i) + flowList.get(i + 1) + flowList.get(i + 2);
if (sum * 4 > capacity) {
capacity = sum * 4;
}
}
dto.setCapacity(capacity);
return dto;
}
}
return null;
}
@Override
public JSONObject findCrossExitRoadLaneInfo(String crossId, String startTime, String endTime, String groupType) {
Map<String, Object> params = new HashMap<>();
......
package net.wanji.opt.servicev2.judgeanalysis.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import net.wanji.opt.dao.mapper.judgeanalysis.AnalysisProblemAndStrategyDayMapper;
import net.wanji.opt.entity.judgeanalysis.AnalysisProblemAndStrategyDay;
import net.wanji.opt.servicev2.judgeanalysis.AnalysisProblemAndStrategyDayService;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import javax.annotation.Resource;
import java.time.LocalDate;
......@@ -21,12 +23,15 @@ import java.util.List;
* @since 2025-03-20
*/
@Service
@Slf4j
public class AnalysisProblemAndStrategyDayImpl extends ServiceImpl<AnalysisProblemAndStrategyDayMapper, AnalysisProblemAndStrategyDay> implements AnalysisProblemAndStrategyDayService {
@Resource
private AnalysisProblemAndStrategyDayMapper analysisProblemAndStrategyDayMapper;
public void selectCountByType() {
StopWatch stopWatch = new StopWatch("事件优化时长计算监控");
stopWatch.start();
//查询路口事件数据
List<AnalysisProblemAndStrategyDay> crossEvenList = analysisProblemAndStrategyDayMapper.selectCrossEvent();
if (crossEvenList.size() > 0) {
......@@ -74,6 +79,9 @@ public class AnalysisProblemAndStrategyDayImpl extends ServiceImpl<AnalysisProbl
analysisProblemAndStrategyDayMapper.insertProblemAndStrategy(vo);
}
}
stopWatch.stop();
log.info("事件优化记录优化耗时:{}ms",stopWatch.getTotalTimeMillis());
}
}
......@@ -71,7 +71,7 @@ public class AnalysisGreenWavePeakDetailServiceImpl extends BaseDubboInterfaceIm
List<Integer> greenList = Stream.of(ids.split(",")).map(o -> Integer.valueOf(o)).collect(Collectors.toList());
Integer yearWeek = Integer.valueOf(year.toString() + week.toString());
Integer lastWeek = yearWeek;//Integer.valueOf(year.toString() + (week - 1);
Integer lastWeek = yearWeek;//Integer.valueOf(year.toString() + (week - 1));
Map<String, Object> params = new HashMap<>();
params.put("greenIdList", greenList);
......@@ -250,7 +250,7 @@ public class AnalysisGreenWavePeakDetailServiceImpl extends BaseDubboInterfaceIm
vo.setAmDurationSameRatioSituation(amDurationSameRatioSituation);
vo.setAmMaxTravelTime(thisMaxTravelTime + "分钟");
vo.setAmMaxTravelTimeSameRatioSituation(maxTravelTimeSituation);
vo.setAmAvgContestIndex(thisAvgCongestIndex + "");
vo.setAmAvgContestIndex(thisAvgCongestIndex);
vo.setAmAvgContestIndexSameRatioSituation(amAvgCongestIndex);
vo.setThisWeekPeakEarliestStartTime(earliestStartTimePo.getPeakStartTime());
vo.setThisWeekPeakLatestEndTime(lastEndTimePo.getPeakEndTime());
......@@ -262,7 +262,7 @@ public class AnalysisGreenWavePeakDetailServiceImpl extends BaseDubboInterfaceIm
vo.setPmDurationSameRatioSituation(amDurationSameRatioSituation);
vo.setPmMaxTravelTime(thisMaxTravelTime + "分钟");
vo.setPmMaxTravelTimeSameRatioSituation(maxTravelTimeSituation);
vo.setPmAvgContestIndex(thisAvgCongestIndex + "");
vo.setPmAvgContestIndex(thisAvgCongestIndex);
vo.setPmAvgContestIndexSameRatioSituation(amAvgCongestIndex);
vo.setLastWeekPeakEarliestStartTime(earliestStartTimePo.getPeakStartTime());
vo.setLastWeekPeakLatestEndTime(lastEndTimePo.getPeakEndTime());
......@@ -282,17 +282,23 @@ public class AnalysisGreenWavePeakDetailServiceImpl extends BaseDubboInterfaceIm
*/
private AnalysisGreenWavePeakDetail getPeakTimeBoundary(List<AnalysisGreenWavePeakDetail> list, Integer type, Integer peakType) {
AnalysisGreenWavePeakDetail ret = null;
if (Objects.equals(1, type)) {
Optional<AnalysisGreenWavePeakDetail> optional = list.stream().filter(o -> Objects.equals(peakType.toString(), o.getPeakType())).min(Comparator.comparing(o -> o.getPeakStartTime()));
if (optional.isPresent()){
ret = optional.get();
}
} else {
Optional<AnalysisGreenWavePeakDetail> optional = list.stream().filter(o -> Objects.equals(peakType.toString(), o.getPeakType())).max(Comparator.comparing(o -> o.getPeakEndTime())) ;
if (optional.isPresent()){
ret = optional.get();
}
//修改为取交通指数最大的一条记录
Optional<AnalysisGreenWavePeakDetail> optional = list.stream().filter(o -> Objects.equals(peakType.toString(), o.getPeakType())).min(Comparator.comparing(AnalysisGreenWavePeakDetail::getTrafficIndex).reversed());
if (optional.isPresent()){
ret = optional.get();
}
//多个时段,取第一个时段的第一个开始时段,最后一个时段的截止时段
// if (Objects.equals(1, type)) {
// Optional<AnalysisGreenWavePeakDetail> optional = list.stream().filter(o -> Objects.equals(peakType.toString(), o.getPeakType())).min(Comparator.comparing(o -> o.getPeakStartTime()));
// if (optional.isPresent()){
// ret = optional.get();
// }
// } else {
// Optional<AnalysisGreenWavePeakDetail> optional = list.stream().filter(o -> Objects.equals(peakType.toString(), o.getPeakType())).max(Comparator.comparing(o -> o.getPeakEndTime())) ;
// if (optional.isPresent()){
// ret = optional.get();
// }
// }
return ret;
}
......
......@@ -22,7 +22,11 @@ public class AnalysisProblemAndStrategyDayTask {
private AnalysisProblemAndStrategyDayService analysisProblemAndStrategyDayService;
@Scheduled(cron = "0 15 1 * * ?")
public void task(){
analysisProblemAndStrategyDayService.selectCountByType();
public void task() {
try {
analysisProblemAndStrategyDayService.selectCountByType();
} catch (Exception e) {
log.error("获取事件优化记录异常", e);
}
}
}
......@@ -4,9 +4,15 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.LocalDateTimeUtil;
import net.wanji.opt.dao.mapper.GreenwaveHistoryMapper;
import net.wanji.opt.dao.mapper.StrategyGreenOptHistMapper;
import net.wanji.opt.dao.mapper.report.AnalysisGreenWaveOptimizeWeekMapper;
import net.wanji.opt.dto.report.GreenHistIndexDTO;
import net.wanji.opt.dto.report.StrategyGreenOptHistDTO;
import net.wanji.opt.entity.report.AnalysisGreenWaveOptimizeWeek;
import net.wanji.opt.service.GreenwaveHistProvider;
import org.joda.time.DateTime;
import org.joda.time.Seconds;
import org.joda.time.format.DateTimeFormat;
......@@ -14,9 +20,12 @@ import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.annotation.Profile;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Date;
......@@ -30,10 +39,10 @@ import java.util.stream.Collectors;
/**
* @author fengyi
* @date 2023/1/13
* @date 2025/4/9
* @description
*/
//@Component
@Component
@Configurable
@EnableScheduling
@Slf4j
......@@ -43,19 +52,23 @@ public class OptimizeStatisticTask {
@Resource
StrategyGreenOptHistMapper strategyGreenOptHistMapper;
@Resource
GreenwaveHistProvider greenwaveHistProvider;
@Resource
GreenwaveHistoryMapper historyMapper;
AnalysisGreenWaveOptimizeWeekMapper analysisGreenWaveOptimizeWeekMapper;
/**
* 干线策略优化时长计算
*/
// @Scheduled(cron查询上周优化记录
@Scheduled(cron = "0 40 1 * * ?")
//@PostConstruct
public void optimizeGreenWaveDurationCal() {
long st = System.currentTimeMillis();
try {
long et = System.currentTimeMillis();
List<StrategyGreenOptHistDTO> durationList = new ArrayList<>();
List<AnalysisGreenWaveOptimizeWeek> durationList = new ArrayList<>();
List<StrategyGreenOptHistDTO> list = strategyGreenOptHistMapper.findGreenWaveOptHist();
Map<Integer, List<StrategyGreenOptHistDTO>> groupByGreenId = list.stream().collect(Collectors.groupingBy(o -> o.getGreenId()));
......@@ -66,16 +79,26 @@ public class OptimizeStatisticTask {
value = value.stream().sorted(Comparator.comparing(StrategyGreenOptHistDTO::getControlTime)).collect(Collectors.toList());
int i = 0;
for (StrategyGreenOptHistDTO result : value) {
if (result.getControlMethod() == -1){
i++;
continue;
}
// if (i==4){
// System.out.println();
// }
int seconds = 900;
if (i != value.size() - 1) {
if (value.get(i + 1).getControlMethod() == -1) {
//下一条记录为取消状态,当前取消时间-上次下方时间
seconds = Seconds.secondsBetween(new DateTime(result.getControlTime()), new DateTime(value.get(i + 1).getControlTime())).getSeconds();
//seconds = Math.abs(seconds);
//超过设定的ControlDuration取ControlDuration
if (seconds > result.getControlDuration()) {
seconds = result.getControlDuration();
}
//log.info("greenId={}:干线绿波方案持续时间计算,下一条记录为取消状态 开始时间:{},截止时间:{},持续时长:{}秒",
// value.get(i + 1).setRoadDirection(result.getRoadDirection());
//log.info("greenId={}:干线绿波方案持续时间计算,下一条记录为取消状态 开始时间:{},截止时间:{},持续时长:{}秒",
// result.getGreenId(),
// new DateTime(result.getControlTime()).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")),
// new DateTime(value.get(i + 1).getControlTime()).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")),
......@@ -92,6 +115,7 @@ public class OptimizeStatisticTask {
} else if (result.getControlMethod() != -1) {
//最后一天记录不为-1取消状态
seconds = Seconds.secondsBetween(new DateTime(result.getControlTime()), new DateTime(new Date())).getSeconds();
// seconds = Math.abs(seconds);
if (seconds > result.getControlDuration()) {
seconds = result.getControlDuration();
}
......@@ -102,20 +126,47 @@ public class OptimizeStatisticTask {
// seconds);
}
result.setDuration(seconds);
//优化控制时段-开始时间
String controlStartTime = result.getControlTime();
String controlStartTime = DateUtil.formatDate(result.getControlTime(),"yyyy-MM-dd HH:mm:ss");
//优化控制时段-截止时间
String controlEndTime = new DateTime(result.getControlTime()).plusSeconds(seconds).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
// if (result.getControlTime().after(new DateTime(result.getControlTime()).plusSeconds(seconds).toDate())){
// System.out.println();
// }
GreenHistIndexDTO dto = greenwaveHistProvider.findGreenIndexByDateScope(result.getGreenId(),controlStartTime,controlEndTime);
durationList.add(result);
AnalysisGreenWaveOptimizeWeek data = new AnalysisGreenWaveOptimizeWeek();
data.setGreenId(result.getGreenId());
data.setStragetyId(result.getStragetyId());
data.setRoadDirection(result.getRoadDirection());
if (dto != null) {
data.setCapacity(dto.getCapacity());
data.setDelayTime(dto.getDelayTime());
data.setSpeed(dto.getSpeed());
data.setTravelTime(dto.getTravelTime());
data.setStopTimes(dto.getStopTimes());
data.setCongestIndex(dto.getTrafficIndex());
}
data.setWeekDay(result.getWeekDay());
data.setOptimizeStartTime(LocalDateTime.parse(controlStartTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
data.setOptimizeEndTime(LocalDateTime.parse(controlEndTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
data.setOptimizeCount(1);
data.setOptimizeDuration(seconds);
data.setWeekStartTime(LocalDateTimeUtil.convertDateToLDT(result.getWeekStartDay()));
data.setWeekEndTime(LocalDateTimeUtil.convertDateToLDT(result.getWeekEndDay()));
data.setYearWeek(result.getYearWeek());
data.setInsertTime(LocalDateTime.now());
durationList.add(data);
i++;
}
}
if (!durationList.isEmpty()) {
analysisGreenWaveOptimizeWeekMapper.insertBatch(durationList);
}
log.info("更新干线策略持续时间据耗时:{}ms,size:{}", et - st, durationList.size());
long et = System.currentTimeMillis();
log.info("批量保存干线优化数据据耗时:{}ms,size:{}", et - st, durationList.size());
} catch (Exception e) {
log.error("", e);
......
......@@ -2,9 +2,11 @@ package net.wanji.opt.vo2.report;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer;
import java.util.ArrayList;
import java.util.Date;
......@@ -34,8 +36,11 @@ public class GreenReportRunStateResponseVO {
private String amMaxTravelTime;
@ApiModelProperty(value = "本周早高峰最大行程时间同比(上周)情况", example = "减少6分钟")
private String amMaxTravelTimeSameRatioSituation;
@ApiModelProperty(value = "平均拥堵指数", example = "4.5")
private String amAvgContestIndex;
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double amAvgContestIndex;
@ApiModelProperty(value = "平均拥堵指数同比(上周)情况", example = "减少0.5")
private String amAvgContestIndexSameRatioSituation;
......@@ -54,8 +59,11 @@ public class GreenReportRunStateResponseVO {
private String pmMaxTravelTime;
@ApiModelProperty(value = "本周早高峰最大行程时间同比(上周)情况", example = "减少6分钟")
private String pmMaxTravelTimeSameRatioSituation;
@ApiModelProperty(value = "平均拥堵指数", example = "4.5")
private String pmAvgContestIndex;
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double pmAvgContestIndex;
@ApiModelProperty(value = "平均拥堵指数同比(上周)情况", example = "减少0.5")
private String pmAvgContestIndexSameRatioSituation;
......
package net.wanji.opt.vo2.report;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer;
@Data
......@@ -18,20 +20,27 @@ public class GreenReportRunStatedDataVO {
private String lastWeekCongestSpan;
@ApiModelProperty(value = "本周拥堵指数", example = "3.5")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double thisWeekCongestIndex;
@ApiModelProperty(value = "上周拥堵指数", example = "3.0")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double lastWeekCongestIndex;
@ApiModelProperty(value = "本周平均车速km/h", example = "30.5")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double thisWeekAvgSpeed;
@ApiModelProperty(value = "上周平均车速km", example = "30.2")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double lastWeekAvgSpeed;
@ApiModelProperty(value = "本周行程时间(分钟)", example = "6.5")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double thisWeekTravelTime;
@ApiModelProperty(value = "上周行程时间(分钟)", example = "8.5")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double lastWeekTravelTime;
@ApiModelProperty(value = "峰期时段", example = "7:35~8:40")
......
......@@ -945,4 +945,64 @@
</select>
<!-- 按时间范围统计干线指标 -->
<select id="findGreenIndexByDateScope" resultType="net.wanji.opt.dto.report.GreenHistIndexDTO">
SELECT
a.green_id greenId,
a.road_direction roadDirection,
b.flow,
b.flow_all flowAll,
round(AVG(a.traffic_index),2) trafficIndex,
round(AVG(a.speed),2) speed,
round(AVG(a.delay_time)) delayTime,
round(AVG(a.stop_times),2) stopTimes,
round(AVG(a.trval_time)) travelTime
FROM
t_greenwave_hist a
LEFT JOIN
(
<!-- 取干线双向协调方向流量最大的 -->
SELECT t3.green_id,t3.cross_id,sum(t3.flow) flow,GROUP_CONCAT(t3.flow) flow_all from (
SELECT t1.green_id,t2.cross_id,t2.dir_type,t2.flow
from t_greenwave_cross t1
join t_cross_dir_data_hist t2
on t1.cross_id=t2.cross_id and t1.in_dir=t2.dir_type
where 1=1
<if test="greenId!=null and greenId !=''">
and t1.green_id = #{greenId}
</if>
<if test="startDate !=null and endDate !=null">
AND t2.start_time BETWEEN #{startDate}
AND #{endDate}
</if>
union
SELECT t1.green_id,t2.cross_id,t2.dir_type,t2.flow
from t_greenwave_cross t1
join t_cross_dir_data_hist t2
on t1.cross_id=t2.cross_id and t1.out_dir=t2.dir_type
WHERE 1=1
<if test="greenId!=null and greenId !=''">
and t1.green_id = #{greenId}
</if>
<if test="startDate !=null and endDate !=null">
AND t2.start_time BETWEEN #{startDate}
AND #{endDate}
</if>
) t3
GROUP BY t3.green_id,t3.cross_id
ORDER BY flow desc limit 1
) b
on a.green_id=b.green_id
WHERE 1=1
<if test="greenId!=null and greenId !=''">
and a.green_id = #{greenId}
</if>
<if test="startDate !=null and endDate !=null">
AND a.start_time BETWEEN #{startDate}
AND #{endDate}
</if>
GROUP BY a.green_id,a.road_direction
</select>
</mapper>
......@@ -47,12 +47,14 @@
<!-- 查询上周优化记录 -->
<select id="findGreenWaveOptHist" resultType="net.wanji.opt.dto.report.StrategyGreenOptHistDTO">
SELECT a.green_id,
a.dir as road_direction,
a.type as stragety_id,
a.control_time,
a.control_duration,
a.control_method,
min(DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)) week_start_day,
max(DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) ) +1 DAY)) week_end_day,
(week(control_time)+1) year_week,
concat(year(control_time),'',(week(control_time)+1)) year_week,
(WEEKDAY(control_time)+1) week_day
FROM t_strategy_green_opt_hist a
WHERE control_time >= DATE_SUB(CURDATE(), INTERVAL (WEEKDAY(CURDATE()) + 7) DAY)
......
......@@ -87,6 +87,23 @@
<if test="insertTime != null">DATE_FORMAT(#{insertTime},'%Y-%m-%d %H:%i:%s'),</if>
<if test="greenId != null and greenId != ''">#{greenId},</if>
</trim>
ON DUPLICATE KEY UPDATE
event_serial_number=VALUES(event_serial_number),
<if test="crossId != null">cross_id=VALUES(cross_id),</if>
<if test="eventCategory != null"> event_category=VALUES(event_category),</if>
<if test="eventType != null">event_type=VALUES(event_type),</if>
<if test="happenStartTime != null">happen_start_time=VALUES(happen_start_time),</if>
<if test="happenEndTime != null">happen_end_time=VALUES(happen_end_time),</if>
<if test="duration != null">duration=VALUES(duration),</if>
<if test="optStatus != null">opt_status=VALUES(opt_status),</if>
<if test="dir != null">dir=VALUES(dir),</if>
<if test="optStartTime != null">opt_start_time=VALUES(opt_start_time),</if>
<if test="optEndTime != null">opt_end_time=VALUES(opt_end_time),</if>
<if test="optDuration != null">opt_duration=VALUES(opt_duration),</if>
<if test="insertTime != null">insert_time=VALUES(insert_time),</if>
<if test="greenId != null and greenId != ''">green_id=VALUES(green_id),</if>
dt=VALUES(dt)
</insert>
</mapper>
\ No newline at end of file
......@@ -5,7 +5,7 @@
<!-- 通用设置 -->
<!-- 通用查询列 -->
<sql id="Base_Column_List">
green_id, road_direction, week_day, optimize_start_time, optimize_end_time, stragety_id, optimize_count, optimize_duration, capacity, stop_times, delay_time, travel_time, speed, year_week, week_start_time, week_end_time, insert_time
green_id, road_direction, week_day, optimize_start_time, optimize_end_time, stragety_id, optimize_count, optimize_duration, capacity,congest_index, stop_times, delay_time, travel_time, speed, year_week, week_start_time, week_end_time, insert_time
</sql>
<!-- 通用条件列 -->
......@@ -123,6 +123,7 @@
<result column="optimize_start_time" property="optimizeStartTime"/>
<result column="optimize_end_time" property="optimizeEndTime"/>
<result column="stragety_id" property="stragetyId"/>
<result column="congest_index" property="congestIndex"/>
<result column="optimize_count" property="optimizeCount"/>
<result column="optimize_duration" property="optimizeDuration"/>
<result column="capacity" property="capacity"/>
......@@ -197,6 +198,7 @@
,week_start_time
,week_end_time
,insert_time
,congest_index
) VALUES (
#{greenId}
,#{roadDirection}
......@@ -215,6 +217,76 @@
,#{weekStartTime}
,#{weekEndTime}
,#{insertTime}
,#{congestIndex}
)
</insert>
<insert id="insertBatch" parameterType="net.wanji.opt.entity.report.AnalysisGreenWaveOptimizeWeek">
INSERT INTO t_analysis_green_wave_optimize_week (
green_id
,road_direction
,week_day
,optimize_start_time
,optimize_end_time
,stragety_id
,optimize_count
,optimize_duration
,capacity
,stop_times
,delay_time
,travel_time
,speed
,year_week
,week_start_time
,week_end_time
,insert_time
,congest_index
) VALUES
<foreach collection="list" item="entity" separator=",">
(
#{entity.greenId}
,#{entity.roadDirection}
,#{entity.weekDay}
,#{entity.optimizeStartTime}
,#{entity.optimizeEndTime}
,#{entity.stragetyId}
,#{entity.optimizeCount}
,#{entity.optimizeDuration}
,#{entity.capacity}
,#{entity.stopTimes}
,#{entity.delayTime}
,#{entity.travelTime}
,#{entity.speed}
,#{entity.yearWeek}
,#{entity.weekStartTime}
,#{entity.weekEndTime}
,#{entity.insertTime}
,#{entity.congestIndex}
)
</foreach>
ON DUPLICATE KEY UPDATE
green_id = VALUES(green_id),
road_direction = VALUES(road_direction),
week_day = VALUES(week_day),
optimize_start_time = VALUES(optimize_start_time),
optimize_end_time = VALUES(optimize_end_time),
stragety_id = VALUES(stragety_id),
optimize_count = VALUES(optimize_count),
optimize_duration = VALUES(optimize_duration),
capacity = VALUES(capacity),
stop_times = VALUES(stop_times),
delay_time = VALUES(delay_time),
delay_time = VALUES(delay_time),
travel_time = VALUES(travel_time),
speed = VALUES(speed),
year_week = VALUES(year_week),
week_start_time = VALUES(week_start_time),
week_end_time = VALUES(week_end_time),
insert_time = VALUES(insert_time),
congest_index = VALUES(congest_index)
</insert>
</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