zjk
2026-07-31 8665daa7aa863f96d0d8f27c167edae1efc38022
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
214
215
216
217
218
219
<?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.SysVisitorMachineMapper">
 
    <resultMap type="SysVisitorMachine" id="SysVisitorMachineResult">
        <id     property="machineId"    column="machine_id" />
        <result property="areaId"       column="area_id" />
        <result property="deviceName"   column="device_name" />
        <result property="brand"        column="brand" />
        <result property="deviceId"     column="device_id" />
        <result property="enabled"      column="enabled" />
        <result property="onlineStatus" column="online_status" />
        <result property="fingerprint"  column="fingerprint" />
        <result property="delFlag"      column="del_flag" />
        <result property="remark"       column="remark" />
        <result property="createBy"     column="create_by" />
        <result property="createTime"   column="create_time" />
        <result property="updateBy"     column="update_by" />
        <result property="updateTime"   column="update_time" />
    </resultMap>
 
    <resultMap type="SysVisitorMachineVO" id="SysVisitorMachineVOResult">
        <id     property="machineId"    column="machine_id" />
        <result property="areaId"       column="area_id" />
        <result property="areaName"     column="area_name" />
        <result property="deviceName"   column="device_name" />
        <result property="brand"        column="brand" />
        <result property="deviceId"     column="device_id" />
        <result property="fingerprint"  column="fingerprint" />
        <result property="enabled"      column="enabled" />
        <result property="onlineStatus" column="online_status" />
        <result property="remark"       column="remark" />
        <result property="createTime"   column="create_time" />
    </resultMap>
 
    <sql id="selectMachineDomain">
        select machine_id,
               area_id,
               device_name,
               brand,
               device_id,
               enabled,
               online_status,
               fingerprint,
               del_flag,
               remark,
               create_by,
               create_time,
               update_by,
               update_time
        from t_visitor_machine
    </sql>
 
    <sql id="selectMachineVo">
        select m.machine_id,
               m.area_id,
               a.area_name,
               m.device_name,
               m.brand,
               m.device_id,
               m.fingerprint,
               m.enabled,
               m.online_status,
               m.remark,
               m.create_time
        from t_visitor_machine m
        left join t_visit_area a on a.area_id = m.area_id and a.del_flag = '0'
    </sql>
 
    <select id="pageList" resultMap="SysVisitorMachineVOResult">
        <include refid="selectMachineVo" />
        <where>
            and m.del_flag = '0'
            <if test="query.areaId != null">
                and (m.area_id = #{query.areaId}
                     or m.area_id in (
                        select area_id from t_visit_area
                        where del_flag = '0'
                          and find_in_set(#{query.areaId}, ancestors)
                     ))
            </if>
            <if test="query.deviceName != null and query.deviceName != ''">
                and m.device_name like concat('%', #{query.deviceName}, '%')
            </if>
            <if test="query.deviceId != null and query.deviceId != ''">
                and m.device_id like concat('%', #{query.deviceId}, '%')
            </if>
            <if test="query.enabled != null">
                and m.enabled = #{query.enabled}
            </if>
            <if test="query.onlineStatus != null and query.onlineStatus != ''">
                and m.online_status = #{query.onlineStatus}
            </if>
        </where>
        order by m.create_time desc, m.machine_id desc
    </select>
 
    <select id="selectVoById" parameterType="Long" resultMap="SysVisitorMachineVOResult">
        <include refid="selectMachineVo" />
        where m.machine_id = #{machineId}
          and m.del_flag = '0'
    </select>
 
    <select id="selectById" parameterType="Long" resultMap="SysVisitorMachineResult">
        <include refid="selectMachineDomain" />
        where machine_id = #{machineId}
          and del_flag = '0'
    </select>
 
    <select id="checkDeviceIdUnique" resultMap="SysVisitorMachineResult">
        <include refid="selectMachineDomain" />
        where device_id = #{deviceId}
          and del_flag = '0'
        <if test="excludeMachineId != null">
            and machine_id != #{excludeMachineId}
        </if>
        limit 1
    </select>
 
    <insert id="insertMachine" parameterType="SysVisitorMachine" useGeneratedKeys="true" keyProperty="machineId">
        insert into t_visitor_machine (
            area_id,
            device_name,
            brand,
            device_id,
            enabled,
            online_status,
            remark,
            create_by,
            create_time
        ) values (
            #{areaId},
            #{deviceName},
            #{brand},
            #{deviceId},
            #{enabled},
            #{onlineStatus},
            #{remark},
            #{createBy},
            sysdate()
        )
    </insert>
 
    <update id="updateMachine" parameterType="SysVisitorMachine">
        update t_visitor_machine
        <set>
            <if test="areaId != null and areaId != ''">
                area_id = #{areaId},
            </if>
            <if test="deviceName != null and deviceName != ''">
                device_name = #{deviceName},
            </if>
            <if test="brand != null and brand != ''">
                brand = #{brand},
            </if>
            <if test="deviceId != null and deviceId != ''">
                device_id = #{deviceId},
            </if>
            <if test="onlineStatus != null and onlineStatus != ''">
                online_status = #{onlineStatus},
            </if>
            <if test="enabled != null">
                enabled = #{enabled},    <!-- 注意:enabled 可能是 Boolean 或 Integer,若允许 false 或 0,则只判 null -->
            </if>
            <if test="onlineStatus != null and onlineStatus != ''">
                online_status = #{onlineStatus},
            </if>
            <if test="fingerprint != null and fingerprint != ''">
                fingerprint = #{fingerprint},
            </if>
            <if test="remark != null and remark != ''">
                remark = #{remark},
            </if>
            <!-- 以下两个字段始终更新,不加 if -->
            update_by = #{updateBy},
            update_time = sysdate()
        </set>
        where machine_id = #{machineId}
        and del_flag = '0'
    </update>
 
    <update id="updateEnabled">
        update t_visitor_machine
        set enabled = #{enabled},
            update_by = #{updateBy},
            update_time = sysdate()
        where del_flag = '0'
          and machine_id in
        <foreach collection="machineIds" item="machineId" open="(" separator="," close=")">
            #{machineId}
        </foreach>
    </update>
 
    <update id="updateOnlineStatus">
        update t_visitor_machine
        set online_status = #{onlineStatus},
            update_by = #{updateBy},
            update_time = sysdate()
        where del_flag = '0'
          and machine_id in
        <foreach collection="machineIds" item="machineId" open="(" separator="," close=")">
            #{machineId}
        </foreach>
    </update>
 
    <update id="deleteByIds">
        update t_visitor_machine
        set del_flag = '1',
            update_by = #{updateBy},
            update_time = sysdate()
        where del_flag = '0'
          and machine_id in
        <foreach collection="machineIds" item="machineId" open="(" separator="," close=")">
            #{machineId}
        </foreach>
    </update>
</mapper>