diff options
| author | renkaige <[email protected]> | 2019-05-07 10:05:19 +0800 |
|---|---|---|
| committer | renkaige <[email protected]> | 2019-05-07 10:05:19 +0800 |
| commit | b3f70174f1e9a58ddb31662a35c7deff5a3a8879 (patch) | |
| tree | f515adeeb2b664fedb1fa243a4655db7ae67f59f | |
| parent | aab229a5ff98c87f61f486a30064c7b307504f29 (diff) | |
1:添加配置修改功能
2:修改流量带宽统计功能从clickhouse中查询并添加分钟,小时,天,月,年的功能
14 files changed, 884 insertions, 1218 deletions
@@ -583,20 +583,22 @@ <artifactId>clickhouse-jdbc</artifactId>
<version>0.1.40</version>
</dependency>
-
-
<!--注意使用该包时,必须使用jdk1.8以上的版本,否则会报 Unsupported major.minor version 52.0错误,如出现该错误,请将项目的编译环境或tomcat的运行依赖的jdk调整为1.8以上 -->
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>3.0.12</version>
</dependency>
-
<dependency>
<groupId>com.zdjizhi</groupId>
<artifactId>galaxy</artifactId>
<version>1.0</version>
</dependency>
+ <dependency>
+ <groupId>javax.validation</groupId>
+ <artifactId>validation-api</artifactId>
+ <version>2.0.1.Final</version>
+ </dependency>
</dependencies>
diff --git a/src/main/java/com/nis/domain/restful/dashboard/TrafficEntity.java b/src/main/java/com/nis/domain/restful/dashboard/TrafficEntity.java new file mode 100644 index 0000000..fd31ce1 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/dashboard/TrafficEntity.java @@ -0,0 +1,43 @@ +package com.nis.domain.restful.dashboard;
+
+import java.io.Serializable;
+
+import javax.validation.constraints.NotNull;
+
+public abstract class TrafficEntity<T> implements Serializable {
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ @NotNull(message = "beginDate is not null")
+ protected String beginDate;// 开始时间
+ @NotNull(message = "endDate is not null")
+ protected String endDate;// 结束时间
+ @NotNull(message = "searchBusinessType is not null")
+ protected Integer searchBusinessType = 1;// 1:五分钟,2:小时,3:天,4:月,5:年
+
+ public String getBeginDate() {
+ return beginDate;
+ }
+
+ public void setBeginDate(String beginDate) {
+ this.beginDate = beginDate;
+ }
+
+ public String getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(String endDate) {
+ this.endDate = endDate;
+ }
+
+ public Integer getSearchBusinessType() {
+ return searchBusinessType;
+ }
+
+ public void setSearchBusinessType(Integer searchBusinessType) {
+ this.searchBusinessType = searchBusinessType;
+ }
+
+}
diff --git a/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatisticCK.java b/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatisticCK.java new file mode 100644 index 0000000..3ef1110 --- /dev/null +++ b/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatisticCK.java @@ -0,0 +1,82 @@ +package com.nis.domain.restful.dashboard;
+
+import java.util.Date;
+/**
+ * 从clickhouse中查询流量统计相关结果映射的bean
+ * @author RenKaiGe
+ *
+ */
+public class TrafficTransStatisticCK extends TrafficEntity<TrafficTransStatisticCK> {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ private Integer addrType;
+ private Integer transType;
+ private Integer entranceId;
+ private Date statTime;
+ private Double num;
+
+ private Integer searchDirection;//方向
+ private Integer searchQuotaType;//1:bps,2:pps,3:linknum
+
+ public Integer getAddrType() {
+ return addrType;
+ }
+
+ public void setAddrType(Integer addrType) {
+ this.addrType = addrType;
+ }
+
+ public Integer getTransType() {
+ return transType;
+ }
+
+ public void setTransType(Integer transType) {
+ this.transType = transType;
+ }
+
+ public Integer getEntranceId() {
+ return entranceId;
+ }
+
+ public void setEntranceId(Integer entranceId) {
+ this.entranceId = entranceId;
+ }
+
+ public Date getStatTime() {
+ return statTime;
+ }
+
+ public void setStatTime(Date statTime) {
+ this.statTime = statTime;
+ }
+
+ public Double getNum() {
+ return num;
+ }
+
+ public void setNum(Double num) {
+ this.num = num;
+ }
+
+ public Integer getSearchDirection() {
+ return searchDirection;
+ }
+
+ public void setSearchDirection(Integer searchDirection) {
+ this.searchDirection = searchDirection;
+ }
+
+ public Integer getSearchQuotaType() {
+ return searchQuotaType;
+ }
+
+ public void setSearchQuotaType(Integer searchQuotaType) {
+ this.searchQuotaType = searchQuotaType;
+ }
+
+
+
+}
diff --git a/src/main/java/com/nis/util/DateUtils.java b/src/main/java/com/nis/util/DateUtils.java index e0b6920..c0edcbf 100644 --- a/src/main/java/com/nis/util/DateUtils.java +++ b/src/main/java/com/nis/util/DateUtils.java @@ -4,11 +4,12 @@ package com.nis.util; import java.text.ParseException; -import java.text.ParsePosition; import java.text.SimpleDateFormat; +import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.apache.commons.lang3.time.DateFormatUtils; @@ -24,7 +25,7 @@ import com.zdjizhi.utils.StringUtil; * @version 2014-4-15 */ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { - public static final Logger logger =LoggerFactory.getLogger(DateUtils.class); + public static final Logger logger = LoggerFactory.getLogger(DateUtils.class); private static String[] parsePatterns = { "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm", "yyyy-MM", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM", "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM" }; @@ -249,8 +250,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { * 将短时间格式字符串转换为指定时间 * * @param strDate - * @param dateFormat - * "yyyy-MM-dd HH:mm:ss" 此参数为空,默认为:"yyyy-MM-dd" + * @param dateFormat "yyyy-MM-dd HH:mm:ss" 此参数为空,默认为:"yyyy-MM-dd" * @return * @throws ParseException */ @@ -264,33 +264,6 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { } /** - * @param args - * @throws ParseException - */ - public static void main(String[] args) throws ParseException { - // System.out.println(formatDate(parseDate("2010/3/6"))); - // System.out.println(getDate("yyyy年MM月dd日 E")); - // long time = new Date().getTime()-parseDate("2012-11-19").getTime(); - // System.out.println(time/(24*60*60*1000)); - /* Date date = new Date(); - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.MONTH, date.getMonth() - 2); - cal.set(Calendar.DAY_OF_MONTH, 1); - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - // timeMap.put("startTime", sdf.format(cal2.getTime())); - // timeMap.put("endTime", sdf.format(cal.getTime())); - logger.info("月报默认开始时间条件:" + sdf.format(cal.getTime()));*/ - - String beginDate = DateUtils.getSpecifiedDayBefore("2018-12-23 10:10:10"); - System.out.println(beginDate); - String bhour = DateUtils.getSpecifiedHourBefore("2018-12-23 10:10:10"); - System.out.println(bhour); - String bhour1 = DateUtils.getSpecifiedHourBefore("2018-12-23 00:10:10"); - System.out.println(bhour1); - - - } - /** * 获得指定日期的前一小时 * * @param specifiedDay @@ -335,6 +308,7 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { String dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime()); return dayAfter; } + /** * 获得指定日期的前一天 * @@ -381,4 +355,199 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { String dayAfter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(c.getTime()); return dayAfter; } + + /** + * 获取某个时间的最近五分钟,strDate和numDate传入一个即可 + * + * @param date 格式yyyy-MM-dd HH:mm:ss + * @param numDate 时间戳 + * @return + */ + public static Calendar getRecentFiveMinute(String strDate, Long numDate) { + Calendar instance = Calendar.getInstance(); + if (strDate != null) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + instance.setTime(sdf.parse(strDate)); + } catch (ParseException e) { + e.printStackTrace(); + } + } else if (numDate != null) { + instance.setTimeInMillis(numDate); + } + + int oldMinute = instance.get(Calendar.MINUTE); + char[] charArray = String.valueOf(oldMinute).toCharArray(); + if (charArray[charArray.length - 1] - '0' >= 5) { + charArray[charArray.length - 1] = '5'; + } else { + charArray[charArray.length - 1] = '0'; + } + instance.set(Calendar.SECOND, 0); + instance.set(Calendar.MINUTE, Integer.valueOf(String.valueOf(charArray))); + return instance; + } + + /** + * 获取两个时间的五分钟间隔,小时间隔,天间隔,月间隔 + * + * @param beginDate 开始时间(包含开始时间) + * @param endDate 结束时间(不包含结束时间) + * @param type 0:五分钟间隔,1:小时间隔,2:天间隔,3:月间隔,4:年间隔 + * @return 返回时间戳集合 + */ + public static List<Long> getTimeInterval(String beginDate, String endDate, int type) { + Calendar beginCal = getRecentFiveMinute(beginDate,null);// 将时间转为最近的五分钟 + Calendar endCal = getRecentFiveMinute(endDate,null); + + List<Long> list = new ArrayList<>(); + boolean bool = true; + + switch (type) { + case 1:// 获取小时间隔 + beginCal.set(Calendar.MINUTE, 0); + beginCal.set(Calendar.HOUR_OF_DAY, beginCal.get(Calendar.HOUR_OF_DAY)); + endCal.set(Calendar.MINUTE, 0); + endCal.set(Calendar.HOUR_OF_DAY, endCal.get(Calendar.HOUR_OF_DAY)); + break; + case 2:// 获取天间隔 + + beginCal.set(Calendar.MINUTE, 0); + beginCal.set(Calendar.HOUR_OF_DAY, 0); + beginCal.set(Calendar.DAY_OF_MONTH, beginCal.get(Calendar.DAY_OF_MONTH)); + + endCal.set(Calendar.MINUTE, 0); + endCal.set(Calendar.HOUR_OF_DAY, 0); + endCal.set(Calendar.DAY_OF_MONTH, endCal.get(Calendar.DAY_OF_MONTH)); + + break; + case 3:// 获取月间隔 + beginCal.set(Calendar.MINUTE, 0); + beginCal.set(Calendar.HOUR_OF_DAY, 0); + beginCal.set(Calendar.DAY_OF_MONTH, 1); + beginCal.set(Calendar.MONTH, beginCal.get(Calendar.MONTH)); + + endCal.set(Calendar.MINUTE, 0); + endCal.set(Calendar.HOUR_OF_DAY, 0); + endCal.set(Calendar.DAY_OF_MONTH, 1); + endCal.set(Calendar.MONTH, endCal.get(Calendar.MONTH)); + break; + case 4:// 获取年间隔 + beginCal.set(Calendar.MINUTE, 0); + beginCal.set(Calendar.HOUR_OF_DAY, 0); + beginCal.set(Calendar.DAY_OF_MONTH, 1); + beginCal.set(Calendar.MONTH, 0); + beginCal.set(Calendar.YEAR, beginCal.get(Calendar.YEAR)); + + endCal.set(Calendar.MINUTE, 0); + endCal.set(Calendar.HOUR_OF_DAY, 0); + endCal.set(Calendar.DAY_OF_MONTH, 1); + endCal.set(Calendar.MONTH, 0); + endCal.set(Calendar.YEAR, endCal.get(Calendar.YEAR)); + break; + } + list.add(beginCal.getTimeInMillis()); + long endTime = endCal.getTimeInMillis(); + while (bool) { + switch (type) { + case 1:// 获取小时间隔 + beginCal.add(Calendar.HOUR_OF_DAY, 1); + break; + case 2:// 获取天间隔 + beginCal.add(Calendar.DAY_OF_MONTH, 1); + break; + case 3:// 获取月间隔 + beginCal.add(Calendar.MONTH, 1); + break; + case 4:// 获取年间隔 + beginCal.add(Calendar.YEAR, 1); + break; + default:// 默认获取五分钟间隔 + beginCal.add(Calendar.MINUTE, 5); + + } + long timeInMillis = beginCal.getTimeInMillis(); + if (timeInMillis < endTime) { + list.add(timeInMillis); + } else { + bool = false; + } + + } + return list; + } + + /** + * 获取一个时间对应的小时,天,月,年等粒度 + * + * @param time 需要转化的时间 + * @param type 0:五分钟粒度,1:小时粒度,2:天粒度,3:月粒度,4:年粒度 + * @return + */ + public static Long getTimeByType(Long time, int type) { + Calendar calendar = Calendar.getInstance(); + calendar.setTimeInMillis(time); + + switch (type) { + case 0:// 获取小时间隔 + calendar=getRecentFiveMinute(null,time); + break; + case 1:// 获取小时间隔 + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.HOUR_OF_DAY, calendar.get(Calendar.HOUR_OF_DAY)); + break; + case 2:// 获取天间隔 + + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.DAY_OF_MONTH, calendar.get(Calendar.DAY_OF_MONTH)); + + break; + case 3:// 获取月间隔 + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.MONTH, calendar.get(Calendar.MONTH)); + break; + case 4:// 获取年间隔 + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.DAY_OF_MONTH, 1); + calendar.set(Calendar.MONTH, 0); + calendar.set(Calendar.YEAR, calendar.get(Calendar.YEAR)); + + break; + } + return calendar.getTimeInMillis(); + } + + /** + * 时间戳 换成日期格式字符串转 + * + * @param 时间 1544602212000 + * @param format 如:yyyy-MM-dd HH:mm:ss + * @return + */ + public static String stampToDate(long timeStamp) { + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");// 这个是你要转成后的时间的格式 + String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间 + return sd; + } + + /** + * 日期格式字符串转换成时间戳 + * + * @param date 字符串日期 + * @param format 如:yyyy-MM-dd HH:mm:ss + * @return + */ + public static Long dateToStamp(String date_str) { + try { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + return sdf.parse(date_str).getTime(); + } catch (Exception e) { + e.printStackTrace(); + } + return 0l; + } } diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index 901758e..d55f218 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -73,7 +73,7 @@ public class ConfigSourcesController extends BaseRestController { @RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.POST)
@ApiOperation(value = "MAAT规则存储接口", httpMethod = "POST", response = Map.class, notes = "接收MAAT规则数据,存储到流量处理平台配置线中")
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
- public Map createMaatConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request,
+ public Map addOrUpdateMaatConfig(@RequestBody ConfigSource configSource, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
@@ -90,11 +90,18 @@ public class ConfigSourcesController extends BaseRestController { && configSource.getConfigCompileList().size() > Constants.MAX_LIST_SIZE) {
thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容");
}
- checkOpAction(thread, System.currentTimeMillis() - start, configSource.getOpAction(),
- Constants.OPACTION_POST);
+ if (configSource.getOpAction() == null || !(configSource.getOpAction() == Constants.OPACTION_POST
+ || configSource.getOpAction() == Constants.OPACTION_PUT)) {// 允许新增或者修改
+ checkOpAction(thread, System.currentTimeMillis() - start, configSource.getOpAction(),
+ Constants.OPACTION_POST);
+ }
// 验证配置编译数据
validateConfigSource(thread, start, configSource);
- configSourcesService.saveMaatConfig(thread, start, configSource.getConfigCompileList(), sb);
+ if (configSource.getOpAction() == Constants.OPACTION_POST) {
+ configSourcesService.saveMaatConfig(thread, start, configSource.getConfigCompileList(), sb);
+ } else {
+ configSourcesService.updateMaatConfig(thread, start, configSource.getConfigCompileList(), sb);
+ }
} else {
throw new RestServiceException("Maat规则不能为空", RestBusinessCode.ConfigSourceIsNull.getValue());
}
@@ -124,6 +131,7 @@ public class ConfigSourcesController extends BaseRestController { "Maat规则下发成功" + sb.toString(), Constants.IS_DEBUG ? configSource : null);
}
+ @Deprecated
@RequestMapping(value = "/cfg/v2/configStartStop", method = RequestMethod.PUT)
@ApiOperation(value = "MAAT规则停用启用接口", httpMethod = "PUT", response = Map.class, notes = "接收MAAT类配置,对配置停用还是启用")
@ApiParam(value = "MAAT规则停用启用接口", name = "configStartStop", required = true)
@@ -139,10 +147,8 @@ public class ConfigSourcesController extends BaseRestController { if (getLock(requestId)) {
checkOpAction(thread, System.currentTimeMillis() - start, configSourceStartStop.getOpAction(),
Constants.OPACTION_PUT);
-
- configSourcesService.updateConfigSources(thread, start,
- configSourceStartStop.getConfigCompileStartStopList(), configSourceStartStop.getOpTime(), sb,
- true);
+ configSourcesService.updateConfigStatus(thread, start,
+ configSourceStartStop.getConfigCompileStartStopList(), configSourceStartStop.getOpTime(), sb);
}
} catch (Exception e) {
@@ -169,9 +175,9 @@ public class ConfigSourcesController extends BaseRestController { }
@RequestMapping(value = "/cfg/v1/configSources", method = RequestMethod.PUT)
- @ApiOperation(value = "MAAT规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收Maat规则,对其状态置为失效")
+ @ApiOperation(value = "MAAT规则状态更新接口", httpMethod = "PUT", response = Map.class, notes = "接收Maat规则,将其状态置为失效或生效")
@ApiParam(value = "MAAT规则对象", name = "configSource", required = true)
- public Map updateConfigSource(@RequestBody ConfigSource configSource, HttpServletRequest request,
+ public Map updateConfigStatus(@RequestBody ConfigSource configSource, HttpServletRequest request,
HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request,
@@ -190,9 +196,9 @@ public class ConfigSourcesController extends BaseRestController { && configSource.getConfigCompileList().size() > Constants.MAX_LIST_SIZE) {
thread.setContent("批量提交数量超过" + Constants.MAX_LIST_SIZE + "条,不记录请求内容");
}
- checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2);
- configSourcesService.updateConfigSources(thread, start, configSource.getConfigCompileList(),
- configSource.getOpTime(), sb, false);
+ checkOpAction(thread, System.currentTimeMillis() - start, opAction, Constants.OPACTION_PUT);
+ configSourcesService.updateConfigStatus(thread, start, configSource.getConfigCompileList(),
+ configSource.getOpTime(), sb);
} else {
throw new RestServiceException("Maat规则不能为空" + sb.toString(),
@@ -701,7 +707,7 @@ public class ConfigSourcesController extends BaseRestController { if (!jsonString.trim().equals("{}")) {// 如果service下没有配置,不论是maat类还是回调类配置,都会传{},有数据的话{}中有内容
configSourcesService.setRedisClusterKey(key, jsonString);
}
- configSourcesService.setAllServiceKey(key);//无论service下有没有数据,都会记录当前需要同步的业务,避免后台有数据,但是界面没有数据的情况,这种情况下可以发送空业务来删除后台的数据
+ configSourcesService.setAllServiceKey(key);// 无论service下有没有数据,都会记录当前需要同步的业务,避免后台有数据,但是界面没有数据的情况,这种情况下可以发送空业务来删除后台的数据
}
if (!StringUtil.isEmpty(lastCompletedTag) && lastCompletedTag.trim().toLowerCase().equals("finished")) {
// 设置配置同步状态为接收配置完成
@@ -824,7 +830,7 @@ public class ConfigSourcesController extends BaseRestController { @RequestMapping(value = "/cfg/v1/getConfigByService", method = RequestMethod.GET)
@ApiOperation(value = "获取有效无效的配置信息", httpMethod = "GET", response = Map.class, notes = "获取有效无效的配置信息")
- public Map getConfigCount(@RequestParam int service,HttpServletRequest request, HttpServletResponse response) {
+ public Map getConfigCount(@RequestParam int service, HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
Map<String, Integer> allConfigByScan = configSourcesService.getConfigByService(service);
@@ -833,4 +839,15 @@ public class ConfigSourcesController extends BaseRestController { allConfigByScan);
}
+ @RequestMapping(value = "/cfg/v1/delAllConfig", method = RequestMethod.DELETE)
+ @ApiOperation(value = "删除所有的配置信息", httpMethod = "DELETE", response = Map.class, notes = "删除所有的配置信息")
+ public Map delAllConfig(HttpServletRequest request, HttpServletResponse response) {
+ long start = System.currentTimeMillis();
+ AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_DELETE, request, null);
+ boolean bool = configSourcesService.delAllConfig();
+ return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "删除所有的配置信息成功",
+// configSourcesService.getAllConfig());
+ bool);
+ }
+
}
diff --git a/src/main/java/com/nis/web/controller/restful/SingleDimensionReportController.java b/src/main/java/com/nis/web/controller/restful/SingleDimensionReportController.java index c88096c..9109842 100644 --- a/src/main/java/com/nis/web/controller/restful/SingleDimensionReportController.java +++ b/src/main/java/com/nis/web/controller/restful/SingleDimensionReportController.java @@ -433,7 +433,6 @@ public class SingleDimensionReportController extends BaseRestController { CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);
reportPage = ntcReportService
.findNtcURLReport(new Page<NtcURLIpReport>(request, response, NtcURLIpReport.class), urlReport);
- CustomerContextHolder.clearCustomerType();
} catch (Exception e) {
saveLogThread.setExceptionInfo("URL统计查询失败:" + e.getMessage());
logger.error("URL统计查询失败:" + ExceptionUtil.getExceptionMsg(e));
@@ -447,6 +446,8 @@ public class SingleDimensionReportController extends BaseRestController { throw new ServiceRuntimeException(saveLogThread, System.currentTimeMillis() - start,
"URL统计查询失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
+ }finally {
+ CustomerContextHolder.clearCustomerType();
}
return serviceLogResponse(saveLogThread, System.currentTimeMillis() - start, request, "URL统计查询成功", reportPage,
diff --git a/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java b/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java index 7cf94d5..7bfb49c 100644 --- a/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java +++ b/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java @@ -1,31 +1,34 @@ package com.nis.web.controller.restful;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
+import org.springframework.validation.BindException;
+import org.springframework.validation.BindingResult;
+import org.springframework.validation.Errors;
+import org.springframework.validation.ObjectError;
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.Page;
import com.nis.domain.restful.NtcRadiusReport;
+import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
import com.nis.restful.RestBusinessCode;
import com.nis.restful.RestServiceException;
import com.nis.restful.ServiceRuntimeException;
import com.nis.util.Constants;
import com.nis.util.DateUtils;
import com.nis.util.ExceptionUtil;
-import com.nis.util.StringUtils;
import com.nis.web.controller.BaseRestController;
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.ServicesRequestLogService;
@@ -37,7 +40,7 @@ import com.zdjizhi.utils.StringUtil; /**
*
* <p>
- * Title: SingleDimensionReport
+ * Title: TrafficeReportController
* </p>
* <p>
* Description:首页流量统计查询controller,改为从clickhouse中获取
@@ -95,57 +98,16 @@ public class TrafficeReportController extends BaseRestController { * 根据ip46,协议tcp,udp查询带宽
*/
@RequestMapping(value = "trafficBandwidthTransThree", method = RequestMethod.GET)
- @ApiOperation(value = "带宽根据ip46,协议tcp,udp查询详情", httpMethod = "GET", notes = "对应带宽根据IPv4,6,协议tcp,udp统计数据显示")
- public Map<String, ?> trafficBandwidthTransThree(@RequestParam String beginDate, @RequestParam String endDate,
- Model model, HttpServletRequest request, HttpServletResponse response) {
- String[] addrTypes = { "4", "6" };// ipv4,ipv6是固定的不会变
- String[] transTypes = { "6", "17" };// 传输层协议,tcp,udp
+ @ApiOperation(value = "查询带宽信息", httpMethod = "GET", notes = "查询各地区,bps|pps|linknums在各个ip类型,传输类型的统计数据")
+ public Map<String, ?> trafficBandwidthTransThree(@Valid TrafficTransStatisticCK trafficTransStatisticCK,
+ HttpServletRequest request, HttpServletResponse response) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request,
null);
- Map<String, List<HashMap>> resultMap = new HashMap<String, List<HashMap>>();
+ Map resultMap = new HashMap();
try {
- if (StringUtils.isEmpty(beginDate) && StringUtils.isEmpty(endDate)) {
- Calendar cal = Calendar.getInstance();
- cal.setTime(new Date());
- endDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());// 获取到完整的时间
- cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
- beginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(cal.getTime());
- }
- String addrType = null;
- Integer transType = null;
- if (addrTypes != null) {
- for (int i = 0; i < addrTypes.length; i++) {
- addrType = addrTypes[i];
- List<HashMap> resultList = trafficReportService.getBandwidthTrans(addrType, transType, beginDate,
- endDate);
- if (resultList != null && resultList.size() > 0) {
- resultMap.put("ipv" + addrType + "Type1", resultList);
- }
-
- resultList = trafficReportService.getBandwidthTrans2(addrType, transType, beginDate, endDate);
- if (resultList != null && resultList.size() > 0) {
- resultMap.put("ipv" + addrType + "Type2", resultList);
- }
- addrType = null;
- }
- }
- if (transTypes != null) {
- for (int i = 0; i < transTypes.length; i++) {
- transType = Integer.valueOf(transTypes[i]);
- List<HashMap> resultList = trafficReportService.getBandwidthTrans(addrType, transType, beginDate,
- endDate);
- if (resultList != null && resultList.size() > 0) {
- resultMap.put("trans" + transType + "Type1", resultList);
- }
- resultList = trafficReportService.getBandwidthTrans2(addrType, transType, beginDate, endDate);
- if (resultList != null && resultList.size() > 0) {
- resultMap.put("trans" + transType + "Type2", resultList);
- }
- transType = null;
- }
- }
-
+ CustomerContextHolder.setCustomerType(CustomerContextHolder.DATA_SOURCE_B);
+ resultMap = trafficReportService.getBandwidthTransByQuoTaType(trafficTransStatisticCK);
} catch (Exception e) {
auditLogThread.setExceptionInfo("带宽实时统计数据检索失败:" + e.getMessage());
logger.error("带宽实时统计数据检索失败:" + ExceptionUtil.getExceptionMsg(e));
@@ -159,7 +121,10 @@ public class TrafficeReportController extends BaseRestController { throw new ServiceRuntimeException(auditLogThread, System.currentTimeMillis() - start,
"带宽实时统计数据检索失败:" + e.getMessage(), RestBusinessCode.service_runtime_error.getValue());
}
+ } finally {
+ CustomerContextHolder.clearCustomerType();
}
+
return serviceLogResponse(auditLogThread, System.currentTimeMillis() - start, request, "带宽实时统计数据检索成功",
resultMap, 0);
}
diff --git a/src/main/java/com/nis/web/dao/TrafficReportDao.java b/src/main/java/com/nis/web/dao/TrafficReportDao.java index 939ee7b..8ddd3ce 100644 --- a/src/main/java/com/nis/web/dao/TrafficReportDao.java +++ b/src/main/java/com/nis/web/dao/TrafficReportDao.java @@ -1,52 +1,19 @@ package com.nis.web.dao;
-import java.util.Date;
import java.util.List;
-import java.util.Map;
-import org.apache.ibatis.annotations.Param;
-
-import com.nis.domain.restful.NtcAttrTypeReport;
-import com.nis.domain.restful.NtcDestipCountryReport;
-import com.nis.domain.restful.NtcEntranceReport;
import com.nis.domain.restful.NtcIpRangeReport;
-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;
-import com.nis.domain.restful.NtcURLIpReport;
-import com.nis.domain.restful.dashboard.NtcTotalReport;
-import com.nis.domain.restful.dashboard.TrafficTransStatistic;
+import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
/**
+ * 从clickhouse中查询相关流量统计数据
*
- * @ClassName:NtcReportDao
- * @Description:TODO(这里用一句话描述这个类的作用)
- * @author (zdx)
- * @date 2018年7月11日 下午5:47:55
- * @version V1.0
+ * @author RenKaiGe
+ *
*/
@MyBatisDao
-public interface TrafficReportDao extends CrudDao {
- List<NtcPzReport> findNtcPzReport(NtcPzReport pz);
-
- List<NtcServiceReport> findNtcServiceReport(NtcServiceReport pz);
-
- List<NtcTagReport> findNtcTagReport(NtcTagReport pz);
-
- List<NtcAttrTypeReport> findNtcAttrTypeReport(NtcAttrTypeReport pz);
-
- List<NtcLwhhReport> findNtcLwhhReport(NtcLwhhReport pz);
-
- List<NtcSrcipDomesticReport> findNtcSrcipDomesticReport(NtcSrcipDomesticReport pz);
-
- List<NtcDestipCountryReport> findNtcDestipCountryReport(NtcDestipCountryReport pz);
-
- List<NtcEntranceReport> findNtcEntranceReport(NtcEntranceReport pz);
-
- List<NtcURLIpReport> findNtcIpURLReport(NtcURLIpReport pz);
+public interface TrafficReportDao {
List<NtcRadiusReport> findAccounList(NtcRadiusReport pz);
@@ -56,20 +23,10 @@ public interface TrafficReportDao extends CrudDao { List<NtcIpRangeReport> findNtcIpRangeReport(NtcIpRangeReport pz);
- void insertNtcIpRangeBatch(List<NtcIpRangeReport> list);
+ List<TrafficTransStatisticCK> getBandwidthBpsFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
+
+ List<TrafficTransStatisticCK> getBandwidthPpsFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
+
+ List<TrafficTransStatisticCK> getBandwidthLinkNumFromCk(TrafficTransStatisticCK trafficTransStatisticCK);
- void truncateNtcIpRange();
-
-
-
- NtcTotalReport getMaxReportTime();
- Map getMaxStatTime();
- List<Map> getTotalReportList(@Param("reportTime") Date reportTime);
- List<Map> getNetFlowPortInfoNew(@Param("statTime") Date statTime);
- List<TrafficTransStatistic> getBandwidthTrans(@Param("entranceId") Integer entranceId,@Param("beginDate") String beginDate,@Param("endDate") String endDate,@Param("addrType") String addrType,@Param("transType") Integer transType);
- List<TrafficTransStatistic> getBandwidthTrans2(@Param("beginDate") String beginDate,@Param("endDate") String endDate);
- Map getEntranceMaxReportTime();
- List<NtcEntranceReport> getActionTrans(@Param("beginDate") String beginDate,@Param("endDate") String endDate ,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql);
-
-
}
diff --git a/src/main/java/com/nis/web/dao/TrafficReportDao.xml b/src/main/java/com/nis/web/dao/TrafficReportDao.xml index ca401bb..2016b30 100644 --- a/src/main/java/com/nis/web/dao/TrafficReportDao.xml +++ b/src/main/java/com/nis/web/dao/TrafficReportDao.xml @@ -1,83 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.nis.web.dao.TrafficReportDao">
- <resultMap id="NtcPzReportMap"
- type="com.nis.domain.restful.NtcPzReport">
- <result column="CFG_ID" jdbcType="BIGINT" property="cfgId" />
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="NtcServiceReportMap"
- type="com.nis.domain.restful.NtcServiceReport">
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="NtcTagReportMap"
- type="com.nis.domain.restful.NtcTagReport">
- <result column="TAG" jdbcType="INTEGER" property="tag" />
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="NtcAttrTypeReportMap"
- type="com.nis.domain.restful.NtcAttrTypeReport">
- <result column="ATTR_TYPE" jdbcType="INTEGER"
- property="attrType" />
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="ntcLwhhReportMap"
- type="com.nis.domain.restful.NtcLwhhReport">
- <result column="LWHH" jdbcType="INTEGER" property="lwhh" />
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="NtcSrcipDomesticReportMap"
- type="com.nis.domain.restful.NtcSrcipDomesticReport">
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="SRC_PROVINCE" jdbcType="VARCHAR"
- property="srcProvince" />
- <result column="SRC_CITY" jdbcType="VARCHAR" property="srcCity" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="NtcDestipCountryReportMap"
- type="com.nis.domain.restful.NtcDestipCountryReport">
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="DEST_COUNTRY" jdbcType="VARCHAR"
- property="destCountry" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
- <resultMap id="NtcEntranceReportMap"
- type="com.nis.domain.restful.NtcEntranceReport">
- <result column="SERVICE" jdbcType="INTEGER" property="service" />
- <result column="ENTRANCE_ID" jdbcType="INTEGER"
- property="entranceId" />
- <result column="SUM" jdbcType="BIGINT" property="sum" />
- <result column="REPORT_TIME" jdbcType="TIMESTAMP"
- property="reportTime" />
- </resultMap>
-
- <resultMap id="NtcURLIpReportMap"
- type="com.nis.domain.restful.NtcURLIpReport">
- <result column="url" jdbcType="VARCHAR" property="url" />
- <result column="ipCount" jdbcType="BIGINT" property="ipCount" />
- <result column="connCount" jdbcType="BIGINT"
- property="connCount" />
- </resultMap>
<resultMap id="NtcRadiusReportMap"
type="com.nis.domain.restful.NtcRadiusReport">
@@ -104,683 +28,27 @@ </resultMap>
- <sql id="commonPorperty">
- SERVICE,SUM,REPORT_TIME
- </sql>
-
- <select id="findNtcPzReport"
- parameterType="com.nis.domain.restful.NtcPzReport"
- resultMap="NtcPzReportMap">
- SELECT
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 1 ">
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- CFG_ID,SERVICE,SUM
- </otherwise>
- </choose>
- FROM (SELECT CFG_ID,SERVICE,SUM(SUM) SUM
- FROM
- </when>
- <otherwise>
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- CFG_ID,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT CFG_ID, SERVICE, SUM(SUM) SUM ,REPORT_TIME
- FROM
- </otherwise>
- </choose>
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_PZ_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_PZ_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 5 ">
- NTC_PZ_STAT_MONTH
- </when>
- <otherwise>
- NTC_PZ_REPORT
- </otherwise>
- </choose>
-
- <where>
- <if test="searchCfgId != null and searchCfgId !=''">
- <![CDATA[AND CFG_ID in (${searchCfgId})]]>
- </if>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 1 ">
- GROUP BY CFG_ID,SERVICE
- )
- </when>
- <otherwise>
- GROUP BY CFG_ID,SERVICE,REPORT_TIME
- )
- </otherwise>
- </choose>
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_PZ_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_PZ_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 5 ">
- NTC_PZ_STAT_MONTH
- </when>
- <otherwise>
- NTC_PZ_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
- <select id="findNtcServiceReport"
- parameterType="com.nis.domain.restful.NtcServiceReport"
- resultMap="NtcServiceReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE, SUM(SUM) SUM ,REPORT_TIME
- FROM
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_SERVICE_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_SERVICE_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_SERVICE_STAT_MONTH
- </when>
- <otherwise>
- NTC_SERVICE_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
-
- GROUP BY SERVICE,REPORT_TIME
- )
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_SERVICE_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_SERVICE_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_SERVICE_STAT_MONTH
- </when>
- <otherwise>
- NTC_SERVICE_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
-
- <select id="findNtcTagReport"
- parameterType="com.nis.domain.restful.NtcTagReport"
- resultMap="NtcTagReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- TAG,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE,TAG,SUM(SUM) SUM ,REPORT_TIME
- FROM
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_TAG_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_TAG_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_TAG_STAT_MONTH
- </when>
- <otherwise>
- NTC_TAG_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchTag != null and searchTag !=''">
- <![CDATA[AND TAG in (${searchTag})]]>
- </if>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
-
- GROUP BY SERVICE,TAG,REPORT_TIME
- )
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_TAG_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_TAG_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_TAG_STAT_MONTH
- </when>
- <otherwise>
- NTC_TAG_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
-
- <select id="findNtcAttrTypeReport"
- parameterType="com.nis.domain.restful.NtcAttrTypeReport"
- resultMap="NtcAttrTypeReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- ATTR_TYPE,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE,ATTR_TYPE, SUM(SUM) SUM ,REPORT_TIME
- FROM
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_ATTR_TYPE_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_ATTR_TYPE_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_ATTR_TYPE_STAT_MONTH
- </when>
- <otherwise>
- NTC_ATTR_TYPE_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchAttrType != null and searchAttrType !=''">
- <![CDATA[AND ATTR_TYPE in (${searchAttrType})]]>
- </if>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
-
- GROUP BY SERVICE,ATTR_TYPE,REPORT_TIME
- )
-
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_ATTR_TYPE_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_ATTR_TYPE_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_ATTR_TYPE_STAT_MONTH
- </when>
- <otherwise>
- NTC_ATTR_TYPE_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
-
- <select id="findNtcLwhhReport"
- parameterType="com.nis.domain.restful.NtcLwhhReport"
- resultMap="ntcLwhhReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- LWHH,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE,LWHH, SUM(SUM) SUM ,REPORT_TIME
- FROM
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_LWHH_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_LWHH_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_LWHH_STAT_MONTH
- </when>
- <otherwise>
- NTC_LWHH_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchLwhh != null and searchLwhh !=''">
- <![CDATA[AND LWHH in (${searchLwhh})]]>
- </if>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
-
- GROUP BY SERVICE,LWHH,REPORT_TIME
- )
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_LWHH_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_LWHH_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_LWHH_STAT_MONTH
- </when>
- <otherwise>
- NTC_LWHH_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
- <select id="findNtcSrcipDomesticReport"
- parameterType="com.nis.domain.restful.NtcSrcipDomesticReport"
- resultMap="NtcSrcipDomesticReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- SRC_PROVINCE,SRC_CITY,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE,SRC_PROVINCE,SRC_CITY, SUM(SUM) SUM ,REPORT_TIME
- FROM
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_SRCIP_DOMESTIC_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_SRCIP_DOMESTIC_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_SRCIP_DOMESTIC_STAT_MONTH
- </when>
- <otherwise>
- NTC_SRCIP_DOMESTIC_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
-
- GROUP BY SERVICE,SRC_PROVINCE,SRC_CITY,REPORT_TIME
- )
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_SRCIP_DOMESTIC_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_SRCIP_DOMESTIC_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_SRCIP_DOMESTIC_STAT_MONTH
- </when>
- <otherwise>
- NTC_SRCIP_DOMESTIC_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
-
- <select id="findNtcDestipCountryReport"
- parameterType="com.nis.domain.restful.NtcDestipCountryReport"
- resultMap="NtcDestipCountryReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- DEST_COUNTRY,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE,DEST_COUNTRY, SUM(SUM) SUM ,REPORT_TIME
- FROM
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_DESTIP_COUNTRY_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_DESTIP_COUNTRY_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_DESTIP_COUNTRY_STAT_MONTH
- </when>
- <otherwise>
- NTC_DESTIP_COUNTRY_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
+ <resultMap id="TrafficTransStatisticCKResultMap"
+ type="com.nis.domain.restful.dashboard.TrafficTransStatisticCK">
+ <result column="addr_type" jdbcType="INTEGER"
+ property="addrType" />
+ <result column="trans_type" jdbcType="INTEGER"
+ property="transType" />
+ <result column="entrance_id" jdbcType="INTEGER"
+ property="entranceId" />
+ <result column="num" jdbcType="DOUBLE" property="num" />
+ <result column="stat_time" jdbcType="TIMESTAMP"
+ property="statTime" />
+ </resultMap>
- GROUP BY SERVICE,DEST_COUNTRY,REPORT_TIME
- )
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_DESTIP_COUNTRY_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_DESTIP_COUNTRY_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_DESTIP_COUNTRY_STAT_MONTH
- </when>
- <otherwise>
- NTC_DESTIP_COUNTRY_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
- <select id="findNtcEntranceReport"
- parameterType="com.nis.domain.restful.NtcEntranceReport"
- resultMap="NtcEntranceReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- ENTRANCE_ID,
- <include refid="commonPorperty" />
- </otherwise>
- </choose>
- FROM (SELECT SERVICE,ENTRANCE_ID, SUM(SUM) SUM ,REPORT_TIME
- FROM
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_ENTRANCE_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_ENTRANCE_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_ENTRANCE_STAT_MONTH
- </when>
- <otherwise>
- NTC_ENTRANCE_REPORT
- </otherwise>
- </choose>
- <where>
- <if test="searchEntrance != null and searchEntrance !=''">
- <![CDATA[AND ENTRANCE_ID in (${searchEntrance})]]>
- </if>
- <if test="searchService != null and searchService !=''">
- <![CDATA[AND SERVICE in (${searchService})]]>
- </if>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND REPORT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND REPORT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- </where>
- GROUP BY SERVICE,ENTRANCE_ID,REPORT_TIME
- )
- <choose>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 2 ">
- NTC_ENTRANCE_STAT_HOUR
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 3 ">
- NTC_ENTRANCE_STAT_DAILY
- </when>
- <when
- test="searchBusinessType !=null and searchBusinessType != '' and searchBusinessType == 4 ">
- NTC_ENTRANCE_STAT_MONTH
- </when>
- <otherwise>
- NTC_ENTRANCE_REPORT
- </otherwise>
- </choose>
- <choose>
- <when
- test="page !=null and page.orderBy != null and page.orderBy != ''">
- ORDER BY ${page.orderBy}
- </when>
- </choose>
- </select>
+ <sql id="commonPorperty">
+ SERVICE,SUM,REPORT_TIME
+ </sql>
- <select id="findNtcIpURLReport"
- parameterType="com.nis.domain.restful.NtcURLIpReport"
- resultMap="NtcURLIpReportMap">
- SELECT
- <choose>
- <when
- test="page !=null and page.fields != null and page.fields != ''">
- ${page.fields}
- </when>
- <otherwise>
- url, ipCount,connCount
- </otherwise>
- </choose>
- FROM (SELECT url,
- count(distinct ip_addr) ipCount,
- sum(sum) connCount
- FROM ntc_reject_url_statistic
- <where>
- <if
- test="searchReportStartTime != null and searchReportStartTime !=''">
- <![CDATA[AND STAT_TIME >= STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if
- test="searchReportEndTime != null and searchReportEndTime !=''">
- <![CDATA[AND STAT_TIME < STR_TO_DATE(#{searchReportEndTime},'%Y-%m-%d %H:%i:%s')]]>
- </if>
- <if test="searchUrl != null and searchUrl !=''">
- AND url like concat(concat('%',#{searchUrl}),'%')
- </if>
- </where>
- GROUP BY url
- ) ntc_reject_url_statistic ORDER BY ipcount desc,connCount desc
- </select>
<select id="findNasIpList"
@@ -791,7 +59,9 @@ <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')]]> -->
+ <!-- <![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')]]> -->
<![CDATA[and report_time>= #{searchReportStartTime} and report_time <#{searchReportEndTime} ]]>
</when>
<otherwise>
@@ -810,7 +80,9 @@ <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')]]> -->
+ <!-- <![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')]]> -->
<![CDATA[and report_time >= #{searchReportStartTime} and report_time <#{searchReportEndTime} ]]>
</when>
<otherwise>
@@ -872,119 +144,109 @@ </select>
- <insert id="insertNtcIpRangeBatch"
- parameterType="com.nis.domain.restful.NtcIpRangeReport">
- INSERT INTO traffic_ip_identify
- (ip_start,ip_end,ip_start_num,ip_end_num,ip_sub,area_type,country)
- VALUES
- <foreach collection="list" item="ipRange" separator=",">
- (#{ipRange.ipStart}, #{ipRange.ipEnd},
- #{ipRange.ipStartNum},
- #{ipRange.ipEndNum},
- #{ipRange.ipSub}, #{ipRange.areaType},
- #{ipRange.country})
- </foreach>
- </insert>
+ <select id="getBandwidthBpsFromCk"
+ resultMap="TrafficTransStatisticCKResultMap">
+ select
+ (SUM(c2s_byte_len + s2c_byte_len)* 8)/ 300 / 1024 / 1024 / 1024 num,
+ toStartOfFiveMinute(stat_time) stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ from
+ ntc_network_traffic_stat
+ where
+ <![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
+ <if test="searchDirection != null">
+ and direction=#{searchDirection}
+ </if>
+ and addr_type in('4',
+ '6')
+ and entrance_id in (1,
+ 2)
+ and trans_type in(6,
+ 17)
+ group by
+ stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ order by
+ stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ </select>
- <update id="truncateNtcIpRange">
- truncate table traffic_ip_identify
- </update>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+<select id="getBandwidthPpsFromCk"
+ resultMap="TrafficTransStatisticCKResultMap">
+ select
+ SUM(c2s_pkt_num + s2c_pkt_num)/ 300 num,
+ toStartOfFiveMinute(stat_time) stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ from
+ ntc_network_traffic_stat
+ where
+ <![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
+ <if test="searchDirection != null">
+ and direction=#{searchDirection}
+ </if>
+ and addr_type in('4',
+ '6')
+ and entrance_id in (1,
+ 2)
+ and trans_type in(6,
+ 17)
+ group by
+ stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ order by
+ stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ </select>
+<select id="getBandwidthLinkNumFromCk"
+ resultMap="TrafficTransStatisticCKResultMap">
+ select
+ SUM(link_num) num,
+ toStartOfFiveMinute(stat_time) stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ from
+ ntc_network_traffic_stat
+ where
+ <![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
+ <if test="searchDirection != null">
+ and direction=#{searchDirection}
+ </if>
+ and addr_type in('4',
+ '6')
+ and entrance_id in (1,
+ 2)
+ and trans_type in(6,
+ 17)
+ group by
+ stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ order by
+ stat_time,
+ addr_type,
+ trans_type,
+ entrance_id
+ </select>
- <resultMap id="BandwidthResultMap" type="com.nis.domain.restful.dashboard.TrafficTransStatistic">
- <id column="stat_id" jdbcType="INTEGER" property="statId" />
- <result column="addr_type" jdbcType="INTEGER" property="addrType" />
- <result column="trans_type" jdbcType="INTEGER" property="transType" />
- <result column="entrance_id" jdbcType="INTEGER" property="entranceId" />
- <result column="link_num" jdbcType="BIGINT" property="linkNum" />
- <result column="c2s_pkt_num" jdbcType="BIGINT" property="c2sPktNum" />
- <result column="s2c_pkt_num" jdbcType="BIGINT" property="s2cPktNum" />
- <result column="c2s_byte_len" jdbcType="BIGINT" property="c2sByteLen" />
- <result column="s2c_byte_len" jdbcType="BIGINT" property="s2cByteLen" />
- <result column="pps" jdbcType="BIGINT" property="pps" />
- <result column="gbps" jdbcType="BIGINT" property="gbps" />
- <result column="stat_time" jdbcType="TIMESTAMP" property="statTime" />
- </resultMap>
-
- <!-- 获取取阻断,监测等流量信息最近时间 -->
- <select id="getMaxReportTime" resultType="com.nis.domain.restful.dashboard.NtcTotalReport">
- SELECT report_time reportTime FROM ntc_total_report order by report_time desc limit 1
- </select>
-
- <!-- 根据最近的时间获取阻断,监测等流量信息 -->
- <select id="getTotalReportList" resultType="java.util.HashMap">
- SELECT SUM(reject_num) rejectNum,SUM(monitor_num) monitorNum,SUM(c2s_pkt_num) c2sPktNum,SUM(s2c_pkt_num) s2cPktNum,SUM(c2s_byte_len) c2sByteLen,SUM(s2c_byte_len) s2cByteLen,SUM(new_uni_conn_num) newUniConnNum,SUM(close_conn_num) closeConnNum,
- SUM(drop_conn_num) dropConnNum,SUM(loop_conn_num) loopConnNum FROM ntc_total_report
- where report_time > DATE_SUB(#{reportTime},INTERVAL 1 hour)
- </select>
-
- <!-- 获取带宽最近时间 -->
- <select id="getMaxStatTime" resultType="java.util.HashMap">
- SELECT stat_time statTime FROM traffic_trans_statistic order by stat_time desc limit 1
- </select>
- <!-- 根据最近时间条获取带宽,进出口流量 -->
- <select id="getNetFlowPortInfoNew" resultType="java.util.HashMap">
- SELECT SUM(total_traffic.inoctets) AS inoctets ,SUM(total_traffic.outoctets) AS outoctets FROM (
- SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
- where stat_time = (SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=1 ORDER BY stat_time DESC LIMIT 0,1) and entrance_id=1
- UNION ALL
- SELECT IFNULL(SUM(c2s_byte_len),0) inoctets ,IFNULL(SUM(s2c_byte_len),0) outoctets FROM traffic_trans_statistic
- where stat_time = (SELECT stat_time FROM traffic_trans_statistic WHERE entrance_id=2 ORDER BY stat_time DESC LIMIT 0,1) and entrance_id=2
- ) total_traffic
- </select>
-
-
- <!-- 获取近一小时的带宽根据ip46,协议 tcp,udp变化 -->
-<select id="getBandwidthTrans" resultMap="BandwidthResultMap">
- select (SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024 gbps, SUM(c2s_pkt_num+s2c_pkt_num)/300 pps, SUM(link_num) linkNum, stat_time time from traffic_trans_statistic
- where <![CDATA[stat_time>=#{beginDate} and stat_time<#{endDate} ]]>
- <if test="addrType != null">
- and addr_type=#{addrType}
- </if>
- <if test="transType != null">
- and trans_type=${transType}
- </if>
- and entrance_id=#{entranceId}
- group by stat_time order by stat_time
-</select>
- <!-- 获取近一小时的带宽根据ip46,协议 tcp,udp变化 -->
-<select id="getBandwidthTrans2" resultMap="BandwidthResultMap">
- select addr_type,trans_type,entrance_id, (SUM(c2s_byte_len+s2c_byte_len)*8)/300/1024/1024/1024 gbps, SUM(c2s_pkt_num+s2c_pkt_num)/300 pps, SUM(link_num) linkNum, stat_time time from traffic_trans_statistic
- where <![CDATA[stat_time<#{endDate} and stat_time>=#{beginDate}]]>
- and addr_type !=0
- and trans_type!=0
- group by stat_time,addr_type,trans_type order by stat_time
-</select>
-
- <!-- 获取报表最近时间 -->
- <select id="getEntranceMaxReportTime" resultType="java.util.HashMap">
- SELECT report_time reportTime FROM ntc_entrance_report order by report_time desc limit 1
- </select>
-
-<!-- entrance 1,2 ,动作为阻断,近一小时 间隔5分钟数据 -->
-<select id="getActionTrans" resultType="com.nis.domain.restful.NtcEntranceReport">
- select sum(sum) sum,report_time time from ntc_entrance_report r where
- <![CDATA[${serviceSql} and report_time<#{endDate} and report_time>=#{beginDate}]]>
- and entrance_id=#{entranceId}
- group by report_time order by report_time
-</select>
</mapper>
\ No newline at end of file diff --git a/src/main/java/com/nis/web/service/AuditLogThread.java b/src/main/java/com/nis/web/service/AuditLogThread.java index 415cbb0..cc9c6a5 100644 --- a/src/main/java/com/nis/web/service/AuditLogThread.java +++ b/src/main/java/com/nis/web/service/AuditLogThread.java @@ -195,7 +195,7 @@ public class AuditLogThread implements Runnable { AuditLogThread thread = new AuditLogThread(); thread.setRemoteAddr(getIpAddr(request)); thread.setRequestURI(request.getRequestURI()); - if (request.getMethod().toLowerCase().equals("get")) { + if (request.getMethod().toLowerCase().equals("get")||request.getMethod().toLowerCase().equals("put")||request.getMethod().toLowerCase().equals("delete")) { thread.setQueryString(request.getQueryString()); thread.setContent(request.getQueryString()); } else { diff --git a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java index b7caa55..d0421c3 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java @@ -43,6 +43,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 用于在实时统计配置后面添加时间,方便读取入库时间
private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
int serviceAndConfigRealDB = Configurations.getIntProperty("serviceAndConfigRealDB", 13);
+
public boolean saveUnMaatConfig(Map<Integer, List<Map<String, String>>> configMap) {
if (configMap != null && configMap.size() > 0) {
int count = 0;
@@ -2272,11 +2273,13 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (idDel) {
String key = "OBSOLETE_RULE:" + service;
transaction.sadd(key, maatKey);// 失效里面加一个,生效里面删除一个
- transaction.srem(key.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"), maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"));
+ transaction.srem(key.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"),
+ maatKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"));
} else {
String key = "EFFECTIVE_RULE:" + service;
transaction.sadd(key, maatKey);// 生效里面加一个,失效里面删一个
- transaction.srem(key.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"), maatKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"));
+ transaction.srem(key.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"),
+ maatKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"));
}
}
transaction.select(redisDBIndex);
@@ -2356,4 +2359,139 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { }
+ @Override
+ public boolean updateMaatConfig(Map<Integer, List<Long>> serviceConfigMap,
+ Map<Integer, List<MaatConfig>> configMap) {
+ if (serviceConfigMap != null && serviceConfigMap.size() > 0&&configMap!=null&&configMap.size()>0) {
+ Jedis resource = null;
+ Transaction transaction =null;
+ try {
+ resource = JedisUtils.getResource(0);
+ transaction = resource.multi();
+ boolean isStart = false;//置为失效
+ int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15);
+ if (serviceConfigMap != null && serviceConfigMap.size() > 0) {
+ for (Integer service : serviceConfigMap.keySet()) {
+ Map<Integer, Set<Long>> compileIdAndDBReal = getCompileIdAndDBReal(
+ serviceConfigMap.get(service), service, idRelaRedisDBIndex);
+ for (Integer redisDb : compileIdAndDBReal.keySet()) {
+ String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb);
+ if (maatVersionStr != null) {
+ Double maatVersion = Double.valueOf(maatVersionStr) + 1D;
+ MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service);
+ Set<Long> list = compileIdAndDBReal.get(redisDb);
+ if (list != null && list.size() > 0) {
+ for (Long id : list) {
+ // 按序号选择Redis数据库
+ transaction.select(redisDb);
+ removeConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb,
+ idRelaRedisDBIndex, isStart);
+ }
+ } else {
+ throw new ServiceRuntimeException("修改配置-删除配置时,未发现对应的配置id信息,请检查配置参数是否正确",
+ RestBusinessCode.ConfigSourceIsNull.getValue());
+ }
+ transaction.incrBy("MAAT_VERSION", 1l);
+ logger.info("修改配置-向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb,
+ Integer.valueOf(maatVersionStr) + 1);
+ } else {
+ throw new ServiceRuntimeException("修改配置-从" + redisDb
+ + "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常",
+ RestBusinessCode.GetMaatVersionFailure.getValue());
+ }
+ }
+ }
+ } else {
+ throw new ServiceRuntimeException("修改配置-删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确",
+ RestBusinessCode.ConfigSourceIsNull.getValue());
+ }
+ if (removeMaatRelation(serviceConfigMap, transaction, isStart)
+ && removeStatisticsReal(serviceConfigMap, transaction, isStart)) {// 先删除成功,再重新下发按配置
+ if (configMap != null && configMap.size() > 0) {
+ int count = 0;
+ Set<Integer> keySet = configMap.keySet();
+ for (Integer redisDBIndex : configMap.keySet()) {
+ if (redisDBIndex >= 0
+ && redisDBIndex < Configurations.getIntProperty("maxRedisDBIndex", 6)) {
+ transaction.select(redisDBIndex);
+ String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDBIndex);
+ if (maatVersionStr == null) {
+ maatVersionStr = "0";
+ }
+ if (maatVersionStr != null) {
+ Double maatVersion = Double.valueOf(maatVersionStr) + 2D;//因为在一个事务中,上面删除获取的MAAT_VERSION+1还没有提交呢,所以这里获取的和上面一样,所以需要加2
+ List<MaatConfig> maatConfigList = configMap.get(redisDBIndex);
+ if (maatConfigList != null && maatConfigList.size() > 0) {
+ for (MaatConfig maatConfig : maatConfigList) {
+ int service = maatConfig.getService();
+ if (ServiceAndRDBIndexReal.isAddASU(service)) {
+ if (!keySet.contains(Constants.TAPREDISDB)) {
+ throw new ServiceRuntimeException(
+ "修改配置-业务类型:" + service + ",需要向阀门" + Constants.TAPREDISDB
+ + "号库分发,但是当前只往" + keySet
+ + "库下发,请检查阀门编号或者当前业务对应的配置文件是否正确",
+ RestBusinessCode.PropertiesIsError.getValue());
+ }
+ }
+
+ MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil
+ .getMaatConfigByService(service);
+ setConfig(maatConfig, maatXmlConfig, maatVersion, service, transaction,
+ redisDBIndex);
+ }
+ transaction.select(redisDBIndex);
+ transaction.incrBy("MAAT_VERSION", 1l);
+ logger.info("修改配置-向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDBIndex,
+ Integer.valueOf(maatVersionStr) + 1);
+ count++;
+ } else {
+ throw new ServiceRuntimeException(
+ "修改配置-向" + redisDBIndex + "号redis库中添加配置时,未发现对应的配置信息,请检查配置参数是否正确",
+ RestBusinessCode.ConfigSourceIsNull.getValue());
+ }
+ }
+ } else {
+ throw new ServiceRuntimeException("修改配置-redis数据库编号:" + redisDBIndex + "不正确,请检查数据库编号",
+ RestBusinessCode.DbIndexNotInRange.getValue());
+ }
+ }
+ if (count == configMap.size()) {
+ addMaatRelation(configMap, transaction);
+ addStatisticsReal(configMap, transaction);
+ transaction.exec();
+ return true;
+ } else {
+ transaction.discard();
+ }
+ }else {
+ transaction.discard();//没有需要新增的配置,取消已经删除的配置
+ }
+ } else {
+ transaction.discard();
+ }
+ } catch (JedisConnectionException e) {
+ String error = "连接redis异常,修改maat配置失败," + e.getMessage();
+ logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
+ throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
+
+ } catch (Exception e) {
+ int businessCode = RestBusinessCode.service_runtime_error.getValue();
+ if (e instanceof ServiceRuntimeException) {
+ businessCode = ((ServiceRuntimeException) e).getErrorCode();
+ }
+ logger.error("修改maat配置发生了异常" + ExceptionUtil.getExceptionMsg(e));
+ if(transaction!=null) {
+ transaction.discard();
+ }
+ throw new ServiceRuntimeException("修改maat配置发生了异常," + e.getMessage(), businessCode);
+ } finally {
+ // 释放连接到连接池
+ JedisUtils.returnResource(resource);
+ }
+ } else {
+ throw new ServiceRuntimeException("Map参数信息不能为空,请检查!", RestBusinessCode.ConfigInfoMapIsNull.getValue());
+ }
+ return false;
+ }
+
}
diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java index 46244c6..8108d8e 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java @@ -38,6 +38,16 @@ public interface ConfigRedisService { */
public boolean saveMaatConfig(Map<Integer, List<MaatConfig>> configMap);
+
+
+ /**
+ * 修改配置内容(先失效配置,然后在重新下发配置)
+ * @param serviceConfigMap 需要删除的maat类配置,key是业务类型,value是配置id集合
+ * @param configMap 需要新增的配置(修改)
+ * @return
+ */
+ public boolean updateMaatConfig(Map<Integer, List<Long>> serviceConfigMap,Map<Integer, List<MaatConfig>> configMap);
+
/**
* 分组复用域配置新增接口,value是配置集合
*
diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index 3881f6f..ab1c056 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -8,23 +8,13 @@ import java.text.SimpleDateFormat; import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import net.sf.json.JSONObject;
-import redis.clients.jedis.Jedis;
-import redis.clients.jedis.JedisCluster;
-import redis.clients.jedis.JedisPool;
-import redis.clients.jedis.JedisPoolConfig;
-import redis.clients.jedis.ScanParams;
-import redis.clients.jedis.ScanResult;
-
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@@ -54,12 +44,17 @@ import com.nis.util.JedisUtils; import com.nis.util.JsonMapper;
import com.nis.util.ReadCommSourceXmlUtil;
import com.nis.util.ServiceAndRDBIndexReal;
-import com.zdjizhi.utils.StringUtil;
-
-import it.unimi.dsi.fastutil.Hash;
-
import com.nis.web.service.AuditLogThread;
import com.nis.web.service.BaseService;
+import com.zdjizhi.utils.StringUtil;
+
+import net.sf.json.JSONObject;
+import redis.clients.jedis.Jedis;
+import redis.clients.jedis.JedisCluster;
+import redis.clients.jedis.ScanParams;
+import redis.clients.jedis.ScanResult;
+import redis.clients.jedis.Transaction;
+import redis.clients.jedis.exceptions.JedisConnectionException;
/**
* @ClassName: ControlService
@@ -124,20 +119,34 @@ public class ConfigSourcesService extends BaseService { }
/**
+ * 修改配置内容,直接利用的之前的删除和新增方法
*
- * @Description:
- * @author (zdx)
- * @date 2018年5月25日 下午3:49:46
* @param thread
* @param start
* @param configCompileList
* @param sb
+ * @throws Exception
+ */
+ public void updateMaatConfig(AuditLogThread thread, long start, List<ConfigCompile> configCompileList,
+ StringBuffer sb) throws Exception {
+ Map<Integer, List<MaatConfig>> configMap = saveConfig(thread, configCompileList, sb);
+ Map<Integer, List<Long>> compileMap = updateConfigStatus(thread, configCompileList, new Date(), sb);
+ configRedisService.updateMaatConfig(compileMap, configMap);
+
+ }
+
+ /**
+ * 封装下发配置的map,供下发和配置修改使用
+ *
+ * @param thread
+ * @param configCompileList
+ * @param sb
* @return
+ * @throws Exception
*/
- public void saveMaatConfig(AuditLogThread thread, long start, List<ConfigCompile> configCompileList,
+ public Map<Integer, List<MaatConfig>> saveConfig(AuditLogThread thread, List<ConfigCompile> configCompileList,
StringBuffer sb) throws Exception {
- long currentTimeMillis = System.currentTimeMillis();
Map<Integer, List<MaatConfig>> maatMap = new HashMap<Integer, List<MaatConfig>>();
Map<Integer, List<MaatConfig>> configMap = new HashMap<Integer, List<MaatConfig>>();
@@ -271,8 +280,25 @@ public class ConfigSourcesService extends BaseService { RestBusinessCode.ServiceNoFoundDBIndex.getValue());
}
}
- logger.info("---------------调用Redis maat配置新增接口---------------------");
+ return configMap;
+ }
+ /**
+ *
+ * @Description: 新增maat配置接口
+ * @author (zdx)
+ * @date 2018年5月25日 下午3:49:46
+ * @param thread
+ * @param start
+ * @param configCompileList
+ * @param sb
+ * @return
+ */
+ public void saveMaatConfig(AuditLogThread thread, long start, List<ConfigCompile> configCompileList,
+ StringBuffer sb) throws Exception {
+ long currentTimeMillis = System.currentTimeMillis();
+ Map<Integer, List<MaatConfig>> configMap = saveConfig(thread, configCompileList, sb);
+ logger.info("---------------调用Redis maat配置新增接口---------------------");
long end = System.currentTimeMillis();
logger.warn("执行ConfigSourcesService.saveMaatConfig用时{}毫秒", end - currentTimeMillis);
configRedisService.saveMaatConfig(configMap);
@@ -334,8 +360,8 @@ public class ConfigSourcesService extends BaseService { }
/**
- * @Description:
- * @author(zdx) @date 2018年12月3日 下午6:48:32
+ * 配置全量同步使用的下发接口,在SyncAllConfigTask.addConfigToRedis()中使用
+ *
* @param configCompileList
* @throws Exception
*/
@@ -536,8 +562,8 @@ public class ConfigSourcesService extends BaseService { return dstMap;
}
- public void updateConfigSources(AuditLogThread thread, long start, List<ConfigCompile> compileList, Date opTime,
- StringBuffer sb, boolean isConfigStartStop) throws Exception {
+ public Map<Integer, List<Long>> updateConfigStatus(AuditLogThread thread, List<ConfigCompile> compileList,
+ Date opTime, StringBuffer sb/* , boolean isConfigStartStop */) throws Exception {
// 所有状态更新的配置isValid的值必须相同
Map<String, String> validIdMap = new HashMap<String, String>();
@@ -547,7 +573,7 @@ public class ConfigSourcesService extends BaseService { }
if (null != compileList && compileList.size() > 0) {
for (ConfigCompile config : compileList) {
- checkCompileOptForUpdate(config, isConfigStartStop);
+ checkCompileOptForUpdate(config);
validIdMap.put(config.getIsValid().toString(), config.getIsValid().toString());
if (config.getOpTime() == null) {
config.setOpTime(opTime);
@@ -571,24 +597,30 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException(RestBusinessCode.IsValidNonUniq.getErrorReason(),
RestBusinessCode.IsValidNonUniq.getValue());
}
+ return compileMap;
+ }
- if (!isConfigStartStop) {
- // 所有的都删除成功返回true
- if (!configRedisService.delMaatConfig(compileMap, false)) {
- throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员",
- RestBusinessCode.service_runtime_error.getValue());
- }
- } else {
- boolean isStart = true;// 置为生效
- Integer isValid = compileList.get(0).getIsValid();
- if (isValid == 0) {
- isStart = false;// 置为失效
- }
- if (!configRedisService.delMaatConfig(compileMap, isStart)) {
- throw new ServiceRuntimeException("停启用MAAT配置时出现异常,具体原因不详,请联系管理员",
- RestBusinessCode.service_runtime_error.getValue());
- }
-
+ /**
+ *
+ * @param thread
+ * @param start
+ * @param compileList
+ * @param opTime
+ * @param sb
+ * @param isConfigStartStop
+ * @throws Exception
+ */
+ public void updateConfigStatus(AuditLogThread thread, long start, List<ConfigCompile> compileList, Date opTime,
+ StringBuffer sb) throws Exception {
+ Map<Integer, List<Long>> compileMap = updateConfigStatus(thread, compileList, opTime, sb);
+ boolean isStart = true;// 置为生效
+ Integer isValid = compileList.get(0).getIsValid();// 上面会校验所有的isValid是否相同
+ if (isValid == 0) {
+ isStart = false;// 置为失效
+ }
+ if (!configRedisService.delMaatConfig(compileMap, isStart)) {
+ throw new ServiceRuntimeException("停启用MAAT配置时出现异常,具体原因不详,请联系管理员",
+ RestBusinessCode.service_runtime_error.getValue());
}
}
@@ -605,7 +637,7 @@ public class ConfigSourcesService extends BaseService { * @param config
* @return
*/
- private void checkCompileOptForUpdate(ConfigCompile config, boolean isConfigStartStop) throws Exception {
+ private void checkCompileOptForUpdate(ConfigCompile config) throws Exception {
if (StringUtil.isEmpty(config.getCompileId())) {
throw new RestServiceException(RestBusinessCode.CompileIdIsNull.getErrorReason(),
@@ -619,12 +651,9 @@ public class ConfigSourcesService extends BaseService { throw new RestServiceException("编译配置id为" + config.getCompileId() + "的IsValid字段不能为空",
RestBusinessCode.IsValidIsNull.getValue());
}
-
- if (!isConfigStartStop) {
- if (config.getIsValid() != 0) {
- throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置在修改时不能为有效",
- RestBusinessCode.IsValidIsF.getValue());
- }
+ if (config.getIsValid() != 0 && config.getIsValid() != 1) {
+ throw new RestServiceException("编译配置id为" + config.getCompileId() + "的配置状态只能是0或1",
+ RestBusinessCode.IsValidIsF.getValue());
}
}
@@ -1397,29 +1426,54 @@ public class ConfigSourcesService extends BaseService { effectiveMap = getAllServiceAndConfigMap(resource, "EFFECTIVE_RULE:*");
obsuleteMap = getAllServiceAndConfigMap(resource, "OBSOLETE_RULE:*");
} else {
- effectiveMap = getServiceAndConfigMap(resource, "EFFECTIVE_RULE:"+service);
- obsuleteMap = getServiceAndConfigMap(resource, "OBSOLETE_RULE:"+service);
+ effectiveMap = getServiceAndConfigMap(resource, "EFFECTIVE_RULE:" + service);
+ obsuleteMap = getServiceAndConfigMap(resource, "OBSOLETE_RULE:" + service);
}
map.put("effective", effectiveMap);
- int effectiveCount=0;
+ int effectiveCount = 0;
for (Integer key : effectiveMap.keySet()) {
- effectiveCount+=effectiveMap.get(key).size();
+ effectiveCount += effectiveMap.get(key).size();
}
map.put("effectiveCount", effectiveCount);
map.put("obsolete", obsuleteMap);
- int obsoleteCount=0;
+ int obsoleteCount = 0;
for (Integer key : obsuleteMap.keySet()) {
- obsoleteCount+=obsuleteMap.get(key).size();
+ obsoleteCount += obsuleteMap.get(key).size();
}
- map.put("obsoleteCount",obsoleteCount);
+ map.put("obsoleteCount", obsoleteCount);
JedisUtils.returnBrokenResource(resource);
} catch (Exception e) {
- logger.error("获取有效无效的配置信息失败,失败原因{}",ExceptionUtil.getExceptionMsg(e));
+ logger.error("获取有效无效的配置信息失败,失败原因{}", ExceptionUtil.getExceptionMsg(e));
throw new RestServiceException("获取有效无效的配置信息失败", RestBusinessCode.syncStatusFailed.getValue());
}
return map;
}
+ public boolean delAllConfig() {
+ Jedis resource = JedisUtils.getResource(0);
+ Transaction transaction = resource.multi();
+ try {
+ for (int i = 1; i < 16; i++) {
+ transaction.select(i);
+ transaction.flushDB();
+ }
+ transaction.exec();
+ return true;
+ } catch (JedisConnectionException e) {
+ String error = "连接redis异常,删除所有的配置失败," + e.getMessage();
+ logger.error(error + " " + ExceptionUtil.getExceptionMsg(e));
+ throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue());
+
+ } catch (Exception e) {
+ logger.error("删除所有的配置信息失败,失败原因{}", ExceptionUtil.getExceptionMsg(e));
+ transaction.discard();
+ throw new RestServiceException("删除所有的配置信息失败", RestBusinessCode.unknow_error.getValue());
+ } finally {
+ // 释放连接到连接池
+ JedisUtils.returnResource(resource);
+ }
+ }
+
private Map<Integer, List<String>> getAllServiceAndConfigMap(Jedis resource, String keys) {
Map<Integer, List<String>> effectiveMap = new HashMap<>();
Set<String> effectiveKeys = resource.keys(keys);
diff --git a/src/main/java/com/nis/web/service/restful/TrafficReportService.java b/src/main/java/com/nis/web/service/restful/TrafficReportService.java index 437a320..eba0906 100644 --- a/src/main/java/com/nis/web/service/restful/TrafficReportService.java +++ b/src/main/java/com/nis/web/service/restful/TrafficReportService.java @@ -2,21 +2,22 @@ package com.nis.web.service.restful; import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Date;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.nis.domain.Page;
import com.nis.domain.restful.NtcRadiusReport;
-import com.nis.domain.restful.dashboard.TrafficTransStatistic;
+import com.nis.domain.restful.dashboard.TrafficTransStatisticCK;
+import com.nis.util.DateUtils;
import com.nis.web.dao.TrafficReportDao;
-import com.nis.web.dao.dashboard.NtcTotalReportDao;
import com.nis.web.service.BaseLogService;
@Service
@@ -70,162 +71,127 @@ public class TrafficReportService extends BaseLogService { }
/**
- * 根据ip46,协议tcp,udp查询带宽
+ * 查询bps/pps/linnum在ip46,tcp,udp的统计数据
*
- * @param addrType
- * @param transType
+ * @param beginDate
+ * @param endDate
+ * @param searchQuotaType bps,pps,linknum
+ * @param searchDirection
* @return
*/
- public List<HashMap> getBandwidthTrans(String addrType, Integer transType, String beginDate, String endDate) {
- ArrayList<HashMap> listMap = new ArrayList<HashMap>();
-
- HashMap m1 = getBandwidthTransEntrance(addrType, transType, beginDate, endDate, 1);
- if (m1 != null && m1.size() > 0) {
- m1.put("entranceId", 1);// 局点1.2 不同来源
- listMap.add(m1);
+ public Map<?, ?> getBandwidthTransByQuoTaType(TrafficTransStatisticCK trafficTransStatisticCK) {
+ List<TrafficTransStatisticCK> list = null;
+ List<Long> timeList = null;
+ Integer searchBusinessType = trafficTransStatisticCK.getSearchBusinessType();
+ if (searchBusinessType == 1) {
+ timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
+ trafficTransStatisticCK.getEndDate(), 0);
+ } else if (searchBusinessType == 2) {
+ timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
+ trafficTransStatisticCK.getEndDate(), 1);
+ } else if (searchBusinessType == 3) {
+ timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
+ trafficTransStatisticCK.getEndDate(), 2);
+ } else if (searchBusinessType == 4) {
+ timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
+ trafficTransStatisticCK.getEndDate(), 3);
+ } else if (searchBusinessType == 5) {
+ timeList = DateUtils.getTimeInterval(trafficTransStatisticCK.getBeginDate(),
+ trafficTransStatisticCK.getEndDate(), 4);
}
- return listMap;
-
- }
-
- /**
- * 根据ip46,协议tcp,udp查询带宽
- *
- * @param addrType
- * @param transType
- * @return
- */
- public List<HashMap> getBandwidthTrans2(String addrType, Integer transType, String beginDate, String endDate) {
- ArrayList<HashMap> listMap = new ArrayList<HashMap>();
-
- HashMap m2 = getBandwidthTransEntrance(addrType, transType, beginDate, endDate, 2);
- if (m2 != null && m2.size() > 0) {
- m2.put("entranceId", 2);
- listMap.add(m2);
+ if (trafficTransStatisticCK.getSearchQuotaType() == 1) {
+ list = trafficReportDao.getBandwidthBpsFromCk(trafficTransStatisticCK);
+ } else if (trafficTransStatisticCK.getSearchQuotaType() == 2) {
+ list = trafficReportDao.getBandwidthPpsFromCk(trafficTransStatisticCK);
+ } else if (trafficTransStatisticCK.getSearchQuotaType() == 3) {
+ list = trafficReportDao.getBandwidthLinkNumFromCk(trafficTransStatisticCK);
}
- return listMap;
+ Map<?, ?> map = convertData2List(list, timeList, searchBusinessType);
+ return map;
}
- public static void main(String[] args) {
-// long a = Long.parseLong("123.3");
- Long.valueOf("123.3");
-
-// long b = Long.parseLong("123.3",1);
-
- long c = Long.valueOf("123.3").longValue();
- }
+ private Map<?, ?> convertData2List(List<TrafficTransStatisticCK> list, List<Long> timeList,
+ Integer searchBusinessType) {
+ Map<String, List<TrafficTransStatisticCK>> mapList = new HashMap<>();
+ Map<String, Map<String, Object>> map = new HashMap<>();
+ if (list != null) {
+ Set<String> dataKey = new HashSet<>();//无论有没有数据都要组装这几个json,界面需要这几个数据
+ dataKey.add("ipv4Type1");//ip只有4,6两种,协议只有tcp和udp,这里都写死了
+ dataKey.add("ipv4Type2");
+ dataKey.add("ipv6Type1");
+ dataKey.add("ipv6Type2");
+
+ dataKey.add("trans6Type1");
+ dataKey.add("trans6Type2");
+ dataKey.add("trans17Type1");
+ dataKey.add("trans17Type2");
+
+ for (TrafficTransStatisticCK trafficTransStatisticCK : list) {
+ Integer entranceId = trafficTransStatisticCK.getEntranceId();
+ Integer addrType = trafficTransStatisticCK.getAddrType();
+ Integer transType = trafficTransStatisticCK.getTransType();
+ String addrAndEntrKey = "ipv" + addrType + "Type" + entranceId;
+ String transAndEntrKey = "trans" + transType + "Type" + entranceId;
+
+ if (mapList.containsKey(addrAndEntrKey)) {
+ mapList.get(addrAndEntrKey).add(trafficTransStatisticCK);
+ } else {
+ List<TrafficTransStatisticCK> transList = new ArrayList<>();
+ transList.add(trafficTransStatisticCK);
+ mapList.put(addrAndEntrKey, transList);
+ }
- /**
- * 查询单个局点流量的数据信息
- *
- * @param addrType
- * @param transType
- * @param beginDate
- * @param endDate
- * @param entranceId
- * @return
- */
- public HashMap getBandwidthTransEntrance(String addrType, Integer transType, String beginDate, String endDate,
- Integer entranceId) {
- long start = System.currentTimeMillis();
- ArrayList<HashMap> listMap = new ArrayList<HashMap>();
- List<TrafficTransStatistic> bandwidthList = new ArrayList<TrafficTransStatistic>();
- HashMap resulMap = new HashMap();
- bandwidthList = trafficReportDao.getBandwidthTrans(entranceId, beginDate, endDate, addrType, transType);
- List timeList = new ArrayList();
- List linkList = new ArrayList();
- List gbpsList = new ArrayList();
- List ppsList = new ArrayList();
- if (bandwidthList != null && bandwidthList.size() > 0) {
- Map<String, Comparable> m = new HashMap<String, Comparable>();
- int inter = 1000 * 60 * 5;// 间隔时间为五分钟
- // 开始时间,结束时间 时间戳
- Long b = dateToStamp(beginDate);
- Long e = dateToStamp(endDate);
- int num = 0;
- Long pointTime = b;
- while (pointTime < e) {
- Map rm = new HashMap();
- Long sumL = 0l;
- Long sumP = 0l;
- Long sumG = 0l;
- if (pointTime >= e) {
- break; // 停止
+ if (mapList.containsKey(transAndEntrKey)) {
+ mapList.get(transAndEntrKey).add(trafficTransStatisticCK);
+ } else {
+ List<TrafficTransStatisticCK> transList = new ArrayList<>();
+ transList.add(trafficTransStatisticCK);
+ mapList.put(transAndEntrKey, transList);
}
- for (TrafficTransStatistic tt : bandwidthList) {
- // 实际时间
- String time = tt.getTime();
- Long t = dateToStamp(time);
- if (t >= pointTime && t < pointTime + inter) {
- // 范围之内分到此pointTime组
- sumL = sumL + tt.getLinkNum();
- sumP = sumP +Long.parseLong(
- tt.getPps().substring(0,tt.getPps().lastIndexOf(".")));
- sumG = sumG +
- Long.parseLong(
- tt.getGbps().substring(0,tt.getGbps().lastIndexOf(".")));
+ }
+ for (String key : dataKey) {//无论这8种key是否都查询出了数据,都要给界面提供每个时间点的数据
+ Map<Long, Long> timeAndNum = new TreeMap<>();
+ Long count = 0l;
+ for (Long time : timeList) {
+ long num = 0l;
+ List<TrafficTransStatisticCK> list2 = mapList.get(key);
+ if (list2 != null && list2.size() > 0) {
+ for (TrafficTransStatisticCK trafficTransStatisticCK : list2) {
+ long transTime = trafficTransStatisticCK.getStatTime().getTime();
+ if (searchBusinessType == 1) {// 五分钟不需要转换了,时间已经是五分钟的格式了
+// transTime = DateUtils.getTimeByType(transTime, 0);//
+ } else if (searchBusinessType == 2) {
+ transTime = DateUtils.getTimeByType(transTime, 1);
+ } else if (searchBusinessType == 3) {
+ transTime = DateUtils.getTimeByType(transTime, 2);
+ } else if (searchBusinessType == 4) {
+ transTime = DateUtils.getTimeByType(transTime, 3);
+ } else if (searchBusinessType == 5) {
+ transTime = DateUtils.getTimeByType(transTime, 4);
+ }
+ if (transTime == time) {
+ num += trafficTransStatisticCK.getNum().longValue();
+ count += trafficTransStatisticCK.getNum().longValue();
+ }
+ }
}
+ timeAndNum.put(time, num);
}
- // 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会
- if (pointTime >= e - inter && sumL > 0) {
- linkList.add(sumL);
- }
- if (pointTime >= e - inter && sumP > 0) {
- ppsList.add(sumP);
- }
- if (pointTime >= e - inter && sumG > 0) {
- gbpsList.add(sumG);
- }
- if (pointTime >= e - inter && (sumL > 0 || sumG > 0 || sumP > 0)) {
- timeList.add(stampToDate(pointTime));
+ Map<String, Object> resultMap = new HashMap<>();
+ List<List<Long>> restList = new ArrayList<List<Long>>();
+ for (Long timeKey : timeAndNum.keySet()) {
+ List<Long> dataList = new ArrayList<>();
+ dataList.add(timeKey);
+ dataList.add(timeAndNum.get(timeKey));
+ restList.add(dataList);
}
- if (pointTime < e - inter) {
- timeList.add(stampToDate(pointTime));
- linkList.add(sumL);
- gbpsList.add(sumG);
- ppsList.add(sumP);
- }
-
- num = num + 1;
- pointTime = b + inter * num;
+ resultMap.put("result", restList);
+ resultMap.put("sum", count);
+ map.put(key, resultMap);
}
- resulMap.put("linkNum", linkList);
- resulMap.put("gbps", gbpsList);
- resulMap.put("pps", ppsList);
- resulMap.put("statTime", timeList);
- }
- return resulMap;
- }
-
- /**
- * 时间戳 换成日期格式字符串转
- *
- * @param 时间 1544602212000
- * @param format 如:yyyy-MM-dd HH:mm:ss
- * @return
- */
- public static String stampToDate(long timeStamp) {
- SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");// 这个是你要转成后的时间的格式
- String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间
- return sd;
- }
-
- /**
- * 日期格式字符串转换成时间戳
- *
- * @param date 字符串日期
- * @param format 如:yyyy-MM-dd HH:mm:ss
- * @return
- */
- public static Long dateToStamp(String date_str) {
- try {
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- return sdf.parse(date_str).getTime();
- } catch (Exception e) {
- e.printStackTrace();
}
- return 0l;
+ return map;
}
}
|
