交换机流量数据表改为分表

This commit is contained in:
gaoyutao
2025-11-21 18:32:03 +08:00
parent be2d123902
commit c6e778c74e
19 changed files with 747 additions and 73 deletions
@@ -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 &gt;= #{startTime}</if>
<if test="endTime != null and endTime != ''"> and create_time &lt;= #{endTime}</if>
</where>
</select>
</mapper>