This commit is contained in:
2025-09-24 11:10:42 +08:00
parent a72b60be98
commit 05b923b1ac
348 changed files with 611 additions and 8472 deletions

View File

@@ -23,7 +23,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="memoryUsage" column="memory_usage" />
<result property="diskUsage" column="disk_usage" />
<result property="networkStatus" column="network_status" />
<result property="heartbeatTime" column="heartbeat_time" />
</resultMap>
<resultMap type="ClientErrorReport" id="ClientErrorReportResult">
@@ -76,7 +75,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="memoryUsage != null">memory_usage,</if>
<if test="diskUsage != null">disk_usage,</if>
<if test="networkStatus != null and networkStatus != ''">network_status,</if>
<if test="heartbeatTime != null">heartbeat_time,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="clientId != null and clientId != ''">#{clientId},</if>
@@ -96,7 +94,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="memoryUsage != null">#{memoryUsage},</if>
<if test="diskUsage != null">#{diskUsage},</if>
<if test="networkStatus != null and networkStatus != ''">#{networkStatus},</if>
<if test="heartbeatTime != null">#{heartbeatTime},</if>
</trim>
</insert>
@@ -119,7 +116,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="memoryUsage != null">memory_usage = #{memoryUsage},</if>
<if test="diskUsage != null">disk_usage = #{diskUsage},</if>
<if test="networkStatus != null and networkStatus != ''">network_status = #{networkStatus},</if>
<if test="heartbeatTime != null">heartbeat_time = #{heartbeatTime},</if>
update_time = NOW()
</trim>
where client_id = #{clientId}
@@ -305,20 +301,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
update client_info set online = #{param2} where client_id = #{param1}
</update>
<!-- 更新客户端心跳信息 -->
<update id="updateClientHeartbeat" parameterType="ClientInfo">
update client_info
<set>
<if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
<if test="heartbeatTime != null">heartbeat_time = #{heartbeatTime},</if>
<if test="online != null and online != ''">online = #{online},</if>
<if test="cpuUsage != null">cpu_usage = #{cpuUsage},</if>
<if test="memoryUsage != null">memory_usage = #{memoryUsage},</if>
<if test="diskUsage != null">disk_usage = #{diskUsage},</if>
<if test="networkStatus != null and networkStatus != ''">network_status = #{networkStatus}</if>
</set>
where client_id = #{clientId}
</update>
<!-- 更新客户端认证信息 -->
<update id="updateClientAuth" parameterType="ClientAuthInfo">
@@ -353,12 +335,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
from client_error_report
</sql>
<!-- 查询客户端心跳记录通用SQL -->
<sql id="selectClientHeartbeatVo">
select id, client_id, username, heartbeat_time, cpu_usage, memory_usage,
disk_usage, network_status
from client_heartbeat
</sql>
<!-- 查询客户端数据采集报告通用SQL -->
<sql id="selectClientDataReportVo">
@@ -384,7 +360,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
LEFT JOIN
(
SELECT
DATE_FORMAT(auth_time, '%Y-%m-%d') as heartbeat_date,
DATE_FORMAT(auth_time, '%Y-%m-%d') as auth_date,
COUNT(DISTINCT client_id) as client_count
FROM
client_info
@@ -392,7 +368,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
auth_time >= DATE_SUB(CURDATE(), INTERVAL 6 DAY)
GROUP BY
DATE_FORMAT(auth_time, '%Y-%m-%d')
) counts ON days.date_str = counts.heartbeat_date
) counts ON days.date_str = counts.auth_date
ORDER BY
days.date_str ASC
</select>
@@ -436,87 +412,34 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
AND collect_time >= DATE_SUB(NOW(), INTERVAL 24 HOUR)
</select>
<!-- 插入1688爬取风控监控数据 -->
<insert id="insertAlibaba1688MonitorData" parameterType="java.util.Map">
INSERT INTO client_alibaba1688_monitor
(
client_id,
ip_address,
event_type,
event_time,
duration,
create_time
)
VALUES
(
#{clientId},
#{ipAddress},
#{eventType},
#{eventTime},
#{duration},
#{createTime}
)
</insert>
<!-- 查询1688爬取风控监控数据列表 -->
<select id="selectAlibaba1688MonitorList" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
m.id,
m.client_id,
m.ip_address,
m.event_type,
m.event_time,
m.duration,
m.create_time,
a.username,
a.hostname
FROM
client_alibaba1688_monitor m
LEFT JOIN
client_info a ON m.client_id = a.client_id
<where>
AND m.event_type != 'MOBILE_FIRST_ACCESS'
<if test="clientId != null and clientId != ''">
AND m.client_id = #{clientId}
</if>
<if test="ipAddress != null and ipAddress != ''">
AND m.ip_address LIKE concat('%', #{ipAddress}, '%')
</if>
<if test="eventType != null and eventType != ''">
AND m.event_type = #{eventType}
</if>
<if test="beginTime != null and beginTime != ''">
AND DATE_FORMAT(m.create_time, '%Y-%m-%d') &gt;= #{beginTime}
</if>
<if test="endTime != null and endTime != ''">
AND DATE_FORMAT(m.create_time, '%Y-%m-%d') &lt;= #{endTime}
</if>
</where>
ORDER BY m.create_time DESC
</select>
<!-- 查询1688爬取风控监控统计信息 -->
<select id="selectAlibaba1688Statistics" resultType="java.util.Map">
SELECT
COUNT(*) AS totalEvents,
SUM(CASE WHEN event_type = 'MOBILE_BLOCKED' THEN 1 ELSE 0 END) AS mobileBlockedCount,
SUM(CASE WHEN event_type = 'DESKTOP_BLOCKED' THEN 1 ELSE 0 END) AS desktopBlockedCount,
COUNT(DISTINCT ip_address) AS uniqueIpCount,
AVG(CASE WHEN event_type = 'MOBILE_BLOCKED' AND duration > 0 THEN duration ELSE NULL END) / 1000 AS avgMobileDuration,
AVG(CASE WHEN event_type = 'DESKTOP_BLOCKED' AND duration > 0 THEN duration ELSE NULL END) / 1000 AS avgDesktopDuration
FROM
client_alibaba1688_monitor
WHERE
create_time >= DATE_SUB(NOW(), INTERVAL 30 DAY)
AND event_type != 'MOBILE_FIRST_ACCESS'
</select>
<!-- 将过期客户端设置为离线状态7天未心跳 -->
<!-- 将过期客户端设置为离线状态5分钟未心跳 -->
<update id="updateExpiredClientsOffline">
UPDATE client_info
SET online = '0'
WHERE online = '1'
AND (heartbeat_time IS NULL OR heartbeat_time &lt; DATE_SUB(NOW(), INTERVAL 7 DAY))
UPDATE client_info
SET online = '0'
WHERE online = '1'
AND (last_active_time IS NULL OR last_active_time &lt; DATE_SUB(NOW(), INTERVAL 5 MINUTE))
</update>
<!-- 查询在线设备数量 -->
<select id="selectOnlineDeviceCount" resultType="int">
SELECT COUNT(*) FROM client_device WHERE status = 'online'
</select>
<!-- 查询在线设备列表 -->
<select id="selectOnlineDevices" resultType="com.ruoyi.system.domain.ClientDevice">
SELECT device_id as deviceId, username, name, os, status, ip, location, last_active_at as lastActiveAt
FROM client_device
WHERE status = 'online'
ORDER BY last_active_at DESC
</select>
<!-- 将过期设备设置为离线状态5分钟未活跃 -->
<update id="updateExpiredDevicesOffline">
UPDATE client_device
SET status = 'offline'
WHERE status = 'online'
AND (last_active_at IS NULL OR last_active_at &lt; DATE_SUB(NOW(), INTERVAL 5 MINUTE))
</update>
<!-- 删除30天前的错误报告 -->