初始流量数据库读取mq入库

This commit is contained in:
gaoyutao
2025-08-21 18:29:22 +08:00
parent 80dbba70fe
commit 34049d1c78
30 changed files with 912 additions and 446 deletions
@@ -6,16 +6,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<update id="createEpsTrafficTable">
CREATE TABLE IF NOT EXISTS ${tableName} (
id BIGINT(20) COMMENT '唯一标识ID',
interface_name VARCHAR(50) COMMENT '接口名称',
mac_address VARCHAR(17) COMMENT 'MAC地址',
operation_status VARCHAR(20) COMMENT '运行状态',
interface_type VARCHAR(30) COMMENT '接口类型',
ipv4_address VARCHAR(15) COMMENT 'IPv4地址',
inbound_packet_loss DECIMAL(5,2) COMMENT '入站丢包率(%)',
outbound_packet_loss DECIMAL(5,2) COMMENT '出站丢包率(%)',
receive_bandwidth DECIMAL(10,2) COMMENT '接收带宽(Mbps)',
send_bandwidth DECIMAL(10,2) COMMENT '发送带宽(Mbps)',
id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
`name` VARCHAR(100) COMMENT '接口名称',
`mac` VARCHAR(50) COMMENT 'MAC地址',
`status` VARCHAR(20) COMMENT '运行状态',
`type` VARCHAR(30) COMMENT '接口类型',
ipV4 VARCHAR(20) COMMENT 'IPv4地址',
`in_dropped` DECIMAL(5,2) COMMENT '入站丢包率(%)',
`out_dropped` DECIMAL(5,2) COMMENT '出站丢包率(%)',
`in_speed` varchar(20) COMMENT '接收带宽(Mbps)',
`out_speed` varchar(20) COMMENT '发送带宽(Mbps)',
business_id varchar(12) COMMENT '业务代码',
business_name varchar(50) COMMENT '业务名称',
service_sn varchar(50) COMMENT '服务器SN',
@@ -26,75 +26,125 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
create_by VARCHAR(50) COMMENT '创建人',
update_by VARCHAR(50) COMMENT '修改人',
client_id VARCHAR(64) COMMENT '设备唯一标识',
PRIMARY KEY (id),
INDEX idx_name_time (interface_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} (
id BIGINT(20) COMMENT '唯一标识ID',
interface_name VARCHAR(50) COMMENT '接口名称',
mac_address VARCHAR(17) COMMENT 'MAC地址',
operation_status VARCHAR(20) COMMENT '运行状态',
interface_type VARCHAR(30) COMMENT '接口类型',
ipv4_address VARCHAR(15) COMMENT 'IPv4地址',
inbound_packet_loss DECIMAL(5,2) COMMENT '入站丢包率(%)',
outbound_packet_loss DECIMAL(5,2) COMMENT '出站丢包率(%)',
receive_bandwidth DECIMAL(10,2) COMMENT '接收带宽(Mbps)',
send_bandwidth DECIMAL(10,2) COMMENT '发送带宽(Mbps)',
id BIGINT(20) AUTO_INCREMENT COMMENT '唯一标识ID',
`name` VARCHAR(100) COMMENT '接口名称',
`mac` VARCHAR(20) COMMENT 'MAC地址',
`status` VARCHAR(20) COMMENT '运行状态',
`type` VARCHAR(30) COMMENT '接口类型',
ipV4 VARCHAR(20) COMMENT 'IPv4地址',
`in_dropped` DECIMAL(5,2) COMMENT '入站丢包率(%)',
`out_dropped` DECIMAL(5,2) COMMENT '出站丢包率(%)',
`in_speed` VARCHAR(20) COMMENT '接收带宽(Mbps)',
`out_speed` VARCHAR(20) COMMENT '发送带宽(Mbps)',
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 '修改人',
client_id VARCHAR(64) COMMENT '设备唯一标识',
PRIMARY KEY (id),
INDEX idx_name_time (interface_name,create_time)
INDEX idx_name_time (`name`,create_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='初始带宽流量表';
</update>
<!-- 单条插入 -->
<insert id="insert">
INSERT INTO ${tableName} (
receive_traffic,
send_traffic,
device_sn,
interface_name,
mac_address,
operation_status,
interface_type,
ipv4_address,
inbound_packet_loss,
outbound_packet_loss,
receive_bandwidth,
send_bandwidth,
business_id,
traffic_port,
create_time,
remark1, remark2, remark3, remark4
business_name,
service_sn,
node_name,
revenue_method,
package_bandwidth,
create_by,
update_by,
client_id
) VALUES (
#{receiveTraffic},
#{sendTraffic},
#{deviceSn},
#{interfaceName},
#{macAddress},
#{operationStatus},
#{interfaceType},
#{ipv4Address},
#{inboundPacketLoss},
#{outboundPacketLoss},
#{receiveBandwidth},
#{sendBandwidth},
#{businessId},
#{trafficPort},
#{createTime},
#{remark1}, #{remark2},
#{remark3}, #{remark4}
#{businessName},
#{serviceSn},
#{nodeName},
#{revenueMethod},
#{packageBandwidth},
#{createBy},
#{updateBy},
#{clientId}
)
</insert>
<!-- 批量插入 -->
<insert id="batchInsert">
INSERT INTO ${tableName} (
receive_traffic,
send_traffic,
device_sn,
id,
interface_name,
mac_address,
operation_status,
interface_type,
ipv4_address,
inbound_packet_loss,
outbound_packet_loss,
receive_bandwidth,
send_bandwidth,
business_id,
traffic_port,
business_name,
service_sn,
node_name,
revenue_method,
package_bandwidth,
create_time,
remark1, remark2, remark3, remark4
update_time,
create_by,
update_by,
client_id
) VALUES
<foreach collection="dataList" item="data" separator=",">
<foreach collection="list" item="data" separator=",">
(
#{data.receiveTraffic},
#{data.sendTraffic},
#{data.deviceSn},
#{data.businessId},
#{data.trafficPort},
#{data.createTime},
#{data.remark1}, #{data.remark2},
#{data.remark3}, #{data.remark4}
#{data.id,jdbcType=BIGINT},
#{data.interfaceName,jdbcType=VARCHAR},
#{data.macAddress,jdbcType=CHAR},
#{data.operationStatus,jdbcType=VARCHAR},
#{data.interfaceType,jdbcType=VARCHAR},
#{data.ipv4Address,jdbcType=VARCHAR},
#{data.inboundPacketLoss,jdbcType=DECIMAL},
#{data.outboundPacketLoss,jdbcType=DECIMAL},
#{data.receiveBandwidth,jdbcType=DECIMAL},
#{data.sendBandwidth,jdbcType=DECIMAL},
#{data.businessId,jdbcType=CHAR},
#{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>
@@ -102,18 +152,31 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<!-- 条件查询 -->
<select id="selectByCondition" resultType="EpsInitialTrafficData">
SELECT
id,
receive_traffic as receiveTraffic,
send_traffic as sendTraffic,
device_sn as deviceSn,
business_id as businessId,
traffic_port as trafficPort,
create_time as createTime,
remark1, remark2, remark3, remark4
id,
`name` AS interfaceName,
`mac` AS macAddress,
`status` AS operationStatus,
`type` AS interfaceType,
`ipV4` AS ipv4Address,
`in_dropped` AS inboundPacketLoss,
`out_dropped` AS outboundPacketLoss,
`in_speed` AS receiveBandwidth,
`out_speed` AS sendBandwidth,
business_id AS businessId,
business_name AS businessName,
service_sn AS serviceSn,
node_name AS nodeName,
revenue_method AS revenueMethod,
package_bandwidth AS packageBandwidth,
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="deviceSn != '' and deviceSn != null">
and device_sn = #{deviceSn}
<if test="serviceSn != '' and serviceSn != null">
and service_sn = #{serviceSn}
</if>
<if test="startTime != null">
and create_time &gt;= #{startTime}
@@ -125,4 +188,35 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</where>
ORDER BY create_time desc
</select>
<!-- 条件查询 -->
<select id="getAllTraficMsg" resultType="EpsInitialTrafficData">
SELECT
id,
`name` AS interfaceName,
`mac` AS macAddress,
`status` AS operationStatus,
`type` AS interfaceType,
`ipV4` AS ipv4Address,
`in_dropped` AS inboundPacketLoss,
`out_dropped` AS outboundPacketLoss,
`in_speed` AS receiveBandwidth,
`out_speed` AS sendBandwidth,
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>
</mapper>
@@ -116,4 +116,23 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
#{id}
</foreach>
</delete>
<select id="getNodeMsgByIp" parameterType="String" resultType="java.util.Map">
SELECT
rrr.hardware_sn AS hardwareSn,
rrr.resource_name AS resourceName,
esrc.revenue_method AS revenueMethod,
esrc.business_code AS businessCode,
esrc.business_name AS businessName
FROM
rm_resource_registration rrr
LEFT JOIN
eps_server_revenue_config esrc
ON
rrr.hardware_sn = esrc.hardware_sn
<where>
and rrr.registration_status = '1'
<if test="ipAddress != null and ipAddress != ''"> and rrr.ip_address = #{ipAddress}</if>
</where>
</select>
</mapper>