增加重点保障事件、事件封堵、监测接口

This commit is contained in:
wangwei
2018-12-25 18:22:33 +08:00
parent ef41d65373
commit accad98477
7 changed files with 754 additions and 0 deletions

View File

@@ -0,0 +1,97 @@
package com.nis.web.controller.restful;
import com.nis.domain.Page;
import com.nis.domain.restful.EventKeyProtection;
import com.nis.domain.restful.EventMonitorOrBlock;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants;
import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.restful.EventService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
/**
* @author GouGe
* @data 2018/12/24 15:21
*/
@RestController
@RequestMapping("${servicePath}")
@Api(value = "EventInfoController", description = "事件封堵、监测、保障接口")
@SuppressWarnings("all")
public class EventInfoController extends BaseRestController {
@Autowired
ServicesRequestLogService servicesRequestLogService;
@Autowired
EventService eventService;
@RequestMapping(value = "/log/v1/ntcEventKeyProtection", method = RequestMethod.GET)
@ApiOperation(value = "重点保障事件总览", httpMethod = "GET", notes = "获取重点保障事件信息", response = Map.class)
public Map<String, ?> getEventKeyProtection(EventKeyProtection eventKeyProtection, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<EventKeyProtection> eventKeyProtectionPage = null;
try {
eventKeyProtectionPage = eventService.getEventsKeyProtection(eventKeyProtection);
} catch (Exception e) {
saveLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
e.printStackTrace();
logger.error(e.getMessage());
if (!(e instanceof RestServiceException)) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"获取重点保障事件信息失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} else {
throw ((RestServiceException) e);
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "获取重点保障事件信息成功",
eventKeyProtectionPage, 0);
}
@RequestMapping(value = "/log/v1/ntcEventsMonitorOrBlock", method = RequestMethod.GET)
@ApiOperation(value = "事件监测、封堵", httpMethod = "GET", notes = "获取事件监测、封堵信息", response = Map.class)
public Map<String, ?> getEventsMonitorOrBlock(EventMonitorOrBlock eventMonitorOrBlock, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
int typeId = eventMonitorOrBlock.getReportType();
String logMark = null;
if(typeId == 1){
logMark = "事件封堵";
}else if(typeId == 2){
logMark = "事件监测";
}else{
logMark = "事件类型未定义、默认查询事件封堵";
eventMonitorOrBlock.setReportType(1);
}
Page<EventMonitorOrBlock> eventMonitorPage = null;
try {
eventMonitorPage = eventService.getEventsMonitorOrBlock(eventMonitorOrBlock,logMark);
} catch (Exception e) {
saveLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
e.printStackTrace();
logger.error(e.getMessage());
if (!(e instanceof RestServiceException)) {
throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"获取"+logMark+"信息失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
} else {
throw ((RestServiceException) e);
}
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "获取"+logMark+"信息成功",
eventMonitorPage, 0);
}
}

View File

@@ -0,0 +1,19 @@
package com.nis.web.dao;
import com.nis.domain.restful.EventKeyProtection;
import com.nis.domain.restful.EventMonitorOrBlock;
import java.util.List;
/**
* @author GouGe
* @data 2018/12/24 17:00
*/
@MyBatisDao
public interface EventServiceDao {
List<EventKeyProtection> getEventsKeyProtection(EventKeyProtection eventKeyProtection);
List<EventMonitorOrBlock> getEventsMonitorOrBlock(EventMonitorOrBlock eventMonitorOrBlock);
}

View File

