App统计图增加功能:添加app趋势详情和App通联关系Top100 数据查询接口
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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<String, ?> 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<String, String> 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<String, ?> appConnRecordTop100(AppConnRecordStatistic entity,Model model, HttpServletRequest request,
|
||||
HttpServletResponse response) {
|
||||
|
||||
long start = System.currentTimeMillis();
|
||||
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
|
||||
null);
|
||||
List<AppConnRecordStatistic> list = new ArrayList<AppConnRecordStatistic>();
|
||||
try {
|
||||
//验证
|
||||
checkAppTrendCondition(entity);
|
||||
if (StringUtil.isEmpty(entity.getSearchStartTime())
|
||||
&& StringUtil.isEmpty(entity.getSearchEndTime())) {
|
||||
Map<String, String> 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Map> appChart(@Param("statTime")Date statTime);
|
||||
List<Map> getAppList(@Param("beginTime")String beginTime,@Param("endTime")String endTime,@Param("appType")Integer[] appType);
|
||||
List<TrafficAppFocusStatistic> getAppTrend(TrafficAppFocusStatistic entity);
|
||||
List<AppConnRecordStatistic> appConnRecordTop100(AppConnRecordStatistic entity);
|
||||
}
|
||||
@@ -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
|
||||
</select>
|
||||
<!-- App 趋势详情 -->
|
||||
<select id="getAppTrend" parameterType="com.nis.domain.restful.dashboard.TrafficAppFocusStatistic" resultType="com.nis.domain.restful.dashboard.TrafficAppFocusStatistic">
|
||||
select stat_time time, max(unique_sip_num) sipNum,max(unique_dip_num) dipNum from traffic_app_focus_statistic t where
|
||||
<![CDATA[ stat_time>= toDateTime(#{searchStartTime}) and stat_time< toDateTime(#{searchEndTime})
|
||||
and app_id=toInt64(#{searchAppId}) ]]>
|
||||
<if test="searchEntranceId">
|
||||
<![CDATA[and entrance_id=toInt64(#{searchEntranceId}) ]]>
|
||||
</if>
|
||||
|
||||
group by stat_time
|
||||
order by stat_time
|
||||
</select>
|
||||
<!-- App通联关系Top100 -->
|
||||
<select id="appConnRecordTop100" parameterType="com.nis.domain.restful.dashboard.AppConnRecordStatistic" resultType="com.nis.domain.restful.dashboard.AppConnRecordStatistic">
|
||||
select found_time,s_ip ipAddr, sum(c2s_byte_num + s2c_byte_num) byteNum, sum(c2s_pkt_num + s2c_pkt_num) pktNum, count(found_time) logNum
|
||||
from tbs_ods_ntc_conn_record_log t where
|
||||
<![CDATA[ found_time>= toDateTime(#{searchStartTime}) and found_time< toDateTime(#{searchEndTime})
|
||||
and app_id=toInt64(#{searchAppId}) ]]>
|
||||
<if test="searchEntranceId">
|
||||
<![CDATA[and entrance_id=toInt64(#{searchEntranceId}) ]]>
|
||||
</if>
|
||||
|
||||
group by found_time,s_ip
|
||||
order by logNum limit 100
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -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<TrafficAppFocusStatistic> appFocusList = new ArrayList<TrafficAppFocusStatistic>();
|
||||
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<Date> dateRangeList = new ArrayList<Date>();
|
||||
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, Constants.TREND_TIME_INTERVAL);
|
||||
}
|
||||
// 存放每个时间点的总数
|
||||
Map<String, List<Long>> ipCountListMap = new HashMap<String, List<Long>>();
|
||||
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<AppConnRecordStatistic> appConnRecordTop100(AppConnRecordStatistic entity) {
|
||||
List<AppConnRecordStatistic> list = new ArrayList<AppConnRecordStatistic>();
|
||||
list = trafficAppStatisticDao.appConnRecordTop100(entity);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user