新增 用户行为统计查询服务 接口

This commit is contained in:
zhangdongxu
2018-10-31 19:33:04 +08:00
parent adaa53ebd1
commit 5e66868e13
6 changed files with 415 additions and 11 deletions

View File

@@ -0,0 +1,136 @@
package com.nis.domain.restful;
import java.io.Serializable;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.wordnik.swagger.annotations.ApiModelProperty;
public class NtcRadiusReport implements Serializable{
private static final long serialVersionUID = 7635016645942704971L;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "接入IP", required = true)
protected String nasIp;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "用户名", required = true)
protected String account;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "次数", required = true)
protected Long num;
@JsonInclude(value = Include.NON_NULL)
@ApiModelProperty(value = "统计时间", required = true)
protected String reportTime;
/**
* 业务类型1:用户名和接口IP列表 2:根据用户统计IP变化趋势 3IP根据统计用户变化趋势
*/
protected String searchBusinessType = "1";
protected String searchReportStartTime;
protected String searchReportEndTime;
protected Long searchReportStartTimeCluster;
protected Long searchReportEndTimeCluster;
protected String searchNasIp;
protected String searchAccount;
protected String groupType;
public String getNasIp() {
return nasIp;
}
public void setNasIp(String nasIp) {
this.nasIp = nasIp;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public Long getNum() {
return num;
}
public void setNum(Long num) {
this.num = num;
}
public String getReportTime() {
return reportTime;
}
public void setReportTime(String reportTime) {
this.reportTime = reportTime;
}
public String getSearchBusinessType() {
return searchBusinessType;
}
@JsonIgnore
public void setSearchBusinessType(String searchBusinessType) {
this.searchBusinessType = searchBusinessType;
}
@JsonIgnore
public String getSearchReportStartTime() {
return searchReportStartTime;
}
public void setSearchReportStartTime(String searchReportStartTime) {
this.searchReportStartTime = searchReportStartTime;
}
@JsonIgnore
public String getSearchReportEndTime() {
return searchReportEndTime;
}
public void setSearchReportEndTime(String searchReportEndTime) {
this.searchReportEndTime = searchReportEndTime;
}
@JsonIgnore
public Long getSearchReportStartTimeCluster() {
return searchReportStartTimeCluster;
}
public void setSearchReportStartTimeCluster(
Long searchReportStartTimeCluster) {
this.searchReportStartTimeCluster = searchReportStartTimeCluster;
}
@JsonIgnore
public Long getSearchReportEndTimeCluster() {
return searchReportEndTimeCluster;
}
public void setSearchReportEndTimeCluster(Long searchReportEndTimeCluster) {
this.searchReportEndTimeCluster = searchReportEndTimeCluster;
}
@JsonIgnore
public String getSearchNasIp() {
return searchNasIp;
}
public void setSearchNasIp(String searchNasIp) {
this.searchNasIp = searchNasIp;
}
@JsonIgnore
public String getSearchAccount() {
return searchAccount;
}
public void setSearchAccount(String searchAccount) {
this.searchAccount = searchAccount;
}
@JsonIgnore
public String getGroupType() {
return groupType;
}
public void setGroupType(String groupType) {
this.groupType = groupType;
}
}

View File

