aijinhui
2023-10-07 2b29a4a26019e3d1692c4b4c76746dba9fac7b22
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
<?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.access.mapper.ArdAlarmAccessMapper">
    
    <resultMap type="ArdAlarmAccess" id="ArdAlarmAccessResult">
        <result property="id"    column="id"    />
        <result property="serialNo"    column="serial_no"    />
        <result property="acsId"    column="acs_id"    />
        <result property="acsName"    column="acs_name"    />
        <result property="defenseType"    column="defense_type"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="alarmTime"    column="alarm_time"    />
        <result property="doorNo"    column="door_no"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="altitude"    column="altitude"    />
        <result property="picUrl"    column="pic_url"    />
        <result property="recordUrl"    column="record_url"    />
        <result property="viewTime"    column="view_time"    />
        <result property="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>
 
    <sql id="selectArdAlarmAccessVo">
        select id, serial_no, acs_id, acs_name, defense_type, alarm_type, alarm_time, door_no, longitude, latitude, altitude, pic_url, record_url, view_time, dept_id, user_id, create_by, create_time from ard_alarm_access
    </sql>
 
    <select id="selectArdAlarmAccessList" parameterType="ArdAlarmAccess" resultMap="ArdAlarmAccessResult">
        <include refid="selectArdAlarmAccessVo"/>
        <where>
            <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>
        </where>
        order by alarm_time desc
    </select>
    
    <select id="selectArdAlarmAccessById" parameterType="String" resultMap="ArdAlarmAccessResult">
        <include refid="selectArdAlarmAccessVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertArdAlarmAccess" parameterType="ArdAlarmAccess">
        insert into ard_alarm_access
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="serialNo != null">serial_no,</if>
            <if test="acsId != null">acs_id,</if>
            <if test="acsName != null">acs_name,</if>
            <if test="defenseType != null">defense_type,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="alarmTime != null">alarm_time,</if>
            <if test="doorNo != null">door_no,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="altitude != null">altitude,</if>
            <if test="picUrl != null">pic_url,</if>
            <if test="recordUrl != null">record_url,</if>
            <if test="viewTime != null">view_time,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="serialNo != null">#{serialNo},</if>
            <if test="acsId != null">#{acsId},</if>
            <if test="acsName != null">#{acsName},</if>
            <if test="defenseType != null">#{defenseType},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="alarmTime != null">#{alarmTime},</if>
            <if test="doorNo != null">#{doorNo},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="altitude != null">#{altitude},</if>
            <if test="picUrl != null">#{picUrl},</if>
            <if test="recordUrl != null">#{recordUrl},</if>
            <if test="viewTime != null">#{viewTime},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>
 
    <update id="updateArdAlarmAccess" parameterType="ArdAlarmAccess">
        update ard_alarm_access
        <trim prefix="SET" suffixOverrides=",">
            <if test="serialNo != null">serial_no = #{serialNo},</if>
            <if test="acsId != null">acs_id = #{acsId},</if>
            <if test="acsName != null">acs_name = #{acsName},</if>
            <if test="defenseType != null">defense_type = #{defenseType},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if>
            <if test="alarmTime != null">alarm_time = #{alarmTime},</if>
            <if test="doorNo != null">door_no = #{doorNo},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="altitude != null">altitude = #{altitude},</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="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteArdAlarmAccessById" parameterType="String">
        delete from ard_alarm_access where id = #{id}
    </delete>
 
    <delete id="deleteArdAlarmAccessByIds" parameterType="String">
        delete from ard_alarm_access where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectCountByAlarmTime" resultType="Integer">
        SELECT COUNT(DISTINCT aaa.acs_id)
        FROM ard_alarm_access aaa
        WHERE aaa.alarm_time >= CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE
          and aaa.view_time is null
    </select>
    <select id="selectListAllByCommand" resultMap="ArdAlarmAccessResult">
        SELECT T.*
        FROM
            (
                SELECT
                    aaa.ID,
                    aaa.acs_id,
                    aaa.acs_name,
                    aaa.serial_no,
                    aaa.defense_type,
                    aaa.door_no,
                    aaa.alarm_type,
                    aaa.alarm_time,
                    aaa.longitude,
                    aaa.latitude,
                    aaa.altitude,
                    aaa.pic_url,
                    aaa.record_url,
                    ROW_NUMBER () OVER ( PARTITION BY aaa.acs_name ORDER BY aaa.alarm_time DESC ) AS rn,
                        COUNT ( CASE WHEN aaa.view_time IS NULL THEN 1 END ) OVER ( PARTITION BY aaa.acs_name ) AS COUNT,
        COUNT ( aaa.alarm_time ) OVER ( PARTITION BY aaa.acs_name ) AS total
                FROM
                    ard_alarm_access aaa
                WHERE
                    aaa.alarm_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE )
                ORDER BY
                    aaa.alarm_time DESC
            ) T
        WHERE
            T.rn = 1
    </select>
    <update id="updateViewTimeByAcsId" parameterType="String">
        update ard_alarm_access
        set view_time=#{viewTime}
        where acs_id = #{acsId}
          and alarm_time &lt;= #{alarmTime}
          and view_time is null
    </update>
 
    <select id="accessYear" resultType="com.ruoyi.statistical.vo.CountVo">
        select to_char(alarm_time::DATE, 'MM') as month,count(id)
        from ard_alarm_access
        where alarm_time &gt;= #{start} and  alarm_time &lt;= #{end}  group by month order by month
    </select>
</mapper>