2018-06-10 16:18:34 +08:00
|
|
|
package com.nis.web.controller.restful;
|
|
|
|
|
|
2018-07-02 16:10:48 +08:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.List;
|
2018-06-22 10:48:53 +08:00
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
2018-10-18 19:19:59 +08:00
|
|
|
import com.zdjizhi.utils.StringUtil;
|
2018-06-22 10:48:53 +08:00
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.ui.Model;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
2018-07-02 16:10:48 +08:00
|
|
|
import com.nis.domain.LogEntity;
|
2018-06-10 16:18:34 +08:00
|
|
|
import com.nis.domain.Page;
|
2018-07-13 12:06:34 +08:00
|
|
|
import com.nis.domain.restful.DkBehaviorLog;
|
2018-07-19 19:30:14 +08:00
|
|
|
import com.nis.domain.restful.PxyHttpLog;
|
2018-07-02 16:10:48 +08:00
|
|
|
import com.nis.restful.RestServiceException;
|
|
|
|
|
import com.nis.util.Configurations;
|
2018-06-10 16:18:34 +08:00
|
|
|
import com.nis.util.Constants;
|
2018-07-02 16:10:48 +08:00
|
|
|
import com.nis.util.DateUtils;
|
2018-08-31 15:11:40 +08:00
|
|
|
import com.nis.util.LogJDBCByDruid;
|
2018-07-02 16:10:48 +08:00
|
|
|
import com.nis.util.JsonMapper;
|
2018-06-10 16:18:34 +08:00
|
|
|
import com.nis.web.controller.BaseRestController;
|
2018-07-19 19:30:14 +08:00
|
|
|
import com.nis.web.service.AuditLogThread;
|
2018-07-02 16:10:48 +08:00
|
|
|
import com.nis.web.service.HiveSqlService;
|
2018-06-10 16:18:34 +08:00
|
|
|
import com.nis.web.service.ServicesRequestLogService;
|
2018-07-24 16:57:48 +08:00
|
|
|
import com.nis.web.service.restful.NtcLogService;
|
2018-06-10 16:18:34 +08:00
|
|
|
import com.wordnik.swagger.annotations.Api;
|
|
|
|
|
import com.wordnik.swagger.annotations.ApiOperation;
|
|
|
|
|
|
|
|
|
|
/**
|
2018-07-02 16:10:48 +08:00
|
|
|
*
|
|
|
|
|
* <p>Title: LogController</p>
|
|
|
|
|
* <p>Description: 日志查询controller</p>
|
|
|
|
|
* <p>Company: IIE</p>
|
|
|
|
|
* @author rkg
|
|
|
|
|
* @date 2018年7月2日
|
|
|
|
|
*
|
2018-06-10 16:18:34 +08:00
|
|
|
*/
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("${servicePath}/log/v1")
|
|
|
|
|
@Api(value = "LogController", description = "配置命中日志基本服务接口")
|
2018-07-02 16:10:48 +08:00
|
|
|
public class LogController extends BaseRestController {
|
|
|
|
|
@Autowired
|
|
|
|
|
protected ServicesRequestLogService servicesRequestLogService;
|
2018-07-12 16:34:17 +08:00
|
|
|
|
|
|
|
|
@Autowired
|
2018-07-24 16:57:48 +08:00
|
|
|
protected NtcLogService ntcLogService;
|
2018-07-02 16:10:48 +08:00
|
|
|
|
2018-07-24 17:45:43 +08:00
|
|
|
@RequestMapping(value = "/dkBehaviorLogs", method = RequestMethod.GET)
|
|
|
|
|
@ApiOperation(value = "行为识别日志查询", httpMethod = "GET", notes = "对日志功能“行为识别”提供数据基础查询服务")
|
|
|
|
|
public Map<String, ?> dkBehaviorLogs(Page page, DkBehaviorLog dkBehaviorLog, Model model, HttpServletRequest request,
|
2018-07-24 11:33:22 +08:00
|
|
|
HttpServletResponse response) {
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
|
|
|
|
|
request, null);
|
|
|
|
|
|
2018-07-24 17:45:43 +08:00
|
|
|
Page<DkBehaviorLog> logPage = null;
|
2018-07-24 11:33:22 +08:00
|
|
|
try {
|
2018-07-24 17:45:43 +08:00
|
|
|
resetTime(dkBehaviorLog);
|
|
|
|
|
ntcLogService.queryConditionCheck(auditLogThread, start, dkBehaviorLog, DkBehaviorLog.class, page);
|
|
|
|
|
logPage = new Page<DkBehaviorLog>();
|
2018-07-24 11:33:22 +08:00
|
|
|
logPage.setPageNo(page.getPageNo());
|
|
|
|
|
logPage.setPageSize(page.getPageSize());
|
|
|
|
|
String orderBy = "";
|
|
|
|
|
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
|
2018-07-24 17:45:43 +08:00
|
|
|
orderBy = Page.getOrderBySql(DkBehaviorLog.class.getSimpleName(), page.getOrderBy());
|
2018-07-24 11:33:22 +08:00
|
|
|
} else {
|
|
|
|
|
orderBy = "found_Time";
|
|
|
|
|
}
|
2018-08-20 15:20:44 +08:00
|
|
|
String sql = HiveSqlService.getSql(page, dkBehaviorLog,
|
2018-09-04 09:24:22 +08:00
|
|
|
getTableName(DkBehaviorLog.class.getSimpleName() + "HiveTable", "DK_BEHAVIOR_LOG"),
|
2018-07-24 11:33:22 +08:00
|
|
|
getCol2Col(), orderBy, null);
|
2018-08-31 15:11:40 +08:00
|
|
|
Map<String, List<Object>> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, DkBehaviorLog.class, "foundTime",
|
2018-07-24 11:33:22 +08:00
|
|
|
"recvTime");
|
|
|
|
|
if (tableMapping == null) {
|
|
|
|
|
logPage.setList(new ArrayList());
|
|
|
|
|
} else {
|
|
|
|
|
List list = tableMapping.get("obj");
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
String jsonString = JsonMapper.toJsonString(list);
|
2018-07-24 17:45:43 +08:00
|
|
|
List<DkBehaviorLog> List = (java.util.List<DkBehaviorLog>) JsonMapper.fromJsonList(jsonString,
|
|
|
|
|
DkBehaviorLog.class);
|
2018-07-24 11:33:22 +08:00
|
|
|
logPage.setList(List);
|
|
|
|
|
logPage.setCount(List.size());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
logPage.setList(new ArrayList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
|
|
|
|
logger.error(e);
|
|
|
|
|
if (!(e instanceof RestServiceException)) {
|
2018-07-24 17:45:43 +08:00
|
|
|
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "行为识别日志检索失败");
|
2018-07-24 11:33:22 +08:00
|
|
|
}
|
|
|
|
|
throw ((RestServiceException) e);
|
|
|
|
|
}
|
2018-07-24 17:45:43 +08:00
|
|
|
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "行为识别日志检索成功",
|
2018-07-24 11:33:22 +08:00
|
|
|
logPage, 0);
|
|
|
|
|
}
|
2018-07-19 19:30:14 +08:00
|
|
|
@RequestMapping(value = "/pxyHttpLogs", method = RequestMethod.GET)
|
|
|
|
|
@ApiOperation(value = "PXY HTTP日志查询", httpMethod = "GET", notes = "对日志功能“控制策略”-“HTTP日志”提供数据基础查询服务")
|
|
|
|
|
public Map<String, ?> pxyHttpLogs(Page page, PxyHttpLog pxyHttpLog, Model model, HttpServletRequest request,
|
|
|
|
|
HttpServletResponse response) {
|
|
|
|
|
long start = System.currentTimeMillis();
|
|
|
|
|
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
|
|
|
|
|
request, null);
|
|
|
|
|
|
|
|
|
|
Page<PxyHttpLog> logPage = null;
|
|
|
|
|
try {
|
|
|
|
|
resetTime(pxyHttpLog);
|
2018-07-24 16:57:48 +08:00
|
|
|
ntcLogService.queryConditionCheck(auditLogThread, start, pxyHttpLog, PxyHttpLog.class, page);
|
2018-07-19 19:30:14 +08:00
|
|
|
logPage = new Page<PxyHttpLog>();
|
|
|
|
|
logPage.setPageNo(page.getPageNo());
|
|
|
|
|
logPage.setPageSize(page.getPageSize());
|
|
|
|
|
String orderBy = "";
|
|
|
|
|
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
|
|
|
|
|
orderBy = Page.getOrderBySql(PxyHttpLog.class.getSimpleName(), page.getOrderBy());
|
|
|
|
|
} else {
|
|
|
|
|
orderBy = "found_Time";
|
|
|
|
|
}
|
2018-08-20 15:20:44 +08:00
|
|
|
String sql = HiveSqlService.getSql(page, pxyHttpLog,
|
2018-09-04 09:24:22 +08:00
|
|
|
getTableName(PxyHttpLog.class.getSimpleName() + "HiveTable", "PXY_HTTP_LOG"),
|
2018-07-19 19:30:14 +08:00
|
|
|
getCol2Col(), orderBy, null);
|
2018-08-31 15:11:40 +08:00
|
|
|
Map<String, List<Object>> tableMapping = new LogJDBCByDruid().tableMapping(page, null, sql, PxyHttpLog.class, "foundTime",
|
2018-07-19 19:30:14 +08:00
|
|
|
"recvTime");
|
|
|
|
|
if (tableMapping == null) {
|
|
|
|
|
logPage.setList(new ArrayList());
|
|
|
|
|
} else {
|
|
|
|
|
List list = tableMapping.get("obj");
|
|
|
|
|
if (list.size() > 0) {
|
|
|
|
|
String jsonString = JsonMapper.toJsonString(list);
|
|
|
|
|
List<PxyHttpLog> List = (java.util.List<PxyHttpLog>) JsonMapper.fromJsonList(jsonString,
|
|
|
|
|
PxyHttpLog.class);
|
|
|
|
|
logPage.setList(List);
|
|
|
|
|
logPage.setCount(List.size());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
logPage.setList(new ArrayList());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
auditLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
|
|
|
|
|
logger.error(e);
|
|
|
|
|
if (!(e instanceof RestServiceException)) {
|
|
|
|
|
e = new RestServiceException(auditLogThread, System.currentTimeMillis() - start, "PXY HTTP日志检索失败");
|
|
|
|
|
}
|
|
|
|
|
throw ((RestServiceException) e);
|
|
|
|
|
}
|
|
|
|
|
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PXY HTTP日志检索成功",
|
|
|
|
|
logPage, 0);
|
|
|
|
|
}
|
2018-07-06 18:07:16 +08:00
|
|
|
|
2018-07-16 14:36:43 +08:00
|
|
|
|
2018-07-06 18:07:16 +08:00
|
|
|
|
|
|
|
|
|
2018-07-02 16:10:48 +08:00
|
|
|
/**
|
|
|
|
|
*判断开始和结束时间是否为null,如果为null则初始化时间
|
|
|
|
|
* @param entity
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public void resetTime(LogEntity<?> entity) throws Exception {
|
2018-10-18 19:19:59 +08:00
|
|
|
if (StringUtil.isEmpty(entity.getSearchFoundStartTime())&& StringUtil.isEmpty(entity.getSearchFoundEndTime())) {
|
2018-08-28 17:05:01 +08:00
|
|
|
Map<String, String> map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(),
|
|
|
|
|
entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "minute");
|
|
|
|
|
entity.setSearchFoundStartTime(map.get("startTime"));
|
|
|
|
|
entity.setSearchFoundEndTime(map.get("endTime"));
|
|
|
|
|
}
|
2018-07-02 16:10:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 将searchFoundStartTime,searchFoundEndTime与foundTime进行关联
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public Map<String, Map<String, String>> getCol2Col() {
|
|
|
|
|
Map<String, Map<String, String>> col2col = new HashMap<String, Map<String, String>>();
|
|
|
|
|
Map<String, String> startMap = new HashMap<String, String>();
|
|
|
|
|
startMap.put("start", "foundTime");
|
|
|
|
|
col2col.put("searchFoundStartTime", startMap);
|
|
|
|
|
Map<String, String> endMap = new HashMap<String, String>();
|
|
|
|
|
endMap.put("end", "foundTime");
|
|
|
|
|
col2col.put("searchFoundEndTime", endMap);
|
|
|
|
|
return col2col;
|
|
|
|
|
}
|
2018-06-12 10:03:32 +08:00
|
|
|
|
2018-06-10 16:18:34 +08:00
|
|
|
}
|