1:删除无用的数据库连接

2:修改pom中使用的hive版本为2.1.1
3:添加IP地址日志查询服务
This commit is contained in:
RenKaiGe-Office
2018-07-02 16:10:48 +08:00
parent 4f4ad8464a
commit 0530479502
22 changed files with 731 additions and 901 deletions

View File

@@ -1,5 +1,10 @@
package com.nis.web.controller.restful;
import java.sql.ResultSet;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
@@ -11,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.nis.domain.LogEntity;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcDnsLog;
import com.nis.domain.restful.NtcFtpLog;
@@ -24,8 +30,15 @@ import com.nis.domain.restful.NtcPptpLog;
import com.nis.domain.restful.NtcPzReport;
import com.nis.domain.restful.NtcSshLog;
import com.nis.domain.restful.NtcSslLog;
import com.nis.restful.RestServiceException;
import com.nis.util.Configurations;
import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.HiveJDBC;
import com.nis.util.JsonMapper;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.BaseLogService;
import com.nis.web.service.HiveSqlService;
import com.nis.web.service.SaveRequestLogThread;
import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.LogTestService;
@@ -33,252 +46,333 @@ import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
/**
* Created by darnell on 2018/6/10.
*
* <p>Title: LogController</p>
* <p>Description: 日志查询controller</p>
* <p>Company: IIE</p>
* @author rkg
* @date 2018年7月2日
*
*/
@RestController
@RequestMapping("${servicePath}/log/v1")
@Api(value = "LogController", description = "配置命中日志基本服务接口")
public class LogController extends BaseRestController{
@Autowired
public LogTestService testService;
@Autowired
protected ServicesRequestLogService servicesRequestLogService;
@RequestMapping(value = "/ntcIpLogs", method = RequestMethod.GET)
@ApiOperation(value = "IP地址日志查询", httpMethod = "GET", notes = "对应配置为IP地址管理存储动作为阻断与监测的命中日志。对日志功能IP地址提供数据基础查询服务")
public Map<String, ?> ntcIpLogs(Page page, NtcIpLog ntcIpLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcIpLog> ntcIpLogPage = new Page<>();
try {
ntcIpLogPage = testService.findNtcIpLogPage(
new Page<NtcIpLog>(request, response, NtcIpLog.class), ntcIpLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IP地址日志检索成功", ntcIpLogPage, 0);
}
@RequestMapping(value = "/ntcHttpLogs", method = RequestMethod.GET)
@ApiOperation(value = "HTTP日志查询", httpMethod = "GET", notes = "对应配置为“网站管理-HTTP”存储动作为阻断与监测的命中日志。对日志功能“网站管理-HTTP”提供数据基础查询服务")
public Map<String, ?> ntcHttpLogs(Page page, NtcHttpLog ntcHttpLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcHttpLog> ntcHttpLogPage = new Page<>();
try {
ntcHttpLogPage = testService.findNtcHttpLogPage(
new Page<NtcHttpLog>(request, response, NtcHttpLog.class), ntcHttpLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Http日志检索成功", ntcHttpLogPage, 0);
}
@RequestMapping(value = "/ntcDnsLogs", method = RequestMethod.GET)
@ApiOperation(value = "DNS日志查询", httpMethod = "GET", notes = "对应配置为“网站管理-DNS”存储动作为阻断与监测的命中日志。对日志功能“网站管理-DNS”提供数据基础查询服务。")
public Map<String, ?> ntcDnsLogs(Page page, NtcDnsLog ntcDnsLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcDnsLog> ntcDnsLogPage = new Page<>();
try {
ntcDnsLogPage = testService.findNtcDnsLogPage(
new Page<NtcDnsLog>(request, response, NtcDnsLog.class), ntcDnsLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Dns日志检索成功", ntcDnsLogPage, 0);
}
@RequestMapping(value = "/ntcMailLogs", method = RequestMethod.GET)
@ApiOperation(value = "EMAIL日志查询", httpMethod = "GET", notes = "对应配置为“邮件管理”,存储动作为阻断与监测的命中日志。对日志功能“邮件管理”提供数据基础查询服务。")
public Map<String, ?> ntcMailLogs(Page page, NtcMailLog ntcMailLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcMailLog> ntcMailLogPage = new Page<>();
try {
ntcMailLogPage = testService.findNtcMailLogPage(
new Page<NtcMailLog>(request, response, NtcMailLog.class), ntcMailLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Mail日志检索成功", ntcMailLogPage, 0);
}
@RequestMapping(value = "/ntcSslLogs", method = RequestMethod.GET)
@ApiOperation(value = "SSL日志查询", httpMethod = "GET", notes = "对应配置为“网站管理-SSL”存储动作为阻断与监测的命中日志。对日志功能“网站管理-SSL”提供数据基础查询服务。")
public Map<String, ?> ntcSslLogs(Page page, NtcSslLog ntcSslLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcSslLog> ntcSslLogPage = new Page<>();
try {
ntcSslLogPage = testService.findNtcSslLogPage(
new Page<NtcSslLog>(request, response, NtcSslLog.class), ntcSslLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSL日志检索成功", ntcSslLogPage, 0);
}
@RequestMapping(value = "/ntcPptpLogs", method = RequestMethod.GET)
@ApiOperation(value = "PPTP日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-PPTP”存储动作为阻断与监测的命中日志。对日志功能“隧道管理-PPTP”提供数据基础查询服务。")
public Map<String, ?> ntcPptpLogs(Page page, NtcPptpLog ntcPptpLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcPptpLog> ntcPptpLogPage = new Page<>();
try {
ntcPptpLogPage = testService.findNtcPptpLogPage(
new Page<NtcPptpLog>(request, response, NtcPptpLog.class), ntcPptpLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PPTP日志检索成功", ntcPptpLogPage, 0);
}
@RequestMapping(value = "/ntcL2tpLogs", method = RequestMethod.GET)
@ApiOperation(value = "L2TP日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-L2TP”存储动作为阻断与监测的命中日志。对日志功能“隧道管理- L2TP”提供数据基础查询服务。")
public Map<String, ?> ntcL2tpLogs(Page page, NtcL2tpLog ntcL2tpLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcL2tpLog> ntcL2tpLogPage = new Page<>();
try {
ntcL2tpLogPage = testService.findNtcL2tpLogPage(
new Page<NtcL2tpLog>(request, response, NtcL2tpLog.class), ntcL2tpLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "L2TP日志检索成功", ntcL2tpLogPage, 0);
}
@RequestMapping(value = "/ntcOpenvpnLogs", method = RequestMethod.GET)
@ApiOperation(value = "OPENVPN日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-OPENVPN”存储动作为阻断与监测的命中日志。对日志功能“隧道管理- OPENVPN”提供数据基础查询服务。")
public Map<String, ?> ntcOpenvpnLogs(Page page, NtcOpenvpnLog ntcOpenvpnLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcOpenvpnLog> ntcOpenvpnLogPage = new Page<>();
try {
ntcOpenvpnLogPage = testService.findNtcOpenvpnLogPage(
new Page<NtcOpenvpnLog>(request, response, NtcOpenvpnLog.class), ntcOpenvpnLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Openvpn日志检索成功", ntcOpenvpnLogPage, 0);
}
@RequestMapping(value = "/ntcIpsecLogs", method = RequestMethod.GET)
@ApiOperation(value = "IPSEC日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-IPSEC”存储动作为监测的命中日志。对日志功能“隧道管理- IPSEC”提供数据基础查询服务。")
public Map<String, ?> ntcIpsecLogs(Page page, NtcIpsecLog ntcIpsecLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcIpsecLog> ntcIpsecLogPage = new Page<>();
try {
ntcIpsecLogPage = testService.findNtcIpsecLogPage(
new Page<NtcIpsecLog>(request, response, NtcIpsecLog.class), ntcIpsecLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IPSEC日志检索成功", ntcIpsecLogPage, 0);
}
@RequestMapping(value = "/ntcSshLogs", method = RequestMethod.GET)
@ApiOperation(value = "SSH日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-SSH”存储动作为阻断与监测的命中日志。对日志功能“隧道管理- SSH”提供数据基础查询服务。")
public Map<String, ?> ntcSshLogs(Page page, NtcSshLog ntcSshLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcSshLog> ntcSshLogPage = new Page<>();
try {
ntcSshLogPage = testService.findNtcSshLogPage(
new Page<NtcSshLog>(request, response, NtcSshLog.class), ntcSshLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSH日志检索成功", ntcSshLogPage, 0);
}
@RequestMapping(value = "/ntcFtpLogs", method = RequestMethod.GET)
@ApiOperation(value = "FTP日志查询", httpMethod = "GET", notes = "对应配置为“文件传输-FTP”,存储动作为阻断与监测的命中日志。对日志功能“文件传输-FTP”提供数据基础查询服务。")
public Map<String, ?> ntcFtpLogs(Page page, NtcFtpLog ntcFtpLog, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<NtcFtpLog> ntcFtpLogPage = new Page<>();
try {
ntcFtpLogPage = testService.findNtcFtpLogPage(
new Page<NtcFtpLog>(request, response, NtcSshLog.class), ntcFtpLog);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "FTP日志检索成功", ntcFtpLogPage, 0);
}
@RequestMapping(value = "/ntcPzReport", method = RequestMethod.GET)
@ApiOperation(value = "配置日志总量统计", httpMethod = "GET", notes = "配置命中日志数量实时统计报表,对外提供多种数据表现形式,具体可应用于界面配置命中总量业务、配置报表业务等")
public Map<String, ?> ntcPzReport(Page page, NtcPzReport ntcPzReport, Model model, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Page<?> ntcPzReportPage = new Page<>();
try {
ntcPzReportPage = testService.findNtcPzReport(new Page<NtcPzReport>(request, response,NtcPzReport.class), ntcPzReport);
} catch(Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "配置总量统计成功", ntcPzReportPage, 0);
}
public class LogController extends BaseRestController {
@Autowired
public LogTestService testService;
@Autowired
protected ServicesRequestLogService servicesRequestLogService;
@RequestMapping(value = "/ntcIpLogs", method = RequestMethod.GET)
@ApiOperation(value = "IP地址日志查询", httpMethod = "GET", notes = "对应配置为IP地址管理存储动作为阻断与监测的命中日志。对日志功能IP地址提供数据基础查询服务")
public Map<String, ?> ntcIpLogs(Page page, NtcIpLog ntcIpLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcIpLog> ntcIpLogPage = null;
try {
testService.queryConditionCheck(auditLogThread, start, ntcIpLog, NtcIpLog.class, page);
ntcIpLogPage = new Page<NtcIpLog>();
String orderBy = "";
if (null != page.getOrderBy() && !page.getOrderBy().equals("")) {
orderBy = page.getOrderBySql(NtcIpLog.class.getSimpleName(), page.getOrderBy());
} else {
orderBy = "found_Time";
}
ResultSet rs = HiveSqlService.getResultSet(page, ntcIpLog,
Configurations.getStringProperty(NtcIpLog.class.getSimpleName() + "HiveTable", "ntc_ip_log"),
getCol2Col(), orderBy, null);
Map<String, List> tableMapping = HiveJDBC.tableMapping(page, null, rs, NtcIpLog.class, "foundTime",
"recvTime");
if (tableMapping == null) {
ntcIpLogPage.setList(new ArrayList());
} else {
List list = new ArrayList();
if (tableMapping.get("obj").size() > page.getPageSize()) {
list = tableMapping.get("obj").subList(0, page.getPageSize());
} else {
list = tableMapping.get("obj").subList(0, tableMapping.get("obj").size());
}
if (list.size() > 0) {
String jsonString = JsonMapper.toJsonString(list);
List<NtcIpLog> List = (java.util.List<NtcIpLog>) JsonMapper.fromJsonList(jsonString,
NtcIpLog.class);
ntcIpLogPage.setList(List);
} else {
ntcIpLogPage.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, "HTTP协议请求日志检索失败");
}
throw ((RestServiceException) e);
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IP地址日志检索成功",
ntcIpLogPage, 0);
}
@RequestMapping(value = "/ntcHttpLogs", method = RequestMethod.GET)
@ApiOperation(value = "HTTP日志查询", httpMethod = "GET", notes = "对应配置为“网站管理-HTTP”存储动作为阻断与监测的命中日志。对日志功能“网站管理-HTTP”提供数据基础查询服务")
public Map<String, ?> ntcHttpLogs(Page page, NtcHttpLog ntcHttpLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcHttpLog> ntcHttpLogPage = new Page<>();
try {
ntcHttpLogPage = testService.findNtcHttpLogPage(new Page<NtcHttpLog>(request, response, NtcHttpLog.class),
ntcHttpLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Http日志检索成功",
ntcHttpLogPage, 0);
}
@RequestMapping(value = "/ntcDnsLogs", method = RequestMethod.GET)
@ApiOperation(value = "DNS日志查询", httpMethod = "GET", notes = "对应配置为“网站管理-DNS”存储动作为阻断与监测的命中日志。对日志功能“网站管理-DNS”提供数据基础查询服务。")
public Map<String, ?> ntcDnsLogs(Page page, NtcDnsLog ntcDnsLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcDnsLog> ntcDnsLogPage = new Page<>();
try {
ntcDnsLogPage = testService.findNtcDnsLogPage(new Page<NtcDnsLog>(request, response, NtcDnsLog.class),
ntcDnsLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Dns日志检索成功",
ntcDnsLogPage, 0);
}
@RequestMapping(value = "/ntcMailLogs", method = RequestMethod.GET)
@ApiOperation(value = "EMAIL日志查询", httpMethod = "GET", notes = "对应配置为“邮件管理”,存储动作为阻断与监测的命中日志。对日志功能“邮件管理”提供数据基础查询服务。")
public Map<String, ?> ntcMailLogs(Page page, NtcMailLog ntcMailLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcMailLog> ntcMailLogPage = new Page<>();
try {
ntcMailLogPage = testService.findNtcMailLogPage(new Page<NtcMailLog>(request, response, NtcMailLog.class),
ntcMailLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Mail日志检索成功",
ntcMailLogPage, 0);
}
@RequestMapping(value = "/ntcSslLogs", method = RequestMethod.GET)
@ApiOperation(value = "SSL日志查询", httpMethod = "GET", notes = "对应配置为“网站管理-SSL”存储动作为阻断与监测的命中日志。对日志功能“网站管理-SSL”提供数据基础查询服务。")
public Map<String, ?> ntcSslLogs(Page page, NtcSslLog ntcSslLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcSslLog> ntcSslLogPage = new Page<>();
try {
ntcSslLogPage = testService.findNtcSslLogPage(new Page<NtcSslLog>(request, response, NtcSslLog.class),
ntcSslLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSL日志检索成功",
ntcSslLogPage, 0);
}
@RequestMapping(value = "/ntcPptpLogs", method = RequestMethod.GET)
@ApiOperation(value = "PPTP日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-PPTP”存储动作为阻断与监测的命中日志。对日志功能“隧道管理-PPTP”提供数据基础查询服务。")
public Map<String, ?> ntcPptpLogs(Page page, NtcPptpLog ntcPptpLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcPptpLog> ntcPptpLogPage = new Page<>();
try {
ntcPptpLogPage = testService.findNtcPptpLogPage(new Page<NtcPptpLog>(request, response, NtcPptpLog.class),
ntcPptpLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "PPTP日志检索成功",
ntcPptpLogPage, 0);
}
@RequestMapping(value = "/ntcL2tpLogs", method = RequestMethod.GET)
@ApiOperation(value = "L2TP日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-L2TP”存储动作为阻断与监测的命中日志。对日志功能“隧道管理- L2TP”提供数据基础查询服务。")
public Map<String, ?> ntcL2tpLogs(Page page, NtcL2tpLog ntcL2tpLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcL2tpLog> ntcL2tpLogPage = new Page<>();
try {
ntcL2tpLogPage = testService.findNtcL2tpLogPage(new Page<NtcL2tpLog>(request, response, NtcL2tpLog.class),
ntcL2tpLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "L2TP日志检索成功",
ntcL2tpLogPage, 0);
}
@RequestMapping(value = "/ntcOpenvpnLogs", method = RequestMethod.GET)
@ApiOperation(value = "OPENVPN日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-OPENVPN”存储动作为阻断与监测的命中日志。对日志功能“隧道管理- OPENVPN”提供数据基础查询服务。")
public Map<String, ?> ntcOpenvpnLogs(Page page, NtcOpenvpnLog ntcOpenvpnLog, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcOpenvpnLog> ntcOpenvpnLogPage = new Page<>();
try {
ntcOpenvpnLogPage = testService.findNtcOpenvpnLogPage(
new Page<NtcOpenvpnLog>(request, response, NtcOpenvpnLog.class), ntcOpenvpnLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "Openvpn日志检索成功",
ntcOpenvpnLogPage, 0);
}
@RequestMapping(value = "/ntcIpsecLogs", method = RequestMethod.GET)
@ApiOperation(value = "IPSEC日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-IPSEC”,存储动作为监测的命中日志。对日志功能“隧道管理- IPSEC”提供数据基础查询服务。")
public Map<String, ?> ntcIpsecLogs(Page page, NtcIpsecLog ntcIpsecLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcIpsecLog> ntcIpsecLogPage = new Page<>();
try {
ntcIpsecLogPage = testService
.findNtcIpsecLogPage(new Page<NtcIpsecLog>(request, response, NtcIpsecLog.class), ntcIpsecLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IPSEC日志检索成功",
ntcIpsecLogPage, 0);
}
@RequestMapping(value = "/ntcSshLogs", method = RequestMethod.GET)
@ApiOperation(value = "SSH日志查询", httpMethod = "GET", notes = "对应配置为“隧道管理-SSH”存储动作为阻断与监测的命中日志。对日志功能“隧道管理- SSH”提供数据基础查询服务。")
public Map<String, ?> ntcSshLogs(Page page, NtcSshLog ntcSshLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcSshLog> ntcSshLogPage = new Page<>();
try {
ntcSshLogPage = testService.findNtcSshLogPage(new Page<NtcSshLog>(request, response, NtcSshLog.class),
ntcSshLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "SSH日志检索成功",
ntcSshLogPage, 0);
}
@RequestMapping(value = "/ntcFtpLogs", method = RequestMethod.GET)
@ApiOperation(value = "FTP日志查询", httpMethod = "GET", notes = "对应配置为“文件传输-FTP”存储动作为阻断与监测的命中日志。对日志功能“文件传输-FTP”提供数据基础查询服务。")
public Map<String, ?> ntcFtpLogs(Page page, NtcFtpLog ntcFtpLog, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<NtcFtpLog> ntcFtpLogPage = new Page<>();
try {
ntcFtpLogPage = testService.findNtcFtpLogPage(new Page<NtcFtpLog>(request, response, NtcSshLog.class),
ntcFtpLog);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "FTP日志检索成功",
ntcFtpLogPage, 0);
}
@RequestMapping(value = "/ntcPzReport", method = RequestMethod.GET)
@ApiOperation(value = "配置日志总量统计", httpMethod = "GET", notes = "配置命中日志数量实时统计报表,对外提供多种数据表现形式,具体可应用于界面配置命中总量业务、配置报表业务等")
public Map<String, ?> ntcPzReport(Page page, NtcPzReport ntcPzReport, Model model, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
SaveRequestLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET,
request, null);
Page<?> ntcPzReportPage = new Page<>();
try {
ntcPzReportPage = testService.findNtcPzReport(new Page<NtcPzReport>(request, response, NtcPzReport.class),
ntcPzReport);
} catch (Exception e) {
e.printStackTrace();
}
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "配置总量统计成功",
ntcPzReportPage, 0);
}
/**
*判断开始和结束时间是否为null,如果为null则初始化时间
* @param entity
* @throws Exception
*/
public void resetTime(LogEntity<?> entity) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Map<String, String> map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(),
entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "log");
entity.setSearchFoundStartTime(map.get("startTime"));
entity.setSearchFoundEndTime(map.get("endTime"));
}
/**
* 将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;
}
}

View File

@@ -0,0 +1,24 @@
package com.nis.web.dao;
import java.util.List;
import com.nis.domain.LogEntity;
import com.nis.domain.restful.NtcIpLog;
/**
*
* <p>Title: DfLogSearchDao</p>
* <p>Description: 日志查询dao</p>
* <p>Company: IIE</p>
* @author rkg
* @date 2018年7月2日
*
*/
@MyBatisDao
public interface DfLogSearchDao extends CrudDao<LogEntity> {
// List<NtcIpLog> findNtcIpLog(NtcIpLog log);
}

View File

@@ -0,0 +1,49 @@
<?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.DfLogSearchDao">
<!-- 所有日志表的公共属性 -->
<sql id="commonPorperty">
cfg_id ,
found_time ,
recv_time ,
trans_proto ,
addr_type ,
d_ip ,
s_ip ,
d_port ,
s_port ,
service ,
entrance_id ,
device_id ,
direction ,
stream_dir ,
cap_ip ,
addr_list ,
user_region
</sql>
<resultMap id="NtcIpLogMap" type="com.nis.domain.restful.NtcIpLog">
<result column="cfg_id" jdbcType="BIGINT" property="cfgId" />
<result column="found_Time" jdbcType="TIMESTAMP" property="foundTime" />
<result column="recv_Time" jdbcType="TIMESTAMP" property="recvTime" />
<result column="trans_proto" jdbcType="VARCHAR" property="transProto" />
<result column="addr_type" jdbcType="INTEGER" property="addrType" />
<result column="d_ip" jdbcType="VARCHAR" property="dIp" />
<result column="s_ip" jdbcType="VARCHAR" property="sIp" />
<result column="d_port" jdbcType="VARCHAR" property="dPort" />
<result column="s_port" jdbcType="VARCHAR" property="sPort" />
<result column="service" jdbcType="INTEGER" property="service" />
<result column="entrance_id" jdbcType="BIGINT" property="entranceId" />
<result column="device_id" jdbcType="INTEGER" property="deviceId" />
<result column="direction" jdbcType="INTEGER" property="direction" />
<result column="stream_dir" jdbcType="INTEGER" property="streamDir" />
<result column="cap_ip" jdbcType="VARCHAR" property="capIp" />
<result column="addr_list" jdbcType="VARCHAR" property="addrList" />
<result column="user_region" jdbcType="VARCHAR" property="userRegion" />
</resultMap>
</mapper>

View File

@@ -40,6 +40,7 @@ public abstract class BaseLogService {
protected final Logger logger = Logger.getLogger(this.getClass());
@Autowired
protected ElasticsearchSqlDao elasticsearchSqlDao;
/**
* wx checkCloumnIsExist(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 可选)
*
@@ -126,34 +127,58 @@ public abstract class BaseLogService {
}
}
public void queryConditionCheck(SaveRequestLogThread thread,long start,LogEntity<?> entity,Class clazz,Page page) {
logger.info("请求参数校验开始----"+System.currentTimeMillis());
/**
* 验证日志查询条件格式是否正确
* @param thread
* @param start
* @param entity
* @param clazz
* @param page
*/
public void queryConditionCheck(SaveRequestLogThread thread, long start, LogEntity<?> entity, Class clazz,
Page page) {
logger.info("请求参数校验开始----" + System.currentTimeMillis());
try {
if (!StringUtil.isBlank(entity.getSearchCfgId())) {
Long.parseLong(entity.getSearchCfgId());
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchCfgId参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchCfgId参数错误");
}
try {
if (!StringUtil.isBlank(entity.getSearchDirection())) {
Integer.parseInt(entity.getSearchDirection());
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "getSearchDirection参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "getSearchDirection参数错误");
}
try {
if (!StringUtil.isBlank(entity.getSearchEntranceId())) {
Long.parseLong(entity.getSearchEntranceId());
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchEntranceId参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchEntranceId参数错误");
}
@@ -163,12 +188,12 @@ public abstract class BaseLogService {
sdf.parse(entity.getSearchFoundEndTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundEndTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundEndTime参数格式格式");
}
@@ -178,41 +203,41 @@ public abstract class BaseLogService {
sdf.parse(entity.getSearchFoundStartTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundStartTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchFoundStartTime参数错误");
}
try {
if (!StringUtil.isBlank(entity.getSearchServiceType())) {
Integer.parseInt(entity.getSearchServiceType());
if (!StringUtil.isBlank(entity.getSearchService())) {
Integer.parseInt(entity.getSearchService());
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchServiceType参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchServiceType参数错误");
}
try {
checkCloumnIsExist(thread,start,clazz, page);
checkCloumnIsExist(thread, start, clazz, page);
} catch (RestServiceException e) {
logger.error(e);
throw e;
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求参数错误");
}
logger.info("请求参数校验结束----"+System.currentTimeMillis());
logger.info("请求参数校验结束----" + System.currentTimeMillis());
}
@@ -232,12 +257,12 @@ public abstract class BaseLogService {
sdf.parse(entity.getSearchStatStartTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchStatStartTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchStatStartTime参数格式错误");
}
@@ -247,12 +272,12 @@ public abstract class BaseLogService {
sdf.parse(entity.getSearchStatEndTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchStatEndTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchStatEndTime参数错误");
}
@@ -261,30 +286,29 @@ public abstract class BaseLogService {
Integer.parseInt(entity.getSearchService());
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchService参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchService参数错误");
}
try {
checkCloumnIsExist(thread,start,clazz, page);
checkCloumnIsExist(thread, start, clazz, page);
} catch (RestServiceException e) {
logger.error(e);
throw e;
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求参数错误");
}
}
/**
* 管控实时统计公共查询字段验证
*
@@ -297,11 +321,11 @@ public abstract class BaseLogService {
sdf.parse(entity.getSearchReportEndTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportEndTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportEndTime参数格式格式");
}
try {
@@ -309,11 +333,11 @@ public abstract class BaseLogService {
sdf.parse(entity.getSearchReportStartTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportStartTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportStartTime参数错误");
}
@@ -322,11 +346,11 @@ public abstract class BaseLogService {
Integer.parseInt(entity.getSearchService());
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchService参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchService参数错误");
}
@@ -336,12 +360,12 @@ public abstract class BaseLogService {
Integer.parseInt(searchAttrType);
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchAttrType参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchAttrType参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchAttrType参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchAttrType参数错误");
}
try {
String searchLwhh = getSearchField(clazz, entity, "searchLwhh");
@@ -349,21 +373,21 @@ public abstract class BaseLogService {
Integer.parseInt(searchLwhh);
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchLwhh参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchLwhh参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchLwhh参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchLwhh参数错误");
}
try {
checkCloumnIsExist(thread,start,clazz, page);
checkCloumnIsExist(thread, start, clazz, page);
} catch (RestServiceException e) {
logger.error(e);
throw e;
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "请求参数错误");
}
@@ -375,31 +399,32 @@ public abstract class BaseLogService {
*
* @param entity
*/
public void queryConditionCheck(SaveRequestLogThread thread, long start,DfReportEntity entity, Class clazz, Page page) {
public void queryConditionCheck(SaveRequestLogThread thread, long start, DfReportEntity entity, Class clazz,
Page page) {
try {
if (!StringUtil.isBlank(entity.getSearchReportEndTime())) {
sdf.parse(entity.getSearchReportEndTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchReportEndTime参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchReportEndTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchReportEndTime参数格式格式");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchReportEndTime参数格式格式");
}
try {
if (!StringUtil.isBlank(entity.getSearchReportStartTime())) {
sdf.parse(entity.getSearchReportStartTime());
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchReportStartTime参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchReportStartTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchReportStartTime参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchReportStartTime参数错误");
}
try {
@@ -408,12 +433,12 @@ public abstract class BaseLogService {
Integer.parseInt(searchAttrType);
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchAttrType参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchAttrType参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchAttrType参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchAttrType参数错误");
}
try {
String searchLwhh = getSearchField(clazz, entity, "searchLwhh");
@@ -421,12 +446,12 @@ public abstract class BaseLogService {
Integer.parseInt(searchLwhh);
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchLwhh参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchLwhh参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchLwhh参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchLwhh参数错误");
}
try {
String searchId = getSearchField(clazz, entity, "searchId");
@@ -434,42 +459,41 @@ public abstract class BaseLogService {
Integer.parseInt(searchId);
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchId参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchId参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchId参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchId参数错误");
}
try {
String searchService = getSearchField(clazz, entity, "searchService");
if (!StringUtil.isBlank(searchService)) {
Integer.parseInt(searchService);
}
} catch (NumberFormatException e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchService参数格式错误",
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchService参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
throw new RestServiceException(thread,start,"searchService参数错误");
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
throw new RestServiceException(thread, start, "searchService参数错误");
}
try {
checkCloumnIsExist(thread,start,clazz, page);
checkCloumnIsExist(thread, start, clazz, page);
} catch (RestServiceException e) {
logger.error(e);
throw e;
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage()+" "+e.getCause());
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread,start,"请求参数错误");
throw new RestServiceException(thread, start, "请求参数错误");
}
}
/**
*
* @Title: getJedisKey
@@ -510,7 +534,7 @@ public abstract class BaseLogService {
String[] strArr = { "30" };
parapeterMapNew.put("pageSize", strArr);
}
}else{
} else {
if (parapeterMapNew.get("pageNo") != null) {
parapeterMapNew.remove("pageNo");
}
@@ -538,8 +562,7 @@ public abstract class BaseLogService {
return key;
}
protected String getSearchField(Class<?> clazz,
Serializable entity, String fieldName) {
protected String getSearchField(Class<?> clazz, Serializable entity, String fieldName) {
try {
Field field = clazz.getDeclaredField(fieldName);
field.setAccessible(true);

View File

@@ -14,7 +14,8 @@ import java.util.Map;
import org.apache.ibatis.mapping.ResultMap;
import org.apache.ibatis.mapping.ResultMapping;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.nis.domain.Page;
import com.nis.util.Configurations;
@@ -25,13 +26,12 @@ import com.nis.util.StringUtil;
import com.nis.util.redis.SaveRedisThread;
public class HiveSqlService {
private final static Logger logger = Logger.getLogger(HiveJDBC.class);
private final static Logger logger = LoggerFactory.getLogger(HiveSqlService.class);
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
public static ResultSet getResultSet(Page page, Object bean, String tableName,
Map<String, Map<String, String>> col2col, String orderBy, String searchActiveSys) throws Exception {
tableName = tableName.toLowerCase();
tableName = Configurations.getStringProperty(tableName, "t_" + tableName).trim();
String showColmun = getFiledsSql(bean.getClass().getSimpleName(), page.getFields());
StringBuffer sql = new StringBuffer();
Map<String, String> filedAndColumnMap = getFiledAndColumnMap(bean.getClass());
@@ -59,8 +59,10 @@ public class HiveSqlService {
Long foundTimePartStart = null;
Long foundTimePartEnd = null;
for (int i = 0; i < fields.length; i++) {
// 现在gwall日志表结构中只有数值和字符串两种类型,数值都是int类型没有bigint所以不需要加L,
Field f = fields[i];
String key = f.getName();// 获取字段名
String typeName = f.getType().getName();
if (f.getType().getName().equals("java.lang.String") && key.startsWith("search")) {
Object value = getFieldValue(bean, key);
if (value != null) {
@@ -81,7 +83,7 @@ public class HiveSqlService {
// value.toString().trim()
// + "','yyyy-mm-dd HH24:mi:ss')");
sql.append(" and " + filedAndColumnMap.get(col2col.get(key).get("start")) + ">="
+ value + "L");
+ value);
} else {
// sql.append(" and " +
// filedAndColumnMap.get(col2col.get(key).get("end"))
@@ -89,7 +91,7 @@ public class HiveSqlService {
// value.toString().trim()
// + "','yyyy-mm-dd HH24:mi:ss')");
sql.append(" and " + filedAndColumnMap.get(col2col.get(key).get("end")) + "<"
+ value + "L");
+ value);
}
}
} else {
@@ -98,39 +100,29 @@ public class HiveSqlService {
key = key.substring(0, 1).toLowerCase() + key.substring(1);
}
if (!value.toString().trim().equals("") && filedAndColumnMap.containsKey(key)
&& (key.toLowerCase().equals("cfgid")
|| key.toLowerCase().equals("entranceid"))) {
sql.append(
" and " + filedAndColumnMap.get(key) + "=" + value.toString().trim() + "L");
} else if (!value.toString().trim().equals("") && filedAndColumnMap.containsKey(key)
&& (key.toLowerCase().equals("protocol") || key.toLowerCase().equals("serverip")
|| key.toLowerCase().equals("clientip")
|| key.toLowerCase().equals("url")
|| key.toLowerCase().equals("mailfrom")
|| key.toLowerCase().equals("mailto")
|| key.toLowerCase().equals("encryptmode")
|| key.toLowerCase().equals("exprotocol")
|| key.toLowerCase().equals("cljip"))) {
if (typeName.equals("java.lang.String")) {
sql.append(" and " + filedAndColumnMap.get(key) + "='" + value.toString().trim()
+ "'");
} else if (!value.toString().trim().equals("") && filedAndColumnMap.containsKey(key)
&& key.toLowerCase().equals("servicetype")) {
} else if (typeName.equals("java.lang.Integer") || typeName.equals("int")) {
sql.append(" and " + filedAndColumnMap.get(key) + "=" + value.toString().trim());
} else if (typeName.equals("java.lang.Long") || typeName.equals("long")) {
sql.append(
" and " + filedAndColumnMap.get(key) + "=" + value.toString().trim() + "L");
}
}
}
}
}
//if (null != searchActiveSys && !searchActiveSys.equals(Constants.ACTIVESYS_A)) {// B版数据库才有found_time_partition字段,A版毛衣found_time_partition分区字段
if (null != searchActiveSys){//为A版日志库添加分区字段
if (null != searchActiveSys) {// 添加分区字段
if (null != foundTimePartStart) {
sql.append(" and found_time_partition>=" + foundTimePartStart + "L");
// sql.append(" and found_time_partition>=" + foundTimePartStart + "L");
sql.append(" and found_time_partition>=" + foundTimePartStart);
}
if (null != foundTimePartEnd) {
sql.append(" and found_time_partition<" + foundTimePartEnd + "L");
// sql.append(" and found_time_partition<" + foundTimePartEnd + "L");
sql.append(" and found_time_partition<" + foundTimePartEnd);
}
}
@@ -141,9 +133,9 @@ public class HiveSqlService {
// sql.append(" order by " + orderBy + " limit 10000) t1) t2 where
// row_Num between " + startNum + " and " + endNum);
sql.append(" limit " + Constants.EVERY_GETHIVEDATANUM);
logger.info("获取数据中心日志sql===================" + sql);
logger.info("获取数据中心日志sql==================={}", sql);
// ResultSet query = HiveJDBC.query(sql.toString());
ResultSet query = HiveDataSource.query(sql.toString(), searchActiveSys);
ResultSet query = HiveDataSource.query(sql.toString());
logger.info("获取数据中心日志成功");
return query;
}
@@ -219,8 +211,10 @@ public class HiveSqlService {
}
}
//if (null != searchActiveSys && !searchActiveSys.equals(Constants.ACTIVESYS_A)) {// B版数据库才有found_time_partition字段,A版毛衣found_time_partition分区字段
if (null != searchActiveSys){
// if (null != searchActiveSys &&
// !searchActiveSys.equals(Constants.ACTIVESYS_A)) {//
// B版数据库才有found_time_partition字段,A版毛衣found_time_partition分区字段
if (null != searchActiveSys) {
if (null != foundTimePartStart) {
countSql.append(" and found_time_partition>=" + foundTimePartStart + "L");
}
@@ -232,7 +226,7 @@ public class HiveSqlService {
}
logger.info("获取数据中心日志总条数sql==================" + countSql.toString());
// ResultSet countRs = HiveJDBC.query(countSql.toString());
ResultSet countRs = HiveDataSource.query(countSql.toString(), searchActiveSys);
ResultSet countRs = HiveDataSource.query(countSql.toString());
String countStr = null;
while (countRs.next()) {
countStr = countRs.getObject(1).toString();

View File

@@ -51,7 +51,7 @@ public class SaveRequestLogThread implements Runnable {
public void run() {
logger.info("线程开始执行!");
//新开线程切换数据源不影响action中的数据源
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_C);//开启数据源C
CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);//开启数据源B
// TODO Auto-generated method stub
if(service!=null){
service.saveRequestLog(remoteAddr,requestURI,queryString,contextPath, operator, version, opAction, opTime, content, requestTime, consumerTime,businessCode,exceptionInfo,traceCode);