设置定时任务,每月1号0点执行 计算 月均日95值,95带宽值/月
This commit is contained in:
@@ -1,25 +1,47 @@
|
||||
package com.ruoyi.system.config;
|
||||
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.InitialSwitchInfoDetails;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.service.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 自动生成数据表
|
||||
*/
|
||||
@Configuration
|
||||
@EnableScheduling
|
||||
@Slf4j
|
||||
public class TableScheduleConfig {
|
||||
|
||||
private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
@Autowired
|
||||
private EpsInitialTrafficDataService epsInitialTrafficDataService;
|
||||
@Autowired
|
||||
private IInitialSwitchInfoDetailsService initialSwitchInfoDetailsService;
|
||||
@Autowired
|
||||
private IEpsNodeBandwidthService epsNodeBandwidthService;
|
||||
@Autowired
|
||||
private IAllInterfaceNameService allInterfaceNameService;
|
||||
@Autowired
|
||||
private IEpsServerRevenueConfigService epsServerRevenueConfigService;
|
||||
@Autowired
|
||||
private IRmEpsTopologyManagementService rmEpsTopologyManagementService;
|
||||
@Autowired
|
||||
private IEpsMethodChangeRecordService epsMethodChangeRecordService;
|
||||
|
||||
// 每月25号创建下月表
|
||||
@Scheduled(cron = "0 0 0 26 * ?")
|
||||
@Scheduled(cron = "0 0 0 25 * ?")
|
||||
// @Scheduled(initialDelay = 5000, fixedDelay = Long.MAX_VALUE)
|
||||
public void createNextMonthTables() {
|
||||
epsInitialTrafficDataService.createNextMonthTables();
|
||||
@@ -28,11 +50,347 @@ public class TableScheduleConfig {
|
||||
// 每天12点执行 计算95带宽值/日
|
||||
@Scheduled(cron = "0 0 0 * * ?", zone = "Asia/Shanghai")
|
||||
public void calculate95BandwidthDaily() {
|
||||
EpsInitialTrafficData queryParam = new EpsInitialTrafficData();
|
||||
epsInitialTrafficDataService.calculate95BandwidthDaily(queryParam);
|
||||
// 获取昨天的日期范围(北京时间)
|
||||
LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1);
|
||||
String dailyStartTime = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00
|
||||
String dailyEndTime = yesterday.atTime(23, 59, 59).format(TIME_FORMAT); // 23:59:59
|
||||
// 日
|
||||
String dayOrMonth = "1";
|
||||
// 有效-95带宽值/日
|
||||
epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam);
|
||||
EpsInitialTrafficData queryParam = new EpsInitialTrafficData();
|
||||
queryParam.setDayOrMonth(dayOrMonth);
|
||||
epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam, dailyStartTime, dailyEndTime);
|
||||
InitialSwitchInfoDetails initialSwitchInfoDetails = new InitialSwitchInfoDetails();
|
||||
epsInitialTrafficDataService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails);
|
||||
initialSwitchInfoDetails.setDayOrMonth(dayOrMonth);
|
||||
initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(initialSwitchInfoDetails, dailyStartTime, dailyEndTime);
|
||||
}
|
||||
|
||||
// 每月1号0点执行 计算95带宽值/月
|
||||
@Scheduled(cron = "0 0 0 1 * ?", zone = "Asia/Shanghai")
|
||||
public void calculateMonthlyBandwidthTasks() {
|
||||
// 获取上个月的日期范围
|
||||
LocalDate lastMonth = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusMonths(0);
|
||||
LocalDate firstDayOfMonth = lastMonth.withDayOfMonth(1);
|
||||
LocalDate lastDayOfMonth = lastMonth.withDayOfMonth(lastMonth.lengthOfMonth());
|
||||
|
||||
String monthlyStartTime = firstDayOfMonth.atStartOfDay().format(TIME_FORMAT);
|
||||
String monthlyEndTime = lastDayOfMonth.atTime(23, 59, 59).format(TIME_FORMAT);
|
||||
|
||||
// 顺序执行各任务,间隔10分钟
|
||||
executeWithDelay(() -> calculateServerMonthlyBandwidth(monthlyStartTime, monthlyEndTime), 0);
|
||||
executeWithDelay(() -> calculateSwitchMonthlyBandwidth(monthlyStartTime, monthlyEndTime), 10);
|
||||
executeWithDelay(() -> calculateServerAvgMonthlyBandwidth(monthlyStartTime, monthlyEndTime), 10);
|
||||
executeWithDelay(() -> calculateSwitchAvgMonthlyBandwidth(monthlyStartTime, monthlyEndTime), 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* 延迟执行任务
|
||||
*/
|
||||
private void executeWithDelay(Runnable task, int delayMinutes) {
|
||||
try {
|
||||
if (delayMinutes > 0) {
|
||||
Thread.sleep(delayMinutes * 60 * 1000);
|
||||
}
|
||||
task.run();
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.error("任务执行被中断", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算服务器月95带宽值
|
||||
*/
|
||||
private void calculateServerMonthlyBandwidth(String monthlyStartTime, String monthlyEndTime) {
|
||||
log.info("开始计算服务器月95带宽值...");
|
||||
try {
|
||||
String dayOrMonth = "2";
|
||||
EpsInitialTrafficData queryParam = new EpsInitialTrafficData();
|
||||
queryParam.setDayOrMonth(dayOrMonth);
|
||||
epsInitialTrafficDataService.calculateBusiness95BandwidthDaily(queryParam, monthlyStartTime, monthlyEndTime);
|
||||
log.info("服务器月95带宽值计算完成");
|
||||
} catch (Exception e) {
|
||||
log.error("计算服务器月95带宽值失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算交换机月95带宽值
|
||||
*/
|
||||
private void calculateSwitchMonthlyBandwidth(String monthlyStartTime, String monthlyEndTime) {
|
||||
log.info("开始计算交换机月95带宽值...");
|
||||
try {
|
||||
String dayOrMonth = "2";
|
||||
InitialSwitchInfoDetails queryParam = new InitialSwitchInfoDetails();
|
||||
queryParam.setDayOrMonth(dayOrMonth);
|
||||
initialSwitchInfoDetailsService.calculateSwitch95BandwidthDaily(queryParam, monthlyStartTime, monthlyEndTime);
|
||||
log.info("交换机月95带宽值计算完成");
|
||||
} catch (Exception e) {
|
||||
log.error("计算交换机月95带宽值失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算服务器月平均95带宽值
|
||||
*/
|
||||
private void calculateServerAvgMonthlyBandwidth(String monthlyStartTime, String monthlyEndTime) {
|
||||
log.info("开始计算服务器月平均95带宽值...");
|
||||
try {
|
||||
EpsNodeBandwidth epsNodeBandwidth = new EpsNodeBandwidth();
|
||||
epsNodeBandwidth.setStartTime(monthlyStartTime);
|
||||
epsNodeBandwidth.setEndTime(monthlyEndTime);
|
||||
|
||||
List<AllInterfaceName> snList = allInterfaceNameService.getAllDeviceSn(new AllInterfaceName());
|
||||
for (AllInterfaceName allInterfaceName : snList) {
|
||||
processServerAvgBandwidth(epsNodeBandwidth, allInterfaceName);
|
||||
}
|
||||
log.info("服务器月平均95带宽值计算完成");
|
||||
} catch (Exception e) {
|
||||
log.error("计算服务器月平均95带宽值失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个服务器的平均带宽计算
|
||||
*/
|
||||
private void processServerAvgBandwidth(EpsNodeBandwidth epsNodeBandwidth, AllInterfaceName allInterfaceName) {
|
||||
final String deviceSn = allInterfaceName.getDeviceSn();
|
||||
|
||||
try {
|
||||
// 1. 设置基础设备信息
|
||||
epsNodeBandwidth.setHardwareSn(deviceSn);
|
||||
|
||||
// 2. 查询服务器配置
|
||||
EpsServerRevenueConfig queryConfig = new EpsServerRevenueConfig();
|
||||
queryConfig.setHardwareSn(deviceSn);
|
||||
List<EpsServerRevenueConfig> configList = epsServerRevenueConfigService.selectEpsServerRevenueConfigList(queryConfig);
|
||||
EpsServerRevenueConfig serverConfig = configList.isEmpty() ? new EpsServerRevenueConfig() : configList.get(0);
|
||||
epsNodeBandwidth.setNodeName(serverConfig.getNodeName());
|
||||
|
||||
// 3. 检查是否需要处理业务变更
|
||||
boolean shouldProcessChange = serverConfig.getUpdateTime() != null
|
||||
&& epsNodeBandwidth.getStartTime() != null
|
||||
&& epsNodeBandwidth.getStartTime().length() >= 10
|
||||
&& "1".equals(serverConfig.getChanged())
|
||||
&& DateUtils.parseDateToStr("yyyy-MM", serverConfig.getUpdateTime())
|
||||
.equals(epsNodeBandwidth.getStartTime().substring(0, 7));
|
||||
|
||||
// 4. 处理业务变更情况
|
||||
if (shouldProcessChange) {
|
||||
// 查询业务变更记录
|
||||
EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord();
|
||||
changeQuery.setHardwareSn(deviceSn);
|
||||
changeQuery.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
changeQuery.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
|
||||
List<EpsMethodChangeRecord> records = epsMethodChangeRecordService.selectEpsMethodChangeRecordList(changeQuery);
|
||||
|
||||
// 按businessCode分组处理(修复null key问题)
|
||||
if (!records.isEmpty()) {
|
||||
Map<String, List<EpsMethodChangeRecord>> groupedRecords = records.stream()
|
||||
.filter(record -> record.getBusinessCode() != null) // 过滤掉businessCode为null的记录
|
||||
.collect(Collectors.groupingBy(EpsMethodChangeRecord::getBusinessCode));
|
||||
|
||||
// 处理每个业务分组
|
||||
for (Map.Entry<String, List<EpsMethodChangeRecord>> entry : groupedRecords.entrySet()) {
|
||||
String businessCode = entry.getKey();
|
||||
// 取第一个有效业务名称(同businessCode的业务名称应该相同)
|
||||
String businessName = entry.getValue().stream()
|
||||
.filter(r -> r.getBusinessName() != null)
|
||||
.findFirst()
|
||||
.map(EpsMethodChangeRecord::getBusinessName)
|
||||
.orElse("未知业务");
|
||||
|
||||
// 创建业务带宽对象
|
||||
EpsNodeBandwidth bandwidthWithBiz = new EpsNodeBandwidth();
|
||||
bandwidthWithBiz.setHardwareSn(deviceSn);
|
||||
bandwidthWithBiz.setNodeName(serverConfig.getNodeName());
|
||||
bandwidthWithBiz.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
bandwidthWithBiz.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
bandwidthWithBiz.setBusinessId(businessCode);
|
||||
bandwidthWithBiz.setBusinessName(businessName);
|
||||
bandwidthWithBiz.setResourceType("1");
|
||||
|
||||
// 执行计算
|
||||
epsNodeBandwidthService.calculateAvg(bandwidthWithBiz);
|
||||
}
|
||||
|
||||
// 处理businessCode为null的记录(如果有)
|
||||
List<EpsMethodChangeRecord> nullBusinessRecords = records.stream()
|
||||
.filter(record -> record.getBusinessCode() == null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!nullBusinessRecords.isEmpty()) {
|
||||
log.warn("服务器 {} 有 {} 条记录的businessCode为null", deviceSn, nullBusinessRecords.size());
|
||||
// 可以选择记录日志或进行其他处理
|
||||
}
|
||||
|
||||
return; // 业务变更处理完成后直接返回
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 处理正常情况(无业务变更或无需处理变更)
|
||||
EpsNodeBandwidth normalBandwidth = new EpsNodeBandwidth();
|
||||
normalBandwidth.setHardwareSn(deviceSn);
|
||||
normalBandwidth.setNodeName(serverConfig.getNodeName());
|
||||
normalBandwidth.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
normalBandwidth.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
normalBandwidth.setBusinessId(serverConfig.getBusinessCode());
|
||||
normalBandwidth.setBusinessName(serverConfig.getBusinessName());
|
||||
normalBandwidth.setResourceType("1");
|
||||
epsNodeBandwidthService.calculateAvg(normalBandwidth);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理服务器 {} 平均带宽失败", deviceSn, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算交换机月平均95带宽值
|
||||
*/
|
||||
private void calculateSwitchAvgMonthlyBandwidth(String monthlyStartTime, String monthlyEndTime) {
|
||||
log.info("开始计算交换机月平均95带宽值...");
|
||||
try {
|
||||
EpsNodeBandwidth epsNodeBandwidth = new EpsNodeBandwidth();
|
||||
epsNodeBandwidth.setStartTime(monthlyStartTime);
|
||||
epsNodeBandwidth.setEndTime(monthlyEndTime);
|
||||
|
||||
List<AllInterfaceName> switchSnList = allInterfaceNameService.getAllSwitchSn(new AllInterfaceName());
|
||||
for (AllInterfaceName switchSnMsg : switchSnList) {
|
||||
processSwitchAvgBandwidth(epsNodeBandwidth, switchSnMsg);
|
||||
}
|
||||
log.info("交换机月平均95带宽值计算完成");
|
||||
} catch (Exception e) {
|
||||
log.error("计算交换机月平均95带宽值失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个交换机的平均带宽计算
|
||||
*/
|
||||
private void processSwitchAvgBandwidth(EpsNodeBandwidth epsNodeBandwidth, AllInterfaceName switchSnMsg) {
|
||||
final String switchSn = switchSnMsg.getSwitchSn();
|
||||
|
||||
try {
|
||||
// 1. 查询交换机拓扑信息
|
||||
RmEpsTopologyManagement managementQuery = new RmEpsTopologyManagement();
|
||||
managementQuery.setSwitchSn(switchSn);
|
||||
List<RmEpsTopologyManagement> topologyList = rmEpsTopologyManagementService.selectRmEpsTopologyManagementList(managementQuery);
|
||||
|
||||
// 2. 设置基础信息
|
||||
RmEpsTopologyManagement topology = topologyList.isEmpty() ? new RmEpsTopologyManagement() : topologyList.get(0);
|
||||
epsNodeBandwidth.setSwitchSn(switchSn);
|
||||
epsNodeBandwidth.setInterfaceName(topology.getInterfaceName());
|
||||
|
||||
// 3. 判断连接设备类型
|
||||
boolean isServerConnected = "1".equals(topology.getConnectedDeviceType());
|
||||
|
||||
// 4. 处理服务器连接的情况
|
||||
if (isServerConnected && topology.getServerSn() != null) {
|
||||
String serverSn = topology.getServerSn();
|
||||
epsNodeBandwidth.setHardwareSn(serverSn);
|
||||
// 查询服务器配置
|
||||
EpsServerRevenueConfig queryConfig = new EpsServerRevenueConfig();
|
||||
queryConfig.setHardwareSn(serverSn);
|
||||
List<EpsServerRevenueConfig> configList = epsServerRevenueConfigService.selectEpsServerRevenueConfigList(queryConfig);
|
||||
EpsServerRevenueConfig serverConfig = configList.isEmpty() ? new EpsServerRevenueConfig() : configList.get(0);
|
||||
epsNodeBandwidth.setNodeName(serverConfig.getNodeName());
|
||||
|
||||
// 检查是否需要处理业务变更
|
||||
boolean shouldProcessChange = serverConfig.getUpdateTime() != null
|
||||
&& epsNodeBandwidth.getStartTime() != null
|
||||
&& epsNodeBandwidth.getStartTime().length() >= 10
|
||||
&& "1".equals(serverConfig.getChanged())
|
||||
&& DateUtils.parseDateToStr("yyyy-MM", serverConfig.getUpdateTime())
|
||||
.equals(epsNodeBandwidth.getStartTime().substring(0, 7));
|
||||
|
||||
if(shouldProcessChange){
|
||||
// 查询业务变更记录
|
||||
EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord();
|
||||
changeQuery.setHardwareSn(serverSn);
|
||||
changeQuery.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
changeQuery.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
|
||||
List<EpsMethodChangeRecord> records = epsMethodChangeRecordService.selectEpsMethodChangeRecordList(changeQuery);
|
||||
|
||||
// 按businessCode分组处理
|
||||
if (!records.isEmpty()) {
|
||||
Map<String, List<EpsMethodChangeRecord>> groupedRecords = records.stream()
|
||||
.filter(record -> record.getBusinessCode() != null) // 过滤掉businessCode为null的记录
|
||||
.collect(Collectors.groupingBy(EpsMethodChangeRecord::getBusinessCode));
|
||||
|
||||
// 处理每个业务分组
|
||||
for (Map.Entry<String, List<EpsMethodChangeRecord>> entry : groupedRecords.entrySet()) {
|
||||
String businessCode = entry.getKey();
|
||||
List<EpsMethodChangeRecord> businessRecords = entry.getValue();
|
||||
|
||||
// 取第一个有效业务名称
|
||||
String businessName = businessRecords.stream()
|
||||
.filter(r -> r.getBusinessName() != null)
|
||||
.findFirst()
|
||||
.map(EpsMethodChangeRecord::getBusinessName)
|
||||
.orElse("未知业务");
|
||||
|
||||
// 创建业务带宽对象
|
||||
EpsNodeBandwidth bandwidthWithBiz = new EpsNodeBandwidth();
|
||||
bandwidthWithBiz.setSwitchSn(switchSn);
|
||||
bandwidthWithBiz.setInterfaceName(topology.getInterfaceName());
|
||||
bandwidthWithBiz.setHardwareSn(serverSn);
|
||||
bandwidthWithBiz.setNodeName(topology.getServerName());
|
||||
bandwidthWithBiz.setUplinkSwitch(topology.getSwitchName());
|
||||
bandwidthWithBiz.setInterfaceLinkDeviceType(topology.getConnectedDeviceType());
|
||||
bandwidthWithBiz.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
bandwidthWithBiz.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
bandwidthWithBiz.setBusinessId(businessCode);
|
||||
bandwidthWithBiz.setBusinessName(businessName);
|
||||
bandwidthWithBiz.setResourceType("2");
|
||||
|
||||
// 执行计算
|
||||
epsNodeBandwidthService.calculateAvg(bandwidthWithBiz);
|
||||
}
|
||||
|
||||
// 处理businessCode为null的记录(如果有)
|
||||
List<EpsMethodChangeRecord> nullBusinessRecords = records.stream()
|
||||
.filter(record -> record.getBusinessCode() == null)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
if (!nullBusinessRecords.isEmpty()) {
|
||||
log.warn("交换机 {} 有 {} 条记录的businessCode为null", switchSn, nullBusinessRecords.size());
|
||||
// 可以选择记录日志或进行其他处理
|
||||
}
|
||||
|
||||
return; // 业务变更处理完成后直接返回
|
||||
}
|
||||
}else{
|
||||
// 5. 处理普通情况(无变更记录)
|
||||
EpsNodeBandwidth normalBandwidth = new EpsNodeBandwidth();
|
||||
normalBandwidth.setSwitchSn(switchSn);
|
||||
normalBandwidth.setInterfaceName(topology.getInterfaceName());
|
||||
normalBandwidth.setHardwareSn(topology.getServerSn());
|
||||
normalBandwidth.setNodeName(topology.getServerName());
|
||||
normalBandwidth.setUplinkSwitch(topology.getSwitchName());
|
||||
normalBandwidth.setInterfaceLinkDeviceType(topology.getConnectedDeviceType());
|
||||
normalBandwidth.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
normalBandwidth.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
normalBandwidth.setBusinessId(serverConfig.getBusinessCode());
|
||||
normalBandwidth.setBusinessName(serverConfig.getBusinessName());
|
||||
normalBandwidth.setResourceType("2");
|
||||
epsNodeBandwidthService.calculateAvg(normalBandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
// 5. 处理机房出口情况
|
||||
EpsNodeBandwidth normalBandwidth = new EpsNodeBandwidth();
|
||||
normalBandwidth.setSwitchSn(switchSn);
|
||||
normalBandwidth.setInterfaceName(topology.getInterfaceName());
|
||||
normalBandwidth.setInterfaceLinkDeviceType(topology.getConnectedDeviceType());
|
||||
normalBandwidth.setStartTime(epsNodeBandwidth.getStartTime());
|
||||
normalBandwidth.setEndTime(epsNodeBandwidth.getEndTime());
|
||||
normalBandwidth.setResourceType("2");
|
||||
epsNodeBandwidthService.calculateAvg(normalBandwidth);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("处理交换机 {} 平均带宽失败", switchSn, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,6 +126,6 @@ public class EpsNodeBandwidthController extends BaseController
|
||||
@PostMapping("/calculateAvg")
|
||||
public AjaxResult calculateAvg(@RequestBody EpsNodeBandwidth epsNodeBandwidth)
|
||||
{
|
||||
return toAjax(epsNodeBandwidthService.insertEpsNodeBandwidth(epsNodeBandwidth));
|
||||
return toAjax(epsNodeBandwidthService.calculateAvg(epsNodeBandwidth));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ public class EpsInitialTrafficData {
|
||||
|
||||
/** 批量插入集合 **/
|
||||
private List<EpsInitialTrafficData> dataList;
|
||||
|
||||
/**
|
||||
* 动态表名
|
||||
* 格式:eps_traffic_[年]_[月]_[日期范围]
|
||||
@@ -124,7 +125,12 @@ public class EpsInitialTrafficData {
|
||||
* 选中的属性名称
|
||||
*/
|
||||
private String[] properties;
|
||||
|
||||
/** 资源类型 */
|
||||
private String resourceType;
|
||||
/** 带宽类型 */
|
||||
private String bandwidthType;
|
||||
/** 日或月 */
|
||||
private String dayOrMonth;
|
||||
|
||||
|
||||
}
|
||||
@@ -3,11 +3,9 @@ package com.ruoyi.system.domain;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.ruoyi.common.core.annotation.Excel;
|
||||
import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
@@ -16,6 +14,7 @@ import java.util.Date;
|
||||
* @author gyt
|
||||
* @date 2025-08-12
|
||||
*/
|
||||
@Data
|
||||
public class EpsNodeBandwidth extends BaseEntity
|
||||
{
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -96,9 +95,9 @@ public class EpsNodeBandwidth extends BaseEntity
|
||||
@Excel(name = "创建人名称")
|
||||
private String creatorName;
|
||||
|
||||
/** remark1 */
|
||||
@Excel(name = "remark1")
|
||||
private String remark1;
|
||||
/** 交换机sn */
|
||||
@Excel(name = "交换机sn")
|
||||
private String switchSn;
|
||||
|
||||
/** 接口名称 */
|
||||
@Excel(name = "接口名称")
|
||||
@@ -126,280 +125,7 @@ public class EpsNodeBandwidth extends BaseEntity
|
||||
/** 结束时间 */
|
||||
private String endTime;
|
||||
/** 月份 */
|
||||
@JsonFormat(pattern = "yyyy-MM")
|
||||
private LocalDate monthTime;
|
||||
private String monthTime;
|
||||
|
||||
@Override
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public LocalDate getMonthTime() {
|
||||
return monthTime;
|
||||
}
|
||||
|
||||
public void setMonthTime(LocalDate monthTime) {
|
||||
this.monthTime = monthTime;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(String startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
|
||||
public String getBusinessName() {
|
||||
return businessName;
|
||||
}
|
||||
|
||||
public void setBusinessName(String businessName) {
|
||||
this.businessName = businessName;
|
||||
}
|
||||
|
||||
public String getBusinessId() {
|
||||
return businessId;
|
||||
}
|
||||
|
||||
public void setBusinessId(String businessId) {
|
||||
this.businessId = businessId;
|
||||
}
|
||||
|
||||
public String getResourceType() {
|
||||
return resourceType;
|
||||
}
|
||||
|
||||
public void setResourceType(String resourceType) {
|
||||
this.resourceType = resourceType;
|
||||
}
|
||||
|
||||
public String getInterfaceLinkDeviceType() {
|
||||
return interfaceLinkDeviceType;
|
||||
}
|
||||
|
||||
public void setInterfaceLinkDeviceType(String interfaceLinkDeviceType) {
|
||||
this.interfaceLinkDeviceType = interfaceLinkDeviceType;
|
||||
}
|
||||
|
||||
public void setId(Long id)
|
||||
{
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setNodeName(String nodeName)
|
||||
{
|
||||
this.nodeName = nodeName;
|
||||
}
|
||||
|
||||
public String getNodeName()
|
||||
{
|
||||
return nodeName;
|
||||
}
|
||||
|
||||
public void setHardwareSn(String hardwareSn)
|
||||
{
|
||||
this.hardwareSn = hardwareSn;
|
||||
}
|
||||
|
||||
public String getHardwareSn()
|
||||
{
|
||||
return hardwareSn;
|
||||
}
|
||||
|
||||
public void setBandwidth95Daily(BigDecimal bandwidth95Daily)
|
||||
{
|
||||
this.bandwidth95Daily = bandwidth95Daily;
|
||||
}
|
||||
|
||||
public BigDecimal getBandwidth95Daily()
|
||||
{
|
||||
return bandwidth95Daily;
|
||||
}
|
||||
|
||||
public void setBandwidth95Monthly(BigDecimal bandwidth95Monthly)
|
||||
{
|
||||
this.bandwidth95Monthly = bandwidth95Monthly;
|
||||
}
|
||||
|
||||
public BigDecimal getBandwidth95Monthly()
|
||||
{
|
||||
return bandwidth95Monthly;
|
||||
}
|
||||
|
||||
public void setPackageBandwidthDaily(BigDecimal packageBandwidthDaily)
|
||||
{
|
||||
this.packageBandwidthDaily = packageBandwidthDaily;
|
||||
}
|
||||
|
||||
public BigDecimal getPackageBandwidthDaily()
|
||||
{
|
||||
return packageBandwidthDaily;
|
||||
}
|
||||
|
||||
public void setCustomerId(String customerId)
|
||||
{
|
||||
this.customerId = customerId;
|
||||
}
|
||||
|
||||
public String getCustomerId()
|
||||
{
|
||||
return customerId;
|
||||
}
|
||||
|
||||
public void setCustomerName(String customerName)
|
||||
{
|
||||
this.customerName = customerName;
|
||||
}
|
||||
|
||||
public String getCustomerName()
|
||||
{
|
||||
return customerName;
|
||||
}
|
||||
|
||||
public void setServiceNumber(String serviceNumber)
|
||||
{
|
||||
this.serviceNumber = serviceNumber;
|
||||
}
|
||||
|
||||
public String getServiceNumber()
|
||||
{
|
||||
return serviceNumber;
|
||||
}
|
||||
|
||||
public void setUplinkSwitch(String uplinkSwitch)
|
||||
{
|
||||
this.uplinkSwitch = uplinkSwitch;
|
||||
}
|
||||
|
||||
public String getUplinkSwitch()
|
||||
{
|
||||
return uplinkSwitch;
|
||||
}
|
||||
|
||||
public void setCreatorId(Long creatorId)
|
||||
{
|
||||
this.creatorId = creatorId;
|
||||
}
|
||||
|
||||
public Long getCreatorId()
|
||||
{
|
||||
return creatorId;
|
||||
}
|
||||
|
||||
public void setCreatorName(String creatorName)
|
||||
{
|
||||
this.creatorName = creatorName;
|
||||
}
|
||||
|
||||
public String getCreatorName()
|
||||
{
|
||||
return creatorName;
|
||||
}
|
||||
|
||||
public void setRemark1(String remark1)
|
||||
{
|
||||
this.remark1 = remark1;
|
||||
}
|
||||
|
||||
public String getRemark1()
|
||||
{
|
||||
return remark1;
|
||||
}
|
||||
|
||||
public String getInterfaceName() {
|
||||
return interfaceName;
|
||||
}
|
||||
|
||||
public void setInterfaceName(String interfaceName) {
|
||||
this.interfaceName = interfaceName;
|
||||
}
|
||||
|
||||
public String getBandwidthType() {
|
||||
return bandwidthType;
|
||||
}
|
||||
|
||||
public void setBandwidthType(String bandwidthType) {
|
||||
this.bandwidthType = bandwidthType;
|
||||
}
|
||||
|
||||
public BigDecimal getBandwidthResult() {
|
||||
return bandwidthResult;
|
||||
}
|
||||
|
||||
public void setBandwidthResult(BigDecimal bandwidthResult) {
|
||||
this.bandwidthResult = bandwidthResult;
|
||||
}
|
||||
|
||||
public BigDecimal getAvgMonthlyBandwidth95() {
|
||||
return avgMonthlyBandwidth95;
|
||||
}
|
||||
|
||||
public void setAvgMonthlyBandwidth95(BigDecimal avgMonthlyBandwidth95) {
|
||||
this.avgMonthlyBandwidth95 = avgMonthlyBandwidth95;
|
||||
}
|
||||
|
||||
public BigDecimal getEffectiveBandwidth95Daily() {
|
||||
return effectiveBandwidth95Daily;
|
||||
}
|
||||
|
||||
public void setEffectiveBandwidth95Daily(BigDecimal effectiveBandwidth95Daily) {
|
||||
this.effectiveBandwidth95Daily = effectiveBandwidth95Daily;
|
||||
}
|
||||
|
||||
public BigDecimal getEffectiveBandwidth95Monthly() {
|
||||
return effectiveBandwidth95Monthly;
|
||||
}
|
||||
|
||||
public void setEffectiveBandwidth95Monthly(BigDecimal effectiveBandwidth95Monthly) {
|
||||
this.effectiveBandwidth95Monthly = effectiveBandwidth95Monthly;
|
||||
}
|
||||
|
||||
public BigDecimal getEffectiveAvgMonthlyBandwidth95() {
|
||||
return effectiveAvgMonthlyBandwidth95;
|
||||
}
|
||||
|
||||
public void setEffectiveAvgMonthlyBandwidth95(BigDecimal effectiveAvgMonthlyBandwidth95) {
|
||||
this.effectiveAvgMonthlyBandwidth95 = effectiveAvgMonthlyBandwidth95;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("id", getId())
|
||||
.append("nodeName", getNodeName())
|
||||
.append("hardwareSn", getHardwareSn())
|
||||
.append("bandwidth95Daily", getBandwidth95Daily())
|
||||
.append("bandwidth95Monthly", getBandwidth95Monthly())
|
||||
.append("packageBandwidthDaily", getPackageBandwidthDaily())
|
||||
.append("customerId", getCustomerId())
|
||||
.append("customerName", getCustomerName())
|
||||
.append("serviceNumber", getServiceNumber())
|
||||
.append("uplinkSwitch", getUplinkSwitch())
|
||||
.append("createTime", getCreateTime())
|
||||
.append("updateTime", getUpdateTime())
|
||||
.append("creatorId", getCreatorId())
|
||||
.append("creatorName", getCreatorName())
|
||||
.append("remark1", getRemark1())
|
||||
.append("interfaceName", getInterfaceName())
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,4 +82,11 @@ public class InitialSwitchInfoDetails extends BaseEntity
|
||||
private String startTime;
|
||||
|
||||
private String endTime;
|
||||
|
||||
/** 资源类型 */
|
||||
private String resourceType;
|
||||
/** 带宽类型 */
|
||||
private String bandwidthType;
|
||||
/** 日或月 */
|
||||
private String dayOrMonth;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.InitialSwitchInfoDetails;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,18 +44,6 @@ public interface EpsInitialTrafficDataService {
|
||||
* @param queryParam 查询参数实体
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
void calculateBusiness95BandwidthDaily(EpsInitialTrafficData queryParam);
|
||||
/**
|
||||
* 计算95带宽值
|
||||
* @param queryParam 查询参数实体
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
void calculate95BandwidthDaily(EpsInitialTrafficData queryParam);
|
||||
/**
|
||||
* 计算交换机95带宽值
|
||||
* @param queryParam 查询参数实体
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam);
|
||||
void calculateBusiness95BandwidthDaily(EpsInitialTrafficData queryParam, String dailyStartTime, String dailyEndTime);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.system.domain.AllInterfaceName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 所有接口名称Service接口
|
||||
*
|
||||
@@ -58,4 +59,8 @@ public interface IAllInterfaceNameService
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteAllInterfaceNameById(Long id);
|
||||
|
||||
List<AllInterfaceName> getAllDeviceSn(AllInterfaceName interfaceName);
|
||||
|
||||
List<AllInterfaceName> getAllSwitchSn(AllInterfaceName allInterfaceName);
|
||||
}
|
||||
|
||||
@@ -65,4 +65,11 @@ public interface IInitialSwitchInfoDetailsService
|
||||
* @param initialSwitchInfoDetails
|
||||
*/
|
||||
R<String> autoSaveSwitchTraffic(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 计算交换机95带宽值
|
||||
* @param queryParam 查询参数实体
|
||||
* @return 流量数据列表
|
||||
*/
|
||||
void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam, String dailyStartTime, String dailyEndTime);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import java.util.List;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.AllInterfaceName;
|
||||
import com.ruoyi.system.mapper.AllInterfaceNameMapper;
|
||||
import com.ruoyi.system.service.IAllInterfaceNameService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.ruoyi.system.mapper.AllInterfaceNameMapper;
|
||||
import com.ruoyi.system.domain.AllInterfaceName;
|
||||
import com.ruoyi.system.service.IAllInterfaceNameService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 所有接口名称Service业务层处理
|
||||
@@ -93,4 +94,13 @@ public class AllInterfaceNameServiceImpl implements IAllInterfaceNameService
|
||||
{
|
||||
return allInterfaceNameMapper.deleteAllInterfaceNameById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AllInterfaceName> getAllDeviceSn(AllInterfaceName interfaceName) {
|
||||
return allInterfaceNameMapper.getAllDeviceSn(interfaceName);
|
||||
}
|
||||
@Override
|
||||
public List<AllInterfaceName> getAllSwitchSn(AllInterfaceName allInterfaceName){
|
||||
return allInterfaceNameMapper.getAllSwitchSn(allInterfaceName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.util.CalculateUtil;
|
||||
import com.ruoyi.system.util.TableRouterUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
@@ -13,25 +14,19 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataService {
|
||||
|
||||
|
||||
private static final Pattern SPEED_PATTERN = Pattern.compile("(\\d+\\.?\\d*)\\s*(\\S*)");
|
||||
|
||||
private static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
@Autowired
|
||||
private EpsInitialTrafficDataMapper epsInitialTrafficDataMapper;
|
||||
@Autowired
|
||||
@@ -39,8 +34,6 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
@Autowired
|
||||
private AllInterfaceNameMapper allInterfaceNameMapper;
|
||||
@Autowired
|
||||
private InitialSwitchInfoDetailsMapper initialSwitchInfoDetailsMapper;
|
||||
@Autowired
|
||||
private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper;
|
||||
@Autowired
|
||||
private EpsMethodChangeRecordMapper epsMethodChangeRecordMapper;
|
||||
@@ -200,50 +193,106 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
}
|
||||
|
||||
/**
|
||||
* 有业务变动的 计算有效95带宽值/日
|
||||
* 计算95带宽值/日
|
||||
* @param queryParam
|
||||
*/
|
||||
@Override
|
||||
public void calculateBusiness95BandwidthDaily(EpsInitialTrafficData queryParam) {
|
||||
// 1. 获取所有设备SN列表
|
||||
public void calculateBusiness95BandwidthDaily(EpsInitialTrafficData queryParam, String dailyStartTime, String dailyEndTime) {
|
||||
// 获取所有设备SN列表
|
||||
List<AllInterfaceName> snList = allInterfaceNameMapper.getAllDeviceSn(new AllInterfaceName());
|
||||
|
||||
// 2. 获取昨天的日期范围(北京时间)
|
||||
LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1);
|
||||
String dailyStartTime = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00
|
||||
String dailyEndTime = yesterday.atTime(23, 59, 59).format(TIME_FORMAT); // 23:59:59
|
||||
|
||||
// 3. 遍历每个设备
|
||||
for (AllInterfaceName interfaceName : snList) {
|
||||
// 遍历处理每个设备
|
||||
snList.forEach(interfaceName -> {
|
||||
queryParam.setServiceSn(interfaceName.getDeviceSn());
|
||||
|
||||
// 4. 检查设备是否有业务变更
|
||||
processDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 处理单个设备的带宽计算
|
||||
*/
|
||||
private void processDeviceBandwidth(EpsInitialTrafficData queryParam,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
// 1. 检查设备是否有业务变更
|
||||
EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig();
|
||||
revenueConfig.setHardwareSn(interfaceName.getDeviceSn());
|
||||
List<EpsServerRevenueConfig> changedList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(revenueConfig);
|
||||
revenueConfig.setHardwareSn(queryParam.getServiceSn());
|
||||
List<EpsServerRevenueConfig> changedList = epsServerRevenueConfigMapper
|
||||
.selectEpsServerRevenueConfigList(revenueConfig);
|
||||
|
||||
if (!changedList.isEmpty() &&
|
||||
// 2. 根据业务变更情况选择计算方式
|
||||
if (hasTrafficMethodChanged(changedList)) {
|
||||
calculateChangedDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
} else {
|
||||
calculateNormalDeviceBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 判断是否为流量型业务变更
|
||||
*/
|
||||
private boolean hasTrafficMethodChanged(List<EpsServerRevenueConfig> changedList) {
|
||||
return !changedList.isEmpty() &&
|
||||
"1".equals(changedList.get(0).getChanged()) &&
|
||||
"1".equals(changedList.get(0).getRevenueMethod())) {
|
||||
|
||||
// 5. 获取业务变更记录(按时间降序)
|
||||
"1".equals(changedList.get(0).getRevenueMethod());
|
||||
}
|
||||
/**
|
||||
* 计算有业务变更设备的带宽
|
||||
*/
|
||||
private void calculateChangedDeviceBandwidth(EpsInitialTrafficData queryParam,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
// 1. 获取业务变更记录(按时间降序)
|
||||
EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord();
|
||||
changeQuery.setHardwareSn(interfaceName.getDeviceSn());
|
||||
changeQuery.setHardwareSn(queryParam.getServiceSn());
|
||||
changeQuery.setStartTime(dailyStartTime);
|
||||
changeQuery.setEndTime(dailyEndTime);
|
||||
List<EpsMethodChangeRecord> records = epsMethodChangeRecordMapper
|
||||
.selectEpsMethodChangeRecordList(changeQuery);
|
||||
|
||||
if (!records.isEmpty()) {
|
||||
// 确保按时间降序排列
|
||||
// 2. 确保按时间降序排列
|
||||
records.sort((r1, r2) -> r2.getCreateTime().compareTo(r1.getCreateTime()));
|
||||
|
||||
// 6. 计算各时间段95值
|
||||
// 3. 计算各时间段95值
|
||||
calculateTimeSegments95(queryParam, records, dailyStartTime, dailyEndTime);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 计算无业务变更设备的带宽
|
||||
*/
|
||||
private void calculateNormalDeviceBandwidth(EpsInitialTrafficData queryParam,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
queryParam.setStartTime(dailyStartTime);
|
||||
queryParam.setEndTime(dailyEndTime);
|
||||
List<EpsInitialTrafficData> dataList = query(queryParam);
|
||||
|
||||
if (!dataList.isEmpty()) {
|
||||
calculateAndSave95Bandwidth(dataList, dailyStartTime, queryParam.getDayOrMonth());
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 计算并保存95带宽值
|
||||
*/
|
||||
private void calculateAndSave95Bandwidth(List<EpsInitialTrafficData> dataList, String dateTime, String dayOrMonth) {
|
||||
// 1. 提取并转换带宽值
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> CalculateUtil.parseSpeedToMbps(data.getOutSpeed()))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 计算95百分位
|
||||
BigDecimal percentile95 = CalculateUtil.calculatePercentile(speedsInMbps, 0.95);
|
||||
|
||||
// 3. 保存结果
|
||||
EpsInitialTrafficData epsInitialTrafficData = dataList.get(0);
|
||||
epsInitialTrafficData.setResourceType("1");
|
||||
if("1".equals(dayOrMonth)){
|
||||
epsInitialTrafficData.setBandwidthType("1");
|
||||
}
|
||||
if("2".equals(dayOrMonth)){
|
||||
epsInitialTrafficData.setBandwidthType("2");
|
||||
}
|
||||
saveBandwidthResult(epsInitialTrafficData, percentile95, dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算设备各时间段的95带宽值
|
||||
@@ -276,146 +325,18 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
queryParam.setEndTime(endTime);
|
||||
List<EpsInitialTrafficData> dataList = query(queryParam);
|
||||
if (!dataList.isEmpty()) {
|
||||
calculate95BandwidthDaily(dataList);
|
||||
calculate95BandwidthDaily(dataList, startTime, queryParam.getDayOrMonth());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void calculate95BandwidthDaily(EpsInitialTrafficData queryParam) {
|
||||
// 1. 获取昨天的日期(北京时间)
|
||||
LocalDate yesterday = LocalDate.now(ZoneId.of("Asia/Shanghai")).minusDays(1);
|
||||
// 2. 定义时间范围字符串
|
||||
String startTimeStr = yesterday.atStartOfDay().format(TIME_FORMAT); // 00:00:00
|
||||
String endTimeStr = yesterday.atTime(23, 59, 59).format(TIME_FORMAT); // 23:59:59
|
||||
queryParam.setStartTime(startTimeStr);
|
||||
queryParam.setEndTime(endTimeStr);
|
||||
queryParam.setRevenueMethod("1");
|
||||
// 查询所有的服务器sn
|
||||
AllInterfaceName allInterfaceName = new AllInterfaceName();
|
||||
List<AllInterfaceName> snList = allInterfaceNameMapper.getAllDeviceSn(allInterfaceName);
|
||||
for (AllInterfaceName interfaceName : snList) {
|
||||
queryParam.setServiceSn(interfaceName.getDeviceSn());
|
||||
// 4. 检查设备是否有业务变更
|
||||
EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig();
|
||||
revenueConfig.setHardwareSn(interfaceName.getDeviceSn());
|
||||
List<EpsServerRevenueConfig> changedList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(revenueConfig);
|
||||
|
||||
if (!changedList.isEmpty() &&
|
||||
"1".equals(changedList.get(0).getChanged()) &&
|
||||
"1".equals(changedList.get(0).getRevenueMethod())) {
|
||||
|
||||
}else{
|
||||
// 查询原始数据
|
||||
List<EpsInitialTrafficData> dataList = query(queryParam);
|
||||
if(!dataList.isEmpty()){
|
||||
// 1. 提取 outSpeed 并转换为 Mbps
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> parseSpeedToMbps(data.getOutSpeed()))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 计算 95% 位置(向上取整)
|
||||
int total = speedsInMbps.size();
|
||||
int position = (int) Math.ceil(0.95 * total) - 1; // 转换为 0-based 索引
|
||||
if (position < 0){
|
||||
position = 0;
|
||||
}
|
||||
if (position >= total){
|
||||
position = total - 1;
|
||||
}
|
||||
|
||||
// 3. 获取 95 值并四舍五入到两位小数
|
||||
BigDecimal percentile95 = speedsInMbps.get(position);
|
||||
BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP);
|
||||
// 服务器信息
|
||||
EpsInitialTrafficData epsInitialTrafficData = dataList.get(0);
|
||||
// 落入带宽计算结果表
|
||||
EpsNodeBandwidth bandwidth = new EpsNodeBandwidth();
|
||||
bandwidth.setHardwareSn(epsInitialTrafficData.getServiceSn());
|
||||
bandwidth.setNodeName(epsInitialTrafficData.getNodeName());
|
||||
bandwidth.setBusinessId(epsInitialTrafficData.getBusinessId());
|
||||
bandwidth.setBusinessName(epsInitialTrafficData.getBusinessName());
|
||||
bandwidth.setResourceType("1");
|
||||
bandwidth.setBandwidthType("1");
|
||||
bandwidth.setBandwidthResult(dailyResult);
|
||||
bandwidth.setBandwidth95Daily(dailyResult);
|
||||
bandwidth.setCreateTime(DateUtils.parseDate(startTimeStr));
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam) {
|
||||
Date now = DateUtils.getNowDate();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.add(Calendar.HOUR_OF_DAY, -24);
|
||||
Date startDate = calendar.getTime();
|
||||
// 格式化时间
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String startTime = sdf.format(startDate);
|
||||
String endTime = sdf.format(now);
|
||||
queryParam.setStartTime(startTime);
|
||||
queryParam.setEndTime(endTime);
|
||||
// 查询所有的服务器sn
|
||||
AllInterfaceName allInterfaceName = new AllInterfaceName();
|
||||
List<AllInterfaceName> switchSnList = allInterfaceNameMapper.getAllSwitchSn(allInterfaceName);
|
||||
for (AllInterfaceName interfaceName : switchSnList) {
|
||||
queryParam.setSwitchSn(interfaceName.getSwitchSn());
|
||||
// 查询原始数据
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper.selectInitialSwitchInfoDetailsList(queryParam);
|
||||
if(!dataList.isEmpty()){
|
||||
// 1. 提取 outSpeed 并转换为 Mbps
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> {
|
||||
// 根据 type 选择 inSpeed 或 outSpeed
|
||||
String speed = ("1".equals(data.getInterfaceDeviceType())) ? data.getInSpeed()+"" : data.getOutSpeed()+"";
|
||||
// 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s)
|
||||
if (speed.matches("^\\d+(\\.\\d+)?$")) {
|
||||
speed += " B/S";
|
||||
}
|
||||
return parseSpeedToMbps(speed);
|
||||
})
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 计算 95% 位置(向上取整)
|
||||
int total = speedsInMbps.size();
|
||||
int position = (int) Math.ceil(0.95 * total) - 1; // 转换为 0-based 索引
|
||||
if (position < 0){
|
||||
position = 0;
|
||||
}
|
||||
if (position >= total){
|
||||
position = total - 1;
|
||||
}
|
||||
|
||||
// 3. 获取 95 值并四舍五入到两位小数
|
||||
BigDecimal percentile95 = speedsInMbps.get(position);
|
||||
BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP);
|
||||
// 服务器信息
|
||||
InitialSwitchInfoDetails initialSwitchInfoDetails = dataList.get(0);
|
||||
// 落入带宽计算结果表
|
||||
EpsNodeBandwidth bandwidth = new EpsNodeBandwidth();
|
||||
bandwidth.setHardwareSn(initialSwitchInfoDetails.getServerSn());
|
||||
bandwidth.setNodeName(initialSwitchInfoDetails.getServerName());
|
||||
bandwidth.setResourceType("2");
|
||||
bandwidth.setBandwidthType("1");
|
||||
bandwidth.setBandwidthResult(dailyResult);
|
||||
bandwidth.setBandwidth95Daily(dailyResult);
|
||||
bandwidth.setCreateTime(startDate);
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算有效-日95带宽值
|
||||
* 计算日95带宽值
|
||||
* @param dataList
|
||||
*/
|
||||
private void calculate95BandwidthDaily(List<EpsInitialTrafficData> dataList){
|
||||
private void calculate95BandwidthDaily(List<EpsInitialTrafficData> dataList, String startTime, String dayOrMonth){
|
||||
// 1. 提取 outSpeed 并转换为 Mbps
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> parseSpeedToMbps(data.getOutSpeed()))
|
||||
.map(data -> CalculateUtil.parseSpeedToMbps(data.getOutSpeed()))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -434,66 +355,55 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP);
|
||||
// 服务器信息
|
||||
EpsInitialTrafficData epsInitialTrafficData = dataList.get(0);
|
||||
// 落入带宽计算结果表
|
||||
EpsNodeBandwidth bandwidth = new EpsNodeBandwidth();
|
||||
bandwidth.setHardwareSn(epsInitialTrafficData.getServiceSn());
|
||||
bandwidth.setNodeName(epsInitialTrafficData.getNodeName());
|
||||
bandwidth.setBusinessId(epsInitialTrafficData.getBusinessId());
|
||||
bandwidth.setBusinessName(epsInitialTrafficData.getBusinessName());
|
||||
bandwidth.setResourceType("1");
|
||||
bandwidth.setBandwidthType("5");
|
||||
bandwidth.setBandwidthResult(dailyResult);
|
||||
bandwidth.setEffectiveBandwidth95Daily(dailyResult);
|
||||
bandwidth.setCreateTime(DateUtils.parseDate(epsInitialTrafficData.getStartTime()));
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth);
|
||||
epsInitialTrafficData.setResourceType("1");
|
||||
if("1".equals(dayOrMonth)){
|
||||
epsInitialTrafficData.setBandwidthType("5");
|
||||
}
|
||||
if("2".equals(dayOrMonth)){
|
||||
epsInitialTrafficData.setBandwidthType("6");
|
||||
}
|
||||
saveBandwidthResult(epsInitialTrafficData, dailyResult, startTime);
|
||||
}
|
||||
/**
|
||||
* 单位换算
|
||||
* @param speedWithUnit
|
||||
* @return
|
||||
* 保存带宽结果
|
||||
*/
|
||||
private static BigDecimal parseSpeedToMbps(String speedWithUnit) {
|
||||
if (speedWithUnit == null || speedWithUnit.trim().isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
Matcher matcher = SPEED_PATTERN.matcher(speedWithUnit.trim());
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("Invalid speed format: " + speedWithUnit);
|
||||
}
|
||||
|
||||
BigDecimal value = new BigDecimal(matcher.group(1));
|
||||
String unit = matcher.group(2).toUpperCase();
|
||||
|
||||
// 处理纯数字(单位为空)
|
||||
if (unit.isEmpty()) {
|
||||
unit = "B/S"; // 默认单位: Bytes/s
|
||||
}
|
||||
|
||||
// 单位换算逻辑(保持不变)
|
||||
switch (unit) {
|
||||
case "B/S":
|
||||
return value.multiply(new BigDecimal("0.000008"));
|
||||
case "KBPS":
|
||||
case "KB/S":
|
||||
return value.divide(new BigDecimal("1000"), 10, RoundingMode.HALF_UP);
|
||||
case "MBPS":
|
||||
case "MB/S":
|
||||
return value;
|
||||
case "GBPS":
|
||||
case "GB/S":
|
||||
return value.multiply(new BigDecimal("1000"));
|
||||
case "TBPS":
|
||||
case "TB/S":
|
||||
return value.multiply(new BigDecimal("1000000"));
|
||||
case "KIB/S":
|
||||
return value.multiply(new BigDecimal("0.008192"));
|
||||
case "MIB/S":
|
||||
return value.multiply(new BigDecimal("8.388608"));
|
||||
case "GIB/S":
|
||||
return value.multiply(new BigDecimal("8589.934592"));
|
||||
private void saveBandwidthResult(EpsInitialTrafficData data,
|
||||
BigDecimal result,
|
||||
String dateTime) {
|
||||
EpsNodeBandwidth bandwidth = new EpsNodeBandwidth();
|
||||
bandwidth.setHardwareSn(data.getServiceSn());
|
||||
bandwidth.setNodeName(data.getNodeName());
|
||||
bandwidth.setBusinessId(data.getBusinessId());
|
||||
bandwidth.setBusinessName(data.getBusinessName());
|
||||
bandwidth.setResourceType(data.getResourceType());
|
||||
bandwidth.setBandwidthType(data.getBandwidthType());
|
||||
bandwidth.setBandwidthResult(result);
|
||||
bandwidth.setCreateTime(DateUtils.parseDate(dateTime));
|
||||
switch (data.getBandwidthType()){
|
||||
case "1":
|
||||
bandwidth.setBandwidth95Daily(result);
|
||||
break;
|
||||
case "2":
|
||||
bandwidth.setBandwidth95Monthly(result);
|
||||
break;
|
||||
case "3":
|
||||
bandwidth.setPackageBandwidthDaily(result);
|
||||
break;
|
||||
case "4":
|
||||
bandwidth.setAvgMonthlyBandwidth95(result);
|
||||
break;
|
||||
case "5":
|
||||
bandwidth.setEffectiveBandwidth95Daily(result);
|
||||
break;
|
||||
case "6":
|
||||
bandwidth.setEffectiveBandwidth95Monthly(result);
|
||||
break;
|
||||
case "7":
|
||||
bandwidth.setEffectiveAvgMonthlyBandwidth95(result);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown speed unit: " + unit);
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown bandwidthType: " + data.getBandwidthType());
|
||||
}
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,10 +3,13 @@ package com.ruoyi.system.service.impl;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.system.domain.EpsInitialTrafficData;
|
||||
import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
import com.ruoyi.system.domain.EpsServerRevenueConfig;
|
||||
import com.ruoyi.system.mapper.EpsNodeBandwidthMapper;
|
||||
import com.ruoyi.system.mapper.EpsServerRevenueConfigMapper;
|
||||
import com.ruoyi.system.service.EpsInitialTrafficDataService;
|
||||
import com.ruoyi.system.service.IEpsNodeBandwidthService;
|
||||
import com.ruoyi.system.util.DateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -18,7 +21,9 @@ import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalTime;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* 节点带宽信息Service业务层处理
|
||||
@@ -27,12 +32,15 @@ import java.util.List;
|
||||
* @date 2025-08-12
|
||||
*/
|
||||
@Service
|
||||
@Slf4j
|
||||
public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
{
|
||||
@Autowired
|
||||
private EpsNodeBandwidthMapper epsNodeBandwidthMapper;
|
||||
@Autowired
|
||||
private EpsInitialTrafficDataService epsInitialTrafficDataService;
|
||||
@Autowired
|
||||
private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper;
|
||||
|
||||
/**
|
||||
* 查询节点带宽信息
|
||||
@@ -53,8 +61,7 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
* @return 节点带宽信息
|
||||
*/
|
||||
@Override
|
||||
public List<EpsInitialTrafficData> relatedData(Long id)
|
||||
{
|
||||
public List<EpsInitialTrafficData> relatedData(Long id) {
|
||||
// 1. 根据ID查询服务器信息
|
||||
EpsNodeBandwidth epsNodeBandwidth = epsNodeBandwidthMapper.selectEpsNodeBandwidthById(id);
|
||||
if (epsNodeBandwidth == null) {
|
||||
@@ -140,33 +147,110 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
* @param epsNodeBandwidth 节点带宽信息
|
||||
* @return 结果
|
||||
*/
|
||||
/**
|
||||
* 计算月均日95值
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public int calculateAvg(EpsNodeBandwidth epsNodeBandwidth) {
|
||||
// 验证是否已经存在记录
|
||||
List<EpsNodeBandwidth> existingRecords = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(epsNodeBandwidth);
|
||||
try {
|
||||
// 1. 参数验证
|
||||
if (epsNodeBandwidth == null) {
|
||||
log.warn("参数为空,无法计算月均日95值");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// 3. 获取计算数据(防止空指针)
|
||||
EpsNodeBandwidth calculatedData = epsNodeBandwidthMapper.calculateAvg(epsNodeBandwidth);
|
||||
// 日95值总和
|
||||
BigDecimal sum95Daily = calculatedData.getBandwidth95Daily();
|
||||
// 日有效95值总和
|
||||
BigDecimal sumEffectiveBandwidth95Daily = calculatedData.getEffectiveBandwidth95Daily();
|
||||
// 计算当月天数并求平均值
|
||||
LocalDate monthTime = epsNodeBandwidth.getMonthTime();
|
||||
int daysInMonth = YearMonth.from(monthTime).lengthOfMonth();
|
||||
// 月均日95值
|
||||
BigDecimal avgMonthlyBandwidth95 = daysInMonth == 0 ? BigDecimal.ZERO :
|
||||
sum95Daily.divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP);
|
||||
epsNodeBandwidth.setAvgMonthlyBandwidth95(avgMonthlyBandwidth95);
|
||||
// 有效-月均日95值
|
||||
BigDecimal effectiveAvgMonthlyBandwidth95 = daysInMonth == 0 ? BigDecimal.ZERO :
|
||||
sumEffectiveBandwidth95Daily.divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP);
|
||||
epsNodeBandwidth.setEffectiveAvgMonthlyBandwidth95(effectiveAvgMonthlyBandwidth95);
|
||||
if (calculatedData == null) {
|
||||
log.warn("未找到计算数据,硬件SN: {}", epsNodeBandwidth.getHardwareSn());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 根据是否存在记录执行更新或插入操作
|
||||
// 4. 安全获取求和值
|
||||
BigDecimal sum95Daily = Optional.ofNullable(calculatedData.getBandwidth95Daily()).orElse(BigDecimal.ZERO);
|
||||
BigDecimal sumEffectiveBandwidth95Daily = Optional.ofNullable(calculatedData.getEffectiveBandwidth95Daily()).orElse(BigDecimal.ZERO);
|
||||
|
||||
// 5. 计算当月天数
|
||||
LocalDate monthTime;
|
||||
try {
|
||||
monthTime = LocalDate.parse(epsNodeBandwidth.getMonthTime() == null
|
||||
? epsNodeBandwidth.getStartTime().substring(0,10) : epsNodeBandwidth.getMonthTime());
|
||||
} catch (Exception e) {
|
||||
log.error("月份时间格式错误: {}", epsNodeBandwidth.getMonthTime() == null
|
||||
? epsNodeBandwidth.getStartTime() : epsNodeBandwidth.getMonthTime(), e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int daysInMonth = YearMonth.from(monthTime).lengthOfMonth();
|
||||
if (daysInMonth == 0) {
|
||||
log.warn("当月天数为0,月份: {}", epsNodeBandwidth.getMonthTime() == null
|
||||
? epsNodeBandwidth.getStartTime() : epsNodeBandwidth.getMonthTime());
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 6. 检查业务变动
|
||||
boolean hasBusinessChange = false;
|
||||
if (epsNodeBandwidth.getHardwareSn() != null) {
|
||||
EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig();
|
||||
revenueConfig.setHardwareSn(epsNodeBandwidth.getHardwareSn());
|
||||
List<EpsServerRevenueConfig> changedList = epsServerRevenueConfigMapper.selectEpsServerRevenueConfigList(revenueConfig);
|
||||
|
||||
if (!changedList.isEmpty()) {
|
||||
EpsServerRevenueConfig epsServerRevenueConfig = changedList.get(0);
|
||||
if (epsServerRevenueConfig.getUpdateTime() != null &&
|
||||
epsNodeBandwidth.getStartTime() != null &&
|
||||
"1".equals(epsServerRevenueConfig.getChanged())) {
|
||||
|
||||
String configTime = DateUtils.parseDateToStr("yyyy-MM", epsServerRevenueConfig.getUpdateTime());
|
||||
hasBusinessChange = epsNodeBandwidth.getStartTime().equals(configTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 7. 计算平均值
|
||||
if (hasBusinessChange) {
|
||||
epsNodeBandwidth.setBandwidthType("7");
|
||||
// 2. 验证是否已经存在记录
|
||||
List<EpsNodeBandwidth> existingRecords = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(epsNodeBandwidth);
|
||||
if(!existingRecords.isEmpty()){
|
||||
epsNodeBandwidth.setId(existingRecords.get(0).getId());
|
||||
epsNodeBandwidth.setUpdateTime(DateUtils.getNowDate());
|
||||
}else{
|
||||
epsNodeBandwidth.setCreateTime(DateUtils.parseDate(epsNodeBandwidth.getStartTime()));
|
||||
}
|
||||
// 有效-月均日95值
|
||||
BigDecimal effectiveAvg = sumEffectiveBandwidth95Daily.divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP);
|
||||
epsNodeBandwidth.setEffectiveAvgMonthlyBandwidth95(effectiveAvg);
|
||||
epsNodeBandwidth.setBandwidthResult(effectiveAvg);
|
||||
// 8. 执行插入或更新操作
|
||||
return existingRecords.isEmpty() ?
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(epsNodeBandwidth) :
|
||||
epsNodeBandwidthMapper.updateEpsNodeBandwidth(epsNodeBandwidth);
|
||||
} else {
|
||||
epsNodeBandwidth.setBandwidthType("4");
|
||||
// 2. 验证是否已经存在记录
|
||||
List<EpsNodeBandwidth> existingRecords = epsNodeBandwidthMapper.selectEpsNodeBandwidthList(epsNodeBandwidth);
|
||||
if(!existingRecords.isEmpty()){
|
||||
epsNodeBandwidth.setId(existingRecords.get(0).getId());
|
||||
epsNodeBandwidth.setUpdateTime(DateUtils.getNowDate());
|
||||
}else{
|
||||
epsNodeBandwidth.setCreateTime(DateUtils.parseDate(epsNodeBandwidth.getStartTime()));
|
||||
}
|
||||
// 月均日95值
|
||||
BigDecimal avgMonthly = sum95Daily.divide(BigDecimal.valueOf(daysInMonth), 2, RoundingMode.HALF_UP);
|
||||
epsNodeBandwidth.setAvgMonthlyBandwidth95(avgMonthly);
|
||||
epsNodeBandwidth.setBandwidthResult(avgMonthly);
|
||||
// 8. 执行插入或更新操作
|
||||
return existingRecords.isEmpty() ?
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(epsNodeBandwidth) :
|
||||
epsNodeBandwidthMapper.updateEpsNodeBandwidth(epsNodeBandwidth);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("计算月均日95值失败", e);
|
||||
throw new RuntimeException("计算月均日95值失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,23 +264,25 @@ public class EpsNodeBandwidthServiceImpl implements IEpsNodeBandwidthService
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据带宽类型设置时间范围
|
||||
* 根据带宽类型设置时间范围(修复T分隔符问题)
|
||||
*/
|
||||
private void setTimeRangeByBandwidthType(EpsInitialTrafficData data, String bandwidthType, LocalDateTime baseTime) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
switch (bandwidthType) {
|
||||
case "1":
|
||||
case "3":
|
||||
case "5": // 日带宽
|
||||
data.setStartTime(baseTime.with(LocalTime.MIN) + ""); // 00:00:00
|
||||
data.setEndTime(baseTime.with(LocalTime.MAX).withNano(0) + ""); // 23:59:59
|
||||
data.setStartTime(baseTime.with(LocalTime.MIN).format(formatter)); // 00:00:00
|
||||
data.setEndTime(baseTime.with(LocalTime.MAX).withNano(0).format(formatter)); // 23:59:59
|
||||
break;
|
||||
case "2":
|
||||
case "4":
|
||||
case "6":
|
||||
case "7": // 月带宽
|
||||
YearMonth month = YearMonth.from(baseTime);
|
||||
data.setStartTime(month.atDay(1).atStartOfDay() + ""); // 当月第一天 00:00:00
|
||||
data.setEndTime(month.atEndOfMonth().atTime(23, 59, 59) + ""); // 当月最后一天 23:59:59
|
||||
data.setStartTime(month.atDay(1).atStartOfDay().format(formatter)); // 当月第一天 00:00:00
|
||||
data.setEndTime(month.atEndOfMonth().atTime(23, 59, 59).format(formatter)); // 当月最后一天 23:59:59
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("不支持的带宽类型: " + bandwidthType);
|
||||
|
||||
@@ -3,17 +3,16 @@ package com.ruoyi.system.service.impl;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.system.domain.AllInterfaceName;
|
||||
import com.ruoyi.system.domain.InitialSwitchInfoDetails;
|
||||
import com.ruoyi.system.domain.RmEpsTopologyManagement;
|
||||
import com.ruoyi.system.mapper.AllInterfaceNameMapper;
|
||||
import com.ruoyi.system.mapper.InitialSwitchInfoDetailsMapper;
|
||||
import com.ruoyi.system.mapper.RmEpsTopologyManagementMapper;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.IInitialSwitchInfoDetailsService;
|
||||
import com.ruoyi.system.util.CalculateUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -34,6 +33,12 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
private RmEpsTopologyManagementMapper rmEpsTopologyManagementMapper;
|
||||
@Autowired
|
||||
private AllInterfaceNameMapper allInterfaceNameMapper;
|
||||
@Autowired
|
||||
private EpsServerRevenueConfigMapper epsServerRevenueConfigMapper;
|
||||
@Autowired
|
||||
private EpsMethodChangeRecordMapper epsMethodChangeRecordMapper;
|
||||
@Autowired
|
||||
private EpsNodeBandwidthMapper epsNodeBandwidthMapper;
|
||||
|
||||
/**
|
||||
* 查询交换机监控信息
|
||||
@@ -229,4 +234,242 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
!Objects.equals(oldRecord.getSwitchName(), newRecord.getSwitchName()) ||
|
||||
!Objects.equals(oldRecord.getSwitchSn(), newRecord.getSwitchSn());
|
||||
}
|
||||
|
||||
public void calculateSwitch95BandwidthDaily(InitialSwitchInfoDetails queryParam, String dailyStartTime, String dailyEndTime) {
|
||||
// 查询所有的交换机SN列表
|
||||
AllInterfaceName allInterfaceName = new AllInterfaceName();
|
||||
List<AllInterfaceName> switchSnList = allInterfaceNameMapper.getAllSwitchSn(allInterfaceName);
|
||||
|
||||
// 遍历处理每个交换机
|
||||
switchSnList.forEach(interfaceName -> {
|
||||
queryParam.setSwitchSn(interfaceName.getSwitchSn());
|
||||
processSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理单个交换机的带宽计算
|
||||
*/
|
||||
private void processSwitchBandwidth(InitialSwitchInfoDetails queryParam,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
// 根据交换机sn查询连接的服务器sn
|
||||
RmEpsTopologyManagement management = new RmEpsTopologyManagement();
|
||||
management.setSwitchSn(queryParam.getSwitchSn());
|
||||
List<RmEpsTopologyManagement> serverSnList = rmEpsTopologyManagementMapper.selectRmEpsTopologyManagementList(management);
|
||||
if(!serverSnList.isEmpty()){
|
||||
if("1".equals(serverSnList.get(0).getConnectedDeviceType())){
|
||||
queryParam.setServerSn(serverSnList.get(0).getServerSn());
|
||||
// 检查交换机连接的服务器是否有业务变更(如果有相关配置)
|
||||
EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig();
|
||||
revenueConfig.setHardwareSn(serverSnList.get(0).getServerSn());
|
||||
List<EpsServerRevenueConfig> changedList = epsServerRevenueConfigMapper
|
||||
.selectEpsServerRevenueConfigList(revenueConfig);
|
||||
// 根据业务变更情况选择计算方式
|
||||
if (hasTrafficMethodChanged(changedList)) {
|
||||
calculateChangedSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
} else {
|
||||
calculateNormalSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
}
|
||||
}
|
||||
if("2".equals(serverSnList.get(0).getConnectedDeviceType())){
|
||||
calculateNormalSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为流量型业务变更
|
||||
*/
|
||||
private boolean hasTrafficMethodChanged(List<EpsServerRevenueConfig> changedList) {
|
||||
return !changedList.isEmpty() &&
|
||||
"1".equals(changedList.get(0).getChanged()) &&
|
||||
"1".equals(changedList.get(0).getRevenueMethod());
|
||||
}
|
||||
/**
|
||||
* 计算有业务变更交换机的带宽
|
||||
*/
|
||||
private void calculateChangedSwitchBandwidth(InitialSwitchInfoDetails queryParam,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
// 获取业务变更记录(按时间降序)
|
||||
EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord();
|
||||
changeQuery.setHardwareSn(queryParam.getServerSn());
|
||||
changeQuery.setStartTime(dailyStartTime);
|
||||
changeQuery.setEndTime(dailyEndTime);
|
||||
List<EpsMethodChangeRecord> records = epsMethodChangeRecordMapper
|
||||
.selectEpsMethodChangeRecordList(changeQuery);
|
||||
|
||||
if (!records.isEmpty()) {
|
||||
// 确保按时间降序排列
|
||||
records.sort((r1, r2) -> r2.getCreateTime().compareTo(r1.getCreateTime()));
|
||||
|
||||
// 计算各时间段95值
|
||||
calculateSwitchTimeSegments95(queryParam, records, dailyStartTime, dailyEndTime);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算无业务变更交换机的带宽
|
||||
*/
|
||||
private void calculateNormalSwitchBandwidth(InitialSwitchInfoDetails queryParam,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
queryParam.setStartTime(dailyStartTime);
|
||||
queryParam.setEndTime(dailyEndTime);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(queryParam);
|
||||
|
||||
if (!dataList.isEmpty()) {
|
||||
calculateAndSaveSwitch95Bandwidth(dataList, dailyStartTime, queryParam.getDayOrMonth());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算并保存交换机95带宽值
|
||||
*/
|
||||
private void calculateAndSaveSwitch95Bandwidth(List<InitialSwitchInfoDetails> dataList, String dateTime, String dayOrMonth) {
|
||||
// 1. 提取并转换带宽值
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> {
|
||||
// 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed
|
||||
String speed = ("1".equals(data.getInterfaceDeviceType())) ?
|
||||
data.getInSpeed() + "" : data.getOutSpeed() + "";
|
||||
// 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s)
|
||||
if (speed.matches("^\\d+(\\.\\d+)?$")) {
|
||||
speed += " B/S";
|
||||
}
|
||||
return CalculateUtil.parseSpeedToMbps(speed);
|
||||
})
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 计算95百分位
|
||||
BigDecimal percentile95 = CalculateUtil.calculatePercentile(speedsInMbps, 0.95);
|
||||
|
||||
// 3. 保存结果
|
||||
InitialSwitchInfoDetails switchInfo = dataList.get(0);
|
||||
switchInfo.setResourceType("2");
|
||||
if("1".equals(dayOrMonth)){
|
||||
switchInfo.setBandwidthType("1");
|
||||
}
|
||||
if("2".equals(dayOrMonth)){
|
||||
switchInfo.setBandwidthType("2");
|
||||
}
|
||||
saveSwitchBandwidthResult(switchInfo, percentile95, dateTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算交换机各时间段的95带宽值
|
||||
*/
|
||||
private void calculateSwitchTimeSegments95(InitialSwitchInfoDetails queryParam,
|
||||
List<EpsMethodChangeRecord> records,
|
||||
String dailyStartTime,
|
||||
String dailyEndTime) {
|
||||
// 1. 处理变更时间段(从最新到最早)
|
||||
String endTime = records.get(0).getCreateTime() + "";
|
||||
for (int i = 1; i < records.size(); i++) {
|
||||
String startTime = records.get(i).getCreateTime() + "";
|
||||
calculateSwitchSegment95(queryParam, startTime, endTime);
|
||||
endTime = startTime; // 移动时间窗口
|
||||
}
|
||||
|
||||
// 2. 处理最早变更前的时间段(昨天00:00:00 ~ 最早变更时间)
|
||||
String earliestChangeTime = records.get(records.size()-1).getCreateTime() + "";
|
||||
calculateSwitchSegment95(queryParam, dailyStartTime, earliestChangeTime);
|
||||
|
||||
// 3. 处理最后变更后的时间段(最新变更时间 ~ 昨天23:59:59)
|
||||
calculateSwitchSegment95(queryParam, endTime, dailyEndTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算交换机单个时间段的95带宽值
|
||||
*/
|
||||
private void calculateSwitchSegment95(InitialSwitchInfoDetails queryParam, String startTime, String endTime) {
|
||||
queryParam.setStartTime(startTime);
|
||||
queryParam.setEndTime(endTime);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(queryParam);
|
||||
if (!dataList.isEmpty()) {
|
||||
calculateSwitch95BandwidthDaily(dataList, startTime, queryParam.getDayOrMonth());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算交换机日95带宽值
|
||||
*/
|
||||
private void calculateSwitch95BandwidthDaily(List<InitialSwitchInfoDetails> dataList, String startTime, String dayOrMonth) {
|
||||
// 1. 提取并转换带宽值
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
.map(data -> {
|
||||
String speed = ("1".equals(data.getInterfaceDeviceType())) ?
|
||||
data.getInSpeed() + "" : data.getOutSpeed() + "";
|
||||
if (speed.matches("^\\d+(\\.\\d+)?$")) {
|
||||
speed += " B/S";
|
||||
}
|
||||
return CalculateUtil.parseSpeedToMbps(speed);
|
||||
})
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 2. 计算95百分位
|
||||
BigDecimal percentile95 = CalculateUtil.calculatePercentile(speedsInMbps, 0.95);
|
||||
BigDecimal dailyResult = percentile95.setScale(2, RoundingMode.HALF_UP);
|
||||
|
||||
// 3. 保存结果
|
||||
InitialSwitchInfoDetails switchInfo = dataList.get(0);
|
||||
switchInfo.setResourceType("2");
|
||||
if("1".equals(dayOrMonth)){
|
||||
switchInfo.setBandwidthType("5");
|
||||
}
|
||||
if("2".equals(dayOrMonth)){
|
||||
switchInfo.setBandwidthType("6");
|
||||
}
|
||||
saveSwitchBandwidthResult(switchInfo, dailyResult, startTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存交换机带宽结果
|
||||
*/
|
||||
private void saveSwitchBandwidthResult(InitialSwitchInfoDetails data,
|
||||
BigDecimal result,
|
||||
String dateTime) {
|
||||
EpsNodeBandwidth bandwidth = new EpsNodeBandwidth();
|
||||
bandwidth.setHardwareSn(data.getServerSn());
|
||||
bandwidth.setSwitchSn(data.getSwitchSn());
|
||||
bandwidth.setNodeName(data.getServerName());
|
||||
bandwidth.setUplinkSwitch(data.getSwitchName());
|
||||
bandwidth.setInterfaceName(data.getName());
|
||||
bandwidth.setBandwidthResult(result);
|
||||
bandwidth.setResourceType(data.getResourceType());
|
||||
bandwidth.setBandwidthType(data.getBandwidthType());
|
||||
bandwidth.setBandwidthResult(result);
|
||||
bandwidth.setCreateTime(DateUtils.parseDate(dateTime));
|
||||
switch (data.getBandwidthType()){
|
||||
case "1":
|
||||
bandwidth.setBandwidth95Daily(result);
|
||||
break;
|
||||
case "2":
|
||||
bandwidth.setBandwidth95Monthly(result);
|
||||
break;
|
||||
case "3":
|
||||
bandwidth.setPackageBandwidthDaily(result);
|
||||
break;
|
||||
case "4":
|
||||
bandwidth.setAvgMonthlyBandwidth95(result);
|
||||
break;
|
||||
case "5":
|
||||
bandwidth.setEffectiveBandwidth95Daily(result);
|
||||
break;
|
||||
case "6":
|
||||
bandwidth.setEffectiveBandwidth95Monthly(result);
|
||||
break;
|
||||
case "7":
|
||||
bandwidth.setEffectiveAvgMonthlyBandwidth95(result);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown bandwidthType: " + data.getBandwidthType());
|
||||
}
|
||||
epsNodeBandwidthMapper.insertEpsNodeBandwidth(bandwidth);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.ruoyi.system.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CalculateUtil {
|
||||
|
||||
private static final Pattern SPEED_PATTERN = Pattern.compile("(\\d+\\.?\\d*)\\s*(\\S*)");
|
||||
/**
|
||||
* 单位换算
|
||||
* @param speedWithUnit
|
||||
* @return
|
||||
*/
|
||||
public static BigDecimal parseSpeedToMbps(String speedWithUnit) {
|
||||
if (speedWithUnit == null || speedWithUnit.trim().isEmpty()) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
Matcher matcher = SPEED_PATTERN.matcher(speedWithUnit.trim());
|
||||
if (!matcher.find()) {
|
||||
throw new IllegalArgumentException("Invalid speed format: " + speedWithUnit);
|
||||
}
|
||||
|
||||
BigDecimal value = new BigDecimal(matcher.group(1));
|
||||
String unit = matcher.group(2).toUpperCase();
|
||||
|
||||
// 处理纯数字(单位为空)
|
||||
if (unit.isEmpty()) {
|
||||
unit = "B/S"; // 默认单位: Bytes/s
|
||||
}
|
||||
|
||||
// 单位换算逻辑(保持不变)
|
||||
switch (unit) {
|
||||
case "B/S":
|
||||
return value.multiply(new BigDecimal("0.000008"));
|
||||
case "KBPS":
|
||||
case "KB/S":
|
||||
return value.divide(new BigDecimal("1000"), 10, RoundingMode.HALF_UP);
|
||||
case "MBPS":
|
||||
case "MB/S":
|
||||
return value;
|
||||
case "GBPS":
|
||||
case "GB/S":
|
||||
return value.multiply(new BigDecimal("1000"));
|
||||
case "TBPS":
|
||||
case "TB/S":
|
||||
return value.multiply(new BigDecimal("1000000"));
|
||||
case "KIB/S":
|
||||
return value.multiply(new BigDecimal("0.008192"));
|
||||
case "MIB/S":
|
||||
return value.multiply(new BigDecimal("8.388608"));
|
||||
case "GIB/S":
|
||||
return value.multiply(new BigDecimal("8589.934592"));
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown speed unit: " + unit);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算百分位值
|
||||
*/
|
||||
public static BigDecimal calculatePercentile(List<BigDecimal> sortedValues, double percentile) {
|
||||
int total = sortedValues.size();
|
||||
int position = (int) Math.ceil(percentile * total) - 1;
|
||||
position = Math.max(0, Math.min(position, total - 1));
|
||||
return sortedValues.get(position).setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
@@ -16,11 +16,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
`out_dropped` DECIMAL(5,2) COMMENT '出站丢包率(%)',
|
||||
`in_speed` varchar(20) COMMENT '接收带宽(Mbps)',
|
||||
`out_speed` varchar(20) COMMENT '发送带宽(Mbps)',
|
||||
business_id varchar(12) COMMENT '业务代码',
|
||||
business_name varchar(50) COMMENT '业务名称',
|
||||
service_sn varchar(50) COMMENT '服务器SN',
|
||||
node_name varchar(50) COMMENT '服务器名称',
|
||||
revenue_method varchar(50) COMMENT '收益方式(1.流量,2包端)',
|
||||
business_id varchar(50) COMMENT '业务代码',
|
||||
business_name varchar(200) COMMENT '业务名称',
|
||||
service_sn varchar(64) COMMENT '服务器SN',
|
||||
node_name varchar(200) COMMENT '服务器名称',
|
||||
revenue_method varchar(10) COMMENT '收益方式(1.流量,2包端)',
|
||||
package_bandwidth DECIMAL(10,2) COMMENT '包端带宽值',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
|
||||
|
||||
@@ -22,7 +22,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="creatorId" column="creator_id" />
|
||||
<result property="creatorName" column="creator_name" />
|
||||
<result property="remark1" column="remark1" />
|
||||
<result property="switchSn" column="switch_sn" />
|
||||
<result property="interfaceName" column="interface_name" />
|
||||
<result property="resourceType" column="resource_type" />
|
||||
<result property="interfaceLinkDeviceType" column="interface_link_device_type" />
|
||||
@@ -34,7 +34,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectEpsNodeBandwidthVo">
|
||||
select id, node_name, hardware_sn, bandwidth_type, bandwidth_result, bandwidth_95_daily, bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, customer_id, customer_name, service_number, uplink_switch, create_time, update_time, creator_id, creator_name, remark1, interface_name, resource_type, interface_link_device_type, effective_bandwidth_95_daily, effective_bandwidth_95_monthly, effective_avg_monthly_bandwidth_95, business_name, business_id from eps_node_bandwidth
|
||||
select id, node_name, hardware_sn, bandwidth_type, bandwidth_result, bandwidth_95_daily, bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, customer_id, customer_name, service_number, uplink_switch, create_time, update_time, creator_id, creator_name, switch_sn, interface_name, resource_type, interface_link_device_type, effective_bandwidth_95_daily, effective_bandwidth_95_monthly, effective_avg_monthly_bandwidth_95, business_name, business_id from eps_node_bandwidth
|
||||
</sql>
|
||||
|
||||
<select id="selectEpsNodeBandwidthList" parameterType="EpsNodeBandwidth" resultMap="EpsNodeBandwidthResult">
|
||||
@@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="uplinkSwitch != null and uplinkSwitch != ''"> and uplink_switch like concat('%', #{uplinkSwitch}, '%')</if>
|
||||
<if test="creatorId != null "> and creator_id = #{creatorId}</if>
|
||||
<if test="creatorName != null and creatorName != ''"> and creator_name like concat('%', #{creatorName}, '%')</if>
|
||||
<if test="remark1 != null and remark1 != ''"> and remark1 = #{remark1}</if>
|
||||
<if test="switchSn != null and switchSn != ''"> and switch_sn = #{switchSn}</if>
|
||||
<if test="interfaceName != null and interfaceName != ''"> and interface_name = #{interfaceName}</if>
|
||||
<if test="resourceType != null and resourceType != ''"> and resource_type = #{resourceType}</if>
|
||||
<if test="interfaceLinkDeviceType != null and interfaceLinkDeviceType != ''"> and interface_link_device_type = #{interfaceLinkDeviceType}</if>
|
||||
@@ -92,7 +92,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">update_time,</if>
|
||||
<if test="creatorId != null">creator_id,</if>
|
||||
<if test="creatorName != null">creator_name,</if>
|
||||
<if test="remark1 != null">remark1,</if>
|
||||
<if test="switchSn != null">switch_sn,</if>
|
||||
<if test="interfaceName != null">interface_name,</if>
|
||||
<if test="resourceType != null">resource_type,</if>
|
||||
<if test="interfaceLinkDeviceType != null">interface_link_device_type,</if>
|
||||
@@ -119,7 +119,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">#{updateTime},</if>
|
||||
<if test="creatorId != null">#{creatorId},</if>
|
||||
<if test="creatorName != null">#{creatorName},</if>
|
||||
<if test="remark1 != null">#{remark1},</if>
|
||||
<if test="switchSn != null">#{switchSn},</if>
|
||||
<if test="interfaceName != null">#{interfaceName},</if>
|
||||
<if test="resourceType != null">#{resourceType},</if>
|
||||
<if test="interfaceLinkDeviceType != null">#{interfaceLinkDeviceType},</if>
|
||||
@@ -150,7 +150,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
<if test="creatorId != null">creator_id = #{creatorId},</if>
|
||||
<if test="creatorName != null">creator_name = #{creatorName},</if>
|
||||
<if test="remark1 != null">remark1 = #{remark1},</if>
|
||||
<if test="switchSn != null">switch_sn = #{switchSn},</if>
|
||||
<if test="interfaceName != null">interface_name = #{interfaceName},</if>
|
||||
<if test="resourceType != null">resource_type = #{resourceType},</if>
|
||||
<if test="interfaceLinkDeviceType != null">interface_link_device_type = #{interfaceLinkDeviceType},</if>
|
||||
@@ -174,17 +174,32 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<select id="calculateAvg" parameterType="EpsNodeBandwidth" resultMap="EpsNodeBandwidthResult">
|
||||
<select id="calculateAvg" parameterType="EpsNodeBandwidth" resultType="EpsNodeBandwidth">
|
||||
select sum(ifnull(bandwidth_95_daily,0)) bandwidth95Daily,
|
||||
sum(ifnull(effective_bandwidth_95_daily,0)) effectiveBandwidth95Daily
|
||||
from eps_node_bandwidth
|
||||
<where>
|
||||
<if test="createTime != null">
|
||||
and left(create_time,7) = #{createTime}
|
||||
<if test="startTime != null">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
<if test="monthTime != null">
|
||||
and left(create_time,7) = #{monthTime}
|
||||
</if>
|
||||
<if test="nodeName != '' and nodeName != null">
|
||||
and node_name = #{nodeName}
|
||||
</if>
|
||||
<if test="hardwareSn != '' and hardwareSn != null">
|
||||
and hardware_sn = #{hardwareSn}
|
||||
</if>
|
||||
<if test="switchSn != '' and switchSn != null">
|
||||
and switch_sn = #{switchSn}
|
||||
</if>
|
||||
<if test="interfaceName != '' and interfaceName != null">
|
||||
and interface_name = #{interfaceName}
|
||||
</if>
|
||||
<if test="businessName != '' and businessName != null">
|
||||
and business_name = #{businessName}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user