Commit 428f9506 authored by duanruiming's avatar duanruiming

[add] 优化监测-AI干线优化

parent beaf2b3c
...@@ -4,20 +4,25 @@ import lombok.AllArgsConstructor; ...@@ -4,20 +4,25 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
import net.wanji.common.utils.tool.StringUtils; import net.wanji.common.utils.tool.StringUtils;
import java.util.Objects;
/** /**
* @author duanruiming * @author duanruiming
* @date 2024/12/03 19:14 * @date 2024/12/03 19:14
* @description
*/ */
@Getter @Getter
@AllArgsConstructor @AllArgsConstructor
public enum GreenBeltDirEnum { public enum GreenBeltDirEnum {
E2W("e2w", "东向西"), //
W2E("w2e", "西向东"), E2W("e2w", "东向西", 3),
N2S("n2s", "北向南"), W2E("w2e", "西向东", 7),
S2N("s2n", "南向北"); N2S("n2s", "北向南", 1),
S2N("s2n", "南向北", 5);
private String code; private String code;
private String desc; private String desc;
private Integer inDir;
public static String getDesc(String code) { public static String getDesc(String code) {
for (GreenBeltDirEnum dirEnum : GreenBeltDirEnum.values()) { for (GreenBeltDirEnum dirEnum : GreenBeltDirEnum.values()) {
...@@ -27,4 +32,22 @@ public enum GreenBeltDirEnum { ...@@ -27,4 +32,22 @@ public enum GreenBeltDirEnum {
} }
return ""; return "";
} }
public static Integer getInDir(String code) {
for (GreenBeltDirEnum value : GreenBeltDirEnum.values()) {
if (StringUtils.equalsIgnoreCase(code, value.getCode())) {
return value.getInDir();
}
}
return 1;
}
public static String getInDirName(Integer dir) {
for (GreenBeltDirEnum value : GreenBeltDirEnum.values()) {
if (Objects.equals(dir, value.getInDir())) {
return value.getDesc();
}
}
return "";
}
} }
...@@ -55,13 +55,13 @@ public class GreenBeltController { ...@@ -55,13 +55,13 @@ public class GreenBeltController {
@ApiResponse(code = 200, message = "OK", response = GreenBeltSpeedWidthVO.class), @ApiResponse(code = 200, message = "OK", response = GreenBeltSpeedWidthVO.class),
}) })
public JsonViewObject greenBeltSpeedWidth(Integer greenId) { public JsonViewObject greenBeltSpeedWidth(Integer greenId) {
Map<String, List<GreenBeltSpeedWidthVO>> map = Collections.EMPTY_MAP; List<GreenBeltSpeedWidthVO> list = Collections.EMPTY_LIST;
try { try {
map = greenBeltInfoService.greenBeltSpeedWidth(greenId); list = greenBeltInfoService.greenBeltSpeedWidth(greenId);
} catch (Exception e) { } catch (Exception e) {
JsonViewObject.newInstance().fail("绿波带宽曲线异常"); JsonViewObject.newInstance().fail("绿波带宽曲线异常");
} }
return JsonViewObject.newInstance().success(map); return JsonViewObject.newInstance().success(list);
} }
@ApiOperation(value = "绿波关键路口流量绿信比", notes = "优化监测-绿波关键路口流量绿信比", response = JsonViewObject.class, @ApiOperation(value = "绿波关键路口流量绿信比", notes = "优化监测-绿波关键路口流量绿信比", response = JsonViewObject.class,
...@@ -71,13 +71,13 @@ public class GreenBeltController { ...@@ -71,13 +71,13 @@ public class GreenBeltController {
@ApiResponse(code = 200, message = "OK", response = GreenBeltKeyCrossFlowTimeVO.class), @ApiResponse(code = 200, message = "OK", response = GreenBeltKeyCrossFlowTimeVO.class),
}) })
public JsonViewObject greenBeltKeyCrossFlowTime(Integer greenId) { public JsonViewObject greenBeltKeyCrossFlowTime(Integer greenId) {
Map<String, List<GreenBeltKeyCrossFlowTimeVO>> map = Collections.EMPTY_MAP; List<GreenBeltKeyCrossFlowTimeVO> list = Collections.EMPTY_LIST;
try { try {
map = greenBeltInfoService.greenBeltKeyCrossFlowTime(greenId); list = greenBeltInfoService.greenBeltKeyCrossFlowTime(greenId);
} catch (Exception e) { } catch (Exception e) {
JsonViewObject.newInstance().fail("绿波带宽曲线异常"); JsonViewObject.newInstance().fail("绿波带宽曲线异常");
} }
return JsonViewObject.newInstance().success(map); return JsonViewObject.newInstance().success(list);
} }
@ApiOperation(value = "干线详情", notes = "优化监测-干线详情", response = JsonViewObject.class, @ApiOperation(value = "干线详情", notes = "优化监测-干线详情", response = JsonViewObject.class,
......
...@@ -6,15 +6,13 @@ import net.wanji.opt.vo.GreenBeltKeyCrossFlowTimeVO; ...@@ -6,15 +6,13 @@ import net.wanji.opt.vo.GreenBeltKeyCrossFlowTimeVO;
import net.wanji.opt.vo.GreenBeltSpeedWidthVO; import net.wanji.opt.vo.GreenBeltSpeedWidthVO;
import java.util.List; import java.util.List;
import java.util.Map;
/** /**
* @author duanruiming * @author duanruiming
* @date 2024/11/19 18:07 * @date 2024/11/19 18:07
*/ */
public interface GreenBeltInfoService { public interface GreenBeltInfoService {
List<GreenBeltFlowStopTimeVO> greenBeltCrossDetailHist(Integer greenId) throws Exception; List<GreenBeltFlowStopTimeVO> greenBeltCrossDetailHist(Integer greenId) throws Exception;
Map<String, List<GreenBeltSpeedWidthVO>> greenBeltSpeedWidth(Integer greenId) throws Exception; List<GreenBeltSpeedWidthVO> greenBeltSpeedWidth(Integer greenId) throws Exception;
Map<String, List<GreenBeltKeyCrossFlowTimeVO>> greenBeltKeyCrossFlowTime(Integer greenId) throws Exception; List<GreenBeltKeyCrossFlowTimeVO> greenBeltKeyCrossFlowTime(Integer greenId) throws Exception;
GreenBeltCrossDetailVO greenBeltCrossDetailList(Integer greenId) throws Exception; GreenBeltCrossDetailVO greenBeltCrossDetailList(Integer greenId) throws Exception;
} }
...@@ -14,7 +14,6 @@ import net.wanji.databus.dao.entity.GreenwaveHistPO; ...@@ -14,7 +14,6 @@ import net.wanji.databus.dao.entity.GreenwaveHistPO;
import net.wanji.databus.dao.entity.GreenwaveInfoPO; import net.wanji.databus.dao.entity.GreenwaveInfoPO;
import net.wanji.databus.dao.entity.GreenwaveRealtimePO; import net.wanji.databus.dao.entity.GreenwaveRealtimePO;
import net.wanji.databus.dao.mapper.*; import net.wanji.databus.dao.mapper.*;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDataRealtimePO; import net.wanji.databus.po.CrossDataRealtimePO;
import net.wanji.databus.po.CrossDirDataHistPO; import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.opt.cache.BaseCrossInfoCache; import net.wanji.opt.cache.BaseCrossInfoCache;
...@@ -29,11 +28,7 @@ import org.springframework.stereotype.Service; ...@@ -29,11 +28,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.DecimalFormat; import java.time.*;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -103,159 +98,212 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService { ...@@ -103,159 +98,212 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
} }
@Override @Override
public Map<String, List<GreenBeltKeyCrossFlowTimeVO>> greenBeltKeyCrossFlowTime(Integer greenId) throws Exception { public List<GreenBeltKeyCrossFlowTimeVO> greenBeltKeyCrossFlowTime(Integer greenId) throws Exception {
try { try {
ObjectMapper mapper = JacksonUtils.getInstance();
DecimalFormat df = new DecimalFormat("#0.00");
List<GreenBeltKeyCrossFlowTimeVO> tempResult = new ArrayList<>();
List<GreenBeltKeyCrossFlowTimeVO> results = new ArrayList<>(); List<GreenBeltKeyCrossFlowTimeVO> results = new ArrayList<>();
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT; LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime); LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
// 最少有一条数据
List<GreenBeltKeyCrossFlowTimeVO.Detail> optResults = getGreenOptList(greenId, startOfDay);
GreenBeltKeyCrossFlowTimeVO.Detail optDetail = optResults.get(0);
String crossId = optDetail.getCrossId();
GreenwaveInfoPO greenwaveInfoPO = GreenWaveInfoCache.greenWaveMap.get(greenId);
String greenDir = greenwaveInfoPO.getGreenDir();
String[] split = greenDir.split(",");
List<Integer> dirList = new ArrayList<>();
for (String s : split) {
dirList.add(Integer.valueOf(s));
}
Instant instant = startOfDay.atZone(ZoneId.systemDefault()).toInstant();
int start = (int) (instant.toEpochMilli() / 1000) + 300;
int end = (int) (System.currentTimeMillis() / 1000) + 300;
List<CrossDirDataHistPO> dirDataHistPOS = crossDirDataHistMapper.selectDirDataList(crossId, dirList, start, end);
if (!CollectionUtils.isEmpty(dirDataHistPOS)) {
Double greenTimeRatio = 0.0;
List<GreenBeltKeyCrossFlowTimeVO.Detail> details = new ArrayList<>();
for (CrossDirDataHistPO dirDataHistPO : dirDataHistPOS) {
GreenBeltKeyCrossFlowTimeVO.Detail detail = new GreenBeltKeyCrossFlowTimeVO.Detail();
detail.setCrossId(crossId);
String crossName = baseCrossInfoCache.getCrossName(crossId);
detail.setCrossName(crossName);
Integer dirType = dirDataHistPO.getDirType();
detail.setDir(String.valueOf(dirType));
detail.setFlow(dirDataHistPO.getFlow());
detail.setStartTime(dirDataHistPO.getStartTime());
detail.setGreenTimeRatio(greenTimeRatio);
for (GreenBeltKeyCrossFlowTimeVO.Detail optResult : optResults) {
Integer curDir = GreenBeltDirEnum.getInDir(optResult.getDir());
if (StringUtils.equalsIgnoreCase("cancel", optResult.getDir()) && Objects.equals(curDir, dirType)
&& dirDataHistPO.getStartTime().getTime() == optResult.getStartTime().getTime()) {
greenTimeRatio = 0.0;
}
if (StringUtils.equalsIgnoreCase(crossId, optResult.getCrossId()) && Objects.equals(curDir, dirType)
&& dirDataHistPO.getStartTime().getTime() == optResult.getStartTime().getTime()) {
detail.setGreenTimeRatio(optResult.getGreenTimeRatio());
greenTimeRatio = optResult.getGreenTimeRatio();
}
}
details.add(detail);
}
if (!CollectionUtils.isEmpty(details)) {
Map<String, List<GreenBeltKeyCrossFlowTimeVO.Detail>> dirMap = details.stream().collect(Collectors.groupingBy(GreenBeltKeyCrossFlowTimeVO.Detail::getDir));
for (Map.Entry<String, List<GreenBeltKeyCrossFlowTimeVO.Detail>> entry : dirMap.entrySet()) {
String dir = entry.getKey();
GreenBeltKeyCrossFlowTimeVO greenBeltKeyCrossFlowTimeVO = new GreenBeltKeyCrossFlowTimeVO();
List<GreenBeltKeyCrossFlowTimeVO.Detail> value = entry.getValue();
String crossName = "";
if (!CollectionUtils.isEmpty(value)) {
GreenBeltKeyCrossFlowTimeVO.Detail detail = value.get(0);
crossName = detail.getCrossName();
}
greenBeltKeyCrossFlowTimeVO.setCrossName(crossName);
greenBeltKeyCrossFlowTimeVO.setDirName(GreenBeltDirEnum.getInDirName(Integer.valueOf(dir)));
List<GreenBeltKeyCrossFlowTimeVO.Detail> collect = value.stream().sorted(Comparator.comparing(GreenBeltKeyCrossFlowTimeVO.Detail::getStartTime)).collect(Collectors.toList());
greenBeltKeyCrossFlowTimeVO.setDetailList(collect);
results.add(greenBeltKeyCrossFlowTimeVO);
}
}
}
// 关键路口历史数据
return results;
} catch (Exception e) {
log.error("绿波关键路口流量绿信比查询异常:", e);
throw new RuntimeException(e);
}
}
/**
* 获取绿波优化列表
*
* @param greenId
* @param startOfDay
* @return
* @throws JsonProcessingException
*/
private List<GreenBeltKeyCrossFlowTimeVO.Detail> getGreenOptList(Integer greenId, LocalDateTime startOfDay) throws Exception {
List<GreenBeltKeyCrossFlowTimeVO.Detail> optResults = null;
try {
optResults = new ArrayList<>();
// 绿波优化数据 // 绿波优化数据
List<StrategyGreenOptHistEntity> entities = new ArrayList<>(); List<StrategyGreenOptHistEntity> entities = new ArrayList<>();
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId); queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay); queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlMethod, 1);
entities = strategyGreenOptHistMapper.selectList(queryWrapper); entities = strategyGreenOptHistMapper.selectList(queryWrapper);
// 如果路口没有绿波,获取当前绿波最大的一条数据 if (CollectionUtils.isEmpty(entities)) {
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapperMaxId = new LambdaQueryWrapper<>(); // 如果路口没有绿波,获取当前绿波最大的一条数据
queryWrapperMaxId.eq(StrategyGreenOptHistEntity::getGreenId, greenId); LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapperMaxId = new LambdaQueryWrapper<>();
queryWrapperMaxId.ge(StrategyGreenOptHistEntity::getControlMethod, 1); queryWrapperMaxId.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapperMaxId.orderByDesc(StrategyGreenOptHistEntity::getControlTime); queryWrapperMaxId.ge(StrategyGreenOptHistEntity::getControlMethod, 1);
queryWrapperMaxId.last("limit 1"); queryWrapperMaxId.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay.minusDays(1));
entities = strategyGreenOptHistMapper.selectList(queryWrapperMaxId); queryWrapperMaxId.orderByDesc(StrategyGreenOptHistEntity::getControlTime);
// 随机路口编号,通过路口编号查询时间轴 queryWrapperMaxId.last("limit 1");
String keyCrossId = ""; entities = strategyGreenOptHistMapper.selectList(queryWrapperMaxId);
String keyGreenDir = ""; }
// 一个绿波只有一个关键路口
if (!CollectionUtils.isEmpty(entities)) { if (!CollectionUtils.isEmpty(entities)) {
for (StrategyGreenOptHistEntity entity : entities) { for (StrategyGreenOptHistEntity entity : entities) {
GreenBeltKeyCrossFlowTimeVO vo = new GreenBeltKeyCrossFlowTimeVO(); GreenBeltKeyCrossFlowTimeVO.Detail detail = new GreenBeltKeyCrossFlowTimeVO.Detail();
String keyCross = entity.getKeyCross(); String keyCross = entity.getKeyCross();
vo.setCrossId(keyCross); detail.setCrossId(keyCross);
vo.setDirName(GreenBeltDirEnum.getDesc(entity.getDir())); detail.setDir(entity.getDir());
Date controlTime = get5MinuteDate(entity.getControlTime()); Date controlTime = get5MinuteDate(entity.getControlTime());
vo.setStartTime(controlTime); detail.setStartTime(controlTime);
String crossGreenDetail = entity.getCrossGreenDetail(); String crossGreenDetail = entity.getCrossGreenDetail();
Integer cycle = entity.getCycle(); Integer cycle = entity.getCycle();
keyCrossId = entity.getKeyCross(); ObjectMapper mapper = JacksonUtils.getInstance();
keyGreenDir = entity.getDir(); List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = mapper.readValue(crossGreenDetail, new TypeReference<List<GreenBeltInfoVO.CrossGreenDetail>>() {
List<GreenBeltInfoVO.CrossGreenDetail> crossGreenDetails = mapper.readValue(crossGreenDetail, new TypeReference<List<GreenBeltInfoVO.CrossGreenDetail>>() {}); });
if (!CollectionUtils.isEmpty(crossGreenDetails)) { if (!CollectionUtils.isEmpty(crossGreenDetails)) {
List<GreenBeltInfoVO.CrossGreenDetail> keyCrossDetail = crossGreenDetails.stream().filter(details -> StringUtils.equalsIgnoreCase(keyCross, details.getCrossId())).collect(Collectors.toList()); List<GreenBeltInfoVO.CrossGreenDetail> keyCrossDetail = crossGreenDetails.stream().filter(details -> StringUtils.equalsIgnoreCase(keyCross, details.getCrossId())).collect(Collectors.toList());
if (!CollectionUtils.isEmpty(keyCrossDetail)) { if (!CollectionUtils.isEmpty(keyCrossDetail)) {
GreenBeltInfoVO.CrossGreenDetail curKeyCross = keyCrossDetail.get(0); for (GreenBeltInfoVO.CrossGreenDetail curKeyCross : keyCrossDetail) {
Double phaseStartTime = curKeyCross.getPhaseStartTime(); String currentCrossId = curKeyCross.getCrossId();
Double phaseEndTime = curKeyCross.getPhaseEndTime(); if (StringUtils.equalsIgnoreCase(keyCross, currentCrossId)) {
Double greenTimeRatio = Double.parseDouble(df.format(phaseEndTime - phaseStartTime / cycle)); Double phaseStartTime = curKeyCross.getPhaseStartTime();
vo.setGreenTimeRatio(greenTimeRatio); Double phaseEndTime = curKeyCross.getPhaseEndTime();
Double greenTimeRatio = (phaseEndTime - phaseStartTime) / cycle;
detail.setGreenTimeRatio(greenTimeRatio);
}
}
} }
} }
tempResult.add(vo); // 设置中间变量 优化结束
} if (entity.getControlMethod() <= 0) {
} detail.setDir("cancel");
// 关键路口历史数据
LambdaQueryWrapper<CrossDataHistPO> histQuery = new LambdaQueryWrapper<>();
histQuery.eq(CrossDataHistPO::getCrossId, keyCrossId);
histQuery.ge(CrossDataHistPO::getStartTime, startOfDay);
List<CrossDataHistPO> crossDataHistPOS = crossDataHistMapper.selectList(histQuery);
if (!CollectionUtils.isEmpty(crossDataHistPOS)) {
for (CrossDataHistPO crossDataHistPO : crossDataHistPOS) {
Date crossStartTime = crossDataHistPO.getStartTime();
String format = DateUtil.format(crossStartTime, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND);
Date minuteDate = get5MinuteDate(format);
Integer flow = crossDataHistPO.getFlow();
GreenBeltKeyCrossFlowTimeVO resultVO = new GreenBeltKeyCrossFlowTimeVO();
resultVO.setStartTime(minuteDate);
resultVO.setFlow(flow);
resultVO.setGreenTimeRatio(0.0);
resultVO.setCrossId(keyCrossId);
resultVO.setDirName(GreenBeltDirEnum.getDesc(keyGreenDir));
String crossName = baseCrossInfoCache.getCrossName(keyCrossId);
resultVO.setCrossName(crossName);
for (GreenBeltKeyCrossFlowTimeVO result : tempResult) {
if (StringUtils.equalsIgnoreCase(keyCrossId, result.getCrossId())
&& minuteDate.getTime() == result.getStartTime().getTime()) {
resultVO.setFlow(flow);
resultVO.setGreenTimeRatio(result.getGreenTimeRatio());
}
} }
results.add(resultVO); optResults.add(detail);
} }
} }
Map<String, List<GreenBeltKeyCrossFlowTimeVO>> map = results.stream().collect(Collectors.groupingBy(GreenBeltKeyCrossFlowTimeVO::getDirName));
return map;
} catch (Exception e) { } catch (Exception e) {
log.error("绿波关键路口流量绿信比查询异常:", e); log.error("绿波优化列表数据异常;", e);
throw new RuntimeException(e); throw new Exception(e);
} }
return optResults;
} }
@Override @Override
public Map<String, List<GreenBeltSpeedWidthVO>> greenBeltSpeedWidth(Integer greenId) throws Exception { public List<GreenBeltSpeedWidthVO> greenBeltSpeedWidth(Integer greenId) throws Exception {
try { try {
List<GreenBeltSpeedWidthVO> results = new ArrayList<>(); List<GreenBeltSpeedWidthVO> results = new ArrayList<>();
LocalDate currentDate = LocalDate.now(); LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT; LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime); LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
// 绿波历史数据
LambdaQueryWrapper<GreenwaveHistPO> greenWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<GreenwaveHistPO> greenWrapper = new LambdaQueryWrapper<>();
greenWrapper.eq(GreenwaveHistPO::getGreenId, greenId); greenWrapper.eq(GreenwaveHistPO::getGreenId, greenId);
greenWrapper.ge(GreenwaveHistPO::getStartTime, startOfDay); greenWrapper.ge(GreenwaveHistPO::getStartTime, startOfDay);
// 绿波历史数据
List<GreenwaveHistPO> greenwaveHistPOS = greenwaveHistMapper.selectList(greenWrapper); List<GreenwaveHistPO> greenwaveHistPOS = greenwaveHistMapper.selectList(greenWrapper);
// 绿波优化数据 // 绿波优化数据
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId); queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay); queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay);
queryWrapper.ne(StrategyGreenOptHistEntity::getControlMethod, -1); queryWrapper.ge(StrategyGreenOptHistEntity::getControlMethod, 1);
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper); List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(greenwaveHistPOS)) { if (!CollectionUtils.isEmpty(greenwaveHistPOS)) {
for (GreenwaveHistPO histPO : greenwaveHistPOS) { Map<String, List<GreenwaveHistPO>> greenDirMap = greenwaveHistPOS.stream().collect(Collectors.groupingBy(GreenwaveHistPO::getRoadDirection));
Integer curGreenId = histPO.getGreenId(); for (Map.Entry<String, List<GreenwaveHistPO>> entry : greenDirMap.entrySet()) {
Date curStartTime = histPO.getStartTime(); String dir = entry.getKey();
String curStartTimeStr = DateUtil.format(curStartTime, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND); GreenBeltSpeedWidthVO greenBeltSpeedWidthVO = new GreenBeltSpeedWidthVO();
Date startTimeminuteDate = get5MinuteDate(curStartTimeStr); greenBeltSpeedWidthVO.setDirName(GreenBeltDirEnum.getDesc(dir));
String roadDirection = histPO.getRoadDirection(); List<GreenBeltSpeedWidthVO.Detail> details = new ArrayList<>();
Double speed = histPO.getSpeed(); List<GreenwaveHistPO> value = entry.getValue();
if (CollectionUtils.isEmpty(entities)) { double greenWidthTime = 0.0;
GreenBeltSpeedWidthVO vo = new GreenBeltSpeedWidthVO(); for (GreenwaveHistPO histPO : value) {
vo.setStartTime(curStartTime); Integer curGreenId = histPO.getGreenId();
vo.setSpeed(speed); Date curStartTime = histPO.getStartTime();
vo.setWidth(0.0); String curStartTimeStr = DateUtil.format(curStartTime, Constants.DATE_FORMAT.E_DATE_FORMAT_SECOND);
vo.setDirName(GreenBeltDirEnum.getDesc(roadDirection)); Date startTimeminuteDate = get5MinuteDate(curStartTimeStr);
results.add(vo); Double speed = histPO.getSpeed();
} else { GreenBeltSpeedWidthVO.Detail detail = new GreenBeltSpeedWidthVO.Detail();
for (StrategyGreenOptHistEntity entity : entities) { for (StrategyGreenOptHistEntity entity : entities) {
Integer optGreenId = entity.getGreenId(); Integer optGreenId = entity.getGreenId();
String controlTime = entity.getControlTime(); String controlTime = entity.getControlTime();
String dir = entity.getDir(); String optDir = entity.getDir();
Date minuteDate = get5MinuteDate(controlTime); Date minuteDate = get5MinuteDate(controlTime);
Double greenWidthTime = entity.getGreenWidthTime(); if (Objects.equals(curGreenId, optGreenId) && StringUtils.equalsIgnoreCase(optDir, dir)
if (Objects.equals(curGreenId, optGreenId) && StringUtils.equalsIgnoreCase(dir, roadDirection)
&& minuteDate.getTime() == startTimeminuteDate.getTime()) { && minuteDate.getTime() == startTimeminuteDate.getTime()) {
GreenBeltSpeedWidthVO vo = new GreenBeltSpeedWidthVO(); greenWidthTime = entity.getGreenWidthTime();
vo.setStartTime(curStartTime); }
vo.setSpeed(speed); if (entity.getControlMethod() <= 0) {
vo.setWidth(greenWidthTime); greenWidthTime = 0.0;
vo.setDirName(GreenBeltDirEnum.getDesc(dir));
results.add(vo);
} else {
GreenBeltSpeedWidthVO vo = new GreenBeltSpeedWidthVO();
vo.setStartTime(curStartTime);
vo.setSpeed(speed);
vo.setWidth(0.0);
vo.setDirName(GreenBeltDirEnum.getDesc(roadDirection));
results.add(vo);
} }
} }
detail.setStartTime(curStartTime);
detail.setSpeed(speed);
detail.setWidth(greenWidthTime);
detail.setDir(dir);
details.add(detail);
} }
greenBeltSpeedWidthVO.setDetailList(details);
results.add(greenBeltSpeedWidthVO);
} }
} }
Map<String, List<GreenBeltSpeedWidthVO>> map = results.stream().collect(Collectors.groupingBy(GreenBeltSpeedWidthVO::getDirName)); return results;
return map;
} catch (Exception e) { } catch (Exception e) {
log.error("绿波带宽曲线异常:", e); log.error("绿波带宽曲线异常:", e);
throw new RuntimeException(e); throw new RuntimeException(e);
......
package net.wanji.opt.vo; package net.wanji.opt.vo;
import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
import lombok.Data; import lombok.Data;
import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author duanruiming * @author duanruiming
...@@ -14,17 +17,26 @@ import java.util.Date; ...@@ -14,17 +17,26 @@ import java.util.Date;
@Data @Data
@ApiModel(value = "优化监测-绿波关键路口流量绿信比实体") @ApiModel(value = "优化监测-绿波关键路口流量绿信比实体")
public class GreenBeltKeyCrossFlowTimeVO { public class GreenBeltKeyCrossFlowTimeVO {
@ApiModelProperty("路口编号")
private String crossId;
@ApiModelProperty("路口名称")
private String crossName;
@ApiModelProperty("时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty("干线方向") @ApiModelProperty("干线方向")
private String dirName; private String dirName;
@ApiModelProperty("流量") @ApiModelProperty("路口名称")
private Integer flow; private String crossName;
@ApiModelProperty("绿信比") private List<Detail> detailList;
private Double greenTimeRatio; @Data
public static class Detail {
@ApiModelProperty("路口编号")
private String crossId;
@ApiModelProperty("干线方向")
private String dir;
@ApiModelProperty("路口名称")
private String crossName;
@ApiModelProperty("时间")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty("流量")
private Integer flow;
@ApiModelProperty("绿信比")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double greenTimeRatio;
}
} }
...@@ -8,6 +8,7 @@ import lombok.Data; ...@@ -8,6 +8,7 @@ import lombok.Data;
import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer; import net.wanji.opt.config.Double2TwoDecimalPlacesSerializer;
import java.util.Date; import java.util.Date;
import java.util.List;
/** /**
* @author duanruiming * @author duanruiming
...@@ -16,15 +17,21 @@ import java.util.Date; ...@@ -16,15 +17,21 @@ import java.util.Date;
@Data @Data
@ApiModel(value = "优化监测-绿波带宽曲线实体") @ApiModel(value = "优化监测-绿波带宽曲线实体")
public class GreenBeltSpeedWidthVO { public class GreenBeltSpeedWidthVO {
@ApiModelProperty("时间") @ApiModelProperty("干线方向名称")
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty("干线方向")
private String dirName; private String dirName;
@ApiModelProperty("速度") private List<Detail> detailList;
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class) @Data
private Double speed; public static class Detail {
@ApiModelProperty("带宽") @ApiModelProperty("时间")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class) @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "HH:mm:ss", timezone = "GMT+8")
private Double width; private Date startTime;
@ApiModelProperty("干线方向")
private String dir;
@ApiModelProperty("速度")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double speed;
@ApiModelProperty("带宽")
@JsonSerialize(using = Double2TwoDecimalPlacesSerializer.class)
private Double width;
}
} }
...@@ -53,6 +53,7 @@ public interface CrossDirDataHistMapper extends BaseMapper<CrossDirDataHistPO> { ...@@ -53,6 +53,7 @@ public interface CrossDirDataHistMapper extends BaseMapper<CrossDirDataHistPO> {
List<CrossDirDataHistPO> selectByCrossIdsDirsAndTimestamp(List<String> crossIdList, List<Integer> dirCodeList, int startTimeStamp, int endTimeStamp); List<CrossDirDataHistPO> selectByCrossIdsDirsAndTimestamp(List<String> crossIdList, List<Integer> dirCodeList, int startTimeStamp, int endTimeStamp);
List<CrossDirDataHistPO> selectByCrossIdDirsAndTimestamp(String crossId, List<Integer> dirCodeList, int startTimeStamp, int endTimeStamp); List<CrossDirDataHistPO> selectByCrossIdDirsAndTimestamp(String crossId, List<Integer> dirCodeList, int startTimeStamp, int endTimeStamp);
List<CrossDirDataHistPO> selectDirDataList(String crossId, List<Integer> dirCodeList, int startTimeStamp, int endTimeStamp);
List<CrossDirDataHistPO> selectByCrossDirAndTimeSection( List<CrossDirDataHistPO> selectByCrossDirAndTimeSection(
@Param("crossId") String crossId, @Param("crossId") String crossId,
......
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="net.wanji.databus.dao.mapper.CrossDirDataHistMapper"> <resultMap id="BaseResultMap" type="net.wanji.databus.po.CrossDirDataHistPO"> <result column="id" property="id"></result> <result column="dir_type" property="dirType"></result> <result column="in_out_type" property="inOutType"></result> <result column="cross_id" property="crossId"></result> <result column="length" property="length"></result> <result column="status" property="status"></result> <result column="traffic_index" property="trafficIndex"></result> <result column="start_time" property="startTime"></result> <result column="capacity" property="capacity"></result> <result column="duration" property="duration"></result> <result column="flow" property="flow"></result> <result column="speed" property="speed"></result> <result column="queue_length" property="queueLength"></result> <result column="stop_times" property="stopTimes"></result> <result column="delay_time" property="delayTime"></result> <result column="sturation" property="sturation"></result> <result column="batch_time" property="batchTime"></result> <result column="gmt_create" property="gmtCreate"></result> <result column="gmt_modified" property="gmtModified"></result> <result column="effusion_rate" property="effusionRate"></result> <result column="green_light_efficiency" property="greenLightEfficiency"></result> </resultMap> <sql id="Base_Column_List"> id,dir_type,in_out_type,cross_id,length,status,traffic_index,start_time,capacity,duration,flow,speed,queue_length,stop_times, delay_time,sturation,no_stop_rate,one_stop_rate,two_stop_rate,three_stop_rate,batch_time,gmt_create,gmt_modified,effusion_rate, green_light_efficiency </sql> <insert id="insertBatch" parameterType="net.wanji.databus.po.CrossDirDataHistPO"> insert ignore into t_cross_dir_data_hist (<include refid="Base_Column_List"></include>) values <foreach collection="list" item="entity" separator=","> ( #{entity.id}, #{entity.dirType}, #{entity.inOutType}, #{entity.crossId}, #{entity.length}, #{entity.status}, #{entity.trafficIndex}, #{entity.startTime}, #{entity.capacity}, #{entity.duration}, #{entity.flow}, #{entity.speed}, #{entity.queueLength}, #{entity.stopTimes}, #{entity.delayTime}, #{entity.sturation}, #{entity.noStopRate},#{entity.oneStopRate},#{entity.twoStopRate},#{entity.threeStopRate},#{entity.batchTime}, #{entity.gmtCreate}, #{entity.gmtModified},#{entity.effusionRate},#{entity.greenLightEfficiency}) </foreach> </insert> <delete id="deleteBatch" parameterType="String"> delete from t_cross_dir_data_hist where cross_id in <foreach collection="list" item="crossId" separator="," open="(" close=")"> #{crossId} </foreach> </delete> <select id="selectByCrossIdAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and batch_time <![CDATA[ >= ]]> #{preSeconds} order by batch_time </select> <select id="selectByCrossIdDirAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type = #{dir} and batch_time <![CDATA[ >= ]]> #{preSeconds} order by batch_time </select> <select id="selectByCrossIdInOutTimestamp" resultType="net.wanji.databus.bo.CrossDirDataHistAvgBO"> SELECT dir_type as dirType, avg(capacity) as avgCapacity, avg(flow) as avgFlow, avg(queue_length) as avgQueueLength, avg(traffic_index) as avgIndex, avg(effusion_rate) as avgeffusionRate FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND in_out_type = #{inOutType} AND batch_time <![CDATA[ >= ]]> #{preSeconds} AND batch_time <![CDATA[ < ]]> #{endSeconds} GROUP BY dir_type </select> <select id="selectNoPark" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 2 and dir_type = #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectPhaseQueue" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 2 and dir_type != #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectNoParkEnd" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type = #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectPhaseQueueEnd" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type != #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectMetricHistDTO" resultType="net.wanji.databus.dto.MetricHistDTO"> select status, start_time, duration, flow, speed, sturation, capacity, stop_times, delay_time, batch_time, one_stop_rate, queue_length, effusion_rate, no_stop_rate, green_light_efficiency from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type = #{dir} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} order by batch_time </select> <select id="selectByCrossIdAndStartEnd" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxDelayTime" resultType="java.lang.Integer"> select max(delay_time) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirType} and in_out_type = #{inOutType} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxQueueLength" resultType="java.lang.Double"> select max(queue_length) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirType} and in_out_type = #{inOutType} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxSaturation" resultType="java.lang.Double"> select max(sturation) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirType} and in_out_type = #{inOutType} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxGreenLightEfficiency" resultType="java.lang.Double"> select max(green_light_efficiency) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirCode} and in_out_type = #{code} and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} </select> <select id="selectByMetrics" resultType="net.wanji.databus.po.CrossDirDataHistPOExt"> SELECT <include refid="Base_Column_List"/> FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND in_out_type = 1 AND dir_type = #{dirInt} AND batch_time <![CDATA[ <= ]]> #{endTimeStamp} AND batch_time <![CDATA[ >= ]]> #{startTimeStamp} </select> <select id="selectByCrossIdsDirsAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"></include> from t_cross_dir_data_hist where cross_id in <foreach collection="crossIdList" item="crossId" separator="," open="(" close=")"> #{crossId} </foreach> and dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach><!-- and in_out_type = 1--> and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} order by batch_time </select> <select id="selectByCrossDirAndTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPO"> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND dir_type = #{dirCode} AND in_out_type = 1 AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%Y-%m-%d') BETWEEN #{boStartDayStr} AND #{boEndDayStr} AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%H:%i') BETWEEN #{startHourMinuteStr} AND #{endHourMinuteStr} </select> <select id="selectByCrossIdDirsAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"></include> from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach> and in_out_type = 1 and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} order by batch_time </select> <select id="selectByCrossDirsAndTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPO"> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach> AND in_out_type = 1 AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%Y-%m-%d') BETWEEN #{boStartDayStr} AND #{boEndDayStr} AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%H:%i') BETWEEN #{startHourMinuteStr} AND #{endHourMinuteStr} </select> <select id="selectByTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPO"><!-- SELECT <include refid="Base_Column_List"></include>--><!-- FROM t_cross_dir_data_hist--><!-- WHERE in_out_type = 1--><!-- AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%Y-%m-%d') BETWEEN #{boStartDayStr} AND #{boEndDayStr}--><!-- AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%H:%i') BETWEEN #{startHourMinuteStr} AND #{endHourMinuteStr}--> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE batch_time BETWEEN UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boStartDayStr}, #{startHourMinuteStr}), '%Y-%m-%d%H:%i')) AND UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boEndDayStr}, #{endHourMinuteStr}), '%Y-%m-%d%H:%i')) AND in_out_type = 1 </select> <select id="selectExtByTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPOExt"> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE batch_time BETWEEN UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boStartDayStr}, #{startHourMinuteStr}), '%Y-%m-%d%H:%i')) AND UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boEndDayStr}, #{endHourMinuteStr}), '%Y-%m-%d%H:%i')) AND in_out_type = 1 </select> </mapper> <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"><mapper namespace="net.wanji.databus.dao.mapper.CrossDirDataHistMapper"> <resultMap id="BaseResultMap" type="net.wanji.databus.po.CrossDirDataHistPO"> <result column="id" property="id"></result> <result column="dir_type" property="dirType"></result> <result column="in_out_type" property="inOutType"></result> <result column="cross_id" property="crossId"></result> <result column="length" property="length"></result> <result column="status" property="status"></result> <result column="traffic_index" property="trafficIndex"></result> <result column="start_time" property="startTime"></result> <result column="capacity" property="capacity"></result> <result column="duration" property="duration"></result> <result column="flow" property="flow"></result> <result column="speed" property="speed"></result> <result column="queue_length" property="queueLength"></result> <result column="stop_times" property="stopTimes"></result> <result column="delay_time" property="delayTime"></result> <result column="sturation" property="sturation"></result> <result column="batch_time" property="batchTime"></result> <result column="gmt_create" property="gmtCreate"></result> <result column="gmt_modified" property="gmtModified"></result> <result column="effusion_rate" property="effusionRate"></result> <result column="green_light_efficiency" property="greenLightEfficiency"></result> </resultMap> <sql id="Base_Column_List"> id,dir_type,in_out_type,cross_id,length,status,traffic_index,start_time,capacity,duration,flow,speed,queue_length,stop_times, delay_time,sturation,no_stop_rate,one_stop_rate,two_stop_rate,three_stop_rate,batch_time,gmt_create,gmt_modified,effusion_rate, green_light_efficiency </sql> <insert id="insertBatch" parameterType="net.wanji.databus.po.CrossDirDataHistPO"> insert ignore into t_cross_dir_data_hist (<include refid="Base_Column_List"></include>) values <foreach collection="list" item="entity" separator=","> ( #{entity.id}, #{entity.dirType}, #{entity.inOutType}, #{entity.crossId}, #{entity.length}, #{entity.status}, #{entity.trafficIndex}, #{entity.startTime}, #{entity.capacity}, #{entity.duration}, #{entity.flow}, #{entity.speed}, #{entity.queueLength}, #{entity.stopTimes}, #{entity.delayTime}, #{entity.sturation}, #{entity.noStopRate},#{entity.oneStopRate},#{entity.twoStopRate},#{entity.threeStopRate},#{entity.batchTime}, #{entity.gmtCreate}, #{entity.gmtModified},#{entity.effusionRate},#{entity.greenLightEfficiency}) </foreach> </insert> <delete id="deleteBatch" parameterType="String"> delete from t_cross_dir_data_hist where cross_id in <foreach collection="list" item="crossId" separator="," open="(" close=")"> #{crossId} </foreach> </delete> <select id="selectByCrossIdAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and batch_time <![CDATA[ >= ]]> #{preSeconds} order by batch_time </select> <select id="selectByCrossIdDirAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type = #{dir} and batch_time <![CDATA[ >= ]]> #{preSeconds} order by batch_time </select> <select id="selectByCrossIdInOutTimestamp" resultType="net.wanji.databus.bo.CrossDirDataHistAvgBO"> SELECT dir_type as dirType, avg(capacity) as avgCapacity, avg(flow) as avgFlow, avg(queue_length) as avgQueueLength, avg(traffic_index) as avgIndex, avg(effusion_rate) as avgeffusionRate FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND in_out_type = #{inOutType} AND batch_time <![CDATA[ >= ]]> #{preSeconds} AND batch_time <![CDATA[ < ]]> #{endSeconds} GROUP BY dir_type </select> <select id="selectNoPark" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 2 and dir_type = #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectPhaseQueue" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 2 and dir_type != #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectNoParkEnd" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type = #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectPhaseQueueEnd" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type != #{dir} and batch_time <![CDATA[ <= ]]> #{currentSeconds} and batch_time <![CDATA[ >= ]]> #{preSeconds} </select> <select id="selectMetricHistDTO" resultType="net.wanji.databus.dto.MetricHistDTO"> select status, start_time, duration, flow, speed, sturation, capacity, stop_times, delay_time, batch_time, one_stop_rate, queue_length, effusion_rate, no_stop_rate, green_light_efficiency from t_cross_dir_data_hist where cross_id = #{crossId} and in_out_type = 1 and dir_type = #{dir} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} order by batch_time </select> <select id="selectByCrossIdAndStartEnd" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"/> from t_cross_dir_data_hist where cross_id = #{crossId} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxDelayTime" resultType="java.lang.Integer"> select max(delay_time) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirType} and in_out_type = #{inOutType} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxQueueLength" resultType="java.lang.Double"> select max(queue_length) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirType} and in_out_type = #{inOutType} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxSaturation" resultType="java.lang.Double"> select max(sturation) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirType} and in_out_type = #{inOutType} and batch_time <![CDATA[ >= ]]> #{startStamp} and batch_time <![CDATA[ <= ]]> #{endStamp} </select> <select id="selectMaxGreenLightEfficiency" resultType="java.lang.Double"> select max(green_light_efficiency) from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type = #{dirCode} and in_out_type = #{code} and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} </select> <select id="selectByMetrics" resultType="net.wanji.databus.po.CrossDirDataHistPOExt"> SELECT <include refid="Base_Column_List"/> FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND in_out_type = 1 AND dir_type = #{dirInt} AND batch_time <![CDATA[ <= ]]> #{endTimeStamp} AND batch_time <![CDATA[ >= ]]> #{startTimeStamp} </select> <select id="selectByCrossIdsDirsAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"></include> from t_cross_dir_data_hist where cross_id in <foreach collection="crossIdList" item="crossId" separator="," open="(" close=")"> #{crossId} </foreach> and dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach><!-- and in_out_type = 1--> and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} order by batch_time </select> <select id="selectByCrossDirAndTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPO"> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND dir_type = #{dirCode} AND in_out_type = 1 AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%Y-%m-%d') BETWEEN #{boStartDayStr} AND #{boEndDayStr} AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%H:%i') BETWEEN #{startHourMinuteStr} AND #{endHourMinuteStr} </select> <select id="selectByCrossIdDirsAndTimestamp" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"></include> from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach> and in_out_type = 1 and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} order by batch_time </select> <!-- 神思推送数据in_out_type=0 --> <select id="selectDirDataList" resultType="net.wanji.databus.po.CrossDirDataHistPO"> select <include refid="Base_Column_List"></include> from t_cross_dir_data_hist where cross_id = #{crossId} and dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach> and batch_time <![CDATA[ >= ]]> #{startTimeStamp} and batch_time <![CDATA[ <= ]]> #{endTimeStamp} order by batch_time </select> <select id="selectByCrossDirsAndTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPO"> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE cross_id = #{crossId} AND dir_type in <foreach collection="dirCodeList" item="dirCode" separator="," open="(" close=")"> #{dirCode} </foreach> AND in_out_type = 1 AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%Y-%m-%d') BETWEEN #{boStartDayStr} AND #{boEndDayStr} AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%H:%i') BETWEEN #{startHourMinuteStr} AND #{endHourMinuteStr} </select> <select id="selectByTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPO"><!-- SELECT <include refid="Base_Column_List"></include>--><!-- FROM t_cross_dir_data_hist--><!-- WHERE in_out_type = 1--><!-- AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%Y-%m-%d') BETWEEN #{boStartDayStr} AND #{boEndDayStr}--><!-- AND DATE_FORMAT(FROM_UNIXTIME(batch_time), '%H:%i') BETWEEN #{startHourMinuteStr} AND #{endHourMinuteStr}--> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE batch_time BETWEEN UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boStartDayStr}, #{startHourMinuteStr}), '%Y-%m-%d%H:%i')) AND UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boEndDayStr}, #{endHourMinuteStr}), '%Y-%m-%d%H:%i')) AND in_out_type = 1 </select> <select id="selectExtByTimeSection" resultType="net.wanji.databus.po.CrossDirDataHistPOExt"> SELECT <include refid="Base_Column_List"></include> FROM t_cross_dir_data_hist WHERE batch_time BETWEEN UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boStartDayStr}, #{startHourMinuteStr}), '%Y-%m-%d%H:%i')) AND UNIX_TIMESTAMP(STR_TO_DATE(concat(#{boEndDayStr}, #{endHourMinuteStr}), '%Y-%m-%d%H:%i')) AND in_out_type = 1 </select> </mapper>
\ No newline at end of file \ No newline at end of file
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment