aijinhui
2023-10-07 22311d8b024f0414cc60a2c408211fdfb9c2f1d3
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
<?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.wall.mapper.ArdAlarmWallMapper">
 
    <resultMap type="ArdAlarmWall" id="ArdAlarmWallResult">
        <result property="id" column="id"/>
        <result property="wallId" column="wall_id"/>
        <result property="wallName" column="wall_name"/>
        <result property="userId" column="user_id"/>
        <result property="alarmType" column="alarm_type"/>
        <result property="alarmTime" column="alarm_time"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="altitude" column="altitude"/>
        <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>
 
    <sql id="selectArdAlarmWallVo">
        select id,
               wall_id,
               wall_name,
               user_id,
               alarm_type,
               alarm_time,
               longitude,
               latitude,
               altitude,
               create_by,
               create_time,
               update_by,
               update_time
        from ard_alarm_wall
    </sql>
 
    <select id="selectArdAlarmWallList" parameterType="ArdAlarmWall" resultMap="ArdAlarmWallResult">
        <include refid="selectArdAlarmWallVo"/>
        <where>
            <if test="wallId != null  and wallId != ''">and wall_id = #{wallId}</if>
            <if test="wallName != null  and wallName != ''">and wall_name = #{wallName}</if>
            <if test="userId != null  and userId != ''">and user_id = #{userId}</if>
            <if test="alarmType != null  and alarmType != ''">and alarm_type = #{alarmType}</if>
<!--            <if test="alarmTime != null ">and alarm_time = #{alarmTime}</if>-->
            <if test="longitude != null ">and longitude = #{longitude}</if>
            <if test="latitude != null ">and latitude = #{latitude}</if>
            <if test="altitude != null ">and altitude = #{altitude}</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>
        </where>
        order by alarm_time desc
    </select>
 
    <select id="selectArdAlarmWallById" parameterType="String" resultMap="ArdAlarmWallResult">
        <include refid="selectArdAlarmWallVo"/>
        where id = #{id}
    </select>
 
    <insert id="insertArdAlarmWall" parameterType="ArdAlarmWall">
        insert into ard_alarm_wall
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="wallId != null">wall_id,</if>
            <if test="wallName != null">wall_name,</if>
            <if test="userId != null">user_id,</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="altitude != null">altitude,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="wallId != null">#{wallId},</if>
            <if test="wallName != null">#{wallName},</if>
            <if test="userId != null">#{userId},</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="altitude != null">#{altitude},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>
 
    <update id="updateArdAlarmWall" parameterType="ArdAlarmWall">
        update ard_alarm_wall
        <trim prefix="SET" suffixOverrides=",">
            <if test="wallId != null">wall_id = #{wallId},</if>
            <if test="wallName != null">wall_name = #{wallName},</if>
            <if test="userId != null">user_id = #{userId},</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="altitude != null">altitude = #{altitude},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteArdAlarmWallById" parameterType="String">
        delete
        from ard_alarm_wall
        where id = #{id}
    </delete>
 
    <delete id="deleteArdAlarmWallByIds" parameterType="String">
        delete from ard_alarm_wall where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectCountByAlarmTime" resultType="Integer">
        SELECT COUNT(DISTINCT aaw.wall_name)
        FROM ard_alarm_wall aaw
        WHERE aaw.alarm_time >= CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE
          and aaw.view_time is null
    </select>
    <select id="selectListAllByCommand" resultMap="ArdAlarmWallResult">
        SELECT T.*
        FROM (
                 SELECT aaa.ID,
                        aaa.user_id,
                        aaa.wall_NAME,
                        aaa.alarm_time,
                        aaa.longitude,
                        aaa.latitude,
                        aaa.altitude,
                        ROW_NUMBER() OVER ( PARTITION BY aaa.wall_NAME ORDER BY aaa.alarm_time DESC ) AS rn, COUNT(CASE WHEN aaa.view_time IS NULL THEN 1 END) OVER ( PARTITION BY aaa.wall_NAME ) AS COUNT,
                        COUNT ( aaa.alarm_time ) OVER ( PARTITION BY aaa.wall_NAME ) AS total
                 FROM
                     ard_alarm_wall aaa
                 WHERE
                     aaa.alarm_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE )
                 ORDER BY
                     aaa.create_time DESC
             ) T
        WHERE T.rn = 1
    </select>
    <update id="updateViewTimeByUserId" parameterType="String">
        update ard_alarm_wall
        set view_time=#{viewTime}
        where user_id = #{userId}
          and create_time &lt;= #{createTime}
          and view_time is null
    </update>
    <select id="wallYear" resultType="com.ruoyi.statistical.vo.CountVo">
        select to_char(alarm_time::DATE, 'MM') as date,count(id)
        from ard_alarm_wall
        where alarm_time &gt;= #{start} and  alarm_time &lt;= #{end}  group by date order by date
    </select>
    <select id="wallMonth" resultType="com.ruoyi.statistical.vo.CountVo">
        select to_char(alarm_time::DATE, 'dd') as date,count(id)
        from ard_alarm_wall
        where alarm_time &gt;= #{start} and  alarm_time &lt;= #{end}  group by date order by date
    </select>
</mapper>