From ea327b17d783c0ee94a8efb9019723a673862262 Mon Sep 17 00:00:00 2001 From: doufenghu Date: Sun, 10 Jun 2018 16:18:34 +0800 Subject: [PATCH] =?UTF-8?q?fix(log):=E6=97=A5=E5=BF=97=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=EF=BC=8C=E5=88=A0=E9=99=A4=E5=8E=86=E5=8F=B2?= =?UTF-8?q?activesys=20=EF=BC=8C=E4=BF=AE=E6=94=B9logSource=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=B1=BB=E5=9E=8B=E4=B8=BAint=E3=80=82=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0NTC=5FIP=5FLOG=20=E6=97=A5=E5=BF=97=E6=A3=80=E7=B4=A2?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=9C=8D=E5=8A=A1=E6=8E=A5=E5=8F=A3=E3=80=82?= =?UTF-8?q?=E5=90=8E=E7=BB=AD=E5=88=A0=E9=99=A4=E5=8E=86=E5=8F=B2=E9=81=97?= =?UTF-8?q?=E7=95=99=E6=97=A5=E5=BF=97=E6=A3=80=E7=B4=A2=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E5=8F=8A=E5=85=B6=E7=9B=B8=E5=85=B3=E5=AF=B9=E8=B1=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/nis/domain/LogEntity.java | 274 +- .../java/com/nis/domain/restful/NtcIpLog.java | 12 + .../nis/restful/DefaultRestErrorResolver.java | 12 +- src/main/java/com/nis/restful/RestResult.java | 18 +- .../com/nis/restful/RestServiceException.java | 37 +- .../nis/util/httpclient/HttpClientUtil.java | 8 +- .../web/controller/BaseRestController.java | 25 +- .../restful/DfKeyConvertUrlController.java | 11 +- .../restful/DfKeyMailAddController.java | 12 +- .../restful/DfLogSearchController.java | 3152 ----------------- .../restful/DjLogSearchController.java | 2304 ------------ .../restful/IntervalTimeSearchController.java | 14 +- .../web/controller/restful/LogController.java | 58 + .../web/controller/sys/AreaController.java | 2 +- .../com/nis/web/service/BaseLogService.java | 2 +- .../nis/web/service/SaveRequestLogThread.java | 4 +- .../service/ServicesRequestLogService.java | 3 - .../web/service/restful/LogTestService.java | 89 + 18 files changed, 314 insertions(+), 5723 deletions(-) create mode 100644 src/main/java/com/nis/domain/restful/NtcIpLog.java delete mode 100644 src/main/java/com/nis/web/controller/restful/DfLogSearchController.java delete mode 100644 src/main/java/com/nis/web/controller/restful/DjLogSearchController.java create mode 100644 src/main/java/com/nis/web/controller/restful/LogController.java create mode 100644 src/main/java/com/nis/web/service/restful/LogTestService.java diff --git a/src/main/java/com/nis/domain/LogEntity.java b/src/main/java/com/nis/domain/LogEntity.java index 0f5bab4..1a3d821 100644 --- a/src/main/java/com/nis/domain/LogEntity.java +++ b/src/main/java/com/nis/domain/LogEntity.java @@ -48,12 +48,10 @@ public abstract class LogEntity implements Serializable { protected Date foundTime; @ApiModelProperty(value="接收时间", required=true) protected Date recvTime; - /*@ApiModelProperty(value="外层嵌套关联信息ID", required=true) - protected Long overId;*/ - @ApiModelProperty(value="外层嵌套关联信息ID", required=true) - protected String overId; @ApiModelProperty(value="协议类型", required=true) protected String protocol; + @ApiModelProperty(value="IP地址类型", required=true) + protected Integer addrType; @ApiModelProperty(value="服务端ip地址", required=true) protected String serverIp; @ApiModelProperty(value="客户端ip地址", required=true) @@ -62,29 +60,25 @@ public abstract class LogEntity implements Serializable { protected Integer serverPort; @ApiModelProperty(value="客户端端口", required=true) protected Integer clientPort; - @ApiModelProperty(value="嵌套协议类型", required=true) - protected String nestProtocol; - @ApiModelProperty(value="嵌套服务端ip地址", required=true) - protected String nestServerIp; - @ApiModelProperty(value="嵌套客户端ip地址", required=true) - protected String nestClientIp; - @ApiModelProperty(value="嵌套服务端端口", required=true) - protected Integer nestServerPort; - @ApiModelProperty(value="嵌套客户端端口", required=true) - protected Integer nestClientPort; - @ApiModelProperty(value="业务类型", required=true) + @ApiModelProperty(value="业务类型", required=true) protected Integer serviceType; + @ApiModelProperty(value="串联设备编号", required=true) + protected Integer deviceId; + @ApiModelProperty(value="传输方向", required=true, notes = "0:域内->域外,1:域外->域内,描述的是CLIENT_IP信息") + protected Integer direction; + @ApiModelProperty(value="流类型", required=true, notes = "0:c2s,1:s2c;2;double") + protected Integer streamType; @ApiModelProperty(value="出入口编号", required=true) protected Long entranceId; @ApiModelProperty(value="处理机IP", required=true) protected String cljIp; - @ApiModelProperty(value="封堵包记录文件", required=true) - protected String injectedPktFile; - - @ApiModelProperty(value="存放现场日志文件的URL地址", required=true) - protected String sceneFile; - @ApiModelProperty(value="管控动作", required=true) - protected Integer action; + + @ApiModelProperty(value="用户嵌套地址列表", required=true) + protected String nestAddrList; + + @ApiModelProperty(value="用户自定义域", required=true) + private String userRegion; + @ApiModelProperty(value="服务端地址定位信息", required=true) protected String serverLocate; @ApiModelProperty(value="客户端地址定位信息", required=true) @@ -94,21 +88,21 @@ public abstract class LogEntity implements Serializable { protected Long foundTimeCluster; protected Long recvTimeCluster; - - + + protected String searchCfgId; protected String searchFoundStartTime; protected String searchFoundEndTime; protected Long searchFoundStartTimeCluster; protected Long searchFoundEndTimeCluster; - protected String searchCfgId; protected String searchProtocol; - protected String searchServiceType; protected String searchServerIp; protected String searchClientIp; + protected Integer searchDirection; + protected String searchServiceType; protected String searchEntranceId; protected String searchCljIp; - protected String tableName;//神通数据库根据A/B版,动态切换表名 + @JsonIgnore public Long getFoundTimeCluster() { @@ -139,19 +133,7 @@ public abstract class LogEntity implements Serializable { public void setSearchFoundEndTimeCluster(Long searchFoundEndTimeCluster) { this.searchFoundEndTimeCluster = searchFoundEndTimeCluster; } - @JsonIgnore - public String getTableName() { - return tableName; - } - public void setTableName(String tableName) { - this.tableName = tableName; - } - public String getOverId() { - return overId; - } - public void setOverId(String overId) { - this.overId = overId; - } + /** * 当前实体分页对象 */ @@ -165,19 +147,12 @@ public abstract class LogEntity implements Serializable { /** * @Title: * @Description: TODO - * @param 入参 + * @param */ public LogEntity() { super(); } - - public String getInjectedPktFile() { - return injectedPktFile; - } - - public void setInjectedPktFile(String injectedPktFile) { - this.injectedPktFile = injectedPktFile; - } + /** @@ -268,26 +243,6 @@ public abstract class LogEntity implements Serializable { - /** - * @return overId - */ - /*public Long getOverId() { - return overId; - } - - - - - *//** - * @param overId 要设置的 overId - *//* - public void setOverId(Long overId) { - this.overId = overId; - }*/ - - - - /** * @return protocol */ @@ -388,105 +343,6 @@ public abstract class LogEntity implements Serializable { - /** - * @return nestProtocol - */ - public String getNestProtocol() { - return nestProtocol; - } - - - - - /** - * @param nestProtocol 要设置的 nestProtocol - */ - public void setNestProtocol(String nestProtocol) { - this.nestProtocol = nestProtocol; - } - - - - - /** - * @return nestServerIp - */ - public String getNestServerIp() { - return nestServerIp; - } - - - - - /** - * @param nestServerIp 要设置的 nestServerIp - */ - public void setNestServerIp(String nestServerIp) { - this.nestServerIp = nestServerIp; - } - - - - - /** - * @return nestClientIp - */ - public String getNestClientIp() { - return nestClientIp; - } - - - - - /** - * @param nestClientIp 要设置的 nestClientIp - */ - public void setNestClientIp(String nestClientIp) { - this.nestClientIp = nestClientIp; - } - - - - - /** - * @return nestServerPort - */ - public Integer getNestServerPort() { - return nestServerPort; - } - - - - - /** - * @param nestServerPort 要设置的 nestServerPort - */ - public void setNestServerPort(Integer nestServerPort) { - this.nestServerPort = nestServerPort; - } - - - - - /** - * @return nestClientPort - */ - public Integer getNestClientPort() { - return nestClientPort; - } - - - - - /** - * @param nestClientPort 要设置的 nestClientPort - */ - public void setNestClientPort(Integer nestClientPort) { - this.nestClientPort = nestClientPort; - } - - - /** * @return serviceType @@ -742,8 +598,6 @@ public abstract class LogEntity implements Serializable { } - - /** * @param searchClientIp 要设置的 searchClientIp */ @@ -763,8 +617,6 @@ public abstract class LogEntity implements Serializable { } - - /** * @param searchEntranceId 要设置的 searchEntranceId */ @@ -795,8 +647,6 @@ public abstract class LogEntity implements Serializable { } - - /** * @return searchServiceType */ @@ -805,9 +655,6 @@ public abstract class LogEntity implements Serializable { return searchServiceType; } - - - /** * @param searchServiceType 要设置的 searchServiceType */ @@ -815,25 +662,64 @@ public abstract class LogEntity implements Serializable { this.searchServiceType = searchServiceType; } - + public Integer getAddrType() { + return addrType; + } - public String getSceneFile() { - return sceneFile; - } - public void setSceneFile(String sceneFile) { - this.sceneFile = sceneFile; - } - - public Integer getAction() { - return action; - } - public void setAction(Integer action) { - this.action = action; - } - - + public void setAddrType(Integer addrType) { + this.addrType = addrType; + } - @Override + public Integer getDeviceId() { + return deviceId; + } + + public void setDeviceId(Integer deviceId) { + this.deviceId = deviceId; + } + + public Integer getDirection() { + return direction; + } + + public void setDirection(Integer direction) { + this.direction = direction; + } + + public Integer getStreamType() { + return streamType; + } + + public void setStreamType(Integer streamType) { + this.streamType = streamType; + } + + public String getNestAddrList() { + return nestAddrList; + } + + public void setNestAddrList(String nestAddrList) { + this.nestAddrList = nestAddrList; + } + + @JsonIgnore + public Integer getSearchDirection() { + return searchDirection; + } + + public void setSearchDirection(Integer searchDirection) { + this.searchDirection = searchDirection; + } + + public String getUserRegion() { + return userRegion; + } + + public void setUserRegion(String userRegion) { + this.userRegion = userRegion; + } + + @Override public String toString() { return ReflectionToStringBuilder.toString(this); } diff --git a/src/main/java/com/nis/domain/restful/NtcIpLog.java b/src/main/java/com/nis/domain/restful/NtcIpLog.java new file mode 100644 index 0000000..5659709 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/NtcIpLog.java @@ -0,0 +1,12 @@ +package com.nis.domain.restful; + +import com.nis.domain.LogEntity; + +/** + * Created by darnell on 2018/6/10. + */ +public class NtcIpLog extends LogEntity { + + + private static final long serialVersionUID = 1325588394265592830L; +} diff --git a/src/main/java/com/nis/restful/DefaultRestErrorResolver.java b/src/main/java/com/nis/restful/DefaultRestErrorResolver.java index d3fda62..987cf67 100644 --- a/src/main/java/com/nis/restful/DefaultRestErrorResolver.java +++ b/src/main/java/com/nis/restful/DefaultRestErrorResolver.java @@ -40,14 +40,7 @@ public class DefaultRestErrorResolver implements RestErrorResolver,InitializingB RestResult error = new RestResult(); error.setStatus(this.getHttpStatusByEx(ex));// 设置http状态 //获取日志源[只有日志需要返回日志源和ActiveSys] - String logSource = ((RestServiceException) ex).getLogSource(); - String activeSys = ((RestServiceException) ex).getActiveSys(); - if(logSource != null ){ - error.setLogSource(logSource); - } - if(activeSys != null ){ - error.setActiveSys(activeSys); - } + int logSource = ((RestServiceException) ex).getLogSource(); //RestServiceException 包含有错误code if(ex instanceof RestServiceException){ @@ -71,8 +64,9 @@ public class DefaultRestErrorResolver implements RestErrorResolver,InitializingB if(this.exceptionMappingDefinitions.containsKey(ex.getClass().getName())){ return HttpStatus.valueOf(Integer.parseInt(this.exceptionMappingDefinitions.get(ex.getClass() .getName()))); + } else { + return HttpStatus.INTERNAL_SERVER_ERROR; } - else return HttpStatus.INTERNAL_SERVER_ERROR; } diff --git a/src/main/java/com/nis/restful/RestResult.java b/src/main/java/com/nis/restful/RestResult.java index d921f83..08444ef 100644 --- a/src/main/java/com/nis/restful/RestResult.java +++ b/src/main/java/com/nis/restful/RestResult.java @@ -48,7 +48,7 @@ public class RestResult { /** * 日志数据来源本地:0 数据中心:1 */ - private String logSource; + private Integer logSource; /** * 追踪状态码 @@ -59,14 +59,13 @@ public class RestResult { } - public RestResult(HttpStatus status, RestBusinessCode businessCode, String msg,String fromUri,String activeSys,String fromSign,String traceCode) { + public RestResult(HttpStatus status, RestBusinessCode businessCode, String msg, String fromUri, Integer logSource,String traceCode) { super(); this.status = status; this.businessCode = businessCode; this.msg = msg; this.fromUri = fromUri; - this.activeSys=activeSys; - this.logSource=logSource; + this.logSource= logSource; this.traceCode=traceCode; } @@ -137,14 +136,15 @@ public class RestResult { this.activeSys = activeSys; } - public String getLogSource() { + public Integer getLogSource() { return logSource; } - public void setLogSource(String logSource) { + + public void setLogSource(Integer logSource) { this.logSource = logSource; } - - /** + + /** * @return data */ public Object getData() { @@ -166,7 +166,9 @@ public class RestResult { this.traceCode = traceCode; } + @Override public String toString() { + return new StringBuilder().append("HttpStatus:").append(getStatus().value()) .append(" errorcode:") .append(this.getBusinessCode().getValue()) diff --git a/src/main/java/com/nis/restful/RestServiceException.java b/src/main/java/com/nis/restful/RestServiceException.java index 410791a..7a2b40c 100644 --- a/src/main/java/com/nis/restful/RestServiceException.java +++ b/src/main/java/com/nis/restful/RestServiceException.java @@ -8,9 +8,7 @@ public class RestServiceException extends RuntimeException{ private int errorCode; - private String logSource; - - private String activeSys; + private int logSource; private String traceCode; /** @@ -33,8 +31,10 @@ public class RestServiceException extends RuntimeException{ this.traceCode = thread.getTraceCode(); thread.setConsumerTime(time); thread.setBusinessCode(this.getErrorCode()); - if(StringUtils.isEmpty(thread.getExceptionInfo())) - thread.setExceptionInfo(message); + if(StringUtils.isEmpty(thread.getExceptionInfo())) { + thread.setExceptionInfo(message); + } + new Thread(thread).start(); } @@ -48,8 +48,10 @@ public class RestServiceException extends RuntimeException{ this.traceCode = thread.getTraceCode(); thread.setConsumerTime(time); thread.setBusinessCode(this.getErrorCode()); - if(StringUtils.isEmpty(thread.getExceptionInfo())) - thread.setExceptionInfo(message); + if(StringUtils.isEmpty(thread.getExceptionInfo())) { + thread.setExceptionInfo(message); + } + new Thread(thread).start(); } @@ -61,19 +63,14 @@ public class RestServiceException extends RuntimeException{ public void setErrorCode(int errorCode) { this.errorCode = errorCode; } - - public String getLogSource() { - return logSource; - } - public void setLogSource(String logSource) { - this.logSource = logSource; - } - public String getActiveSys() { - return activeSys; - } - public void setActiveSys(String activeSys) { - this.activeSys = activeSys; - } + + public int getLogSource() { + return logSource; + } + + public void setLogSource(int logSource) { + this.logSource = logSource; + } public String getTraceCode() { return traceCode; diff --git a/src/main/java/com/nis/util/httpclient/HttpClientUtil.java b/src/main/java/com/nis/util/httpclient/HttpClientUtil.java index 1e45481..d3f393a 100644 --- a/src/main/java/com/nis/util/httpclient/HttpClientUtil.java +++ b/src/main/java/com/nis/util/httpclient/HttpClientUtil.java @@ -15,6 +15,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.nis.util.JsonMapper; import org.apache.http.NameValuePair; import org.apache.http.client.ClientProtocolException; import org.apache.http.client.entity.UrlEncodedFormEntity; @@ -107,10 +108,9 @@ public class HttpClientUtil { } public static void main(String[] args) throws ClientProtocolException, IOException { HttpClientUtil hd = new HttpClientUtil(); - hd.get("http://10.0.6.115:9200/_sql?sql=select * from dfipportlog-2016-09-07-15 limit 1 10"); - Map map = new HashMap(); - map.put("id","1"); - hd.post("http://localhost:8080/springMVC/menu/getChildren.do",map); + String result = hd.get("http://10.0.6.104:8080/galaxy/service/cfg/v1/configPzIdSources"); + Object mapResult = JsonMapper.fromJsonString(result,Map.class); + System.out.println(result); } } diff --git a/src/main/java/com/nis/web/controller/BaseRestController.java b/src/main/java/com/nis/web/controller/BaseRestController.java index 1632757..b27a30b 100644 --- a/src/main/java/com/nis/web/controller/BaseRestController.java +++ b/src/main/java/com/nis/web/controller/BaseRestController.java @@ -219,9 +219,18 @@ public class BaseRestController { return convert(restResult); } - public Map serviceResponse(SaveRequestLogThread thread, long time, HttpServletRequest request, - HttpServletResponse response, String msg, Object data, String activeSys, String logSource) { - logger.info("结果集处理开始----" + System.currentTimeMillis()); + /** + * 日志结果响应格式规范 + * @param auditLogThread + * @param executedTime + * @param request + * @param msg + * @param data + * @param logSource + * @return + */ + public Map serviceLogResponse(SaveRequestLogThread auditLogThread, long executedTime, HttpServletRequest request, + String msg, Object data, Integer logSource) { RestResult restResult = new RestResult(); String requestMethod = request.getMethod(); if (requestMethod.equals(RequestMethod.GET.name())) { @@ -240,12 +249,11 @@ public class BaseRestController { restResult.setFromUri(request.getRequestURI()); restResult.setData(data); restResult.setMsg(msg); - restResult.setActiveSys(activeSys); restResult.setLogSource(logSource); - restResult.setTraceCode(thread.getTraceCode()); - thread.setConsumerTime(time); - thread.setBusinessCode(restResult.getBusinessCode().getValue()); - new Thread(thread).start(); + restResult.setTraceCode(auditLogThread.getTraceCode()); + auditLogThread.setConsumerTime(executedTime); + auditLogThread.setBusinessCode(restResult.getBusinessCode().getValue()); + new Thread(auditLogThread).start(); return convert(restResult); } @@ -264,7 +272,6 @@ public class BaseRestController { } successMap.put(RestConstants.TRACE_CODE, re.getTraceCode()); successMap.put(RestConstants.REST_SERVICE_DATA, re.getData()); - logger.info("结果集处理结束----" + System.currentTimeMillis()); return successMap; } diff --git a/src/main/java/com/nis/web/controller/restful/DfKeyConvertUrlController.java b/src/main/java/com/nis/web/controller/restful/DfKeyConvertUrlController.java index 95d2aaf..4edf3a7 100644 --- a/src/main/java/com/nis/web/controller/restful/DfKeyConvertUrlController.java +++ b/src/main/java/com/nis/web/controller/restful/DfKeyConvertUrlController.java @@ -50,7 +50,7 @@ public class DfKeyConvertUrlController extends BaseRestController{ @Autowired protected ServicesRequestLogService servicesRequestLogService; - protected String logSource = "0"; + protected int logSource = 0; @RequestMapping(value="/dfKeyConvertUrlSources", method = RequestMethod.GET) @ApiOperation(value="关键字业务转换URL日志信息获取" , httpMethod = "GET", notes="get log list") @@ -61,7 +61,9 @@ public class DfKeyConvertUrlController extends BaseRestController{ if(!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys) - ) searchActiveSys=Constants.ACTIVESYS_B; + ) { + searchActiveSys=Constants.ACTIVESYS_B; + } long start=System.currentTimeMillis(); SaveRequestLogThread thread=super.saveRequestLog(servicesRequestLogService,Constants.OPACTION_GET,request, null); @@ -80,11 +82,10 @@ public class DfKeyConvertUrlController extends BaseRestController{ if (!(e instanceof RestServiceException)) { e = new RestServiceException(thread, System.currentTimeMillis() - start, "关键字业务转换URL日志信息检索失败"); } - ((RestServiceException) e).setActiveSys(searchActiveSys); ((RestServiceException) e).setLogSource(logSource); throw ((RestServiceException) e); } - return serviceResponse(thread,System.currentTimeMillis()-start,request, response, "关键字业务转换URL日志信息检索成功",dfKeyConvertUrlPage - ,searchActiveSys, logSource); + return serviceLogResponse(thread, System.currentTimeMillis()-start, request, "关键字业务转换URL日志信息检索成功",dfKeyConvertUrlPage + , logSource); } } diff --git a/src/main/java/com/nis/web/controller/restful/DfKeyMailAddController.java b/src/main/java/com/nis/web/controller/restful/DfKeyMailAddController.java index 15d37a3..91b7b7c 100644 --- a/src/main/java/com/nis/web/controller/restful/DfKeyMailAddController.java +++ b/src/main/java/com/nis/web/controller/restful/DfKeyMailAddController.java @@ -50,7 +50,7 @@ public class DfKeyMailAddController extends BaseRestController { @Autowired protected DfKeyMailAddService dfKeyMailAddService; - protected String logSource = "0"; + protected int logSource = 0; @RequestMapping(value = "/dfKeyMailAddSources", method = RequestMethod.GET) @ApiOperation(value = "关键字业务转换邮件地址日志信息获取", httpMethod = "GET", notes = "get log list") @@ -61,7 +61,9 @@ public class DfKeyMailAddController extends BaseRestController { if(!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys) - ) searchActiveSys=Constants.ACTIVESYS_B; + ) { + searchActiveSys=Constants.ACTIVESYS_B; + } long start = System.currentTimeMillis(); SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); @@ -81,11 +83,11 @@ public class DfKeyMailAddController extends BaseRestController { if (!(e instanceof RestServiceException)) { e = new RestServiceException(thread, System.currentTimeMillis() - start, "关键字业务转换邮件地址日志信息检索失败"); } - ((RestServiceException) e).setActiveSys(searchActiveSys); + ((RestServiceException) e).setLogSource(logSource); throw ((RestServiceException) e); } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "关键字业务转换邮件地址日志信息检索成功", - dfKeyMailAddPage,searchActiveSys, logSource); + return serviceLogResponse(thread, System.currentTimeMillis() - start, request, "关键字业务转换邮件地址日志信息检索成功", + dfKeyMailAddPage, logSource); } } diff --git a/src/main/java/com/nis/web/controller/restful/DfLogSearchController.java b/src/main/java/com/nis/web/controller/restful/DfLogSearchController.java deleted file mode 100644 index 8d14ec4..0000000 --- a/src/main/java/com/nis/web/controller/restful/DfLogSearchController.java +++ /dev/null @@ -1,3152 +0,0 @@ -/** -* @Title: DfLogSearchController.java -* @Package com.nis.web.controller -* @Description: TODO(用一句话描述该文件做什么) -* @author (ddm) -* @date 2016年9月5日 下午10:52:37 -* @version V1.0 -*/ -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; -import javax.servlet.http.HttpServletResponse; - -import org.apache.cxf.common.util.StringUtils; -import org.apache.log4j.Logger; -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.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.nis.datasource.CustomerContextHolder; -import com.nis.domain.LogEntity; -import com.nis.domain.Page; -import com.nis.domain.restful.DfDnsLog; -import com.nis.domain.restful.DfFtpLog; -import com.nis.domain.restful.DfHttpKeywordLog; -import com.nis.domain.restful.DfHttpReqLog; -import com.nis.domain.restful.DfHttpResLog; -import com.nis.domain.restful.DfIpPortLog; -import com.nis.domain.restful.DfIpsecLog; -import com.nis.domain.restful.DfL2tpLog; -import com.nis.domain.restful.DfMailLog; -import com.nis.domain.restful.DfOpenvpnLog; -import com.nis.domain.restful.DfPptpLog; -import com.nis.domain.restful.DfSshLog; -import com.nis.domain.restful.DfSslLog; -import com.nis.domain.restful.DfTunnelRandomLog; -import com.nis.restful.RestBusinessCode; -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.util.StringUtil; -import com.nis.util.redis.RedisDao; -import com.nis.util.redis.SaveRedisThread; -import com.nis.web.controller.BaseRestController; -import com.nis.web.service.HiveSqlService; -import com.nis.web.service.SaveRequestLogThread; -import com.nis.web.service.ServicesRequestLogService; -import com.nis.web.service.restful.DfLogSearchService; -import com.wordnik.swagger.annotations.ApiOperation; - -/** - * @ClassName: DfLogSearchController - * @Description: TODO(这里用一句话描述这个类的作用) - * @author (ddm) - * @date 2016年9月5日 下午10:52:37 - * @version V1.0 - */ -@RestController -//@RequestMapping("${servicePath}/log/v1") -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class DfLogSearchController extends BaseRestController { - protected final Logger logger1 = Logger.getLogger(this.getClass()); - - protected String logSource = "0"; - - @Autowired - protected DfLogSearchService dfLogService; - @Autowired - protected RedisDao redisDao; - @Autowired - protected ServicesRequestLogService servicesRequestLogService; - - @RequestMapping(value = "/dfIpPortLogs", method = RequestMethod.GET) - @ApiOperation(value = "端口封堵分页获取", httpMethod = "GET", notes = "get log list") - public Map dfIpPortLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfIpPortLog ipPortLog, Model model, HttpServletRequest request, HttpServletResponse response) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - long start = System.currentTimeMillis(); - - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - Page ipPortLogPage = new Page(); - boolean keyExists = false; - String key = ""; - String countKey = ""; - try { - resetTime(ipPortLog); - logger1.info("请求参数检验开始---" + System.currentTimeMillis()); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, ipPortLog, DfIpPortLog.class, page); - logger1.info("请求参数检验结束---" + System.currentTimeMillis()); - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(ipPortLog.getSearchFoundStartTime(), - ipPortLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (ipPortLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (ipPortLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - ipPortLog.setTableName(Configurations.getStringProperty(DfIpPortLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - ipPortLog.setTableName(Configurations - .getStringProperty(DfIpPortLog.class.getSimpleName() + "B", "t_xa_df_ip_port_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - ipPortLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(ipPortLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - ipPortLogPage = dfLogService.findIpPortPageCluster( - new Page(request, response, DfIpPortLog.class), ipPortLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, ipPortLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - logger1.info("hive-redis查询开始---" + System.currentTimeMillis()); - List list = new ArrayList(); - ipPortLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfIpPortLog bean = (DfIpPortLog) JsonMapper.fromJsonString(str, DfIpPortLog.class); - list.add(bean); - } - ipPortLogPage.setList(list); - - } else { - ipPortLogPage.setList(new ArrayList()); - } - logger1.info("hive-redis查询结束---" + System.currentTimeMillis()); - } else { - logger1.info("hive查询开始---" + System.currentTimeMillis()); - ipPortLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfIpPortLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, ipPortLog, "DF_IP_PORT_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfIpPortLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ipPortLogPage.setList(new ArrayList()); - - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfIpPortLog.class); - ipPortLogPage.setList(List); - - } else { - ipPortLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - ipPortLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipPortLog, countKey, "DF_IP_PORT_LOG", - getCol2Col(), searchActiveSys); - ipPortLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipPortLog, countKey, "DF_IP_PORT_LOG", - getCol2Col(), searchActiveSys); - ipPortLogPage.setCount(Long.valueOf(hivePageCount)); - } - ipPortLogPage.setPageNo(page.getPageNo()); - ipPortLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - ipPortLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(ipPortLogPage.getList().size()); - logger1.info("Redis查询结束:" + endTime); - logger1.info("Redis时长:" + ((endTime - startTime) / 1000)); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - logger1.info("orcl查询开始时间:" + startTime); - ipPortLogPage = dfLogService.findIpPortPage( - new Page(request, response, DfIpPortLog.class), ipPortLog, searchActiveSys); - long endTime = System.currentTimeMillis(); - logger1.info("orcl查询结束时间:" + endTime); - logger1.info("orcl时长:" + ((endTime - startTime) / 1000)); - if (Constants.IS_OPEN_REDIS) { - logger1.info("redis存储开始时间:" + endTime); - new SaveRedisThread(key, ipPortLogPage, Constants.ORACLE_EXPIRE).start(); - logger1.info("redis存储结束时间:" + endTime); - } - } - } - - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "端口封堵日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "端口封堵日志检索成功", - ipPortLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfHttpReqLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议请求封堵分页获取", httpMethod = "GET", notes = "get log list") - public Map dfHttpReqLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - // @RequestParam(value = "type", required = false, defaultValue = - // "oracle") String type, - Page page, DfHttpReqLog httpReqLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpReqLogPage = new Page(); - try { - resetTime(httpReqLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, httpReqLog, DfHttpReqLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpReqLog.getSearchFoundStartTime(), - httpReqLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (httpReqLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (httpReqLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - httpReqLog.setTableName(Configurations.getStringProperty(DfHttpReqLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - httpReqLog.setTableName(Configurations - .getStringProperty(DfHttpReqLog.class.getSimpleName() + "B", "t_xa_df_http_req_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - httpReqLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(httpReqLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - httpReqLogPage = dfLogService.findHttpReqPageCluster( - new Page(request, response, DfHttpReqLog.class), httpReqLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, httpReqLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpReqLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfHttpReqLog bean = (DfHttpReqLog) JsonMapper.fromJsonString(str, DfHttpReqLog.class); - list.add(bean); - } - httpReqLogPage.setList(list); - - } else { - httpReqLogPage.setList(new ArrayList()); - } - } else { - - httpReqLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfHttpReqLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpReqLog, "DF_HTTP_REQ_LOG", getCol2Col(), - orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfHttpReqLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpReqLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfHttpReqLog.class); - httpReqLogPage.setList(List); - } else { - httpReqLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpReqLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqLog, countKey, "DF_HTTP_REQ_LOG", - getCol2Col(), searchActiveSys); - httpReqLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqLog, countKey, "DF_HTTP_REQ_LOG", - getCol2Col(), searchActiveSys); - httpReqLogPage.setCount(Long.valueOf(hivePageCount)); - } - - httpReqLogPage.setPageNo(page.getPageNo()); - httpReqLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - - // 存在则直接从redis中查询 - if (keyExists) { - httpReqLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpReqLogPage = dfLogService.findHttpReqPage( - new Page(request, response, DfHttpReqLog.class), httpReqLog, - searchActiveSys); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpReqLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议请求日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "HTTP协议请求日志检索成功", - httpReqLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfHttpResLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议响应封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfHttpResLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfHttpResLog httpResLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpResLogPage = new Page(); - - try { - resetTime(httpResLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, httpResLog, DfHttpResLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpResLog.getSearchFoundStartTime(), - httpResLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (httpResLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (httpResLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - httpResLog.setTableName(Configurations.getStringProperty(DfHttpResLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - httpResLog.setTableName(Configurations - .getStringProperty(DfHttpResLog.class.getSimpleName() + "B", "t_xa_df_http_res_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - httpResLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(httpResLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - httpResLogPage = dfLogService.findHttpResPageCluster( - new Page(request, response, DfHttpResLog.class), httpResLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, httpResLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpResLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfHttpResLog bean = (DfHttpResLog) JsonMapper.fromJsonString(str, DfHttpResLog.class); - list.add(bean); - } - httpResLogPage.setList(list); - } else { - httpResLogPage.setList(new ArrayList()); - } - } else { - - httpResLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfHttpResLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpResLog, "DF_HTTP_RES_LOG", getCol2Col(), - orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfHttpResLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpResLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfHttpResLog.class); - httpResLogPage.setList(List); - } else { - httpResLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpResLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpResLog, countKey, "DF_HTTP_RES_LOG", - getCol2Col(), searchActiveSys); - httpResLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpResLog, countKey, "DF_HTTP_RES_LOG", - getCol2Col(), searchActiveSys); - httpResLogPage.setCount(Long.valueOf(hivePageCount)); - } - httpResLogPage.setPageNo(page.getPageNo()); - httpResLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - httpResLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpResLogPage = dfLogService.findHttpResPage( - new Page(request, response, DfHttpResLog.class), httpResLog, searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpResLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议响应日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "HTTP协议响应日志检索成功", - httpResLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfHttpKeywordLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议关键字、请求多域、响应多域封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfHttpKeywordLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfHttpKeywordLog httpKeywordLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - String searchServiceType = httpKeywordLog.getSearchServiceType(); - if (StringUtils.isEmpty(searchServiceType)) { - httpKeywordLog.setSearchServiceType("5"); // 0x05 - } - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpKeywordLogPage = new Page(); - - try { - resetTime(httpKeywordLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, httpKeywordLog, DfHttpKeywordLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpKeywordLog.getSearchFoundStartTime(), - httpKeywordLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (httpKeywordLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (httpKeywordLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - httpKeywordLog.setTableName(Configurations.getStringProperty(DfHttpKeywordLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - httpKeywordLog.setTableName(Configurations - .getStringProperty(DfHttpKeywordLog.class.getSimpleName() + "B", "t_xa_df_http_keyword_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - httpKeywordLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(httpKeywordLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - httpKeywordLogPage = dfLogService.findHttpKeywordPageCluster( - new Page(request, response, DfHttpKeywordLog.class), httpKeywordLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, httpKeywordLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpKeywordLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfHttpKeywordLog bean = (DfHttpKeywordLog) JsonMapper.fromJsonString(str, - DfHttpKeywordLog.class); - list.add(bean); - } - httpKeywordLogPage.setList(list); - - } else { - httpKeywordLogPage.setList(new ArrayList()); - } - } else { - - httpKeywordLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfHttpKeywordLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpKeywordLog, "DF_HTTP_KEYWORD_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfHttpKeywordLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpKeywordLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DfHttpKeywordLog.class); - httpKeywordLogPage.setList(List); - - } else { - httpKeywordLogPage.setList(new ArrayList()); - } - - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpKeywordLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpKeywordLog, countKey, - "DF_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpKeywordLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpKeywordLog, countKey, - "DF_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpKeywordLogPage.setCount(Long.valueOf(hivePageCount)); - } - httpKeywordLogPage.setPageNo(page.getPageNo()); - httpKeywordLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - httpKeywordLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpKeywordLogPage = dfLogService.findHttpKeywordPage( - new Page(request, response, DfHttpKeywordLog.class), httpKeywordLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpKeywordLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议关键字、请求多域、响应多域封堵日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, - "HTTP协议关键字、请求多域、响应多域封堵日志检索成功", httpKeywordLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfHttpReqMultiPartLogs", method = RequestMethod.GET) - @ApiOperation(value = "Http协议请求多域封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfHttpReqMultiPartLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfHttpKeywordLog httpReqMultiLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - httpReqMultiLog.setSearchServiceType("17"); // 0x11 - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpReqMultiPage = new Page(); - - try { - resetTime(httpReqMultiLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, httpReqMultiLog, DfHttpKeywordLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpReqMultiLog.getSearchFoundStartTime(), - httpReqMultiLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpReqMultiPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfHttpKeywordLog bean = (DfHttpKeywordLog) JsonMapper.fromJsonString(str, - DfHttpKeywordLog.class); - list.add(bean); - } - httpReqMultiPage.setList(list); - - } else { - httpReqMultiPage.setList(new ArrayList()); - } - } else { - - httpReqMultiPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfHttpKeywordLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpReqMultiLog, "DF_HTTP_KEYWORD_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfHttpKeywordLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpReqMultiPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DfHttpKeywordLog.class); - httpReqMultiPage.setList(List); - - } else { - httpReqMultiPage.setList(new ArrayList()); - } - - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpReqMultiPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqMultiLog, countKey, - "DF_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpReqMultiPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqMultiLog, countKey, - "DF_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpReqMultiPage.setCount(Long.valueOf(hivePageCount)); - } - httpReqMultiPage.setPageNo(page.getPageNo()); - httpReqMultiPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - httpReqMultiPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpReqMultiPage = dfLogService.findHttpMultiPartPage( - new Page(request, response, DfHttpKeywordLog.class), httpReqMultiLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpReqMultiPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "Http协议请求多域封堵日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "Http协议请求多域封堵日志检索成功", - httpReqMultiPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfHttpResMultiPartLogs", method = RequestMethod.GET) - @ApiOperation(value = "Http协议响应多域封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfHttpResMultiPartLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfHttpKeywordLog httpResMultiLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - httpResMultiLog.setSearchServiceType("18"); // 0x12 - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpResMultiPage = new Page(); - - try { - resetTime(httpResMultiLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, httpResMultiLog, DfHttpKeywordLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpResMultiLog.getSearchFoundStartTime(), - httpResMultiLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpResMultiPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfHttpKeywordLog bean = (DfHttpKeywordLog) JsonMapper.fromJsonString(str, - DfHttpKeywordLog.class); - list.add(bean); - } - httpResMultiPage.setList(list); - - } else { - httpResMultiPage.setList(new ArrayList()); - } - } else { - - httpResMultiPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfHttpKeywordLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpResMultiLog, "DF_HTTP_KEYWORD_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfHttpKeywordLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpResMultiPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DfHttpKeywordLog.class); - httpResMultiPage.setList(List); - } else { - httpResMultiPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpResMultiPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpResMultiLog, countKey, - "DF_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpResMultiPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpResMultiLog, countKey, - "DF_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpResMultiPage.setCount(Long.valueOf(hivePageCount)); - } - httpResMultiPage.setPageNo(page.getPageNo()); - httpResMultiPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - httpResMultiPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpResMultiPage = dfLogService.findHttpMultiPartPage( - new Page(request, response, DfHttpKeywordLog.class), httpResMultiLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpResMultiPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "Http协议响应多域封堵日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "Http协议响应多域封堵日志检索成功", - httpResMultiPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfMailLogs", method = RequestMethod.GET) - @ApiOperation(value = "MAIL封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfMailLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfMailLog mailLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page mailLogPage = new Page(); - - try { - resetTime(mailLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, mailLog, DfMailLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(mailLog.getSearchFoundStartTime(), - mailLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (mailLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (mailLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - mailLog.setTableName(Configurations.getStringProperty(DfMailLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - mailLog.setTableName(Configurations - .getStringProperty(DfMailLog.class.getSimpleName() + "B", "t_xa_df_mail_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - mailLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(mailLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - mailLogPage = dfLogService.findMailPageCluster( - new Page(request, response, DfMailLog.class), mailLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, mailLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - mailLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfMailLog bean = (DfMailLog) JsonMapper.fromJsonString(str, DfMailLog.class); - list.add(bean); - } - mailLogPage.setList(list); - - } else { - mailLogPage.setList(new ArrayList()); - } - } else { - - mailLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfMailLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, mailLog, "DF_MAIL_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfMailLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - mailLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfMailLog.class); - mailLogPage.setList(List); - } else { - mailLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - mailLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(mailLog, countKey, "DF_MAIL_LOG", - getCol2Col(), searchActiveSys); - mailLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(mailLog, countKey, "DF_MAIL_LOG", getCol2Col(), - searchActiveSys); - mailLogPage.setCount(Long.valueOf(hivePageCount)); - } - - mailLogPage.setPageNo(page.getPageNo()); - mailLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - mailLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - mailLogPage = dfLogService.findMailPage(new Page(request, response, DfMailLog.class), - mailLog, searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, mailLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "MAIL日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "MAIL日志检索成功", mailLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfDnsLogs", method = RequestMethod.GET) - @ApiOperation(value = "DNS封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfDnsLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfDnsLog dnsLog, HttpServletRequest request, HttpServletResponse response, Model model) { - logger1.info("dfDnsLogList接口请求方法开始----" + System.currentTimeMillis()); - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page dnsLogPage = new Page(); - - try { - resetTime(dnsLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, dnsLog, DfDnsLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(dnsLog.getSearchFoundStartTime(), - dnsLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logger1.info("hive开始----" + System.currentTimeMillis()); - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (dnsLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (dnsLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - dnsLog.setTableName(Configurations.getStringProperty(DfDnsLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - dnsLog.setTableName(Configurations - .getStringProperty(DfDnsLog.class.getSimpleName() + "B", "t_xa_df_dns_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - dnsLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(dnsLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - dnsLogPage = dfLogService.findDnsPageCluster( - new Page(request, response, DfDnsLog.class), dnsLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, dnsLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - dnsLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfDnsLog bean = (DfDnsLog) JsonMapper.fromJsonString(str, DfDnsLog.class); - list.add(bean); - } - dnsLogPage.setList(list); - - } else { - dnsLogPage.setList(new ArrayList()); - } - } else { - - dnsLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfDnsLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, dnsLog, "DF_DNS_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfDnsLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - dnsLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfDnsLog.class); - dnsLogPage.setList(List); - - } else { - dnsLogPage.setList(new ArrayList()); - } - - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - dnsLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(dnsLog, countKey, "DF_DNS_LOG", - getCol2Col(), searchActiveSys); - dnsLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(dnsLog, countKey, "DF_DNS_LOG", getCol2Col(), - searchActiveSys); - dnsLogPage.setCount(Long.valueOf(hivePageCount)); - } - - dnsLogPage.setPageNo(page.getPageNo()); - dnsLogPage.setPageSize(page.getPageSize()); - logger1.info("hive结束----" + System.currentTimeMillis()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - logger1.info("redis Key校验开始----" + System.currentTimeMillis()); - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - logger1.info("redis Key校验结束----" + System.currentTimeMillis()); - } - // 存在则直接从redis中查询 - if (keyExists) { - logger1.info("redis查询开始----" + System.currentTimeMillis()); - dnsLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - logger1.info("redis查询结束----" + System.currentTimeMillis()); - } else { - logger1.info("oracle查询开始----" + System.currentTimeMillis()); - // 不存在则查询数据库并保存查询结果到redis中 - dnsLogPage = dfLogService.findDnsPage(new Page(request, response, DfDnsLog.class), dnsLog, - searchActiveSys); - logger1.info("oracle查询结束----" + System.currentTimeMillis()); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, dnsLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "DNS日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } finally { - logger1.info("dfDnsLogList接口请求方法结束----" + System.currentTimeMillis()); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "DNS日志检索成功", dnsLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfFtpLogs", method = RequestMethod.GET) - @ApiOperation(value = "FTP封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfFtpLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfFtpLog ftpLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page ftpLogPage = new Page(); - - try { - resetTime(ftpLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, ftpLog, DfFtpLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(ftpLog.getSearchFoundStartTime(), - ftpLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - ftpLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfFtpLog bean = (DfFtpLog) JsonMapper.fromJsonString(str, DfFtpLog.class); - list.add(bean); - } - - ftpLogPage.setList(list); - - } else { - ftpLogPage.setList(new ArrayList()); - } - } else { - - ftpLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfFtpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, ftpLog, "DF_FTP_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfFtpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - ftpLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfFtpLog.class); - ftpLogPage.setList(List); - - } else { - ftpLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - ftpLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ftpLog, countKey, "DF_FTP_LOG", - getCol2Col(), searchActiveSys); - ftpLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ftpLog, countKey, "DF_FTP_LOG", getCol2Col(), - searchActiveSys); - ftpLogPage.setCount(Long.valueOf(hivePageCount)); - } - ftpLogPage.setPageNo(page.getPageNo()); - ftpLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - ftpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - ftpLogPage = dfLogService.findFtpPage(new Page(request, response, DfFtpLog.class), ftpLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, ftpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "FTP日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "FTP日志检索成功", ftpLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfPPTPLogs", method = RequestMethod.GET) - @ApiOperation(value = "PPTP封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfPptpLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfPptpLog pptpLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page pptpLogPage = new Page(); - - try { - resetTime(pptpLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, pptpLog, DfPptpLog.class, page); - - // 单独对PPTP的EncryptMode字段校验 - if (!StringUtil.isBlank(pptpLog.getSearchEncryptMode())) { - Integer.parseInt(pptpLog.getSearchEncryptMode()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(pptpLog.getSearchFoundStartTime(), - pptpLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (pptpLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (pptpLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - pptpLog.setTableName(Configurations.getStringProperty(DfPptpLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - pptpLog.setTableName(Configurations - .getStringProperty(DfPptpLog.class.getSimpleName() + "B", "t_xa_df_pptp_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - pptpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(pptpLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - pptpLogPage = dfLogService.findPptpPageCluster( - new Page(request, response, DfPptpLog.class), pptpLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, pptpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - pptpLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfPptpLog bean = (DfPptpLog) JsonMapper.fromJsonString(str, DfPptpLog.class); - list.add(bean); - } - pptpLogPage.setList(list); - - } else { - pptpLogPage.setList(new ArrayList()); - } - } else { - - pptpLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfPptpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, pptpLog, "DF_PPTP_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfPptpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - pptpLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfPptpLog.class); - pptpLogPage.setList(List); - - } else { - pptpLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - pptpLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(pptpLog, countKey, "DF_PPTP_LOG", - getCol2Col(), searchActiveSys); - pptpLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(pptpLog, countKey, "DF_PPTP_LOG", getCol2Col(), - searchActiveSys); - pptpLogPage.setCount(Long.valueOf(hivePageCount)); - } - pptpLogPage.setPageNo(page.getPageNo()); - pptpLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - pptpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - pptpLogPage = dfLogService.findPptpPage(new Page(request, response, DfPptpLog.class), - pptpLog, searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, pptpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "searchEncryptMode参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "PPTP日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "PPTP日志检索成功", pptpLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfL2tpLogs", method = RequestMethod.GET) - @ApiOperation(value = "L2TP封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfL2tpLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfL2tpLog l2tpLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page l2tpLogPage = new Page(); - - try { - resetTime(l2tpLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, l2tpLog, DfL2tpLog.class, page); - - // 单独对Ipsec的EncryptMode字段校验 - if (!StringUtil.isBlank(l2tpLog.getSearchEncryptMode())) { - Integer.parseInt(l2tpLog.getSearchEncryptMode()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(l2tpLog.getSearchFoundStartTime(), - l2tpLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (l2tpLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (l2tpLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - l2tpLog.setTableName(Configurations.getStringProperty(DfL2tpLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - l2tpLog.setTableName(Configurations - .getStringProperty(DfL2tpLog.class.getSimpleName() + "B", "t_xa_df_l2tp_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - l2tpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(l2tpLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - l2tpLogPage = dfLogService.findL2tpPageCluster( - new Page(request, response, DfL2tpLog.class), l2tpLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, l2tpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - l2tpLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfL2tpLog bean = (DfL2tpLog) JsonMapper.fromJsonString(str, DfL2tpLog.class); - list.add(bean); - } - - l2tpLogPage.setList(list); - - } else { - l2tpLogPage.setList(new ArrayList()); - } - } else { - - l2tpLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfL2tpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, l2tpLog, "DF_L2TP_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfL2tpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - l2tpLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfL2tpLog.class); - l2tpLogPage.setList(List); - } else { - l2tpLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - l2tpLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(l2tpLog, countKey, "DF_L2TP_LOG", - getCol2Col(), searchActiveSys); - l2tpLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(l2tpLog, countKey, "DF_L2TP_LOG", getCol2Col(), - searchActiveSys); - l2tpLogPage.setCount(Long.valueOf(hivePageCount)); - } - l2tpLogPage.setPageNo(page.getPageNo()); - l2tpLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - l2tpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - l2tpLogPage = dfLogService.findL2tpPage(new Page(request, response, DfL2tpLog.class), - l2tpLog, searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, l2tpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "EncryptMode参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "L2TP日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "L2TP日志检索成功", l2tpLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfIpsecLogs", method = RequestMethod.GET) - @ApiOperation(value = "IPSEC封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfIpsecLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfIpsecLog ipsecLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page ipsecLogPage = new Page(); - - try { - resetTime(ipsecLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, ipsecLog, DfIpsecLog.class, page); - - // 单独对Ipsec的exProtocol字段校验 - if (!StringUtil.isBlank(ipsecLog.getSearchExProtocol())) { - Integer.parseInt(ipsecLog.getSearchExProtocol()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(ipsecLog.getSearchFoundStartTime(), - ipsecLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (ipsecLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (ipsecLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - ipsecLog.setTableName(Configurations.getStringProperty(DfIpsecLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - ipsecLog.setTableName(Configurations - .getStringProperty(DfIpsecLog.class.getSimpleName() + "B", "t_xa_df_ipsec_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - ipsecLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(ipsecLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - ipsecLogPage = dfLogService.findIpsecPageCluster( - new Page(request, response, DfIpsecLog.class), ipsecLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, ipsecLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - ipsecLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfIpsecLog bean = (DfIpsecLog) JsonMapper.fromJsonString(str, DfIpsecLog.class); - list.add(bean); - } - - ipsecLogPage.setList(list); - - } else { - ipsecLogPage.setList(new ArrayList()); - } - } else { - - ipsecLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfIpsecLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, ipsecLog, "DF_IPSEC_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfIpsecLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - ipsecLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfIpsecLog.class); - ipsecLogPage.setList(List); - - } else { - ipsecLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - ipsecLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipsecLog, countKey, "DF_IPSEC_LOG", - getCol2Col(), searchActiveSys); - ipsecLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipsecLog, countKey, "DF_IPSEC_LOG", - getCol2Col(), searchActiveSys); - ipsecLogPage.setCount(Long.valueOf(hivePageCount)); - } - ipsecLogPage.setPageNo(page.getPageNo()); - ipsecLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - ipsecLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - ipsecLogPage = dfLogService.findIpsecPage(new Page(request, response, DfIpsecLog.class), - ipsecLog, searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, ipsecLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "exProtocol参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "IPSEC日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "IPSEC日志检索成功", - ipsecLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfOpenVpnLogs", method = RequestMethod.GET) - @ApiOperation(value = "OPENVPN封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfOpenvpnLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfOpenvpnLog openvpnLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page openvpnLogPage = new Page(); - - try { - resetTime(openvpnLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, openvpnLog, DfOpenvpnLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(openvpnLog.getSearchFoundStartTime(), - openvpnLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (openvpnLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (openvpnLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - openvpnLog.setTableName(Configurations.getStringProperty(DfOpenvpnLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - openvpnLog.setTableName(Configurations - .getStringProperty(DfOpenvpnLog.class.getSimpleName() + "B", "t_xa_df_openvpn_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - openvpnLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(openvpnLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - openvpnLogPage = dfLogService.findOpenvpnPageCluster( - new Page(request, response, DfOpenvpnLog.class), openvpnLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, openvpnLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - openvpnLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfOpenvpnLog bean = (DfOpenvpnLog) JsonMapper.fromJsonString(str, DfOpenvpnLog.class); - list.add(bean); - } - - openvpnLogPage.setList(list); - - } else { - openvpnLogPage.setList(new ArrayList()); - } - } else { - - openvpnLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfOpenvpnLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, openvpnLog, "DF_OPENVPN_LOG", getCol2Col(), - orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfOpenvpnLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - openvpnLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfOpenvpnLog.class); - openvpnLogPage.setList(List); - - } else { - - openvpnLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - openvpnLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(openvpnLog, countKey, "DF_OPENVPN_LOG", - getCol2Col(), searchActiveSys); - openvpnLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(openvpnLog, countKey, "DF_OPENVPN_LOG", - getCol2Col(), searchActiveSys); - openvpnLogPage.setCount(Long.valueOf(hivePageCount)); - } - openvpnLogPage.setPageNo(page.getPageNo()); - openvpnLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - - if (keyExists) { - openvpnLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - openvpnLogPage = dfLogService.findOpenvpnPage( - new Page(request, response, DfOpenvpnLog.class), openvpnLog, searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, openvpnLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "OPENVPN日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "OPENVPN日志检索成功", - openvpnLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfSSHLogs", method = RequestMethod.GET) - @ApiOperation(value = "SSH封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfSshLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfSshLog sshLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page sshLogPage = new Page(); - - try { - resetTime(sshLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, sshLog, DfSshLog.class, page); - - // 单独对SSH的EncryptMode字段校验 - if (!StringUtil.isBlank(sshLog.getSearchEncryptMode())) { - Long.parseLong(sshLog.getSearchEncryptMode()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(sshLog.getSearchFoundStartTime(), - sshLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (sshLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (sshLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - sshLog.setTableName(Configurations.getStringProperty(DfSshLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - sshLog.setTableName(Configurations - .getStringProperty(DfSshLog.class.getSimpleName() + "B", "t_xa_df_ssh_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - sshLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(sshLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - sshLogPage = dfLogService.findSshPageCluster( - new Page(request, response, DfSshLog.class), sshLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, sshLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - sshLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfSshLog bean = (DfSshLog) JsonMapper.fromJsonString(str, DfSshLog.class); - list.add(bean); - } - - sshLogPage.setList(list); - - } else { - sshLogPage.setList(new ArrayList()); - } - } else { - - sshLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfSshLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, sshLog, "DF_SSH_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfSshLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - sshLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfSshLog.class); - sshLogPage.setList(List); - } else { - sshLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - sshLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sshLog, countKey, "DF_SSH_LOG", - getCol2Col(), searchActiveSys); - sshLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sshLog, countKey, "DF_SSH_LOG", getCol2Col(), - searchActiveSys); - sshLogPage.setCount(Long.valueOf(hivePageCount)); - } - sshLogPage.setPageNo(page.getPageNo()); - sshLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - sshLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - sshLogPage = dfLogService.findSshPage(new Page(request, response, DfSshLog.class), sshLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, sshLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "searchEncryptMode参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "SSH日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "SSH日志检索成功", sshLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfSSLLogs", method = RequestMethod.GET) - @ApiOperation(value = "SSL封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfSslLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfSslLog sslLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page sslLogPage = new Page(); - try { - resetTime(sslLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, sslLog, DfSslLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(sslLog.getSearchFoundStartTime(), - sslLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (sslLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (sslLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - sslLog.setTableName(Configurations.getStringProperty(DfSslLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - sslLog.setTableName(Configurations - .getStringProperty(DfSslLog.class.getSimpleName() + "B", "t_xa_df_ssl_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - sslLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(sslLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - sslLogPage = dfLogService.findSslPageCluster( - new Page(request, response, DfSslLog.class), sslLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, sslLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - sslLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfSslLog bean = (DfSslLog) JsonMapper.fromJsonString(str, DfSslLog.class); - list.add(bean); - } - - sslLogPage.setList(list); - - } else { - sslLogPage.setList(new ArrayList()); - } - } else { - - sslLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfSslLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, sslLog, "DF_SSL_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfSslLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - sslLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DfSslLog.class); - sslLogPage.setList(List); - } else { - sslLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - sslLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sslLog, countKey, "DF_SSL_LOG", - getCol2Col(), searchActiveSys); - sslLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sslLog, countKey, "DF_SSL_LOG", getCol2Col(), - searchActiveSys); - sslLogPage.setCount(Long.valueOf(hivePageCount)); - } - sslLogPage.setPageNo(page.getPageNo()); - sslLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - sslLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - sslLogPage = dfLogService.findSslPage(new Page(request, response, DfSslLog.class), sslLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, sslLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "SSL日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "SSL日志检索成功", sslLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/dfTunnelRandomLogs", method = RequestMethod.GET) - @ApiOperation(value = "隧道协议随机封堵日志获取", httpMethod = "GET", notes = "get log list") - public Map dfTunnelRandomLogs( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DfTunnelRandomLog tunnelRandomLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys)) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page tunnelRandomLogPage = new Page(); - try { - resetTime(tunnelRandomLog); - // 请求参数校验 - dfLogService.queryConditionCheck(thread, start, tunnelRandomLog, DfTunnelRandomLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(tunnelRandomLog.getSearchFoundStartTime(), - tunnelRandomLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // 神通数据库查询打开 && (( A版&&查询开始时间>神通数据库数据A最早时间)||( - // B版&&查询开始时间>神通数据库数据B最早时间)) - if (Constants.IS_SELECT_CLUSTER && ((Constants.ACTIVESYS_A.equals(searchActiveSys) - && (tunnelRandomLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_A_START_TIME) - || (Constants.ACTIVESYS_B.equals(searchActiveSys) - && (tunnelRandomLog.getSearchFoundStartTimeCluster()*1000) > Constants.CLUSTER_B_START_TIME))) { - // 打开神通数据库 - logger.info("开启神通数据库---" + System.currentTimeMillis()); - CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_H);// 开启数据源F - // 拼凑rediskeyA、B版 - if (Constants.ACTIVESYS_A.equals(searchActiveSys)) { - whichHive = "&CLUSTERA"; - // A版表名动态设置 - tunnelRandomLog.setTableName(Configurations.getStringProperty(DfTunnelRandomLog.class.getSimpleName() + "A", - "t_xa_df_ip_port_log_hit_mpp").trim()); - } else if (Constants.ACTIVESYS_B.equals(searchActiveSys)) { - whichHive = "&CLUSTERB"; - // B版表名动态设置 - tunnelRandomLog.setTableName(Configurations - .getStringProperty(DfTunnelRandomLog.class.getSimpleName() + "B", "t_xa_df_tunnel_random_log_mpp") - .trim()); - } - - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 加上AB版的条件 - key = key + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - long startTime = System.currentTimeMillis(); - logger1.info("Redis查询开始:" + startTime); - - tunnelRandomLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - - long endTime = System.currentTimeMillis(); - logger1.info(tunnelRandomLogPage.getList().size()); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - long startTime = System.currentTimeMillis(); - tunnelRandomLogPage = dfLogService.findTunnelRandomPageCluster( - new Page(request, response, DfTunnelRandomLog.class), tunnelRandomLog, - searchActiveSys); - long endTime = System.currentTimeMillis(); - if (Constants.IS_OPEN_REDIS) { - new SaveRedisThread(key, tunnelRandomLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } else { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - tunnelRandomLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DfTunnelRandomLog bean = (DfTunnelRandomLog) JsonMapper.fromJsonString(str, - DfTunnelRandomLog.class); - list.add(bean); - } - - tunnelRandomLogPage.setList(list); - - } else { - tunnelRandomLogPage.setList(new ArrayList()); - } - } else { - - tunnelRandomLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DfSslLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, tunnelRandomLog, "DF_TUNNEL_RANDOM_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DfSslLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - tunnelRandomLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DfTunnelRandomLog.class); - tunnelRandomLogPage.setList(List); - } else { - tunnelRandomLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = dfLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - tunnelRandomLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(tunnelRandomLog, countKey, - "DF_TUNNEL_RANDOM_LOG", getCol2Col(), searchActiveSys); - tunnelRandomLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(tunnelRandomLog, countKey, - "DF_TUNNEL_RANDOM_LOG", getCol2Col(), searchActiveSys); - tunnelRandomLogPage.setCount(Long.valueOf(hivePageCount)); - } - tunnelRandomLogPage.setPageNo(page.getPageNo()); - tunnelRandomLogPage.setPageSize(page.getPageSize()); - } - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = dfLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - tunnelRandomLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - tunnelRandomLogPage = dfLogService.findTunnelRandomPage( - new Page(request, response, DfTunnelRandomLog.class), tunnelRandomLog, - searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, tunnelRandomLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "隧道协议随机封堵日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "隧道协议随机封堵日志检索成功", - tunnelRandomLogPage, searchActiveSys, logSource); - } - - public Map> getCol2Col() { - Map> col2col = new HashMap>(); - Map startMap = new HashMap(); - startMap.put("start", "foundTime"); - col2col.put("searchFoundStartTime", startMap); - Map endMap = new HashMap(); - endMap.put("end", "foundTime"); - col2col.put("searchFoundEndTime", endMap); - return col2col; - } - - /** - * @Title: resetTime - * @Description: TODO(日志开始结束时间为空则默认为本地存储时间) - * @param @param - * entity - * @return Map 返回类型 - * @author (DDM) - * @version V1.0 - */ - public void resetTime(LogEntity entity) throws Exception { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - Map map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(), - entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME, "log"); - entity.setSearchFoundStartTime(map.get("startTime")); - entity.setSearchFoundEndTime(map.get("endTime")); - entity.setSearchFoundStartTimeCluster(sdf.parse(map.get("startTime")).getTime() / 1000); - entity.setSearchFoundEndTimeCluster(sdf.parse(map.get("endTime")).getTime() / 1000); - } -} diff --git a/src/main/java/com/nis/web/controller/restful/DjLogSearchController.java b/src/main/java/com/nis/web/controller/restful/DjLogSearchController.java deleted file mode 100644 index 6299d5a..0000000 --- a/src/main/java/com/nis/web/controller/restful/DjLogSearchController.java +++ /dev/null @@ -1,2304 +0,0 @@ -/** -* @Title: DjLogSearchController.java -* @Package com.nis.web.controller.restful -* @Description: TODO(用一句话描述该文件做什么) -* @author (zbc) -* @date 2016年9月7日上午8:45:58 -* @version V1.0 -*/ -package com.nis.web.controller.restful; - -import java.sql.ResultSet; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.cxf.common.util.StringUtils; -import org.apache.log4j.Logger; -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.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.nis.domain.LogEntity; -import com.nis.domain.Page; -import com.nis.domain.restful.DjDnsLog; -import com.nis.domain.restful.DjFtpLog; -import com.nis.domain.restful.DjHttpKeywordLog; -import com.nis.domain.restful.DjHttpReqLog; -import com.nis.domain.restful.DjHttpResLog; -import com.nis.domain.restful.DjIpPortLog; -import com.nis.domain.restful.DjIpsecLog; -import com.nis.domain.restful.DjL2tpLog; -import com.nis.domain.restful.DjMailLog; -import com.nis.domain.restful.DjOpenvpnLog; -import com.nis.domain.restful.DjPptpLog; -import com.nis.domain.restful.DjSshLog; -import com.nis.domain.restful.DjSslLog; -import com.nis.restful.RestBusinessCode; -import com.nis.restful.RestServiceException; -import com.nis.util.Constants; -import com.nis.util.DateUtils; -import com.nis.util.HiveJDBC; -import com.nis.util.JsonMapper; -import com.nis.util.StringUtil; -import com.nis.util.redis.RedisDao; -import com.nis.util.redis.SaveRedisThread; -import com.nis.web.controller.BaseRestController; -import com.nis.web.service.HiveSqlService; -import com.nis.web.service.SaveRequestLogThread; -import com.nis.web.service.ServicesRequestLogService; -import com.nis.web.service.restful.DjLogSearchService; -import com.wordnik.swagger.annotations.ApiOperation; - -/** - * - * @ClassName: DjLogSearchController - * @Description: TODO(这里用一句话描述这个类的作用) - * @author (zbc) - * @date 2016年9月7日上午8:45:58 - * @version V1.0 - */ -@RestController -//@RequestMapping("${servicePath}/log/v1") -@SuppressWarnings({ "rawtypes", "unchecked" }) -public class DjLogSearchController extends BaseRestController { - protected final Logger logger1 = Logger.getLogger(this.getClass()); - protected String logSource = "0"; - @Autowired - protected DjLogSearchService djLogService; - @Autowired - protected RedisDao redisDao; - @Autowired - protected ServicesRequestLogService servicesRequestLogService; - - @RequestMapping(value = "/djIpPortLogs", method = RequestMethod.GET) - @ApiOperation(value = "端口监测分页获取", httpMethod = "GET", notes = "get log list") - public Map djIpPortLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjIpPortLog ipPortLog, Model model, HttpServletRequest request, HttpServletResponse response) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page ipPortLogPage = null; - - try { - resetTime(ipPortLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, ipPortLog, DjIpPortLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(ipPortLog.getSearchFoundStartTime(), - ipPortLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List ipPortList = new ArrayList(); - ipPortLogPage = new Page(); - List strlist = redisDao.getList(key, startNum, endNum); - if (null != strlist && strlist.size() > 0) { - if (null != strlist && strlist.size() > 0) { - for (String str : strlist) { - DjIpPortLog ipPort = (DjIpPortLog) JsonMapper.fromJsonString(str, DjIpPortLog.class); - ipPortList.add(ipPort); - } - } - ipPortLogPage.setList(ipPortList); - } else { - ipPortLogPage.setList(new ArrayList()); - } - } else { - ipPortLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjIpPortLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, ipPortLog, "DJ_IP_PORT_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjIpPortLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - ipPortLogPage.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 List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjIpPortLog.class); - ipPortLogPage.setList(List); - - } else { - ipPortLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - // 判断key是否存在 - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - ipPortLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipPortLog, countKey, "DJ_IP_PORT_LOG", - getCol2Col(), searchActiveSys); - ipPortLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipPortLog, countKey, "DJ_IP_PORT_LOG", - getCol2Col(), searchActiveSys); - ipPortLogPage.setCount(Long.valueOf(hivePageCount)); - } - ipPortLogPage.setPageNo(page.getPageNo()); - ipPortLogPage.setPageSize(page.getPageSize()); - - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - ipPortLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - ipPortLogPage = djLogService - .findIpPortPage(new Page(request, response, DjIpPortLog.class), ipPortLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, ipPortLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "端口监测日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "端口监测日志检索成功", - ipPortLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djHttpReqLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议请求监测分页获取", httpMethod = "GET", notes = "get log list") - public Map djHttpReqLogList(@RequestParam(value = "searchActiveSys", required = false) String searchActiveSys, - Page page, DjHttpReqLog httpReqLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpReqLogPage = null; - - try { - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, httpReqLog, DjHttpReqLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpReqLog.getSearchFoundStartTime(), - httpReqLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List httpReqList = new ArrayList(); - httpReqLogPage = new Page(); - List strlist = redisDao.getList(key, startNum, endNum); - if (null != strlist && strlist.size() > 0) { - if (null != strlist && strlist.size() > 0) { - for (String str : strlist) { - DjHttpReqLog djHttpReqLog = (DjHttpReqLog) JsonMapper.fromJsonString(str, - DjHttpReqLog.class); - httpReqList.add(djHttpReqLog); - } - } - httpReqLogPage.setList(httpReqList); - } else { - httpReqLogPage.setList(new ArrayList()); - } - } else { - httpReqLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjHttpReqLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpReqLog, "DJ_HTTP_REQ_LOG", getCol2Col(), - orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjHttpReqLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpReqLogPage.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 List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjHttpReqLog.class); - httpReqLogPage.setList(List); - - } else { - httpReqLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpReqLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqLog, countKey, "DJ_HTTP_REQ_LOG", - getCol2Col(), searchActiveSys); - httpReqLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqLog, countKey, "DJ_HTTP_REQ_LOG", - getCol2Col(), searchActiveSys); - httpReqLogPage.setCount(Long.valueOf(hivePageCount)); - } - httpReqLogPage.setPageNo(page.getPageNo()); - httpReqLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - httpReqLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - httpReqLogPage = djLogService - .findHttpReqPage(new Page(request, response, DjHttpReqLog.class), httpReqLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpReqLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议请求日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "HTTP协议请求日志检索成功", - httpReqLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djHttpResLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议响应监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djHttpResLogsList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjHttpResLog djHttpResLog, Model model, HttpServletRequest request, - HttpServletResponse response) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page djHttpResLogPage = null; - try { - resetTime(djHttpResLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, djHttpResLog, DjHttpResLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(djHttpResLog.getSearchFoundStartTime(), - djHttpResLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List httpResList = new ArrayList(); - djHttpResLogPage = new Page(); - List list = redisDao.getList(key, startNum, endNum); - if (null != list && list.size() > 0) { - if (null != list && list.size() > 0) { - for (String str : list) { - DjHttpResLog httpResLog = (DjHttpResLog) JsonMapper.fromJsonString(str, - DjHttpResLog.class); - httpResList.add(httpResLog); - } - } - djHttpResLogPage.setList(httpResList); - } else { - djHttpResLogPage.setList(new ArrayList()); - } - } else { - - djHttpResLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjHttpResLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, djHttpResLog, "DJ_HTTP_RES_LOG", getCol2Col(), - orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjHttpResLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - djHttpResLogPage.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 List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjHttpResLog.class); - djHttpResLogPage.setList(List); - } else { - djHttpResLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - djHttpResLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(djHttpResLog, countKey, "DJ_HTTP_RES_LOG", - getCol2Col(), searchActiveSys); - djHttpResLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(djHttpResLog, countKey, "DJ_HTTP_RES_LOG", - getCol2Col(), searchActiveSys); - djHttpResLogPage.setCount(Long.valueOf(hivePageCount)); - } - djHttpResLogPage.setPageNo(page.getPageNo()); - djHttpResLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - djHttpResLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - djHttpResLogPage = djLogService.findHttpResPage( - new Page(request, response, DjHttpResLog.class), djHttpResLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, djHttpResLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议响应监测日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "HTTP协议响应监测日志检索成功", - djHttpResLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djHttpKeywordLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议关键字、请求多域、响应多域监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djHttpKeywordLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjHttpKeywordLog httpKeywordLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - String searchServiceType = httpKeywordLog.getSearchServiceType(); - if (StringUtils.isEmpty(searchServiceType)) { - httpKeywordLog.setSearchServiceType("51"); // 0x33 - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpKeywordLogPage = null; - - try { - resetTime(httpKeywordLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, httpKeywordLog, DjHttpKeywordLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpKeywordLog.getSearchFoundStartTime(), - httpKeywordLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpKeywordLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjHttpKeywordLog bean = (DjHttpKeywordLog) JsonMapper.fromJsonString(str, - DjHttpKeywordLog.class); - list.add(bean); - } - } - httpKeywordLogPage.setList(list); - } else { - httpKeywordLogPage.setList(new ArrayList()); - } - } else { - - httpKeywordLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjHttpKeywordLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpKeywordLog, "DJ_HTTP_KEYWORD_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjHttpKeywordLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpKeywordLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DjHttpKeywordLog.class); - httpKeywordLogPage.setList(List); - } else { - httpKeywordLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpKeywordLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpKeywordLog, countKey, - "DJ_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpKeywordLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpKeywordLog, countKey, - "DJ_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpKeywordLogPage.setCount(Long.valueOf(hivePageCount)); - } - httpKeywordLogPage.setPageNo(page.getPageNo()); - httpKeywordLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - - if (keyExists) { - httpKeywordLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpKeywordLogPage = djLogService.findHttpKeywordPage( - new Page(request, response, DjHttpKeywordLog.class), httpKeywordLog,searchActiveSys); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpKeywordLogPage, Constants.ORACLE_EXPIRE).start(); - } - - } - - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议关键字、请求多域、响应多域日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, - "HTTP协议关键字、请求多域、响应多域日志检索成功", httpKeywordLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djHttpReqMultiPartLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议请求多域监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djHttpReqMultiPartLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjHttpKeywordLog httpReqMultiLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - httpReqMultiLog.setSearchServiceType("61"); // 0x3d - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpReqMulitiLogPage = null; - - try { - resetTime(httpReqMultiLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, httpReqMultiLog, DjHttpKeywordLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpReqMultiLog.getSearchFoundStartTime(), - httpReqMultiLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpReqMulitiLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjHttpKeywordLog bean = (DjHttpKeywordLog) JsonMapper.fromJsonString(str, - DjHttpKeywordLog.class); - list.add(bean); - } - } - httpReqMulitiLogPage.setList(list); - } else { - httpReqMulitiLogPage.setList(new ArrayList()); - } - } else { - - httpReqMulitiLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjHttpKeywordLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpReqMultiLog, "DJ_HTTP_KEYWORD_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjHttpKeywordLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpReqMulitiLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DjHttpKeywordLog.class); - httpReqMulitiLogPage.setList(List); - } else { - httpReqMulitiLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpReqMulitiLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqMultiLog, countKey, - "DJ_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpReqMulitiLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpReqMultiLog, countKey, - "DJ_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpReqMulitiLogPage.setCount(Long.valueOf(hivePageCount)); - } - httpReqMulitiLogPage.setPageNo(page.getPageNo()); - httpReqMulitiLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - - if (keyExists) { - httpReqMulitiLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpReqMulitiLogPage = djLogService.findHttpMultiPartPage( - new Page(request, response, DjHttpKeywordLog.class), httpReqMultiLog,searchActiveSys); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpReqMulitiLogPage, Constants.ORACLE_EXPIRE).start(); - } - - } - - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议请求多域监测日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "HTTP协议请求多域监测日志检索成功", - httpReqMulitiLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djHttpResMultiPartLogs", method = RequestMethod.GET) - @ApiOperation(value = "HTTP协议响应多域监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djHttpResMultiPartLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjHttpKeywordLog httpResMultiLog, HttpServletRequest request, HttpServletResponse response, - Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - httpResMultiLog.setSearchServiceType("62"); // 0x3e - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page httpResMulitiLogPage = null; - - try { - resetTime(httpResMultiLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, httpResMultiLog, DjHttpKeywordLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(httpResMultiLog.getSearchFoundStartTime(), - httpResMultiLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - httpResMulitiLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjHttpKeywordLog bean = (DjHttpKeywordLog) JsonMapper.fromJsonString(str, - DjHttpKeywordLog.class); - list.add(bean); - } - } - httpResMulitiLogPage.setList(list); - } else { - httpResMulitiLogPage.setList(new ArrayList()); - } - } else { - - httpResMulitiLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjHttpKeywordLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, httpResMultiLog, "DJ_HTTP_KEYWORD_LOG", - getCol2Col(), orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjHttpKeywordLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - httpResMulitiLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper - .fromJsonList(jsonString, DjHttpKeywordLog.class); - httpResMulitiLogPage.setList(List); - } else { - httpResMulitiLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - httpResMulitiLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpResMultiLog, countKey, - "DJ_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpResMulitiLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(httpResMultiLog, countKey, - "DJ_HTTP_KEYWORD_LOG", getCol2Col(), searchActiveSys); - httpResMulitiLogPage.setCount(Long.valueOf(hivePageCount)); - } - httpResMulitiLogPage.setPageNo(page.getPageNo()); - httpResMulitiLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - - if (keyExists) { - httpResMulitiLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - httpResMulitiLogPage = djLogService.findHttpMultiPartPage( - new Page(request, response, DjHttpKeywordLog.class), httpResMultiLog,searchActiveSys); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, httpResMulitiLogPage, Constants.ORACLE_EXPIRE).start(); - } - - } - - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "HTTP协议响应多域监测日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "HTTP协议响应多域监测日志检索成功", - httpResMulitiLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djMailLogs", method = RequestMethod.GET) - @ApiOperation(value = "MAIL监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djMailLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjMailLog mailLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page mailLogPage = null; - - try { - resetTime(mailLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, mailLog, DjMailLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(mailLog.getSearchFoundStartTime(), - mailLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - mailLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjMailLog bean = (DjMailLog) JsonMapper.fromJsonString(str, DjMailLog.class); - list.add(bean); - } - } - mailLogPage.setList(list); - } else { - mailLogPage.setList(new ArrayList()); - } - } else { - - mailLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjMailLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, mailLog, "DJ_MAIL_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjMailLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - mailLogPage.setList(new ArrayList()); - - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjMailLog.class); - mailLogPage.setList(List); - } else { - mailLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - mailLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(mailLog, countKey, "DJ_MAIL_LOG", - getCol2Col(), searchActiveSys); - mailLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(mailLog, countKey, "DJ_MAIL_LOG", getCol2Col(), - searchActiveSys); - mailLogPage.setCount(Long.valueOf(hivePageCount)); - } - - mailLogPage.setPageNo(page.getPageNo()); - mailLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - - if (keyExists) { - mailLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - mailLogPage = djLogService.findMailPage(new Page(request, response, DjMailLog.class), - mailLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, mailLogPage, Constants.ORACLE_EXPIRE).start(); - } - - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "MAIL日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "MAIL日志检索成功", mailLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/djDnsLogs", method = RequestMethod.GET) - @ApiOperation(value = "DNS监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djDnsLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjDnsLog dnsLog, HttpServletRequest request, HttpServletResponse response, Model model) { - logger1.info("djDnsLogList接口请求方法开始----" + System.currentTimeMillis()); - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page dnsLogPage = null; - - try { - resetTime(dnsLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, dnsLog, DjDnsLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(dnsLog.getSearchFoundStartTime(), - dnsLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logger1.info("hive开始----" + System.currentTimeMillis()); - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List dnsList = new ArrayList(); - dnsLogPage = new Page(); - List list = redisDao.getList(key, startNum, endNum); - if (null != list && list.size() > 0) { - if (null != list && list.size() > 0) { - for (String str : list) { - DjDnsLog djDnsLog = (DjDnsLog) JsonMapper.fromJsonString(str, DjDnsLog.class); - dnsList.add(djDnsLog); - } - } - dnsLogPage.setList(dnsList); - } else { - dnsLogPage.setList(new ArrayList()); - } - } else { - - dnsLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjDnsLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, dnsLog, "DJ_DNS_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjDnsLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - dnsLogPage.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 List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjDnsLog.class); - dnsLogPage.setList(List); - } else { - dnsLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - dnsLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(dnsLog, countKey, "DJ_DNS_LOG", - getCol2Col(), searchActiveSys); - dnsLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(dnsLog, countKey, "DJ_DNS_LOG", getCol2Col(), - searchActiveSys); - dnsLogPage.setCount(Long.valueOf(hivePageCount)); - } - dnsLogPage.setPageNo(page.getPageNo()); - dnsLogPage.setPageSize(page.getPageSize()); - logger1.info("hive结束----" + System.currentTimeMillis()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - logger1.info("redis Key校验开始----" + System.currentTimeMillis()); - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - logger1.info("redis Key校验结束----" + System.currentTimeMillis()); - } - - if (keyExists) { - logger1.info("redis查询开始----" + System.currentTimeMillis()); - dnsLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - logger1.info("redis查询结束----" + System.currentTimeMillis()); - } else { - logger1.info("oracle查询开始----" + System.currentTimeMillis()); - dnsLogPage = djLogService.findDnsPage(new Page(request, response, DjDnsLog.class), - dnsLog,searchActiveSys); - logger1.info("oracle查询结束----" + System.currentTimeMillis()); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, dnsLogPage, Constants.ORACLE_EXPIRE).start(); - } - - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "DNS日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } finally { - logger1.info("djDnsLogList接口请求方法结束----" + System.currentTimeMillis()); - } - - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "DNS日志检索成功", dnsLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/djFtpLogs", method = RequestMethod.GET) - @ApiOperation(value = "FTP监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djFtpLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjFtpLog ftpLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page ftpLogPage = null; - - try { - resetTime(ftpLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, ftpLog, DjFtpLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(ftpLog.getSearchFoundStartTime(), - ftpLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - ftpLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjFtpLog bean = (DjFtpLog) JsonMapper.fromJsonString(str, DjFtpLog.class); - list.add(bean); - } - } - ftpLogPage.setList(list); - } else { - ftpLogPage.setList(new ArrayList()); - } - } else { - - ftpLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjFtpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, ftpLog, "DJ_FTP_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjFtpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - ftpLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjFtpLog.class); - ftpLogPage.setList(List); - } else { - ftpLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - ftpLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ftpLog, countKey, "DJ_FTP_LOG", - getCol2Col(), searchActiveSys); - ftpLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ftpLog, countKey, "DJ_FTP_LOG", getCol2Col(), - searchActiveSys); - ftpLogPage.setCount(Long.valueOf(hivePageCount)); - } - ftpLogPage.setPageNo(page.getPageNo()); - ftpLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - ftpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - ftpLogPage = djLogService.findFtpPage(new Page(request, response, DjFtpLog.class), - ftpLog,searchActiveSys); - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, ftpLogPage, Constants.ORACLE_EXPIRE).start(); - } - - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "FTP日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "FTP日志检索成功", ftpLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/djPPTPLogs", method = RequestMethod.GET) - @ApiOperation(value = "PPTP监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djPptpLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjPptpLog pptpLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page pptpLogPage = null; - - try { - resetTime(pptpLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, pptpLog, DjPptpLog.class, page); - - // 单独对PPTP的EncryptMode字段校验 - if (!StringUtil.isBlank(pptpLog.getSearchEncryptMode())) { - Integer.parseInt(pptpLog.getSearchEncryptMode()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(pptpLog.getSearchFoundStartTime(), - pptpLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - pptpLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjPptpLog bean = (DjPptpLog) JsonMapper.fromJsonString(str, DjPptpLog.class); - list.add(bean); - } - } - - pptpLogPage.setList(list); - - } else { - pptpLogPage.setList(new ArrayList()); - } - } else { - - pptpLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjPptpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, pptpLog, "DJ_PPTP_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjPptpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - pptpLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjPptpLog.class); - pptpLogPage.setList(List); - - } else { - pptpLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - pptpLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(pptpLog, countKey, "DJ_PPTP_LOG", - getCol2Col(), searchActiveSys); - pptpLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(pptpLog, countKey, "DJ_PPTP_LOG", getCol2Col(), - searchActiveSys); - pptpLogPage.setCount(Long.valueOf(hivePageCount)); - } - - pptpLogPage.setPageNo(page.getPageNo()); - pptpLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - pptpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - pptpLogPage = djLogService.findPptpPage(new Page(request, response, DjPptpLog.class), - pptpLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, pptpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "searchEncryptMode参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "PPTP日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "PPTP日志检索成功", pptpLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/djL2tpLogs", method = RequestMethod.GET) - @ApiOperation(value = "L2TP监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djL2tpLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjL2tpLog l2tpLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page l2tpLogPage = null; - - try { - resetTime(l2tpLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, l2tpLog, DjL2tpLog.class, page); - - // 单独对Ipsec的EncryptMode字段校验 - if (!StringUtil.isBlank(l2tpLog.getSearchEncryptMode())) { - Integer.parseInt(l2tpLog.getSearchEncryptMode()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(l2tpLog.getSearchFoundStartTime(), - l2tpLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - l2tpLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjL2tpLog bean = (DjL2tpLog) JsonMapper.fromJsonString(str, DjL2tpLog.class); - list.add(bean); - } - } - - l2tpLogPage.setList(list); - - } else { - l2tpLogPage.setList(new ArrayList()); - } - } else { - - l2tpLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjL2tpLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, l2tpLog, "DJ_L2TP_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjL2tpLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - l2tpLogPage.setList(new ArrayList()); - - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjL2tpLog.class); - l2tpLogPage.setList(List); - - } else { - l2tpLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - l2tpLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(l2tpLog, countKey, "DJ_L2TP_LOG", - getCol2Col(), searchActiveSys); - l2tpLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(l2tpLog, countKey, "DJ_L2TP_LOG", getCol2Col(), - searchActiveSys); - l2tpLogPage.setCount(Long.valueOf(hivePageCount)); - } - l2tpLogPage.setPageNo(page.getPageNo()); - l2tpLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - l2tpLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - l2tpLogPage = djLogService.findL2tpPage(new Page(request, response, DjL2tpLog.class), - l2tpLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, l2tpLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "EncryptMode参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "L2TP日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "L2TP日志检索成功", l2tpLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/djIpsecLogs", method = RequestMethod.GET) - @ApiOperation(value = "IPSEC监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djIpsecLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjIpsecLog ipsecLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page ipsecLogPage = null; - - try { - resetTime(ipsecLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, ipsecLog, DjIpsecLog.class, page); - - // 单独对Ipsec的exProtocol字段校验 - if (!StringUtil.isBlank(ipsecLog.getSearchExProtocol())) { - Integer.parseInt(ipsecLog.getSearchExProtocol()); - } - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(ipsecLog.getSearchFoundStartTime(), - ipsecLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - ipsecLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjIpsecLog bean = (DjIpsecLog) JsonMapper.fromJsonString(str, DjIpsecLog.class); - list.add(bean); - } - } - - ipsecLogPage.setList(list); - - } else { - ipsecLogPage.setList(new ArrayList()); - } - } else { - - ipsecLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjIpsecLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, ipsecLog, "DJ_IPSEC_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjIpsecLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - ipsecLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjIpsecLog.class); - ipsecLogPage.setList(List); - } else { - ipsecLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - ipsecLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipsecLog, countKey, "DJ_IPSEC_LOG", - getCol2Col(), searchActiveSys); - ipsecLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(ipsecLog, countKey, "DJ_IPSEC_LOG", - getCol2Col(), searchActiveSys); - ipsecLogPage.setCount(Long.valueOf(hivePageCount)); - } - ipsecLogPage.setPageNo(page.getPageNo()); - ipsecLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - ipsecLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - ipsecLogPage = djLogService.findIpsecPage(new Page(request, response, DjIpsecLog.class), - ipsecLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, ipsecLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "exProtocol参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "IPSEC日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "IPSEC日志检索成功", - ipsecLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djOpenVpnLogs", method = RequestMethod.GET) - @ApiOperation(value = "OPENVPN监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djOpenvpnLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjOpenvpnLog openvpnLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page openvpnLogPage = null; - - try { - resetTime(openvpnLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, openvpnLog, DjOpenvpnLog.class, page); - if (Constants.ONLY_SEL_FROM_HIVE - || (HiveSqlService.ifTimeGreaterThan48(openvpnLog.getSearchFoundStartTime(), - openvpnLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据\ - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - openvpnLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjOpenvpnLog bean = (DjOpenvpnLog) JsonMapper.fromJsonString(str, DjOpenvpnLog.class); - list.add(bean); - } - } - - openvpnLogPage.setList(list); - - } else { - openvpnLogPage.setList(new ArrayList()); - } - } else { - - openvpnLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjOpenvpnLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, openvpnLog, "DJ_OPENVPN_LOG", getCol2Col(), - orderBy, searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjOpenvpnLog.class, - "foundTime", "recvTime"); - if (tableMapping == null) { - openvpnLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjOpenvpnLog.class); - openvpnLogPage.setList(List); - - } else { - openvpnLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - openvpnLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(openvpnLog, countKey, "DJ_OPENVPN_LOG", - getCol2Col(), searchActiveSys); - openvpnLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(openvpnLog, countKey, "DJ_OPENVPN_LOG", - getCol2Col(), searchActiveSys); - openvpnLogPage.setCount(Long.valueOf(hivePageCount)); - } - - openvpnLogPage.setPageNo(page.getPageNo()); - openvpnLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - openvpnLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), - Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - openvpnLogPage = djLogService - .findOpenvpnPage(new Page(request, response, DjOpenvpnLog.class), openvpnLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, openvpnLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "OPENVPN日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "OPENVPN日志检索成功", - openvpnLogPage, searchActiveSys, logSource); - } - - @RequestMapping(value = "/djSSHLogs", method = RequestMethod.GET) - @ApiOperation(value = "SSH监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djSshLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjSshLog sshLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page sshLogPage = null; - - try { - resetTime(sshLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, sshLog, DjSshLog.class, page); - - // 单独对SSH的EncryptMode字段校验 - if (!StringUtil.isBlank(sshLog.getSearchEncryptMode())) { - Long.parseLong(sshLog.getSearchEncryptMode()); - } - - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(sshLog.getSearchFoundStartTime(), - sshLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - sshLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjSshLog bean = (DjSshLog) JsonMapper.fromJsonString(str, DjSshLog.class); - list.add(bean); - } - } - - sshLogPage.setList(list); - - } else { - sshLogPage.setList(new ArrayList()); - } - } else { - - sshLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjSshLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, sshLog, "DJ_SSH_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjSshLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - sshLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjSshLog.class); - sshLogPage.setList(List); - - } else { - sshLogPage.setList(new ArrayList()); - } - } - } - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - sshLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sshLog, countKey, "DJ_SSH_LOG", - getCol2Col(), searchActiveSys); - sshLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sshLog, countKey, "DJ_SSH_LOG", getCol2Col(), - searchActiveSys); - sshLogPage.setCount(Long.valueOf(hivePageCount)); - } - sshLogPage.setPageNo(page.getPageNo()); - sshLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - sshLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - sshLogPage = djLogService.findSshPage(new Page(request, response, DjSshLog.class), - sshLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, sshLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (NumberFormatException e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - RestServiceException restE = new RestServiceException(thread, System.currentTimeMillis() - start, - "searchEncryptMode参数格式错误", RestBusinessCode.param_formate_error.getValue()); - restE.setActiveSys(searchActiveSys); - restE.setLogSource(logSource); - throw restE; - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "SSH日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "SSH日志检索成功", sshLogPage, - searchActiveSys, logSource); - } - - @RequestMapping(value = "/djSSLLogs", method = RequestMethod.GET) - @ApiOperation(value = "SSL监测日志获取", httpMethod = "GET", notes = "get log list") - public Map djSslLogList( - @RequestParam(value = "searchActiveSys", required = false, defaultValue = Constants.ACTIVESYS_B) String searchActiveSys, - Page page, DjSslLog sslLog, HttpServletRequest request, HttpServletResponse response, Model model) { - String whichHive = "&HIVEB"; - if (!Constants.ACTIVESYS_A.equals(searchActiveSys) - && !Constants.ACTIVESYS_C.equals(searchActiveSys) ) { - searchActiveSys = Constants.ACTIVESYS_B; - whichHive = "&HIVEB"; - } else { - whichHive = "&HIVEA"; - } - - long start = System.currentTimeMillis(); - SaveRequestLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); - boolean keyExists = false; - String key = ""; - String countKey = ""; - Page sslLogPage = null; - - try { - resetTime(sslLog); - // 请求参数校验 - djLogService.queryConditionCheck(thread, start, sslLog, DjSslLog.class, page); - - if (Constants.ONLY_SEL_FROM_HIVE || (HiveSqlService.ifTimeGreaterThan48(sslLog.getSearchFoundStartTime(), - sslLog.getSearchFoundEndTime()) && Constants.SEL_FROM_HIVE)) {// 从数据库中查询数据 - logSource = "1"; - // if (true) { - int startNum = (page.getPageNo() - 1) * page.getPageSize(); - int endNum = startNum + page.getPageSize() - 1; - if (Constants.IS_OPEN_REDIS && Constants.DATACENTER_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, true) + whichHive; - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - if (keyExists) { - List list = new ArrayList(); - sslLogPage = new Page(); - List strList = redisDao.getList(key, startNum, endNum); - if (null != strList && strList.size() > 0) { - if (null != strList && strList.size() > 0) { - for (String str : strList) { - DjSslLog bean = (DjSslLog) JsonMapper.fromJsonString(str, DjSslLog.class); - list.add(bean); - } - } - sslLogPage.setList(list); - } else { - sslLogPage.setList(new ArrayList()); - } - } else { - sslLogPage = new Page(); - String orderBy = ""; - if (null != page.getOrderBy() && !page.getOrderBy().equals("")) { - orderBy = page.getOrderBySql(DjSslLog.class.getSimpleName(), page.getOrderBy()); - } else { - orderBy = "found_Time"; - } - ResultSet rs = HiveSqlService.getResultSet(page, sslLog, "DJ_SSL_LOG", getCol2Col(), orderBy, - searchActiveSys); - Map tableMapping = HiveJDBC.tableMapping(page, key, rs, DjSslLog.class, "foundTime", - "recvTime"); - if (tableMapping == null) { - sslLogPage.setList(new ArrayList()); - } else { - List strList = new ArrayList(); - if (tableMapping.get("obj").size() > page.getPageSize()) { - strList = tableMapping.get("obj").subList(0, page.getPageSize()); - } else { - strList = tableMapping.get("obj").subList(0, tableMapping.get("obj").size()); - } - if (strList.size() > 0) { - String jsonString = JsonMapper.toJsonString(strList); - List List = (java.util.List) JsonMapper.fromJsonList(jsonString, - DjSslLog.class); - sslLogPage.setList(List); - } else { - sslLogPage.setList(new ArrayList()); - } - } - } - - if (Constants.IS_OPEN_REDIS && Constants.IS_GET_HIVECOUNT) { - countKey = djLogService.getJedisKey(request, true) + "&pageCount" + whichHive; - // 判断key是否存在 - boolean countKeyExists = redisDao.exists(countKey); - if (countKeyExists) { - String count = redisDao.getString(countKey); - sslLogPage.setCount(Long.valueOf(count)); - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sslLog, countKey, "DJ_SSL_LOG", - getCol2Col(), searchActiveSys); - sslLogPage.setCount(Long.valueOf(hivePageCount)); - } - } else { - Long hivePageCount = HiveSqlService.getHivePageCount(sslLog, countKey, "DJ_SSL_LOG", getCol2Col(), - searchActiveSys); - sslLogPage.setCount(Long.valueOf(hivePageCount)); - } - sslLogPage.setPageNo(page.getPageNo()); - sslLogPage.setPageSize(page.getPageSize()); - } else {// 从oracle中查询数据 - if (Constants.IS_OPEN_REDIS) { - // 根据查询条件获取key - key = djLogService.getJedisKey(request, false); - // 判断key是否存在 - keyExists = redisDao.exists(key); - } - // 存在则直接从redis中查询 - if (keyExists) { - sslLogPage = (Page) JsonMapper.fromJsonString(redisDao.getString(key), Page.class); - } else { - // 不存在则查询数据库并保存查询结果到redis中 - sslLogPage = djLogService.findSslPage(new Page(request, response, DjSslLog.class), - sslLog,searchActiveSys); - - if (Constants.IS_OPEN_REDIS) - new SaveRedisThread(key, sslLogPage, Constants.ORACLE_EXPIRE).start(); - } - } - } catch (Exception e) { - thread.setExceptionInfo(e.getMessage() + " " + e.getCause()); - e.printStackTrace(); - logger1.error(e); - if (!(e instanceof RestServiceException)) { - e = new RestServiceException(thread, System.currentTimeMillis() - start, "SSL日志检索失败"); - } - ((RestServiceException) e).setActiveSys(searchActiveSys); - ((RestServiceException) e).setLogSource(logSource); - throw ((RestServiceException) e); - } - return serviceResponse(thread, System.currentTimeMillis() - start, request, response, "SSL日志检索成功", sslLogPage, - searchActiveSys, logSource); - } - - public Map> getCol2Col() { - Map> col2col = new HashMap>(); - Map startMap = new HashMap(); - startMap.put("start", "foundTime"); - col2col.put("searchFoundStartTime", startMap); - Map endMap = new HashMap(); - endMap.put("end", "foundTime"); - col2col.put("searchFoundEndTime", endMap); - return col2col; - } - - /** - * @Title: resetTime - * @Description: TODO(日志开始结束时间为空则默认为本地存储时间) - * @param @param - * entity - * @return Map 返回类型 - * @author (DDM) - * @version V1.0 - */ - public void resetTime(LogEntity entity) throws Exception{ - Map map = DateUtils.getLocalTime(entity.getSearchFoundStartTime(), - entity.getSearchFoundEndTime(), Constants.LOG_LOCAL_TIME,"log"); - entity.setSearchFoundStartTime(map.get("startTime")); - entity.setSearchFoundEndTime(map.get("endTime")); - } -} diff --git a/src/main/java/com/nis/web/controller/restful/IntervalTimeSearchController.java b/src/main/java/com/nis/web/controller/restful/IntervalTimeSearchController.java index 5ef436f..b9ecf1f 100644 --- a/src/main/java/com/nis/web/controller/restful/IntervalTimeSearchController.java +++ b/src/main/java/com/nis/web/controller/restful/IntervalTimeSearchController.java @@ -50,7 +50,7 @@ public class IntervalTimeSearchController extends BaseRestController{ @Autowired protected ServicesRequestLogService servicesRequestLogService; - protected String logSource = "0"; + protected Integer logSource = 0; @RequestMapping(value="/djFlowControlStopSources", method = RequestMethod.GET) @ApiOperation(value="监测规则流控信息获取" , httpMethod = "GET", notes="get log list") @@ -59,9 +59,12 @@ public class IntervalTimeSearchController extends BaseRestController{ Page page, DjFlowControlStop flowControlStop, HttpServletRequest request, HttpServletResponse response, Model model) { - if(!Constants.ACTIVESYS_A.equals(searchActiveSys) + if (!Constants.ACTIVESYS_A.equals(searchActiveSys) && !Constants.ACTIVESYS_C.equals(searchActiveSys) - )searchActiveSys=Constants.ACTIVESYS_B; + ) { + searchActiveSys=Constants.ACTIVESYS_B; + + } long start=System.currentTimeMillis(); SaveRequestLogThread thread=super.saveRequestLog(servicesRequestLogService,Constants.OPACTION_GET,request, null); @@ -79,11 +82,10 @@ public class IntervalTimeSearchController extends BaseRestController{ if (!(e instanceof RestServiceException)) { e = new RestServiceException(thread, System.currentTimeMillis() - start, "监测规则流控信息检索失败"); } - ((RestServiceException) e).setActiveSys(searchActiveSys); ((RestServiceException) e).setLogSource(logSource); throw ((RestServiceException) e); } - return serviceResponse(thread,System.currentTimeMillis()-start,request, response, "监测规则流控信息检索成功",flowControlStopPage - ,searchActiveSys, logSource); + return serviceLogResponse(thread, System.currentTimeMillis()-start,request, "监测规则流控信息检索成功", flowControlStopPage + , logSource); } } diff --git a/src/main/java/com/nis/web/controller/restful/LogController.java b/src/main/java/com/nis/web/controller/restful/LogController.java new file mode 100644 index 0000000..49a1a4d --- /dev/null +++ b/src/main/java/com/nis/web/controller/restful/LogController.java @@ -0,0 +1,58 @@ +package com.nis.web.controller.restful; + +import com.nis.domain.Page; +import com.nis.domain.restful.NtcIpLog; +import com.nis.util.Constants; +import com.nis.web.controller.BaseRestController; +import com.nis.web.service.SaveRequestLogThread; +import com.nis.web.service.ServicesRequestLogService; +import com.nis.web.service.restful.LogTestService; +import com.wordnik.swagger.annotations.Api; +import com.wordnik.swagger.annotations.ApiOperation; +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; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Map; + +/** + * Created by darnell on 2018/6/10. + */ +@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 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 ntcIpLogPage = new Page<>(); + try { + ntcIpLogPage = testService.findNtcIpLogPage( + new Page(request, response, NtcIpLog.class), ntcIpLog); + + } catch(Exception e) { + e.printStackTrace(); + } + + + + + + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "IP地址日志检索成功", ntcIpLogPage, 0); + } + + +} diff --git a/src/main/java/com/nis/web/controller/sys/AreaController.java b/src/main/java/com/nis/web/controller/sys/AreaController.java index 65525a2..dbb8048 100644 --- a/src/main/java/com/nis/web/controller/sys/AreaController.java +++ b/src/main/java/com/nis/web/controller/sys/AreaController.java @@ -24,7 +24,7 @@ import com.nis.web.controller.BaseController; @Controller @RequestMapping("${adminPath}/sys/area") public class AreaController extends BaseController { - + @ModelAttribute public SysArea get(@RequestParam(required=false) Long id) { diff --git a/src/main/java/com/nis/web/service/BaseLogService.java b/src/main/java/com/nis/web/service/BaseLogService.java index 0deefe9..2cf280d 100644 --- a/src/main/java/com/nis/web/service/BaseLogService.java +++ b/src/main/java/com/nis/web/service/BaseLogService.java @@ -219,7 +219,7 @@ public abstract class BaseLogService { /** * wx 报表查询条件检查 * - * @param className + * @param clazz * 需要检验的实体名称[需要保证resultMap的id命名方式为[className]Map] * @param page * 需要校验的page对象 diff --git a/src/main/java/com/nis/web/service/SaveRequestLogThread.java b/src/main/java/com/nis/web/service/SaveRequestLogThread.java index 087121c..08c4fea 100644 --- a/src/main/java/com/nis/web/service/SaveRequestLogThread.java +++ b/src/main/java/com/nis/web/service/SaveRequestLogThread.java @@ -19,8 +19,9 @@ import org.apache.log4j.Logger; import com.nis.datasource.CustomerContextHolder; /** + * 审计日志工作线程 * @ClassName: SaveLogThread.java - * @Description: TODO + * @Description: 用于记录业务操作日志,后期用于审计及相关联调验证工作 * @author (dell) * @date 2016年10月14日 下午6:26:41 * @version V1.0 @@ -66,7 +67,6 @@ public class SaveRequestLogThread implements Runnable { * 创建一个新的实例 SaveRequestLogThread. * * @param service - * @param requestAddr * @param requestURI * @param queryString * @param contextPath diff --git a/src/main/java/com/nis/web/service/ServicesRequestLogService.java b/src/main/java/com/nis/web/service/ServicesRequestLogService.java index 91ae120..4b71063 100644 --- a/src/main/java/com/nis/web/service/ServicesRequestLogService.java +++ b/src/main/java/com/nis/web/service/ServicesRequestLogService.java @@ -67,9 +67,6 @@ public class ServicesRequestLogService { * request中的参数 * @param contextPath * request中的参数 - * @param request - * 请求 - * @param response * 响应 * @param operator * 操作人 diff --git a/src/main/java/com/nis/web/service/restful/LogTestService.java b/src/main/java/com/nis/web/service/restful/LogTestService.java new file mode 100644 index 0000000..93e53c0 --- /dev/null +++ b/src/main/java/com/nis/web/service/restful/LogTestService.java @@ -0,0 +1,89 @@ +package com.nis.web.service.restful; + +import com.beust.jcommander.internal.Lists; +import com.nis.domain.Page; +import com.nis.domain.restful.DfIpPortLog; +import com.nis.domain.restful.NtcIpLog; +import com.nis.util.Constants; +import com.nis.web.service.BaseLogService; +import org.apache.log4j.Logger; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Created by darnell on 2018/6/10. + * 日志测试业务类,用于接口或临时验证测试使用 + */ +@Service +public class LogTestService extends BaseLogService { + + protected final Logger logger = Logger.getLogger(this.getClass()); + + + /** + * IP地址日志检索测试业务方法 + * @param page + * @param entity + * @return + * @throws Exception + */ + public Page findNtcIpLogPage(Page page, NtcIpLog entity) throws Exception{ + List ntcIpLogs = Lists.newArrayList(); + NtcIpLog ntcIpLog = new NtcIpLog(); + ntcIpLog.setId(35L); + ntcIpLog.setCfgId(531L); + ntcIpLog.setServiceType(16); + ntcIpLog.setFoundTime(new Date()); + ntcIpLog.setRecvTime(new Date()); + ntcIpLog.setAddrType(4); + ntcIpLog.setProtocol("IPv4_TCP"); + ntcIpLog.setClientIp("192.168.10.106"); + ntcIpLog.setClientPort(80); + ntcIpLog.setServerIp("202.106.0.20"); + ntcIpLog.setServerPort(8443); + ntcIpLog.setCljIp("10.0.6.240"); + ntcIpLog.setDeviceId(1356981); + ntcIpLog.setDirection(0); + ntcIpLog.setStreamType(0); + ntcIpLog.setEntranceId(21L); + ntcIpLog.setUserRegion("531"); + ntcIpLog.setClientLocate("本地地址"); + ntcIpLog.setServerLocate("中国 北京 电信宽带光纤"); + ntcIpLogs.add(ntcIpLog); + + ntcIpLog = new NtcIpLog(); + ntcIpLog.setId(36L); + ntcIpLog.setCfgId(532L); + ntcIpLog.setServiceType(128); + ntcIpLog.setFoundTime(new Date()); + ntcIpLog.setRecvTime(new Date()); + ntcIpLog.setAddrType(4); + ntcIpLog.setProtocol("IPv4_TCP"); + ntcIpLog.setClientIp("192.168.10.106"); + ntcIpLog.setClientPort(80); + ntcIpLog.setServerIp("202.106.0.20"); + ntcIpLog.setServerPort(8443); + ntcIpLog.setCljIp("10.0.6.240"); + ntcIpLog.setDeviceId(1356981); + ntcIpLog.setDirection(0); + ntcIpLog.setStreamType(0); + ntcIpLog.setEntranceId(21L); + ntcIpLog.setUserRegion("531"); + ntcIpLog.setClientLocate("本地地址"); + ntcIpLog.setServerLocate("中国 北京 电信宽带光纤"); + ntcIpLogs.add(ntcIpLog); + page.setCount(ntcIpLogs.size()); + + page.setList(ntcIpLogs); + + + return page; + } + + + + +}