yeg
2026-09-29 b78295e8da96c3e5e76befeef9582ce5273dbb74
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?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.battery.business.mapper.TDetectionCabinetMapper">
 
    <resultMap type="TDetectionCabinet" id="TDetectionCabinetResult">
        <id property="cabinetId" column="cabinet_id" />
        <result property="adapterId" column="adapter_id" />
        <result property="adapterCode" column="adapter_code" />
        <result property="cabinetCode" column="cabinet_code" />
        <result property="cabinetName" column="cabinet_name" />
        <result property="ipAddress" column="ip_address" />
        <result property="macAddress" column="mac_address" />
        <result property="manufacturer" column="manufacturer" />
        <result property="model" column="model" />
        <result property="capacity" column="capacity" />
        <result property="channelCount" column="channel_count" />
        <result property="onlineStatus" column="online_status" />
        <result property="testStatus" column="test_status" />
        <result property="status" column="status" />
        <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" />
        <result property="delFlag" column="del_flag" />
        <result property="registrationStatus" column="registration_status" />
        <collection property="relatedTests" column="cabinet_id"
                    select="com.battery.business.mapper.DeviceRelatedTestMapper.selectCabinetRelatedTests" />
    </resultMap>
 
    <sql id="activeCabinetTestExists">
        exists (
            select 1 from t_test_channel_binding binding
            join t_detection_channel channel_fact on channel_fact.channel_id = binding.channel_id
            join t_test test_fact on test_fact.test_id = binding.test_id
            where channel_fact.cabinet_id = t_detection_cabinet.cabinet_id
              and channel_fact.del_flag = 0 and test_fact.del_flag = 0
              and test_fact.test_status in ('RUNNING', 'PAUSED', 'RUNNING_ABNORMAL')
        )
    </sql>
 
    <sql id="selectDetectionCabinetVo">
        select cabinet_id, adapter_id, adapter_code, cabinet_code, cabinet_name, ip_address, mac_address,
               manufacturer, model, capacity, channel_count,
               case when upper(online_status) = 'ONLINE' or online_status = '0' then '0' else '1' end as online_status,
               case when <include refid="activeCabinetTestExists"/> then '1' else '0' end as test_status,
               status, create_by, create_time, update_by, update_time, remark, del_flag, registration_status
        from t_detection_cabinet
    </sql>
 
    <select id="selectDetectionCabinetList" parameterType="TDetectionCabinet" resultMap="TDetectionCabinetResult">
        <include refid="selectDetectionCabinetVo"/>
        <where>
            del_flag = 0 and registration_status = 'REGISTERED'
            <if test="device != null and device != ''">
                and (ip_address like concat('%', #{device}, '%')
                    or cabinet_code like concat('%', #{device}, '%')
                    or mac_address like concat('%', #{device}, '%')
                    or cabinet_name like concat('%', #{device}, '%'))
            </if>
            <if test="beginCreateTime != null">and create_time &gt;= #{beginCreateTime}</if>
            <if test="endCreateTime != null">and create_time &lt;= #{endCreateTime}</if>
            <if test="cabinetCode != null and cabinetCode != ''">and cabinet_code like concat('%', #{cabinetCode}, '%')</if>
            <if test="cabinetName != null and cabinetName != ''">and cabinet_name like concat('%', #{cabinetName}, '%')</if>
            <if test="ipAddress != null and ipAddress != ''">and ip_address = #{ipAddress}</if>
            <if test="macAddress != null and macAddress != ''">and mac_address = #{macAddress}</if>
            <if test="status != null and status != ''">and status = #{status}</if>
        </where>
        order by create_time desc, cabinet_id desc
    </select>
 
    <select id="selectRegisteredCabinetCodes" resultType="String">
        select cabinet_code from t_detection_cabinet where del_flag = 0
    </select>
 
    <select id="selectDetectionCabinetById" parameterType="Long" resultMap="TDetectionCabinetResult">
        <include refid="selectDetectionCabinetVo"/>
        where cabinet_id = #{cabinetId} and del_flag = 0 and registration_status = 'REGISTERED'
    </select>
 
    <select id="selectByCabinetCode" parameterType="String" resultMap="TDetectionCabinetResult">
        <include refid="selectDetectionCabinetVo"/>
        where cabinet_code = #{cabinetCode} and del_flag = 0 limit 1
    </select>
 
    <select id="selectByMacAddress" parameterType="String" resultMap="TDetectionCabinetResult">
        <include refid="selectDetectionCabinetVo"/>
        where mac_address = #{macAddress} and del_flag = 0 limit 1
    </select>
 
    <insert id="insertDetectionCabinet" parameterType="TDetectionCabinet" useGeneratedKeys="true" keyProperty="cabinetId">
        insert into t_detection_cabinet
        (adapter_id, adapter_code, cabinet_code, cabinet_name, manufacturer, model, capacity, channel_count,
         vendor_device_type, vendor_device_id, ip_address, mac_address, online_status, last_seen_at_utc,
         registration_status, status, create_by, create_time, remark, del_flag)
        values
        (#{adapterId}, #{adapterCode}, #{cabinetCode}, #{cabinetName}, #{manufacturer}, #{model}, #{capacity},
         #{channelCount}, #{vendorDeviceType}, #{vendorDeviceId}, #{ipAddress}, #{macAddress}, #{onlineStatus},
         #{lastSeenAtUtc}, 'REGISTERED', #{status}, #{createBy}, sysdate(), #{remark}, 0)
    </insert>
 
    <insert id="insertDetectionChannel" parameterType="TDetectionChannel" useGeneratedKeys="true" keyProperty="channelId">
        insert into t_detection_channel
        (adapter_id, adapter_code, cabinet_id, devtype, devid, subdevid, chlid, display_no,
         online_status, work_status, last_seen_at_utc, status, create_time, del_flag)
        values
        (#{adapterId}, #{adapterCode}, #{cabinetId}, #{devtype}, #{devid}, #{subdevid}, #{chlid}, #{displayNo},
         #{onlineStatus}, #{workStatus}, #{lastSeenAtUtc}, '0', sysdate(), 0)
    </insert>
 
    <update id="updateRegisteredCabinetObservation">
        update t_detection_cabinet
        set vendor_device_type = coalesce(vendor_device_type, #{devtype}),
            vendor_device_id = coalesce(vendor_device_id, #{devid}),
            online_status = #{onlineStatus}, update_time = sysdate()
        <if test="updateLastSeen">, last_seen_at_utc = #{lastSeenAtUtc}</if>
        where adapter_code = #{adapterCode}
          and ((vendor_device_type = #{devtype} and vendor_device_id = #{devid})
               or cabinet_code = concat(#{adapterCode}, '-', #{devtype}, '-', #{devid}))
          and del_flag = 0 and registration_status = 'REGISTERED'
    </update>
 
    <update id="updateRegisteredChannelObservation">
        update t_detection_channel
        set online_status = case when #{onlineStatus} in ('ONLINE', '1') then 'ONLINE' else 'OFFLINE' end,
            work_status = case #{workStatus}
                when 'PAUSED' then 'PAUSED'
                when 'PROTECTED' then 'ABNORMAL'
                when 'FINISHED' then 'ENDED'
                when 'STOPPED' then 'ENDED'
                when 'WORKING' then 'RUNNING'
                when 'SYNCHRONIZING' then 'RUNNING'
                when 'LIT' then 'RUNNING'
                when 'WAITING_TIMEOUT' then 'RUNNING'
                when 'WAITING_START' then 'RUNNING'
                when 'LOCKED' then 'RUNNING'
                when 'RUNNING' then 'RUNNING'
                else 'UNOBSERVABLE' end,
            update_time = sysdate()
        <if test="updateLastSeen">, last_seen_at_utc = #{lastSeenAtUtc}</if>
        where adapter_code = #{adapterCode}
          and devtype = #{devtype} and devid = #{devid}
          and subdevid = #{subdevid} and chlid = #{chlid}
          and del_flag = 0
          and exists (select 1 from t_detection_cabinet cabinet
                      where cabinet.cabinet_id = t_detection_channel.cabinet_id
                        and cabinet.del_flag = 0 and cabinet.registration_status = 'REGISTERED')
    </update>
 
    <update id="markRegisteredFactsUnobservable">
        update t_detection_channel
        set online_status = 'OFFLINE', work_status = 'UNOBSERVABLE', update_time = sysdate()
        where adapter_code = #{adapterCode} and del_flag = 0
    </update>
 
    <update id="markRegisteredCabinetsOffline">
        update t_detection_cabinet
        set online_status = 'OFFLINE', update_time = sysdate()
        where adapter_code = #{adapterCode} and del_flag = 0 and registration_status = 'REGISTERED'
    </update>
 
    <update id="touchRegisteredChannelObservation">
        update t_detection_channel
        set last_seen_at_utc = #{lastSeenAtUtc}, update_time = sysdate()
        where adapter_code = #{adapterCode}
          and devtype = #{devtype} and devid = #{devid}
          and subdevid = #{subdevid} and chlid = #{chlid}
          and online_status = 'ONLINE' and del_flag = 0
    </update>
 
    <update id="touchRegisteredCabinetObservation">
        update t_detection_cabinet
        set last_seen_at_utc = #{lastSeenAtUtc}, update_time = sysdate()
        where adapter_code = #{adapterCode}
          and vendor_device_type = #{devtype} and vendor_device_id = #{devid}
          and online_status = 'ONLINE' and del_flag = 0 and registration_status = 'REGISTERED'
    </update>
 
    <update id="updateDetectionCabinet" parameterType="TDetectionCabinet">
        update t_detection_cabinet
        <set>
            <if test="cabinetCode != null and cabinetCode != ''">cabinet_code = #{cabinetCode},</if>
            <if test="cabinetName != null and cabinetName != ''">cabinet_name = #{cabinetName},</if>
            <if test="ipAddress != null and ipAddress != ''">ip_address = #{ipAddress},</if>
            <if test="macAddress != null and macAddress != ''">mac_address = #{macAddress},</if>
            <if test="manufacturer != null">manufacturer = #{manufacturer},</if>
            <if test="model != null">model = #{model},</if>
            <if test="capacity != null">capacity = #{capacity},</if>
            <if test="channelCount != null">channel_count = #{channelCount},</if>
            <if test="remark != null">remark = #{remark},</if>
            update_by = #{updateBy}, update_time = sysdate()
        </set>
        where cabinet_id = #{cabinetId} and del_flag = 0 and registration_status = 'REGISTERED'
    </update>
 
    <update id="updateDetectionCabinetStatus" parameterType="TDetectionCabinet">
        update t_detection_cabinet set status = #{status}, update_by = #{updateBy}, update_time = sysdate()
        where cabinet_id = #{cabinetId} and del_flag = 0 and registration_status = 'REGISTERED'
    </update>
 
    <update id="deleteDetectionChannelsByCabinetId">
        update t_detection_channel set del_flag = channel_id, update_time = sysdate()
        where cabinet_id = #{cabinetId} and del_flag = 0
    </update>
 
    <update id="deleteDetectionCabinetById">
        update t_detection_cabinet
        set del_flag = cabinet_id, update_by = #{updateBy}, update_time = sysdate()
        where cabinet_id = #{cabinetId} and del_flag = 0 and registration_status = 'REGISTERED'
    </update>
 
</mapper>