@@ -0,0 +1,75 @@
<?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="com.nis.web.dao.EventServiceDao">
<select id="getEventsKeyProtection" resultType="com.nis.domain.restful.EventKeyProtection"
useCache="false" flushCache="true">
SELECT task_time as taskTime,
report_time as reportTime,
task_id as taskId,
task_name as taskName,
letter_num as letterNum,
config_num as configNum,
monitor_num as monitorTime,
control_num as controlerNum
FROM ntc_major_task_report
<where>
<if test="searchReportStartTime != null and searchReportStartTime !=''">
<![CDATA[AND report_time >= #{searchReportStartTime}]]>
</if>
<if test="searchReportEndTime != null and searchReportEndTime !=''">
<![CDATA[AND report_time < #{searchReportEndTime}]]>
</if>
<if test="searchTaskStartTime != null and searchTaskStartTime !=''">
<![CDATA[AND task_time >= #{searchTaskStartTime}]]>
</if>
<if test="searchTaskEndTime != null and searchTaskEndTime !=''">
<![CDATA[AND task_time < #{searchTaskEndTime}]]>
</if>
<if test="taskId != null and taskId !='' and taskId != 0">
AND task_id = #{taskId}
</if>
<if test="taskName != null and taskName !=''">
AND task_name like concat(concat('%',#{taskName}),'%')
</if>
</where>
order by taskId asc;
</select>
<select id="getEventsMonitorOrBlock" resultType="com.nis.domain.restful.EventMonitorOrBlock"
useCache="false" flushCache="true">
SELECT task_time as taskTime,
report_time as reportTime,
task_id as taskId,
task_name as taskName,
ip_num as ipNum,
http_num as httpNum,
mail_num as mailNum,
vedio_num as vedioNum,
agent_num as agentNum
FROM ntc_task_report
<where>
<if test="searchReportStartTime != null and searchReportStartTime !=''">
<![CDATA[AND report_time >= #{searchReportStartTime}]]>
</if>
<if test="searchReportEndTime != null and searchReportEndTime !=''">
<![CDATA[AND report_time < #{searchReportEndTime}]]>
</if>
<if test="searchTaskStartTime != null and searchTaskStartTime !=''">
<![CDATA[AND task_time >= #{searchTaskStartTime}]]>
</if>
<if test="searchTaskEndTime != null and searchTaskEndTime !=''">
<![CDATA[AND task_time < #{searchTaskEndTime}]]>
</if>
<if test="taskId != null and taskId !='' and taskId != 0">
AND task_id = #{taskId}
</if>
<if test="reportType != null and reportType !=''">
AND report_type = #{reportType}
</if>
<if test="taskName != null and taskName !=''">
AND task_name like concat(concat('%',#{taskName}),'%')
</if>
</where>
order by taskId asc;
</select>
</mapper>

View File

@@ -0,0 +1,144 @@
package com.nis.web.service.restful;
import com.nis.domain.Page;
import com.nis.domain.restful.EventKeyProtection;
import com.nis.domain.restful.EventMonitorOrBlock;
import com.nis.util.CalendarUtils;
import com.nis.util.DateUtils;
import com.nis.web.dao.EventServiceDao;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.apache.log4j.Logger;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* @author GouGe
* @data 2018/12/24 15:30
*/
@Service
public class EventService {
@Autowired
EventServiceDao eventServiceDao;
protected final Logger logger = Logger.getLogger(SystemHomePageService.class);
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
/**
* 重点保障事件
*
* @param eventKeyProtection
* @return
* @throws ParseException
*/
public Page<EventKeyProtection> getEventsKeyProtection(EventKeyProtection eventKeyProtection) throws ParseException {
List<EventKeyProtection> list = new ArrayList();
Page<EventKeyProtection> page = new Page<>();
String searchReportStartTime = eventKeyProtection.getSearchReportStartTime();
String searchReportEndTime = eventKeyProtection.getSearchReportEndTime();
String searchTaskStartTime = eventKeyProtection.getSearchTaskStartTime();
String searchTaskEndTime = eventKeyProtection.getSearchTaskEndTime();
String taskName = eventKeyProtection.getTaskName();
long taskId = eventKeyProtection.getTaskId();
int countParamEmpty = 0;
try{
logger.info("开始获取重点保障事件信息,参数为{"
+ ((null == searchReportStartTime && !"".equals(searchReportStartTime)) ? ""+countParamEmpty++ : format.parse(searchReportStartTime))
+ "},{"
+ ((null == searchReportEndTime && !"".equals(searchReportEndTime)) ? ""+countParamEmpty++ : format.parse(searchReportEndTime))
+ "},{"
+ ((null == searchTaskStartTime && !"".equals(searchTaskStartTime)) ? ""+countParamEmpty++ : format.parse(searchTaskStartTime))
+ "},{"
+ ((null == searchTaskEndTime && !"".equals(searchTaskEndTime)) ? ""+countParamEmpty++ : format.parse(searchTaskEndTime))
+ "},{"
+ ((null == taskName && !"".equals(taskName)) ? ""+countParamEmpty++ : taskName)
+ "},{"
+ ((null == String.valueOf(taskId) && !"".equals(String.valueOf(taskId))) ? ""+countParamEmpty++ : (long)taskId));
}catch(Exception ex){
logger.error("时间参数处理转换异常,{}", ex);
String rangeOfday = CalendarUtils.getRangeOfday(DateUtils.getDateTime());
String startTemp = CalendarUtils.getRangeNhourOfTime(rangeOfday, -24);
eventKeyProtection = new EventKeyProtection();
eventKeyProtection.setSearchReportStartTime(startTemp);
logger.info("获取重点保障事件API请求参数转换异常,默认查询昨天"+startTemp+"至今数据");
}
if(countParamEmpty == 6){
String rangeOfday = CalendarUtils.getRangeOfday(DateUtils.getDateTime());
String startTemp = CalendarUtils.getRangeNhourOfTime(rangeOfday, -24);
eventKeyProtection = new EventKeyProtection();
eventKeyProtection.setSearchReportStartTime(startTemp);
logger.info("获取重点保障事件API请求参数为空,默认查询昨天"+startTemp+"至今数据");
}
try {
list = eventServiceDao.getEventsKeyProtection(eventKeyProtection);
} catch (Exception ex) {
logger.error("重点保障事件查询异常,{}", ex);
}
page.setList(list);
return page;
}
/**
* 事件监测、封堵
*
* @param eventMonitorOrBlock
* @return
*/
public Page<EventMonitorOrBlock> getEventsMonitorOrBlock(EventMonitorOrBlock eventMonitorOrBlock,String logMark) {
List<EventMonitorOrBlock> list = new ArrayList();
Page<EventMonitorOrBlock> page = new Page<>();
String searchReportStartTime = eventMonitorOrBlock.getSearchReportStartTime();
String searchReportEndTime = eventMonitorOrBlock.getSearchReportEndTime();
String searchTaskStartTime = eventMonitorOrBlock.getSearchTaskStartTime();
String searchTaskEndTime = eventMonitorOrBlock.getSearchTaskEndTime();
String taskName = eventMonitorOrBlock.getTaskName();
long taskId = eventMonitorOrBlock.getTaskId();
int countParamEmpty = 0;
if (taskName != null) {
eventMonitorOrBlock.setTaskName(taskName.trim());
}
try{
logger.info("开始获取"+logMark+",参数为{"
+ ((null == searchReportStartTime && !"".equals(searchReportStartTime)) ? ""+countParamEmpty++ : format.parse(searchReportStartTime))
+ "},{"
+ ((null == searchReportEndTime && !"".equals(searchReportEndTime)) ? ""+countParamEmpty++ : format.parse(searchReportEndTime))
+ "},{"
+ ((null == searchTaskStartTime && !"".equals(searchTaskStartTime)) ? ""+countParamEmpty++ : format.parse(searchTaskStartTime))
+ "},{"
+ ((null == searchTaskEndTime && !"".equals(searchTaskEndTime)) ? ""+countParamEmpty++ : format.parse(searchTaskEndTime))
+ "},{"
+ ((null == taskName && !"".equals(taskName)) ? ""+countParamEmpty++ : taskName)
+ "},{"
+ ((null == String.valueOf(taskId) && !"".equals(String.valueOf(taskId))) ? ""+countParamEmpty++ : (long)taskId));
}catch(Exception ex){
logger.error("时间参数处理转换异常,{}", ex);
String rangeNhourOfTime = CalendarUtils.getRangeOfhour(DateUtils.getDateTime());
String startTemp = CalendarUtils.getRangeNhourOfTime(rangeNhourOfTime, -1);
int typeId = eventMonitorOrBlock.getReportType();
eventMonitorOrBlock = new EventMonitorOrBlock();
eventMonitorOrBlock.setSearchReportStartTime(startTemp);
eventMonitorOrBlock.setReportType(typeId);
logger.info("获取"+logMark+"API请求参数转换异常,默认查询上一小时"+startTemp+"到现在的数据");
}
if(countParamEmpty==6){
String rangeNhourOfTime = CalendarUtils.getRangeOfhour(DateUtils.getDateTime());
String startTemp = CalendarUtils.getRangeNhourOfTime(rangeNhourOfTime, -1);
int typeId = eventMonitorOrBlock.getReportType();
eventMonitorOrBlock = new EventMonitorOrBlock();
eventMonitorOrBlock.setSearchReportStartTime(startTemp);
eventMonitorOrBlock.setReportType(typeId);
logger.info("获取"+logMark+"API请求参数为空,默认查询上一小时"+startTemp+"到现在的数据");
}
try {
list = eventServiceDao.getEventsMonitorOrBlock(eventMonitorOrBlock);
} catch (Exception ex) {
logger.error(logMark+"查询异常,{}", ex);
}
page.setList(list);
return page;
}
}