@@ -1,12 +1,11 @@
package com.nis.web.controller.restful;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zdjizhi.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -19,6 +18,7 @@ import com.nis.domain.restful.NtcDestipCountryReport;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcLwhhReport;
import com.nis.domain.restful.NtcPzReport;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.NtcReportEntity;
import com.nis.domain.restful.NtcServiceReport;
import com.nis.domain.restful.NtcSrcipDomesticReport;
@@ -32,6 +32,8 @@ import com.nis.web.service.ServicesRequestLogService;
import com.nis.web.service.restful.NtcReportService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.zdjizhi.utils.DateUtil;
import com.zdjizhi.utils.StringUtil;
/**
*
@@ -355,6 +357,33 @@ public class SingleDimensionReport extends BaseRestController {
0);
}
@RequestMapping(value = "/ntcRadiusReport", method = RequestMethod.GET)
@ApiOperation(value = "用户行为统计查询服务", httpMethod = "GET", notes = "用户行为统计查询服务基于用户名或接入IP维度聚合")
public Map<String, ?> ntcRadiusReport(NtcRadiusReport ntcRadiusReport, Model model,
HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread saveLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
List dataList = null;
try {
ntcReportService.checkNtcRadiusReportCondition(saveLogThread, start, ntcRadiusReport);
setGroupType(ntcRadiusReport);
dataList= ntcReportService.findNtcRadiusReport(ntcRadiusReport);
} catch (Exception e) {
saveLogThread.setExceptionInfo(e.getMessage() + " " + e.getCause());
e.printStackTrace();
logger.error(e.getMessage());
if (!(e instanceof RestServiceException)) {
e = new RestServiceException(saveLogThread, System.currentTimeMillis() - start, "用户行为统计查询失败");
}
throw ((RestServiceException) e);
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "用户行为统计查询成功", dataList,
0);
}
/**
* @Description:
* @author (zdx)
@@ -393,5 +422,25 @@ public class SingleDimensionReport extends BaseRestController {
}
}
/**
* @Description:
* @author(zdx)
* @date 2018年10月31日 下午2:43:13
* @param ntcRadiusReport
* @throws Exception
*/
public void setGroupType(NtcRadiusReport ntcRadiusReport) throws Exception {
String groupType ="";
Long times = DateUtil.convertStringToTimestamp(ntcRadiusReport.getSearchReportEndTime(), DateUtil.YYYY_MM_DD_HH24_MM_SS)-DateUtil.convertStringToTimestamp(ntcRadiusReport.getSearchReportStartTime(), DateUtil.YYYY_MM_DD_HH24_MM_SS);
if (times<=24*60*60L) {
groupType ="hour";
}else{
if (times<=30*24*60*60L) {
groupType ="day";
}else {
groupType ="month";
}
}
ntcRadiusReport.setGroupType(groupType);
}
}

View File

@@ -7,6 +7,7 @@ import com.nis.domain.restful.NtcDestipCountryReport;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcLwhhReport;
import com.nis.domain.restful.NtcPzReport;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.NtcServiceReport;
import com.nis.domain.restful.NtcSrcipDomesticReport;
import com.nis.domain.restful.NtcTagReport;
@@ -29,4 +30,7 @@ public interface NtcReportDao extends CrudDao {
List<NtcSrcipDomesticReport> findNtcSrcipDomesticReport(NtcSrcipDomesticReport pz);
List<NtcDestipCountryReport> findNtcDestipCountryReport(NtcDestipCountryReport pz);
List<NtcEntranceReport> findNtcEntranceReport(NtcEntranceReport pz);
List<NtcRadiusReport> findAccounList(NtcRadiusReport pz);
List<NtcRadiusReport> findNasIpList(NtcRadiusReport pz);
List<NtcRadiusReport> findNtcRadiusReport(NtcRadiusReport pz);
}

View File

