yeg
2026-09-05 bc9a169ce3648467136a279d167f72c4fbab9595
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?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.TCollectorMapper">
 
    <resultMap type="TCollector" id="TCollectorResult">
        <id property="collectorId" column="collector_id" />
        <result property="adapterId" column="adapter_id" />
        <result property="collectorCode" column="collector_code" />
        <result property="ipAddress" column="ip_address" />
        <result property="macAddress" column="mac_address" />
        <result property="collectorName" column="collector_name" />
        <result property="manufacturer" column="manufacturer" />
        <result property="model" column="model" />
        <result property="channelCount" column="channel_count" />
        <result property="onlineStatus" column="online_status" />
        <result property="testStatus" column="test_status" />
        <result property="currentTest" column="current_test" />
        <result property="lastSeenAtUtc" column="last_seen_at_utc" />
        <result property="status" column="status" />
        <result property="delFlag" column="del_flag" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
        <result property="remark" column="remark" />
    </resultMap>
 
    <sql id="selectCollectorVo">
        select c.collector_id, c.collector_code, c.adapter_id, c.ip_address, c.mac_address, c.collector_name,
               c.manufacturer, c.model, c.channel_count,
               case when upper(c.online_status) = 'ONLINE' or c.online_status = '1' then '1' else '0' end as online_status,
               c.last_seen_at_utc,
               case when exists (
                   select 1 from t_test_collector_channel mapping
                   join t_test test_fact on test_fact.test_id = mapping.test_id
                   where mapping.collector_id = c.collector_id
                     and test_fact.del_flag = 0
                     and test_fact.test_status in ('RUNNING', 'PAUSED')
               ) then '1' else '0' end as test_status,
               case when exists (
                   select 1 from t_test_collector_channel mapping
                   join t_test test_fact on test_fact.test_id = mapping.test_id
                   where mapping.collector_id = c.collector_id
                     and test_fact.del_flag = 0
                     and test_fact.test_status in ('RUNNING', 'PAUSED')
               ) then '待确认' else null end as current_test,
               c.status, c.del_flag, c.create_by,
               c.create_time, c.update_by, c.update_time, c.remark
        from t_collector c
    </sql>
 
    <select id="selectCollectorById" parameterType="Long" resultMap="TCollectorResult">
        <include refid="selectCollectorVo" />
        where collector_id = #{collectorId}
          and del_flag = '0'
    </select>
 
    <select id="selectCollectorList" parameterType="TCollector" resultMap="TCollectorResult">
        <include refid="selectCollectorVo" />
        <where>
            del_flag = '0'
            <if test="device != null and device != ''">
                and (ip_address like concat('%', #{device}, '%')
                    or collector_code like concat('%', #{device}, '%')
                    or mac_address like concat('%', #{device}, '%')
                    or collector_name like concat('%', #{device}, '%'))
            </if>
            <if test="beginCreateTime != null and beginCreateTime != ''">
                and create_time &gt;= #{beginCreateTime}
            </if>
            <if test="endCreateTime != null and endCreateTime != ''">
                and create_time &lt;= #{endCreateTime}
            </if>
            <if test="onlineStatus != null and onlineStatus != ''">
                and online_status = #{onlineStatus}
            </if>
            <if test="testStatus != null and testStatus != ''">
                and (case when exists (
                    select 1 from t_test_collector_channel mapping
                    join t_test test_fact on test_fact.test_id = mapping.test_id
                    where mapping.collector_id = c.collector_id
                      and test_fact.del_flag = 0
                      and test_fact.test_status in ('RUNNING', 'PAUSED')
                ) then '1' else '0' end) = #{testStatus}
            </if>
            <if test="status != null and status != ''">
                and status = #{status}
            </if>
        </where>
        order by create_time desc, collector_id desc
    </select>
 
    <select id="selectRegisteredCollectorCodes" resultType="String">
        select collector_code
        from t_collector
        where del_flag = '0'
    </select>
 
    <select id="selectCollectorByCode" parameterType="String" resultMap="TCollectorResult">
        <include refid="selectCollectorVo" />
        where collector_code = #{collectorCode}
          and del_flag = '0'
        limit 1
    </select>
 
    <select id="selectCollectorByMacAddress" parameterType="String" resultMap="TCollectorResult">
        <include refid="selectCollectorVo" />
        where mac_address = #{macAddress}
          and del_flag = '0'
        limit 1
    </select>
 
    <insert id="insertCollector" parameterType="TCollector" useGeneratedKeys="true" keyProperty="collectorId">
        insert into t_collector
        (collector_code, ip_address, mac_address, collector_name, manufacturer, model,
         channel_count, online_status, last_seen_at_utc,
         status, del_flag, create_by, create_time, remark)
        values
        (#{collectorCode}, #{ipAddress}, #{macAddress}, #{collectorName}, #{manufacturer}, #{model},
         #{channelCount}, case when #{onlineStatus} in ('1', 'ONLINE') then 'ONLINE' else 'OFFLINE' end,
         #{lastSeenAtUtc},
         #{status}, #{delFlag}, #{createBy}, #{createTime}, #{remark})
    </insert>
 
    <update id="updateRegisteredObservation">
        update t_collector
        set online_status = case when #{onlineStatus} in ('1', 'ONLINE') then 'ONLINE' else 'OFFLINE' end,
            last_seen_at_utc = utc_timestamp(3), update_time = sysdate()
        where collector_code = #{collectorCode} and del_flag = 0
    </update>
 
    <update id="updateCollector" parameterType="TCollector">
        update t_collector
        <set>
            collector_code = #{collectorCode},
            ip_address = #{ipAddress},
            mac_address = #{macAddress},
            collector_name = #{collectorName},
            manufacturer = #{manufacturer},
            model = #{model},
            channel_count = #{channelCount},
            status = #{status},
            remark = #{remark},
            update_by = #{updateBy},
            update_time = #{updateTime}
        </set>
        where collector_id = #{collectorId}
          and del_flag = '0'
    </update>
 
    <update id="updateCollectorStatus" parameterType="TCollector">
        update t_collector
        set status = #{status},
            update_by = #{updateBy},
            update_time = #{updateTime}
        where collector_id = #{collectorId}
          and del_flag = '0'
    </update>
 
    <update id="deleteCollectorById">
        update t_collector
        set del_flag = cast(collector_id as char),
            update_by = #{updateBy},
            update_time = sysdate()
        where collector_id = #{collectorId}
          and del_flag = '0'
    </update>
</mapper>