‘liusuyi’
2023-06-25 1aad56563c6861e13f3a837eb7ef410723cc2358
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
<?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.alarm.cameraAlarm.mapper.ArdAlarmCameraMapper">
    
    <resultMap type="ArdAlarmCamera" id="ArdAlarmCameraResult">
        <result property="id"    column="id"    />
        <result property="cameraId"    column="camera_id"    />
        <result property="cameraName"    column="camera_name"    />
        <result property="cameraChannel"    column="camera_channel"    />
        <result property="cameraType"    column="camera_type"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="alarmTime"    column="alarm_time"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="ruleId"    column="rule_id"    />
        <result property="picUrl"    column="pic_url"    />
        <result property="recordUrl"    column="record_url"    />
        <result property="viewTime"    column="view_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="userId"    column="user_id"    />
        <result property="deptId"    column="dept_id"    />
    </resultMap>
 
    <sql id="selectArdAlarmCameraVo">
        select id, camera_id, camera_name, camera_channel, camera_type, alarm_type, alarm_time, longitude, latitude, rule_id, pic_url, record_url, view_time, create_by, create_time, user_id, dept_id from ard_alarm_camera
    </sql>
 
    <select id="selectArdAlarmCameraList" parameterType="ArdAlarmCamera" resultMap="ArdAlarmCameraResult">
        <include refid="selectArdAlarmCameraVo"/>
        <where>  
            <if test="cameraId != null  and cameraId != ''"> and camera_id = #{cameraId}</if>
            <if test="cameraName != null  and cameraName != ''"> and camera_name like '%'||#{cameraName}||'%'</if>
            <if test="cameraChannel != null "> and camera_channel = #{cameraChannel}</if>
            <if test="cameraType != null  and cameraType != ''"> and camera_type = #{cameraType}</if>
            <if test="alarmType != null  and alarmType != ''"> and alarm_type = #{alarmType}</if>
<!--            <if test="alarmTime != null "> and alarm_time = #{alarmTime}</if>-->
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND alarm_time &gt;= to_timestamp(#{params.beginTime},'yyyy-MM-DD HH24:MI:ss')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND alarm_time &lt;= to_timestamp(#{params.endTime},'yyyy-MM-DD HH24:MI:ss')
            </if>
            <if test="longitude != null "> and longitude = #{longitude}</if>
            <if test="latitude != null "> and latitude = #{latitude}</if>
            <if test="ruleId != null "> and rule_id = #{ruleId}</if>
            <if test="picUrl != null  and picUrl != ''"> and pic_url = #{picUrl}</if>
            <if test="recordUrl != null  and recordUrl != ''"> and record_url = #{recordUrl}</if>
            <if test="viewTime != null "> and view_time = #{viewTime}</if>
            <if test="userId != null  and userId != ''"> and user_id = #{userId}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
        </where>
        order by alarm_time desc
    </select>
    
    <select id="selectArdAlarmCameraById" parameterType="String" resultMap="ArdAlarmCameraResult">
        <include refid="selectArdAlarmCameraVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertArdAlarmCamera" parameterType="ArdAlarmCamera">
        insert into ard_alarm_camera
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="cameraId != null">camera_id,</if>
            <if test="cameraName != null">camera_name,</if>
            <if test="cameraChannel != null">camera_channel,</if>
            <if test="cameraType != null">camera_type,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="alarmTime != null">alarm_time,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="ruleId != null">rule_id,</if>
            <if test="picUrl != null">pic_url,</if>
            <if test="recordUrl != null">record_url,</if>
            <if test="viewTime != null">view_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="cameraId != null">#{cameraId},</if>
            <if test="cameraName != null">#{cameraName},</if>
            <if test="cameraChannel != null">#{cameraChannel},</if>
            <if test="cameraType != null">#{cameraType},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="alarmTime != null">#{alarmTime},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="ruleId != null">#{ruleId},</if>
            <if test="picUrl != null">#{picUrl},</if>
            <if test="recordUrl != null">#{recordUrl},</if>
            <if test="viewTime != null">#{viewTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>
 
    <update id="updateArdAlarmCamera" parameterType="ArdAlarmCamera">
        update ard_alarm_camera
        <trim prefix="SET" suffixOverrides=",">
            <if test="cameraId != null">camera_id = #{cameraId},</if>
            <if test="cameraName != null">camera_name = #{cameraName},</if>
            <if test="cameraChannel != null">camera_channel = #{cameraChannel},</if>
            <if test="cameraType != null">camera_type = #{cameraType},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if>
            <if test="alarmTime != null">alarm_time = #{alarmTime},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="ruleId != null">rule_id = #{ruleId},</if>
            <if test="picUrl != null">pic_url = #{picUrl},</if>
            <if test="recordUrl != null">record_url = #{recordUrl},</if>
            <if test="viewTime != null">view_time = #{viewTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteArdAlarmCameraById" parameterType="String">
        delete from ard_alarm_camera where id = #{id}
    </delete>
 
    <delete id="deleteArdAlarmCameraByIds" parameterType="String">
        delete from ard_alarm_camera where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectListAllByCommand" resultMap="ArdAlarmCameraResult">
        SELECT T
                   .*
        FROM
            (
                SELECT
                    aac.ID,
                    aac.camera_id,
                    aac.camera_name,
                    aac.alarm_time,
                    aac.longitude,
                    aac.latitude,
                    aac.record_url,
                    ROW_NUMBER () OVER ( PARTITION BY aac.camera_id ORDER BY aac.alarm_time DESC ) AS rn,
                        COUNT ( CASE WHEN aac.view_time IS NULL THEN 1 END ) OVER ( PARTITION BY aac.camera_id ) AS COUNT,
        COUNT ( aac.alarm_time ) OVER ( PARTITION BY camera_id ) AS total
                FROM
                    ard_alarm_camera aac
                WHERE
                    aac.alarm_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE )
                ORDER BY
                    aac.alarm_time DESC
            ) T
        WHERE
            T.rn = 1
    </select>
    <select id="selectCountByAlarmTime" resultType="Integer">
        SELECT COUNT(DISTINCT aac.camera_name)
        FROM ard_alarm_camera aac
        WHERE aac.alarm_time >= CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE
    </select>
</mapper>