@@ -50,6 +50,13 @@
<result column="SUM" jdbcType="BIGINT" property="sum" />
<result column="REPORT_TIME" jdbcType="TIMESTAMP" property="reportTime" />
</resultMap>
<resultMap id="NtcRadiusReportMap" type="com.nis.domain.restful.NtcRadiusReport">
<result column="ACCOUNT" jdbcType="VARCHAR" property="account" />
<result column="NAS_IP" jdbcType="VARCHAR" property="nasIp" />
<result column="SUM" jdbcType="BIGINT" property="sum" />
<result column="REPORT_TIME" jdbcType="TIMESTAMP" property="reportTime" />
</resultMap>
<sql id="commonPorperty">
SERVICE,SUM,REPORT_TIME
</sql>
@@ -601,4 +608,113 @@
</when>
</choose>
</select>
<select id="findNasIpList" parameterType="com.nis.domain.restful.NtcRadiusReport"
resultMap="NtcRadiusReportMap">
select nas_ip,sum(num) num from ntc_radius_report
<where>
<choose>
<when test="searchReportStartTime != null and searchReportStartTime !=''">
<![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s') AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
</when>
<otherwise>
and REPORT_TIME>=DATE_SUB(now(), INTERVAL 1 DAY)
</otherwise>
</choose>
</where>
group by NAS_IP order by num desc;
</select>
<select id="findAccounList" parameterType="com.nis.domain.restful.NtcRadiusReport"
resultMap="NtcRadiusReportMap">
select account,sum(num) num from ntc_radius_report
<where>
<choose>
<when test="searchReportStartTime != null and searchReportStartTime !=''">
<![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s') AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
</when>
<otherwise>
and REPORT_TIME>DATE_SUB(now(), INTERVAL 1 DAY)
</otherwise>
</choose>
</where>
group by account order by num desc;
</select>
<select id="findNtcRadiusReport" parameterType="com.nis.domain.restful.NtcRadiusReport"
resultMap="NtcRadiusReportMap">
SELECT
<if test="searchAccount != null and searchAccount !=''">
nas_ip,
</if>
<if test="searchNasIp != null and searchNasIp !=''">
account,
</if>
<choose>
<when test="groupType!= null and groupType!='' and groupType == 'day'">
DATE_FORMAT(REPORT_TIME, '%Y-%m-%d')
</when>
<when test="groupType!= null and groupType!='' and groupType == 'month'">
DATE_FORMAT(REPORT_TIME, '%Y-%m')
</when>
<otherwise>
DATE_FORMAT(REPORT_TIME, '%Y-%m-%d %H')
</otherwise>
</choose>
REPORT_TIME,sum(num) num
FROM ntc_radius_report
<where>
<if test="searchAccount != null and searchAccount !=''">
<![CDATA[AND account =#{searchAccount}]]>
</if>
<if test="searchNasIp != null and searchNasIp !=''">
<![CDATA[AND nas_ip =#{searchNasIp}]]>
</if>
<choose>
<when test="searchReportStartTime != null and searchReportStartTime !=''">
<![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s') AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
</when>
<otherwise>
<![CDATA[AND REPORT_TIME>DATE_SUB(now(), INTERVAL 1 DAY) ]]>
</otherwise>
</choose>
</where>
GROUP BY
<if test="searchAccount != null and searchAccount !=''">
<![CDATA[nas_ip]]>
</if>
<if test="searchNasIp != null and searchNasIp !=''">
<![CDATA[account]]>
</if>
,
<choose>
<when test="groupType!= null and groupType!='' and groupType == 'day'">
DATE_FORMAT(REPORT_TIME, '%Y-%m-%d')
</when>
<when test="groupType!= null and groupType!='' and groupType == 'month'">
DATE_FORMAT(REPORT_TIME, '%Y-%m')
</when>
<otherwise>
DATE_FORMAT(REPORT_TIME, '%Y-%m-%d %H')
</otherwise>
</choose>
ORDER BY
<choose>
<when test="groupType!= null and groupType!='' and groupType == 'day'">
DATE_FORMAT(REPORT_TIME, '%Y-%m-%d')
</when>
<when test="groupType!= null and groupType!='' and groupType == 'month'">
DATE_FORMAT(REPORT_TIME, '%Y-%m')
</when>
<otherwise>
DATE_FORMAT(REPORT_TIME, '%Y-%m-%d %H')
</otherwise>
</choose>
ASC
</select>
</mapper>

View File

@@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import com.nis.domain.LogEntity;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.NtcReportEntity;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
@@ -294,14 +295,6 @@ public abstract class BaseLogService {
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportEndTime参数错误");
}
if (!StringUtil.isBlank(entity.getSearchBusinessType())&&!StringUtil.isNumeric(entity.getSearchBusinessType())) {
logger.error(RestBusinessCode.param_formate_error.getErrorReason()+",searchBusinessType参数格式错误");
thread.setExceptionInfo("searchBusinessType参数格式错误");
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
"searchBusinessType参数格式错误",
RestBusinessCode.param_formate_error.getValue());
}
logger.info("实时报表统计查询参数校验结束----" + System.currentTimeMillis());
@@ -339,6 +332,90 @@ public abstract class BaseLogService {
}
}
}
/**
* @Description:验证用户行为日志统计查询条件
* @author(zdx)
* @date 2018年10月31日 下午4:53:27
* @param thread
* @param start
* @param entity
*/
public void checkNtcRadiusReportCondition(AuditLogThread thread, long start, NtcRadiusReport entity) {
logger.info("用户行为日志统计参数校验开始----" + System.currentTimeMillis());
if (!StringUtil.isBlank(entity.getSearchBusinessType())&&!StringUtil.isNumeric(entity.getSearchBusinessType())) {
logger.error(RestBusinessCode.param_formate_error.getErrorReason()+",searchBusinessType参数格式错误");
thread.setExceptionInfo("searchBusinessType参数格式错误");
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
"searchBusinessType参数格式错误",
RestBusinessCode.param_formate_error.getValue());
}
int timeCount = 0;
try {
if (!StringUtil.isBlank(entity.getSearchReportStartTime())) {
sdf.parse(entity.getSearchReportStartTime());
timeCount++;
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportStartTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportStartTime参数错误");
}
try {
if (!StringUtil.isBlank(entity.getSearchReportEndTime())) {
sdf.parse(entity.getSearchReportEndTime());
timeCount++;
}
} catch (ParseException e) {
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportEndTime参数格式错误",
RestBusinessCode.param_formate_error.getValue());
} catch (Exception e) {
thread.setExceptionInfo(e.getMessage() + " " + e.getCause());
logger.error(e);
throw new RestServiceException(thread, System.currentTimeMillis() - start, "searchReportEndTime参数错误");
}
if (timeCount!=2) {
logger.error(RestBusinessCode.config_integrity_error.getErrorReason()+",searchReportStartTime和searchReportEndTime参数必须同时填写");
thread.setExceptionInfo("searchReportStartTime和searchReportEndTime参数必须同时填写");
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
"searchReportStartTime和searchReportEndTime参数必须同时填写",
RestBusinessCode.config_integrity_error.getValue());
}
//根据用户查看IP趋势时(searchBusinessType=2),用户名必需填写
if ("2".equals(entity.getSearchBusinessType())&&StringUtil.isEmpty(entity.getSearchAccount())) {
logger.error(RestBusinessCode.config_integrity_error.getErrorReason()+",searchBusinessType=2时searchAccount参数必须填写");
thread.setExceptionInfo("searchBusinessType=2时searchAccount参数必须填写");
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
"searchBusinessType=2时searchAccount参数必须填写",
RestBusinessCode.config_integrity_error.getValue());
}
//根据用户查看IP趋势时(searchBusinessType=3),用户名必需填写
if ("3".equals(entity.getSearchBusinessType())&&StringUtil.isEmpty(entity.getSearchNasIp())) {
logger.error(RestBusinessCode.config_integrity_error.getErrorReason()+",searchBusinessType=3时searchNasIp参数必须填写");
thread.setExceptionInfo("searchBusinessType=3时searchNasIp参数必须填写");
throw new RestServiceException(thread,
System.currentTimeMillis() - start,
"searchBusinessType=3时searchNasIp参数必须填写",
RestBusinessCode.config_integrity_error.getValue());
}
logger.info("用户行为日志统计参数校验结束----" + System.currentTimeMillis());
}
/**
*

View File

@@ -14,6 +14,7 @@ import com.nis.domain.restful.NtcDestipCountryReport;
import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcLwhhReport;
import com.nis.domain.restful.NtcPzReport;
import com.nis.domain.restful.NtcRadiusReport;
import com.nis.domain.restful.NtcServiceReport;
import com.nis.domain.restful.NtcSrcipDomesticReport;
import com.nis.domain.restful.NtcTagReport;
@@ -102,4 +103,25 @@ public class NtcReportService extends BaseLogService {
page.setList(dao.findNtcEntranceReport(entity));
return page;
}
public List findNtcRadiusReport(NtcRadiusReport entity) throws Exception {
List resultList = null;
if ("1".equals(entity.getSearchBusinessType())) {
resultList = new ArrayList<Map>();
Map<String, List<NtcRadiusReport>> restMap = new HashMap<String, List<NtcRadiusReport>>();
List<NtcRadiusReport> accountList =dao.findAccounList(entity);
restMap.put("accountList", accountList);
List<NtcRadiusReport> nasIpList =dao.findNasIpList(entity);
restMap.put("nasIpList", nasIpList);
resultList.add(restMap);
}else{
resultList = dao.findNtcRadiusReport(entity);
}
return resultList;
}
}