| | |
| | | package com.yssh.controller; |
| | | |
| | | import com.yssh.entity.Qxsh; |
| | | import com.yssh.utils.CacheUtils; |
| | | import com.yssh.utils.DateUtils; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | |
| | | import com.yssh.utils.Result; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Api(tags = "告警分析") |
| | | @RequestMapping("/warning") |
| | |
| | | @Resource |
| | | private WarningAnalyseService warningService; |
| | | |
| | | /** |
| | | * 1.查询当前时间的所有点位value值(以47.dat查询即可) |
| | | * 2.筛选大于yssh_bjyj中的jcbj字段的值 返回id+经纬度+value |
| | | */ |
| | | @ApiOperationSupport(order = 1) |
| | | @ApiOperation(value = "获取实时报警", notes = "获取实时报警分析数据") |
| | | @GetMapping("/runAlarm") |
| | |
| | | return Result.OK(warningService.getRunTimeAlarmAnalyse()); |
| | | } |
| | | |
| | | /** |
| | | * 1.查询当前时间的所有点位value值(以47.dat查询即可) |
| | | * 2.筛选大于yssh_bjyj中的jcyj字段的值 返回id+经纬度+value |
| | | */ |
| | | @ApiOperationSupport(order = 2) |
| | | @ApiOperation(value = "获取实时预警", notes = "获取实时预警分析数据") |
| | | @GetMapping("/runWarning") |
| | |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 3) |
| | | @ApiOperation(value = "本月预警、报警统计", notes = "本月预警、报警统计,返回参数alarmNumber对应值为本月报警数据量,参数warningNumber对应值为本月预警数据量") |
| | | @ApiOperation(value = "本月预警报警统计", notes = "本月预警报警统计,返回参数alarmNumber对应值为本月报警数据量,参数warningNumber对应值为本月预警数据量") |
| | | @GetMapping("/monthCount") |
| | | public Result thisMonthCount() { |
| | | return Result.OK(warningService.countThisMonthAlarmAndWarning()); |
| | | public Result thisMonthCount(@RequestParam(value = "end", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date date) { |
| | | return Result.OK(warningService.monthCount(null == date ? new Date() : date)); |
| | | } |
| | | |
| | | @ApiOperationSupport(order = 4) |
| | |
| | | if (null == begin || null == end) { |
| | | return Result.error(null); |
| | | } |
| | | |
| | | if (begin.getTime() > end.getTime()) { |
| | | Date tmp = end; |
| | | Date tmp = begin; |
| | | begin = end; |
| | | end = tmp; |
| | | } |
| | |
| | | |
| | | public List<Qxsh> selectMonthTop10(String time); |
| | | |
| | | public Integer countMonthForWarn(@Param("start") Integer start, @Param("end") Integer end); |
| | | |
| | | public Integer countMonthForAlarm(@Param("start") Integer start, @Param("end") Integer end); |
| | | |
| | | public List<Map<String, Object>> count7DayForWarn(@Param("start") Integer start, @Param("end") Integer end); |
| | | |
| | | public List<Map<String, Object>> count7DayForAlarm(@Param("start") Integer start, @Param("end") Integer end); |
| | |
| | | } |
| | | } |
| | | |
| | | public Map<String, Integer> countThisMonthAlarmAndWarning() { |
| | | /** |
| | | * 本月预警报警统计 |
| | | */ |
| | | public Map<String, Integer> monthCount(Date date) { |
| | | Date startDate = DateUtils.getMonthStart(date); |
| | | Date endDate = DateUtils.getMonthEnd(date); |
| | | Integer start = Integer.parseInt(DateUtils.getYyyyMmDdHh(startDate)); |
| | | Integer end = Integer.parseInt(DateUtils.getYyyyMmDdHh(endDate)); |
| | | |
| | | Map<String, Integer> result = new HashMap<>(); |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("startTime", DateUtils.getYyyyMmDdHhMmSs(DateUtils.getMonthStart())); |
| | | param.put("endTime", DateUtils.getYyyyMmDdHhMmSs(DateUtils.getMonthEnd())); |
| | | |
| | | /*param.put("type", 0); |
| | | List<WarningVo> alarms = warningDetailMapper.selectWarningDetailByMap(param); |
| | | if (StringUtils.isNull(alarms)) { |
| | | alarms = new ArrayList<>(); |
| | | } |
| | | result.put("alarmNumber", alarms.size());*/ |
| | | Integer alarmNum = warningDetailMapper.countAlarmByMap(param); |
| | | result.put("alarmNumber", null == alarmNum ? 0 : alarmNum); |
| | | |
| | | param.put("type", 1); |
| | | /*List<WarningVo> warnings = warningDetailMapper.selectWarningDetailByMap(param); |
| | | if (StringUtils.isNull(warnings)) { |
| | | warnings = new ArrayList<>(); |
| | | } |
| | | result.put("warningNumber", warnings.size());*/ |
| | | Integer warnNum = warningDetailMapper.countWarnByMap(param); |
| | | Integer warnNum = qxshMapper.countMonthForWarn(start, end); |
| | | result.put("warningNumber", null == warnNum ? 0 : warnNum); |
| | | |
| | | Integer alarmNum = qxshMapper.countMonthForAlarm(start, end); |
| | | result.put("alarmNumber", null == alarmNum ? 0 : alarmNum); |
| | | |
| | | return result; |
| | | } |
| | | |
| | |
| | | * |
| | | * @return String |
| | | **/ |
| | | public static Date getMonthStart() { |
| | | public static Date getMonthStart(Date date) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | //cal.set(Calendar.MONTH, 3); |
| | | // cal.set(Calendar.MONTH, 3) |
| | | cal.setTime(date); |
| | | cal.set(Calendar.DAY_OF_MONTH, 1); |
| | | return dateTime(YYYY_MM_DD_HH_MM_SS, parseDateToStr(YYYY_MM_DD, cal.getTime()) + " 00:00:00"); |
| | | } |
| | |
| | | * |
| | | * @return String |
| | | **/ |
| | | public static Date getMonthEnd() { |
| | | public static Date getMonthEnd(Date date) { |
| | | Calendar cal = Calendar.getInstance(); |
| | | //cal.set(Calendar.MONTH, 3); |
| | | // cal.set(Calendar.MONTH, 3) |
| | | cal.setTime(date); |
| | | cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); |
| | | return dateTime(YYYY_MM_DD_HH_MM_SS, parseDateToStr(YYYY_MM_DD, cal.getTime()) + " 23:59:59"); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | //System.out.println(parseDateToStr(YYYY_MM_DD_HH_MM_SS, getMonthStart())); |
| | | //System.err.println(parseDateToStr(YYYY_MM_DD_HH_MM_SS, getMonthEnd())); |
| | | System.out.println(parseDateToStr(YYYY_MM_DD_HH_MM_SS, getAPeriodOfTime(getNowDate(), -7, Calendar.DATE))); |
| | | } |
| | | } |
| | |
| | | limit 10; |
| | | </select> |
| | | |
| | | <select id="countMonthForWarn" resultType="java.lang.Integer"> |
| | | select count(*) |
| | | from yssh_qxsh |
| | | where time between #{start} and #{end} and name like 'AI-%' |
| | | and value > (select jcyj from alert_config limit 1) and value <= (select jcbj from alert_config limit 1); |
| | | </select> |
| | | |
| | | <select id="countMonthForAlarm" resultType="java.lang.Integer"> |
| | | select count(*) |
| | | from yssh_qxsh |
| | | where time between #{start} and #{end} and name like 'AI-%' and value > (select jcbj from alert_config limit 1); |
| | | </select> |
| | | |
| | | <select id="count7DayForWarn" resultType="java.util.Map"> |
| | | with rs as ( |
| | | select left(time, 8) "createTime" |