初始流量数据库读取mq入库
This commit is contained in:
+1
@@ -22,4 +22,5 @@ public class TableScheduleConfig {
|
||||
public void createNextMonthTables() {
|
||||
epsInitialTrafficDataService.createNextMonthTables();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+12
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.common.core.web.page.TableDataInfo;
|
||||
import com.ruoyi.common.log.annotation.Log;
|
||||
import com.ruoyi.common.log.enums.BusinessType;
|
||||
import com.ruoyi.common.security.annotation.InnerAuth;
|
||||
import com.ruoyi.common.security.annotation.RequiresPermissions;
|
||||
import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
|
||||
@@ -70,4 +71,15 @@ public class EpsServerRevenueConfigController extends BaseController
|
||||
return toAjax(epsServerRevenueConfigService.updateEpsServerRevenueConfig(epsServerRevenueConfig));
|
||||
}
|
||||
|
||||
/**
|
||||
* 流量相关数据入库
|
||||
*/
|
||||
@Log(title = "流量相关数据入库", businessType = BusinessType.EXPORT)
|
||||
@InnerAuth
|
||||
@PostMapping("/autoSaveServiceTrafficData")
|
||||
public void autoSaveServiceTrafficData(@RequestBody EpsServerRevenueConfig epsServerRevenueConfig)
|
||||
{
|
||||
epsServerRevenueConfigService.autoSaveServiceTrafficData(epsServerRevenueConfig);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+70
-26
@@ -1,8 +1,10 @@
|
||||
package com.ruoyi.system.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,15 +15,82 @@ import java.util.List;
|
||||
*/
|
||||
@Data
|
||||
public class EpsInitialTrafficData {
|
||||
/** 主键ID */
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/** 唯一标识ID */
|
||||
private Long id;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
private String interfaceName;
|
||||
|
||||
/** MAC地址 */
|
||||
@Excel(name = "MAC地址")
|
||||
private String macAddress;
|
||||
|
||||
/** 运行状态 */
|
||||
@Excel(name = "运行状态")
|
||||
private String operationStatus;
|
||||
|
||||
/** 接口类型 */
|
||||
@Excel(name = "接口类型")
|
||||
private String interfaceType;
|
||||
|
||||
/** IPv4地址 */
|
||||
@Excel(name = "IPv4地址")
|
||||
private String ipv4Address;
|
||||
|
||||
/** 入站丢包率(%) */
|
||||
@Excel(name = "入站丢包率(%)")
|
||||
private BigDecimal inboundPacketLoss;
|
||||
|
||||
/** 出站丢包率(%) */
|
||||
@Excel(name = "出站丢包率(%)")
|
||||
private BigDecimal outboundPacketLoss;
|
||||
|
||||
/** 接收带宽(Mbps) */
|
||||
@Excel(name = "接收带宽(Mbps)")
|
||||
private BigDecimal receiveBandwidth;
|
||||
|
||||
/** 发送带宽(Mbps) */
|
||||
@Excel(name = "发送带宽(Mbps)")
|
||||
private BigDecimal sendBandwidth;
|
||||
|
||||
/** 业务代码 */
|
||||
@Excel(name = "业务代码")
|
||||
private String businessId;
|
||||
|
||||
/** 业务名称 */
|
||||
@Excel(name = "业务名称")
|
||||
private String businessName;
|
||||
|
||||
/** 服务器SN */
|
||||
@Excel(name = "服务器SN")
|
||||
private String serviceSn;
|
||||
|
||||
/** 服务器名称 */
|
||||
@Excel(name = "服务器名称")
|
||||
private String nodeName;
|
||||
|
||||
/** 收益方式(1.流量,2包端) */
|
||||
@Excel(name = "收益方式(1.流量,2包端)")
|
||||
private String revenueMethod;
|
||||
|
||||
/** 包端带宽值 */
|
||||
@Excel(name = "包端带宽值")
|
||||
private BigDecimal packageBandwidth;
|
||||
|
||||
/** 批量插入集合 **/
|
||||
private List<EpsInitialTrafficData> dataList;
|
||||
/**
|
||||
* 动态表名
|
||||
* 格式:eps_traffic_[年]_[月]_[日期范围]
|
||||
* 示例:eps_traffic_2023_08_1_10
|
||||
*/
|
||||
private String tableName;
|
||||
/** 设备唯一标识 */
|
||||
private String clientId;
|
||||
|
||||
/** 流量统计开始时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@@ -31,36 +100,11 @@ public class EpsInitialTrafficData {
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime endTime;
|
||||
|
||||
/** 接收流量(单位:MB) */
|
||||
private Double receiveTraffic;
|
||||
|
||||
/** 发送流量(单位:MB) */
|
||||
private Double sendTraffic;
|
||||
|
||||
/** 设备序列号 */
|
||||
private String deviceSn;
|
||||
/** 流量端口 */
|
||||
private String trafficPort;
|
||||
/** 业务代码 */
|
||||
private String businesId;
|
||||
|
||||
/** 数据创建时间 */
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/** 备用字段1 */
|
||||
private String remark1;
|
||||
|
||||
/** 备用字段2 */
|
||||
private String remark2;
|
||||
|
||||
/** 备用字段3 */
|
||||
private String remark3;
|
||||
|
||||
/** 备用字段4 */
|
||||
private String remark4;
|
||||
/** 批量插入集合 **/
|
||||
private List<EpsInitialTrafficData> dataList;
|
||||
|
||||
|
||||
}
|
||||
+7
@@ -34,4 +34,11 @@ public interface EpsInitialTrafficDataMapper {
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
List<EpsInitialTrafficData> selectByCondition(EpsInitialTrafficData condition);
|
||||
/**
|
||||
* 查询初始流量信息
|
||||
* @param condition 查询条件实体
|
||||
* @return 初始流量数据列表
|
||||
*/
|
||||
List<EpsInitialTrafficData> getAllTraficMsg(EpsInitialTrafficData condition);
|
||||
|
||||
}
|
||||
|
||||
+9
@@ -4,6 +4,7 @@ import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务器收益方式配置Mapper接口
|
||||
@@ -68,4 +69,12 @@ public interface EpsServerRevenueConfigMapper
|
||||
* @return 数据条数
|
||||
*/
|
||||
public int countBySn(@Param("hardwareSn") String hardwareSn);
|
||||
|
||||
/**
|
||||
* 查询服务器信息
|
||||
*
|
||||
* @param ipAddress ipv4地址
|
||||
* @return 服务器收益方式配置
|
||||
*/
|
||||
public Map getNodeMsgByIp(@Param("ipAddress") String ipAddress);
|
||||
}
|
||||
|
||||
+6
@@ -33,5 +33,11 @@ public interface EpsInitialTrafficDataService {
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
List<EpsInitialTrafficData> query(EpsInitialTrafficData queryParam);
|
||||
/**
|
||||
* 查询初始流量信息
|
||||
* @param queryParam 查询参数实体
|
||||
* @return 初始流量数据列表
|
||||
*/
|
||||
List<EpsInitialTrafficData> getAllTraficMsg(EpsInitialTrafficData queryParam);
|
||||
|
||||
}
|
||||
|
||||
+9
-1
@@ -1,8 +1,9 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 服务器收益方式配置Service接口
|
||||
*
|
||||
@@ -58,4 +59,11 @@ public interface IEpsServerRevenueConfigService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEpsServerRevenueConfigById(Long id);
|
||||
|
||||
/**
|
||||
* 保存业务相关流量表
|
||||
* 每5分钟自动执行
|
||||
* @param epsServerRevenueConfig
|
||||
*/
|
||||
void autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig);
|
||||
}
|
||||
|
||||
+24
-3
@@ -151,14 +151,35 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
.flatMap(tableName -> {
|
||||
EpsInitialTrafficData condition = new EpsInitialTrafficData();
|
||||
condition.setTableName(tableName);
|
||||
condition.setDeviceSn(queryParam.getDeviceSn());
|
||||
condition.setServiceSn(queryParam.getServiceSn());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
condition.setReceiveTraffic(queryParam.getReceiveTraffic());
|
||||
condition.setSendTraffic(queryParam.getSendTraffic());
|
||||
condition.setBusinessId(queryParam.getBusinessId());
|
||||
condition.setBusinessName(queryParam.getBusinessName());
|
||||
return epsInitialTrafficDataMapper.selectByCondition(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 查询初始流量信息
|
||||
*/
|
||||
@Override
|
||||
public List<EpsInitialTrafficData> getAllTraficMsg(EpsInitialTrafficData queryParam) {
|
||||
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableRouterUtil.getTableNamesBetweenInitial(queryParam.getStartTime(), queryParam.getEndTime());
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
EpsInitialTrafficData condition = new EpsInitialTrafficData();
|
||||
condition.setTableName(tableName);
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
condition.setInterfaceName(queryParam.getInterfaceName());
|
||||
return epsInitialTrafficDataMapper.getAllTraficMsg(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+7
-14
@@ -6,6 +6,7 @@ import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
import com.ruoyi.system.mapper.EpsNodeBandwidthMapper;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.service.IEpsNodeBandwidthService;
|
||||
import com.ruoyi.system.util.DateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -13,8 +14,10 @@ import org.webjars.NotFoundException;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.*;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.YearMonth;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -60,10 +63,10 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
|
||||
// 2. 设置查询条件
|
||||
EpsInitialTrafficData queryParams = new EpsInitialTrafficData();
|
||||
queryParams.setDeviceSn(epsNodeBandwidth.getHardwareSn());
|
||||
queryParams.setServiceSn(epsNodeBandwidth.getHardwareSn());
|
||||
|
||||
// 3. 根据带宽类型设置时间范围
|
||||
LocalDateTime createTime = dateToLocalDateTime(epsNodeBandwidth.getCreateTime());
|
||||
LocalDateTime createTime = DateUtil.dateToLocalDateTime(epsNodeBandwidth.getCreateTime());
|
||||
setTimeRangeByBandwidthType(queryParams, epsNodeBandwidth.getBandwidthType(), createTime);
|
||||
|
||||
// 4. 查询并返回数据
|
||||
@@ -176,16 +179,6 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
return epsNodeBandwidthMapper.getAvgDetailMsg(epsNodeBandwidth);
|
||||
}
|
||||
|
||||
/**
|
||||
* Date 类型 转为 LocalDateTime 类型
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime dateToLocalDateTime(Date date) {
|
||||
return date.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
/**
|
||||
* 根据带宽类型设置时间范围
|
||||
*/
|
||||
|
||||
+83
-23
@@ -2,14 +2,18 @@ package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.security.utils.SecurityUtils;
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.EpsMethodChangeRecord;
|
||||
import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
import com.ruoyi.system.mapper.EpsServerRevenueConfigMapper;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.service.IEpsServerRevenueConfigService;
|
||||
import com.ruoyi.system.util.DateUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务器收益方式配置Service业务层处理
|
||||
@@ -22,6 +26,8 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
|
||||
{
|
||||
@Autowired
|
||||
private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper;
|
||||
@Autowired
|
||||
private EpsInitialTrafficDataService epsInitialTrafficDataService;
|
||||
|
||||
/**
|
||||
* 查询服务器收益方式配置
|
||||
@@ -78,34 +84,88 @@ public class EpsServerRevenueConfigServiceImpl implements IEpsServerRevenueConfi
|
||||
// 修改条数
|
||||
int rows = epsServerRevenueConfigMapper.updateEpsServerRevenueConfig(epsServerRevenueConfig);
|
||||
if(rows>=0){
|
||||
EpsMethodChangeRecord epsMethodChangeRecord = new EpsMethodChangeRecord();
|
||||
// 节点名称
|
||||
epsMethodChangeRecord.setNodeName(epsServerRevenueConfig.getNodeName());
|
||||
// 硬件sn
|
||||
epsMethodChangeRecord.setHardwareSn(epsServerRevenueConfig.getHardwareSn());
|
||||
// 修改时间
|
||||
epsMethodChangeRecord.setCreateTime(DateUtils.getNowDate());
|
||||
// 修改人
|
||||
epsMethodChangeRecord.setCreatBy(SecurityUtils.getUsername());
|
||||
// 修改内容
|
||||
String content = "";
|
||||
if("流量".equals(nowRevenueMethod)){
|
||||
// 修改内容
|
||||
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
|
||||
",业务为"+epsServerRevenueConfig.getBusinessName();
|
||||
}
|
||||
if("包端".equals(nowRevenueMethod)){
|
||||
// 修改内容
|
||||
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
|
||||
",带宽值设置为"+epsServerRevenueConfig.getPackageBandwidth()+"Mbps,"+"业务为"+epsServerRevenueConfig.getBusinessName();
|
||||
}
|
||||
epsMethodChangeRecord.setChangeContent(content);
|
||||
// 添加操作记录
|
||||
epsServerRevenueConfigMapper.insertEpsServerRevenueConfig(epsServerRevenueConfig);
|
||||
addRecord(epsServerRevenueConfig);
|
||||
// 添加包端数据到相关数据表
|
||||
saveServiceTrafficData(epsServerRevenueConfig);
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
/**
|
||||
* 添加服务器配置操作记录
|
||||
*/
|
||||
private void addRecord(EpsServerRevenueConfig epsServerRevenueConfig) {
|
||||
String nowRevenueMethod = getMethodName(epsServerRevenueConfig.getRevenueMethod());
|
||||
EpsMethodChangeRecord changeRecord = new EpsMethodChangeRecord();
|
||||
// 设置基本信息
|
||||
changeRecord.setNodeName(epsServerRevenueConfig.getNodeName());
|
||||
changeRecord.setHardwareSn(epsServerRevenueConfig.getHardwareSn());
|
||||
changeRecord.setCreateTime(DateUtils.getNowDate());
|
||||
changeRecord.setCreatBy(SecurityUtils.getUsername());
|
||||
// 修改内容
|
||||
String content = "";
|
||||
if("流量".equals(nowRevenueMethod)){
|
||||
// 修改内容
|
||||
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
|
||||
",业务为"+epsServerRevenueConfig.getBusinessName();
|
||||
}
|
||||
if("包端".equals(nowRevenueMethod)){
|
||||
// 修改内容
|
||||
content = "收益方式变为【"+nowRevenueMethod+"】,流量网口设置为"+epsServerRevenueConfig.getTrafficPort()+
|
||||
",带宽值设置为"+epsServerRevenueConfig.getPackageBandwidth()+"Mbps,"+"业务为"+epsServerRevenueConfig.getBusinessName();
|
||||
}
|
||||
changeRecord.setChangeContent(content);
|
||||
// 添加操作记录
|
||||
epsServerRevenueConfigMapper.insertEpsServerRevenueConfig(epsServerRevenueConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存流量信息
|
||||
* @param epsServerRevenueConfig
|
||||
*/
|
||||
private void saveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) {
|
||||
// 查询初始流量数据
|
||||
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
|
||||
epsInitialTrafficData.setServiceSn(epsServerRevenueConfig.getHardwareSn());
|
||||
epsInitialTrafficData.setBusinessId(epsServerRevenueConfig.getBusinessCode());
|
||||
epsInitialTrafficData.setBusinessName(epsServerRevenueConfig.getBusinessName());
|
||||
epsInitialTrafficData.setInterfaceName(epsServerRevenueConfig.getTrafficPort());
|
||||
epsInitialTrafficData.setPackageBandwidth(epsServerRevenueConfig.getPackageBandwidth());
|
||||
epsInitialTrafficData.setRevenueMethod(epsServerRevenueConfig.getRevenueMethod());
|
||||
epsInitialTrafficData.setNodeName(epsServerRevenueConfig.getNodeName());
|
||||
epsInitialTrafficData.setStartTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
|
||||
epsInitialTrafficData.setEndTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
|
||||
epsInitialTrafficDataService.save(epsInitialTrafficData);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存流量信息
|
||||
* @param epsServerRevenueConfig
|
||||
*/
|
||||
@Override
|
||||
public void autoSaveServiceTrafficData(EpsServerRevenueConfig epsServerRevenueConfig) {
|
||||
// 查询初始流量数据
|
||||
EpsInitialTrafficData epsInitialTrafficData = new EpsInitialTrafficData();
|
||||
epsInitialTrafficData.setStartTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
|
||||
epsInitialTrafficData.setEndTime(DateUtil.dateToLocalDateTime(epsServerRevenueConfig.getCreateTime()));
|
||||
List<EpsInitialTrafficData> dataList = epsInitialTrafficDataService.getAllTraficMsg(epsInitialTrafficData);
|
||||
for (EpsInitialTrafficData initialTrafficData : dataList) {
|
||||
// 根据ip查询节点名称
|
||||
String ip = initialTrafficData.getIpv4Address();
|
||||
Map nodeMsg = epsServerRevenueConfigMapper.getNodeMsgByIp(ip);
|
||||
// 赋值
|
||||
initialTrafficData.setServiceSn(nodeMsg.get("hardwareSn") + "");
|
||||
initialTrafficData.setNodeName(nodeMsg.get("resourceName") + "");
|
||||
initialTrafficData.setRevenueMethod(nodeMsg.get("revenueMethod") + "");
|
||||
initialTrafficData.setBusinessId(nodeMsg.get("businessCode") + "");
|
||||
initialTrafficData.setBusinessName(nodeMsg.get("businessName") + "");
|
||||
initialTrafficData.setStartTime(initialTrafficData.getCreateTime());
|
||||
initialTrafficData.setEndTime(initialTrafficData.getCreateTime());
|
||||
// 流量相关数据入库
|
||||
epsInitialTrafficDataService.save(initialTrafficData);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 批量删除服务器收益方式配置
|
||||
*
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.ruoyi.system.util;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
|
||||
public class DateUtil {
|
||||
|
||||
/**
|
||||
* Date 类型 转为 LocalDateTime 类型
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static LocalDateTime dateToLocalDateTime(Date date) {
|
||||
return date.toInstant()
|
||||
.atZone(ZoneId.systemDefault())
|
||||
.toLocalDateTime();
|
||||
}
|
||||
}
|
||||
+35
-1
@@ -12,7 +12,9 @@ import java.util.Set;
|
||||
public class TableRouterUtil {
|
||||
|
||||
// 表名前缀
|
||||
private static final String TABLE_PREFIX = "eps_initial_traffic";
|
||||
private static final String TABLE_PREFIX = "eps_traffic_details";
|
||||
|
||||
private static final String TABLE_PREFIX_INITIAL = "initial_bandwidth_traffic";
|
||||
|
||||
// 日期格式
|
||||
private static final DateTimeFormatter YEAR_MONTH_FORMAT =
|
||||
@@ -42,6 +44,19 @@ public class TableRouterUtil {
|
||||
yearMonth,
|
||||
getDayRange(day));
|
||||
}
|
||||
public static String getInitialTableName(LocalDateTime createTime) {
|
||||
if (createTime == null) {
|
||||
throw new IllegalArgumentException("创建时间不能为null");
|
||||
}
|
||||
|
||||
String yearMonth = createTime.format(YEAR_MONTH_FORMAT);
|
||||
int day = createTime.getDayOfMonth();
|
||||
|
||||
return String.format("%s_%s_%s",
|
||||
TABLE_PREFIX_INITIAL,
|
||||
yearMonth,
|
||||
getDayRange(day));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间范围内涉及的所有表名
|
||||
@@ -62,6 +77,25 @@ public class TableRouterUtil {
|
||||
|
||||
return tableNames;
|
||||
}
|
||||
/**
|
||||
* 获取时间范围内涉及的所有表名
|
||||
* @param startTime 开始时间(包含)
|
||||
* @param endTime 结束时间(包含)
|
||||
* @return 按时间顺序排列的表名集合
|
||||
*/
|
||||
public static Set<String> getTableNamesBetweenInitial(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
validateTimeRange(startTime, endTime);
|
||||
|
||||
Set<String> tableNames = new LinkedHashSet<>();
|
||||
LocalDateTime current = startTime.withHour(0).withMinute(0).withSecond(0);
|
||||
|
||||
while (!current.isAfter(endTime)) {
|
||||
tableNames.add(getInitialTableName(current));
|
||||
current = current.plusDays(1);
|
||||
}
|
||||
|
||||
return tableNames;
|
||||
}
|
||||
|
||||
|
||||
// 获取日期区间
|
||||
|
||||
Reference in New Issue
Block a user