交换机流量数据表改为分表
This commit is contained in:
+2
-2
@@ -20,7 +20,7 @@ public class TableSubUtil {
|
||||
* @throws IllegalArgumentException 如果createTime为null
|
||||
*
|
||||
* 示例:
|
||||
* 2023-08-05 14:30:00 → rm_mtr_probe_result_2023_08_01_10
|
||||
* 2023-08-05 14:30:00 → rm_mtr_probe_result_2023_08_1_10
|
||||
* 2023-08-15 09:15:00 → rm_mtr_probe_result_2023_08_11_20
|
||||
* 2023-08-25 18:45:00 → rm_mtr_probe_result_2023_08_21_31
|
||||
*/
|
||||
@@ -93,7 +93,7 @@ public class TableSubUtil {
|
||||
throw new IllegalArgumentException("日期必须在1-31之间");
|
||||
}
|
||||
|
||||
if (day <= 10) return "01_10";
|
||||
if (day <= 10) return "1_10";
|
||||
if (day <= 20) return "11_20";
|
||||
return "21_31";
|
||||
}
|
||||
|
||||
+2
-7
@@ -208,15 +208,10 @@ public class EpsNodeBandwidthController extends BaseController
|
||||
}
|
||||
return getDataTable(pageInfo.getList(), pageInfo.getTotal());
|
||||
} else{
|
||||
// 4. 设置分页参数
|
||||
PageDomain pageDomain = new PageDomain();
|
||||
pageDomain.setPageNum(epsNodeBandwidth.getPageNum());
|
||||
pageDomain.setPageSize(epsNodeBandwidth.getPageSize());
|
||||
startPage(pageDomain);
|
||||
// 处理交换机信息
|
||||
List<InitialSwitchInfoDetails> switchInfoDetails = initialSwitchInfoDetailsService.getRelevantSwitch(
|
||||
PageInfo<InitialSwitchInfoDetails> pageInfo = initialSwitchInfoDetailsService.getRelevantSwitch(
|
||||
epsNodeBandwidth, dailyStartTime, dailyEndTime);
|
||||
return getDataTable(switchInfoDetails);
|
||||
return getDataTable(pageInfo.getList(), pageInfo.getTotal());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取ID为{}的相关数据失败", id, e);
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.system.controller;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.poi.ExcelUtil;
|
||||
import com.ruoyi.common.core.web.controller.BaseController;
|
||||
@@ -104,7 +105,7 @@ public class InitialSwitchInfoDetailsController extends BaseController
|
||||
@PostMapping("/autoSaveSwitchTraffic")
|
||||
public R<String> autoSaveSwitchTraffic(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
|
||||
{
|
||||
return initialSwitchInfoDetailsService.autoSaveSwitchTraffic(initialSwitchInfoDetails);
|
||||
return initialSwitchInfoDetailsService.autoSaveSwitchTrafficSharding(initialSwitchInfoDetails);
|
||||
}
|
||||
/**
|
||||
* 图形分析-95带宽值mbps/日 v1.1
|
||||
@@ -144,7 +145,7 @@ public class InitialSwitchInfoDetailsController extends BaseController
|
||||
@PostMapping("/geSwitchListByMonitorView")
|
||||
public TableDataInfo geSwitchListByMonitorView(@RequestBody InitialSwitchInfoDetails initialSwitchInfoDetails)
|
||||
{
|
||||
List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsService.geSwitchListByMonitorView(initialSwitchInfoDetails);
|
||||
return getDataTable(list);
|
||||
PageInfo pageInfo = initialSwitchInfoDetailsService.geSwitchListByMonitorView(initialSwitchInfoDetails);
|
||||
return getDataTable(pageInfo.getList(), pageInfo.getTotal());
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -128,4 +128,6 @@ public class InitialSwitchInfoDetails extends BaseEntity
|
||||
private String unit;
|
||||
/** 监控看板概览id */
|
||||
private Long monitorId;
|
||||
/** 表名 */
|
||||
private String tableName;
|
||||
}
|
||||
|
||||
+13
@@ -22,6 +22,19 @@ public interface EpsInitialTrafficDataMapper {
|
||||
* @param tableName
|
||||
*/
|
||||
void createMtrProbeResultTable(@Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
* 创建交换机初始流量表
|
||||
* @param tableName
|
||||
*/
|
||||
void createSwitchInfoTable(@Param("tableName") String tableName);
|
||||
|
||||
/**
|
||||
* 创建交换机业务流量表
|
||||
* @param tableName
|
||||
*/
|
||||
|
||||
void createSwitchInfoDetailsTable(@Param("tableName") String tableName);
|
||||
/**
|
||||
* 单条插入数据
|
||||
* @param data 流量数据
|
||||
|
||||
+28
@@ -69,6 +69,13 @@ public interface InitialSwitchInfoDetailsMapper
|
||||
*/
|
||||
int saveBatchSwitchTraffic(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 批量新增交换机流量业务数据
|
||||
* @param initialSwitchInfoDetails
|
||||
* @return
|
||||
*/
|
||||
int saveBatchSwitchTrafficSharding(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 查询交换机信息
|
||||
* @param initialSwitchInfoDetails
|
||||
@@ -89,4 +96,25 @@ public interface InitialSwitchInfoDetailsMapper
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> geSwitchListByMonitorView(InitialSwitchInfoDetails queryParam);
|
||||
|
||||
/**
|
||||
* 分表查询流量数据
|
||||
* @param initialSwitchInfoDetails
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> getAllSwitchInfoMsgSharding(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 分表查询业务表流量数据
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> getSwitchDetailListSharding(InitialSwitchInfoDetails condition);
|
||||
|
||||
/**
|
||||
* 分表查询业务表信息
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> selectInitialSwitchInfoDetailsListSharding(InitialSwitchInfoDetails condition);
|
||||
}
|
||||
|
||||
+16
-2
@@ -1,5 +1,6 @@
|
||||
package com.ruoyi.system.service;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.system.domain.EpsNodeBandwidth;
|
||||
import com.ruoyi.system.domain.InitialSwitchInfoDetails;
|
||||
@@ -70,6 +71,12 @@ public interface IInitialSwitchInfoDetailsService
|
||||
*/
|
||||
R<String> autoSaveSwitchTraffic(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 保存交换机流量信息
|
||||
* @param initialSwitchInfoDetails
|
||||
*/
|
||||
R<String> autoSaveSwitchTrafficSharding(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 计算交换机95带宽值
|
||||
* @param queryParam 查询参数实体
|
||||
@@ -90,7 +97,7 @@ public interface IInitialSwitchInfoDetailsService
|
||||
* @param epsNodeBandwidth
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> getRelevantSwitch(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime);
|
||||
PageInfo<InitialSwitchInfoDetails> getRelevantSwitch(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime);
|
||||
/**
|
||||
* 当前在线交换机接收带宽总流量
|
||||
* @return
|
||||
@@ -123,5 +130,12 @@ public interface IInitialSwitchInfoDetailsService
|
||||
* @param initialSwitchInfoDetails
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfoDetails> geSwitchListByMonitorView(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
PageInfo geSwitchListByMonitorView(InitialSwitchInfoDetails initialSwitchInfoDetails);
|
||||
|
||||
/**
|
||||
* 选中的交换机流量求和
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<InitialSwitchInfoDetails> sumSwitchTrafficDetailsSharding(InitialSwitchInfoDetails queryParam);
|
||||
}
|
||||
|
||||
+14
@@ -66,6 +66,10 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
createTrafficStatsTable(year, month);
|
||||
// 创建mtr探测丢包结果表
|
||||
createMtrProbeResultTable(year, month);
|
||||
// 创建交换机流量初始表
|
||||
createSwitchInfoTable(year, month);
|
||||
// 创建交换机流量业务表
|
||||
createSwitchInfoDetailsTable(year, month);
|
||||
}
|
||||
|
||||
private void createTrafficDetailsTable(int year, int month) {
|
||||
@@ -85,6 +89,16 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
|
||||
epsInitialTrafficDataMapper.createMtrProbeResultTable(tableName);
|
||||
});
|
||||
}
|
||||
private void createSwitchInfoTable(int year, int month) {
|
||||
createRangeTables(year, month, "initial_switch_info", (tableName) -> {
|
||||
epsInitialTrafficDataMapper.createSwitchInfoTable(tableName);
|
||||
});
|
||||
}
|
||||
private void createSwitchInfoDetailsTable(int year, int month) {
|
||||
createRangeTables(year, month, "initial_switch_info_details", (tableName) -> {
|
||||
epsInitialTrafficDataMapper.createSwitchInfoDetailsTable(tableName);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
||||
+4
-4
@@ -165,8 +165,8 @@ public class EpsTaskStatisticsServiceImpl implements IEpsTaskStatisticsService
|
||||
queryParam.setBusinessCode(epsTaskStatistics.getBusinessCode());
|
||||
queryParam.setClientIds(clientIds);
|
||||
queryParam.setInterfaceNames(interfaceNames);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.sumSwitchTrafficByclientIds(queryParam);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsService
|
||||
.sumSwitchTrafficDetailsSharding(queryParam);
|
||||
if(!dataList.isEmpty()){
|
||||
trafficRedisHashUtil.saveListToHash(epsTaskStatistics.getId().toString(), dataList);
|
||||
processSwitch95Data(dataList, epsTaskStatistics);
|
||||
@@ -189,8 +189,8 @@ public class EpsTaskStatisticsServiceImpl implements IEpsTaskStatisticsService
|
||||
queryParam.setBusinessCode(epsTaskStatistics.getBusinessCode());
|
||||
queryParam.setClientIds(clientIds);
|
||||
queryParam.setInterfaceNames(interfaceNames);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.sumSwitchTrafficByclientIds(queryParam);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsService
|
||||
.sumSwitchTrafficDetailsSharding(queryParam);
|
||||
if(!dataList.isEmpty()){
|
||||
trafficRedisHashUtil.saveListToHash(epsTaskStatistics.getId().toString(), dataList);
|
||||
}
|
||||
|
||||
+191
-21
@@ -1,16 +1,15 @@
|
||||
package com.ruoyi.system.service.impl;
|
||||
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.ruoyi.common.core.domain.R;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.EchartsDataUtils;
|
||||
import com.ruoyi.common.core.utils.SpeedUtils;
|
||||
import com.ruoyi.common.core.utils.StringUtils;
|
||||
import com.ruoyi.common.core.utils.*;
|
||||
import com.ruoyi.common.core.web.page.PageDomain;
|
||||
import com.ruoyi.system.domain.*;
|
||||
import com.ruoyi.system.enums.ReviewEnum;
|
||||
import com.ruoyi.system.mapper.*;
|
||||
import com.ruoyi.system.service.IInitialSwitchInfoDetailsService;
|
||||
import com.ruoyi.system.util.CalculateUtil;
|
||||
import com.ruoyi.system.util.PaginationUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -63,6 +62,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
private RmMonitorConfigMapper rmMonitorConfigMapper;
|
||||
|
||||
private static final String DATE_TIME_FORMATTER = "yyyy-MM-dd HH:mm:ss";
|
||||
private final static String TABLE_PREFIX = "initial_switch_info_details";
|
||||
|
||||
/**
|
||||
* 查询交换机监控信息
|
||||
@@ -217,6 +217,111 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流量初始表流量信息
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<InitialSwitchInfoDetails> getSwitchTrafficMsgSharding(InitialSwitchInfoDetails queryParam) {
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getTableNamesBetween(queryParam.getStartTime(), queryParam.getEndTime(), "initial_switch_info");
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
InitialSwitchInfoDetails condition = new InitialSwitchInfoDetails();
|
||||
condition.setTableName(tableName);
|
||||
condition.setClientId(queryParam.getClientId());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return initialSwitchInfoDetailsMapper.getAllSwitchInfoMsgSharding(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 保存交换机流量信息
|
||||
* @param initialSwitchInfoDetails
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
||||
@Override
|
||||
public R<String> autoSaveSwitchTrafficSharding(InitialSwitchInfoDetails initialSwitchInfoDetails) {
|
||||
// 查询初始流量数据
|
||||
List<InitialSwitchInfoDetails> dataList = getSwitchTrafficMsgSharding(initialSwitchInfoDetails);
|
||||
List<InitialSwitchInfoDetails> batchList = new ArrayList<>();
|
||||
if(!dataList.isEmpty()){
|
||||
for (InitialSwitchInfoDetails details : dataList) {
|
||||
// 取发送或接收流量最大值赋值到maxSpeed
|
||||
calculateMaxSpeed(details);
|
||||
// id自增
|
||||
details.setId(null);
|
||||
// 根据接口名称查询交换机信息
|
||||
String interfaceName = details.getName();
|
||||
RmEpsTopologyManagement rmEpsTopologyManagement = new RmEpsTopologyManagement();
|
||||
rmEpsTopologyManagement.setInterfaceName(interfaceName);
|
||||
rmEpsTopologyManagement.setClientId(details.getClientId());
|
||||
List<RmEpsTopologyManagement> managements = rmEpsTopologyManagementMapper.selectRmEpsTopologyManagementList(rmEpsTopologyManagement);
|
||||
// 赋值
|
||||
if(!managements.isEmpty()){
|
||||
for (RmEpsTopologyManagement management : managements) {
|
||||
details.setSwitchSn(management.getSwitchSn());
|
||||
details.setSwitchName(management.getSwitchName());
|
||||
details.setInterfaceDeviceType(management.getConnectedDeviceType());
|
||||
details.setServerName(management.getServerName());
|
||||
details.setServerPort(management.getServerPort());
|
||||
details.setServerClientId(management.getServerClientId());
|
||||
// 查询端口备注信息
|
||||
RmSwitchInterfaceInfo queryOtheName = new RmSwitchInterfaceInfo();
|
||||
queryOtheName.setClientId(details.getClientId());
|
||||
queryOtheName.setInterfaceName(management.getInterfaceName());
|
||||
List<RmSwitchInterfaceInfo> interfaceInfos = rmSwitchInterfaceInfoMapper.selectRmSwitchInterfaceInfoList(queryOtheName);
|
||||
if(!interfaceInfos.isEmpty()){
|
||||
// 接口别名
|
||||
details.setInterfaceNameRemark(interfaceInfos.get(0).getInterfaceRemark());
|
||||
}
|
||||
// 根据服务器sn查询业务
|
||||
if(management.getServerClientId() != null){
|
||||
String serverClientId = management.getServerClientId();
|
||||
// 查询业务信息
|
||||
EpsBusinessDeploy queryBD = new EpsBusinessDeploy();
|
||||
queryBD.setClientId(serverClientId);
|
||||
queryBD.setReviewStatus(ReviewEnum.通过.getCode());
|
||||
List<EpsBusinessDeploy> businessDeploys = epsBusinessDeployMapper.selectEpsBusinessDeployList(queryBD);
|
||||
if(!businessDeploys.isEmpty()){
|
||||
details.setBusinessCode(businessDeploys.get(0).getBusinessCode());
|
||||
details.setBusinessName(businessDeploys.get(0).getBusinessName());
|
||||
}
|
||||
}else {
|
||||
details.setBusinessCode(null);
|
||||
details.setBusinessName(null);
|
||||
}
|
||||
batchList.add(details);
|
||||
}
|
||||
}else{
|
||||
batchList.add(details);
|
||||
}
|
||||
}
|
||||
}
|
||||
initialSwitchInfoDetails.setDataList(batchList);
|
||||
Date createTime = DateUtils.parseDate(initialSwitchInfoDetails.getStartTime());
|
||||
initialSwitchInfoDetails.setTableName(TableSubUtil.getTableName(createTime, TABLE_PREFIX));
|
||||
if(batchList.isEmpty()){
|
||||
return R.fail("交换机流量数据为空");
|
||||
}else{
|
||||
// 流量相关数据入库
|
||||
try {
|
||||
initialSwitchInfoDetailsMapper.saveBatchSwitchTrafficSharding(initialSwitchInfoDetails);
|
||||
log.info("交换机流量数据批量入库成功,数据量:{}", batchList.size());
|
||||
// 接口名称保存
|
||||
processSwitchInterfaceNames(batchList);
|
||||
return R.ok("数据保存成功");
|
||||
} catch (Exception e) {
|
||||
log.error("交换机流量数据入库失败,数据量:{},错误原因:{}",
|
||||
batchList.size(), e.getMessage(), e);
|
||||
return R.fail("数据保存失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 辅助方法
|
||||
* 获取 inSpeed 和 outSpeed 的最大值并设置到 maxSpeed
|
||||
@@ -392,8 +497,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
switchInfoDetails.setName(epsNodeBandwidth.getInterfaceName());
|
||||
switchInfoDetails.setBusinessCode(epsNodeBandwidth.getBusinessId());
|
||||
switchInfoDetails.setBusinessName(epsNodeBandwidth.getBusinessName());
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(switchInfoDetails);
|
||||
List<InitialSwitchInfoDetails> dataList = getSwitchTrafficDetailsListSharding(switchInfoDetails);
|
||||
if(!dataList.isEmpty()){
|
||||
// 1. 提取并转换带宽值
|
||||
List<BigDecimal> speedsInMbps = dataList.stream()
|
||||
@@ -428,7 +532,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<InitialSwitchInfoDetails> getRelevantSwitch(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime) {
|
||||
public PageInfo<InitialSwitchInfoDetails> getRelevantSwitch(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime) {
|
||||
InitialSwitchInfoDetails switchInfoDetails = new InitialSwitchInfoDetails();
|
||||
switchInfoDetails.setStartTime(dailyStartTime);
|
||||
switchInfoDetails.setEndTime(dailyEndTime);
|
||||
@@ -439,9 +543,9 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
switchInfoDetails.setName(epsNodeBandwidth.getInterfaceName());
|
||||
switchInfoDetails.setBusinessCode(epsNodeBandwidth.getBusinessId());
|
||||
// switchInfoDetails.setBusinessName(epsNodeBandwidth.getBusinessName());
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(switchInfoDetails);
|
||||
return dataList;
|
||||
List<InitialSwitchInfoDetails> dataList = getSwitchTrafficDetailsListSharding(switchInfoDetails);
|
||||
PageInfo<InitialSwitchInfoDetails> pageInfo = PaginationUtil.paginate(dataList, epsNodeBandwidth.getPageNum(), epsNodeBandwidth.getPageSize());
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -461,8 +565,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
InitialSwitchInfoDetails switchInfoDetails = new InitialSwitchInfoDetails();
|
||||
switchInfoDetails.setStartTime(dailyStartTime);
|
||||
switchInfoDetails.setEndTime(dailyEndTime);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(switchInfoDetails);
|
||||
List<InitialSwitchInfoDetails> dataList = getSwitchTrafficDetailsListSharding(switchInfoDetails);
|
||||
if(!dataList.isEmpty()){
|
||||
for (InitialSwitchInfoDetails initialSwitchInfoDetails : dataList) {
|
||||
// 交换机接收带宽流量
|
||||
@@ -545,8 +648,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
String dailyEndTime, String calculationMode) {
|
||||
queryParam.setStartTime(dailyStartTime);
|
||||
queryParam.setEndTime(dailyEndTime);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(queryParam);
|
||||
List<InitialSwitchInfoDetails> dataList = getSwitchTrafficDetailsListSharding(queryParam);
|
||||
|
||||
if (!dataList.isEmpty()) {
|
||||
calculateAndSaveSwitch95Bandwidth(dataList, dailyStartTime, queryParam.getDayOrMonth(), calculationMode);
|
||||
@@ -618,8 +720,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
private void calculateSwitchSegment95(InitialSwitchInfoDetails queryParam, String startTime, String endTime, String calculationMode) {
|
||||
queryParam.setStartTime(startTime);
|
||||
queryParam.setEndTime(endTime);
|
||||
List<InitialSwitchInfoDetails> dataList = initialSwitchInfoDetailsMapper
|
||||
.selectInitialSwitchInfoDetailsList(queryParam);
|
||||
List<InitialSwitchInfoDetails> dataList = getSwitchTrafficDetailsListSharding(queryParam);
|
||||
if (!dataList.isEmpty()) {
|
||||
calculateSwitch95BandwidthDaily(dataList, startTime, queryParam.getDayOrMonth(), calculationMode);
|
||||
}
|
||||
@@ -952,7 +1053,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
queryParam.setEndTime(endTime);
|
||||
queryParam.setClientIds(clientIds);
|
||||
queryParam.setInterfaceNames(interfaceNames);
|
||||
List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsMapper.sumSwitchTrafficByclientIds(queryParam);
|
||||
List<InitialSwitchInfoDetails> list = sumSwitchTrafficDetailsSharding(queryParam);
|
||||
return list;
|
||||
}
|
||||
return null;
|
||||
@@ -963,7 +1064,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<InitialSwitchInfoDetails> geSwitchListByMonitorView(InitialSwitchInfoDetails initialSwitchInfoDetails) {
|
||||
public PageInfo geSwitchListByMonitorView(InitialSwitchInfoDetails initialSwitchInfoDetails) {
|
||||
// 拿到选中的交换机
|
||||
String resources = initialSwitchInfoDetails.getClientIds();
|
||||
String clientIds = Arrays.stream(resources.split(","))
|
||||
@@ -983,17 +1084,19 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
pageDomain.setPageNum(initialSwitchInfoDetails.getPageNum());
|
||||
pageDomain.setPageSize(initialSwitchInfoDetails.getPageSize());
|
||||
startPage(pageDomain);
|
||||
List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsMapper.geSwitchListByMonitorView(initialSwitchInfoDetails);
|
||||
return list;
|
||||
List<InitialSwitchInfoDetails> list = getSwitchTrafficDetailsMsgSharding(initialSwitchInfoDetails);
|
||||
PageInfo pageInfo = PaginationUtil.paginate(list, initialSwitchInfoDetails.getPageNum(), initialSwitchInfoDetails.getPageSize());
|
||||
return pageInfo;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取交换机网口网络速率
|
||||
* @param initialSwitchInfoDetails
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> switchNetSpeedEcharts(InitialSwitchInfoDetails initialSwitchInfoDetails, BigDecimal percentile95) {
|
||||
List<InitialSwitchInfoDetails> list = initialSwitchInfoDetailsMapper.getswitchDetailList(initialSwitchInfoDetails);
|
||||
List<InitialSwitchInfoDetails> list = getSwitchTrafficDetailsMsgSharding(initialSwitchInfoDetails);
|
||||
if(list == null){
|
||||
list = new ArrayList<>();
|
||||
}
|
||||
@@ -1031,4 +1134,71 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
|
||||
}
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* 查询流量业务表流量信息
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<InitialSwitchInfoDetails> getSwitchTrafficDetailsMsgSharding(InitialSwitchInfoDetails queryParam) {
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getTableNamesBetween(queryParam.getStartTime(), queryParam.getEndTime(), TABLE_PREFIX);
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
InitialSwitchInfoDetails condition = new InitialSwitchInfoDetails();
|
||||
condition.setTableName(tableName);
|
||||
condition.setClientId(queryParam.getClientId());
|
||||
condition.setName(queryParam.getName());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return initialSwitchInfoDetailsMapper.getSwitchDetailListSharding(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
/**
|
||||
* 选中的交换机流量求和
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<InitialSwitchInfoDetails> sumSwitchTrafficDetailsSharding(InitialSwitchInfoDetails queryParam) {
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getTableNamesBetween(queryParam.getStartTime(), queryParam.getEndTime(), TABLE_PREFIX);
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
InitialSwitchInfoDetails condition = new InitialSwitchInfoDetails();
|
||||
condition.setTableName(tableName);
|
||||
condition.setClientIds(queryParam.getClientIds());
|
||||
condition.setInterfaceNames(queryParam.getInterfaceNames());
|
||||
condition.setBusinessCode(queryParam.getBusinessCode());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return initialSwitchInfoDetailsMapper.sumSwitchTrafficByclientIds(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询流量业务表流量信息
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<InitialSwitchInfoDetails> getSwitchTrafficDetailsListSharding(InitialSwitchInfoDetails queryParam) {
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getTableNamesBetween(queryParam.getStartTime(), queryParam.getEndTime(), TABLE_PREFIX);
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
InitialSwitchInfoDetails condition = new InitialSwitchInfoDetails();
|
||||
BeanUtils.copyProperties(queryParam, condition);
|
||||
condition.setTableName(tableName);
|
||||
return initialSwitchInfoDetailsMapper.selectInitialSwitchInfoDetailsListSharding(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-19
@@ -95,35 +95,41 @@ public class RmResourceRegistrationServiceImpl implements IRmResourceRegistratio
|
||||
setNetWorkMsg(resourceRegistration);
|
||||
}
|
||||
}
|
||||
if(rmResourceRegistration.getQueryParam() != null && rmResourceRegistration.getQueryParam() != ""){
|
||||
String queryValue = rmResourceRegistration.getQueryParam().trim();
|
||||
// 筛选公网IP私网IP设备SN相等的数据
|
||||
if(rmResourceRegistration.getQueryParam() != null && !rmResourceRegistration.getQueryParam().trim().isEmpty()){
|
||||
String queryValue = rmResourceRegistration.getQueryParam().trim().toLowerCase(); // 转为小写便于模糊匹配
|
||||
|
||||
// 从rmResourceRegistrationList列表中筛选符合条件的数据
|
||||
List<RmResourceRegistration> filteredList = rmResourceRegistrationList.stream()
|
||||
.filter(item -> item != null)
|
||||
.filter(item ->
|
||||
// 检查公网IP (IP1-3和管理网)
|
||||
queryValue.equals(item.getIp1PublicIp()) ||
|
||||
queryValue.equals(item.getIp2PublicIp()) ||
|
||||
queryValue.equals(item.getIp3PublicIp()) ||
|
||||
queryValue.equals(item.getMgmtPublicIp()) ||
|
||||
.filter(item -> {
|
||||
// 如果查询值为空,返回所有数据
|
||||
if (queryValue.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 检查私网IP (IP1-3和管理网)
|
||||
queryValue.equals(item.getIp1Ipv4Address()) ||
|
||||
queryValue.equals(item.getIp2Ipv4Address()) ||
|
||||
queryValue.equals(item.getIp3Ipv4Address()) ||
|
||||
queryValue.equals(item.getMgmtIpv4Address()) ||
|
||||
// 检查公网IP (IP1-3和管理网)
|
||||
return (item.getIp1PublicIp() != null && item.getIp1PublicIp().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp2PublicIp() != null && item.getIp2PublicIp().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp3PublicIp() != null && item.getIp3PublicIp().toLowerCase().contains(queryValue)) ||
|
||||
(item.getMgmtPublicIp() != null && item.getMgmtPublicIp().toLowerCase().contains(queryValue)) ||
|
||||
|
||||
// 检查设备SN
|
||||
queryValue.equals(item.getHardwareSn()) ||
|
||||
queryValue.equals(item.getClientId())
|
||||
)
|
||||
// 检查私网IP (IP1-3和管理网)
|
||||
(item.getIp1Ipv4Address() != null && item.getIp1Ipv4Address().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp2Ipv4Address() != null && item.getIp2Ipv4Address().toLowerCase().contains(queryValue)) ||
|
||||
(item.getIp3Ipv4Address() != null && item.getIp3Ipv4Address().toLowerCase().contains(queryValue)) ||
|
||||
(item.getMgmtIpv4Address() != null && item.getMgmtIpv4Address().toLowerCase().contains(queryValue)) ||
|
||||
|
||||
// 检查设备SN
|
||||
(item.getHardwareSn() != null && item.getHardwareSn().toLowerCase().contains(queryValue)) ||
|
||||
(item.getClientId() != null && item.getClientId().toLowerCase().contains(queryValue));
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
List<RmResourceRegistration> pageInfo = applyPagination(filteredList, rmResourceRegistration.getPageNum(), rmResourceRegistration.getPageSize());
|
||||
resultMap.put("list", pageInfo);
|
||||
resultMap.put("total", filteredList.size());
|
||||
return resultMap;
|
||||
}else{
|
||||
} else {
|
||||
resultMap.put("list", rmResourceRegistrationList);
|
||||
}
|
||||
return resultMap;
|
||||
|
||||
+70
@@ -82,6 +82,76 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
INDEX idx_mtr_client_id (mtr_client_id, create_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='网络mtr探测结果表';
|
||||
</update>
|
||||
<update id="createSwitchInfoTable">
|
||||
CREATE TABLE IF NOT EXISTS ${tableName} (
|
||||
id BIGINT(20) AUTO_INCREMENT COMMENT '主键ID',
|
||||
client_id VARCHAR(255) NOT NULL COMMENT '客户端ID',
|
||||
name VARCHAR(100) NOT NULL COMMENT '网络接口名称',
|
||||
switch_ip VARCHAR(100) COMMENT '交换机IP',
|
||||
in_bytes DECIMAL(22,0) COMMENT '接收流量(字节)',
|
||||
out_bytes DECIMAL(22,0) COMMENT '发送流量(字节)',
|
||||
in_speed DECIMAL(20,2) DEFAULT 0.00 COMMENT '接收速率(bit/s)',
|
||||
out_speed DECIMAL(20,2) DEFAULT 0.00 COMMENT '发送速率(bit/s)',
|
||||
max_speed DECIMAL(20,0) COMMENT '流量最大值',
|
||||
status VARCHAR(20) COMMENT '接口状态',
|
||||
type VARCHAR(30) COMMENT '接口类型',
|
||||
if_speed VARCHAR(50) COMMENT '端口速率(Mbps)',
|
||||
if_index VARCHAR(50) COMMENT '端口索引',
|
||||
if_in_discards VARCHAR(50) COMMENT '入站丢包',
|
||||
if_out_discards VARCHAR(50) COMMENT '出站丢包',
|
||||
if_in_errors VARCHAR(50) COMMENT '入站错误',
|
||||
if_out_errors VARCHAR(50) COMMENT '出站错误',
|
||||
create_time DATETIME COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
create_by VARCHAR(50) COMMENT '创建人',
|
||||
update_by VARCHAR(50) COMMENT '更新人',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_switch_record (client_id, switch_ip, name, create_time),
|
||||
INDEX idx_create_time (create_time),
|
||||
INDEX idx_draw (client_id, name, create_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='交换机监控信息表';
|
||||
</update>
|
||||
|
||||
<update id="createSwitchInfoDetailsTable">
|
||||
CREATE TABLE IF NOT EXISTS ${tableName} (
|
||||
id BIGINT(20) AUTO_INCREMENT COMMENT '主键ID',
|
||||
client_id VARCHAR(255) NOT NULL COMMENT '客户端ID',
|
||||
name VARCHAR(100) NOT NULL COMMENT '网络接口名称',
|
||||
switch_ip VARCHAR(100) COMMENT '交换机IP',
|
||||
switch_name VARCHAR(100) COMMENT '交换机名称',
|
||||
switch_sn VARCHAR(64) COMMENT '交换机SN',
|
||||
in_bytes DECIMAL(22,2) COMMENT '接收流量(字节)',
|
||||
out_bytes DECIMAL(22,2) COMMENT '发送流量(字节)',
|
||||
in_speed DECIMAL(20,2) COMMENT '接收速率(bit/s)',
|
||||
out_speed DECIMAL(20,2) COMMENT '发送速率(bit/s)',
|
||||
max_speed DECIMAL(20,2) COMMENT '流量最大值',
|
||||
status VARCHAR(20) COMMENT '接口状态',
|
||||
type VARCHAR(30) COMMENT '接口类型',
|
||||
interface_device_type VARCHAR(50) COMMENT '连接设备类型',
|
||||
interface_name_remark VARCHAR(255) COMMENT '接口别名',
|
||||
server_name VARCHAR(100) COMMENT '服务器名称',
|
||||
server_client_id VARCHAR(255) COMMENT '服务器客户端ID',
|
||||
server_port VARCHAR(200) COMMENT '服务器网口',
|
||||
server_sn VARCHAR(64) COMMENT '服务器SN',
|
||||
business_code VARCHAR(100) COMMENT '业务代码',
|
||||
business_name VARCHAR(200) COMMENT '业务名称',
|
||||
if_speed VARCHAR(50) COMMENT '端口速率(Mbps)',
|
||||
if_index VARCHAR(50) COMMENT '端口索引',
|
||||
if_in_discards VARCHAR(50) COMMENT '入站丢包',
|
||||
if_out_discards VARCHAR(50) COMMENT '出站丢包',
|
||||
if_in_errors VARCHAR(50) COMMENT '入站错误',
|
||||
if_out_errors VARCHAR(50) COMMENT '出站错误',
|
||||
create_time DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
create_by VARCHAR(50) COMMENT '创建人',
|
||||
update_by VARCHAR(50) COMMENT '更新人',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY uk_switch_detail (client_id, switch_ip, name, create_time),
|
||||
INDEX idx_filter_sort (name, interface_device_type, switch_sn, create_time),
|
||||
INDEX idx_create_time (create_time),
|
||||
INDEX idx_client_time (client_id, name, create_time)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='交换机监控详情表';
|
||||
</update>
|
||||
|
||||
<!-- 单条插入语句 -->
|
||||
<insert id="insert">
|
||||
|
||||
+193
-1
@@ -41,6 +41,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
<sql id="selectInitialSwitchInfoDetailsVo">
|
||||
select id, client_id, name, in_bytes, out_bytes, status, type, in_speed, out_speed, switch_ip, create_by, update_by, create_time, update_time, switch_name, interface_device_type, server_name, server_port, server_sn, switch_sn, business_code, business_name, if_speed, if_in_discards, if_out_discards, if_in_errors, if_out_errors, if_index, max_speed, interface_name_remark, server_client_id from initial_switch_info_details
|
||||
</sql>
|
||||
<sql id="selectInitialSwitchInfoDetailsVoSharding">
|
||||
select id, client_id, name, in_bytes, out_bytes, status, type, in_speed, out_speed, switch_ip, create_by, update_by, create_time, update_time, switch_name, interface_device_type, server_name, server_port, server_sn, switch_sn, business_code, business_name, if_speed, if_in_discards, if_out_discards, if_in_errors, if_out_errors, if_index, max_speed, interface_name_remark, server_client_id from ${tableName}
|
||||
</sql>
|
||||
|
||||
<select id="selectInitialSwitchInfoDetailsList" parameterType="InitialSwitchInfoDetails" resultMap="InitialSwitchInfoDetailsResult">
|
||||
<include refid="selectInitialSwitchInfoDetailsVo"/>
|
||||
@@ -311,6 +314,90 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<insert id="saveBatchSwitchTrafficSharding" parameterType="InitialSwitchInfoDetails">
|
||||
INSERT IGNORE INTO ${tableName}
|
||||
(
|
||||
client_id,
|
||||
`name`,
|
||||
in_bytes,
|
||||
out_bytes,
|
||||
status,
|
||||
`type`,
|
||||
in_speed,
|
||||
out_speed,
|
||||
max_speed,
|
||||
switch_ip,
|
||||
if_index,
|
||||
if_speed,
|
||||
if_in_discards,
|
||||
if_out_discards,
|
||||
if_in_errors,
|
||||
if_out_errors,
|
||||
switch_name,
|
||||
interface_device_type,
|
||||
`server_name`,
|
||||
server_port,
|
||||
server_sn,
|
||||
switch_sn,
|
||||
business_code,
|
||||
business_name,
|
||||
create_by,
|
||||
update_by,
|
||||
create_time,
|
||||
update_time,
|
||||
interface_name_remark,
|
||||
server_client_id
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="dataList" item="item" separator=",">
|
||||
(
|
||||
#{item.clientId},
|
||||
#{item.name},
|
||||
#{item.inBytes},
|
||||
#{item.outBytes},
|
||||
#{item.status},
|
||||
#{item.type},
|
||||
#{item.inSpeed},
|
||||
#{item.outSpeed},
|
||||
#{item.maxSpeed},
|
||||
#{item.switchIp},
|
||||
#{item.ifIndex},
|
||||
#{item.ifSpeed},
|
||||
#{item.ifInDiscards},
|
||||
#{item.ifOutDiscards},
|
||||
#{item.ifInErrors},
|
||||
#{item.ifOutErrors},
|
||||
#{item.switchName},
|
||||
#{item.interfaceDeviceType},
|
||||
#{item.serverName},
|
||||
#{item.serverPort},
|
||||
#{item.serverSn},
|
||||
#{item.switchSn},
|
||||
#{item.businessCode},
|
||||
#{item.businessName},
|
||||
#{item.createBy},
|
||||
#{item.updateBy},
|
||||
<choose>
|
||||
<when test="item.createTime != null">
|
||||
#{item.createTime}
|
||||
</when>
|
||||
<otherwise>
|
||||
NOW()
|
||||
</otherwise>
|
||||
</choose>,
|
||||
<choose>
|
||||
<when test="item.updateTime != null">
|
||||
#{item.updateTime}
|
||||
</when>
|
||||
<otherwise>
|
||||
NOW()
|
||||
</otherwise>
|
||||
</choose>,
|
||||
#{item.interfaceNameRemark},
|
||||
#{item.serverClientId}
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="getswitchDetailList" parameterType="InitialSwitchInfoDetails" resultType="InitialSwitchInfoDetails">
|
||||
select in_speed inSpeed, out_speed outSpeed, create_time createTime from initial_switch_info_details
|
||||
<where>
|
||||
@@ -343,7 +430,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
select sum(ifnull(in_speed,0)) AS inSpeed,
|
||||
sum(ifnull(out_speed,0)) AS outSpeed,
|
||||
sum(ifnull(max_speed,0)) AS maxSpeed,
|
||||
create_time createTime from initial_switch_info_details
|
||||
create_time createTime from ${tableName}
|
||||
<where>
|
||||
<if test="businessCode != null and businessCode != ''"> and business_code = #{businessCode}</if>
|
||||
<if test="businessName != null and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
|
||||
@@ -392,4 +479,109 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
|
||||
<!-- 查询交换机信息-->
|
||||
<select id="getAllSwitchInfoMsgSharding" parameterType="InitialSwitchInfoDetails" resultType="InitialSwitchInfoDetails">
|
||||
SELECT
|
||||
id,
|
||||
client_id AS clientId,
|
||||
`name`,
|
||||
in_bytes AS inBytes,
|
||||
out_bytes AS outBytes,
|
||||
status,
|
||||
`type`,
|
||||
in_speed AS inSpeed,
|
||||
out_speed AS outSpeed,
|
||||
switch_ip AS switchIp,
|
||||
if_index AS ifIndex,
|
||||
if_speed AS ifSpeed,
|
||||
if_in_discards AS ifInDiscards,
|
||||
if_out_discards AS ifOutDiscards,
|
||||
if_in_errors AS ifInErrors,
|
||||
if_out_errors AS ifOutErrors,
|
||||
create_by AS createBy,
|
||||
update_by AS updateBy,
|
||||
create_time AS createTime,
|
||||
update_time AS updateTime
|
||||
FROM
|
||||
${tableName}
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="startTime != null and startTime != ''"> and create_time >= #{startTime}</if>
|
||||
<if test="endTime != null and endTime != ''"> and create_time <= #{endTime}</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
<select id="getSwitchDetailListSharding" parameterType="InitialSwitchInfoDetails" resultType="InitialSwitchInfoDetails">
|
||||
select switch_name switchName,client_id clientId, name, in_speed inSpeed, out_speed outSpeed, create_time createTime from ${tableName}
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="name != null and name != ''"> and name = #{name}</if>
|
||||
<if test="inBytes != null "> and in_bytes = #{inBytes}</if>
|
||||
<if test="outBytes != null "> and out_bytes = #{outBytes}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||
<if test="inSpeed != null "> and in_speed = #{inSpeed}</if>
|
||||
<if test="outSpeed != null "> and out_speed = #{outSpeed}</if>
|
||||
<if test="switchIp != null and switchIp != ''"> and switch_ip = #{switchIp}</if>
|
||||
<if test="switchName != null and switchName != ''"> and switch_name like concat('%', #{switchName}, '%')</if>
|
||||
<if test="interfaceDeviceType != null and interfaceDeviceType != ''"> and interface_device_type = #{interfaceDeviceType}</if>
|
||||
<if test="serverName != null and serverName != ''"> and server_name like concat('%', #{serverName}, '%')</if>
|
||||
<if test="serverPort != null and serverPort != ''"> and server_port = #{serverPort}</if>
|
||||
<if test="serverSn != null and serverSn != ''"> and server_sn = #{serverSn}</if>
|
||||
<if test="switchSn != null and switchSn != ''"> and switch_sn = #{switchSn}</if>
|
||||
<if test="businessCode != null and businessCode != ''"> and business_code = #{businessCode}</if>
|
||||
<if test="businessName != null and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
|
||||
<if test="startTime != null">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
<if test="clientIds != '' and clientIds != null">
|
||||
and client_id in
|
||||
<foreach collection="clientIds.split(',')" item="clientId" open="(" separator="," close=")">
|
||||
#{clientId}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="interfaceNames != null and interfaceNames != ''">
|
||||
and name in
|
||||
<foreach collection="interfaceNames.split(',')" item="name" open="(" separator="," close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="selectInitialSwitchInfoDetailsListSharding" parameterType="InitialSwitchInfoDetails" resultMap="InitialSwitchInfoDetailsResult">
|
||||
<include refid="selectInitialSwitchInfoDetailsVoSharding"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="name != null and name != ''"> and name = #{name}</if>
|
||||
<if test="inBytes != null "> and in_bytes = #{inBytes}</if>
|
||||
<if test="outBytes != null "> and out_bytes = #{outBytes}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||
<if test="inSpeed != null "> and in_speed = #{inSpeed}</if>
|
||||
<if test="outSpeed != null "> and out_speed = #{outSpeed}</if>
|
||||
<if test="switchIp != null and switchIp != ''"> and switch_ip = #{switchIp}</if>
|
||||
<if test="switchName != null and switchName != ''"> and switch_name like concat('%', #{switchName}, '%')</if>
|
||||
<if test="interfaceDeviceType != null and interfaceDeviceType != ''"> and interface_device_type = #{interfaceDeviceType}</if>
|
||||
<if test="serverName != null and serverName != ''"> and server_name like concat('%', #{serverName}, '%')</if>
|
||||
<if test="serverPort != null and serverPort != ''"> and server_port = #{serverPort}</if>
|
||||
<if test="serverSn != null and serverSn != ''"> and server_sn = #{serverSn}</if>
|
||||
<if test="switchSn != null and switchSn != ''"> and switch_sn = #{switchSn}</if>
|
||||
<if test="businessCode != null and businessCode != ''"> and business_code = #{businessCode}</if>
|
||||
<if test="businessName != null and businessName != ''"> and business_name like concat('%', #{businessName}, '%')</if>
|
||||
<if test="interfaceNameRemark != null and interfaceNameRemark != ''"> and interface_name_remark = #{interfaceNameRemark}</if>
|
||||
<if test="serverClientId != null and serverClientId != ''"> and server_client_id = #{serverClientId}</if>
|
||||
<if test="startTime != null">
|
||||
and create_time >= #{startTime}
|
||||
</if>
|
||||
<if test="endTime != null">
|
||||
and create_time <= #{endTime}
|
||||
</if>
|
||||
</where>
|
||||
order by create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -7,6 +7,7 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 交换机流量监控信息对象 initial_switch_info
|
||||
@@ -69,6 +70,10 @@ public class InitialSwitchInfo extends BaseEntity
|
||||
private String calculationMode;
|
||||
/* 单位 */
|
||||
private String unit;
|
||||
/** 表名 */
|
||||
private String tableName;
|
||||
/** 批量新增集合 */
|
||||
private List<InitialSwitchInfo> list;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -70,4 +70,19 @@ public interface InitialSwitchInfoMapper
|
||||
public int batchInsertInitialSwitchInfo(@Param("list") List<InitialSwitchInfo> list);
|
||||
|
||||
InitialSwitchInfo getSwitchNetDetailsMsg(InitialSwitchInfo initialSwitchInfo);
|
||||
InitialSwitchInfo getSwitchNetDetailsMsgSharding(InitialSwitchInfo initialSwitchInfo);
|
||||
|
||||
/**
|
||||
* 分表批量插入
|
||||
* @param initialSwitchInfo
|
||||
* @return
|
||||
*/
|
||||
int batchInsertInitialSwitchInfoSharding(InitialSwitchInfo initialSwitchInfo);
|
||||
|
||||
/**
|
||||
* 分表查询交换机信息
|
||||
* @param condition
|
||||
* @return
|
||||
*/
|
||||
List<InitialSwitchInfo> selectInitialSwitchInfoListSharding(InitialSwitchInfo condition);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.ruoyi.rocketmq.service;
|
||||
|
||||
import com.ruoyi.rocketmq.domain.InitialSwitchInfo;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -68,6 +69,14 @@ public interface IInitialSwitchInfoService
|
||||
*/
|
||||
public int batchInsertInitialSwitchInfo(List<InitialSwitchInfo> list);
|
||||
|
||||
/**
|
||||
* 批量新增交换机流量监控信息
|
||||
*
|
||||
* @param list 交换机流量监控信息集合
|
||||
* @return 结果
|
||||
*/
|
||||
public int batchInsertInitialSwitchInfoSharding(List<InitialSwitchInfo> list, Date createTime);
|
||||
|
||||
/**
|
||||
* 交换机网络基础信息
|
||||
* @param initialSwitchInfo
|
||||
|
||||
+80
-13
@@ -1,14 +1,12 @@
|
||||
package com.ruoyi.rocketmq.service.impl;
|
||||
|
||||
import com.ruoyi.common.core.utils.ConvertOtherTypeUtil;
|
||||
import com.ruoyi.common.core.utils.DateUtils;
|
||||
import com.ruoyi.common.core.utils.EchartsDataUtils;
|
||||
import com.ruoyi.common.core.utils.SpeedUtils;
|
||||
import com.ruoyi.common.core.utils.*;
|
||||
import com.ruoyi.rocketmq.domain.InitialSwitchInfo;
|
||||
import com.ruoyi.rocketmq.mapper.InitialSwitchInfoMapper;
|
||||
import com.ruoyi.rocketmq.service.IInitialSwitchInfoService;
|
||||
import com.ruoyi.system.api.RemoteRevenueConfigService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Isolation;
|
||||
@@ -16,11 +14,9 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 交换机流量监控信息Service业务层处理
|
||||
@@ -37,6 +33,8 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
@Autowired
|
||||
private RemoteRevenueConfigService remoteRevenueConfigService;
|
||||
|
||||
private final static String TABLE_PREFIX = "initial_switch_info";
|
||||
|
||||
/**
|
||||
* 查询交换机流量监控信息
|
||||
*
|
||||
@@ -127,6 +125,73 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
throw new RuntimeException("批量保存失败",e);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 批量新增交换机流量监控信息
|
||||
*
|
||||
* @param list 交换机流量监控信息集合
|
||||
* @return 结果
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
||||
public int batchInsertInitialSwitchInfoSharding(List<InitialSwitchInfo> list, Date createTime) {
|
||||
if (list == null || list.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
// 按表名分组批量插入
|
||||
Map<String, List<InitialSwitchInfo>> groupedData = list.stream()
|
||||
.map(data -> {
|
||||
try {
|
||||
InitialSwitchInfo processed = new InitialSwitchInfo();
|
||||
BeanUtils.copyProperties(data,processed);
|
||||
if (data.getCreateTime() == null) {
|
||||
data.setCreateTime(DateUtils.getNowDate());
|
||||
}
|
||||
processed.setTableName(TableSubUtil.getTableName(createTime, TABLE_PREFIX));
|
||||
return processed;
|
||||
} catch (Exception e){
|
||||
log.error("数据处理失败",e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}).collect(Collectors.groupingBy(
|
||||
InitialSwitchInfo::getTableName,
|
||||
LinkedHashMap::new, // 保持插入顺序
|
||||
Collectors.toList()));
|
||||
|
||||
groupedData.forEach((tableName, dataList) -> {
|
||||
try {
|
||||
InitialSwitchInfo data = new InitialSwitchInfo();
|
||||
data.setTableName(tableName);
|
||||
data.setList(dataList);
|
||||
initialSwitchInfoMapper.batchInsertInitialSwitchInfoSharding(data);
|
||||
} catch (Exception e) {
|
||||
log.error("表{}插入失败", tableName, e);
|
||||
throw new RuntimeException("批量插入失败", e);
|
||||
}
|
||||
});
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 分表查询交换机网卡流量信息
|
||||
* @param queryParam
|
||||
* @return
|
||||
*/
|
||||
public List<InitialSwitchInfo> getSwitchMsgSharding(InitialSwitchInfo queryParam) {
|
||||
// 获取涉及的表名
|
||||
Set<String> tableNames = TableSubUtil.getTableNamesBetween(queryParam.getStartTime(), queryParam.getEndTime(), TABLE_PREFIX);
|
||||
|
||||
// 并行查询各表
|
||||
return tableNames.parallelStream()
|
||||
.flatMap(tableName -> {
|
||||
InitialSwitchInfo condition = new InitialSwitchInfo();
|
||||
condition.setTableName(tableName);
|
||||
condition.setClientId(queryParam.getClientId());
|
||||
condition.setStartTime(queryParam.getStartTime());
|
||||
condition.setEndTime(queryParam.getEndTime());
|
||||
return initialSwitchInfoMapper.selectInitialSwitchInfoListSharding(condition).stream();
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取交换机网络端口的基础信息
|
||||
@@ -135,7 +200,9 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
*/
|
||||
@Override
|
||||
public InitialSwitchInfo getSwitchNetDetailsMsg(InitialSwitchInfo initialSwitchInfo) {
|
||||
InitialSwitchInfo info = initialSwitchInfoMapper.getSwitchNetDetailsMsg(initialSwitchInfo);
|
||||
String tableName = TableSubUtil.getTableName(DateUtils.getNowDate(), TABLE_PREFIX);
|
||||
initialSwitchInfo.setTableName(tableName);
|
||||
InitialSwitchInfo info = initialSwitchInfoMapper.getSwitchNetDetailsMsgSharding(initialSwitchInfo);
|
||||
if(info != null && info.getType()!=null){
|
||||
info.setType(ConvertOtherTypeUtil.getInterfaceTypeName(Integer.parseInt(info.getType())));
|
||||
}
|
||||
@@ -149,7 +216,7 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> switchNetSpeedEcharts(InitialSwitchInfo initialSwitchInfo) {
|
||||
List<InitialSwitchInfo> list = initialSwitchInfoMapper.selectInitialSwitchInfoList(initialSwitchInfo);
|
||||
List<InitialSwitchInfo> list = getSwitchMsgSharding(initialSwitchInfo);
|
||||
try {
|
||||
String unit = SpeedUtils.calculateUnit(list, "inSpeed", "outSpeed");
|
||||
if(initialSwitchInfo.getUnit() != null){
|
||||
@@ -185,7 +252,7 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> switchNetDiscardsEcharts(InitialSwitchInfo initialSwitchInfo) {
|
||||
List<InitialSwitchInfo> list = initialSwitchInfoMapper.selectInitialSwitchInfoList(initialSwitchInfo);
|
||||
List<InitialSwitchInfo> list = getSwitchMsgSharding(initialSwitchInfo);
|
||||
Map<String, Function<InitialSwitchInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInDiscardsData", info -> info.getIfInDiscards());
|
||||
extractors.put("netOutDiscardsData", info -> info.getIfOutDiscards());
|
||||
@@ -202,7 +269,7 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> switchNetTotalEcharts(InitialSwitchInfo initialSwitchInfo) {
|
||||
List<InitialSwitchInfo> list = initialSwitchInfoMapper.selectInitialSwitchInfoList(initialSwitchInfo);
|
||||
List<InitialSwitchInfo> list = getSwitchMsgSharding(initialSwitchInfo);
|
||||
Map<String, Function<InitialSwitchInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInTotalData", info -> info.getInBytes().multiply(new BigDecimal(8)));
|
||||
extractors.put("netOutTotalData", info -> info.getOutBytes().multiply(new BigDecimal(8)));
|
||||
@@ -219,7 +286,7 @@ public class InitialSwitchInfoServiceImpl implements IInitialSwitchInfoService
|
||||
*/
|
||||
@Override
|
||||
public Map<String, Object> switchNetErrDiscardsEcharts(InitialSwitchInfo initialSwitchInfo) {
|
||||
List<InitialSwitchInfo> list = initialSwitchInfoMapper.selectInitialSwitchInfoList(initialSwitchInfo);
|
||||
List<InitialSwitchInfo> list = getSwitchMsgSharding(initialSwitchInfo);
|
||||
Map<String, Function<InitialSwitchInfo, ?>> extractors = new LinkedHashMap<>();
|
||||
extractors.put("netInErrDiscardsData", info -> info.getIfInErrors());
|
||||
extractors.put("netOutErrDiscardsData", info -> info.getIfOutErrors());
|
||||
|
||||
+1
-1
@@ -213,7 +213,7 @@ public class ProcessSwitchCollectDataService {
|
||||
// 临时表 用来计算inSpeed outSeppd
|
||||
initialSwitchInfoTempService.batchInsertInitialSwitchInfoTemp(switchInfos);
|
||||
// 初始交换机数据入库
|
||||
initialSwitchInfoService.batchInsertInitialSwitchInfo(switchInfos);
|
||||
initialSwitchInfoService.batchInsertInitialSwitchInfoSharding(switchInfos, createTime);
|
||||
// 业务表入库
|
||||
InitialSwitchInfoDetailsRemote detailsRemote = new InitialSwitchInfoDetailsRemote();
|
||||
detailsRemote.setClientId(clientId);
|
||||
|
||||
@@ -38,6 +38,17 @@
|
||||
if_speed, if_in_discards, if_out_discards, if_in_errors, if_out_errors, create_by, update_by, create_time,
|
||||
update_time from initial_switch_info
|
||||
</sql>
|
||||
<sql id="selectInitialSwitchInfoVoSharding">
|
||||
select id, client_id, name, in_bytes, out_bytes,
|
||||
CASE
|
||||
WHEN status = 1 THEN 'up'
|
||||
WHEN status = 2 THEN 'down'
|
||||
ELSE `status`
|
||||
END AS status,
|
||||
type, in_speed, out_speed, switch_ip, if_index,
|
||||
if_speed, if_in_discards, if_out_discards, if_in_errors, if_out_errors, create_by, update_by, create_time,
|
||||
update_time from ${tableName}
|
||||
</sql>
|
||||
|
||||
<select id="selectInitialSwitchInfoList" parameterType="InitialSwitchInfo" resultMap="InitialSwitchInfoResult">
|
||||
<include refid="selectInitialSwitchInfoVo"/>
|
||||
@@ -189,4 +200,66 @@
|
||||
where client_id = #{clientId} and name = #{name}
|
||||
limit 1
|
||||
</select>
|
||||
<select id="getSwitchNetDetailsMsgSharding" parameterType="String" resultMap="InitialSwitchInfoResult">
|
||||
<include refid="selectInitialSwitchInfoVoSharding"/>
|
||||
where client_id = #{clientId} and name = #{name}
|
||||
order by create_time desc
|
||||
limit 1
|
||||
</select>
|
||||
|
||||
<insert id="batchInsertInitialSwitchInfoSharding" parameterType="InitialSwitchInfo">
|
||||
INSERT IGNORE INTO ${tableName}
|
||||
(
|
||||
client_id, `name`, in_bytes, out_bytes, status, `type`, in_speed, out_speed, switch_ip,
|
||||
if_index, if_speed, if_in_discards, if_out_discards, if_in_errors, if_out_errors,
|
||||
create_by, update_by, create_time, update_time
|
||||
)
|
||||
VALUES
|
||||
<foreach collection="list" item="item" separator=",">
|
||||
(
|
||||
#{item.clientId}, #{item.name}, #{item.inBytes}, #{item.outBytes},
|
||||
#{item.status}, #{item.type}, #{item.inSpeed}, #{item.outSpeed}, #{item.switchIp},
|
||||
#{item.ifIndex}, #{item.ifSpeed}, #{item.ifInDiscards},#{item.ifOutDiscards},#{item.ifInErrors},#{item.ifOutErrors},
|
||||
#{item.createBy}, #{item.updateBy},
|
||||
<choose>
|
||||
<when test="item.createTime != null">
|
||||
#{item.createTime}
|
||||
</when>
|
||||
<otherwise>
|
||||
NOW()
|
||||
</otherwise>
|
||||
</choose>,
|
||||
<choose>
|
||||
<when test="item.updateTime != null">
|
||||
#{item.updateTime}
|
||||
</when>
|
||||
<otherwise>
|
||||
NOW()
|
||||
</otherwise>
|
||||
</choose>
|
||||
)
|
||||
</foreach>
|
||||
</insert>
|
||||
<select id="selectInitialSwitchInfoListSharding" parameterType="InitialSwitchInfo" resultMap="InitialSwitchInfoResult">
|
||||
<include refid="selectInitialSwitchInfoVoSharding"/>
|
||||
<where>
|
||||
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
|
||||
<if test="name != null and name != ''"> and name = #{name}</if>
|
||||
<if test="inBytes != null "> and in_bytes = #{inBytes}</if>
|
||||
<if test="outBytes != null "> and out_bytes = #{outBytes}</if>
|
||||
<if test="status != null and status != ''"> and status = #{status}</if>
|
||||
<if test="type != null and type != ''"> and type = #{type}</if>
|
||||
<if test="inSpeed != null "> and in_speed = #{inSpeed}</if>
|
||||
<if test="outSpeed != null "> and out_speed = #{outSpeed}</if>
|
||||
<if test="switchIp != null and switchIp != ''"> and switch_ip = #{switchIp}</if>
|
||||
<if test="ifIndex != null and ifIndex != ''"> and if_index = #{ifIndex}</if>
|
||||
<if test="ifSpeed != null "> and if_speed = #{ifSpeed}</if>
|
||||
<if test="ifInDiscards != null "> and if_in_discards = #{ifInDiscards}</if>
|
||||
<if test="ifOutDiscards != null "> and if_out_discards = #{ifOutDiscards}</if>
|
||||
<if test="ifInErrors != null "> and if_in_errors = #{ifInErrors}</if>
|
||||
<if test="ifOutErrors != null "> and if_out_errors = #{ifOutErrors}</if>
|
||||
<if test="startTime != null and startTime != ''"> and create_time >= #{startTime}</if>
|
||||
<if test="endTime != null and endTime != ''"> and create_time <= #{endTime}</if>
|
||||
</where>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user