Commit c42ad362 authored by wang yecheng's avatar wang yecheng

路口问题概况-单路口发送时段 方向

parent ef79c171
...@@ -5,6 +5,8 @@ import lombok.extern.slf4j.Slf4j; ...@@ -5,6 +5,8 @@ import lombok.extern.slf4j.Slf4j;
import net.wanji.common.framework.i18n.I18nResourceBundle; 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.CrossDirProblemTrendAnalysisResult; import net.wanji.opt.controllerv2.judgeanalysis.design.response.crossproblem.CrossDirProblemTrendAnalysisResult;
import net.wanji.opt.controllerv2.judgeanalysis.design.response.crossproblem.CrossProblemDirTrendAnalysisResult;
import net.wanji.opt.controllerv2.judgeanalysis.design.response.crossproblem.CrossProblemTimeDirReasonResult;
import net.wanji.opt.entity.judgeanalysis.AnalysisProblemCrossDirHour; import net.wanji.opt.entity.judgeanalysis.AnalysisProblemCrossDirHour;
import net.wanji.opt.servicev2.judgeanalysis.AnalysisProblemCrossDirHourService; import net.wanji.opt.servicev2.judgeanalysis.AnalysisProblemCrossDirHourService;
...@@ -15,6 +17,7 @@ import net.wanji.opt.api.ResultGenerator; ...@@ -15,6 +17,7 @@ import net.wanji.opt.api.ResultGenerator;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.core.MediaType;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -77,6 +80,14 @@ public class AnalysisProblemCrossDirHourController { ...@@ -77,6 +80,14 @@ public class AnalysisProblemCrossDirHourController {
analysisProblemCrossDirHourService.removes(ids); analysisProblemCrossDirHourService.removes(ids);
return ResultGenerator.genSuccessResult(); return ResultGenerator.genSuccessResult();
} }
@ApiOperation(value = "单路口-各方向问题情况分布", response = CrossProblemDirTrendAnalysisResult.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "String"),
@ApiImplicitParam(name = "eventType", value = "事件代码 701:空放 702:路口失衡,703:路口溢出 707:路口拥堵", required = true, dataType = "String"),
@ApiImplicitParam(name = "startTime", value = "开始时间,格式:yyyyMMdd", required = false, dataType = "Integer", defaultValue = "20250317"),
@ApiImplicitParam(name = "endTime", value = "结束时间,格式:yyyyMMdd", required = false, dataType = "Integer", defaultValue = "20250318"),
})
@GetMapping(value = "/dir-trend") @GetMapping(value = "/dir-trend")
@ApiResponses({ @ApiResponses({
@ApiResponse(code = 200, message = "OK", response = CrossDirProblemTrendAnalysisResult.class), @ApiResponse(code = 200, message = "OK", response = CrossDirProblemTrendAnalysisResult.class),
...@@ -93,4 +104,28 @@ public class AnalysisProblemCrossDirHourController { ...@@ -93,4 +104,28 @@ public class AnalysisProblemCrossDirHourController {
return jsonView; return jsonView;
} }
@ApiOperation(value = "单路口-问题发生时段、方向、原因分析", response = JsonViewObject.class,
produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
@ApiImplicitParams({
@ApiImplicitParam(name = "crossId", value = "路口ID", required = true, dataType = "String"),
// @ApiImplicitParam(name = "timeType", value = "事件类型 1:近一个月 2:近一周", required = true, dataType = "Integer", defaultValue = "1"),
@ApiImplicitParam(name = "startTime", value = "开始时间,格式:yyyyMMdd", required = false, dataType = "Integer", defaultValue = "20250317"),
@ApiImplicitParam(name = "endTime", value = "结束时间,格式:yyyyMMdd", required = false, dataType = "Integer", defaultValue = "20250318"),
@ApiImplicitParam(name = "eventType", value = "事件代码 701:空放 702:路口失衡,703:路口溢出 707:路口拥堵", required = true, dataType = "String"),
})
@GetMapping(value = "/detail")
@ApiResponses({
@ApiResponse(code = 200, message = "OK", response = CrossProblemTimeDirReasonResult.class),
})
public JsonViewObject detail(String crossId,String eventType,Integer startTime, Integer endTime) {
JsonViewObject jsonView=JsonViewObject.newInstance();
try{
Map<String,Object> resDate=analysisProblemCrossDirHourService.crossingHappyByProblemTrend(crossId,eventType,startTime,endTime);
jsonView.success(resDate);
}catch (Exception e){
jsonView.fail(I18nResourceBundle.getConstants("GET_FAILED_MSG"));
log.error("{} getAll error", this.getClass().getSimpleName(), e);
}
return jsonView;
}
} }
\ No newline at end of file
...@@ -45,5 +45,11 @@ public interface AnalysisProblemCrossDirHourMapper extends BaseMapper<AnalysisPr ...@@ -45,5 +45,11 @@ public interface AnalysisProblemCrossDirHourMapper extends BaseMapper<AnalysisPr
Integer addAnalysisProblemCrossDirHour(AnalysisProblemCrossDirHour analysisProblemCrossDirHour); Integer addAnalysisProblemCrossDirHour(AnalysisProblemCrossDirHour analysisProblemCrossDirHour);
List<AnalysisProblemCrossDirHour> selectSingerByProblemTrend(Map<String, Object> Map); List<AnalysisProblemCrossDirHour> selectSingerByProblemTrend(Map<String, Object> Map);
List<AnalysisProblemCrossDirHour>selectHappyByProblemTrend(Map<String, Object> Map);
List<AnalysisProblemCrossDirHour> selectDirectByProblemTrend(Map<String, Object> Map);
} }
...@@ -82,4 +82,5 @@ public class AnalysisProblemCrossDirHour implements Serializable { ...@@ -82,4 +82,5 @@ public class AnalysisProblemCrossDirHour implements Serializable {
private String typeName; private String typeName;
//数量统计 //数量统计
private String countNumber; private String countNumber;
private String hours_window_start_time;
} }
...@@ -54,4 +54,6 @@ public interface AnalysisProblemCrossDirHourService extends IService<AnalysisPro ...@@ -54,4 +54,6 @@ public interface AnalysisProblemCrossDirHourService extends IService<AnalysisPro
void removes(List<Long> ids); void removes(List<Long> ids);
Map<String, Object> directionByProblemTrend(String crossId, String eventType, Integer startTime, Integer endTime) throws ParseException; Map<String, Object> directionByProblemTrend(String crossId, String eventType, Integer startTime, Integer endTime) throws ParseException;
Map<String, Object> crossingHappyByProblemTrend(String crossId,String eventType, Integer startTime, Integer endTime)throws Exception;
} }
...@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service; ...@@ -16,6 +16,8 @@ import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -108,7 +110,7 @@ import java.util.stream.Collectors; ...@@ -108,7 +110,7 @@ import java.util.stream.Collectors;
for(Map.Entry<Integer,List<AnalysisProblemCrossDirHour>>entry:groupByType.entrySet()){ for(Map.Entry<Integer,List<AnalysisProblemCrossDirHour>>entry:groupByType.entrySet()){
Integer key = entry.getKey(); Integer key = entry.getKey();
//同一方向每个日期问题数量 //同一方向每个日期问题数量
List<AnalysisProblemCrossDirHour> value = entry.getValue(); List<AnalysisProblemCrossDirHour> value = entry.getValue();
String typeName = value.get(0).getTypeName(); String typeName = value.get(0).getTypeName();
...@@ -140,4 +142,59 @@ import java.util.stream.Collectors; ...@@ -140,4 +142,59 @@ import java.util.stream.Collectors;
jsonObject.put("timeList",sortedSet); jsonObject.put("timeList",sortedSet);
return jsonObject; return jsonObject;
} }
Map<String,Object>getHappyParamMap(String crossId,String eventType,Integer startTime, Integer endTime){
Map<String,Object> map=new HashMap();
map.put("crossId",crossId);
map.put("eventType",eventType);
map.put("startTime",startTime);
map.put("endTime",endTime);
return map;
}
@Override
public Map<String, Object> crossingHappyByProblemTrend(String crossId, String eventType,Integer startTime, Integer endTime) throws Exception {
//按照小时
List<AnalysisProblemCrossDirHour> listHourSql =analysisProblemCrossDirHourMapper.selectHappyByProblemTrend(getHappyParamMap(crossId,eventType,startTime,endTime));
//按照方向
List<AnalysisProblemCrossDirHour> happyDriectList=analysisProblemCrossDirHourMapper.selectDirectByProblemTrend(getHappyParamMap(crossId,eventType,startTime,endTime));
//所有时间段
Set<String> allHourset=new LinkedHashSet();
//所有方向
List<Map<String ,Object>> allHappyList=new ArrayList<>();
// 定义时间格式
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
//取出时间
for (AnalysisProblemCrossDirHour list: listHourSql) {
String stringHour = list.getHours_window_start_time();
if(stringHour!=null ) {
// 解析时间字符串为LocalTime对象
LocalTime startTimeHour = LocalTime.parse(stringHour, formatter);
// 对时间加一个小时得到结束时间
LocalTime endTimeHour = startTimeHour.plusHours(1);
// 格式化开始时间和结束时间为所需的字符串格式
String formattedTimeRange = startTimeHour.format(formatter) + " - " + endTimeHour.format(formatter);
allHourset.add(formattedTimeRange);
}
}
//取出方向
for (AnalysisProblemCrossDirHour dirlist: happyDriectList) {
Integer dirCode = dirlist.getDir();
Map<String,Object>maplist=new HashMap<>();
maplist.put("dir",dirCode);
maplist.put("dirName", CrossDirEnum.getDesc(dirCode));
allHappyList.add(maplist);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("dirList", allHappyList);
jsonObject.put("timeList",allHourset);
return jsonObject;
}
} }
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
<result column="dir" property="dir"/> <result column="dir" property="dir"/>
<result column="dt" property="dt"/> <result column="dt" property="dt"/>
<result column="insert_time" property="insertTime"/> <result column="insert_time" property="insertTime"/>
<result column="hours_window_start_time" property="hours_window_start_time"/> <!-- 添加此行 -->
</resultMap> </resultMap>
<!-- 查询表t_analysis_problem_cross_dir_hour所有信息 --> <!-- 查询表t_analysis_problem_cross_dir_hour所有信息 -->
...@@ -195,4 +196,60 @@ ...@@ -195,4 +196,60 @@
GROUP BY dt, t1.dir GROUP BY dt, t1.dir
ORDER BY dt ORDER BY dt
</select> </select>
<select id="selectHappyByProblemTrend" parameterType="map" resultMap="AnalysisProblemCrossDirHourMap">
SELECT
dt,
dir,
t1.cross_id,
sum(event_number)AS event_number ,
DATE_FORMAT(t1.window_start_time,'%H:%i') AS hours_window_start_time ,
t1.event_type,
t2.label AS typeName
FROM t_analysis_problem_cross_dir_hour t1
JOIN t_config_event_category t2 ON t1.event_type = t2.event_type
WHERE
1=1
<if test="startTime != null and endTime != ''">
and dt >= #{startTime} AND dt &lt;= #{endTime}
</if>
<if test="crossId != null and crossId != ''">
and t1.cross_id = #{crossId}
</if>
<if test="eventType != null and eventType != ''">
and t1.event_type = #{eventType}
</if>
GROUP BY
DATE_FORMAT(t1.window_start_time,'%H:%i')
ORDER BY event_number desc
limit 2
</select>
<select id="selectDirectByProblemTrend" parameterType="map" resultMap="AnalysisProblemCrossDirHourMap">
SELECT
dt,
dir,
t1.cross_id,
sum(event_number)AS event_number ,
DATE_FORMAT(t1.window_start_time,'%H:%i') ,
t1.event_type,
t2.label AS typeName
FROM t_analysis_problem_cross_dir_hour t1
JOIN t_config_event_category t2 ON t1.event_type = t2.event_type
WHERE
1=1
<if test="startTime != null and endTime != ''">
and dt >= #{startTime} AND dt &lt;= #{endTime}
</if>
<if test="crossId != null and crossId != ''">
and t1.cross_id = #{crossId}
</if>
<if test="eventType != null and eventType != ''">
and t1.event_type = #{eventType}
</if>
GROUP BY
dir
ORDER BY event_number desc
limit 2
</select>
</mapper> </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