diff --git a/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java b/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java index 9df8852..09b30cd 100644 --- a/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java +++ b/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java @@ -1,44 +1,8 @@ package com.nis.web.controller.restful; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Map; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -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 com.nis.datasource.CustomerContextHolder; import com.nis.domain.Page; -import com.nis.domain.restful.NtcAppLog; -import com.nis.domain.restful.NtcBgpLog; -import com.nis.domain.restful.NtcCollectRadiusLog; -import com.nis.domain.restful.NtcCollectVoipLog; -import com.nis.domain.restful.NtcConnRecordLog; -import com.nis.domain.restful.NtcConnRecordPercent; -import com.nis.domain.restful.NtcDdosLog; -import com.nis.domain.restful.NtcDnsLog; -import com.nis.domain.restful.NtcFtpLog; -import com.nis.domain.restful.NtcHttpLog; -import com.nis.domain.restful.NtcHttpRecordLog; -import com.nis.domain.restful.NtcIpLog; -import com.nis.domain.restful.NtcIpsecLog; -import com.nis.domain.restful.NtcKeywordsUrlLog; -import com.nis.domain.restful.NtcL2tpLog; -import com.nis.domain.restful.NtcMailLog; -import com.nis.domain.restful.NtcOpenvpnLog; -import com.nis.domain.restful.NtcP2pLog; -import com.nis.domain.restful.NtcPptpLog; -import com.nis.domain.restful.NtcSshLog; -import com.nis.domain.restful.NtcSslLog; -import com.nis.domain.restful.NtcSslRecordLog; -import com.nis.domain.restful.NtcStreamingMediaLog; -import com.nis.domain.restful.NtcVoipLog; +import com.nis.domain.restful.*; import com.nis.domain.restful.dashboard.TrafficAsnStatistic; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; @@ -47,15 +11,22 @@ import com.nis.util.Constants; import com.nis.util.DateUtils; import com.nis.util.ExceptionUtil; import com.nis.web.controller.BaseRestController; -import com.nis.web.service.AuditLogThread; -import com.nis.web.service.LogDataService; -import com.nis.web.service.NtcHttpRecordLogsService; -import com.nis.web.service.NtcSslRecordLogsService; -import com.nis.web.service.ServicesRequestLogService; +import com.nis.web.service.*; import com.nis.web.service.restful.NtcLogService; import com.wordnik.swagger.annotations.Api; import com.wordnik.swagger.annotations.ApiOperation; import com.zdjizhi.utils.StringUtil; +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.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Map; /** * @ClassName:NtcLogSearchController @@ -702,18 +673,18 @@ public class NtcLogSearchController extends BaseRestController { public Map ntcConnRecordLogs(Page page, NtcConnRecordLog ntcConnRecordLog, Model model, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); - AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, - null); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null); + try { - if (StringUtil.isEmpty(ntcConnRecordLog.getSearchFoundStartTime()) - && StringUtil.isEmpty(ntcConnRecordLog.getSearchFoundEndTime())) { + if (StringUtil.isBlank(ntcConnRecordLog.getSearchFoundStartTime()) + && StringUtil.isBlank(ntcConnRecordLog.getSearchFoundEndTime())) { Map map = DateUtils.getLocalTime(null, null, Constants.LOG_LOCAL_TIME, "minute"); ntcConnRecordLog.setSearchFoundStartTime(map.get("startTime")); ntcConnRecordLog.setSearchFoundEndTime(map.get("endTime")); } - ntcLogService.queryConditionCheck(auditLogThread, start, ntcConnRecordLog, NtcConnRecordLog.class, page); - ntcLogService.ntcConnRecordLogsQueryConditionCheck(auditLogThread, start, ntcConnRecordLog, - NtcConnRecordLog.class, page); + + ntcLogService.ntcConnRecordLogsConditionCheck(auditLogThread, start, ntcConnRecordLog, NtcConnRecordLog.class, page); + logDataService.getData(page, ntcConnRecordLog); } catch (Exception e) { auditLogThread.setExceptionInfo("通联关系日志检索失败:" + e.getMessage()); diff --git a/src/main/java/com/nis/web/service/BaseLogService.java b/src/main/java/com/nis/web/service/BaseLogService.java index 410ee38..1532e52 100644 --- a/src/main/java/com/nis/web/service/BaseLogService.java +++ b/src/main/java/com/nis/web/service/BaseLogService.java @@ -10,7 +10,9 @@ import com.nis.restful.RestServiceException; import com.nis.restful.ServiceRuntimeException; import com.nis.util.ExceptionUtil; import com.nis.util.elasticsearch.ElasticsearchSqlDao; +import com.zdjizhi.utils.DateUtils; import com.zdjizhi.utils.StringUtil; +import com.zdjizhi.utils.TimeConstants; import org.apache.ibatis.mapping.ResultMap; import org.apache.ibatis.mapping.ResultMapping; import org.apache.ibatis.session.SqlSessionFactory; @@ -20,8 +22,6 @@ import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletRequest; import java.io.Serializable; import java.lang.reflect.Field; -import java.text.ParseException; -import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -36,7 +36,6 @@ import java.util.Map; @SuppressWarnings({ "rawtypes" }) public abstract class BaseLogService { - private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); protected final Logger logger = Logger.getLogger(this.getClass()); @Autowired protected ElasticsearchSqlDao elasticsearchSqlDao; @@ -163,6 +162,7 @@ public abstract class BaseLogService { throw new RestServiceException("getSearchDirection参数错误", RestBusinessCode.param_formate_error.getValue()); } + try { if (!StringUtil.isBlank(entity.getSearchEntranceId())) { Long.parseLong(entity.getSearchEntranceId()); @@ -175,24 +175,17 @@ public abstract class BaseLogService { try { if (!StringUtil.isBlank(entity.getSearchFoundEndTime())) { - sdf.setLenient(false); - sdf.parse(entity.getSearchFoundEndTime()); + DateUtils.convertStringToDate(entity.getSearchFoundEndTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchFoundEndTime参数格式错误", RestBusinessCode.param_formate_error.getValue()); } catch (Exception e) { throw new RestServiceException("searchFoundEndTime参数错误", RestBusinessCode.param_formate_error.getValue()); } try { if (!StringUtil.isBlank(entity.getSearchFoundStartTime())) { - sdf.setLenient(false); - sdf.parse(entity.getSearchFoundStartTime()); + DateUtils.convertStringToDate(entity.getSearchFoundStartTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchFoundStartTime参数格式错误", - RestBusinessCode.param_formate_error.getValue()); - } catch (Exception e) { + } catch (Exception e) { throw new RestServiceException("searchFoundStartTime参数错误", RestBusinessCode.param_formate_error.getValue()); } //service参数改为可以传多个 @@ -207,15 +200,7 @@ public abstract class BaseLogService { } } -// try { -// if (!StringUtil.isBlank(entity.getSearchService())) { -// Integer.parseInt(entity.getSearchService()); -// } -// } catch (NumberFormatException e) { -// throw new RestServiceException("searchService参数格式错误", RestBusinessCode.param_formate_error.getValue()); -// } catch (Exception e) { -// throw new RestServiceException("searchService参数错误", RestBusinessCode.param_formate_error.getValue()); -// } + try { checkCloumnIsExist(thread, start, clazz, page); } catch (RestServiceException e) { @@ -242,24 +227,17 @@ public abstract class BaseLogService { logger.info("请求参数校验开始----" + System.currentTimeMillis()); try { if (!StringUtil.isBlank(entity.getSearchFoundEndTime())) { - sdf.setLenient(false); - sdf.parse(entity.getSearchFoundEndTime()); + DateUtils.convertStringToDate(entity.getSearchFoundEndTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchFoundEndTime参数格式错误", RestBusinessCode.param_formate_error.getValue()); } catch (Exception e) { - throw new RestServiceException("searchFoundEndTime参数格式格式", RestBusinessCode.param_formate_error.getValue()); + throw new RestServiceException("searchFoundEndTime参数错误", RestBusinessCode.param_formate_error.getValue()); } try { if (!StringUtil.isBlank(entity.getSearchFoundStartTime())) { - sdf.setLenient(false); - sdf.parse(entity.getSearchFoundStartTime()); + DateUtils.convertStringToDate(entity.getSearchFoundStartTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchFoundStartTime参数格式错误", - RestBusinessCode.param_formate_error.getValue()); - } catch (Exception e) { + } catch (Exception e) { throw new RestServiceException("searchFoundStartTime参数错误", RestBusinessCode.param_formate_error.getValue()); } @@ -296,28 +274,24 @@ public abstract class BaseLogService { // searchService checkNumericCondition(thread, start, entity.getSearchService(), "searchService"); + try { if (!StringUtil.isBlank(entity.getSearchReportStartTime())) { - sdf.parse(entity.getSearchReportStartTime()); + DateUtils.convertStringToDate(entity.getSearchReportStartTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchReportStartTime参数格式错误", - RestBusinessCode.param_formate_error.getValue()); } catch (Exception e) { - throw new RestServiceException("searchReportStartTime参数错误", - RestBusinessCode.param_formate_error.getValue()); + throw new RestServiceException("searchReportStartTime参数格式错误", RestBusinessCode.param_formate_error.getValue()); } try { if (!StringUtil.isBlank(entity.getSearchReportEndTime())) { - sdf.parse(entity.getSearchReportEndTime()); + DateUtils.convertStringToDate(entity.getSearchReportEndTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchReportEndTime参数格式错误", - RestBusinessCode.param_formate_error.getValue()); - } catch (Exception e) { + } catch (Exception e) { throw new RestServiceException("searchReportEndTime参数错误", RestBusinessCode.param_formate_error.getValue()); } + + if (!StringUtil.isBlank(entity.getSearchBusinessType()) && !StringUtil.isNumeric(entity.getSearchBusinessType())) { throw new RestServiceException("searchBusinessType参数格式错误", RestBusinessCode.param_formate_error.getValue()); @@ -370,35 +344,29 @@ public abstract class BaseLogService { throw new RestServiceException("searchBusinessType参数格式错误", RestBusinessCode.param_formate_error.getValue()); } - int timeCount = 0; + if (StringUtil.isBlank(entity.getSearchReportStartTime()) + || StringUtil.isBlank(entity.getSearchReportEndTime())) { + throw new RestServiceException("searchReportStartTime和searchReportEndTime参数必须同时填写", + RestBusinessCode.config_integrity_error.getValue()); + } + try { if (!StringUtil.isBlank(entity.getSearchReportStartTime())) { - sdf.parse(entity.getSearchReportStartTime()); - timeCount++; + DateUtils.convertStringToDate(entity.getSearchReportStartTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchReportStartTime参数格式错误", - RestBusinessCode.param_formate_error.getValue()); - } catch (Exception e) { + } catch (Exception e) { throw new RestServiceException("searchReportStartTime参数错误", RestBusinessCode.param_formate_error.getValue()); } try { if (!StringUtil.isBlank(entity.getSearchReportEndTime())) { - sdf.parse(entity.getSearchReportEndTime()); - timeCount++; + DateUtils.convertStringToDate(entity.getSearchReportEndTime(), TimeConstants.YYYY_MM_DD_HH24_MM_SS); } - } catch (ParseException e) { - throw new RestServiceException("searchReportEndTime参数格式错误", - RestBusinessCode.param_formate_error.getValue()); } catch (Exception e) { throw new RestServiceException("searchReportEndTime参数错误", RestBusinessCode.param_formate_error.getValue()); } - if (timeCount == 1) { - throw new RestServiceException("searchReportStartTime和searchReportEndTime参数必须同时填写", - RestBusinessCode.config_integrity_error.getValue()); - } + // 根据用户查看IP趋势时(searchBusinessType=2),用户名必需填写 if ("2".equals(entity.getSearchBusinessType()) && StringUtil.isEmpty(entity.getSearchAccount())) { diff --git a/src/main/java/com/nis/web/service/restful/NtcLogService.java b/src/main/java/com/nis/web/service/restful/NtcLogService.java index bcfb3f6..81dcad9 100644 --- a/src/main/java/com/nis/web/service/restful/NtcLogService.java +++ b/src/main/java/com/nis/web/service/restful/NtcLogService.java @@ -30,11 +30,13 @@ public class NtcLogService extends BaseLogService { * @param clazz * @param page */ - public void ntcConnRecordLogsQueryConditionCheck(AuditLogThread thread, long start, NtcConnRecordLog entity, Class clazz, Page page) { + public void ntcConnRecordLogsConditionCheck(AuditLogThread thread, long start, NtcConnRecordLog entity, Class clazz, Page page) { logger.info("ntcConnRecordLogsQueryConditionCheck start----" + System.currentTimeMillis()); + queryConditionCheck(thread, start, entity, clazz, page); + //app protocol website - if (!StringUtil.isBlank(entity.getSearchAppId())) { + if (StringUtil.isNotBlank(entity.getSearchAppId())) { String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchAppId(), ","); if (split.length > 10) { throw new RestServiceException("searchAppId max(10)", @@ -49,7 +51,7 @@ public class NtcLogService extends BaseLogService { } } - if (!StringUtil.isBlank(entity.getSearchProtoId())) { + if (StringUtil.isNotBlank(entity.getSearchProtoId())) { String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchProtoId(), ","); if (split.length > 10) { throw new RestServiceException("searchProtoId max(10)", @@ -64,7 +66,7 @@ public class NtcLogService extends BaseLogService { } } - if (!StringUtil.isBlank(entity.getSearchWebId())) { + if (StringUtil.isNotBlank(entity.getSearchWebId())) { String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchWebId(), ","); if (split.length > 10) { throw new RestServiceException("searchWebId max(10)", @@ -80,25 +82,24 @@ public class NtcLogService extends BaseLogService { } } - try { - if (!StringUtil.isBlank(entity.getSearchDirection())) { - Integer.parseInt(entity.getSearchDirection()); + + if (StringUtil.isNotBlank(entity.getSearchIspCode())) { + String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchIspCode(), ","); + if (split.length > 10) { + throw new RestServiceException("searchIspCode max(10)", + RestBusinessCode.param_formate_error.getValue()); + } + for (String ispCode : split) { + try { + Long.parseLong(ispCode); + } catch (Exception e) { + throw new RestServiceException("searchIspCode 参数错误", RestBusinessCode.param_formate_error.getValue()); + } + } - } catch (NumberFormatException e) { - throw new RestServiceException("getSearchDirection参数格式错误", RestBusinessCode.param_formate_error.getValue()); - } catch (Exception e) { - throw new RestServiceException("getSearchDirection参数错误", RestBusinessCode.param_formate_error.getValue()); } - try { - if (!StringUtil.isBlank(entity.getSearchEntranceId())) { - Long.parseLong(entity.getSearchEntranceId()); - } - } catch (NumberFormatException e) { - throw new RestServiceException("searchEntranceId参数格式错误", RestBusinessCode.param_formate_error.getValue()); - } catch (Exception e) { - throw new RestServiceException("searchEntranceId参数错误", RestBusinessCode.param_formate_error.getValue()); - } + logger.info("ntcConnRecordLogsQueryConditionCheck end----" + System.currentTimeMillis()); }