Commit ffaaa9be authored by duanruiming's avatar duanruiming

[add] 优化绿波时序图历史查询;历史时间查询

parent ff25ca82
......@@ -38,11 +38,22 @@ public class StrategyGreenBeltController {
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = GreenBeltInfoVO.class),
})
public JsonViewObject greenBeltChart(Integer greenId) throws Exception {
GreenBeltChartVO greenBeltChartVO = strategyGreenBeltService.selectChart(greenId, null);
public JsonViewObject greenBeltChart(Integer greenId, String dateStr) throws Exception {
GreenBeltChartVO greenBeltChartVO = strategyGreenBeltService.selectChart(greenId, dateStr);
return JsonViewObject.newInstance().success(greenBeltChartVO);
}
@ApiOperation(value = "绿波时序图当天下发时间", notes = "绿波时序图当天下发时间", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@GetMapping(value = "/greenBeltChartControlTime")
@ApiResponses({
@ApiResponse(code = 200, message = "OK"),
})
public JsonViewObject greenBeltChartControlTime(Integer greenId) throws Exception {
List<String> dates = strategyGreenBeltService.greenBeltChartControlTime(greenId);
return JsonViewObject.newInstance().success(dates);
}
@ApiOperation(value = "绿波停车次数排队长度", notes = "绿波停车次数排队长度", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
......
......@@ -4,7 +4,6 @@ import net.wanji.opt.synthesis.pojo.vo.GreenBeltAreaIndexVO;
import net.wanji.opt.vo.GreenBeltChartVO;
import net.wanji.opt.vo.GreenBeltStopTimesQueueLengthVO;
import java.util.Date;
import java.util.List;
/**
......@@ -13,7 +12,8 @@ import java.util.List;
*/
public interface StrategyGreenBeltService {
GreenBeltChartVO selectChart(Integer greenId, Date queryDate);
GreenBeltChartVO selectChart(Integer greenId, String dateStr);
List<GreenBeltStopTimesQueueLengthVO> greenBeltStopTimeQueueLength(Integer greenId);
GreenBeltAreaIndexVO greenBeltAreaIndex(Integer greenId);
List<String> greenBeltChartControlTime(Integer greenId);
}
......@@ -2,12 +2,12 @@ package net.wanji.opt.synthesis.service.impl;
import com.alibaba.excel.util.DateUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.utils.tool.JacksonUtils;
import net.wanji.common.utils.tool.StringUtils;
import net.wanji.databus.dao.entity.GreenwaveHistPO;
import net.wanji.databus.dao.entity.GreenwaveRealtimePO;
import net.wanji.databus.dao.mapper.GreenwaveHistMapper;
......@@ -20,10 +20,16 @@ import net.wanji.opt.synthesis.service.StrategyGreenBeltService;
import net.wanji.opt.vo.GreenBeltChartVO;
import net.wanji.opt.vo.GreenBeltInfoVO;
import net.wanji.opt.vo.GreenBeltStopTimesQueueLengthVO;
import org.apache.logging.log4j.util.PropertySource;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.text.ParseException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
......@@ -42,6 +48,33 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService {
@Resource
GreenwaveRealtimeMapper greenwaveRealtimeMapper;
@Override
public List<String> greenBeltChartControlTime(Integer greenId) {
try {
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.MIDNIGHT;
LocalDateTime startOfDay = LocalDateTime.of(currentDate, startTime);
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.eq(StrategyGreenOptHistEntity::getControlMethod, 1);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, startOfDay);
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(entities)) {
Set<String> dateSet = entities.stream().map(StrategyGreenOptHistEntity::getControlTime).collect(Collectors.toSet());
List<String> dates = new ArrayList<>(dateSet.size());
for (String dateStr : dateSet) {
dates.add(dateStr.substring(11, 16));
}
Collections.sort(dates);
return dates;
}
} catch (Exception e) {
log.error("查询绿波时序图时间异常:", e);
throw new RuntimeException(e);
}
return Collections.emptyList();
}
@Override
public GreenBeltAreaIndexVO greenBeltAreaIndex(Integer greenId) {
LambdaQueryWrapper<GreenwaveRealtimePO> queryWrapper = new LambdaQueryWrapper<>();
......@@ -96,16 +129,31 @@ public class StrategyGreenBeltServiceImpl implements StrategyGreenBeltService {
@Override
public GreenBeltChartVO selectChart(Integer greenId, Date queryDate) {
public GreenBeltChartVO selectChart(Integer greenId, String dateStr) {
try {
if (Objects.isNull(queryDate)) {
queryDate = new Date();
}
ObjectMapper mapper = JacksonUtils.getInstance();
QueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("green_id", greenId);
queryWrapper.orderByDesc("control_time");
queryWrapper.last("LIMIT 2");
LambdaQueryWrapper<StrategyGreenOptHistEntity> queryWrapper = new LambdaQueryWrapper<>();
// 查询历史时序图
if (StringUtils.isNotBlank(dateStr)) {
LocalTime time = LocalTime.parse(dateStr);
LocalDate currentDate = LocalDate.now();
LocalDateTime dateTime = LocalDateTime.of(currentDate, time);
// 格式化输出为指定格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String formattedDateTime = dateTime.format(formatter);
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.eq(StrategyGreenOptHistEntity::getControlMethod, 1);
queryWrapper.ge(StrategyGreenOptHistEntity::getControlTime, dateTime);
queryWrapper.orderByAsc(StrategyGreenOptHistEntity::getControlTime);
queryWrapper.last("limit 2");
} else {
queryWrapper.eq(StrategyGreenOptHistEntity::getGreenId, greenId);
queryWrapper.eq(StrategyGreenOptHistEntity::getControlMethod, 1);
queryWrapper.orderByDesc(StrategyGreenOptHistEntity::getControlTime);
//queryWrapper.last("LIMIT 2");
queryWrapper.last("limit 2");
}
List<StrategyGreenOptHistEntity> entities = strategyGreenOptHistMapper.selectList(queryWrapper);
if (!CollectionUtils.isEmpty(entities)) {
Map<String, List<StrategyGreenOptHistEntity>> controlTimeMap = entities.stream().collect(Collectors.groupingBy(StrategyGreenOptHistEntity::getControlTime));
......
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