获取最新策略增加路由信息方法、交换机带宽收益

This commit is contained in:
gaoyutao
2025-10-27 18:16:47 +08:00
parent 36362e2236
commit 46bf4c4114
19 changed files with 376 additions and 148 deletions
@@ -140,5 +140,7 @@ public class EpsNodeBandwidth extends BaseEntity
private List<String> switchNames;
/** 计算方式 */
private String calculationMode;
/** 客户端id */
private String clientId;
}
@@ -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 = "交换机名称")
@@ -481,11 +481,7 @@ public class EpsInitialTrafficDataServiceImpl implements EpsInitialTrafficDataSe
* 计算并保存95带宽值
*/
private void calculateAndSave95Bandwidth(List<EpsInitialTrafficData> dataList, String dateTime, String dayOrMonth, String calculationMode) {
boolean eff = false;
if(!dataList.isEmpty()){
if(dataList.size()<288){
eff = true;
}
// 1. 提取并转换带宽值
List<BigDecimal> 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());
@@ -130,11 +130,12 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
List<InitialSwitchInfoDetails> 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<BigDecimal> 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<RmEpsTopologyManagement> 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<EpsServerRevenueConfig> 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<EpsMethodChangeRecord> records = epsMethodChangeRecordMapper
@@ -518,18 +536,12 @@ public class InitialSwitchInfoDetailsServiceImpl implements IInitialSwitchInfoDe
*/
private void calculateAndSaveSwitch95Bandwidth(List<InitialSwitchInfoDetails> dataList, String dateTime,
String dayOrMonth, String calculationMode) {
boolean eff = false;
if(!dataList.isEmpty()){
if(dataList.size()<288){
eff = true;
}
// 1. 提取并转换带宽值
List<BigDecimal> 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<BigDecimal> 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());
@@ -196,7 +196,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</foreach>
</insert>
<!-- 检查接口名称是否存在 -->
<select id="getAllDeviceSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
SELECT
device_sn AS deviceSn
@@ -207,18 +206,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
group by device_sn
</select>
<!-- 检查交换机接口名称是否存在 -->
<select id="getAllSwitchSn" parameterType="AllInterfaceName" resultType="AllInterfaceName">
SELECT
switch_sn AS switchSn, switch_ip switchIp
client_id AS clientId, switch_ip switchIp
FROM
all_interface_name
<where>
and resource_type = '2' and switch_sn != ''
and resource_type = '2' and client_id != ''
</where>
group by switch_sn
group by client_id
</select>
<!-- MyBatis Mapper XML配置 -->
<update id="batchUpdate" parameterType="java.util.List">
<foreach collection="list" item="item" index="index" open="" separator=";" close="">
UPDATE all_interface_name
@@ -35,16 +35,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="businessId" column="business_id" />
<result property="remark1" column="remark1" />
<result property="createDatetime" column="create_datetime" />
<result property="clientId" column="client_id" />
</resultMap>
<sql id="selectEpsNodeBandwidthVo">
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
</sql>
<select id="selectEpsNodeBandwidthList" parameterType="EpsNodeBandwidth" resultMap="EpsNodeBandwidthResult">
<include refid="selectEpsNodeBandwidthVo"/>
<where>
<if test="nodeName != null and nodeName != ''"> and node_name like concat('%', #{nodeName}, '%')</if>
<if test="clientId != null and clientId != ''"> and client_id = #{clientId}</if>
<if test="hardwareSn != null and hardwareSn != ''"> and hardware_sn = #{hardwareSn}</if>
<if test="calculationMode != null and calculationMode != ''"> and calculation_mode = #{calculationMode}</if>
<if test="bandwidthType != null and bandwidthType != ''"> and bandwidth_type = #{bandwidthType}</if>
@@ -123,6 +130,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="businessName != null">business_name,</if>
<if test="businessId != null">business_id,</if>
<if test="remark1 != null">remark1,</if>
<if test="clientId != null">client_id,</if>
create_datetime,
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
@@ -153,6 +161,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="businessName != null">#{businessName},</if>
<if test="businessId != null">#{businessId},</if>
<if test="remark1 != null">#{remark1},</if>
<if test="clientId != null">#{clientId},</if>
NOW(),
</trim>
</insert>
@@ -188,6 +197,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="businessId != null">business_id = #{businessId},</if>
<if test="remark1 != null">remark1 = #{remark1},</if>
<if test="createDatetime != null">create_datetime = #{createDatetime},</if>
<if test="clientId != null">client_id = #{clientId},</if>
</trim>
where id = #{id}
</update>
@@ -252,6 +262,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="calculationMode != '' and calculationMode != null">
and calculation_mode = #{calculationMode}
</if>
<if test="clientId != '' and clientId != null">
and client_id = #{clientId}
</if>
</where>
</select>
@@ -273,6 +286,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="businessId != '' and businessId != null">
and business_id = #{businessId}
</if>
<if test="clientId != '' and clientId != null">
and client_id = #{clientId}
</if>
</where>
</select>
@@ -291,6 +307,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="businessId != '' and businessId != null">
and business_id = #{businessId}
</if>
<if test="clientId != '' and clientId != null">
and client_id = #{clientId}
</if>
</where>
</select>
</mapper>
@@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="type" column="type" />
<result property="inSpeed" column="in_speed" />
<result property="outSpeed" column="out_speed" />
<result property="maxSpeed" column="max_speed" />
<result property="switchIp" column="switch_ip" />
<result property="createBy" column="create_by" />
<result property="updateBy" column="update_by" />
@@ -36,7 +37,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<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 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
</sql>
<select id="selectInitialSwitchInfoDetailsList" parameterType="InitialSwitchInfoDetails" resultMap="InitialSwitchInfoDetailsResult">
@@ -85,6 +86,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null">type,</if>
<if test="inSpeed != null">in_speed,</if>
<if test="outSpeed != null">out_speed,</if>
<if test="maxSpeed != null">max_speed,</if>
<if test="switchIp != null">switch_ip,</if>
<if test="createBy != null">create_by,</if>
<if test="updateBy != null">update_by,</if>
@@ -114,6 +116,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null">#{type},</if>
<if test="inSpeed != null">#{inSpeed},</if>
<if test="outSpeed != null">#{outSpeed},</if>
<if test="maxSpeed != null">#{maxSpeed},</if>
<if test="switchIp != null">#{switchIp},</if>
<if test="createBy != null">#{createBy},</if>
<if test="updateBy != null">#{updateBy},</if>
@@ -147,6 +150,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="type != null">type = #{type},</if>
<if test="inSpeed != null">in_speed = #{inSpeed},</if>
<if test="outSpeed != null">out_speed = #{outSpeed},</if>
<if test="maxSpeed != null">max_speed = #{maxSpeed},</if>
<if test="switchIp != null">switch_ip = #{switchIp},</if>
<if test="createBy != null">create_by = #{createBy},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
@@ -192,6 +196,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`type`,
in_speed AS inSpeed,
out_speed AS outSpeed,
max_speed AS maxSpeed,
switch_ip AS switchIp,
if_index AS ifIndex,
if_speed AS ifSpeed,
@@ -224,6 +229,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
`type`,
in_speed,
out_speed,
max_speed,
switch_ip,
if_index,
if_speed,
@@ -255,6 +261,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{item.type},
#{item.inSpeed},
#{item.outSpeed},
#{item.maxSpeed},
#{item.switchIp},
#{item.ifIndex},
#{item.ifSpeed},