Commit 2e5b5215 authored by hanbing's avatar hanbing

[add] 态势监测-表格实时推送

parent e5adda23
package net.wanji.opt.bo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author Kent HAN
* @date 2023/6/9 13:52
*/
@Data
@ApiModel(value = "CrossIdAndIsFirstBO", description = "表格实时推送")
public class CrossIdAndIsFirstBO {
@ApiModelProperty(value = "路口ID")
private String crossId;
@ApiModelProperty(value = "是否初次调用 0否 1是")
private Integer isFirstInvoke;
}
...@@ -7,7 +7,6 @@ import io.swagger.annotations.ApiResponses; ...@@ -7,7 +7,6 @@ import io.swagger.annotations.ApiResponses;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.databus.bo.CrossIdBO; import net.wanji.databus.bo.CrossIdBO;
import net.wanji.opt.bo.*; import net.wanji.opt.bo.*;
import net.wanji.opt.dto.strategy.AddOrUpdateSceneDTO;
import net.wanji.opt.dto.trend.AbnormalCrossListDTO; import net.wanji.opt.dto.trend.AbnormalCrossListDTO;
import net.wanji.opt.dto.trend.EventAlarmDTO; import net.wanji.opt.dto.trend.EventAlarmDTO;
import net.wanji.opt.dto.trend.GreenwaveListDTO; import net.wanji.opt.dto.trend.GreenwaveListDTO;
...@@ -178,7 +177,7 @@ public class TrendController { ...@@ -178,7 +177,7 @@ public class TrendController {
@PostMapping(value = "/countRealTime", @PostMapping(value = "/countRealTime",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON) produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "OK", response = AddOrUpdateSceneDTO.class), @ApiResponse(code = 200, message = "OK", response = CountRealTimeVO.class),
}) })
public JsonViewObject countRealTime(@RequestBody CrossIdBO crossIdBO) { public JsonViewObject countRealTime(@RequestBody CrossIdBO crossIdBO) {
String crossId = crossIdBO.getCrossId(); String crossId = crossIdBO.getCrossId();
...@@ -197,4 +196,16 @@ public class TrendController { ...@@ -197,4 +196,16 @@ public class TrendController {
TableQueryVO tableQueryVO = trendService.tableQuery(crossIdAndTimeSpanBO); TableQueryVO tableQueryVO = trendService.tableQuery(crossIdAndTimeSpanBO);
return JsonViewObject.newInstance().success(tableQueryVO); return JsonViewObject.newInstance().success(tableQueryVO);
} }
@ApiOperation(value = "表格实时推送", notes = "表格实时推送",response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@PostMapping(value = "/tableRealTime",
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = TableQueryVO.class),
})
public JsonViewObject tableRealTime(@RequestBody CrossIdAndIsFirstBO crossIdAndIsFirstBO) {
TableQueryVO tableRealTimeVO = trendService.tableRealTime(crossIdAndIsFirstBO);
return JsonViewObject.newInstance().success(tableRealTimeVO);
}
} }
\ No newline at end of file
...@@ -41,4 +41,7 @@ public interface TrendService { ...@@ -41,4 +41,7 @@ public interface TrendService {
CountRealTimeVO countRealTime(String crossId); CountRealTimeVO countRealTime(String crossId);
TableQueryVO tableQuery(CrossIdAndTimeSpanBO crossIdAndTimeSpanBO); TableQueryVO tableQuery(CrossIdAndTimeSpanBO crossIdAndTimeSpanBO);
TableQueryVO tableRealTime(CrossIdAndIsFirstBO crossIdAndIsFirstBO);
} }
...@@ -39,6 +39,7 @@ import java.text.SimpleDateFormat; ...@@ -39,6 +39,7 @@ import java.text.SimpleDateFormat;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*; import java.util.*;
import java.util.function.Function; import java.util.function.Function;
import java.util.regex.Matcher; import java.util.regex.Matcher;
...@@ -93,6 +94,11 @@ public class TrendServiceImpl implements TrendService { ...@@ -93,6 +94,11 @@ public class TrendServiceImpl implements TrendService {
put(8, 1); put(8, 1);
}}; }};
// 表格实时推送开始时间
private Date tableRealTimeFirstDate;
// 表格周期推送开始时间
private Date tableCycleFirstDate;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public TrendServiceImpl(GreenwaveInfoMapper greenwaveInfoMapper, BaseCrossInfoMapper baseCrossInfoMapper, public TrendServiceImpl(GreenwaveInfoMapper greenwaveInfoMapper, BaseCrossInfoMapper baseCrossInfoMapper,
...@@ -1079,6 +1085,40 @@ public class TrendServiceImpl implements TrendService { ...@@ -1079,6 +1085,40 @@ public class TrendServiceImpl implements TrendService {
return tableQueryVO; return tableQueryVO;
} }
@Override
public TableQueryVO tableRealTime(CrossIdAndIsFirstBO crossIdAndIsFirstBO) {
String crossId = crossIdAndIsFirstBO.getCrossId();
Integer isFirstInvoke = crossIdAndIsFirstBO.getIsFirstInvoke();
// 如果是初次调用,需初始化开始时间
if (1 == isFirstInvoke) {
initFirstDate();
}
// 以当前时间为结束时间
Date endDate = new Date();
TableQueryVO tableQueryVO = new TableQueryVO();
// todo 查询秒级数据
// 查询周期数据
int startTimeStamp = (int) (tableCycleFirstDate.getTime() / 1000);
int endTimeStamp = (int) (endDate.getTime() / 1000);
List<CrossLaneDataHistPOExt> poExtList = crossLaneDataHistMapper
.selectByCrossIdAndTimeSpan(crossId, startTimeStamp, endTimeStamp);
tableQueryVO.setCycleData(buildCycleData(poExtList));
return tableQueryVO;
}
private void initFirstDate() {
tableRealTimeFirstDate = new Date();
// 将当前时间向前推10分钟
LocalDateTime now = LocalDateTime.now();
LocalDateTime tenMinutesAgo = now.minus(10, ChronoUnit.MINUTES);
Date resultDate = Date.from(tenMinutesAgo.atZone(ZoneId.systemDefault()).toInstant());
tableCycleFirstDate = resultDate;
}
private List<TableQueryVO.CycleDataElement> buildCycleData(List<CrossLaneDataHistPOExt> poExtList) { private List<TableQueryVO.CycleDataElement> buildCycleData(List<CrossLaneDataHistPOExt> poExtList) {
List<TableQueryVO.CycleDataElement> res = new ArrayList<>(); List<TableQueryVO.CycleDataElement> res = new ArrayList<>();
...@@ -1112,7 +1152,11 @@ public class TrendServiceImpl implements TrendService { ...@@ -1112,7 +1152,11 @@ public class TrendServiceImpl implements TrendService {
res.add(vo); res.add(vo);
} }
return res; List<TableQueryVO.CycleDataElement> sortedRes = res.stream()
.sorted(Comparator.comparing(TableQueryVO.CycleDataElement::getTime))
.collect(Collectors.toList());
return sortedRes;
} }
private MainlineSchemeAnalysisVO.GreenwaveData findMatchingData( private MainlineSchemeAnalysisVO.GreenwaveData findMatchingData(
......
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