Commit f7baaa67 authored by zhoushiguang's avatar zhoushiguang

事件场景评价接口

parent acb62a59
package net.wanji.opt.controller;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.ResponseHeader;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.common.framework.rest.JsonViewObject;
import net.wanji.opt.dto.CrossIdAndMinutesDTO;
import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.service.EvaluateService;
import net.wanji.opt.service.EventService;
import net.wanji.opt.vo.EvaluateCrossDetailVO;
import net.wanji.opt.vo.EvaluateMetricsVO;
import net.wanji.opt.vo.GreenWaveRunStateVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;
import java.util.List;
import java.util.Map;
@RestController
@Slf4j
@RequestMapping("/event")
@Api(value="EventController", description="事件相关", tags = "事件相关")
public class EventController {
@Resource
EventService eventService;
@GetMapping("/count")
@ApiOperation(httpMethod="GET",value="事件总次数统计", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "Integer",defaultValue = "13N8J0B5P10"),
@ApiImplicitParam(name = "eventType", value = "事件类型 701:空放 702:失衡 703:溢出", required = false, dataType = "String",defaultValue = "701"),
@ApiImplicitParam(name = "startTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2025-01-05 00:00:00"),
@ApiImplicitParam(name = "endTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2025-01-05 23:59:59"),
})
@ApiResponses({
@ApiResponse(code = 200, message = "成功", response = EventStatisticPo.class,
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
})
public JsonViewObject evaluateCrossDetail(String crossId,String eventType,String startTime,String endTime) {
EventStatisticPo result = null;
try {
result = eventService.findCrossEventCount(crossId,eventType,startTime,endTime );
return JsonViewObject.newInstance().success(result);
} catch (DubboProviderException e) {
e.printStackTrace();
return JsonViewObject.newInstance().fail(e);
}
}
@GetMapping("/distribute")
@ApiOperation(httpMethod="GET",value="空放、失衡、溢出事件分布情况", notes="")
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "Integer",defaultValue = "13N8J0B5P10"),
// @ApiImplicitParam(name = "eventType", value = "事件类型 701:空放 702:失衡 703:溢出", required = false, dataType = "String",defaultValue = "701"),
@ApiImplicitParam(name = "startTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2025-01-05 00:00:00"),
@ApiImplicitParam(name = "endTime", value = "截止时间,格式:yyyy-MM-dd HH:mm:ss", required = false, dataType = "String",defaultValue = "2025-01-05 23:59:59"),
})
@ApiResponses({
@ApiResponse(code = 200, message = "成功", response = EventStatisticPo.class,
responseHeaders = {@ResponseHeader(name = "Content-Type", description = "application/json")})
})
public JsonViewObject distribute(String crossId,String startTime,String endTime) {
try {
List<Map<String,Object>> result = eventService.findEventDistribute(crossId,startTime,endTime );
return JsonViewObject.newInstance().success(result);
} catch (DubboProviderException e) {
e.printStackTrace();
return JsonViewObject.newInstance().fail(e);
}
}
}
\ No newline at end of file
......@@ -2,11 +2,14 @@ package net.wanji.opt.dao.mapper;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.po.trend.EventInfoSimplePo;
import net.wanji.opt.po.trend.HoloEventInfoPO;
import org.springframework.stereotype.Repository;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author duanruiming
......@@ -19,5 +22,10 @@ public interface HoloEventMapper extends BaseMapper<HoloEventInfoPO> {
Integer selectEmergencyCountWithLaneIds(String crossId, int startStamp, int endStamp, List<String> laneIds);
List<HoloEventInfoPO> selectAIList(Date startTime);
List<HoloEventInfoPO> selectAIGreenList(Date startTime);
EventStatisticPo findCrossEventCount(Map<String,Object> params);
List<EventInfoSimplePo> findEventDistribute(Map<String,Object> params);
}
package net.wanji.opt.dao.mapper.base;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import net.wanji.common.framework.mapper.BaseInterfaceMapper;
import net.wanji.opt.po.base.BaseRidInfo;
/**
* <p>
* 路段基础信息
* </p>
*
* @Author fengyi
* @Date 2024-11-14
*/
public interface BaseRidInfoMapper extends BaseMapper<BaseRidInfo> {
}
package net.wanji.opt.po.base;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
/**
* <p>
* 路段基础信息
* </p>
*
* @Author fengyi
* @Date 2024-11-14
*/
@Data
@ApiModel(value="BaseRidInfo对象", description="路段基础信息")
@TableName("t_base_rid_info")
public class BaseRidInfo {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "路段名称")
private String name;
@ApiModelProperty(value = "道路编号")
private String roadId;
@ApiModelProperty(value = "道路名称")
private String roadName;
@ApiModelProperty(value = "道路方向编号")
private String roadDirId;
@ApiModelProperty(value = "开始路口编号")
private String startCrossId;
@ApiModelProperty(value = "结束路口编号")
private String endCrossId;
@ApiModelProperty(value = "驶出方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer outDir;
@ApiModelProperty(value = "驶入方向:1北;2东北;3东;4东南;5南;6西南;7西;8西北")
private Integer inDir;
@ApiModelProperty(value = "驶出角度,正北顺时针0~359")
private Double startAngle;
@ApiModelProperty(value = "驶入角度,正北顺时针0~359")
private Double endAngle;
@ApiModelProperty(value = "行驶方向:0上行;1下行")
private Integer direction;
@ApiModelProperty(value = "顺序号:路段在道路方向的顺序号")
private Integer sort;
@ApiModelProperty(value = "路段走向:1 南向北;2 西向东;3 北向南;4 东向西;5 内环;6 外环;99 其他(参见路段走向字典)")
private Integer trend;
@ApiModelProperty(value = "道路等级: 41000 高速公路; 42000 国道; 43000 城市快速路; 44000 城市主干道; 45000 城市次干道; 47000 城市普通道路; 51000 省道; 52000 县道; 53000 乡道; 54000 县乡村内部道路; 49 小路(参见道路等级字典)")
private Integer level;
@ApiModelProperty(value = "行政区划代码,跨区数据会以逗号分开")
private String areaCode;
@ApiModelProperty(value = "路段长度(米)")
private Double length;
@ApiModelProperty(value = "路段宽度(米)")
private Double width;
@ApiModelProperty(value = "是否单行线:0否;1是;99其他")
private Integer isOneway;
@ApiModelProperty(value = "路段类型:1路段;3匝道;4隧道;5桥梁;6高架;99其他")
private Integer type;
@ApiModelProperty(value = "主辅标志:1主路;2辅路;99其他 (参见主辅标志字典)")
private Integer mainFlag;
@ApiModelProperty(value = "空间对象")
private String wkt;
@ApiModelProperty(value = "信控路段编号")
private String scId;
@ApiModelProperty(value = "信控路段名称")
private String scName;
@ApiModelProperty(value = "信控路段序号")
private Integer scSort;
@ApiModelProperty(value = "创建时间")
private Date gmtCreate;
@ApiModelProperty(value = "修改时间")
private Date gmtModified;
}
package net.wanji.opt.po.base;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.models.auth.In;
import lombok.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @author fengyi
* @date 2024/12/24
* @description
*/
@Data
public class EventStatisticPo {
@ApiModelProperty(name = "路口编号",notes = "")
private String crossId;
@ApiModelProperty(value = "事件类型", notes = "")
private String eventType;
@ApiModelProperty(value = "事件类型描述", notes = "")
private String eventTypeDesc;
@ApiModelProperty(value = "事件次数", notes = "")
private Integer eventCount;
@ApiModelProperty(value = "时间轴", notes = "")
private String timeAxis;
@ApiModelProperty(value = "事件方向集合", notes = "",hidden = true)
private String dirs;
@ApiModelProperty(value = "每个方向发生的次数", notes = "")
private Map<String,Long> dirEventCount;
@ApiModelProperty(value = "进口道方向",notes = "")
private Map<String,String> dirWkt;
}
package net.wanji.opt.po.trend;
import com.alibaba.fastjson.annotation.JSONField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import net.wanji.common.framework.Constants;
import net.wanji.common.utils.tool.DateUtil;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
/**
* @author duanruiming
* @date 2024/05/17 9:45
*/
@Data
@EqualsAndHashCode(callSuper = false)
@TableName("t_event_info")
@ApiModel(value = "HoloEventInfoPO", description = "交通事件信息")
public class EventInfoSimplePo implements Serializable {
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "二级类别")
@JsonProperty("eventType")
//@JSONField(name = "eventType")
private String eventType;
@ApiModelProperty(value = "事件发生时间")
@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date startTime;
@ApiModelProperty(value = "事件结束时间")
//@JSONField(format = "yyyy-MM-dd HH:mm:ss")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
@ApiModelProperty(value = "事件持续时长,单位秒")
private Integer duration;
@ApiModelProperty(value = "横轴时间轴", notes = "")
private String timeAxis;
@ApiModelProperty(value = "纵轴日期 格式:(dd/MM)", notes = "")
private String date;
}
\ No newline at end of file
......@@ -73,7 +73,7 @@ public class HoloEventInfoPO implements Serializable {
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private Date endTime;
@ApiModelProperty(value = "事件持续时长,单位分钟")
@ApiModelProperty(value = "事件持续时长,单位")
private Integer duration;
@ApiModelProperty(value = "事件来源", notes = "1-系统检测;2-接处警;3-互联网;4-交管部门;5-济南城市大脑;")
......@@ -106,4 +106,8 @@ public class HoloEventInfoPO implements Serializable {
private String extend;
@ApiModelProperty(value = "拓展字段")
private Integer alarmStatus;
@ApiModelProperty(value = "时间轴", notes = "")
private String timeAxis;
}
\ No newline at end of file
package net.wanji.opt.service;
import com.alibaba.fastjson.JSONObject;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.vo.GreenwaveListVO;
import net.wanji.opt.bo.CrossIdAndIsFirstBO;
import net.wanji.opt.bo.CrossIdAndTimeSpanBO;
import net.wanji.opt.bo.GreenwaveDetailBO;
import net.wanji.opt.bo.GreenwaveIdAndTimeStampBO;
import net.wanji.opt.bo.GreenwaveIdBO;
import net.wanji.opt.bo.SaveGreenwaveStrategyBO;
import net.wanji.opt.dto.trend.AbnormalCrossListDTO;
import net.wanji.opt.dto.trend.GreenwaveListDTO;
import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.po.trend.AnalysisRidTurnIndicators;
import net.wanji.opt.po.trend.HoloEventInfoPO;
import net.wanji.opt.vo.AbnormalCrossDetailVO;
import net.wanji.opt.vo.AbnormalCrossVO;
import net.wanji.opt.vo.CommonCrossIdDateTimeVO;
import net.wanji.opt.vo.CommonCrossIdVO;
import net.wanji.opt.vo.CountRealTimeVO;
import net.wanji.opt.vo.CrossStatusTimeRateVO;
import net.wanji.opt.vo.EventAlarmVO;
import net.wanji.opt.vo.GreenStatusTimeRateVO;
import net.wanji.opt.vo.GreenWaveCrossMonitorVO;
import net.wanji.opt.vo.GreenwaveCrossMetricsVO;
import net.wanji.opt.vo.GreenwaveDetailVO;
import net.wanji.opt.vo.GreenwaveRunMonitorVO;
import net.wanji.opt.vo.GreenwaveStats;
import net.wanji.opt.vo.HoloEventVO;
import net.wanji.opt.vo.HotspotCrossLaneVO;
import net.wanji.opt.vo.HotspotCrossTurnVO;
import net.wanji.opt.vo.HotspotCrossVO;
import net.wanji.opt.vo.LaneIdAliasNameVO;
import net.wanji.opt.vo.LanePeriodTurnVO;
import net.wanji.opt.vo.LaneSnapshotIndexVO;
import net.wanji.opt.vo.OptTypeVO;
import net.wanji.opt.vo.OverflowEvent;
import net.wanji.opt.vo.TableQueryVO;
import net.wanji.opt.vo.Top5IndexVO;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* 事件接口
*/
public interface EventService {
/**
* 查询路口事件统计数
* @param crossId
* @param type
* @param startTime
* @param endTime
* @return
*/
EventStatisticPo findCrossEventCount(String crossId, String type, String startTime, String endTime) throws DubboProviderException;
/**
* 场景分布
* @param crossId
* @param startTime
* @param endTime
* @return
*/
List<Map<String,Object>> findEventDistribute(String crossId, String startTime, String endTime) throws DubboProviderException;
}
package net.wanji.opt.service.base;
import net.wanji.common.framework.dubbointerface.BaseDubboInterface;
import net.wanji.opt.po.base.BaseRidInfo;
/**
* <p>
* 路段基础信息
* </p>
*
* @Author fengyi
* @Date 2024-11-14
*/
public interface BaseRidInfoProvider {
}
package net.wanji.opt.service.base.impl;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.dubbointerface.impl.BaseDubboInterfaceImpl;
import net.wanji.common.framework.mapper.BaseInterfaceMapper;
import net.wanji.opt.dao.mapper.base.BaseRidInfoMapper;
import net.wanji.opt.po.base.BaseRidInfo;
import net.wanji.opt.service.base.BaseRidInfoProvider;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.HashMap;
/**
* <p>
* 路段基础信息
* </p>
*
* @Author fengyi
* @Date 2024-11-14
*/
@Slf4j
@Component
@Service
public class BaseRidInfoProviderImpl implements BaseRidInfoProvider {
@Resource
private BaseRidInfoMapper baseRidInfoMapper;
}
package net.wanji.opt.service.impl;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import net.wanji.common.enums.BaseEnum;
import net.wanji.common.enums.CrossInOutEnum;
import net.wanji.common.enums.StrategyAndMetricsEnum;
import net.wanji.common.enums.TurnConvertEnum;
import net.wanji.common.framework.exception.DubboProviderException;
import net.wanji.common.utils.tool.CrossUtil;
import net.wanji.common.utils.tool.DateUtil;
import net.wanji.common.utils.tool.TimeArrayUtil;
import net.wanji.databus.bo.CrossIdBO;
import net.wanji.databus.dao.entity.BaseCrossSchedulesPO;
import net.wanji.databus.dao.entity.BaseCrossSchedulesPlanPO;
import net.wanji.databus.dao.entity.BaseCrossSchemePO;
import net.wanji.databus.dao.entity.CrossSectionPO;
import net.wanji.databus.dao.mapper.BaseCrossDirInfoMapper;
import net.wanji.databus.dao.mapper.BaseCrossSchedulesMapper;
import net.wanji.databus.dao.mapper.BaseCrossSchedulesPlanMapper;
import net.wanji.databus.dao.mapper.BaseCrossSchemeMapper;
import net.wanji.databus.dao.mapper.BaseCrossSectionMapper;
import net.wanji.databus.dao.mapper.BaseCrossTurnInfoMapper;
import net.wanji.databus.dao.mapper.CrossDataHistMapper;
import net.wanji.databus.dao.mapper.CrossDataRealtimeMapper;
import net.wanji.databus.dao.mapper.CrossDirDataHistMapper;
import net.wanji.databus.dao.mapper.CrossTurnDataHistMapper;
import net.wanji.databus.po.CrossDataHistPO;
import net.wanji.databus.po.CrossDirDataHistPO;
import net.wanji.databus.po.CrossDirDataHistPOExt;
import net.wanji.databus.po.CrossTurnDataHistPO;
import net.wanji.databus.po.CrossTurnDataHistPOExt;
import net.wanji.opt.bo.CrossSchemeListBO;
import net.wanji.opt.bo.CurveChartBO;
import net.wanji.opt.bo.CurveChartBO.DirTurn;
import net.wanji.opt.bo.ProblemSchemeBO;
import net.wanji.opt.bo.SchemeDetailOverallBO;
import net.wanji.opt.common.EsDateIndexUtil;
import net.wanji.opt.common.enums.TimeGranularityEnum;
import net.wanji.opt.dao.mapper.HoloEventMapper;
import net.wanji.opt.dao.mapper.base.BaseRidInfoMapper;
import net.wanji.opt.dao.mapper.strategy.SceneMapper;
import net.wanji.opt.dao.mapper.strategy.SceneStrategyMapper;
import net.wanji.opt.dao.mapper.strategy.StrategyMapper;
import net.wanji.opt.po.base.BaseRidInfo;
import net.wanji.opt.po.base.CrossLaneDataHistPoExtend;
import net.wanji.opt.po.base.EventStatisticPo;
import net.wanji.opt.po.strategy.ScenePO;
import net.wanji.opt.po.strategy.SceneStrategyPO;
import net.wanji.opt.po.strategy.StrategyPO;
import net.wanji.opt.po.trend.EventInfoSimplePo;
import net.wanji.opt.po.trend.HoloEventInfoPO;
import net.wanji.opt.service.EventService;
import net.wanji.opt.service.SchemeEvaluateService;
import net.wanji.opt.vo.RunningEvaluateMetricsDetailVO;
import net.wanji.opt.vo.SchemeEvaluateCrossSchemeListVO;
import net.wanji.opt.vo.SchemeEvaluateCurveChartVO;
import net.wanji.opt.vo.SchemeEvaluateProblemSchemeVO;
import net.wanji.opt.vo.SchemeEvaluateSchemeDetailOverallVO;
import net.wanji.opt.vo.SchemeEvaluateSchemeDetailedProblemVO;
import net.wanji.opt.vo.SchemeEvaluateStrategyMetricMenuVO;
import org.jetbrains.annotations.NotNull;
import org.joda.time.DateTime;
import org.joda.time.Minutes;
import org.joda.time.Seconds;
import org.joda.time.format.DateTimeFormat;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
*
*/
@Slf4j
@Service
public class EventServiceImpl implements EventService {
@Resource
HoloEventMapper holoEventMapper;
@Resource
BaseRidInfoMapper baseRidInfoMapper;
@Override
public EventStatisticPo findCrossEventCount(String crossId, String type, String startTime, String endTime) throws DubboProviderException {
Map<String, Object> params = new HashMap<>();
params.put("crossId", crossId);
params.put("startDate", startTime);
params.put("endDate", endTime);
params.put("eventType", type);
EventStatisticPo po = holoEventMapper.findCrossEventCount(params);
if (po != null) {
String dirs = po.getDirs();
if (Objects.nonNull(dirs)) {
String[] sps = dirs.split(",");
List<Map<String, Object>> list = new ArrayList<>();
//统计每个方向发生的次数
Map<String, Long> countMap = Arrays.stream(sps).collect(Collectors.groupingBy(String::valueOf, Collectors.counting()));
countMap.entrySet().forEach(o -> {
Map<String, Object> map = new HashMap<>();
map.put("dir", o.getKey());
map.put("count", o.getValue());
list.add(map);
});
po.setDirEventCount(countMap);
}
QueryWrapper<BaseRidInfo> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("end_cross_id", crossId);
List<BaseRidInfo> ridList = baseRidInfoMapper.selectList(queryWrapper);
Map<String, List<String>> group = ridList.stream().collect(Collectors.groupingBy(o -> o.getInDir().toString(), Collectors.mapping(BaseRidInfo::getWkt, Collectors.toList())));
//进口道方向wkt
Map<String, String> dirWkt = new HashMap<>();
group.forEach((k, v) -> {
dirWkt.put(k, v.get(0));
});
po.setDirWkt(dirWkt);
}
return po;
}
@Override
public List<Map<String, Object>> findEventDistribute(String crossId, String startTime, String endTime) {
Map<String, Object> params = new HashMap<>();
params.put("crossId", crossId);
params.put("startDate", startTime);
params.put("endDate", endTime);
List<Map<String, Object>> retList = new ArrayList<>();
DateTime start = DateTime.parse(startTime, DateTimeFormat.forPattern(EsDateIndexUtil.YMD_HM_FORMATTER));
DateTime end = DateTime.parse(endTime, DateTimeFormat.forPattern(EsDateIndexUtil.YMD_HM_FORMATTER));
//存放时段
Set<String> sortedSet = getTimeScopeList(start, end, EsDateIndexUtil.YMD_HM_FORMATTER);
List<EventInfoSimplePo> list = holoEventMapper.findEventDistribute(params);
//每5分组分组
Map<String, List<EventInfoSimplePo>> group = list.stream().collect(Collectors.groupingBy(o -> o.getTimeAxis()));
group.forEach((time, valList1) -> {
//5分组内数据按类型分组
Map<String, List<EventInfoSimplePo>> groupByType = valList1.stream().collect(Collectors.groupingBy(o -> o.getEventType()));
List<EventInfoSimplePo> tmpList = new ArrayList<>();
groupByType.forEach((type, valList2) -> {
EventInfoSimplePo tmp = null;
for (EventInfoSimplePo po : valList2) {
po.setDate(net.wanji.common.utils.tool.DateUtil.formatDate(po.getStartTime(), "M/d"));
//合并时间重叠事件
if (tmp != null) {
Date agoStartTime = tmp.getStartTime();
Date agoEndTime = tmp.getEndTime();
Date currentStartTime = po.getStartTime();
Date currentEndTime = po.getEndTime();
if (currentStartTime.before(agoEndTime)) {
int duration = Seconds.secondsBetween(new DateTime(agoStartTime.getTime()), new DateTime(currentEndTime.getTime())).getSeconds();
po.setDuration(duration);
po.setStartTime(agoStartTime);
po.setEndTime(currentEndTime);
//清理合并前的记录
tmpList.remove(tmp);
}
}
tmpList.add(po);
tmp = po;
}
});
Map<String, Object> map = new HashMap<>();
map.put("timeAxis", time);
map.put("statusByDateList", tmpList);
retList.add(map);
});
Set<String> timeList = group.keySet();
//补充缺少时段数据,保留时段字段默认值
// for (String timeSec : sortedSet) {
// if (!timeList.contains(timeSec)) {
// Map<String, Object> map = new HashMap<>();
// map.put("timeAxis", timeSec);
// map.put("statusByDateList", new ArrayList<>());
// retList.add(map);
// }
// }
List<Map<String, Object>> sortList = retList.stream().sorted(Comparator.comparing(o -> o.get("timeAxis").toString())).collect(Collectors.toList());
return sortList;
}
public Set<String> getTimeScopeList(DateTime start, DateTime end, String dateFormat) {
Set<String> indexList = new HashSet<>();
int diffNum = Minutes.minutesBetween(start, end).getMinutes();
int unitTime = 5;
for (int i = 0; i <= diffNum; i = i + unitTime) {
String format = start.plusMinutes(i).toString(dateFormat);
indexList.add(format);
}
return indexList;
}
}
......@@ -75,8 +75,10 @@ public class SceneEvaluateServiceImpl implements SceneEvaluateService {
Date endDate = bo.getEndDate();
SceneEvaluateAbnormalDistributeVO vo = new SceneEvaluateAbnormalDistributeVO();
List<SceneEvaluateAbnormalDistributeVO.TimeDistribution> timeDistributionList =
buildTimeDistributionList(crossId, startDate, endDate);
vo.setTimeDateDistributionList(buildTimeDateDistributionList(timeDistributionList));
setCounts(timeDistributionList, vo);
......@@ -1345,13 +1347,16 @@ public class SceneEvaluateServiceImpl implements SceneEvaluateService {
partEnd.add(Calendar.DAY_OF_MONTH, 1);
int startStamp = (int)(start.getTimeInMillis() / 1000);
int endStamp = (int)(partEnd.getTimeInMillis() / 1000);
//按开始、截止时间查询事件列表
List<MetricHistDTO> crossDTOList = crossDataHistMapper.selectMetricHistDTO(
crossId, startStamp, endStamp);
// 过滤有问题的记录
List<MetricHistDTO> filteredList = crossDTOList.stream()
.filter(metricHistDTO -> metricHistDTO.getStatus() != null && !metricHistDTO.getStatus().equals(0))
.collect(Collectors.toList());
timeDistribution.setProblemStatusList(runningEvaluateService.buildProblemStatusList(filteredList));
res.add(timeDistribution);
}
return res;
......
......@@ -249,11 +249,12 @@
(
SELECT start_time,
(case
when #{groupType}=0 then start_time
when #{groupType}=0 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 5 ) * 5 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
when #{groupType}=4 then DATE_FORMAT(start_time,'%Y-%m-%d 00:00:00' )
else DATE_FORMAT(start_time,'%Y-01-01 00:00:00') <!-- 按查询时间范围不分粒度进行聚合处理 -->
end
) unit_time,
t.cross_id,
......@@ -335,7 +336,7 @@
SUM(TIMESTAMPDIFF(SECOND,start_time, end_time)) duration,
TIMESTAMPDIFF(SECOND,#{startDate}, #{endDate}) total_time
from t_event_info t
where start_time > #{startDate} and start_time &lt; #{endDate}
where start_time >= #{startDate} and start_time &lt; #{endDate}
<if test="eventTypeList!=null and eventTypeList.size>0">
and t.type in
<foreach collection="eventTypeList" item="item" index="index" open="(" close=")" separator=",">
......@@ -398,7 +399,7 @@
left join (
SELECT cross_id,dir_type,start_time,flow,speed,queue_length,stop_times,delay_time,sturation ,traffic_index,
(case
when #{groupType}=0 then start_time
when #{groupType}=0 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 5 ) * 5 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
......@@ -406,7 +407,7 @@
end
) unit_time
from t_cross_dir_data_hist
WHERE start_time > #{startDate} and start_time &lt; #{endDate}
WHERE start_time >= #{startDate} and start_time &lt; #{endDate}
) t2
on t2.cross_id=t1.end_cross_id and t2.dir_type=t1.dir
GROUP BY t1.start_cross_id,t1.dir,t2.unit_time
......@@ -446,7 +447,7 @@
left join (
SELECT id as lane_id,cross_id,start_time,flow,speed,queue_length,stop_times,delay_time,sturation ,
(case
when #{groupType}=0 then start_time
when #{groupType}=0 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 5 ) * 5 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=1 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 15 ) * 15 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=2 then DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 30 ) * 30 ),'%Y-%m-%d %H:%i:00' )
when #{groupType}=3 then DATE_FORMAT(start_time,'%Y-%m-%d %H:00:00' )
......@@ -454,7 +455,7 @@
end
) unit_time
from t_lane_data_hist
WHERE start_time > #{startDate} and start_time &lt; #{endDate}
WHERE start_time >= #{startDate} and start_time &lt; #{endDate}
) t2
on t2.lane_id=t1.lane_id
GROUP BY t1.end_cross_id,t1.dir,t1.lane_id,t1.turn,t2.unit_time
......
......@@ -56,4 +56,35 @@
order by t2.alarm_status desc
</select>
<!-- 空放、失衡、溢出事件分布查询 -->
<select id="findEventDistribute" resultType="net.wanji.opt.po.trend.EventInfoSimplePo">
select cross_id,type as event_type,start_time,end_time,
TIMESTAMPDIFF(SECOND,start_time, ifnull(end_time,now())) duration,
DATE_FORMAT(concat( date( start_time ), ' ', HOUR ( start_time ), ':', floor( MINUTE ( start_time ) / 5 ) * 5 ),'%Y-%m-%d %H:%i:00' ) time_axis
from t_event_info
where type in ('701', '702','703')
and cross_id=#{crossId}
and start_time > #{startDate} and start_time &lt; #{endDate}
</select>
<!-- 查看路口事件数量 -->
<select id="findCrossEventCount" resultType="net.wanji.opt.po.base.EventStatisticPo">
select type as event_type,count(*) event_count,group_concat(distinct dir) dirs,b.label as event_type_desc
from t_event_info a left join t_config_event_category b on a.type=b.event_type
where 1=1
<if test="crossId !=null and crossId !=''">
and cross_id = #{crossId}
</if>
<if test="eventType!=null and eventType !=''">
and a.type = #{eventType}
</if>
<if test="startDate!=null and endDate !=''">
and start_time > #{startDate} and start_time &lt; #{endDate}
</if>
GROUP BY type
</select>
</mapper>
\ No newline at end of file
<?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.opt.dao.mapper.base.BaseRidInfoMapper">
<!-- 通用查询映射结果 -->
<resultMap id="BaseResultMap" type="net.wanji.opt.po.base.BaseRidInfo">
<id column="id" property="id" />
<result column="name" property="name" />
<result column="road_id" property="roadId" />
<result column="road_name" property="roadName" />
<result column="road_dir_id" property="roadDirId" />
<result column="start_cross_id" property="startCrossId" />
<result column="end_cross_id" property="endCrossId" />
<result column="out_dir" property="outDir" />
<result column="in_dir" property="inDir" />
<result column="start_angle" property="startAngle" />
<result column="end_angle" property="endAngle" />
<result column="direction" property="direction" />
<result column="sort" property="sort" />
<result column="trend" property="trend" />
<result column="level" property="level" />
<result column="area_code" property="areaCode" />
<result column="length" property="length" />
<result column="width" property="width" />
<result column="is_oneway" property="isOneway" />
<result column="type" property="type" />
<result column="main_flag" property="mainFlag" />
<result column="wkt" property="wkt" />
<result column="sc_id" property="scId" />
<result column="sc_name" property="scName" />
<result column="sc_sort" property="scSort" />
<result column="gmt_create" property="gmtCreate" />
<result column="gmt_modified" property="gmtModified" />
</resultMap>
<sql id="Table_Name">
t_base_rid_info
</sql>
<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
id, name, road_id, road_name, road_dir_id, start_cross_id, end_cross_id, out_dir, in_dir, start_angle, end_angle, direction, sort, trend, level, area_code, length, width, is_oneway, type, main_flag, wkt, sc_id, sc_name, sc_sort, gmt_create, gmt_modified
</sql>
<!--新增操作 -->
<insert id="save" parameterType="net.wanji.opt.po.base.BaseRidInfo">
insert into
<include refid="Table_Name"/>
(<include refid="Base_Column_List"/>)
values(
#{id}
,#{name}
,#{roadId}
,#{roadName}
,#{roadDirId}
,#{startCrossId}
,#{endCrossId}
,#{outDir}
,#{inDir}
,#{startAngle}
,#{endAngle}
,#{direction}
,#{sort}
,#{trend}
,#{level}
,#{areaCode}
,#{length}
,#{width}
,#{isOneway}
,#{type}
,#{mainFlag}
,#{wkt}
,#{scId}
,#{scName}
,#{scSort}
,#{gmtCreate}
,#{gmtModified}
)
</insert>
<!--根据ID查询-->
<select id="findById" resultMap="BaseResultMap" parameterType="String">
select
<include refid="Base_Column_List"/>
from
<include refid="Table_Name"/>
where s_id = #{id}
</select>
<!--获取数据总数-->
<select id="getCount" parameterType="java.util.Map" resultType="int">
select count(*) from
<include refid="Table_Name"/>
where 1=1
<include refid="sql_query"/>
<include refid="fuzzySearch"/>
</select>
<!-- 查询所有数据-->
<select id="findAll" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from
<include refid="Table_Name"/>
<!--ORDER BY `dt_create_date` DESC-->
</select>
<!-- 通过条件查询所有数据-->
<select id="findByMap" parameterType="java.util.Map" resultMap="BaseResultMap">
select
<include refid="Base_Column_List"/>
from
<include refid="Table_Name"/>
<where>
<include refid="sql_query"/>
<include refid="fuzzySearch"/>
</where>
<!--ORDER BY `dt_create_date` DESC-->
</select>
<!--分组分页查询-->
<select id="findByPage" parameterType="java.util.Map" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List"/>
FROM
<include refid="Table_Name"/>
<where>
<include refid="sql_query"/>
<include refid="fuzzySearch"/>
</where>
<!--ORDER BY `dt_create_date` DESC-->
limit #{startRowNum}, #{pageSize}
</select>
<!--更新-->
<update id="update" parameterType="net.wanji.opt.po.base.BaseRidInfo">
update
<include refid="Table_Name"/>
<include refid="sql_update"/>
where
id = #{id}
</update>
<!--根据ID删除-->
<delete id="deleteById" parameterType="String">
delete from
<include refid="Table_Name"/>
where
id = #{id}
</delete>
<sql id="fuzzySearch">
<if test="keyword != null and keyword !=''">
and (locate(#{keyword,jdbcType=VARCHAR}, s_name)>0
)
</if>
</sql>
<sql id="sql_query">
<if test="id != null and id != '' ">
<![CDATA[ and id = #{id}]]>
</if>
<if test="name != null and name != '' ">
<![CDATA[ and name = #{name}]]>
</if>
<if test="roadId != null and roadId != '' ">
<![CDATA[ and road_id = #{roadId}]]>
</if>
<if test="roadName != null and roadName != '' ">
<![CDATA[ and road_name = #{roadName}]]>
</if>
<if test="roadDirId != null and roadDirId != '' ">
<![CDATA[ and road_dir_id = #{roadDirId}]]>
</if>
<if test="startCrossId != null and startCrossId != '' ">
<![CDATA[ and start_cross_id = #{startCrossId}]]>
</if>
<if test="endCrossId != null and endCrossId != '' ">
<![CDATA[ and end_cross_id = #{endCrossId}]]>
</if>
<if test="outDir != null and outDir != '' ">
<![CDATA[ and out_dir = #{outDir}]]>
</if>
<if test="inDir != null and inDir != '' ">
<![CDATA[ and in_dir = #{inDir}]]>
</if>
<if test="startAngle != null and startAngle != '' ">
<![CDATA[ and start_angle = #{startAngle}]]>
</if>
<if test="endAngle != null and endAngle != '' ">
<![CDATA[ and end_angle = #{endAngle}]]>
</if>
<if test="direction != null and direction != '' ">
<![CDATA[ and direction = #{direction}]]>
</if>
<if test="sort != null and sort != '' ">
<![CDATA[ and sort = #{sort}]]>
</if>
<if test="trend != null and trend != '' ">
<![CDATA[ and trend = #{trend}]]>
</if>
<if test="level != null and level != '' ">
<![CDATA[ and level = #{level}]]>
</if>
<if test="areaCode != null and areaCode != '' ">
<![CDATA[ and area_code = #{areaCode}]]>
</if>
<if test="length != null and length != '' ">
<![CDATA[ and length = #{length}]]>
</if>
<if test="width != null and width != '' ">
<![CDATA[ and width = #{width}]]>
</if>
<if test="isOneway != null and isOneway != '' ">
<![CDATA[ and is_oneway = #{isOneway}]]>
</if>
<if test="type != null and type != '' ">
<![CDATA[ and type = #{type}]]>
</if>
<if test="mainFlag != null and mainFlag != '' ">
<![CDATA[ and main_flag = #{mainFlag}]]>
</if>
<if test="wkt != null and wkt != '' ">
<![CDATA[ and wkt = #{wkt}]]>
</if>
<if test="scId != null and scId != '' ">
<![CDATA[ and sc_id = #{scId}]]>
</if>
<if test="scName != null and scName != '' ">
<![CDATA[ and sc_name = #{scName}]]>
</if>
<if test="scSort != null and scSort != '' ">
<![CDATA[ and sc_sort = #{scSort}]]>
</if>
<if test="gmtCreate != null and gmtCreate != '' ">
<![CDATA[ and gmt_create = #{gmtCreate}]]>
</if>
<if test="gmtModified != null and gmtModified != '' ">
<![CDATA[ and gmt_modified = #{gmtModified}]]>
</if>
</sql>
<!--更新操作-->
<sql id="sql_update">
<set>
<if test="id != null and id != '' ">
<![CDATA[ id = #{id}, ]]>
</if>
<if test="name != null and name != '' ">
<![CDATA[ name = #{name}, ]]>
</if>
<if test="roadId != null and roadId != '' ">
<![CDATA[ road_id = #{roadId}, ]]>
</if>
<if test="roadName != null and roadName != '' ">
<![CDATA[ road_name = #{roadName}, ]]>
</if>
<if test="roadDirId != null and roadDirId != '' ">
<![CDATA[ road_dir_id = #{roadDirId}, ]]>
</if>
<if test="startCrossId != null and startCrossId != '' ">
<![CDATA[ start_cross_id = #{startCrossId}, ]]>
</if>
<if test="endCrossId != null and endCrossId != '' ">
<![CDATA[ end_cross_id = #{endCrossId}, ]]>
</if>
<if test="outDir != null and outDir != '' ">
<![CDATA[ out_dir = #{outDir}, ]]>
</if>
<if test="inDir != null and inDir != '' ">
<![CDATA[ in_dir = #{inDir}, ]]>
</if>
<if test="startAngle != null and startAngle != '' ">
<![CDATA[ start_angle = #{startAngle}, ]]>
</if>
<if test="endAngle != null and endAngle != '' ">
<![CDATA[ end_angle = #{endAngle}, ]]>
</if>
<if test="direction != null and direction != '' ">
<![CDATA[ direction = #{direction}, ]]>
</if>
<if test="sort != null and sort != '' ">
<![CDATA[ sort = #{sort}, ]]>
</if>
<if test="trend != null and trend != '' ">
<![CDATA[ trend = #{trend}, ]]>
</if>
<if test="level != null and level != '' ">
<![CDATA[ level = #{level}, ]]>
</if>
<if test="areaCode != null and areaCode != '' ">
<![CDATA[ area_code = #{areaCode}, ]]>
</if>
<if test="length != null and length != '' ">
<![CDATA[ length = #{length}, ]]>
</if>
<if test="width != null and width != '' ">
<![CDATA[ width = #{width}, ]]>
</if>
<if test="isOneway != null and isOneway != '' ">
<![CDATA[ is_oneway = #{isOneway}, ]]>
</if>
<if test="type != null and type != '' ">
<![CDATA[ type = #{type}, ]]>
</if>
<if test="mainFlag != null and mainFlag != '' ">
<![CDATA[ main_flag = #{mainFlag}, ]]>
</if>
<if test="wkt != null and wkt != '' ">
<![CDATA[ wkt = #{wkt}, ]]>
</if>
<if test="scId != null and scId != '' ">
<![CDATA[ sc_id = #{scId}, ]]>
</if>
<if test="scName != null and scName != '' ">
<![CDATA[ sc_name = #{scName}, ]]>
</if>
<if test="scSort != null and scSort != '' ">
<![CDATA[ sc_sort = #{scSort}, ]]>
</if>
<if test="gmtCreate != null and gmtCreate != '' ">
<![CDATA[ gmt_create = #{gmtCreate}, ]]>
</if>
<if test="gmtModified != null and gmtModified != '' ">
<![CDATA[ gmt_modified = #{gmtModified}, ]]>
</if>
</set>
</sql>
</mapper>
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