<?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.tube.mapper.ArdAlarmTubeMapper"> 
 | 
  
 | 
    <resultMap type="ArdAlarmTube" id="ArdAlarmTubeResult"> 
 | 
        <result property="id" column="id"/> 
 | 
        <result property="host" column="host"/> 
 | 
        <result property="tubeId" column="tube_id"/> 
 | 
        <result property="tubeName" column="tube_name"/> 
 | 
        <result property="tubeType" column="tube_type"/> 
 | 
        <result property="pipeDiameter" column="pipe_diameter"/> 
 | 
        <result property="color" column="color"/> 
 | 
        <result property="position" column="position"/> 
 | 
        <result property="type" column="type"/> 
 | 
        <result property="alarmType" column="alarm_type"/> 
 | 
        <result property="alarmTime" column="alarm_time"/> 
 | 
        <result property="watcher" column="watcher"/> 
 | 
        <result property="createTime" column="create_time"/> 
 | 
        <result property="longitude" column="longitude"/> 
 | 
        <result property="latitude" column="latitude"/> 
 | 
        <result property="altitude" column="altitude"/> 
 | 
        <result property="recordUrl" column="record_url"/> 
 | 
        <result property="viewTime" column="view_time"/> 
 | 
    </resultMap> 
 | 
  
 | 
    <sql id="selectArdAlarmTubeVo"> 
 | 
        select id, 
 | 
               host, 
 | 
               tube_id, 
 | 
               tube_name, 
 | 
               tube_type, 
 | 
               pipe_diameter, 
 | 
               color, 
 | 
               position, 
 | 
               type, 
 | 
               alarm_type, 
 | 
               alarm_time, 
 | 
               watcher, 
 | 
               create_time, 
 | 
               longitude, 
 | 
               latitude, 
 | 
               altitude, 
 | 
               record_url, 
 | 
               view_time 
 | 
        from ard_alarm_tube 
 | 
    </sql> 
 | 
  
 | 
    <select id="selectArdAlarmTubeList" parameterType="ArdAlarmTube" resultMap="ArdAlarmTubeResult"> 
 | 
        <include refid="selectArdAlarmTubeVo"/> 
 | 
        <where> 
 | 
            <if test="host != null  and host != ''">and host = #{host}</if> 
 | 
            <if test="tubeId != null  and tubeId != ''">and tube_id = #{tubeId}</if> 
 | 
            <if test="tubeName != null  and tubeName != ''">and tube_name like '%'||#{tubeName}||'%'</if> 
 | 
            <if test="tubeType != null  and tubeType != ''">and tube_type = #{tubeType}</if> 
 | 
            <if test="pipeDiameter != null  and pipeDiameter != ''">and pipe_diameter = #{pipeDiameter}</if> 
 | 
            <if test="color != null  and color != ''">and color = #{color}</if> 
 | 
            <if test="position != null  and position != ''">and position = #{position}</if> 
 | 
            <if test="type != null  and type != ''">and type = #{type}</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 >= to_timestamp(#{params.beginTime},'yyyy-MM-DD HH24:MI:ss') 
 | 
            </if> 
 | 
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> 
 | 
                AND alarm_time <= to_timestamp(#{params.endTime},'yyyy-MM-DD HH24:MI:ss') 
 | 
            </if> 
 | 
            <if test="watcher != null  and watcher != ''">and watcher = #{watcher}</if> 
 | 
            <if test="longitude != null  and longitude != ''">and longitude = #{longitude}</if> 
 | 
            <if test="latitude != null  and latitude != ''">and latitude = #{latitude}</if> 
 | 
            <if test="altitude != null  and altitude != ''">and altitude = #{altitude}</if> 
 | 
            <if test="recordUrl != null  and recordUrl != ''">and record_url = #{recordUrl}</if> 
 | 
            <if test="viewTime != null ">and view_time = #{viewTime}</if> 
 | 
        </where> 
 | 
        order by alarm_time desc 
 | 
    </select> 
 | 
  
 | 
    <select id="selectArdAlarmTubeById" parameterType="String" resultMap="ArdAlarmTubeResult"> 
 | 
        <include refid="selectArdAlarmTubeVo"/> 
 | 
        where id = #{id} 
 | 
    </select> 
 | 
  
 | 
    <insert id="insertArdAlarmTube" parameterType="ArdAlarmTube"> 
 | 
        insert into ard_alarm_tube 
 | 
        <trim prefix="(" suffix=")" suffixOverrides=","> 
 | 
            <if test="id != null">id,</if> 
 | 
            <if test="host != null">host,</if> 
 | 
            <if test="tubeId != null">tube_id,</if> 
 | 
            <if test="tubeName != null">tube_name,</if> 
 | 
            <if test="tubeType != null">tube_type,</if> 
 | 
            <if test="pipeDiameter != null">pipe_diameter,</if> 
 | 
            <if test="color != null">color,</if> 
 | 
            <if test="position != null">position,</if> 
 | 
            <if test="type != null">type,</if> 
 | 
            <if test="alarmType != null">alarm_type,</if> 
 | 
            <if test="alarmTime != null">alarm_time,</if> 
 | 
            <if test="watcher != null">watcher,</if> 
 | 
            <if test="createTime != null">create_time,</if> 
 | 
            <if test="longitude != null">longitude,</if> 
 | 
            <if test="latitude != null">latitude,</if> 
 | 
            <if test="altitude != null">altitude,</if> 
 | 
            <if test="recordUrl != null">record_url,</if> 
 | 
            <if test="viewTime != null">view_time,</if> 
 | 
        </trim> 
 | 
        <trim prefix="values (" suffix=")" suffixOverrides=","> 
 | 
            <if test="id != null">#{id},</if> 
 | 
            <if test="host != null">#{host},</if> 
 | 
            <if test="tubeId != null">#{tubeId},</if> 
 | 
            <if test="tubeName != null">#{tubeName},</if> 
 | 
            <if test="tubeType != null">#{tubeType},</if> 
 | 
            <if test="pipeDiameter != null">#{pipeDiameter},</if> 
 | 
            <if test="color != null">#{color},</if> 
 | 
            <if test="position != null">#{position},</if> 
 | 
            <if test="type != null">#{type},</if> 
 | 
            <if test="alarmType != null">#{alarmType},</if> 
 | 
            <if test="alarmTime != null">#{alarmTime},</if> 
 | 
            <if test="watcher != null">#{watcher},</if> 
 | 
            <if test="createTime != null">#{createTime},</if> 
 | 
            <if test="longitude != null">#{longitude},</if> 
 | 
            <if test="latitude != null">#{latitude},</if> 
 | 
            <if test="altitude != null">#{altitude},</if> 
 | 
            <if test="recordUrl != null">#{recordUrl},</if> 
 | 
            <if test="viewTime != null">#{viewTime},</if> 
 | 
        </trim> 
 | 
    </insert> 
 | 
  
 | 
    <update id="updateArdAlarmTube" parameterType="ArdAlarmTube"> 
 | 
        update ard_alarm_tube 
 | 
        <trim prefix="SET" suffixOverrides=","> 
 | 
            <if test="host != null">host = #{host},</if> 
 | 
            <if test="tubeId != null">tube_id = #{tubeId},</if> 
 | 
            <if test="tubeName != null">tube_name = #{tubeName},</if> 
 | 
            <if test="tubeType != null">tube_type = #{tubeType},</if> 
 | 
            <if test="pipeDiameter != null">pipe_diameter = #{pipeDiameter},</if> 
 | 
            <if test="color != null">color = #{color},</if> 
 | 
            <if test="position != null">position = #{position},</if> 
 | 
            <if test="type != null">type = #{type},</if> 
 | 
            <if test="alarmType != null">alarm_type = #{alarmType},</if> 
 | 
            <if test="alarmTime != null">alarm_time = #{alarmTime},</if> 
 | 
            <if test="watcher != null">watcher = #{watcher},</if> 
 | 
            <if test="createTime != null">create_time = #{createTime},</if> 
 | 
            <if test="longitude != null">longitude = #{longitude},</if> 
 | 
            <if test="latitude != null">latitude = #{latitude},</if> 
 | 
            <if test="altitude != null">altitude = #{altitude},</if> 
 | 
            <if test="recordUrl != null">record_url = #{recordUrl},</if> 
 | 
            <if test="viewTime != null">view_time = #{viewTime},</if> 
 | 
        </trim> 
 | 
        where id = #{id} 
 | 
    </update> 
 | 
  
 | 
    <delete id="deleteArdAlarmTubeById" parameterType="String"> 
 | 
        delete 
 | 
        from ard_alarm_tube 
 | 
        where id = #{id} 
 | 
    </delete> 
 | 
  
 | 
    <delete id="deleteArdAlarmTubeByIds" parameterType="String"> 
 | 
        delete from ard_alarm_tube where id in 
 | 
        <foreach item="id" collection="array" open="(" separator="," close=")"> 
 | 
            #{id} 
 | 
        </foreach> 
 | 
    </delete> 
 | 
    <select id="selectListAllByCommand" resultMap="ArdAlarmTubeResult"> 
 | 
        SELECT T.* 
 | 
        FROM ( 
 | 
                 SELECT aat.ID, 
 | 
                        aat.tube_id, 
 | 
                        aat.tube_name, 
 | 
                        aat.alarm_time, 
 | 
                        aat.longitude, 
 | 
                        aat.latitude, 
 | 
                        aat.altitude, 
 | 
                        aat.record_url, 
 | 
                        ROW_NUMBER() OVER ( PARTITION BY aat.tube_id ORDER BY aat.alarm_time DESC ) AS rn, COUNT(CASE WHEN aat.view_time IS NULL THEN 1 END) OVER ( PARTITION BY aat.tube_id ) AS COUNT, 
 | 
                    COUNT ( aat.alarm_time ) OVER ( PARTITION BY tube_id ) AS total 
 | 
                 FROM 
 | 
                     ard_alarm_tube aat 
 | 
                 WHERE 
 | 
                     aat.alarm_time >= ( CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE ) 
 | 
                 order by aat.alarm_time desc 
 | 
             ) T 
 | 
        WHERE T.rn = 1 
 | 
    </select> 
 | 
    <select id="selectCountByAlarmTime" resultType="Integer"> 
 | 
        SELECT COUNT(DISTINCT aat.tube_id) 
 | 
        FROM ard_alarm_tube aat 
 | 
        WHERE aat.alarm_time >= CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE 
 | 
          and aat.view_time is null 
 | 
    </select> 
 | 
    <update id="updateViewTimeByTubeId" parameterType="String"> 
 | 
        update ard_alarm_tube 
 | 
        set view_time=#{viewTime} 
 | 
        where tube_id = #{tubeId} 
 | 
          and alarm_time <= #{alarmTime} 
 | 
          and view_time is null 
 | 
    </update> 
 | 
    <select id="tubeYear" resultType="com.ruoyi.statistical.vo.CountVo"> 
 | 
        select to_char(create_time::DATE, 'MM') as date,count(id) 
 | 
        from ard_alarm_tube 
 | 
        where create_time >= #{start} and  create_time <= #{end}  group by date order by date 
 | 
    </select> 
 | 
    <select id="tubeMonth" resultType="com.ruoyi.statistical.vo.CountVo"> 
 | 
        select to_char(create_time::DATE, 'dd') as date,count(id) 
 | 
        from ard_alarm_tube 
 | 
        where create_time >= #{start} and  create_time <= #{end}  group by date order by date 
 | 
    </select> 
 | 
</mapper> 
 |