磁盘表分表,增加磁盘名称存储CRUD

This commit is contained in:
gaoyutao
2026-01-15 10:27:40 +08:00
parent ac406d88fe
commit c921a83d27
18 changed files with 788 additions and 31 deletions
@@ -1,6 +1,7 @@
package com.tongran.system.controller;
import com.tongran.common.core.web.controller.BaseController;
import com.tongran.common.core.web.domain.AjaxResult;
import com.tongran.system.domain.EpsInitialTrafficData;
import com.tongran.system.domain.InitialSwitchInfoDetails;
import com.tongran.system.service.EpsInitialTrafficDataService;
@@ -24,6 +25,11 @@ public class CalculateController extends BaseController {
@Autowired
private IInitialSwitchInfoDetailsService initialSwitchInfoDetailsService;
@GetMapping("/createTables")
public AjaxResult createTables(Long plusMonth){
epsInitialTrafficDataService.createNextMonthTables(plusMonth);
return success();
}
@GetMapping("/calculate95BandwidthDaily")
public void calculate95BandwidthDaily(String day){
// 获取昨天的日期范围(北京时间)
@@ -72,4 +72,6 @@ public interface EpsInitialTrafficDataMapper {
void createOtherMsgTable(String tableName);
void createSwitchOpMdTable(String tableName);
void createDiskInfo(String tableName);
}
@@ -19,6 +19,12 @@ public interface EpsInitialTrafficDataService {
* 每月25日0点自动执行
*/
void createNextMonthTables();
/**
* 创建分表
* @param plusMonth 下几个月
*/
void createNextMonthTables(Long plusMonth);
/**
* 保存单条流量数据
* @param data 流量数据
@@ -74,8 +74,31 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
createOtherMsgTable(year, month);
// 创建交换机光模块表
createSwitchOpMdTable(year, month);
// 创建磁盘信息表
createDiskInfo(year, month);
}
public void createNextMonthTables(Long plusMonth) {
LocalDate nextMonth = LocalDate.now().plusMonths(plusMonth);
int year = nextMonth.getYear();
int month = nextMonth.getMonthValue();
// 创建流量详情表
createTrafficDetailsTable(year, month);
// 创建流量初始表
createTrafficStatsTable(year, month);
// 创建mtr探测丢包结果表
createMtrProbeResultTable(year, month);
// 创建交换机流量初始表
createSwitchInfoTable(year, month);
// 创建交换机流量业务表
createSwitchInfoDetailsTable(year, month);
// 创建服务器其他信息表
createOtherMsgTable(year, month);
// 创建交换机光模块表
createSwitchOpMdTable(year, month);
// 创建磁盘信息表
createDiskInfo(year, month);
}
private void createTrafficDetailsTable(int year, int month) {
createRangeTables(year, month, "eps_traffic_details", (tableName) -> {
epsInitialTrafficDataMapper.createEpsTrafficTable(tableName);
@@ -114,6 +137,11 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
epsInitialTrafficDataMapper.createSwitchOpMdTable(tableName);
});
}
private void createDiskInfo(int year, int month) {
createRangeTables(year, month, "initial_disk_info", (tableName) -> {
epsInitialTrafficDataMapper.createDiskInfo(tableName);
});
}
/**
@@ -201,6 +201,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
UNIQUE KEY uk_client_fiber_time (client_id, create_time, fiber_port_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='光模块信息表';
</update>
<update id="createDiskInfo">
CREATE TABLE IF NOT EXISTS ${tableName} (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
`client_id` varchar(255) NOT NULL COMMENT '客户端ID',
`name` varchar(100) NOT NULL COMMENT '磁盘名称(如sda、sdb等)',
`serial` varchar(100) COMMENT '磁盘序列号',
`total` bigint(20) COMMENT '磁盘总大小(GB)',
`write_speed` bigint(20) COMMENT '磁盘写入速率(字节/秒)',
`read_speed` bigint(20) COMMENT '磁盘读取速率(字节/秒)',
`write_times` bigint(20) COMMENT '磁盘写入次数',
`read_times` bigint(20) COMMENT '磁盘读取次数',
`write_bytes` bigint(20) COMMENT '磁盘写入总字节数',
`read_bytes` bigint(20) COMMENT '磁盘读取总字节数',
`create_by` varchar(50) COMMENT '创建人',
`update_by` varchar(50) COMMENT '更新人',
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
`type` varchar(255) COMMENT '磁盘类型',
`used_space` bigint(20) COMMENT '已用空间',
PRIMARY KEY (`id`),
UNIQUE KEY uk_client_disk_time (`client_id`, `name`, `create_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='磁盘监控信息表';
</update>
<!-- 单条插入语句 -->
<insert id="insert">
INSERT INTO ${tableName} (