liusuyi
2024-10-10 38f29e38fcc668171dc05c53d40a36b895c86102
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
<?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.digitization3.mapper.ArdAlarmDigitization3Mapper">
    
    <resultMap type="ArdAlarmDigitization3" id="ArdAlarmDigitization3Result">
        <result property="id"    column="id"    />
        <result property="xmmc"    column="xmmc"    />
        <result property="fKey"    column="f_key"    />
        <result property="fName"    column="f_name"    />
        <result property="wellNo"    column="well_no"    />
        <result property="alarmTime"    column="alarm_time"    />
        <result property="alarmType"    column="alarm_type"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="altitude"    column="altitude"    />
        <result property="createTime"    column="create_time"    />
        <result property="viewTime"    column="view_time"    />
    </resultMap>
 
    <sql id="selectArdAlarmDigitization3Vo">
        select id, xmmc, f_key, f_name, well_no, alarm_time, alarm_type, longitude, latitude, altitude, create_time, view_time from ard_alarm_digitization3
    </sql>
 
    <select id="selectArdAlarmDigitization3List" parameterType="ArdAlarmDigitization3" resultMap="ArdAlarmDigitization3Result">
        <include refid="selectArdAlarmDigitization3Vo"/>
        <where>  
            <if test="xmmc != null  and xmmc != ''"> and xmmc = #{xmmc}</if>
            <if test="fKey != null  and fKey != ''"> and f_key = #{fKey}</if>
            <if test="fName != null  and fName != ''"> and f_name like '%'||#{fName}||'%'</if>
            <if test="wellNo != null  and wellNo != ''"> and well_no = #{wellNo}</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="alarmType != null  and alarmType != ''"> and alarm_type = #{alarmType}</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="viewTime != null "> and view_time = #{viewTime}</if>
        </where>
    </select>
    
    <select id="selectArdAlarmDigitization3ById" parameterType="String" resultMap="ArdAlarmDigitization3Result">
        <include refid="selectArdAlarmDigitization3Vo"/>
        where id = #{id}
    </select>
        
    <insert id="insertArdAlarmDigitization3" parameterType="ArdAlarmDigitization3">
        insert into ard_alarm_digitization3
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="xmmc != null">xmmc,</if>
            <if test="fKey != null">f_key,</if>
            <if test="fName != null">f_name,</if>
            <if test="wellNo != null">well_no,</if>
            <if test="alarmTime != null">alarm_time,</if>
            <if test="alarmType != null">alarm_type,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="altitude != null">altitude,</if>
            <if test="createTime != null">create_time,</if>
            <if test="viewTime != null">view_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="xmmc != null">#{xmmc},</if>
            <if test="fKey != null">#{fKey},</if>
            <if test="fName != null">#{fName},</if>
            <if test="wellNo != null">#{wellNo},</if>
            <if test="alarmTime != null">#{alarmTime},</if>
            <if test="alarmType != null">#{alarmType},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="altitude != null">#{altitude},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="viewTime != null">#{viewTime},</if>
         </trim>
        ON conflict(id)  DO NOTHING;
    </insert>
 
    <update id="updateArdAlarmDigitization3" parameterType="ArdAlarmDigitization3">
        update ard_alarm_digitization3
        <trim prefix="SET" suffixOverrides=",">
            <if test="xmmc != null">xmmc = #{xmmc},</if>
            <if test="fKey != null">f_key = #{fKey},</if>
            <if test="fName != null">f_name = #{fName},</if>
            <if test="wellNo != null">well_no = #{wellNo},</if>
            <if test="alarmTime != null">alarm_time = #{alarmTime},</if>
            <if test="alarmType != null">alarm_type = #{alarmType},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="altitude != null">altitude = #{altitude},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="viewTime != null">view_time = #{viewTime},</if>
        </trim>
        where id = #{id}
    </update>
 
    <delete id="deleteArdAlarmDigitization3ById" parameterType="String">
        delete from ard_alarm_digitization3 where id = #{id}
    </delete>
 
    <delete id="deleteArdAlarmDigitization3ByIds" parameterType="String">
        delete from ard_alarm_digitization3 where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="selectListAllByCommand" resultMap="ArdAlarmDigitization3Result">
        SELECT T
                   .*
        FROM
            (
                SELECT
                    aad.ID,
                    aad.well_no,
                    aad.alarm_type,
                    aad.alarm_time,
                    aad.longitude,
                    aad.latitude,
                    aad.altitude,
                    ROW_NUMBER () OVER ( PARTITION BY aad.well_no ORDER BY aad.alarm_time DESC ) AS rn,
                        COUNT ( CASE WHEN aad.view_time IS NULL THEN 1 END ) OVER ( PARTITION BY aad.well_no ) AS COUNT,
        COUNT ( aad.alarm_time ) OVER ( PARTITION BY aad.well_no ) AS total
                FROM
                    ard_alarm_digitization3 aad
                WHERE
                    aad.alarm_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE )
                ORDER BY
                    aad.alarm_time DESC
            ) T
        WHERE
            T.rn = 1
    </select>
    <select id="selectCountByAlarmTime" resultType="Integer">
        SELECT COUNT(DISTINCT aat.id)
        FROM ard_alarm_digitization3 aat
        WHERE aat.alarm_time >= CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE
          and aat.view_time is null
    </select>
    <update id="updateViewTimeByWellNo" parameterType="String">
        update ard_alarm_digitization3
        set view_time=#{viewTime}
        where well_no = #{wellNo}
          and alarm_time &lt;= #{alarmTime}
          and view_time is null
    </update>
    <select id="digitizationYear" resultType="com.ruoyi.statistical.vo.CountVo">
        select to_char(alarm_time::DATE, 'MM') as date,count(id)
        from ard_alarm_digitization3
        where alarm_time &gt;= #{start} and  alarm_time &lt;= #{end}  group by date order by date
    </select>
    <select id="digitizationMonth" resultType="com.ruoyi.statistical.vo.CountVo">
        select to_char(alarm_time::DATE, 'dd') as date,count(id)
        from ard_alarm_digitization3
        where alarm_time &gt;= #{start} and  alarm_time &lt;= #{end}  group by date order by date
    </select>
</mapper>