“mitao”
2026-02-04 458334ecf2bf8aa76ac6d07226ed29878c56b070
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
<?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.DeviceUsageMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ruoyi.system.model.DeviceUsage">
        <id column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="deleted" property="deleted"/>
        <result column="name" property="name"/>
        <result column="update_time" property="updateTime"/>
        <result column="properties" property="properties"/>
        <result column="creator_id" property="creatorId"/>
        <result column="device_id" property="deviceId"/>
        <result column="project_id" property="projectId"/>
        <result column="disabled" property="disabled"/>
    </resultMap>
    <select id="getDeviceUsageList" resultType="java.lang.String">
        select t2.properties from device_usage t1
        left join device t2 on t1.device_id = t2.id
        where t1.project_id =#{id}
    </select>
    <select id="getDeviceList" resultType="com.ruoyi.system.vo.DeviceListVo">
 
        select t1.id, t1.name, t1.create_time, t1.properties, t1.type, latest.record_time as checkTime
        from device t1
        left join device_usage t2 on t1.id = t2.device_id
        left join (
        select device_id, max(create_time) as record_time
        from record
        group by device_id
        ) latest on t1.id = latest.device_id
        where t2.project_id = #{query.projectId} and t2.deleted = 0
        <if test="query.type != null">
            and t1.type = #{query.type}
        </if>
        <if test="query.content!= null and query.content!=''">
            and t1.name like CONCAT('%', #{query.content}, '%')
        </if>
        <if test="query.startTime != null and query.startTime != ''">
            and latest.record_time >= #{query.startTime}
        </if>
        <if test="query.endTime != null and query.endTime != ''">
            and #{query.endTime} >=latest.record_time
        </if>
        order by latest.record_time desc
    </select>
    <select id="deviceList" resultType="com.ruoyi.system.vo.EntrustDeviceListVo">
        select t2.id, t2.name, t2.create_time, t2.properties, t2.type, latest.record_time as checkTime,t3.name as projectName,
        t3.id as projectId
        from device_usage t1
        left join device t2 on t2.id = t1.device_id
        left join (
        select device_id, max(create_time) as record_time
        from record
        where device_id is not null and deleted = 0 and record_type ='error'
        group by device_id
        ) latest on t2.id = latest.device_id
        left join project t3 on t1.project_id = t3.id
        where  t1.deleted = 0
        <if test="query.projectId != null">
            and t1.project_id = #{query.projectId}
        </if>
        <if test="query.projectIds != null">
            and t1.project_id in
            <foreach item="item" index="index" collection="query.projectIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="query.type != null">
            and t2.type = #{query.type}
        </if>
        <if test="query.content!= null and query.content!=''">
            and t2.name like CONCAT('%', #{query.content}, '%')
        </if>
 
        order by latest.record_time desc
    </select>
    <select id="projectList" resultType="com.ruoyi.system.vo.EntrustProjectVo">
        select
        t1.*,result.risk_level
        from project t1
 
        left join (
        select score,project_id,risk_level
        from eval_result
        group by project_id
        order by create_time desc
        ) result on t1.id = result.project_id
        where t1.deleted = 0
 
        <if test="query.clientId != null">
            and t1.client_id = #{query.clientId}
        </if>
        <if test="query.projectIds != null">
            and t1.id in
            <foreach item="item" index="index" collection="query.projectIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="query.projectId != null">
            and t1.id = #{query.projectId}
        </if>
        <if test="query.type != null">
            and t1.type = #{query.type}
        </if>
        <if test="query.riskLevel != null">
            and `result`.risk_level = #{query.riskLevel}
        </if>
        <if test="query.name!= null and query.name!=''">
            and t1.name like CONCAT('%', #{query.name}, '%')
        </if>
        GROUP BY t1.id
        order by t1.create_time desc
    </select>
    <select id="projectReport" resultType="com.ruoyi.system.vo.EntrustProjectReportVo">
        select t1.name,t1.type,t2.score,t2.risk_level,t3.time as checkTime
        from plan t1
        left join eval_result t2 on t1.id = t2.plan_id and t2.project_id = #{query.projectId}
        left join check t3 on t1.id = t3.plan_id and t3.project_id = #{query.projectId}
        where t1.deleted = 0 and t2.deleted = 0 and t2.deleted = 0
 
    </select>
    <select id="errorList" resultType="com.ruoyi.system.vo.ErrorListVo">
        select t1.*,t2.project_id,t2.plan_id,t3.`name` as  projectName,t4.`name` as planName
             ,t5.`name` as problemName,IF(t1.device_id is null ,1,2) as type,t1.create_time as checkTime
        ,IF(t6.state  is null,0,t6.state) as state
        from record t1
                 LEFT JOIN task t2 on t1.check_task_id = t2.id
                 LEFT JOIN project t3 on t2.project_id = t3.id
                 LEFT JOIN plan t4 on t2.plan_id = t4.id
                 LEFT JOIN problem t5 ON t1.problem_id = t5.id
        left join error_review t6 on t1.error_review_id = t6.id
        where t1.deleted = 0 and t2.deleted = 0  and t1.`level` =0
          <if test="query.recordIds != null">
            and t1.id in
            <foreach item="item" index="index" collection="query.recordIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
 
        <if test="query.projectId != null">
            and t2.project_id = #{query.projectId}
        </if>
        <if test="query.state ==0 ">
            and t6.state is null
        </if>
        <if test="query.state ==1 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.state ==2 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.state ==3 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.type != null and query.type == 1">
            and t1.device_id is null
        </if>
        <if test="query.type != null and query.type == 2">
            and t1.device_id is not null
        </if>
 
        <if test="query.content!= null and query.content!=''">
            and (t3.name like CONCAT('%', #{query.content}, '%')
                or
            t5.name like CONCAT('%', #{query.content}, '%')
                or
            t1.remark like CONCAT('%', #{query.content}, '%')
                )
        </if>
        order by t1.create_time desc
    </select>
    <select id="deviceErrorList" resultType="com.ruoyi.system.vo.ErrorListVo">
        select t1.*,t2.project_id,t2.plan_id,t3.`name` as  projectName,t4.`name` as planName
        ,t5.`name` as problemName,IF(t1.device_id is null ,1,2) as type,t1.create_time as checkTime
        ,IF(t6.state  is null,0,t6.state) as state
        from record t1
        LEFT JOIN task t2 on t1.check_task_id = t2.id
        LEFT JOIN project t3 on t2.project_id = t3.id
        LEFT JOIN plan t4 on t2.plan_id = t4.id
        LEFT JOIN problem t5 ON t1.problem_id = t5.id
        left join error_review t6 on t1.error_review_id = t6.id
 
        where t1.deleted = 0 and t2.deleted = 0  and t1.device_id is not null
        <if test="query.recordIds != null">
            and t1.id in
            <foreach item="item" index="index" collection="query.recordIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="query.projectId != null">
            and t2.project_id = #{query.projectId}
        </if>
        <if test="query.state ==0 ">
            and t6.state is null
        </if>
        <if test="query.state ==1 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.state ==2 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.state ==3 ">
            and t6.state = #{query.state}
        </if>
 
        <if test="query.content!= null and query.content!=''">
            and (t3.name like CONCAT('%', #{query.content}, '%')
            or
            t5.name like CONCAT('%', #{query.content}, '%')
            or
            t1.remark like CONCAT('%', #{query.content}, '%')
            )
        </if>
        order by t1.create_time desc
    </select>
    <select id="safetyErrorList" resultType="com.ruoyi.system.vo.ErrorListVo">
        select t1.*,t2.project_id,t2.plan_id,t3.`name` as  projectName,t4.`name` as planName
        ,t5.`name` as problemName,IF(t1.device_id is null ,1,2) as type,t1.create_time as checkTime
        ,IF(t6.state  is null,0,t6.state) as state
        from record t1
        LEFT JOIN task t2 on t1.check_task_id = t2.id
        LEFT JOIN project t3 on t2.project_id = t3.id
        LEFT JOIN plan t4 on t2.plan_id = t4.id
        LEFT JOIN problem t5 ON t1.problem_id = t5.id
        left join error_review t6 on t1.error_review_id = t6.id
 
        where t1.deleted = 0   and t1.device_id is null
        <if test="query.recordIds != null">
            and t1.id in
            <foreach item="item" index="index" collection="query.recordIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="query.projectId != null">
            and t2.project_id = #{query.projectId}
        </if>
        <if test="query.state ==0 ">
            and t6.state is null
        </if>
        <if test="query.state ==1 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.state ==2 ">
            and t6.state = #{query.state}
        </if>
        <if test="query.state ==3 ">
            and t6.state = #{query.state}
        </if>
 
        <if test="query.content!= null and query.content!=''">
            and (t3.name like CONCAT('%', #{query.content}, '%')
            or
            t5.name like CONCAT('%', #{query.content}, '%')
            or
            t1.remark like CONCAT('%', #{query.content}, '%')
            )
        </if>
        order by t1.create_time desc
    </select>
 
    <select id="getProjectDeviceCount" resultType="com.ruoyi.system.vo.DeviceCountVo"
            parameterType="java.lang.Integer">
 
        select t1.type, count(t1.id) as count
        from device t1
            left join device_usage t2
        on t1.id = t2.device_id
        where t2.project_id = #{id} and t2.deleted = 0
        group by t1.type
    </select>
 
</mapper>