Files
saas-houduan/ruoyi-modules/ruoyi-system/src/main/resources/mapper/system/EpsInitialTrafficDataMapper.xml
T

300 lines
12 KiB
XML
Raw Normal View History

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.system.mapper.EpsInitialTrafficDataMapper">
<update id="createEpsTrafficTable">
CREATE TABLE IF NOT EXISTS ${tableName} (
id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
`name` VARCHAR(255) COMMENT '接口名称',
`mac` VARCHAR(50) COMMENT 'MAC地址',
`status` VARCHAR(20) COMMENT '运行状态',
`type` VARCHAR(30) COMMENT '接口类型',
ipV4 VARCHAR(20) COMMENT 'IPv4地址',
`in_dropped` DECIMAL(20,2) COMMENT '入站丢包率(%)',
`out_dropped` DECIMAL(20,2) COMMENT '出站丢包率(%)',
`in_speed` varchar(50) COMMENT '接收带宽(bit)',
`out_speed` varchar(50) COMMENT '发送带宽(bit)',
`total_in_speed` varchar(50) COMMENT '总接收带宽(bit)',
`total_out_speed` varchar(50) COMMENT '总发送带宽(bit)',
`machine_flow` varchar(50) COMMENT '金山带宽(bit)',
`speed` varchar(100) COMMENT '协商速度',
`duplex` varchar(100) COMMENT '工作模式',
business_id varchar(50) COMMENT '业务代码',
business_name varchar(200) COMMENT '业务名称',
service_sn varchar(64) COMMENT '服务器SN',
node_name varchar(200) COMMENT '服务器名称',
revenue_method varchar(10) COMMENT '收益方式(1.流量,2包端)',
package_bandwidth DECIMAL(10,2) COMMENT '包端带宽值',
create_time DATETIME COMMENT '创建时间',
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
create_by VARCHAR(50) COMMENT '创建人',
update_by VARCHAR(50) COMMENT '修改人',
client_id VARCHAR(255) COMMENT '设备唯一标识',
PRIMARY KEY (id),
UNIQUE KEY uk_client_mac_name_time (client_id, mac, name, create_time),
INDEX idx_name_time (`name`,create_time),
INDEX idx_revenue_method (revenue_method),
INDEX idx_service_sn (service_sn)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='EPS设备流量初始数据表';
</update>
<update id="createEpsInitialTrafficTable">
CREATE TABLE IF NOT EXISTS ${tableName} (
2025-08-21 18:29:22 +08:00
id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
`name` VARCHAR(255) COMMENT '接口名称',
`mac` VARCHAR(20) COMMENT 'MAC地址',
`status` VARCHAR(20) COMMENT '运行状态',
2025-08-21 18:29:22 +08:00
`type` VARCHAR(30) COMMENT '接口类型',
ipV4 VARCHAR(20) COMMENT 'IPv4地址',
2025-09-02 19:54:54 +08:00
`in_dropped` DECIMAL(20,2) COMMENT '入站丢包率(%)',
`out_dropped` DECIMAL(20,2) COMMENT '出站丢包率(%)',
`in_speed` VARCHAR(50) COMMENT '接收带宽(Mbps)',
`out_speed` VARCHAR(50) COMMENT '发送带宽(Mbps)',
`total_in_speed` VARCHAR(50) COMMENT '总接收带宽(Mbps)',
`total_out_speed` VARCHAR(50) COMMENT '总发送带宽(Mbps)',
`speed` varchar(100) COMMENT '协商速度',
`duplex` varchar(100) 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 '修改人',
client_id VARCHAR(255) COMMENT '设备唯一标识',
PRIMARY KEY (id),
UNIQUE KEY uk_client_mac_name_time (client_id, mac, name, create_time),
2025-08-21 18:29:22 +08:00
INDEX idx_name_time (`name`,create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='初始带宽流量表';
</update>
2025-08-22 18:13:10 +08:00
<!-- 单条插入语句 -->
<insert id="insert">
INSERT INTO ${tableName} (
2025-08-22 18:13:10 +08:00
`name`,
`mac`,
`status`,
`type`,
ipV4,
`in_dropped`,
`out_dropped`,
`in_speed`,
`out_speed`,
`total_in_speed`,
`total_out_speed`,
`speed`,
`duplex`,
business_id,
2025-08-21 18:29:22 +08:00
business_name,
service_sn,
node_name,
revenue_method,
package_bandwidth,
create_by,
update_by,
client_id
) VALUES (
2025-08-22 18:13:10 +08:00
#{name},
#{mac},
#{status},
#{type},
#{ipV4},
#{inDropped},
#{outDropped},
#{inSpeed},
#{outSpeed},
#{totalInSpeed},
#{totalOutSpeed},
#{speed},
#{duplex},
#{businessId},
2025-08-21 18:29:22 +08:00
#{businessName},
#{serviceSn},
#{nodeName},
#{revenueMethod},
#{packageBandwidth},
#{createBy},
#{updateBy},
#{clientId}
)
</insert>
2025-08-22 18:13:10 +08:00
<!-- 批量插入语句 -->
<insert id="batchInsert">
INSERT IGNORE INTO ${tableName} (
2025-08-21 18:29:22 +08:00
id,
2025-08-22 18:13:10 +08:00
`name`,
`mac`,
`status`,
`type`,
ipV4,
`in_dropped`,
`out_dropped`,
`in_speed`,
`out_speed`,
`total_in_speed`,
`total_out_speed`,
`speed`,
`duplex`,
business_id,
2025-08-21 18:29:22 +08:00
business_name,
service_sn,
node_name,
revenue_method,
package_bandwidth,
create_time,
2025-08-21 18:29:22 +08:00
update_time,
create_by,
update_by,
client_id
) VALUES
2025-08-22 18:13:10 +08:00
<foreach collection="dataList" item="data" separator=",">
(
2025-08-21 18:29:22 +08:00
#{data.id,jdbcType=BIGINT},
2025-08-22 18:13:10 +08:00
#{data.name,jdbcType=VARCHAR},
#{data.mac,jdbcType=VARCHAR},
#{data.status,jdbcType=VARCHAR},
#{data.type,jdbcType=VARCHAR},
#{data.ipV4,jdbcType=VARCHAR},
#{data.inDropped,jdbcType=DECIMAL},
#{data.outDropped,jdbcType=DECIMAL},
#{data.inSpeed,jdbcType=VARCHAR},
#{data.outSpeed,jdbcType=VARCHAR},
#{data.totalInSpeed,jdbcType=VARCHAR},
#{data.totalOutSpeed,jdbcType=VARCHAR},
#{data.speed,jdbcType=VARCHAR},
#{data.duplex,jdbcType=VARCHAR},
2025-08-22 18:13:10 +08:00
#{data.businessId,jdbcType=VARCHAR},
2025-08-21 18:29:22 +08:00
#{data.businessName,jdbcType=VARCHAR},
#{data.serviceSn,jdbcType=VARCHAR},
#{data.nodeName,jdbcType=VARCHAR},
#{data.revenueMethod,jdbcType=VARCHAR},
#{data.packageBandwidth,jdbcType=DECIMAL},
#{data.createTime,jdbcType=TIMESTAMP},
#{data.updateTime,jdbcType=TIMESTAMP},
#{data.createBy,jdbcType=VARCHAR},
#{data.updateBy,jdbcType=VARCHAR},
#{data.clientId,jdbcType=VARCHAR}
)
</foreach>
</insert>
<!-- 条件查询 -->
<select id="selectByCondition" resultType="EpsInitialTrafficData">
SELECT
a.id,
GROUP_CONCAT(DISTINCT a.`name` SEPARATOR ',') AS name,
a.`mac` AS mac,
a.`status` AS status,
a.`type` AS type,
a.`ipV4` AS ipV4,
a.`in_dropped` AS inDropped,
a.`out_dropped` AS outDropped,
CAST(sum(ifnull(a.`in_speed`,0)) AS DECIMAL(20,0)) AS inSpeed,
CAST(sum(ifnull(a.`out_speed`,0)) AS DECIMAL(20,0)) AS outSpeed,
CAST(sum(ifnull(a.`total_in_speed`,0)) AS DECIMAL(20,0)) AS totalInSpeed,
CAST(sum(ifnull(a.`total_out_speed`,0)) AS DECIMAL(20,0)) AS totalOutSpeed,
a.`machine_flow` AS machineFlow,
a.`speed` AS speed,
a.`duplex` AS duplex,
a.business_id AS businessId,
a.business_name AS businessName,
a.service_sn AS serviceSn,
a.node_name AS nodeName,
a.revenue_method AS revenueMethod,
a.package_bandwidth AS packageBandwidth,
a.create_time AS createTime,
a.update_time AS updateTime,
a.create_by AS createBy,
a.update_by AS updateBy,
a.client_id AS clientId
FROM ${tableName} a
INNER JOIN rm_network_interface b ON a.client_id = b.client_id and a.mac=b.mac_address
AND (b.bind_ip = 1 OR b.bind_ip = 3)
AND b.new_flag = 1
<where>
2025-08-21 18:29:22 +08:00
<if test="serviceSn != '' and serviceSn != null">
and a.service_sn = #{serviceSn}
</if>
<if test="businessId != '' and businessId != null">
and a.business_id = #{businessId}
</if>
<if test="clientId != '' and clientId != null">
and a.client_id = #{clientId}
</if>
<if test="startTime != null">
and a.create_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and a.create_time &lt;= #{endTime}
</if>
<if test="revenueMethod != null">
and a.revenue_method = #{revenueMethod}
</if>
</where>
GROUP BY a.create_time DESC
</select>
2025-08-21 18:29:22 +08:00
<!-- 条件查询 -->
<select id="getAllTraficMsg" resultType="EpsInitialTrafficData">
SELECT
id,
2025-08-22 18:13:10 +08:00
`name` AS name,
`mac` AS mac,
`status` AS status,
`type` AS type,
`ipV4` AS ipV4,
`in_dropped` AS inDropped,
`out_dropped` AS outDropped,
`in_speed` AS inSpeed,
`out_speed` AS outSpeed,
`total_in_speed` AS totalInSpeed,
`total_out_speed` AS totalOutSpeed,
`speed` AS speed,
`duplex` AS duplex,
2025-08-21 18:29:22 +08:00
create_time AS createTime,
update_time AS updateTime,
create_by AS createBy,
update_by AS updateBy,
client_id AS clientId
FROM ${tableName}
<where>
<if test="startTime != null">
and create_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and create_time &lt;= #{endTime}
</if>
</where>
ORDER BY create_time desc
</select>
<update id="updateMachineTraffic" parameterType="EpsInitialTrafficData">
update ${tableName} set machine_flow=#{machineFlow} where client_id=#{clientId} and create_time=#{createTime}
</update>
<select id="getTrafficListByClientIds" resultType="EpsInitialTrafficData">
SELECT
CAST(sum(ifnull(in_speed,0)) AS DECIMAL(20,0)) AS inSpeed,
CAST(sum(ifnull(out_speed,0)) AS DECIMAL(20,0)) AS outSpeed,
create_time AS createTime
FROM ${tableName}
<where>
<if test="businessId != '' and businessId != null">
and business_id = #{businessId}
</if>
<if test="startTime != null">
and create_time &gt;= #{startTime}
</if>
<if test="endTime != null">
and create_time &lt;= #{endTime}
</if>
<if test="clientIds != null">
and client_id in
<foreach collection="clientIds.split(',')" item="clientId" open="(" separator="," close=")">
#{clientId}
</foreach>
</if>
</where>
group by create_time
ORDER BY out_speed desc
</select>
</mapper>