‘liusuyi’
2023-06-13 6b68dddf393b885698d48760c8e1972d574e30c4
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
<?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.stealAlarm.mapper.ArdAlarmStealelecMapper">
    <resultMap id="BaseResultMap" type="ArdAlarmStealelec">
        <id column="id" property="id"/>
        <result column="command" property="command"/>
        <result column="name" property="name"/>
        <result column="describe" property="describe"/>
        <result column="catalog_text" property="catalogText"/>
        <result column="description" property="description"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="view_time" property="viewTime"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
        <result column="user_id" property="userId"/>
        <result column="dept_id" property="deptId"/>
    </resultMap>
    <sql id="Base_Column_List">
        id
        ,command, name, describe, catalog_text, description, start_time, end_time,view_time,longitude,latitude,create_by,create_time,user_id,dept_id
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from ard_alarm_stealelec
        where id = #{id,jdbcType=VARCHAR}
    </select>
    <select id="selectHistoryByCondition" resultMap="BaseResultMap">
        select * from ard_alarm_stealelec aas left join ard_alarmpoints_well aa on aas.describe=aa.well_id
        <where>
            <if test="params.describe != null and params.describe != ''">
                and aas.describe like concat('%' , #{params.describe}::text, '%')
            </if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                and start_time &gt;= to_timestamp(#{params.beginTime},'yyyy-MM-DD')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                and start_time &lt;= to_timestamp(#{params.endTime},'yyyy-MM-DD')
            </if>
        </where>
    </select>
    <select id="selectAllByCommandArdAlarmStealelecList" resultMap="BaseResultMap">
        SELECT T.*
        FROM (
                 SELECT aas.ID,
                        aas.DESCRIBE,
                        aas.start_time,
                        aas.longitude,
                        aas.latitude,
                        aas.altitude,
                        ROW_NUMBER() OVER ( PARTITION BY aas.DESCRIBE ORDER BY aas.start_time DESC ) AS rn, COUNT(CASE WHEN aas.view_time IS NULL THEN 1 END) OVER ( PARTITION BY aas.DESCRIBE ) AS COUNT,
                    COUNT ( aas.start_time ) OVER ( PARTITION BY DESCRIBE ) AS total
                 FROM
                     ard_alarm_stealelec aas
                 WHERE
                     aas.start_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE )
             ) T
        WHERE T.rn = 1
    </select>
    <select id="selectRealByCondition" resultMap="BaseResultMap">
        SELECT aas.*, A.COUNT, A.total
        FROM (
                 SELECT MAX(C.ID)   AS ID,
                        COUNT(C.ID) AS total,
                        COUNT(CASE C.view_time WHEN NULL THEN C.DESCRIBE ELSE '0' END) AS count
                 FROM
                     (
                     SELECT aas0.* FROM ard_alarm_stealelec aas0
                     LEFT JOIN sys_dept d ON aas0.dept_id = d.dept_id
                     WHERE aas0.dept_id = #{deptId}
                     OR aas0.dept_id IN ( SELECT T.dept_id FROM sys_dept T WHERE CAST ( #{deptId} AS VARCHAR ) = ANY ( string_to_array( ancestors, ',' ) ) )
                     ) C
                 WHERE
                     C.start_time >= (now() - INTERVAL '%${refreshTime}%' MINUTE)
                   AND C.view_time is NULL
                 GROUP BY C.DESCRIBE
             ) A
                 LEFT JOIN ard_alarm_stealelec aas ON A.ID = aas.ID
        ORDER BY aas.start_time DESC LIMIT 50
    </select>
    <update id="updateViewTimeByDescribe" parameterType="String">
        update ard_alarm_stealelec
        set view_time=#{viewTime}
        where describe = #{describe}
          and start_time&lt;=#{alarmTime}
          and view_time is null
    </update>
    <insert id="insert" parameterType="ArdAlarmStealelec">
        insert into ard_alarm_stealelec(<include refid="Base_Column_List"/>)
        values (#{id},#{command}, #{name},#{describe},#{catalogText},#{description}, #{startTime}, #{endTime},
        #{viewTime},#{longitude},#{latitude},#{createBy},#{createTime},#{userId},#{deptId})
    </insert>
</mapper>