测试环境配置、新增mtr探测丢包率结果存储方法
This commit is contained in:
@@ -71,6 +71,8 @@ public enum MsgEnum {
|
||||
|
||||
Agent版本更新("AGENT_VERSION_UPDATE"),
|
||||
|
||||
MTR探测上报("MTR_DETECT"),
|
||||
|
||||
Agent版本更新应答("AGENT_VERSION_UPDATE_RSP");
|
||||
|
||||
private String value;
|
||||
|
||||
+17
@@ -6,6 +6,7 @@ import java.lang.management.ManagementFactory;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.*;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
@@ -43,6 +44,22 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
|
||||
Date now = calendar.getTime();
|
||||
return now;
|
||||
}
|
||||
/**
|
||||
* 获取今天的时间范围数组
|
||||
* 返回:String[2] {开始时间, 结束时间}
|
||||
* 格式:["2024-01-15 00:00:00", "2024-01-15 23:59:59"]
|
||||
*/
|
||||
public static String[] getTodayTimeRange() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
LocalDateTime startOfDay = now.with(LocalTime.MIN);
|
||||
LocalDateTime endOfDay = now.with(LocalTime.MAX);
|
||||
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
return new String[] {
|
||||
startOfDay.format(formatter),
|
||||
endOfDay.format(formatter)
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期, 默认格式为yyyy-MM-dd
|
||||
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
package com.ruoyi.common.core.utils;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class TableSubUtil {
|
||||
|
||||
// 日期格式
|
||||
private static final String YEAR_MONTH_FORMAT = "yyyy_MM";
|
||||
private static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
/**
|
||||
* 根据创建时间获取表名
|
||||
* @param createTime 记录创建时间
|
||||
* @param prefix 表名前缀
|
||||
* @return 对应的分表名称
|
||||
* @throws IllegalArgumentException 如果createTime为null
|
||||
*
|
||||
* 示例:
|
||||
* 2023-08-05 14:30:00 → rm_mtr_probe_result_2023_08_01_10
|
||||
* 2023-08-15 09:15:00 → rm_mtr_probe_result_2023_08_11_20
|
||||
* 2023-08-25 18:45:00 → rm_mtr_probe_result_2023_08_21_31
|
||||
*/
|
||||
public static String getTableName(Date createTime, String prefix) {
|
||||
if (createTime == null) {
|
||||
throw new IllegalArgumentException("创建时间不能为null");
|
||||
}
|
||||
|
||||
SimpleDateFormat yearMonthFormat = new SimpleDateFormat(YEAR_MONTH_FORMAT);
|
||||
String yearMonth = yearMonthFormat.format(createTime);
|
||||
|
||||
SimpleDateFormat dayFormat = new SimpleDateFormat("dd");
|
||||
int day = Integer.parseInt(dayFormat.format(createTime));
|
||||
|
||||
return String.format("%s_%s_%s",
|
||||
prefix,
|
||||
yearMonth,
|
||||
getDayRange(day));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间范围内涉及的所有表名
|
||||
* @param startTime 开始时间 (格式: "yyyy-MM-dd HH:mm:ss")
|
||||
* @param endTime 结束时间 (格式: "yyyy-MM-dd HH:mm:ss")
|
||||
* @param prefix 表名前缀
|
||||
* @return 按时间顺序排列的表名集合
|
||||
*/
|
||||
public static Set<String> getTableNamesBetween(String startTime, String endTime, String prefix) {
|
||||
Date start = parseDateTime(startTime);
|
||||
Date end = parseDateTime(endTime);
|
||||
validateTimeRange(start, end);
|
||||
|
||||
Set<String> tableNames = new LinkedHashSet<>();
|
||||
|
||||
// 使用java.util.Calendar进行日期操作
|
||||
java.util.Calendar current = java.util.Calendar.getInstance();
|
||||
current.setTime(start);
|
||||
current.set(java.util.Calendar.HOUR_OF_DAY, 0);
|
||||
current.set(java.util.Calendar.MINUTE, 0);
|
||||
current.set(java.util.Calendar.SECOND, 0);
|
||||
current.set(java.util.Calendar.MILLISECOND, 0);
|
||||
|
||||
java.util.Calendar endCal = java.util.Calendar.getInstance();
|
||||
endCal.setTime(end);
|
||||
|
||||
while (!current.after(endCal)) {
|
||||
tableNames.add(getTableName(current.getTime(), prefix));
|
||||
current.add(java.util.Calendar.DAY_OF_MONTH, 1);
|
||||
}
|
||||
|
||||
return tableNames;
|
||||
}
|
||||
|
||||
// 解析字符串为Date
|
||||
private static Date parseDateTime(String dateTimeStr) {
|
||||
if (dateTimeStr == null || dateTimeStr.trim().isEmpty()) {
|
||||
throw new IllegalArgumentException("时间字符串不能为空");
|
||||
}
|
||||
try {
|
||||
SimpleDateFormat format = new SimpleDateFormat(DATE_TIME_FORMAT);
|
||||
return format.parse(dateTimeStr);
|
||||
} catch (ParseException e) {
|
||||
throw new IllegalArgumentException("时间格式必须为: yyyy-MM-dd HH:mm:ss", e);
|
||||
}
|
||||
}
|
||||
|
||||
// 获取日期区间
|
||||
private static String getDayRange(int day) {
|
||||
if (day < 1 || day > 31) {
|
||||
throw new IllegalArgumentException("日期必须在1-31之间");
|
||||
}
|
||||
|
||||
if (day <= 10) return "01_10";
|
||||
if (day <= 20) return "11_20";
|
||||
return "21_31";
|
||||
}
|
||||
|
||||
// 验证时间范围
|
||||
private static void validateTimeRange(Date start, Date end) {
|
||||
if (start == null || end == null) {
|
||||
throw new IllegalArgumentException("时间范围参数不能为null");
|
||||
}
|
||||
if (start.after(end)) {
|
||||
throw new IllegalArgumentException("开始时间不能晚于结束时间");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user