From 46bf4c4114987daa8d967e3ee89740ed6f5c5928 Mon Sep 17 00:00:00 2001 From: gaoyutao Date: Mon, 27 Oct 2025 18:16:47 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=9C=80=E6=96=B0=E7=AD=96?= =?UTF-8?q?=E7=95=A5=E5=A2=9E=E5=8A=A0=E8=B7=AF=E7=94=B1=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E3=80=81=E4=BA=A4=E6=8D=A2=E6=9C=BA=E5=B8=A6?= =?UTF-8?q?=E5=AE=BD=E6=94=B6=E7=9B=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/system/domain/EpsNodeBandwidth.java | 2 + .../domain/InitialSwitchInfoDetails.java | 2 + .../EpsInitialTrafficDataServiceImpl.java | 52 +---- .../InitialSwitchInfoDetailsServiceImpl.java | 100 ++++----- .../mapper/system/AllInterfaceNameMapper.xml | 9 +- .../mapper/system/EpsNodeBandwidthMapper.xml | 21 +- .../system/InitialSwitchInfoDetailsMapper.xml | 9 +- .../rocketmq/domain/RmNetworkInterface.java | 2 +- .../rocketmq/domain/vo/PolicyTypeVo.java | 2 + .../ruoyi/rocketmq/domain/vo/RspResultVo.java | 13 ++ .../rocketmq/handler/MessageHandler.java | 201 ++++++++++++++---- .../service/IRmNetworkInterfaceService.java | 6 + .../impl/InitialDiskInfoServiceImpl.java | 3 + .../impl/RmDeploymentPolicyServiceImpl.java | 8 +- .../impl/RmMonitorPolicyServiceImpl.java | 4 +- .../impl/RmNetworkInterfaceServiceImpl.java | 69 ++++++ .../rocketmq/InitialDockerInfoMapper.xml | 2 + .../rocketmq/RmAgentManagementMapper.xml | 17 +- .../mapper/rocketmq/RmMonitorPolicyMapper.xml | 2 +- 19 files changed, 376 insertions(+), 148 deletions(-) create mode 100644 ruoyi-rocketmq/src/main/java/com/ruoyi/rocketmq/domain/vo/RspResultVo.java diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java index edc42ad..dda7723 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/EpsNodeBandwidth.java @@ -140,5 +140,7 @@ public class EpsNodeBandwidth extends BaseEntity private List switchNames; /** 计算方式 */ private String calculationMode; + /** 客户端id */ + private String clientId; } diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java index e7a490b..5738105 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/domain/InitialSwitchInfoDetails.java @@ -52,6 +52,8 @@ public class InitialSwitchInfoDetails extends BaseEntity /** 发送流量(bytes/s) */ @Excel(name = "发送流量", readConverterExp = "b=ytes/s") private BigDecimal outSpeed; + /** 发送或接收流量的最大值 */ + private BigDecimal maxSpeed; /** 交换机名称 */ @Excel(name = "交换机名称") diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java index 1368874..c3936de 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/EpsInitialTrafficDataServiceImpl.java @@ -481,11 +481,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe * 计算并保存95带宽值 */ private void calculateAndSave95Bandwidth(List dataList, String dateTime, String dayOrMonth, String calculationMode) { - boolean eff = false; if(!dataList.isEmpty()){ - if(dataList.size()<288){ - eff = true; - } // 1. 提取并转换带宽值 List speedsInMbps = dataList.stream() .map(data -> CalculateUtil.parseSpeedToMbps(data.getOutSpeed(), calculationMode)) @@ -498,24 +494,11 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe // 3. 保存结果 EpsInitialTrafficData epsInitialTrafficData = dataList.get(0); epsInitialTrafficData.setResourceType("1"); - if("2".equals(epsInitialTrafficData.getRevenueMethod())){ - percentile95 = epsInitialTrafficData.getPackageBandwidth(); - epsInitialTrafficData.setBandwidthType("3"); - }else { - if("1".equals(dayOrMonth)){ - if(eff){ - epsInitialTrafficData.setBandwidthType("5"); - }else { - epsInitialTrafficData.setBandwidthType("1"); - } - } - if("2".equals(dayOrMonth)){ - if(eff){ - epsInitialTrafficData.setBandwidthType("6"); - }else { - epsInitialTrafficData.setBandwidthType("2"); - } - } + if("1".equals(dayOrMonth)){ + epsInitialTrafficData.setBandwidthType("1"); + } + if("2".equals(dayOrMonth)){ + epsInitialTrafficData.setBandwidthType("2"); } saveBandwidthResult(epsInitialTrafficData, percentile95, dateTime, calculationMode); } @@ -583,25 +566,11 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe // 服务器信息 EpsInitialTrafficData epsInitialTrafficData = dataList.get(0); epsInitialTrafficData.setResourceType("1"); - if("2".equals(epsInitialTrafficData.getRevenueMethod())){ - dailyResult = epsInitialTrafficData.getPackageBandwidth(); - epsInitialTrafficData.setBandwidthType("3"); - }else{ - if(CalculateUtil.isEff(dataList)){ - if("1".equals(dayOrMonth)){ - epsInitialTrafficData.setBandwidthType("5"); - } - if("2".equals(dayOrMonth)){ - epsInitialTrafficData.setBandwidthType("6"); - } - }else { - if("1".equals(dayOrMonth)){ - epsInitialTrafficData.setBandwidthType("1"); - } - if("2".equals(dayOrMonth)){ - epsInitialTrafficData.setBandwidthType("2"); - } - } + if("1".equals(dayOrMonth)){ + epsInitialTrafficData.setBandwidthType("1"); + } + if("2".equals(dayOrMonth)){ + epsInitialTrafficData.setBandwidthType("2"); } saveBandwidthResult(epsInitialTrafficData, dailyResult, startTime, calculationMode); } @@ -612,6 +581,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe BigDecimal result, String dateTime, String calculationMode) { EpsNodeBandwidth bandwidth = new EpsNodeBandwidth(); + bandwidth.setClientId(data.getClientId()); bandwidth.setHardwareSn(data.getServiceSn()); bandwidth.setCalculationMode(calculationMode); bandwidth.setNodeName(data.getNodeName()); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java index 4a846be..ab5bdc1 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/InitialSwitchInfoDetailsServiceImpl.java @@ -130,11 +130,12 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe List batchList = new ArrayList<>(); if(!dataList.isEmpty()){ for (InitialSwitchInfoDetails details : dataList) { + // 取发送或接收流量最大值赋值到maxSpeed + calculateMaxSpeed(details); // id自增 details.setId(null); // 根据接口名称查询交换机信息 String interfaceName = details.getName(); - String switchSn = details.getSwitchSn(); RmEpsTopologyManagement rmEpsTopologyManagement = new RmEpsTopologyManagement(); rmEpsTopologyManagement.setInterfaceName(interfaceName); rmEpsTopologyManagement.setSwitchIpAddress(details.getSwitchIp()); @@ -192,6 +193,34 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe } } } + /** + * 辅助方法 + * 获取 inSpeed 和 outSpeed 的最大值并设置到 maxSpeed + * @param switchInfo 包含速度信息的实体类 + */ + public static void calculateMaxSpeed(InitialSwitchInfoDetails switchInfo) { + if (switchInfo == null) { + return; + } + // 获取 inSpeed 和 outSpeed + BigDecimal inSpeed = switchInfo.getInSpeed(); + BigDecimal outSpeed = switchInfo.getOutSpeed(); + // 处理可能为null的情况 + if (inSpeed == null && outSpeed == null) { + switchInfo.setMaxSpeed(null); + return; + } + if (inSpeed == null) { + switchInfo.setMaxSpeed(outSpeed); + return; + } + if (outSpeed == null) { + switchInfo.setMaxSpeed(inSpeed); + return; + } + // 比较并设置最大值 + switchInfo.setMaxSpeed(inSpeed.compareTo(outSpeed) > 0 ? inSpeed : outSpeed); + } /** * 批量处理接口名称 */ @@ -314,7 +343,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe // 遍历处理每个交换机 switchSnList.forEach(interfaceName -> { - queryParam.setSwitchSn(interfaceName.getSwitchSn()); + queryParam.setClientId(interfaceName.getClientId()); queryParam.setSwitchIp(interfaceName.getSwitchIp()); processSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode); }); @@ -330,6 +359,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe public void recalculateSwitch95Bandwidth(EpsNodeBandwidth epsNodeBandwidth, String dailyStartTime, String dailyEndTime, String calculationMode) { InitialSwitchInfoDetails switchInfoDetails = new InitialSwitchInfoDetails(); + switchInfoDetails.setClientId(epsNodeBandwidth.getClientId()); switchInfoDetails.setStartTime(dailyStartTime); switchInfoDetails.setEndTime(dailyEndTime); switchInfoDetails.setSwitchSn(epsNodeBandwidth.getSwitchSn()); @@ -346,9 +376,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe List speedsInMbps = dataList.stream() .map(data -> { // 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed - String speed = "1".equals(data.getInterfaceDeviceType()) - ? (data.getInSpeed() != null ? data.getInSpeed().toString() : BigDecimal.ZERO.toString()) - : (data.getOutSpeed() != null ? data.getOutSpeed().toString() : BigDecimal.ZERO.toString()); + String speed = data.getMaxSpeed() != null ? data.getMaxSpeed().toString() : BigDecimal.ZERO.toString(); // 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s) if (speed.matches("^\\d+(\\.\\d+)?$")) { speed += " B/S"; @@ -436,7 +464,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe String dailyEndTime, String calculationMode) { // 根据交换机sn查询连接的服务器sn RmEpsTopologyManagement management = new RmEpsTopologyManagement(); - management.setSwitchSn(queryParam.getSwitchSn()); + management.setClientId(queryParam.getClientId()); management.setSwitchIpAddress(queryParam.getSwitchIp()); List serverSnList = rmEpsTopologyManagementMapper.selectRmEpsTopologyManagementList(management); if(!serverSnList.isEmpty()){ @@ -444,19 +472,9 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe queryParam.setName(rmEpsTopologyManagement.getInterfaceName()); if("1".equals(rmEpsTopologyManagement.getConnectedDeviceType())){ queryParam.setServerSn(rmEpsTopologyManagement.getServerSn()); - // 检查交换机连接的服务器是否有业务变更(如果有相关配置) - EpsServerRevenueConfig revenueConfig = new EpsServerRevenueConfig(); - revenueConfig.setHardwareSn(rmEpsTopologyManagement.getServerSn()); - List changedList = epsServerRevenueConfigMapper - .selectEpsServerRevenueConfigList(revenueConfig); // 根据业务变更情况选择计算方式 - if (hasTrafficMethodChanged(changedList)) { - calculateChangedSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode); - } else { - calculateNormalSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode); - } - } - if("2".equals(rmEpsTopologyManagement.getConnectedDeviceType())){ + calculateChangedSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode); + }else{ queryParam.setServerSn(null); calculateNormalSwitchBandwidth(queryParam, dailyStartTime, dailyEndTime, calculationMode); } @@ -480,7 +498,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe String dailyEndTime, String calculationMode) { // 获取业务变更记录(按时间降序) EpsMethodChangeRecord changeQuery = new EpsMethodChangeRecord(); - changeQuery.setHardwareSn(queryParam.getServerSn()); + changeQuery.setClientId(queryParam.getClientId()); changeQuery.setStartTime(dailyStartTime); changeQuery.setEndTime(dailyEndTime); List records = epsMethodChangeRecordMapper @@ -518,18 +536,12 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe */ private void calculateAndSaveSwitch95Bandwidth(List dataList, String dateTime, String dayOrMonth, String calculationMode) { - boolean eff = false; if(!dataList.isEmpty()){ - if(dataList.size()<288){ - eff = true; - } // 1. 提取并转换带宽值 List speedsInMbps = dataList.stream() .map(data -> { // 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed - String speed = "1".equals(data.getInterfaceDeviceType()) - ? (data.getInSpeed() != null ? data.getInSpeed().toString() : BigDecimal.ZERO.toString()) - : (data.getOutSpeed() != null ? data.getOutSpeed().toString() : BigDecimal.ZERO.toString()); + String speed = data.getMaxSpeed() != null ? data.getMaxSpeed().toString() : BigDecimal.ZERO.toString(); // 如果 speed 是纯数字,补充单位 "B/S"(Bytes/s) if (speed.matches("^\\d+(\\.\\d+)?$")) { speed += " B/S"; @@ -546,18 +558,10 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe InitialSwitchInfoDetails switchInfo = dataList.get(0); switchInfo.setResourceType("2"); if("1".equals(dayOrMonth)){ - if(eff){ - switchInfo.setBandwidthType("5"); - }else{ - switchInfo.setBandwidthType("1"); - } + switchInfo.setBandwidthType("1"); } if("2".equals(dayOrMonth)){ - if(eff){ - switchInfo.setBandwidthType("6"); - }else{ - switchInfo.setBandwidthType("2"); - } + switchInfo.setBandwidthType("2"); } saveSwitchBandwidthResult(switchInfo, percentile95, dateTime, calculationMode); } @@ -608,9 +612,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe List speedsInMbps = dataList.stream() .map(data -> { // 根据 interfaceDeviceType 选择 inSpeed 或 outSpeed - String speed = "1".equals(data.getInterfaceDeviceType()) - ? (data.getInSpeed() != null ? data.getInSpeed().toString() : BigDecimal.ZERO.toString()) - : (data.getOutSpeed() != null ? data.getOutSpeed().toString() : BigDecimal.ZERO.toString()); + String speed = data.getMaxSpeed() != null ? data.getMaxSpeed().toString() : BigDecimal.ZERO.toString(); if (speed.matches("^\\d+(\\.\\d+)?$")) { speed += " B/S"; } @@ -626,20 +628,11 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe // 3. 保存结果 InitialSwitchInfoDetails switchInfo = dataList.get(0); switchInfo.setResourceType("2"); - if(CalculateUtil.isEff(dataList)){ - if("1".equals(dayOrMonth)){ - switchInfo.setBandwidthType("5"); - } - if("2".equals(dayOrMonth)){ - switchInfo.setBandwidthType("6"); - } - }else { - if("1".equals(dayOrMonth)){ - switchInfo.setBandwidthType("1"); - } - if("2".equals(dayOrMonth)){ - switchInfo.setBandwidthType("2"); - } + if("1".equals(dayOrMonth)){ + switchInfo.setBandwidthType("1"); + } + if("2".equals(dayOrMonth)){ + switchInfo.setBandwidthType("2"); } saveSwitchBandwidthResult(switchInfo, dailyResult, startTime, calculationMode); } @@ -653,6 +646,7 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe EpsNodeBandwidth bandwidth = new EpsNodeBandwidth(); bandwidth.setBusinessName(data.getBusinessName()); bandwidth.setBusinessId(data.getBusinessCode()); + bandwidth.setClientId(data.getClientId()); bandwidth.setHardwareSn(data.getServerSn()); bandwidth.setCalculationMode(calculationMode); bandwidth.setSwitchSn(data.getSwitchSn()); diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml index f5ecc61..cfee62b 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/AllInterfaceNameMapper.xml @@ -196,7 +196,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - - - UPDATE all_interface_name diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml index 1fb57dd..a94eae7 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsNodeBandwidthMapper.xml @@ -35,16 +35,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - select id, node_name, hardware_sn, calculation_mode, bandwidth_type, bandwidth_result, bandwidth_95_daily, bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, machine_flow, 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, remark1, create_datetime from eps_node_bandwidth + select id, node_name, hardware_sn, calculation_mode, bandwidth_type, bandwidth_result, bandwidth_95_daily, + bandwidth_95_monthly, avg_monthly_bandwidth_95, package_bandwidth_daily, machine_flow, 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, + remark1, create_datetime, client_id from eps_node_bandwidth @@ -273,6 +286,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and business_id = #{businessId} + + and client_id = #{clientId} + @@ -291,6 +307,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and business_id = #{businessId} + + and client_id = #{clientId} + \ No newline at end of file diff --git a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml index 405556a..ed5cf54 100644 --- a/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml +++ b/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/InitialSwitchInfoDetailsMapper.xml @@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -36,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - 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 from initial_switch_info_details + select id, client_id, name, in_bytes, out_bytes, status, type, in_speed, out_speed, max_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 from initial_switch_info_details where client_id = #{clientId} and `id` = #{id} + order by create_time desc + limit 1