Commit 36f9f27d authored by zhoushiguang's avatar zhoushiguang

国产化修改

parent ea984a31
......@@ -71,7 +71,7 @@ public class BaseCrossInfoCache implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
init();
//init();
}
public void init() {
......
......@@ -53,7 +53,7 @@ public class BaseCrossPhaseInfoCache implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
init();
// init();
}
public void init() {
......
......@@ -53,7 +53,7 @@ public class CrossDirTurnPhaseCache implements CommandLineRunner {
@Override
public void run(String... args) {
init();
// init();
}
/**
......
......@@ -62,7 +62,7 @@ public class CrossRidInfoCache implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
init();
// init();
}
public void init() {
......
......@@ -26,7 +26,7 @@ public class GreenCrossDirInfoCache implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
try {
init();
// init();
} catch (Exception e) {
log.error("缓存加载失败:", e);
throw new RuntimeException(e);
......
......@@ -28,12 +28,12 @@ public class GreenWaveInfoCache implements CommandLineRunner {
@Override
public void run(String... args) throws Exception {
try {
List<GreenwaveInfoPO> greenWaveInfoPOS = greenwaveInfoMapper.selectAll();
if (!CollectionUtils.isEmpty(greenWaveInfoPOS)) {
for (GreenwaveInfoPO greenWaveInfoPO : greenWaveInfoPOS) {
greenWaveMap.put(greenWaveInfoPO.getId(), greenWaveInfoPO);
}
}
// List<GreenwaveInfoPO> greenWaveInfoPOS = greenwaveInfoMapper.selectAll();
// if (!CollectionUtils.isEmpty(greenWaveInfoPOS)) {
// for (GreenwaveInfoPO greenWaveInfoPO : greenWaveInfoPOS) {
// greenWaveMap.put(greenWaveInfoPO.getId(), greenWaveInfoPO);
// }
// }
} catch (Exception e) {
log.error("绿波信息初始化失败:", e);
throw new RuntimeException("绿波信息初始化失败!");
......
......@@ -8,7 +8,7 @@ import java.text.ParseException;
import java.util.List;
public interface AnalysisGreenCongestionPeriodService {
public void selectCountByCongestionPeriod() throws ParseException;
public void selectCountByCongestionPeriod() throws ParseException;
public void selectCountByLandData() throws ParseException;
public void selectCountByCrossData() throws ParseException;
public void selectCountByCrossDataOneDay() throws ParseException;
......
package net.wanji.opt.servicev2.judgeanalysis.impl;
import com.github.pagehelper.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import net.wanji.databus.dao.entity.GreenwaveInfoPO;
import net.wanji.databus.dao.mapper.GreenwaveInfoMapper;
import net.wanji.opt.common.TimeIntervalMerger;
......@@ -55,6 +56,7 @@ import java.util.stream.Collectors;
* @since 2025-03-20
*/
@Service
@Slf4j
public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCongestionPeriodService {
@Resource
private AnalysisGreenCongestionPeriodMapper analysisGreenCongestionPeriodMapper;
......@@ -80,7 +82,10 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
for (int i = 0; i < 7; i++) {
LocalDate date = todayOfWeek.plusDays(i);
//获取干线数据
long st = System.currentTimeMillis();
List<AnalysisGreenCongestionPeriod> greenList = analysisGreenCongestionPeriodMapper.selectGreenDataHist(date.toString());
long et = System.currentTimeMillis();
log.info("获取干线数据耗时:{}ms,date:{},size:{}",et-st,date.toString(),greenList.size());
LinkedList<AnalysisGreenCongestionPeriod> queue = new LinkedList<>();
String greenId = "";
String roadDirection = "";
......@@ -105,8 +110,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay", i + 1);
map.put("roadDirection", roadDirection);
map.put("peakType", isMoning(startTime));
map.put("weekStartTime", todayOfWeek);
map.put("weekEndTime", endOfWeek);
map.put("weekStartTime", todayOfWeek.toString());
map.put("weekEndTime", endOfWeek.toString());
map.put("greenId", greenId);
map.put("status", queue.getFirst().getStatus());
//写入缓行数据
......@@ -132,8 +137,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay", i + 1);
map.put("roadDirection", roadDirection);
map.put("peakType", isMoning(startTime));
map.put("weekStartTime", todayOfWeek);
map.put("weekEndTime", endOfWeek);
map.put("weekStartTime", todayOfWeek.toString());
map.put("weekEndTime", endOfWeek.toString());
map.put("greenId", greenId);
map.put("status", queue.getFirst().getStatus());
//写入缓行数据
......@@ -153,8 +158,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay", i + 1);
map.put("roadDirection", roadDirection);
map.put("peakType", isMoning(startTime));
map.put("weekStartTime", todayOfWeek);
map.put("weekEndTime", endOfWeek);
map.put("weekStartTime", todayOfWeek.toString());
map.put("weekEndTime", endOfWeek.toString());
map.put("greenId", greenId);
map.put("status", queue.getFirst().getStatus());
//写入缓行数据
......@@ -174,8 +179,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay", i + 1);
map.put("roadDirection", roadDirection);
map.put("peakType", isMoning(startTime));
map.put("weekStartTime", todayOfWeek);
map.put("weekEndTime", endOfWeek);
map.put("weekStartTime", todayOfWeek.toString());
map.put("weekEndTime", endOfWeek.toString());
map.put("greenId", greenId);
map.put("status", queue.getLast().getStatus());
//写入缓行数据
......@@ -205,6 +210,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
enqueue(queue, temp);
}
}
long et1 = System.currentTimeMillis();
log.info("干线数据计算总耗时:{}ms,date:{}",et1-et,date.toString());
}
}
......@@ -610,8 +617,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",i + 1);
map.put("roadDirection",roadDirection);
map.put("peakType",isMoning(startTime));
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("avgFlow",avgFlow);
map.put("greenId",temp.getGreenId());
......@@ -708,8 +715,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",i + 1);
map.put("roadDirection",roadDirection);
map.put("peakType",3);
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("avgFlow",avgFlow);
map.put("greenId",queue.getFirst().getGreenId());
......@@ -775,8 +782,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",i + 1);
map.put("roadDirection",roadDirection);
map.put("peakType",3);
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("avgFlow",avgFlow);
map.put("greenId",peakDetailList.get(b).getGreenId());
......@@ -833,8 +840,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay", i + 1);
map.put("roadDirection", roadDirection);
map.put("peakType", 3);
map.put("weekStartTime", todayOfWeek);
map.put("weekEndTime", endOfWeek);
map.put("weekStartTime", todayOfWeek.toString());
map.put("weekEndTime", endOfWeek.toString());
map.put("maxFlow", maxFlow);
map.put("avgFlow", avgFlow);
map.put("greenId", peakDetailList.get(b).getGreenId());
......@@ -895,8 +902,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",i + 1);
map.put("roadDirection",roadDirection);
map.put("peakType",3);
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("avgFlow",avgFlow);
map.put("greenId",queue.getFirst().getGreenId());
......@@ -1481,8 +1488,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",day);
map.put("peakType",isMoning(startTime));
map.put("dayType",isWorkDate(day));
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("maxFlowDate",maxFlowDate);
map.put("sumFlowDate",sumFlowDate);
......@@ -1506,15 +1513,19 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
list.clear();
crossId = temp.getCrossId();
//计算该路口交通指数阈值,取一天的9点至16点30之间交通指数倒序的90%的数值为动态阈值
List<laneDataHist> crossTrafficList = analysisGreenCongestionPeriodMapper.selectCrossTrafficThreshold(date.toString().replaceAll("-",""),crossId);
if(crossTrafficList.get(9).getTrafficIndex() <= 1.5) {
trafficThreshold = 1.5;
}else {
trafficThreshold = crossTrafficList.get(9).getTrafficIndex();
try {
List<laneDataHist> crossTrafficList = analysisGreenCongestionPeriodMapper.selectCrossTrafficThreshold(date.toString().replaceAll("-", ""), crossId);
if (crossTrafficList.get(9).getTrafficIndex() <= 1.5) {
trafficThreshold = 1.5;
} else {
trafficThreshold = crossTrafficList.get(9).getTrafficIndex();
}
startTime = "";
endTime = "";
enqueue(queue, temp);
}catch (Exception e) {
log.error("",e);
}
startTime = "";
endTime = "";
enqueue(queue,temp);
}
}
queue.clear();
......@@ -1590,8 +1601,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",day);
map.put("peakType",3);
map.put("dayType",isWorkDate(day));
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("maxFlowDate",maxFlowDate);
map.put("sumFlowDate",sumFlowDate);
......@@ -1668,8 +1679,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",day);
map.put("peakType",3);
map.put("dayType",isWorkDate(day));
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("maxFlowDate",maxFlowDate);
map.put("sumFlowDate",sumFlowDate);
......@@ -1738,8 +1749,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",day);
map.put("peakType",3);
map.put("dayType",isWorkDate(day));
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("maxFlowDate",maxFlowDate);
map.put("sumFlowDate",sumFlowDate);
......@@ -1811,8 +1822,8 @@ public class AnalysisGreenCongestionPeriodServiceImpl implements AnalysisGreenCo
map.put("weekDay",day);
map.put("peakType",3);
map.put("dayType",isWorkDate(day));
map.put("weekStartTime",todayOfWeek);
map.put("weekEndTime",endOfWeek);
map.put("weekStartTime",todayOfWeek.toString());
map.put("weekEndTime",endOfWeek.toString());
map.put("maxFlow",maxFlow);
map.put("maxFlowDate",maxFlowDate);
map.put("sumFlowDate",sumFlowDate);
......
......@@ -13,6 +13,7 @@ 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.text.ParseException;
......@@ -20,7 +21,7 @@ import java.text.ParseException;
@Configurable
@EnableScheduling
@Slf4j
@Profile("docker")
@Profile("!dev")
public class AnalysisGreenCongestionPeriodWeekTask {
@Autowired
private AnalysisGreenCongestionPeriodService analysisGreenCongestionPeriodService;
......@@ -29,31 +30,44 @@ public class AnalysisGreenCongestionPeriodWeekTask {
EventInfoService eventInfoService;
@Scheduled(cron = "0 30 2 ? * 1")
public void task() throws ParseException {
//@PostConstruct
public void task() throws ParseException {
try {
long st = System.currentTimeMillis();
analysisGreenCongestionPeriodService.selectCountByCongestionPeriod();
long et = System.currentTimeMillis();
log.info("计算任务 selectCountByCongestionPeriod 耗时:{}ms", et - st);
} catch (Exception e) {
log.error("", e);
}
try {
long st = System.currentTimeMillis();
analysisGreenCongestionPeriodService.selectCountByLandData();
//analysisGreenCongestionPeriodService.selectCountByCrossData();
}catch (Exception e){
log.error("",e);
long et = System.currentTimeMillis();
log.info("计算任务 selectCountByLandData 耗时:{}ms", et - st);
} catch (Exception e) {
log.error("", e);
}
}
@Scheduled(cron = "0 0 2 ? * ? ")
public void taskDay() throws ParseException {
public void taskDay() throws ParseException {
try {
long st = System.currentTimeMillis();
analysisGreenCongestionPeriodService.selectCountByCrossDataOneDay();
}catch (Exception e){
log.error("",e);
long et = System.currentTimeMillis();
log.info("计算任务 taskDay 耗时:{}ms", et - st);
} catch (Exception e) {
log.error("", e);
}
}
@Scheduled(cron = "0 0 2 ? * ? ")
public void insertCrossSlowRunEventData() throws ParseException {
public void insertCrossSlowRunEventData() throws ParseException {
long st = System.currentTimeMillis();
try {
DateTime endTDateTime = DateUtil.date();
......@@ -63,13 +77,15 @@ public class AnalysisGreenCongestionPeriodWeekTask {
String sdt = startTDateTime.toString("yyyy-MM-dd HH:00:00");
//窗口截止时间
endTDateTime = DateUtil.parseDateTime(sdt).offset(DateField.HOUR,24).offset(DateField.SECOND,-1);
endTDateTime = DateUtil.parseDateTime(sdt).offset(DateField.HOUR, 24).offset(DateField.SECOND, -1);
String edt = endTDateTime.toString("yyyy-MM-dd HH:mm:ss");
eventInfoService.insertCrossSlowRunEventData(sdt,edt);
eventInfoService.insertCrossSlowRunEventData(sdt, edt);
}catch (Exception e){
log.error("",e);
} catch (Exception e) {
log.error("", e);
}
long et = System.currentTimeMillis();
log.info("计算任务 insertCrossSlowRunEventData 耗时:{}ms", et - st);
}
}
......@@ -22,14 +22,14 @@ public class AnalysisProblemCrossDayTask implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("服务启动时--干线协调方向频发拥堵/缓行路段--任务执行时间:" + LocalDateTime.now());
// log.info("服务启动时--干线协调方向频发拥堵/缓行路段--任务执行时间:" + LocalDateTime.now());
// 干线协调方向频发拥堵/缓行路段
try {
// analysisProblemCrossDayService.insertAnalysisProblemCrossDay();
} catch (Exception e) {
log.error("服务启动时--干线协调方向频发拥堵/缓行路段--任务执行错误" + e);
}
log.info("服务启动时--干线协调方向频发拥堵/缓行路段--任务执行结束时间:" + LocalDateTime.now());
// log.info("服务启动时--干线协调方向频发拥堵/缓行路段--任务执行结束时间:" + LocalDateTime.now());
}
/**
......
......@@ -23,14 +23,14 @@ public class AnalysisProblemCrossDirHourTask implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("服务启动时--周总体拥堵概况更新--任务执行时间:" + LocalDateTime.now());
// log.info("服务启动时--周总体拥堵概况更新--任务执行时间:" + LocalDateTime.now());
// 周总体拥堵概况更新
try {
// executeCrossOverFlowTask();
}catch (Exception e){
log.error("服务启动时--周总体拥堵概况更新--任务执行错误" + e);
}
log.info("服务启动时--周总体拥堵概况更新--任务执行结束时间:" + LocalDateTime.now());
// log.info("服务启动时--周总体拥堵概况更新--任务执行结束时间:" + LocalDateTime.now());
}
/**
......
......@@ -18,14 +18,14 @@ public class GreenWaveWeekDataTask implements ApplicationRunner {
private GreenWaveWeekDataService greenWaveWeekDataService;
@Override
public void run(ApplicationArguments args) throws Exception {
log.info("服务启动时--周总体拥堵概况更新--任务执行时间:" + LocalDateTime.now());
// log.info("服务启动时--周总体拥堵概况更新--任务执行时间:" + LocalDateTime.now());
// 周总体拥堵概况更新
try {
// greenWaveWeekDataService.insertGreenWaveWeekData();
}catch (Exception e){
log.error("服务启动时--周总体拥堵概况更新--任务执行错误" + e);
}
log.info("服务启动时--周总体拥堵概况更新--任务执行结束时间:" + LocalDateTime.now());
// log.info("服务启动时--周总体拥堵概况更新--任务执行结束时间:" + LocalDateTime.now());
}
/**
......
......@@ -243,130 +243,7 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
//==========================================================================================================//
List<AnalysisReportCrossOptimizeDetail> optimizeList = new ArrayList<>();
Map<String, List<StrategyCrossResultEntity>> groupByCross = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getCurrentAlgo()));
for (Map.Entry<String, List<StrategyCrossResultEntity>> entry : groupByCross.entrySet()) {
String[] sps = entry.getKey().split("_");
String crossId = sps[0];
String strategy = sps[1];
String eventType = null;
if (Objects.equals("1", strategy)) {
eventType = "701";
} else if (Objects.equals("2", strategy)) {
eventType = "702";
} else if (Objects.equals("3", strategy)) {
eventType = "703";
} else if (Objects.equals("4", strategy)) {
eventType = "704";
}
List<StrategyCrossResultEntity> value = entry.getValue();
StrategyCrossResultEntity minTime = value.stream().min(Comparator.comparing(o -> o.getIssueTime())).orElse(new StrategyCrossResultEntity());
StrategyCrossResultEntity maxTime = value.stream().max(Comparator.comparing(o -> o.getIssueTime())).orElse(new StrategyCrossResultEntity());
int duration = value.stream().mapToInt(o -> o.getDuration()).sum();
long count = value.size();
//优化控制时段-开始时间
String controlStartTime = DateUtil.formatDate(minTime.getIssueTime(), "yyyy-MM-dd HH:mm:ss");
//优化控制时段-截止时间
String controlEndTime = new DateTime(maxTime.getIssueTime()).plusSeconds(duration).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
DateTime optStartTime = DateTime.parse(controlStartTime, DateTimeFormat.forPattern(EsDateIndexUtil.YMD_HM_FORMATTER));
String optStartTimeStr = controlStartTime.substring(0, controlStartTime.indexOf(" ") + 1) + Tools.fillZeroFront(optStartTime.getHourOfDay() + "", 2) + ":" + Tools.fillZeroFront((int) Math.ceil(optStartTime.getMinuteOfHour() / 5) * 5 + "", 2) + ":00";
//===========================================================================//
Map<String, Object> params = new HashMap<>();
params.put("crossId", crossId);
params.put("startDate", optStartTimeStr);
params.put("endDate", controlEndTime);
params.put("groupType", "0");
params.put("objectType", "4");
//本周指标数据
List<CrossLaneDataHistPoExtend> thisWeekList = greenwaveHistoryMapper.findCrossObjectIndex(params);
AnalysisReportCrossOptimizeDetail thisData = this.getWeedData(thisWeekList);
//===========================================================================//
//上周策略同期-开始时间
DateTime lastWeekDateStartTime = optStartTime.minusWeeks(1);
DateTime lastWeekDateEndTime = new DateTime(maxTime.getIssueTime()).plusSeconds(duration).minusWeeks(1);
String lastWeekStartTime = lastWeekDateStartTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
String lastOptStartTimeStr = lastWeekStartTime.substring(0, lastWeekStartTime.indexOf(" ") + 1) + Tools.fillZeroFront(lastWeekDateStartTime.getHourOfDay() + "", 2) + ":" + Tools.fillZeroFront((int) Math.ceil(lastWeekDateStartTime.getMinuteOfHour() / 5) * 5 + "", 2) + ":00";
String lastWeekEndTime = lastWeekDateEndTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
params.put("startDate", lastOptStartTimeStr);
params.put("endDate", lastWeekEndTime);
//上周指标数据
List<CrossLaneDataHistPoExtend> lastWeekList = greenwaveHistoryMapper.findCrossObjectIndex(params);
AnalysisReportCrossOptimizeDetail lastData = this.getWeedData(lastWeekList);
DateTime issueTime = new DateTime(minTime.getIssueTime());
//===========================================================================//
AnalysisReportCrossOptimizeDetail detail = new AnalysisReportCrossOptimizeDetail();
detail.setCrossId(minTime.getCrossId());
detail.setYearWeek(Integer.parseInt(issueTime.getYear() + "" + issueTime.getWeekOfWeekyear()));
detail.setWeekDay(issueTime.getDayOfWeek() + 1);
detail.setWeekStartTime(cn.hutool.core.date.DateUtil.beginOfWeek(minTime.getIssueTime()).toLocalDateTime());
detail.setWeekEndTime(cn.hutool.core.date.DateUtil.endOfWeek(minTime.getIssueTime()).toLocalDateTime());
detail.setOptimizeCount((int) count);
detail.setOptimizeDuration(duration);
detail.setOptimizeStartTime(LocalDateTime.parse(controlStartTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
detail.setOptimizeEndTime(LocalDateTime.parse(controlEndTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
detail.setStragetyId(minTime.getCurrentAlgo());
detail.setCapacity(thisData.getCapacity());
detail.setStopTimes(thisData.getStopTimes());
detail.setDelayTime(thisData.getDelayTime());
detail.setMaxQueueLength(thisData.getMaxQueueLength());
detail.setLastWeekCapacity(lastData.getCapacity());
detail.setLastWeekStopTimes(lastData.getStopTimes());
detail.setLastWeekDelayTime(lastData.getDelayTime());
detail.setLastWeekMaxQueueLength(lastData.getMaxQueueLength());
detail.setInsertTime(LocalDateTime.now());
//===========================================================================//
String eventSerialNumber = minTime.getEventId();
Map<String, Object> eventParma = new HashMap<>();
eventParma.put("eventSerialNumber", eventSerialNumber);
List<EventInfo> eventInfoList = eventInfoMapper.findByMap(eventParma);
//获取事件方向
if (!eventInfoList.isEmpty()) {
String dir = eventInfoList.get(0).getDir();
detail.setDirs(CommonUtils.getEventHappenDirName(dir));
}
//===========================================================================//
params.clear();
params.put("crossId", crossId);
params.put("dt", DateUtil.formatDate(minTime.getIssueTime(), "yyyyMMdd"));
params.put("eventType", eventType);
EventStatisticPo countPo = holoEventMapper.findCrossEventCount(params);
if (countPo != null) {
detail.setProblemCount(countPo.getEventCount());
}
params.put("dt", DateUtil.formatDate(lastWeekDateStartTime.toDate(), "yyyyMMdd"));
//===========================================================================//
EventStatisticPo lastCountPo = holoEventMapper.findCrossEventCount(params);
if (lastCountPo != null) {
detail.setLastWeekOptimizeCount(lastCountPo.getEventCount());
}
//===========================================================================//
AiOptimizeStatistic param = new AiOptimizeStatistic();
param.setCrossId(crossId);
param.setStatisticTime(Integer.valueOf( DateUtil.formatDate(lastWeekDateStartTime.toDate(), "yyyyMMdd")));
param.setStrategy(Integer.valueOf(strategy));
List<AiOptimizeStatistic> lastOptList = aiOptimizeStatisticMapper.findAiOptimizeStatisticByCondition(param);
if (!lastOptList.isEmpty()) {
detail.setLastWeekOptimizeDuration(lastOptList.get(0).getOptimizeDuration());
detail.setLastWeekOptimizeCount(lastOptList.get(0).getOptimizeCount());
}
//===========================================================================//
optimizeList.add(detail);
if (optimizeList.size() % 100 == 0) {
analysisReportCrossOptimizeDetailMapper.insertBatch(optimizeList);
optimizeList.clear();
log.info("计算路口周报-路口优分批入库耗时:{}ms,size:{} ,starDate:{}", System.currentTimeMillis() - et1, optimizeList.size(), startDate);
}
}
this.saveOptimizeInfo(optimizeList, list, startDate);
//==========================================================================================================//
if (!optimizeList.isEmpty()) {
analysisReportCrossOptimizeDetailMapper.insertBatch(optimizeList);
......@@ -383,6 +260,134 @@ public class ReportGreenAndCrossOptimizeStatisticTask {
}
private void saveOptimizeInfo(List<AnalysisReportCrossOptimizeDetail> optimizeList, List<StrategyCrossResultEntity> list, String startDate) {
long et1 = System.currentTimeMillis();
Map<String, List<StrategyCrossResultEntity>> groupByCross = list.stream().collect(Collectors.groupingBy(o -> o.getCrossId() + "_" + o.getCurrentAlgo()));
for (Map.Entry<String, List<StrategyCrossResultEntity>> entry : groupByCross.entrySet()) {
String[] sps = entry.getKey().split("_");
String crossId = sps[0];
String strategy = sps[1];
String eventType = null;
if (Objects.equals("1", strategy)) {
eventType = "701";
} else if (Objects.equals("2", strategy)) {
eventType = "702";
} else if (Objects.equals("3", strategy)) {
eventType = "703";
} else if (Objects.equals("4", strategy)) {
eventType = "704";
}
List<StrategyCrossResultEntity> value = entry.getValue();
StrategyCrossResultEntity minTime = value.stream().min(Comparator.comparing(o -> o.getIssueTime())).orElse(new StrategyCrossResultEntity());
StrategyCrossResultEntity maxTime = value.stream().max(Comparator.comparing(o -> o.getIssueTime())).orElse(new StrategyCrossResultEntity());
int duration = value.stream().mapToInt(o -> o.getDuration()).sum();
long count = value.size();
//优化控制时段-开始时间
String controlStartTime = DateUtil.formatDate(minTime.getIssueTime(), "yyyy-MM-dd HH:mm:ss");
//优化控制时段-截止时间
String controlEndTime = new DateTime(maxTime.getIssueTime()).plusSeconds(duration).toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
DateTime optStartTime = DateTime.parse(controlStartTime, DateTimeFormat.forPattern(EsDateIndexUtil.YMD_HM_FORMATTER));
String optStartTimeStr = controlStartTime.substring(0, controlStartTime.indexOf(" ") + 1) + Tools.fillZeroFront(optStartTime.getHourOfDay() + "", 2) + ":" + Tools.fillZeroFront((int) Math.ceil(optStartTime.getMinuteOfHour() / 5) * 5 + "", 2) + ":00";
//===========================================================================//
Map<String, Object> params = new HashMap<>();
params.put("crossId", crossId);
params.put("startDate", optStartTimeStr);
params.put("endDate", controlEndTime);
params.put("groupType", "0");
params.put("objectType", "4");
//本周指标数据
List<CrossLaneDataHistPoExtend> thisWeekList = greenwaveHistoryMapper.findCrossObjectIndex(params);
AnalysisReportCrossOptimizeDetail thisData = this.getWeedData(thisWeekList);
//===========================================================================//
//上周策略同期-开始时间
DateTime lastWeekDateStartTime = optStartTime.minusWeeks(1);
DateTime lastWeekDateEndTime = new DateTime(maxTime.getIssueTime()).plusSeconds(duration).minusWeeks(1);
String lastWeekStartTime = lastWeekDateStartTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
String lastOptStartTimeStr = lastWeekStartTime.substring(0, lastWeekStartTime.indexOf(" ") + 1) + Tools.fillZeroFront(lastWeekDateStartTime.getHourOfDay() + "", 2) + ":" + Tools.fillZeroFront((int) Math.ceil(lastWeekDateStartTime.getMinuteOfHour() / 5) * 5 + "", 2) + ":00";
String lastWeekEndTime = lastWeekDateEndTime.toString(DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
params.put("startDate", lastOptStartTimeStr);
params.put("endDate", lastWeekEndTime);
//上周指标数据
List<CrossLaneDataHistPoExtend> lastWeekList = greenwaveHistoryMapper.findCrossObjectIndex(params);
AnalysisReportCrossOptimizeDetail lastData = this.getWeedData(lastWeekList);
DateTime issueTime = new DateTime(minTime.getIssueTime());
//===========================================================================//
AnalysisReportCrossOptimizeDetail detail = new AnalysisReportCrossOptimizeDetail();
detail.setCrossId(minTime.getCrossId());
detail.setYearWeek(Integer.parseInt(issueTime.getYear() + "" + issueTime.getWeekOfWeekyear()));
detail.setWeekDay(issueTime.getDayOfWeek() + 1);
detail.setWeekStartTime(cn.hutool.core.date.DateUtil.beginOfWeek(minTime.getIssueTime()).toLocalDateTime());
detail.setWeekEndTime(cn.hutool.core.date.DateUtil.endOfWeek(minTime.getIssueTime()).toLocalDateTime());
detail.setOptimizeCount((int) count);
detail.setOptimizeDuration(duration);
detail.setOptimizeStartTime(LocalDateTime.parse(controlStartTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
detail.setOptimizeEndTime(LocalDateTime.parse(controlEndTime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
detail.setStragetyId(minTime.getCurrentAlgo());
detail.setCapacity(thisData.getCapacity());
detail.setStopTimes(thisData.getStopTimes());
detail.setDelayTime(thisData.getDelayTime());
detail.setMaxQueueLength(thisData.getMaxQueueLength());
detail.setLastWeekCapacity(lastData.getCapacity());
detail.setLastWeekStopTimes(lastData.getStopTimes());
detail.setLastWeekDelayTime(lastData.getDelayTime());
detail.setLastWeekMaxQueueLength(lastData.getMaxQueueLength());
detail.setInsertTime(LocalDateTime.now());
//===========================================================================//
String eventSerialNumber = minTime.getEventId();
Map<String, Object> eventParma = new HashMap<>();
eventParma.put("eventSerialNumber", eventSerialNumber);
List<EventInfo> eventInfoList = eventInfoMapper.findByMap(eventParma);
//获取事件方向
if (!eventInfoList.isEmpty()) {
String dir = eventInfoList.get(0).getDir();
detail.setDirs(CommonUtils.getEventHappenDirName(dir));
}
//===========================================================================//
params.clear();
params.put("crossId", crossId);
params.put("dt", DateUtil.formatDate(minTime.getIssueTime(), "yyyyMMdd"));
params.put("eventType", eventType);
EventStatisticPo countPo = holoEventMapper.findCrossEventCount(params);
if (countPo != null) {
detail.setProblemCount(countPo.getEventCount());
}
params.put("dt", DateUtil.formatDate(lastWeekDateStartTime.toDate(), "yyyyMMdd"));
//===========================================================================//
EventStatisticPo lastCountPo = holoEventMapper.findCrossEventCount(params);
if (lastCountPo != null) {
detail.setLastWeekOptimizeCount(lastCountPo.getEventCount());
}
//===========================================================================//
AiOptimizeStatistic param = new AiOptimizeStatistic();
param.setCrossId(crossId);
param.setStatisticTime(Integer.valueOf(DateUtil.formatDate(lastWeekDateStartTime.toDate(), "yyyyMMdd")));
param.setStrategy(Integer.valueOf(strategy));
List<AiOptimizeStatistic> lastOptList = aiOptimizeStatisticMapper.findAiOptimizeStatisticByCondition(param);
if (!lastOptList.isEmpty()) {
detail.setLastWeekOptimizeDuration(lastOptList.get(0).getOptimizeDuration());
detail.setLastWeekOptimizeCount(lastOptList.get(0).getOptimizeCount());
}
//===========================================================================//
optimizeList.add(detail);
if (optimizeList.size() % 100 == 0) {
analysisReportCrossOptimizeDetailMapper.insertBatch(optimizeList);
optimizeList.clear();
log.info("计算路口周报-路口优分批入库耗时:{}ms,size:{} ,starDate:{}", System.currentTimeMillis() - et1, optimizeList.size(), startDate);
}
}
}
private AnalysisReportCrossOptimizeDetail getWeedData(List<CrossLaneDataHistPoExtend> list) {
AnalysisReportCrossOptimizeDetail ret = new AnalysisReportCrossOptimizeDetail();
......
......@@ -2,14 +2,18 @@ spring:
cloud:
nacos:
config:
server-addr: 37.12.182.29:8848
server-addr: 37.8.219.227:28848
file-extension: yaml
group: signal
namespace: signal
username: nacos
password: nacos
password: Nacos@2025
application:
# dubbo启动需要程序名称
name: signal-optimize-data-compute
main:
allow-circular-references: true
inforsuite:
license-path: d:/data/license
\ No newline at end of file
......@@ -48,22 +48,22 @@
where green_id = #{greenId}
</select>
<!-- 统计指标查询 -->
<select id="findStatisticIndex" resultMap="BaseResultMap">
SELECT
green_id,
(case
when road_direction='n2s' then '南向北'
when road_direction='s2n' then '北向南'
when road_direction='e2w' then '东向西'
when road_direction='w2e' then '西向东'
end ) road_direction,
DATE_FORMAT( start_time, '%Y-%m-%d %H:%i:00' ) start_time,
(case
when road_direction='n2s' then '南向北'
when road_direction='s2n' then '北向南'
when road_direction='e2w' then '东向西'
when road_direction='w2e' then '西向东'
end ) road_direction,
to_char(start_time, 'YYYY-MM-DD HH24:MI:00') start_time,
round(AVG(speed),2) speed,
round(AVG(delay_time)) delay_time,
round(AVG(stop_times),2) stop_times,
round(AVG(trval_time)) trval_time,
round(AVG(if(queue_length=-1,null,queue_length))) queue_length,
round(AVG(NULLIF(queue_length, -1))) queue_length,
speed_factor
FROM
t_greenwave_hist
......@@ -71,39 +71,39 @@
<include refid="sql_query"/>
<include refid="fuzzySearch"/>
<if test="startDate !=null and endDate !=null">
AND start_time BETWEEN #{startDate}
AND #{endDate}
AND start_time BETWEEN #{startDate} AND #{endDate}
</if>
GROUP BY green_id,road_direction,DATE_FORMAT( start_time, '%Y-%m-%d %H:%i:00' );
GROUP BY green_id,road_direction, to_char(start_time, 'YYYY-MM-DD HH24:MI:00');
</select>
<select id="selectRunMonitorV2" resultType="net.wanji.databus.dao.entity.GreenwaveHistPOExt">
SELECT green_id,
(case
when road_direction='n2s' then '南向北'
when road_direction='s2n' then '北向南'
when road_direction='e2w' then '东向西'
when road_direction='w2e' then '西向东'
end ) roadDirection,
DATE_FORMAT(start_time, '%H:%i') AS hour,
(case
when road_direction='n2s' then '南向北'
when road_direction='s2n' then '北向南'
when road_direction='e2w' then '东向西'
when road_direction='w2e' then '西向东'
end ) roadDirection,
TO_CHAR( start_time, 'HH24:MI' ) AS hour,
speed AS avg_speed,
traffic_index AS congestion_index,
trval_time AS trval_time
FROM t_greenwave_hist
WHERE gmt_modified &gt; DATE_FORMAT(#{date}, '%Y-%m-%d 00:00:00')
AND gmt_modified &lt; DATE_FORMAT(DATE_ADD(#{date}, INTERVAL 1 HOUR), '%Y-%m-%d %H:00:00')
and green_id = #{greenId}
WHERE gmt_modified &gt; date_trunc('DAY', #{date} :: TIMESTAMP)
AND gmt_modified &lt; date_trunc('HOUR', #{date} :: TIMESTAMP) + interval '1 HOUR'
and green_id = #{greenId}
</select>
<!-- 查看路口协调/非协调方向5分钟粒度平均指标 -->
<select id="findUnCoordinateCrossIndex" resultType="map">
SELECT t.cross_id,
t.start_time,
group_concat(concat(t.type,',',t.queue_length,',',T.stop_times,',',T.flow) SEPARATOR '@') index_list
group_concat(concat(t.type,',',t.queue_length,',',t.stop_times,',',t.flow) SEPARATOR '@') index_list
FROM (
SELECT cross_id,
avg(queue_length) queue_length,
round(avg(stop_times), 2) stop_times,
round(AVG(stop_times) :: numeric, 2 ) stop_times,
DATE_FORMAT(start_time, '%Y-%m-%d %H:%i:00') start_time,
round(avg(flow)) flow,
1 as type
......@@ -111,13 +111,13 @@
WHERE cross_id = #{crossId}
AND dir_type not in (SELECT in_dir from t_greenwave_cross where cross_id=#{crossId}
union SELECT out_dir from t_greenwave_cross where cross_id=#{crossId}
)
)
AND start_time BETWEEN #{startDate} AND #{endDate}
GROUP BY cross_id, start_time
UNION
SELECT cross_id,
avg(queue_length) queue_length,
round(avg(stop_times), 2) stop_times,
round( AVG ( stop_times ) :: numeric , 2 ) stop_times,
DATE_FORMAT(start_time, '%Y-%m-%d %H:%i:00') start_time,
round(avg(flow)) flow,
2 as type
......@@ -125,34 +125,35 @@
WHERE cross_id = #{crossId}
AND dir_type in (SELECT in_dir from t_greenwave_cross where cross_id=#{crossId}
union SELECT out_dir from t_greenwave_cross where cross_id=#{crossId}
)
)
AND start_time BETWEEN #{startDate} AND #{endDate}
GROUP BY cross_id, start_time
) t
GROUP BY t.cross_id,t.start_time
;
GROUP BY t.cross_id,t.start_time;
</select>
<!-- 绿波路口级指标趋势,支持按5分钟、15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findGreenWaveCrossIndex" resultMap="net.wanji.databus.dao.mapper.CrossDataHistMapper.BaseResultMap">
SELECT MIN(ifnull(t.unit_time,#{startDate})) start_time,
SELECT MIN(COALESCE(t.unit_time,#{startDate})) start_time,
cross_id,
AVG(traffic_index) traffic_index,
SUM(flow) flow,
round(AVG(speed),2) speed,
round(AVG(speed) :: NUMERIC,2) speed,
MAX(queue_length) queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(stop_times) :: NUMERIC,2) stop_times,
round(AVG(delay_time),0) delay_time,
round(AVG(sturation),4) sturation
round(AVG(sturation) :: NUMERIC,4) sturation
FROM
(
SELECT start_time,
(case
when #{groupType}=0 then start_time
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
when #{groupType}=1 then to_char(date_trunc( 'HOUR', start_time ) + ( FLOOR ( EXTRACT ( MINUTE FROM start_time ) / 15 ) * 15 ) * INTERVAL '1 MINUTE',
'YYYY-MM-DD HH24:MI:00')
when #{groupType}=2 then TO_CHAR(DATE_TRUNC( 'day', start_time ) + ( EXTRACT ( HOUR FROM start_time ) * INTERVAL '1 hour' ) + ( FLOOR ( EXTRACT ( MINUTE FROM start_time ) / 30 ) * 30 ) * INTERVAL '1 minute',
'YYYY-MM-DD HH24:MI:00')
when #{groupType}=3 then TO_CHAR( DATE_TRUNC( 'hour', start_time ), 'YYYY-MM-DD HH24:00:00' )
when #{groupType}=4 then TO_CHAR( DATE_TRUNC( 'day', start_time ), 'YYYY-MM-DD 00:00:00' )
end
) unit_time,
cross_id,
......@@ -175,30 +176,30 @@
GROUP BY t.cross_id,unit_time
</select>
<!-- 绿波路口方向级指标趋势,支持按5分钟粒度、15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findGreenWaveCrossDirIndex"
resultMap="net.wanji.databus.dao.mapper.CrossDirDataHistMapper.BaseResultMap">
SELECT MIN(ifnull(t.unit_time,#{startDate})) start_time,
SELECT MIN(COALESCE(t.unit_time,#{startDate})) start_time,
cross_id,
dir_type,
round(AVG(traffic_index),2) traffic_index,
round(AVG(traffic_index) :: NUMERIC,2) traffic_index,
SUM(flow) flow,
round(AVG(speed),2) speed,
round(AVG(speed) :: NUMERIC,2) speed,
MAX(queue_length) queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),2) delay_time,
round(AVG(sturation),4) sturation
round(AVG(stop_times) :: NUMERIC,2) stop_times,
round(AVG(delay_time) :: NUMERIC,2) delay_time,
round(AVG(sturation) :: NUMERIC,4) sturation
FROM
(
SELECT start_time,
(case
when #{groupType}=0 then start_time
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
end
) unit_time,
when #{groupType}=1 then dt_15min
when #{groupType}=2 then dt_30min
when #{groupType}=3 then dt_60min
when #{groupType}=4 then TO_CHAR( start_time, 'YYYY-MM-DD 00:00:00' )
ELSE TO_CHAR( start_time, 'YYYY-01-01 00:00:00' )
END
) AS unit_time,
cross_id,
dir_type,
(traffic_index) traffic_index,
......@@ -220,192 +221,195 @@
GROUP BY t.cross_id,t.dir_type,unit_time
</select>
<!-- 绿波路口转向级指标趋势,支持按5分钟粒度、15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findGreenWaveCrossTurnIndex"
resultMap="net.wanji.databus.dao.mapper.CrossTurnDataHistMapper.BaseResultMap">
SELECT MIN(ifnull(t.unit_time,#{startDate})) start_time,
SELECT MIN(COALESCE(t.unit_time,#{startDate})) start_time,
cross_id crossId,
in_dir,
turn_type,
round(AVG(traffic_index),2) traffic_index,
round(AVG(traffic_index) ::numeric,2) traffic_index,
SUM(flow) flow,
round(AVG(speed),2) speed,
round(AVG(speed) ::numeric,2) speed,
MAX(queue_length) queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),2) delay_time,
round(AVG(sturation),4) sturation
round(AVG(stop_times) ::numeric,2) stop_times,
round(AVG(delay_time) ::numeric,2) delay_time,
round(AVG(sturation) ::numeric,4) sturation
FROM
(
SELECT start_time,
(case
when #{groupType}=0 then start_time
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
end
) unit_time,
cross_id,
in_dir,
turn_type,
traffic_index,
flow,
speed,
queue_length,
stop_times,
delay_time,
sturation
FROM t_cross_turn_data_hist t
where 1=1
<if test="crossId!=null and crossId !=''">
and cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
AND start_time >= #{startDate} and start_time &lt; #{endDate}
</if>
SELECT start_time,
(case
when #{groupType}=0 then start_time
when #{groupType}=1 then TO_CHAR(DATE_TRUNC('day', start_time) +(EXTRACT(HOUR FROM start_time) * INTERVAL '1 hour') +
(FLOOR(EXTRACT(MINUTE FROM start_time)/15)*15) * INTERVAL '1 minute','YYYY-MM-DD HH24:MI:00')
when #{groupType}=2 then TO_CHAR(DATE_TRUNC('day', start_time) +(EXTRACT(HOUR FROM start_time) * INTERVAL '1 hour') +
(FLOOR(EXTRACT(MINUTE FROM start_time)/30)*30) * INTERVAL '1 minute','YYYY-MM-DD HH24:MI:00')
when #{groupType}=3 then TO_CHAR(DATE_TRUNC('hour', start_time), 'YYYY-MM-DD HH24:00:00')
when #{groupType}=4 then TO_CHAR(DATE_TRUNC('day', start_time), 'YYYY-MM-DD 00:00:00')
end
) unit_time,
cross_id,
in_dir,
turn_type,
traffic_index,
flow,
speed,
queue_length,
stop_times,
delay_time,
sturation
FROM t_cross_turn_data_hist t
where 1=1
<if test="crossId!=null and crossId !=''">
and cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
AND start_time >= #{startDate} and start_time &lt; #{endDate}
</if>
) t
GROUP BY t.cross_id,t.in_dir,t.turn_type,unit_time
</select>
<!-- 统一接口:绿波路口车道级指标趋势,支持按5分钟粒度、15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findCrossObjectIndex"
resultType="net.wanji.opt.po.base.CrossLaneDataHistPoExtend">
SELECT (case
when #{groupType}=4 then date_format(dt,'%Y-%m-%d 00:00:00')
else
MIN(ifnull(t.unit_time,#{startDate}))
end
) start_time,
when #{groupType}='4' then TO_CHAR( to_date( dt :: TEXT, 'YYYYMMDD' ), 'YYYY-MM-DD 00:00:00' )
else
MIN (COALESCE (t.unit_time,
to_char(to_date(#{startDate},'YYYYMMDD'),'YYYY-MM-DD 00:00:00')) )
end
) start_time,
cross_id ,
lane_no ,
dir_type ,
turn_type ,
SUM(flow) flow,
round(AVG(speed),2) speed,
ROUND( AVG ( speed ) :: NUMERIC, 2 ) speed,
MAX(queue_length) max_queue_length,
MIN(queue_length) min_queue_length,
round(AVG(queue_length)) avg_queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),2) delay_time,
round(AVG(traffic_index),2) traffic_index,
round(AVG(sturation),4) sturation,
round(AVG(green_light_efficiency),4) green_light_efficiency,
round(AVG(vehicle_length_ratio_mean),4) vehicle_length_ratio_mean,
group_concat(service_level) service_level
ROUND( AVG ( queue_length ) :: NUMERIC ) avg_queue_length,
ROUND( AVG ( stop_times ) :: NUMERIC, 2 ) stop_times,
ROUND( AVG ( delay_time ) :: NUMERIC, 2 ) delay_time,
ROUND( AVG ( COALESCE(traffic_index, 1) ) :: NUMERIC, 2 ) traffic_index,
ROUND( AVG ( sturation ) :: NUMERIC, 4 ) sturation,
ROUND( AVG ( green_light_efficiency ) :: NUMERIC, 4 ) green_light_efficiency,
ROUND( AVG ( cast(vehicle_length_ratio_mean as NUMERIC) ), 4 ) vehicle_length_ratio_mean,
STRING_AGG(service_level :: text , ',') service_level
FROM
(
SELECT start_time,dt,
(case
when #{groupType}=0 then start_time
when #{groupType}=1 then dt_15min
when #{groupType}=2 then dt_30min
when #{groupType}=3 then dt
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
else DATE_FORMAT(start_time,'%Y-01-01 00:00:00') <!-- 按查询时间范围不分粒度进行聚合处理 -->
end
) unit_time,
t.cross_id,
<choose>
<!-- 方向级 -->
<when test="objectType==1">
dir_type,
null as lane_no,
null as turn_type,
null as service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
</when>
<!-- 转向级 -->
<when test="objectType==2">
t.in_dir as dir_type,
t.turn_type,
null as lane_no,
null as service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
</when>
<!-- 车道级 -->
<when test="objectType==3">
t2.sort as lane_no,
t2.dir as dir_type,
t2.turn as turn_type,
null as service_level,
null as traffic_index,
green_light_efficiency,
vehicle_length_ratio_mean,
</when>
<!-- 路口级 -->
<when test="objectType==4">
null as lane_no,
null as dir_type,
null as turn_type,
ifnull(service_level,'A') service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
</when>
<otherwise>
</otherwise>
</choose>
flow,
speed,
queue_length,
stop_times,
delay_time,
sturation
<choose>
<!-- 方向级 -->
<when test="objectType==1">
FROM t_cross_dir_data_hist t
</when>
<!-- 转向级 -->
<when test="objectType==2">
FROM t_cross_turn_data_hist t
</when>
<!-- 车道级 -->
<when test="objectType==3">
FROM t_lane_data_hist t join t_base_lane_info t2 on t.id=t2.id
</when>
<!-- 路口级 -->
<when test="objectType==4">
FROM t_cross_data_hist t
</when>
<otherwise>
</otherwise>
</choose>
where 1=1
<if test="crossId!=null and crossId !=''">
and t.cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
and dt >= date_format(#{startDate},'%Y%m%d') and dt &lt;= date_format(#{endDate},'%Y%m%d')
AND start_time >= #{startDate} and start_time &lt; #{endDate}
</if>
<choose>
<!-- 方向级 -->
<when test="objectType==1">
<if test="dir !=null and dir !=null">
and dir_type = #{dir}
</if>
</when>
<!-- 转向级 -->
<when test="objectType==2">
<if test="dir !=null and dir !=null">
and t.in_dir = #{dir}
</if>
</when>
<!-- 车道级 -->
<when test="objectType==3">
<if test="dir !=null and dir !=null">
and t2.dir = #{dir}
</if>
</when>
<otherwise>
</otherwise>
</choose>
SELECT start_time,dt,
(case
when #{groupType}='0' then start_time
when #{groupType}='1' then dt_15min
when #{groupType}='2' then dt_30min
when #{groupType}='3' then dt_60min
when #{groupType}='4' then TO_CHAR(start_time, 'YYYY-MM-DD 00:00:00' )
ELSE TO_CHAR( start_time, 'YYYY-01-01 00:00:00' ) <!-- 按查询时间范围不分粒度进行聚合处理 -->
end
) unit_time,
t.cross_id,
<choose>
<!-- 方向级 -->
<when test="objectType==1">
dir_type,
null as lane_no,
null as turn_type,
null as service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
</when>
<!-- 转向级 -->
<when test="objectType==2">
t.in_dir as dir_type,
t.turn_type,
null as lane_no,
null as service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
</when>
<!-- 车道级 -->
<when test="objectType==3">
t2.sort as lane_no,
t2.dir as dir_type,
t2.turn as turn_type,
null service_level,
1 as traffic_index,
green_light_efficiency,
vehicle_length_ratio_mean,
</when>
<!-- 路口级 -->
<when test="objectType==4">
null as lane_no,
null as dir_type,
null as turn_type,
coalesce(service_level,'A') service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
</when>
<otherwise>
</otherwise>
</choose>
flow,
speed,
queue_length,
stop_times,
delay_time,
sturation
<choose>
<!-- 方向级 -->
<when test="objectType==1">
FROM t_cross_dir_data_hist t
</when>
<!-- 转向级 -->
<when test="objectType==2">
FROM t_cross_turn_data_hist t
</when>
<!-- 车道级 -->
<when test="objectType==3">
FROM t_lane_data_hist t join t_base_lane_info t2 on t.id=t2.id
</when>
<!-- 路口级 -->
<when test="objectType==4">
FROM t_cross_data_hist t
</when>
<otherwise>
</otherwise>
</choose>
where 1=1
<if test="crossId!=null and crossId !=''">
and t.cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
AND dt >= TO_CHAR( to_date( #{startDate}, 'YYYYMMDD' ), 'YYYYMMDD' ) :: INTEGER
AND dt &lt;= TO_CHAR( to_date( #{endDate}, 'YYYY-MM-DD' ), 'YYYYMMDD' ) :: INTEGER
AND start_time >= #{startDate} :: TIMESTAMP
AND start_time &lt; #{endDate} :: TIMESTAMP
</if>
<choose>
<!-- 方向级 -->
<when test="objectType==1">
<if test="dir !=null and dir !=null">
and dir_type = #{dir}
</if>
</when>
<!-- 转向级 -->
<when test="objectType==2">
<if test="dir !=null and dir !=null">
and t.in_dir = #{dir}
</if>
</when>
<!-- 车道级 -->
<when test="objectType==3">
<if test="dir !=null and dir !=null">
and t2.dir = #{dir}
</if>
</when>
<otherwise>
</otherwise>
</choose>
) t
<choose>
<!-- 方向级 -->
......@@ -430,24 +434,26 @@
</select>
<!-- 查看干线拥堵运行状态 -->
<select id="findGreenWaveRunState" resultType="net.wanji.opt.vo.GreenWaveRunStateVO">
select type as state,count(*) count,
SUM(TIMESTAMPDIFF(SECOND,start_time, end_time)) duration,
TIMESTAMPDIFF(SECOND,#{startDate}, #{endDate}) total_time
from t_event_info t
where start_time >= #{startDate} and start_time &lt; #{endDate}
SELECT
type AS state,
count(*) AS count,
SUM(EXTRACT(EPOCH FROM (end_time - start_time)))::INTEGER AS duration,
EXTRACT(EPOCH FROM (#{endDate}::timestamp - #{startDate}::timestamp))::INTEGER AS total_time
FROM t_event_info t
WHERE start_time >= #{startDate}::timestamp
AND start_time &lt; #{endDate}::timestamp
<if test="eventTypeList!=null and eventTypeList.size>0">
and t.type in
AND t.type IN
<foreach collection="eventTypeList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
<if test="crossId !=null and crossId !=''">
and cross_id = #{crossId}
AND cross_id = #{crossId}
</if>
<if test="greenId !=null and greenId !=''">
and green_id = #{greenId}
AND green_id = cast(#{greenId} as varchar)
</if>
GROUP BY type
</select>
......@@ -476,95 +482,95 @@
</if>
</select>
<!-- 路口各出口方向路段指标 -->
<select id="findCrossExitRoadIndex"
resultType="net.wanji.opt.po.base.CrossLaneDataHistPoExtend">
select t1.start_cross_id as cross_id,
t1.dir as dir_type,
MIN(ifnull(t2.unit_time,#{startDate})) start_time,
round(AVG(t2.traffic_index),2) traffic_index,
SUM(t2.flow) flow,
round(AVG(t2.speed),2) speed,
MAX(t2.queue_length) max_queue_length,
MIN(t2.queue_length) min_queue_length,
round(AVG(t2.queue_length)) avg_queue_length,
round(AVG(t2.stop_times),2) stop_times,
round(AVG(t2.delay_time),2) delay_time,
round(AVG(t2.sturation),4) sturation
t1.dir as dir_type,
MIN(COALESCE(t2.unit_time :: TIMESTAMP,#{startDate}::timestamp)) start_time,
round(AVG(t2.traffic_index)::numeric,2) traffic_index,
SUM(t2.flow) flow,
round(AVG(t2.speed)::numeric,2) speed,
MAX(t2.queue_length) max_queue_length,
MIN(t2.queue_length) min_queue_length,
round(AVG(t2.queue_length)::numeric) avg_queue_length,
round(AVG(t2.stop_times)::numeric,2) stop_times,
round(AVG(t2.delay_time)::numeric,2) delay_time,
round(AVG(t2.sturation)::numeric,4) sturation
from
(
select id,start_cross_id,end_cross_id,in_dir as dir, 2 as type
from t_base_rid_info
where 1=1 <if test="crossId!=null and crossId !=''">
and start_cross_id = #{crossId}
</if>
) t1
left join (
SELECT cross_id,dir_type,start_time,flow,speed,queue_length,stop_times,delay_time,sturation ,traffic_index,
(case
when #{groupType}=0 then start_time
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
end
) unit_time
from t_cross_dir_data_hist
WHERE start_time >= #{startDate} and start_time &lt; #{endDate}
) t2
on t2.cross_id=t1.end_cross_id and t2.dir_type=t1.dir
(
select id,start_cross_id,end_cross_id,in_dir as dir, 2 as type
from t_base_rid_info
where 1=1 <if test="crossId!=null and crossId !=''">
and start_cross_id = #{crossId}
</if>
) t1
left join (
SELECT cross_id,dir_type,start_time,flow,speed,queue_length,stop_times,delay_time,sturation,traffic_index,
(case
when #{groupType}='0' then start_time
when #{groupType}='1' then dt_15min
when #{groupType}='2' then dt_30min
when #{groupType}='3' then dt_60min
when #{groupType}='4' then TO_CHAR(start_time, 'YYYY-MM-DD 00:00:00' )
ELSE TO_CHAR( start_time, 'YYYY-01-01 00:00:00' ) <!-- 按查询时间范围不分粒度进行聚合处理 -->
end
) unit_time
from t_cross_dir_data_hist
WHERE start_time >= #{startDate}::timestamp and start_time &lt; #{endDate}::timestamp
) t2
on t2.cross_id=t1.end_cross_id and t2.dir_type=t1.dir
GROUP BY t1.start_cross_id,t1.dir,t2.unit_time
</select>
<!-- 路口各出口方向路段车道指标 -->
<select id="findCrossExitRoadLaneIndex"
resultType="net.wanji.opt.po.base.CrossLaneDataHistPoExtend">
select t1.end_cross_id as cross_id,
t1.dir as dir_type,
t1.lane_id,
t1.lane_no,
t1.turn as turn_type,
MIN(ifnull(t2.unit_time,#{startDate})) start_time,
SUM(t2.flow) flow,
round(AVG(t2.speed),2) speed,
MAX(t2.queue_length) max_queue_length,
MIN(t2.queue_length) min_queue_length,
round(AVG(t2.queue_length)) avg_queue_length,
round(AVG(t2.stop_times),2) stop_times,
round(AVG(t2.delay_time),2) delay_time,
round(AVG(t2.sturation),4) sturation
t1.dir as dir_type,
t1.lane_id,
t1.lane_no,
t1.turn as turn_type,
MIN(COALESCE(t2.unit_time :: TIMESTAMP,#{startDate}::timestamp)) start_time,
SUM(t2.flow) flow,
round(AVG(t2.speed)::numeric,2) speed,
MAX(t2.queue_length) max_queue_length,
MIN(t2.queue_length) min_queue_length,
round(AVG(t2.queue_length)::numeric) avg_queue_length,
round(AVG(t2.stop_times)::numeric,2) stop_times,
round(AVG(t2.delay_time)::numeric,2) delay_time,
round(AVG(t2.sturation)::numeric,4) sturation
from
(
select t2.start_cross_id,t2.end_cross_id,t1.rid,t1.id lane_id,sort as lane_no,t1.type,t1.dir,t1.turn
from t_base_lane_info t1
JOIN (
select id,start_cross_id,end_cross_id,out_dir as dir, 2 as type
from t_base_rid_info
where 1=1 <if test="crossId!=null and crossId !=''">
and start_cross_id = #{crossId}
</if>
) t2 on t1.cross_id=t2.end_cross_id and t1.type=t2.type and t1.dir=t2.dir
) t1
left join (
SELECT id as lane_id,cross_id,start_time,flow,speed,queue_length,stop_times,delay_time,sturation ,
(case
when #{groupType}=0 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 5 ) * 5 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
end
) unit_time
from t_lane_data_hist
WHERE start_time >= #{startDate} and start_time &lt; #{endDate}
) t2
on t2.lane_id=t1.lane_id
(
select t2.start_cross_id,t2.end_cross_id,t1.rid,t1.id lane_id,sort as lane_no,t1.type,t1.dir,t1.turn
from t_base_lane_info t1
JOIN (
select id,start_cross_id,end_cross_id,out_dir as dir, 2 as type
from t_base_rid_info
where 1=1 <if test="crossId!=null and crossId !=''">
and start_cross_id = #{crossId}
</if>
) t2 on t1.cross_id=t2.end_cross_id and t1.type=t2.type and t1.dir=t2.dir
) t1
left join (
SELECT id as lane_id,cross_id,start_time,flow,speed,queue_length,stop_times,delay_time,sturation,
(case
when #{groupType}='0' then start_time
when #{groupType}='1' then dt_15min
when #{groupType}='2' then dt_30min
when #{groupType}='3' then dt_60min
when #{groupType}='4' then TO_CHAR(start_time, 'YYYY-MM-DD 00:00:00' )
ELSE TO_CHAR( start_time, 'YYYY-01-01 00:00:00' ) <!-- 按查询时间范围不分粒度进行聚合处理 -->
end
) unit_time
from t_lane_data_hist
WHERE start_time >= #{startDate}::timestamp and start_time &lt; #{endDate}::timestamp
) t2
on t2.lane_id=t1.lane_id
GROUP BY t1.end_cross_id,t1.dir,t1.lane_id,t1.turn,t2.unit_time
ORDER BY t1.end_cross_id,t1.dir,t1.lane_no
</select>
<!--新增操作 -->
<insert id="save" parameterType="net.wanji.opt.entity.GreenwaveHist">
insert into
......@@ -676,7 +682,7 @@
<![CDATA[ and id = #{id}]]>
</if>
<if test="greenId != null and greenId != '' ">
<![CDATA[ and green_id = #{greenId}]]>
<![CDATA[ and green_id = cast(#{greenId} as INTEGER)]]>
</if>
<if test="status != null and status != '' ">
<![CDATA[ and status = #{status}]]>
......@@ -735,7 +741,7 @@
<![CDATA[ id = #{id}, ]]>
</if>
<if test="greenId != null and greenId != '' ">
<![CDATA[ green_id = #{greenId}, ]]>
<![CDATA[ green_id = cast(#{greenId} as varchar)]]>
</if>
<if test="status != null and status != '' ">
<![CDATA[ status = #{status}, ]]>
......@@ -788,36 +794,36 @@
</set>
</sql>
<!-- 统一接口:绿波路口车道级指标趋势,支持按5分钟粒度、15分钟粒度、30分钟粒度、1小时粒度汇聚 -->
<select id="findCrossObjectIndexByDay"
resultType="net.wanji.opt.po.base.CrossLaneDataHistPoExtend">
SELECT
MIN(ifnull(t.unit_time,#{startDate})) start_time,
cross_id ,
lane_no ,
dir_type ,
turn_type ,
MIN(COALESCE(t.unit_time :: TIMESTAMP,#{startDate}::timestamp)) start_time,
cross_id,
lane_no,
dir_type,
turn_type,
SUM(flow) flow,
round(AVG(speed),2) speed,
ROUND(AVG(speed)::numeric,2) speed,
MAX(queue_length) max_queue_length,
MIN(queue_length) min_queue_length,
round(AVG(queue_length)) avg_queue_length,
round(AVG(stop_times),2) stop_times,
round(AVG(delay_time),2) delay_time,
round(AVG(traffic_index),2) traffic_index,
round(AVG(sturation),4) sturation,
round(AVG(green_light_efficiency),4) green_light_efficiency,
round(AVG(vehicle_length_ratio_mean),4) vehicle_length_ratio_mean,
group_concat(service_level) service_level
ROUND(AVG(queue_length)::numeric) avg_queue_length,
ROUND(AVG(stop_times)::numeric,2) stop_times,
ROUND(AVG(delay_time)::numeric,2) delay_time,
ROUND(AVG(traffic_index)::numeric,2) traffic_index,
ROUND(AVG(sturation)::numeric,4) sturation,
ROUND(AVG(green_light_efficiency)::numeric,4) green_light_efficiency,
ROUND(AVG(vehicle_length_ratio_mean ::numeric),4) vehicle_length_ratio_mean,
STRING_AGG(service_level,',') service_level
FROM
(
SELECT start_time,
(case
when #{groupType}=0 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 5 ) * 5 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
else DATE_FORMAT(now(),'%Y-01-01 00:00:00') <!-- 按查询时间范围不分粒度进行聚合处理 -->
when #{groupType}='0' then start_time
when #{groupType}='1' then dt_15min
when #{groupType}='2' then dt_30min
when #{groupType}='3' then dt_60min
when #{groupType}='4' then TO_CHAR(start_time, 'YYYY-MM-DD 00:00:00' )
ELSE TO_CHAR( start_time, 'YYYY-01-01 00:00:00' ) <!-- 按查询时间范围不分粒度进行聚合处理 -->
end
) unit_time,
t.cross_id,
......@@ -857,7 +863,7 @@
null as lane_no,
null as dir_type,
null as turn_type,
ifnull(service_level,'A') service_level,
COALESCE(service_level,'A') service_level,
traffic_index,
green_light_efficiency,
null as vehicle_length_ratio_mean,
......@@ -888,7 +894,6 @@
<when test="objectType==4">
FROM t_cross_data_hist t
</when>
<otherwise>
</otherwise>
</choose>
......@@ -897,7 +902,7 @@
and t.cross_id = #{crossId}
</if>
<if test="startDate !=null and endDate !=null">
and dt = date_format(#{startDate},'%Y%m%d')
and dt = TO_CHAR(#{startDate}::date,'YYYYMMDD') :: integer
</if>
<choose>
<!-- 方向级 -->
......@@ -942,65 +947,61 @@
<otherwise>
</otherwise>
</choose>
</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
ROUND(AVG(a.traffic_index)::numeric,2) trafficIndex,
ROUND(AVG(a.speed)::numeric,2) speed,
ROUND(AVG(a.delay_time)::numeric) delayTime,
ROUND(AVG(a.stop_times)::numeric,2) stopTimes,
ROUND(AVG(a.trval_time)::numeric) 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>
SELECT t3.green_id,t3.cross_id,SUM(t3.flow) flow,STRING_AGG(t3.flow::text,',') 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}::timestamp
AND #{endDate}::timestamp
</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}::timestamp
AND #{endDate}::timestamp
</if>
) t3
GROUP BY t3.green_id,t3.cross_id
ORDER BY flow desc limit 1
ORDER BY flow DESC LIMIT 1
) b
on a.green_id=b.green_id
ON a.green_id=b.green_id
WHERE 1=1
<if test="greenId!=null and greenId !=''">
and a.green_id = #{greenId}
AND a.green_id = #{greenId}
</if>
<if test="startDate !=null and endDate !=null">
AND a.start_time BETWEEN #{startDate}
AND #{endDate}
AND a.start_time BETWEEN #{startDate}::timestamp
AND #{endDate}::timestamp
</if>
GROUP BY a.green_id,a.road_direction
</select>
......
......@@ -459,7 +459,7 @@
cross_id,
concat( '[', STRING_AGG(dir_type||'',','), ']' ) as dir,
start_time,
DATE_ADD( start_time, INTERVAL 5 MINUTE ) AS end_time,
DATE_ADD( start_time, INTERVAL '5 MINUTE' ) AS end_time,
dt,
now()
FROM
......@@ -469,7 +469,8 @@
AND `status` = 2
GROUP BY
cross_id,
start_time
start_time,
dt
HAVING
count(*)>=2
ON CONFLICT (cross_id,dir,start_time)
......
......@@ -23,8 +23,9 @@
</resultMap>
<select id="selectGreenDataHist" parameterType="String" resultMap="AnalysisGreenCongestionPeriodMap">
SELECT a.green_id,a.road_direction,a.start_time,a.status FROM t_greenwave_hist a
where a.start_time between TO_TIMESTAMP(#{date},'YYYY-MM-DD 00:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 23:59:59')
SELECT a.green_id,a.road_direction,a.start_time,a.status
FROM t_greenwave_hist a
where a.start_time between (TO_TIMESTAMP(#{date},'YYYY-MM-DD 00:00:00'))::TIMESTAMP and (DATE_TRUNC('day',#{date}::date) + INTERVAL '1 DAY' - INTERVAL '1 SECOND' )::TIMESTAMP
and a.green_id is not null
order by a.green_id,a.road_direction,a.start_time
</select>
......@@ -36,7 +37,7 @@
<insert id="insertGreenCongestionPeriodData" parameterType="map">
insert into t_analysis_green_wave_congest_time_span (green_id,road_direction,week_day,congest_start_time,congest_end_time,congest_index,status,travel_time,speed,peak_type,year_week,week_start_time,week_end_time,insert_time)
SELECT a.green_id,a.road_direction,#{weekDay} as week_day, TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') as congest_start_time,TO_TIMESTAMP(DATE_ADD(#{endTime},INTERVAL 5 MINUTE),'YYYY-MM-DD HH24:MI:SS') as congest_end_time,AVG(traffic_index),#{status} as status,CEIL(AVG(trval_time)),AVG(speed),
SELECT a.green_id,a.road_direction,#{weekDay} as week_day, TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') as congest_start_time,TO_TIMESTAMP(DATE_ADD(#{endTime},INTERVAL '5 MINUTE'),'YYYY-MM-DD HH24:MI:SS') as congest_end_time,AVG(traffic_index),#{status} as status,CEIL(AVG(trval_time)),AVG(speed),
#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now()
FROM t_greenwave_hist a
where a.start_time between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
......@@ -71,7 +72,7 @@
where t1.key_cross_id is not null and t.type = 2) t3 on t2.id = t3.id
where t3.key_cross_id is not null and dt = CAST(#{date} AS INT4) ) t4
where t4.cross_id = #{crossId}
and t4.start_time between TO_TIMESTAMP(DATE_SUB(#{startTime},INTERVAL '10 MINUTE'),'YYYY-MM-DD HH24:MI:00') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
and t4.start_time between DATE_SUB(#{startTime},INTERVAL '10 MINUTE') and TO_TIMESTAMP(#{endTime},'YYYY-MM-DD HH24:MI:SS')
group by t4.cross_id,t4.start_time
</select>
......@@ -84,7 +85,7 @@
#{avgFlow} as flow,#{maxFlow} as max_flow,#{peakType} as peak_type,#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,
TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now(),#{trafficThreshold} as traffic_threshold
from t_greenwave_hist a
where TO_TIMESTAMP(a.start_time,'YYYY-MM-DD HH24:MI:00') between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(DATE_SUB(#{endTime},INTERVAL '5 MINUTE'),'YYYY-MM-DD HH24:MI:SS')
where a.start_time between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:SS') and DATE_SUB(#{endTime},INTERVAL '5 MINUTE')
and CAST(a.green_id AS VARCHAR) = #{greenId}
and a.road_direction = #{roadDirection}
</insert>
......@@ -93,7 +94,7 @@
select t.green_id,t1.key_cross_id as cross_id, t.road_direction,t.peak_start_time as start_time,t.peak_end_time as endTime ,t.traffic_index,t.peak_type
from t_analysis_green_wave_peak_detail t
left join t_greenwave_key_cross_lane t1 on t1.green_id = t.green_id
where t.peak_start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 00:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 23:59:59')
where t.peak_start_time BETWEEN TO_TIMESTAMP(#{date}||' 00:00:00','YYYY-MM-DD HH24:MI:SS') and TO_TIMESTAMP(#{date}||' 23:59:59','YYYY-MM-DD HH24:MI:SS')
order by t.green_id,t1.key_cross_id ,t.road_direction,t.peak_type,t.traffic_index desc
</select>
......@@ -107,8 +108,8 @@
<select id="selectCrossTrafficThreshold" parameterType="String" resultMap="AnalysisLaneDataHistMap">
select t.cross_id,t.traffic_index
from t_cross_data_hist t
where t.start_time BETWEEN TO_TIMESTAMP(#{date},'YYYY-MM-DD 09:00:00') and TO_TIMESTAMP(#{date},'YYYY-MM-DD 16:30:10')
and t.cross_id = #{crossId}
where t.start_time BETWEEN TO_TIMESTAMP(#{date}||'090000','YYYYMMDDHH24MISS') and TO_TIMESTAMP(#{date}||'163010','YYYYMMDDHH24MISS')
and t.cross_id = #{crossId}
order by t.traffic_index desc
</select>
......@@ -131,8 +132,22 @@
#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,
TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now()
from t_cross_data_hist a
where TO_TIMESTAMP(a.start_time,'YYYY-MM-DD HH24:MI:00') between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:00') and TO_TIMESTAMP(DATE_SUB(#{endTime},INTERVAL 5 MINUTE),'YYYY-MM-DD HH24:MI:SS')
where a.start_time between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:00') and DATE_SUB(#{endTime},INTERVAL '5 MINUTE')
and a.cross_id = #{crossId}
ON CONFLICT ("year_week", "cross_id", "peak_start_time", "week_day", "day_type", "peak_type")
DO UPDATE SET
peak_end_time=excluded.peak_end_time ,
day_total_flow=excluded.day_total_flow ,
day_max_hour_flow=excluded.day_max_hour_flow ,
peak_max_hour_flow=excluded.peak_max_hour_flow ,
peak_traffic_index=excluded.peak_traffic_index ,
peak_capacity=excluded.peak_capacity ,
peak_avg_deay_time=excluded.peak_avg_deay_time ,
peak_max_queue_length=excluded.peak_max_queue_length ,
peak_avg_stop_times=excluded.peak_avg_stop_times ,
week_start_time=excluded.week_start_time ,
week_end_time=excluded.week_end_time ,
insert_time=excluded.insert_time
</insert>
<insert id="insertCrossDataHistByDay" parameterType="map">
......@@ -146,8 +161,22 @@
#{weekNumber} as year_week,TO_TIMESTAMP(#{weekStartTime},'YYYY-MM-DD') as week_start_time,
TO_TIMESTAMP(#{weekEndTime},'YYYY-MM-DD') as week_end_time,now(),#{maxFlow},sum(flow),AVG(speed)
from t_cross_data_hist a
where TO_TIMESTAMP(a.start_time,'YYYY-MM-DD HH24:MI:00') between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:00') and TO_TIMESTAMP(DATE_SUB(#{endTime},INTERVAL 5 MINUTE),'YYYY-MM-DD HH24:MI:SS')
where a.start_time between TO_TIMESTAMP(#{startTime},'YYYY-MM-DD HH24:MI:00') and DATE_SUB(#{endTime},INTERVAL '5 MINUTE')
and a.cross_id = #{crossId}
ON CONFLICT ("year_week", "cross_id", "peak_start_time", "week_day", "day_type", "peak_type")
DO UPDATE SET
peak_end_time=excluded.peak_end_time ,
day_total_flow=excluded.day_total_flow ,
day_max_hour_flow=excluded.day_max_hour_flow ,
peak_max_hour_flow=excluded.peak_max_hour_flow ,
peak_traffic_index=excluded.peak_traffic_index ,
peak_capacity=excluded.peak_capacity ,
peak_avg_deay_time=excluded.peak_avg_deay_time ,
peak_max_queue_length=excluded.peak_max_queue_length ,
peak_avg_stop_times=excluded.peak_avg_stop_times ,
week_start_time=excluded.week_start_time ,
week_end_time=excluded.week_end_time ,
insert_time=excluded.insert_time
</insert>
<select id="selectCrossPeakDetail" parameterType="String" resultMap="AnalysisLaneDataHistMap">
......
......@@ -40,7 +40,7 @@
and a.dt >= CAST(#{dtStart} AS INT4) and a.dt &lt;= CAST(#{dtEnd} AS INT4)
</when>
<otherwise>
and a.dt = CAST(TO_CHAR(DATE_sub(now(), INTERVAL 24 HOUR ), 'YYYYMMDD') AS INT4)
and a.dt = CAST(TO_CHAR(DATE_sub(now(), INTERVAL '24 HOUR' ), 'YYYYMMDD') AS INT4)
</otherwise>
</choose>
and a.type in ('701', '702', '703', '707')
......@@ -57,7 +57,7 @@
and a.dt >= CAST(#{dtStart} AS INT4) and a.dt &lt;= CAST(#{dtEnd} AS INT4)
</when>
<otherwise>
and a.dt = CASE(TO_CHAR((DATE_sub(now(), INTERVAL 24 HOUR ), 'YYYYMMDD') AS INT4)
and a.dt = CAST(TO_CHAR(DATE_sub(now(), INTERVAL '24 HOUR' ), 'YYYYMMDD') AS INT4)
</otherwise>
</choose>
and a.type in ('705','706')
......@@ -70,11 +70,11 @@
from t_strategy_green_opt_hist a
where a.control_time = (select MAX(control_time)
from t_strategy_green_opt_hist
where green_id = #{greenID}
and control_time <![CDATA[ >= ]]> DATE_FORMAT(DATE_sub(#{time}, INTERVAL control_duration SECOND), 'YYYY-MM-DD HH24:MI:SS')
where green_id = CAST(#{greenID} AS VARCHAR)
and control_time <![CDATA[ >= ]]> DATE_sub(TO_TIMESTAMP(#{time}, 'YYYY-MM-DD HH24:MI:SS'), INTERVAL 1800 SECOND)
and control_time <![CDATA[ <= ]]> TO_TIMESTAMP(#{time}, 'YYYY-MM-DD HH24:MI:SS')
and response_code = 200)
and a.green_id = #{greenID}
and a.green_id = CAST(#{greenID} AS VARCHAR)
</select>
<select id="getCrossStrategy" parameterType="String" resultMap="AnalysisProblemAndStrategyDayMap">
......@@ -84,7 +84,7 @@
from t_strategy_cross_result a
where a.event_id = #{eventSerialNumber}
and response_code = 200
and dt = CAST(TO_CHAR(#{time}, 'YYYYMMDD') AS INT4)
and dt = CAST(TO_CHAR(to_timestamp(#{time},'YYYY-MM-DD HH24:00:00'), 'YYYYMMDD') AS INT4)
and a.cross_id = #{crossID}
</select>
......
......@@ -230,22 +230,24 @@
TO_CHAR(a.start_time,'HH24:MI:SS'),
'~',
CONCAT(TO_CHAR(a.end_time,'HH24:MI:SS'))
)
ORDER BY extract(epoch from (a.end_time - a.start_time)) desc
)::text
,',' ORDER BY extract(epoch from (a.end_time - a.start_time)) desc
)
,',',1) as serious_time_span,
max(extract(epoch from (a.end_time - a.start_time)) as serious_duration,
max(extract(epoch from (a.end_time - a.start_time))) as serious_duration,
STRING_AGG(CONCAT(
TO_CHAR(a.start_time,'HH24:MI:SS'),
'~',
CONCAT(TO_CHAR(a.end_time,'HH24:MI:SS'))
)
)::text
) time_span_list,
(EXTRACT(ISODOW FROM start_time)+1) week_day,
concat(TO_CHAR(start_time,'YYYY'),'',(EXTRACT(WEEKS FROM start_time::date)+1)) year_week
concat(TO_CHAR(start_time,'YYYY'),'',(EXTRACT(WEEKS FROM start_time::date)+1))::INTEGER year_week
from t_event_info a
left join t_base_cross_info b on a.cross_id = b.id
where dt = CAST(TO_CHAR(DATE_SUB(now(),INTERVAL 1 DAY),'YYYYMMDD') AS INT4) and a.type in ('701','702','703','707')
where dt = CAST(TO_CHAR(DATE_SUB(now(),INTERVAL '1 DAY'),'YYYYMMDD') AS INT4) and a.type in ('701','702','703','707')
group by a.cross_id, b.area_id,a.category,a.type
ON CONFLICT (cross_id,event_type,dt)
......@@ -289,25 +291,28 @@
TO_CHAR(a.start_time,'HH24:MI:SS'),
'~',
CONCAT(TO_CHAR(a.end_time,'HH24:MI:SS'))
),
',' ORDER BY extract(epoch from (a.end_time - a.start_time)) desc
)::text
,',' ORDER BY extract(epoch from (a.end_time - a.start_time)) desc
)
,',',1) as serious_time_span,
max( extract(epoch from (a.end_time - a.start_time))) as serious_duration,
STRING_AGG(CONCAT(
TO_CHAR(a.start_time,'HH24:MI:SS'),
'~',
CONCAT(TO_CHAR(a.end_time,'HH24:MI:SS'))
),','
)::text
,','
) time_span_list,
(EXTRACT(ISODOW FROM start_time)+1) week_day,
concat(TO_CHAR(start_time,'YYYY'),'',(EXTRACT(WEEKS FROM start_time::date)+1)) year_week
concat(TO_CHAR(start_time,'YYYY'),'',(EXTRACT(WEEKS FROM start_time::date)+1))::INTEGER year_week
from (
<!-- 路口缓行计算 -->
SELECT
cross_id,
start_time,
DATE_ADD( start_time, INTERVAL 5 MINUTE ) AS end_time,
DATE_ADD( start_time, INTERVAL '5 MINUTE' ) AS end_time,
dt,
'4' AS category,
'708' AS type
......@@ -350,10 +355,10 @@
e.area_id,
d.category,
d.type,
d.dir,
cast(d.dir as int),
count(1) as event_number ,
sum( extract(epoch from (d.end_time - d.start_time) ) as duration ,
TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL 1 HOUR) AS VARCHAR),'YYYY-MM-DD HH24:00:00') as dh1,
sum( extract(epoch from (d.end_time - d.start_time)) ) as duration ,
TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL '1 HOUR') AS VARCHAR),'YYYY-MM-DD HH24:00:00') as dh1,
TO_TIMESTAMP(CAST(now() AS VARCHAR),'YYYY-MM-DD HH24:00:00') as dh2,
CAST(TO_CHAR(now(),'YYYYMMDD') AS INT4) as dt ,
now()
......@@ -363,7 +368,7 @@
from
(select a.cross_id,a.category,a.type,a.start_time,a.end_time,SUBSTR(a.dir,2,LENGTH(a.dir)-2) as dir
from t_event_info a
where a.start_time >= TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL 1 HOUR) AS VARCHAR),'YYYY-MM-DD HH24:00:00')
where a.start_time >= TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL '1 HOUR') AS VARCHAR),'YYYY-MM-DD HH24:00:00')
and a.start_time <![CDATA[ < ]]> TO_TIMESTAMP(CAST(now() AS VARCHAR),'YYYY-MM-DD HH24:00:00')
and a.type in ('701','702','703','707')
and a.dir is not null
......@@ -509,12 +514,12 @@
b.out_dir,
c.name,
b.green_id,
DATE_SUB(CURDATE_DATE, INTERVAL 1 DAY) as startTime,
DATE_SUB(CURDATE_DATE, INTERVAL 1 SECOND) as endTime
DATE_SUB(CURRENT_DATE, INTERVAL 1 DAY) as startTime,
DATE_SUB(CURRENT_DATE, INTERVAL 1 SECOND) as endTime
FROM
( SELECT count(*) AS dir_count, cross_id, dir_type, status FROM t_cross_dir_data_hist
WHERE
start_time BETWEEN DATE_SUB(CURDATE_DATE, INTERVAL '1 DAY') AND DATE_SUB(CURDATE_DATE, INTERVAL '1 SECOND')
start_time BETWEEN DATE_SUB(CURRENT_DATE, INTERVAL '1 DAY') AND DATE_SUB(CURRENT_DATE, INTERVAL '1 SECOND')
GROUP BY cross_id, dir_type, status ) a
LEFT JOIN t_greenwave_cross b ON a.cross_id = b.cross_id
LEFT JOIN t_base_cross_info c ON a.cross_id = c.id
......
......@@ -167,12 +167,12 @@
<!-- 新增表t_analysis_problem_green_day信息 -->
<insert id="insertAnalysisProblemGreenDay">
insert into t_analysis_problem_green_day (id,green_id,area_id,event_category,event_type,event_number,event_total_time,dt,insert_time)
select uuid_generate_v4(), a.green_id, b.area_id,a.category,a.type,count(1) as event_number ,
select uuid_generate_v4(), cast(a.green_id as int), b.area_id,a.category,a.type,count(1) as event_number ,
sum( extract(epoch from (a.end_time - a.start_time)) ) as duration ,
dt , now()
from t_event_info a
left join t_greenwave_info b on a.green_id = b.id
where dt = CAST(TO_CHAR(DATE_SUB(now(),INTERVAL 1 DAY),'YYYYMMDD') AS INT4) and a.type in ('705','706') and a.green_id != ''
left join t_greenwave_info b on cast(a.green_id as int) = b.id
where dt = CAST(TO_CHAR(DATE_SUB(now(),INTERVAL '1 DAY'),'YYYYMMDD') AS INT4) and a.type in ('705','706') and a.green_id != ''
group by a.green_id, b.area_id,a.category,a.type
ON CONFLICT (green_id,event_type,dt)
DO UPDATE SET
......@@ -188,35 +188,66 @@
<!-- 新增表t_analysis_problem_green_hour信息 -->
<insert id="insertAnalysisProblemGreenHour">
insert into t_analysis_problem_green_hour (id,green_id,area_id,event_category,event_type,dir,event_number,event_total_time,window_start_time,window_end_time,dt,insert_time)
select uuid_generate_v4(), d.green_id, e.area_id,d.category,d.type,d.dir,count(1) as event_number , sum( TIMESTAMPDIFF(SECOND, d.start_time , d.end_time) ) as duration ,
TO_CHAR(DATE_SUB(now(),INTERVAL 1 HOUR),'YYYY-MM-DD HH24:00:00') as dh1, TO_CHAR(now(),'YYYY-MM-DD HH24:00:00') as dh2,
TO_CHAR(now(),'YYYYMMDD') as dt , now()
from
(select DISTINCT b.green_id,b.category,b.type,b.start_time,b.end_time, unnest(string_to_array(dir, ',')) AS dir
from
(select a.green_id,a.category,a.type,a.start_time,a.end_time,SUBSTR(a.dir,2,LENGTH(a.dir)-2) as dir
from t_event_info a
where a.start_time >= TO_TIMESTAMP(CAST(DATE_SUB(now(),INTERVAL 1 HOUR) AS VARCHAR),'YYYY-MM-DD HH24:00:00')
and a.start_time <![CDATA[ < ]]> TO_TIMESTAMP(CAST(now() AS VARCHAR),'YYYY-MM-DD HH24:00:00')
and a.type in ('705','706') and a.green_id != ''
and a.dir is not null
and length(a.dir)>2
) b
INSERT INTO t_analysis_problem_green_hour ( ID, green_id, area_id, event_category, event_type, dir, event_number, event_total_time, window_start_time, window_end_time, dt, insert_time )
SELECT
uuid_generate_v4 ( ),
d.green_id,
e.area_id,
d.category,
d.TYPE,
cast(d.dir as int),
COUNT ( 1 ) AS event_number,
SUM(EXTRACT(EPOCH FROM (d.end_time - d.start_time)))::INTEGER AS duration,
TO_CHAR( DATE_SUB ( now( ), INTERVAL '1 HOUR' ), 'YYYY-MM-DD HH24:00:00' )::TIMESTAMP AS dh1,
TO_CHAR( now( ), 'YYYY-MM-DD HH24:00:00' )::TIMESTAMP AS dh2,
TO_CHAR( now( ), 'YYYYMMDD' )::INTEGER AS dt,
now( )
FROM
(
SELECT DISTINCT
cast(b.green_id as int),
b.category,
b.TYPE,
b.start_time,
b.end_time,
UNNEST ( string_to_array( dir, ',' ) ) AS dir
FROM
(
SELECT
A.green_id,
A.category,
A.TYPE,
A.start_time,
A.end_time,
SUBSTR( A.dir, 2, LENGTH ( A.dir ) - 2 ) AS dir
FROM
t_event_info A
WHERE
A.start_time >= TO_TIMESTAMP( CAST ( DATE_SUB ( now( ), INTERVAL '1 HOUR' ) AS VARCHAR ), 'YYYY-MM-DD HH24:00:00' )
AND A.start_time &lt; TO_TIMESTAMP( CAST ( now( ) AS VARCHAR ), 'YYYY-MM-DD HH24:00:00' )
AND A.TYPE IN ( '705', '706' )
AND A.green_id != ''
AND A.dir IS NOT NULL
AND LENGTH ( A.dir ) > 2
) b
) d
left join t_greenwave_info e on d.green_id = e.id
group by d.green_id, e.area_id,d.category,d.type,d.dir
ON CONFLICT (dir,green_id,dt,event_type,window_start_time)
DO UPDATE SET
id=excluded.id,
area_id=excluded.area_id,
event_category=excluded.event_category,
dir=excluded.dir,
event_number=excluded.event_number,
event_total_time=excluded.event_total_time,
window_end_time=excluded.window_end_time,
insert_time=excluded.insert_time
;
LEFT JOIN t_greenwave_info e ON d.green_id = e.ID
GROUP BY
d.green_id,
e.area_id,
d.category,
d.TYPE,
d.dir
ON CONFLICT ( dir, green_id, dt, event_type, window_start_time ) DO
UPDATE
SET ID = excluded.ID,
area_id = excluded.area_id,
event_category = excluded.event_category,
dir = excluded.dir,
event_number = excluded.event_number,
event_total_time = excluded.event_total_time,
window_end_time = excluded.window_end_time,
insert_time = excluded.insert_time;
</insert>
<!-- 根据条件查询表t_analysis_problem_green_day信息 -->
......
......@@ -171,7 +171,7 @@
<include refid="AnalysisGreenWaveOptimizeWeekByCondition" />
</select>
<select id="getTotalityData"
resultType="net.wanji.opt.controllerv2.report.vo.GreenWaveOptimizeAnalysisDataDTO">
resultType="net.wanji.opt.vo2.report.GreenWaveOptimizeAnalysisDataDTO">
SELECT
COALESCE(sum( optimize_count ),0) AS optimize_count,
COALESCE(sum( optimize_duration ),0) AS optimize_duration,
......@@ -196,7 +196,7 @@
</foreach>
</if>
</select>
<select id="selectListByYearWeek" resultType="net.wanji.opt.controllerv2.report.vo.AnalysisGreenWaveOptimizeWeekVO">
<select id="selectListByYearWeek" resultType="net.wanji.opt.vo2.report.AnalysisGreenWaveOptimizeWeekVO">
SELECT
<include refid="Base_Column_List"/>
FROM t_analysis_green_wave_optimize_week where year_week = #{yearWeek}
......
......@@ -28,7 +28,7 @@
</foreach>
</if>
</select>
<select id="getTotalitySituation" resultType="net.wanji.opt.controllerv2.report.vo.CrossPeakAnalysis">
<select id="getTotalitySituation" resultType="net.wanji.opt.vo2.report.CrossPeakAnalysis">
SELECT
cross_id,
<if test="dayType = null">
......
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