From a8b9ffc2196f80f4dfe752554ca9e4edf3683277 Mon Sep 17 00:00:00 2001 From: renkaige Date: Mon, 7 Jan 2019 10:19:40 +0600 Subject: [PATCH] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/nis/domain/LogEntity.java | 20 +++ .../nis/domain/restful/NtcConnRecordLog.java | 89 ++++++++++ .../dashboard/AppConnRecordStatistic.java | 48 ++++++ .../restful/dashboard/AppTrendEntity.java | 40 +++++ .../dashboard/TrafficAppFocusStatistic.java | 29 ++++ .../restful/DashboardServiceController.java | 163 ++++++++++++++++++ .../restful/NtcLogSearchController.java | 1 + .../java/com/nis/web/dao/DfLogSearchDao.xml | 9 + .../dao/dashboard/TrafficAppStatisticDao.java | 5 +- .../dao/dashboard/TrafficAppStatisticDao.xml | 25 +++ .../web/service/restful/DashboardService.java | 66 +++++++ .../web/service/restful/NtcLogService.java | 89 ++++++++++ 12 files changed, 583 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/nis/domain/restful/dashboard/AppConnRecordStatistic.java create mode 100644 src/main/java/com/nis/domain/restful/dashboard/AppTrendEntity.java create mode 100644 src/main/java/com/nis/domain/restful/dashboard/TrafficAppFocusStatistic.java diff --git a/src/main/java/com/nis/domain/LogEntity.java b/src/main/java/com/nis/domain/LogEntity.java index 64d3860..a2f048e 100644 --- a/src/main/java/com/nis/domain/LogEntity.java +++ b/src/main/java/com/nis/domain/LogEntity.java @@ -109,6 +109,26 @@ public abstract class LogEntity implements Serializable { protected String searchCapIp;//处理机IP protected String searchFoundStartTime;//开始发现时间 protected String searchFoundEndTime;//结束发现时间 + + //add by dxy 2019-01-05 仅限于NtcConnRecordLog需求,考虑以后可能会放开其他日志查询,所以放到公共类 + protected String searchServerLocate;//serverLocate + protected String searchClientLocate;//clientLocate + + public String getSearchServerLocate() { + return searchServerLocate; + } + + public void setSearchServerLocate(String searchServerLocate) { + this.searchServerLocate = searchServerLocate; + } + + public String getSearchClientLocate() { + return searchClientLocate; + } + + public void setSearchClientLocate(String searchClientLocate) { + this.searchClientLocate = searchClientLocate; + } /** * 当前实体分页对象 diff --git a/src/main/java/com/nis/domain/restful/NtcConnRecordLog.java b/src/main/java/com/nis/domain/restful/NtcConnRecordLog.java index 56935a5..551d2f4 100644 --- a/src/main/java/com/nis/domain/restful/NtcConnRecordLog.java +++ b/src/main/java/com/nis/domain/restful/NtcConnRecordLog.java @@ -1,5 +1,6 @@ package com.nis.domain.restful; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.nis.domain.LogEntity; import com.wordnik.swagger.annotations.ApiModelProperty; @@ -28,7 +29,23 @@ public class NtcConnRecordLog extends LogEntity { protected String c2sByteNum; @ApiModelProperty(value = "", required = true) protected String s2cByteNum; + + @ApiModelProperty(value = "", required = true) + protected Long protoId; + @ApiModelProperty(value = "", required = true) + protected Long appId; + @ApiModelProperty(value = "", required = true) + protected Long webId; + protected String searchSAsn;//sAsn + protected String searchDAsn;//dAsn + protected String searchAppId;//app + protected String searchWebId;//web + protected String searchProtoId;//proto + //protected String searchServerLocate;//serverLocate + //protected String searchClientLocate;//clientLocate + + @JsonIgnore public String getAppLabel() { return appLabel; } @@ -69,4 +86,76 @@ public class NtcConnRecordLog extends LogEntity { this.s2cByteNum = s2cByteNum; } + public Long getProtoId() { + return protoId; + } + + public void setProtoId(Long protoId) { + this.protoId = protoId; + } + + public Long getAppId() { + return appId; + } + + public void setAppId(Long appId) { + this.appId = appId; + } + + public Long getWebId() { + return webId; + } + + public void setWebId(Long webId) { + this.webId = webId; + } + + + @JsonIgnore + public String getSearchSAsn() { + return searchSAsn; + } + + public void setSearchSAsn(String searchSAsn) { + this.searchSAsn = searchSAsn; + } + + @JsonIgnore + public String getSearchDAsn() { + return searchDAsn; + } + + public void setSearchDAsn(String searchDAsn) { + this.searchDAsn = searchDAsn; + } + + @JsonIgnore + public String getSearchAppId() { + return searchAppId; + } + + public void setSearchAppId(String searchAppId) { + this.searchAppId = searchAppId; + } + + @JsonIgnore + public String getSearchWebId() { + return searchWebId; + } + + public void setSearchWebId(String searchWebId) { + this.searchWebId = searchWebId; + } + + @JsonIgnore + public String getSearchProtoId() { + return searchProtoId; + } + + public void setSearchProtoId(String searchProtoId) { + this.searchProtoId = searchProtoId; + } + + + } diff --git a/src/main/java/com/nis/domain/restful/dashboard/AppConnRecordStatistic.java b/src/main/java/com/nis/domain/restful/dashboard/AppConnRecordStatistic.java new file mode 100644 index 0000000..270bc4b --- /dev/null +++ b/src/main/java/com/nis/domain/restful/dashboard/AppConnRecordStatistic.java @@ -0,0 +1,48 @@ +package com.nis.domain.restful.dashboard; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class AppConnRecordStatistic extends AppTrendEntity{ + + protected String ipAddr; + protected String pktNum; + protected String byteNum; + protected String logNum; //日志数量 + + public AppConnRecordStatistic() { + super(); + // TODO Auto-generated constructor stub + } + public AppConnRecordStatistic(String ipAddr, String pktNum, String byteNum, + String logNum) { + super(); + this.ipAddr = ipAddr; + this.pktNum = pktNum; + this.byteNum = byteNum; + this.logNum = logNum; + } + public String getIpAddr() { + return ipAddr; + } + public void setIpAddr(String ipAddr) { + this.ipAddr = ipAddr; + } + public String getPktNum() { + return pktNum; + } + public void setPktNum(String pktNum) { + this.pktNum = pktNum; + } + public String getByteNum() { + return byteNum; + } + public void setByteNum(String byteNum) { + this.byteNum = byteNum; + } + public String getLogNum() { + return logNum; + } + public void setLogNum(String logNum) { + this.logNum = logNum; + } +} diff --git a/src/main/java/com/nis/domain/restful/dashboard/AppTrendEntity.java b/src/main/java/com/nis/domain/restful/dashboard/AppTrendEntity.java new file mode 100644 index 0000000..8c3518b --- /dev/null +++ b/src/main/java/com/nis/domain/restful/dashboard/AppTrendEntity.java @@ -0,0 +1,40 @@ +package com.nis.domain.restful.dashboard; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public class AppTrendEntity{ + + private String searchAppId; + private String searchStartTime; + private String searchEndTime; + private String searchEntranceId; + + @JsonIgnore + public String getSearchAppId() { + return searchAppId; + } + public void setSearchAppId(String searchAppId) { + this.searchAppId = searchAppId; + } + @JsonIgnore + public String getSearchStartTime() { + return searchStartTime; + } + public void setSearchStartTime(String searchStartTime) { + this.searchStartTime = searchStartTime; + } + @JsonIgnore + public String getSearchEndTime() { + return searchEndTime; + } + public void setSearchEndTime(String searchEndTime) { + this.searchEndTime = searchEndTime; + } + @JsonIgnore + public String getSearchEntranceId() { + return searchEntranceId; + } + public void setSearchEntranceId(String searchEntranceId) { + this.searchEntranceId = searchEntranceId; + } +} diff --git a/src/main/java/com/nis/domain/restful/dashboard/TrafficAppFocusStatistic.java b/src/main/java/com/nis/domain/restful/dashboard/TrafficAppFocusStatistic.java new file mode 100644 index 0000000..b388952 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/dashboard/TrafficAppFocusStatistic.java @@ -0,0 +1,29 @@ +package com.nis.domain.restful.dashboard; + +import java.util.Date; + +public class TrafficAppFocusStatistic extends AppTrendEntity{ + + private Date time; + private Long sipNum; + private Long dipNum; + + public Date getTime() { + return time; + } + public void setTime(Date time) { + this.time = time; + } + public Long getSipNum() { + return sipNum; + } + public void setSipNum(Long sipNum) { + this.sipNum = sipNum; + } + public Long getDipNum() { + return dipNum; + } + public void setDipNum(Long dipNum) { + this.dipNum = dipNum; + } +} diff --git a/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java b/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java index 8bd2d84..fe3a4db 100644 --- a/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java +++ b/src/main/java/com/nis/web/controller/restful/DashboardServiceController.java @@ -1,5 +1,6 @@ package com.nis.web.controller.restful; +import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -19,7 +20,12 @@ 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.restful.NtcConnNumReport; +import com.nis.domain.restful.NtcRadiusReport; +import com.nis.domain.restful.dashboard.AppConnRecordStatistic; +import com.nis.domain.restful.dashboard.AppTrendEntity; +import com.nis.domain.restful.dashboard.TrafficAppFocusStatistic; import com.nis.restful.RestBusinessCode; import com.nis.restful.RestServiceException; import com.nis.restful.ServiceRuntimeException; @@ -985,4 +991,161 @@ public class DashboardServiceController extends BaseRestController { return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "流量各指标趋势统计成功", restMap, 0); } + /** + * @Description: + * @author(zdx) + * @date 2019年1月4日 下午8:57:32 + * @param model + * @param entity + * @param request + * @param response + * @return + */ + @RequestMapping(value = "trafficAppTrend", method = RequestMethod.GET) + @ApiOperation(value = "App趋势详情查询", httpMethod = "GET", notes = "对App趋势详情提供数据查询服务") + public Map trafficAppTrend(TrafficAppFocusStatistic entity, Model model, + HttpServletRequest request, HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); + Map resultMap = new HashMap(); + try { + //验证 + checkAppTrendCondition(entity); + if (StringUtil.isEmpty(entity.getSearchStartTime()) + && StringUtil.isEmpty(entity.getSearchEndTime())) { + Map map = DateUtils.getLocalTime(null, null, Constants.LOG_LOCAL_TIME, "hour"); + entity.setSearchStartTime(map.get("startTime")); + entity.setSearchEndTime(map.get("endTime")); + } + //将数据源切换到本地clickhouse + CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B); + resultMap = dashboardService.getAppTrend(entity); + CustomerContextHolder.clearCustomerType(); + } catch (Exception e) { + auditLogThread.setExceptionInfo("App趋势详情数据检索失败:" + e.getMessage()); + logger.error("App趋势详情数据检索失败:" + ExceptionUtil.getExceptionMsg(e)); + if (e instanceof RestServiceException) { + throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start, + "App趋势详情数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); + } else if (e instanceof ServiceRuntimeException) { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "App趋势详情数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); + } else { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "App趋势详情数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + } + } + + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App趋势详情数据检索成功", + resultMap, 0); + } + + /** + * @Description: + * @author(zdx) + * @date 2019年1月4日 下午8:57:12 + * @param beginDate + * @param endDate + * @param model + * @param request + * @param response + * @return + */ + @RequestMapping(value = "appConnRecordTop100", method = RequestMethod.GET) + @ApiOperation(value = "App通联关系Top100", httpMethod = "GET", notes = "对App通联关系Top100提供查询服务。") + public Map appConnRecordTop100(AppConnRecordStatistic entity,Model model, HttpServletRequest request, + HttpServletResponse response) { + + long start = System.currentTimeMillis(); + AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, + null); + List list = new ArrayList(); + try { + //验证 + checkAppTrendCondition(entity); + if (StringUtil.isEmpty(entity.getSearchStartTime()) + && StringUtil.isEmpty(entity.getSearchEndTime())) { + Map map = DateUtils.getLocalTime(null, null, Constants.LOG_LOCAL_TIME, "hour"); + entity.setSearchStartTime(map.get("startTime")); + entity.setSearchEndTime(map.get("endTime")); + } + CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B); + list = dashboardService.appConnRecordTop100(entity); + CustomerContextHolder.clearCustomerType(); + } catch (Exception e) { + auditLogThread.setExceptionInfo("App通联关系Top100数据检索失败:" + e.getMessage()); + logger.error("App通联关系Top100检索失败:" + ExceptionUtil.getExceptionMsg(e)); + if (e instanceof RestServiceException) { + throw new RestServiceException(auditLogThread, System.currentTimeMillis() - start, + "App通联关系Top100数据检索失败:" + e.getMessage(), ((RestServiceException) e).getErrorCode()); + } else if (e instanceof ServiceRuntimeException) { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "App通联关系Top100数据检索失败:" + e.getMessage(), ((ServiceRuntimeException) e).getErrorCode()); + } else { + throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start, + "App通联关系Top100数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue()); + } + } + return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "App通联关系Top100数据检索成功", list, + 0); + } + /** + */ + public void checkAppTrendCondition(AppTrendEntity entity) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + int timeCount = 0; + try { + if (!StringUtil.isBlank(entity.getSearchStartTime())) { + sdf.parse(entity.getSearchStartTime()); + timeCount++; + } + } catch (ParseException e) { + throw new RestServiceException("searchStartTime参数格式错误", + RestBusinessCode.param_formate_error.getValue()); + } catch (Exception e) { + throw new RestServiceException("searchStartTime参数错误", + RestBusinessCode.param_formate_error.getValue()); + } + + try { + if (!StringUtil.isBlank(entity.getSearchEndTime())) { + sdf.parse(entity.getSearchEndTime()); + timeCount++; + } + } catch (ParseException e) { + throw new RestServiceException("searchEndTime参数格式错误", + RestBusinessCode.param_formate_error.getValue()); + } catch (Exception e) { + throw new RestServiceException("searchEndTime参数错误", RestBusinessCode.param_formate_error.getValue()); + } + if (timeCount == 1) { + throw new RestServiceException("searchStartTime和searchEndTime参数必须同时填写", + RestBusinessCode.config_integrity_error.getValue()); + } + //验证AppId和EntranceId必须是数值 + checkNumericCondition(entity.getSearchAppId(),"searchAppId"); + checkNumericCondition(entity.getSearchEntranceId(),"searchEntranceId"); + logger.info("用户行为日志统计参数校验结束----" + System.currentTimeMillis()); + + } + public void checkNumericCondition(String condition, String condName) { + if (!StringUtil.isEmpty(condition)) { + Boolean flag = false; + if (condition.contains(",")) { + String services[] = condition.split(","); + for (String service : services) { + if (!StringUtil.isNumeric(service)) { + flag = true; + break; + } + } + } else if (!StringUtil.isNumeric(condition)) { + flag = true; + } + if (flag) { + throw new RestServiceException(condName + "参数格式错误", RestBusinessCode.param_formate_error.getValue()); + } + } + } } 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 5a8a2dc..f2dbc2c 100644 --- a/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java +++ b/src/main/java/com/nis/web/controller/restful/NtcLogSearchController.java @@ -696,6 +696,7 @@ public class NtcLogSearchController extends BaseRestController { ntcConnRecordLog.setSearchFoundEndTime(map.get("endTime")); } ntcLogService.queryConditionCheck(auditLogThread, start, ntcConnRecordLog, NtcConnRecordLog.class, page); + ntcLogService.ntcConnRecordLogsQueryConditionCheck(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/dao/DfLogSearchDao.xml b/src/main/java/com/nis/web/dao/DfLogSearchDao.xml index 2f4314e..2782054 100644 --- a/src/main/java/com/nis/web/dao/DfLogSearchDao.xml +++ b/src/main/java/com/nis/web/dao/DfLogSearchDao.xml @@ -1523,6 +1523,15 @@ + + + + + \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java index 9d06ec2..119b073 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.java @@ -5,7 +5,8 @@ import java.util.List; import java.util.Map; import org.apache.ibatis.annotations.Param; - +import com.nis.domain.restful.dashboard.AppConnRecordStatistic; +import com.nis.domain.restful.dashboard.TrafficAppFocusStatistic; import com.nis.domain.restful.dashboard.TrafficAppStatistic; import com.nis.web.dao.MyBatisDao; @MyBatisDao @@ -14,4 +15,6 @@ public interface TrafficAppStatisticDao { TrafficAppStatistic getMaxStatTime(); List appChart(@Param("statTime")Date statTime); List getAppList(@Param("beginTime")String beginTime,@Param("endTime")String endTime,@Param("appType")Integer[] appType); + List getAppTrend(TrafficAppFocusStatistic entity); + List appConnRecordTop100(AppConnRecordStatistic entity); } \ No newline at end of file diff --git a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml index d0f8ada..61c04b0 100644 --- a/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml +++ b/src/main/java/com/nis/web/dao/dashboard/TrafficAppStatisticDao.xml @@ -42,4 +42,29 @@ GROUP BY app_type ) p LEFT JOIN ui_code_app_dic c ON p.app_type=c.view_code ORDER BY p.GByte DESC + + + + \ No newline at end of file diff --git a/src/main/java/com/nis/web/service/restful/DashboardService.java b/src/main/java/com/nis/web/service/restful/DashboardService.java index 05d32d5..465c4f2 100644 --- a/src/main/java/com/nis/web/service/restful/DashboardService.java +++ b/src/main/java/com/nis/web/service/restful/DashboardService.java @@ -22,7 +22,9 @@ import org.springframework.stereotype.Service; import com.beust.jcommander.internal.Maps; import com.nis.domain.restful.NtcConnNumReport; import com.nis.domain.restful.NtcEntranceReport; +import com.nis.domain.restful.dashboard.AppConnRecordStatistic; import com.nis.domain.restful.dashboard.NtcTotalReport; +import com.nis.domain.restful.dashboard.TrafficAppFocusStatistic; import com.nis.domain.restful.dashboard.TrafficAppStatistic; import com.nis.domain.restful.dashboard.TrafficHttpFocusStatistic; import com.nis.domain.restful.dashboard.TrafficIpActiveStatistic; @@ -1633,4 +1635,68 @@ public class DashboardService extends BaseService { } return restMap; } + + public Map getAppTrend(TrafficAppFocusStatistic entity) { + List appFocusList = new ArrayList(); + appFocusList = trafficAppStatisticDao.getAppTrend(entity); + Map resultMap = new HashMap(); + if(!StringUtil.isEmpty(appFocusList)){ + Date beginDate = DateUtils.parseDate(entity.getSearchStartTime()); + Date endDate = DateUtils.parseDate(entity.getSearchEndTime()); + List dateRangeList = new ArrayList(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(beginDate); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + while (calendar.getTime().compareTo(endDate) < 0) { + dateRangeList.add(calendar.getTime()); + calendar.add(Calendar.MINUTE, 1); + } + // 存放每个时间点的总数 + Map> ipCountListMap = new HashMap>(); + int index = 0; + List resultSipList = new ArrayList(); + List resultDipList = new ArrayList(); + Long sipTotal = 0L; + Long dipTotal = 0L; + for (int i = 0; i < dateRangeList.size(); i++) { + // 存放一个时间点中总数 + List sipList = new ArrayList(); + List dipList = new ArrayList(); + Date date = dateRangeList.get(i); + Long sipNum = 0L; + Long dipNum = 0L; + for (int j = index; j < appFocusList.size(); j++) { + TrafficAppFocusStatistic info = appFocusList.get(j); + if (info.getTime() != null) { + if (info.getTime().compareTo(date) >= 0 && (i + 1 < dateRangeList.size()?info.getTime().compareTo(dateRangeList.get(i + 1)) < 0:true)) { + sipNum = sipNum + info.getSipNum(); + dipNum = dipNum + info.getDipNum(); + } else { + index = j; + break; + } + } + } + sipList.add(date.getTime()); + sipList.add(sipNum); + resultSipList.add(sipList); + dipList.add(date.getTime()); + dipList.add(dipNum); + resultDipList.add(dipList); + sipTotal+=sipNum; + dipTotal+=dipNum; + } + resultMap.put("sipResult", resultSipList); + resultMap.put("dipResult", resultDipList); + resultMap.put("sipSum", sipTotal); + resultMap.put("dipSum", dipTotal); + } + return resultMap; + } + + public List appConnRecordTop100(AppConnRecordStatistic entity) { + List list = new ArrayList(); + list = trafficAppStatisticDao.appConnRecordTop100(entity); + return list; + } } 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 898e9f1..bcfb3f6 100644 --- a/src/main/java/com/nis/web/service/restful/NtcLogService.java +++ b/src/main/java/com/nis/web/service/restful/NtcLogService.java @@ -1,8 +1,16 @@ package com.nis.web.service.restful; + + import org.springframework.stereotype.Service; +import com.nis.domain.Page; +import com.nis.domain.restful.NtcConnRecordLog; +import com.nis.restful.RestBusinessCode; +import com.nis.restful.RestServiceException; +import com.nis.web.service.AuditLogThread; import com.nis.web.service.BaseLogService; +import com.zdjizhi.utils.StringUtil; /** * @Description:TODO(这里用一句话描述这个类的作用) @@ -13,4 +21,85 @@ import com.nis.web.service.BaseLogService; @Service public class NtcLogService extends BaseLogService { + /** + * 验证日志查询条件格式是否正确 + * + * @param thread + * @param start + * @param entity + * @param clazz + * @param page + */ + public void ntcConnRecordLogsQueryConditionCheck(AuditLogThread thread, long start, NtcConnRecordLog entity, Class clazz, Page page) { + logger.info("ntcConnRecordLogsQueryConditionCheck start----" + System.currentTimeMillis()); + + //app protocol website + if (!StringUtil.isBlank(entity.getSearchAppId())) { + String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchAppId(), ","); + if (split.length > 10) { + throw new RestServiceException("searchAppId max(10)", + RestBusinessCode.param_formate_error.getValue()); + } + for (String appId : split) { + try { + Long.parseLong(appId); + } catch (Exception e) { + throw new RestServiceException("searchAppId error", RestBusinessCode.param_formate_error.getValue()); + } + + } + } + if (!StringUtil.isBlank(entity.getSearchProtoId())) { + String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchProtoId(), ","); + if (split.length > 10) { + throw new RestServiceException("searchProtoId max(10)", + RestBusinessCode.param_formate_error.getValue()); + } + for (String protoId : split) { + try { + Long.parseLong(protoId); + } catch (Exception e) { + throw new RestServiceException("searchAppId error", RestBusinessCode.param_formate_error.getValue()); + } + + } + } + if (!StringUtil.isBlank(entity.getSearchWebId())) { + String[] split = org.apache.commons.lang.StringUtils.split(entity.getSearchWebId(), ","); + if (split.length > 10) { + throw new RestServiceException("searchWebId max(10)", + RestBusinessCode.param_formate_error.getValue()); + } + for (String appId : split) { + try { + Long.parseLong(appId); + } catch (Exception e) { + throw new RestServiceException("searchWebId 参数错误", RestBusinessCode.param_formate_error.getValue()); + } + + } + } + + try { + if (!StringUtil.isBlank(entity.getSearchDirection())) { + Integer.parseInt(entity.getSearchDirection()); + } + } 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()); + + } }