Commit 80cc4f8d authored by duanruiming's avatar duanruiming

[add] 优化绿波数据插入逻辑sql

parent 2ca7a1cc
......@@ -200,8 +200,9 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay);
queryWrapper.ne(StrategyGreenOptHistEntity::getControlMethod, -1);
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(greenwaveHistPOS) && !CollectionUtils.isEmpty(entities)) {
if (!CollectionUtils.isEmpty(greenwaveHistPOS)) {
for (GreenwaveHistPO histPO : greenwaveHistPOS) {
Integer curGreenId = histPO.getGreenId();
Date curStartTime = histPO.getStartTime();
......@@ -209,22 +210,37 @@ public class GreenBeltServiceImpl implements GreenBeltInfoService {
Date startTimeminuteDate = get5MinuteDate(curStartTimeStr);
String roadDirection = histPO.getRoadDirection();
Double speed = histPO.getSpeed();
for (StrategyGreenOptHistEntity entity : entities) {
Integer optGreenId = entity.getGreenId();
String controlTime = entity.getControlTime();
String dir = entity.getDir();
Date minuteDate = get5MinuteDate(controlTime);
Double greenWidthTime = entity.getGreenWidthTime();
if (Objects.equals(curGreenId, optGreenId) && StringUtils.equalsIgnoreCase(dir, roadDirection)
&& minuteDate.getTime() == startTimeminuteDate.getTime()) {
GreenBeltSpeedWidthVO vo = new GreenBeltSpeedWidthVO();
vo.setStartTime(curStartTime);
vo.setSpeed(speed);
vo.setWidth(greenWidthTime);
vo.setDirName(GreenBeltDirEnum.getDesc(dir));
results.add(vo);
if (CollectionUtils.isEmpty(entities)) {
GreenBeltSpeedWidthVO vo = new GreenBeltSpeedWidthVO();
vo.setStartTime(curStartTime);
vo.setSpeed(speed);
vo.setWidth(0.0);
vo.setDirName(GreenBeltDirEnum.getDesc(roadDirection));
results.add(vo);
} else {
for (StrategyGreenOptHistEntity entity : entities) {
Integer optGreenId = entity.getGreenId();
String controlTime = entity.getControlTime();
String dir = entity.getDir();
Date minuteDate = get5MinuteDate(controlTime);
Double greenWidthTime = entity.getGreenWidthTime();
if (Objects.equals(curGreenId, optGreenId) && StringUtils.equalsIgnoreCase(dir, roadDirection)
&& minuteDate.getTime() == startTimeminuteDate.getTime()) {
GreenBeltSpeedWidthVO vo = new GreenBeltSpeedWidthVO();
vo.setStartTime(curStartTime);
vo.setSpeed(speed);
vo.setWidth(greenWidthTime);
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);
}
}
}
}
}
......
......@@ -88,10 +88,13 @@
<insert id="insertBatch" parameterType="net.wanji.databus.dao.entity.GreenwaveHistPO">
insert into t_greenwave_hist
(<include refid="Base_Column_List"/>)
(green_id, status,type,traffic_index,speed,trval_time,stop_times,queue_length,cong_rate,delay_time,nopark_pass_rate,
cord_reliability,cord_queue_ratio,uncoordinate_phase_queue, start_time, gmt_create,gmt_modified,
strategy, strategy_duration, optimize_count, optimize_seconds,
green_wave_width, direction, plan_cycle, speed_high, speed_down, road_direction, sturation, batch_time)
values
<foreach collection="list" item="entity" separator=",">
(#{entity.id}, #{entity.greenId}, #{entity.status}, #{entity.type}, #{entity.trafficIndex},#{entity.speed},
(#{entity.greenId}, #{entity.status}, #{entity.type}, #{entity.trafficIndex},#{entity.speed},
#{entity.trvalTime}, #{entity.stopTimes}, #{entity.queueLength}, #{entity.congRate},
#{entity.delayTime}, #{entity.noparkPassRate}, #{entity.cordReliability}, #{entity.cordQueueRatio},
#{entity.uncoordinatePhaseQueue}, #{entity.startTime}, #{entity.gmtCreate}, #{entity.gmtModified},
......@@ -100,6 +103,8 @@
#{entity.speedDown}, #{entity.roadDirection}, #{entity.sturation}, #{entity.batchTime}
)
</foreach>
ON DUPLICATE KEY UPDATE
gmt_modified = values(gmt_modified)
</insert>
</mapper>
......@@ -54,10 +54,13 @@
<insert id="insertBatch" parameterType="net.wanji.databus.dao.entity.GreenwaveRealtimePO">
insert into t_greenwave_realtime
(<include refid="Base_Column_List"></include>)
(green_id, status,type,traffic_index,speed,trval_time,stop_times,queue_length,cong_rate,delay_time,nopark_pass_rate,
cord_reliability, cord_queue_ratio, uncoordinate_phase_queue, start_time, gmt_create,gmt_modified,
strategy, strategy_duration, optimize_count, optimize_seconds,
green_wave_width, direction, plan_cycle, speed_high, speed_down, road_direction, sturation, batch_time)
values
<foreach collection="list" item="entity" separator=",">
(#{entity.id}, #{entity.greenId}, #{entity.status}, #{entity.type}, #{entity.trafficIndex}, #{entity.speed},
(#{entity.greenId}, #{entity.status}, #{entity.type}, #{entity.trafficIndex}, #{entity.speed},
#{entity.trvalTime}, #{entity.stopTimes}, #{entity.queueLength}, #{entity.congRate},
#{entity.delayTime}, #{entity.noparkPassRate}, #{entity.cordReliability}, #{entity.cordQueueRatio},
#{entity.uncoordinatePhaseQueue}, #{entity.startTime}, #{entity.gmtCreate}, #{entity.gmtModified},
......
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