<?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="acsName!=null and acsName!=''"> 
 | 
                AND acs_name like concat('%', #{acsName}, '%') 
 | 
            </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> 
 | 
        </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 <= #{alarmTime} 
 | 
          and view_time is null 
 | 
    </update> 
 | 
  
 | 
    <select id="accessYear" resultType="com.ruoyi.statistical.vo.CountVo"> 
 | 
        select to_char(alarm_time::DATE, 'MM') as date,count(id) 
 | 
        from ard_alarm_access 
 | 
        where alarm_time >= #{start} and  alarm_time <= #{end}  group by date order by date 
 | 
    </select> 
 | 
    <select id="accessMonth" resultType="com.ruoyi.statistical.vo.CountVo"> 
 | 
        select to_char(alarm_time::DATE, 'dd') as date,count(id) 
 | 
        from ard_alarm_access 
 | 
        where alarm_time >= #{start} and  alarm_time <= #{end}  group by date order by date 
 | 
    </select> 
 | 
</mapper> 
 |