Commit 6d1592b4 authored by fengyasheng's avatar fengyasheng

事件优化记录查询

告警优化路口事件数按事件类型/持续时间分布情况x时间轴优化
parent 4614181c
...@@ -282,9 +282,12 @@ public class EsDateIndexUtil { ...@@ -282,9 +282,12 @@ public class EsDateIndexUtil {
} }
public static void main(String[] args) { public static void main(String[] args) {
DateTime start = DateTime.now().withTimeAtStartOfDay(); // DateTime start = DateTime.now().withTimeAtStartOfDay();
DateTime end = DateTime.now(); // DateTime end = DateTime.now();
List<String> indexByTime = EsDateIndexUtil.getTimeScopeList(start, end, TimeGranularityEnum.ONE_HOUR,"HH:mm"); // List<String> indexByTime = EsDateIndexUtil.getTimeScopeList(start, end, TimeGranularityEnum.ONE_HOUR,"HH:mm");
String start = "2025-03-21 00:00:00";
String end = "2025-03-21 23:00:00";
List<String> indexByTime = EsDateIndexUtil.getTimeGranularityAxisAll("1",start, end);
System.out.println(indexByTime); System.out.println(indexByTime);
......
...@@ -9,6 +9,7 @@ import net.wanji.common.framework.i18n.I18nResourceBundle; ...@@ -9,6 +9,7 @@ import net.wanji.common.framework.i18n.I18nResourceBundle;
import net.wanji.common.framework.rest.JsonViewObject; import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.controllerv2.judgeanalysis.design.response.crossproblem.CrossProblemDistributeAnalysisResult; import net.wanji.opt.controllerv2.judgeanalysis.design.response.crossproblem.CrossProblemDistributeAnalysisResult;
import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo; import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo;
import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfoVO;
import net.wanji.opt.servicev2.eventoptimize.TEventOptimizeInfoService; import net.wanji.opt.servicev2.eventoptimize.TEventOptimizeInfoService;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
...@@ -28,6 +29,36 @@ public class TEventOptimizeInfoController { ...@@ -28,6 +29,36 @@ public class TEventOptimizeInfoController {
private TEventOptimizeInfoService tEventOptimizeInfoService; private TEventOptimizeInfoService tEventOptimizeInfoService;
// 新增接口用于调用带有条件的分页查询 // 新增接口用于调用带有条件的分页查询
@ApiOperation(value = "报警优化信息-事件优化记录查询-根据条件分页查询记录", notes = "根据条件分页查询记录", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,hidden = false)
@ApiImplicitParams({
@ApiImplicitParam(name = "currentPage", value = "页数", required = true, dataType = "int",defaultValue = "1",example = "1"),
@ApiImplicitParam(name = "pageSize", value = "每页条数", required = true, dataType = "int",defaultValue = "10"),
@ApiImplicitParam(name = "startTime", value = "开始时间,格式:yyyy-MM-dd HH:mm:ss", required = true, dataType = "String",defaultValue = "2025-03-21 00:00:00"),
@ApiImplicitParam(name = "endTime", value = "结束时间,格式:yyyy-MM-dd HH:mm:ss", required = true, dataType = "String",defaultValue = "2025-03-21 23:00:00"),
@ApiImplicitParam(name = "crossId", value = "路口id", required = true, dataType = "String",defaultValue = "",example = "13NAF0B5PH0"),
@ApiImplicitParam(name = "greenId", value = "干线id", required = true, dataType = "int",defaultValue = "",example = "4"),
})
@GetMapping("/selectPageWithCrossIdAndGreenId")
public JsonViewObject selectPageWithCrossIdAndGreenId(
@RequestParam int currentPage,
@RequestParam int pageSize,
@RequestParam(required = false) String startTime,
@RequestParam(required = false) String endTime,
@RequestParam(required = false) int greenId,
@RequestParam(required = false) String crossId) {
JsonViewObject jsonView = JsonViewObject.newInstance();
try {
Page<TEventOptimizeInfoVO> retData = tEventOptimizeInfoService.selectPageWithCrossIdAndGreenId(currentPage, pageSize, startTime, endTime, crossId,greenId);
jsonView.success(retData);
} catch (Exception e) {
jsonView.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG"));
log.error("{} getAll error", this.getClass().getSimpleName(), e);
}
return jsonView;
}
@ApiOperation(value = "报警优化信息-根据条件分页查询记录", notes = "根据条件分页查询记录", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,hidden = false) @ApiOperation(value = "报警优化信息-根据条件分页查询记录", notes = "根据条件分页查询记录", produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,hidden = false)
@ApiImplicitParams({ @ApiImplicitParams({
@ApiImplicitParam(name = "currentPage", value = "页数", required = true, dataType = "int",defaultValue = "1",example = "1"), @ApiImplicitParam(name = "currentPage", value = "页数", required = true, dataType = "int",defaultValue = "1",example = "1"),
......
...@@ -37,6 +37,9 @@ class CrossProblemDistributeResponse { ...@@ -37,6 +37,9 @@ class CrossProblemDistributeResponse {
@ApiModelProperty(value = "时段列表(小时/分钟)粒度格式:HH:mm",example = "[\"00:15\",\"00:30\"]",dataType = "String[]") @ApiModelProperty(value = "时段列表(小时/分钟)粒度格式:HH:mm",example = "[\"00:15\",\"00:30\"]",dataType = "String[]")
private List<String> timeList = new ArrayList<>(); private List<String> timeList = new ArrayList<>();
@ApiModelProperty(value = "时段列表(年-月-日 小时:分钟:秒)粒度格式:yyyy-MM-dd HH:mm:ss",example = "[\"2025-03-21 00:15:00\",\"2025-03-21 00:30:00\"]",dataType = "String[]")
private List<String> timeListAll = new ArrayList<>();
// @ApiModelProperty(value = "各路口时段流量列表", // @ApiModelProperty(value = "各路口时段流量列表",
// example = "[{\"name\":\"路口1\",\"list\":[150,300]}," + // example = "[{\"name\":\"路口1\",\"list\":[150,300]}," +
// "{\"name\":\"路口2\",\"list\":[150,300]}]") // "{\"name\":\"路口2\",\"list\":[150,300]}]")
......
...@@ -16,6 +16,13 @@ public interface TEventOptimizeInfoMapper extends BaseMapper<TEventOptimizeInfo> ...@@ -16,6 +16,13 @@ public interface TEventOptimizeInfoMapper extends BaseMapper<TEventOptimizeInfo>
@Param("startTime") String startTime, @Param("startTime") String startTime,
@Param("endTime") String endTime, @Param("endTime") String endTime,
@Param("crossId") String crossId); @Param("crossId") String crossId);
Page<TEventOptimizeInfo> selectPageWithCrossIdAndGreenId(@Param("page") Page<TEventOptimizeInfo> page,
@Param("startTime") String startTime,
@Param("endTime") String endTime,
@Param("crossId") String crossId,
@Param("greenId") int greenId);
List<Map<String,String>> getCrossOptimizeDistribute(@Param("groupType") Integer groupType, List<Map<String,String>> getCrossOptimizeDistribute(@Param("groupType") Integer groupType,
@Param("startTime") String startTime, @Param("startTime") String startTime,
@Param("endTime") String endTime, @Param("endTime") String endTime,
......
package net.wanji.opt.entity.eventoptimize;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@Data
public class TEventOptimizeInfoVO {
@ApiModelProperty(value = "路口ID")
private String crossId;
@ApiModelProperty(value = "二级类别")
private String eventType;
@TableField("opt_status")
@ApiModelProperty(value = "优化状态 0 未优化 1-优化过 根据上面告警状态如果有2 3状态认为优化过")
private Integer optStatus;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "事件优化开始时间")
private Date optStartTime;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
@ApiModelProperty(value = "事件优化结束时间")
private Date optEndTime;
@ApiModelProperty(value = "优化时长,单位秒")
private Integer optDuration;
@TableField("green_id")
@ApiModelProperty(value = "干线ID")
private Integer greenId;
}
\ No newline at end of file
...@@ -5,11 +5,14 @@ import com.alibaba.fastjson.JSONObject; ...@@ -5,11 +5,14 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo; import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo;
import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfoVO;
public interface TEventOptimizeInfoService extends IService<TEventOptimizeInfo> { public interface TEventOptimizeInfoService extends IService<TEventOptimizeInfo> {
Page<TEventOptimizeInfo> queryPageWithConditions(int currentPage, int pageSize, String startTime, String endTime, String crossId); Page<TEventOptimizeInfo> queryPageWithConditions(int currentPage, int pageSize, String startTime, String endTime, String crossId);
Page<TEventOptimizeInfoVO> selectPageWithCrossIdAndGreenId(int currentPage, int pageSize, String startTime, String endTime, String crossId, int greenId);
JSONObject getCrossOptimizeDistribute(String crossId, String startTime, String endTime, Integer groupType); JSONObject getCrossOptimizeDistribute(String crossId, String startTime, String endTime, Integer groupType);
Page<TEventOptimizeInfo> pageWithLineConditions(int currentPage, int pageSize, String startTime, String endTime, Integer greenId); Page<TEventOptimizeInfo> pageWithLineConditions(int currentPage, int pageSize, String startTime, String endTime, Integer greenId);
......
...@@ -4,10 +4,14 @@ import com.alibaba.fastjson.JSONObject; ...@@ -4,10 +4,14 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.wanji.databus.po.EventOptimizeCountPo; import net.wanji.databus.po.EventOptimizeCountPo;
import net.wanji.opt.controllerv2.judgeanalysis.design.response.crossproblem.CrossProblemDistributeAnalysisResult; import net.wanji.opt.common.EsDateIndexUtil;
import net.wanji.opt.dao.mapper.eventoptimize.TEventOptimizeInfoMapper; import net.wanji.opt.dao.mapper.eventoptimize.TEventOptimizeInfoMapper;
import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo; import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo;
import net.wanji.opt.entity.eventoptimize.TEventOptimizeInfoVO;
import net.wanji.opt.servicev2.eventoptimize.TEventOptimizeInfoService; import net.wanji.opt.servicev2.eventoptimize.TEventOptimizeInfoService;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
...@@ -28,16 +32,32 @@ public class TEventOptimizeInfoServiceImpl extends ServiceImpl<TEventOptimizeInf ...@@ -28,16 +32,32 @@ public class TEventOptimizeInfoServiceImpl extends ServiceImpl<TEventOptimizeInf
return baseMapper.selectPageWithConditions(page, startTime, endTime, crossId); return baseMapper.selectPageWithConditions(page, startTime, endTime, crossId);
} }
@Override
public Page<TEventOptimizeInfoVO> selectPageWithCrossIdAndGreenId(int currentPage, int pageSize, String startTime, String endTime, String crossId, int greenId) {
Page<TEventOptimizeInfo> page = new Page<>(currentPage, pageSize);
Page<TEventOptimizeInfo> tEventOptimizeInfoPage = baseMapper.selectPageWithCrossIdAndGreenId(page, startTime, endTime, crossId, greenId);
List<TEventOptimizeInfoVO> collect = tEventOptimizeInfoPage.getRecords().stream().map(x -> {
TEventOptimizeInfoVO tEventOptimizeInfoVO = new TEventOptimizeInfoVO();
BeanUtils.copyProperties(x, tEventOptimizeInfoVO);
return tEventOptimizeInfoVO;
}).collect(Collectors.toList());
Page<TEventOptimizeInfoVO> pageVO = new Page<>(currentPage, pageSize);
pageVO.setTotal(page.getTotal());
pageVO.setRecords(collect);
return pageVO;
}
@Override @Override
public JSONObject getCrossOptimizeDistribute(String crossId, String startTime, String endTime, Integer groupType) { public JSONObject getCrossOptimizeDistribute(String crossId, String startTime, String endTime, Integer groupType) {
List<Map<String, String>> crossOptimizeDistribute = tEventOptimizeInfoMapper.getCrossOptimizeDistribute(groupType, startTime, endTime, crossId); List<Map<String, String>> crossOptimizeDistribute = tEventOptimizeInfoMapper.getCrossOptimizeDistribute(groupType, startTime, endTime, crossId);
List<String> timeLabelList = crossOptimizeDistribute.stream().map(x -> { // List<String> timeLabelList = crossOptimizeDistribute.stream().map(x -> {
return x.get("time_label"); // return x.get("time_label");
}) // })
.distinct() // .distinct()
.sorted() // .sorted()
.collect(Collectors.toList()); // .collect(Collectors.toList());
List<EventOptimizeCountPo> optimizeCountPoList = new ArrayList<>(); List<String> sortedSet = EsDateIndexUtil.getTimeGranularityAxisAll(String.valueOf(groupType), startTime, endTime);
// 按事件类型分组 // 按事件类型分组
Map<String, EventOptimizeCountPo> eventTypeMap = new HashMap<>(); Map<String, EventOptimizeCountPo> eventTypeMap = new HashMap<>();
for (Map<String, String> data : crossOptimizeDistribute) { for (Map<String, String> data : crossOptimizeDistribute) {
...@@ -46,27 +66,46 @@ public class TEventOptimizeInfoServiceImpl extends ServiceImpl<TEventOptimizeInf ...@@ -46,27 +66,46 @@ public class TEventOptimizeInfoServiceImpl extends ServiceImpl<TEventOptimizeInf
EventOptimizeCountPo item = new EventOptimizeCountPo(); EventOptimizeCountPo item = new EventOptimizeCountPo();
item.setEventLabel(getEventLabel(eventType)); // 设置事件名称 item.setEventLabel(getEventLabel(eventType)); // 设置事件名称
item.setEventType(eventType); item.setEventType(eventType);
item.setNoOptimizeNumberList(new ArrayList<>(Collections.nCopies(timeLabelList.size(), 0))); item.setNoOptimizeNumberList(new ArrayList<>(Collections.nCopies(sortedSet.size(), 0)));
item.setTotalNumberList(new ArrayList<>(Collections.nCopies(timeLabelList.size(), 0))); item.setTotalNumberList(new ArrayList<>(Collections.nCopies(sortedSet.size(), 0)));
return item; return item;
}); });
// 更新对应时间的统计数据 // 更新对应时间的统计数据
int timeIndex = timeLabelList.indexOf(data.get("time_label")); int timeIndex = sortedSet.indexOf(data.get("time_label"));
String totalCount = String.valueOf(data.get("total_count")) ; String totalCount = String.valueOf(data.get("total_count")) ;
String unoptimizedCount = String.valueOf(data.get("unoptimized_count")) ; String unoptimizedCount = String.valueOf(data.get("unoptimized_count")) ;
optimizeCountPo.getTotalNumberList().set(timeIndex, Integer.valueOf(totalCount)); optimizeCountPo.getTotalNumberList().set(timeIndex, Integer.valueOf(totalCount));
optimizeCountPo.getNoOptimizeNumberList().set(timeIndex, Integer.valueOf(unoptimizedCount)); optimizeCountPo.getNoOptimizeNumberList().set(timeIndex, Integer.valueOf(unoptimizedCount));
optimizeCountPoList.add(optimizeCountPo);
} }
ArrayList<String> timeLabelList = new ArrayList<>(Collections.nCopies(sortedSet.size(), ""));
sortedSet.forEach(x->{
String timeFormat = getTimeFormat(groupType,x);
int index = sortedSet.indexOf(x);
timeLabelList.set(index,timeFormat);
});
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("timeList", timeLabelList); jsonObject.put("timeList", timeLabelList);
jsonObject.put("timeListAll", sortedSet);
jsonObject.put("dataList", eventTypeMap.values()); jsonObject.put("dataList", eventTypeMap.values());
return jsonObject; return jsonObject;
} }
private String getTimeFormat(Integer groupType, String time) {
DateTime dateTime = DateTime.parse(time, DateTimeFormat.forPattern(EsDateIndexUtil.YMD_HM_FORMATTER));
String format = "";
if(!ObjectUtils.isEmpty(groupType) && groupType == 4 ){
format = dateTime.toString("yyyy-MM-dd");
}else {
format = dateTime.toString("HH:mm");
}
return format;
}
// 获取事件名称(可以根据实际需求扩展) // 获取事件名称(可以根据实际需求扩展)
private String getEventLabel(String eventType) { private String getEventLabel(String eventType) {
String eventLabel = tEventOptimizeInfoMapper.getEventLabel(eventType); String eventLabel = tEventOptimizeInfoMapper.getEventLabel(eventType);
......
...@@ -9,12 +9,21 @@ ...@@ -9,12 +9,21 @@
AND (#{endTime} IS NULL OR happen_end_time &lt;= #{endTime}) AND (#{endTime} IS NULL OR happen_end_time &lt;= #{endTime})
AND (#{crossId} IS NULL OR cross_id = #{crossId}) AND (#{crossId} IS NULL OR cross_id = #{crossId})
</select> </select>
<select id="selectPageWithCrossIdAndGreenId" parameterType="map" resultType="net.wanji.opt.entity.eventoptimize.TEventOptimizeInfo">
SELECT *
FROM t_event_optimize_info
WHERE (#{startTime} IS NULL OR happen_start_time >= #{startTime})
AND (#{endTime} IS NULL OR happen_end_time &lt;= #{endTime})
AND (#{crossId} IS NULL OR cross_id = #{crossId})
AND (#{greenId} IS NULL OR green_id = #{greenId})
AND opt_status != 0
</select>
<select id="getCrossOptimizeDistribute" parameterType="map" resultType="java.util.Map"> <select id="getCrossOptimizeDistribute" parameterType="map" resultType="java.util.Map">
SELECT SELECT
(CASE (CASE
WHEN #{groupType} = 4 THEN DATE_FORMAT(unit_time, '%Y-%m-%d') -- 按天粒度格式化为 yyyy-MM-dd WHEN #{groupType} = 4 THEN DATE_FORMAT(unit_time, '%Y-%m-%d') -- 按天粒度格式化为 yyyy-MM-dd
ELSE DATE_FORMAT(unit_time, '%H:%i') -- 其他粒度格式化为 HH:mm ELSE unit_time -- 其他粒度格式化为 HH:mm
END) AS time_label, END) AS time_label,
event_type, event_type,
SUM(total_count) AS total_count, SUM(total_count) AS total_count,
......
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