fuliqi
2024-09-25 8244adbb31a684de274a7b11a2e5293eb6dea46d
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
<?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.ycl.platform.mapper.YwPointMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ycl.platform.domain.vo.YwPointVO">
        <result column="id" property="id"/>
        <result column="point_name" property="pointName"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="unit_id" property="unitId"/>
        <result column="unit_name" property="unitName"/>
        <result column="status" property="status"/>
        <result column="dept_id" property="deptId"/>
        <result column="dept_name" property="deptName"/>
        <result column="remark" property="remark"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="province_tag" property="provinceTag"/>
        <result column="important_tag" property="importantTag"/>
        <result column="important_command_image_tag" property="importantCommandImageTag"/>
        <result column="dept_tag" property="deptTag"/>
    </resultMap>
 
    <select id="selectData" resultType="com.ycl.platform.base.BaseSelect">
 
    </select>
 
    <select id="page" resultMap="BaseResultMap">
        SELECT
        typ.id,
        typ.point_name,
        typ.start_time,
        typ.end_time,
        typ.unit_id,
        tyu.unit_name,
        typ.status,
        typ.dept_id,
        sd.dept_name,
        typ.remark,
        typ.create_time,
        typ.update_time,
        typ.important_tag,
        typ.province_tag,
        typ.important_command_image_tag,
        typ.dept_tag
        FROM
        t_yw_point typ
        LEFT JOIN t_yw_unit tyu ON typ.unit_id = tyu.id AND tyu.deleted = 0
        LEFT JOIN sys_dept sd ON typ.dept_id = sd.dept_id AND sd.del_flag = 0
        <where>
            <if test="query.pointName != null and query.pointName != ''">
                AND typ.point_name like concat('%', #{query.pointName}, '%')
            </if>
        </where>
    </select>
 
    <select id="dataCenterPage" resultType="com.ycl.platform.domain.vo.PointDetailVO">
        SELECT
               m.*
        FROM
             t_yw_point p INNER JOIN t_monitor m ON p.serial_number = m.serial_number
        <where>
            <if test="query.keyword != null and query.keyword != ''">
                AND (m.name like concat('%', #{query.keyword}, '%') OR m.serial_number like concat('%', #{query.keyword}, '%'))
            </if>
            <if test="query.dataType == 1">
                AND p.province_tag = 1
            </if>
            <if test="query.dataType == 2">
                AND p.dept_tag = 1
            </if>
            <choose>
                <when test="query.deptTag == 1">
                    AND p.dept_tag = 1
                </when>
                <when test="query.deptTag == 2">
                    AND p.province_tag = 1
                </when>
                <when test="query.deptTag == 3">
                    AND p.important_tag = 1
                </when>
                <when test="query.deptTag == 4">
                    AND p.important_command_image_tag = 1
                </when>
                <when test="query.deptTag == 5">
                    AND p.new_device = 1
                </when>
            </choose>
            <choose>
                <when test="query.deviceType == 1">
                    AND m.camera_fun_type like '%1%'
                </when>
                <when test="query.deviceType == 2">
                    AND m.camera_fun_type like '%2%'
                </when>
                <when test="query.deviceType == 3">
                    AND m.camera_fun_type like '%3%'
                </when>
            </choose>
        </where>
    </select>
 
    <select id="distinctCount" resultType="integer">
        SELECT
            count(DISTINCT m.serial_number)
        FROM
            t_yw_point p INNER JOIN t_monitor m ON p.serial_number = m.serial_number
        <where>
            <if test="query.dataType == 1">
                AND p.province_tag = 1
            </if>
            <choose>
                <when test="query.deptTag == 1">
                    AND dept_tag = 1
                </when>
                <when test="query.deptTag == 2">
                    AND province_tag = 1
                </when>
                <when test="query.deptTag == 3">
                    AND important_tag = 1
                </when>
                <when test="query.deptTag == 4">
                    AND important_command_image_tag = 1
                </when>
                <when test="query.deptTag == 5">
                    AND new_device = 1
                </when>
            </choose>
            <choose>
                <when test="query.deviceType == 1">
                    AND m.camera_fun_type like '%1%'
                </when>
                <when test="query.deviceType == 2">
                    AND m.camera_fun_type like '%2%'
                </when>
                <when test="query.deviceType == 3">
                    AND m.camera_fun_type like '%3%'
                </when>
            </choose>
        </where>
    </select>
 
    <select id="home" resultType="com.ycl.platform.domain.entity.YwPoint">
        <![CDATA[
        SELECT t_yw_point.id, point_name, start_time, end_time, status, unit_name AS remark
        FROM t_yw_point
                 LEFT JOIN t_yw_unit ON t_yw_unit.id = t_yw_point.unit_id AND t_yw_point.deleted = 0
        WHERE t_yw_point.deleted = 0
          AND TIMESTAMPDIFF(MONTH, NOW(), end_time) <= (SELECT config_value
                                                        FROM sys_config
                                                        WHERE config_key = 'operation.and.maintenance.expiration.warning.time')
        ORDER BY end_time
        ]]>
    </select>
 
    <select id="selectByTag" resultType="com.ycl.platform.domain.entity.YwPoint">
        select * from t_yw_point
        <where>
            <if test="important!=null and important == true ">
                and important_tag = #{important}
            </if>
            <if test="province!=null and province == true ">
                and province_tag = #{province}
            </if>
            <if test="commandImage!=null and commandImage == true ">
                and important_command_image_tag = #{commandImage}
            </if>
            <if test="deptTag !=null and deptTag == true ">
                and dept_tag = #{deptTag}
            </if>
        </where>
    </select>
 
    <select id="export" resultType="com.ycl.platform.domain.excel.PointExport">
        SELECT
        m.name as pointName,
        m.serial_number,
        m.ip as pointIp,
        yu.unit_name,
        yp.start_time,
        yp.end_time,
        CASE WHEN yp.province_tag = 0 THEN '否' ELSE '是' END AS provinceTagString,
        CASE WHEN yp.important_tag = 0 THEN '否' ELSE '是' END AS importantTagString,
        CASE WHEN yp.important_command_image_tag = 0 THEN '否' ELSE '是' END AS importantCommandImageTagString,
        CASE WHEN yp.dept_tag = 0 THEN '否' ELSE '是' END AS deptTag
        FROM
        t_yw_point yp
        INNER JOIN t_monitor m ON yp.serial_number = m.serial_number
        LEFT JOIN t_yw_unit yu ON yu.id = yp.unit_id
        <where>
            <if test="query.pointName != null and query.pointName != ''">
                AND m.name like concat('%', #{query.pointName} ,'%')
            </if>
        </where>
        ORDER BY yu.unit_name
    </select>
 
    <delete id="deleteAll">
        delete from t_yw_point
    </delete>
 
    <update id="updatePoint">
        <foreach collection="pointList" separator=";" item="point">
            UPDATE t_yw_point
            SET
            <if test="point.pointName != null and point.pointName != ''">
                point_name = #{point.pointName},
            </if>
            <if test="point.unitId != null">
                unit_id = #{point.unitId},
            </if>
            <if test="point.startTime != null">
                start_time = #{point.startTime},
            </if>
            <if test="point.endTime != null">
                end_time = #{point.endTime},
            </if>
            province_tag = #{point.provinceTag},
            important_command_image_tag = #{point.importantCommandImageTag},
            dept_tag = #{point.deptTag}
            WHERE serial_number = #{point.serialNumber}
        </foreach>
    </update>
 
    <select id="countNotFinishedWorkOrderByPointId" resultType="com.ycl.platform.domain.vo.YwPointVO">
        SELECT
            yp.id, yp.point_name, wo.serial_number
        FROM
             t_yw_point yp
                 INNER JOIN t_work_order wo ON yp.serial_number = wo.serial_number
                                                   AND wo.status not in ('AUDITING_SUCCESS','WAIT_DISTRIBUTE')
                                                   AND wo.deleted = 0
                                                   AND yp.deleted = 0
        WHERE
            yp.id = #{pointId}
    </select>
 
    <select id="countNotFinishedWorkOrderByGb" resultType="com.ycl.platform.domain.vo.YwPointVO">
        SELECT
            yp.id, yp.point_name, wo.serial_number
        FROM
            t_yw_point yp
                INNER JOIN t_work_order wo ON yp.serial_number = wo.serial_number
                AND wo.status not in ('AUDITING_SUCCESS','WAIT_DISTRIBUTE')
                AND wo.deleted = 0
                AND yp.deleted = 0
                AND yp.serial_number = #{serialNumber}
        LIMIT 1
    </select>
 
    <select id="getDeptPointGB" resultType="string">
        SELECT
            DISTINCT serial_number
        FROM
             t_yw_point
        WHERE
            <if test="tagType == 0">
                dept_tag = 1
            </if>
            <if test="tagType == 1">
                important_tag = 1
            </if>
            <if test="tagType == 2">
                important_command_image_tag = 1
            </if>
             AND deleted = 0
    </select>
 
    <select id="select" resultType="com.ycl.platform.domain.entity.YwPoint">
        SELECT
               *
        FROM
             t_yw_point
        <where>
            <if test="keyword != null and keyword != ''">
                AND (serial_number like concat('%', #{keyword}, '%') or point_name like concat('%', #{keyword}, '%'))
            </if>
            <if test="unitId != null">
                AND unit_id = #{unitId}
            </if>
            AND deleted = 0
        </where>
 
    </select>
 
    <select id="getReportResult" resultType="com.ycl.platform.domain.vo.ReportAuditingRecordVO">
        SELECT
               ar.result, r.begin_create_time, r.end_create_time
        FROM
             t_report r
                 INNER JOIN t_report_auditing_record ar ON r.id = ar.report_id
                                                               AND ar.deleted = 0
                                                               AND r.report_type = #{reportType}
                                                               AND r.deleted = 0
                                                               AND r.serial_number = #{serialNumber}
                                                                AND ar.result = 1
        ORDER BY
             ar.create_time DESC
        limit 1
    </select>
 
    <select id="getTagsByGB" resultType="com.ycl.platform.domain.vo.CheckTagVO">
        SELECT
               serial_number as no, province_tag, important_tag, important_command_image_tag, dept_tag
        FROM
            t_yw_point
        WHERE
            deleted = 0 AND serial_number in <foreach collection="gbList" open="(" separator="," close=")" item="no">#{no}</foreach>
        GROUP BY
            serial_number, province_tag, important_tag, important_command_image_tag, dept_tag
    </select>
 
 
</mapper>