| <?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.steal.mapper.ArdAlarmStealelecMapper"> | 
|     <resultMap id="BaseResultMap" type="ArdAlarmStealelec"> | 
|         <id column="id" property="id"/> | 
|         <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 | 
|         , name, describe, catalog_text, description, start_time, end_time,view_time,longitude,latitude,altitude,create_by,create_time,user_id,dept_id | 
|     </sql> | 
|     <select id="selectArdAlarmStealelecList" parameterType="ArdAlarmStealelec" resultMap="BaseResultMap"> | 
|         select | 
|         <include refid="Base_Column_List"/> | 
|         from ard_alarm_stealelec | 
|         <where> | 
|             <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> | 
|                 AND start_time >= to_timestamp(#{params.beginTime},'yyyy-MM-DD HH24:MI:ss') | 
|             </if> | 
|             <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | 
|                 AND start_time <= to_timestamp(#{params.endTime},'yyyy-MM-DD HH24:MI:ss') | 
|             </if> | 
|         </where> | 
|         order by start_time desc | 
|     </select> | 
|     <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 >= to_timestamp(#{params.beginTime},'yyyy-MM-DD') | 
|             </if> | 
|             <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> | 
|                 and start_time <= to_timestamp(#{params.endTime},'yyyy-MM-DD') | 
|             </if> | 
|         </where> | 
|     </select> | 
|     <select id="selectListAllByCommand" 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 ) | 
|                  order by aas.start_time desc | 
|              ) 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> | 
|     <select id="selectCountByStartTime" resultType="Integer"> | 
|         select count(DISTINCT aas."describe") | 
|         from ard_alarm_stealelec aas | 
|         where aas.start_time >= (CURRENT_TIMESTAMP - INTERVAL '%${refreshTime}%' MINUTE) | 
|         and aas.view_time is null | 
|     </select> | 
|     <update id="updateViewTimeByDescribe" parameterType="String"> | 
|         update ard_alarm_stealelec | 
|         set view_time=#{viewTime} | 
|         where describe = #{describe} | 
|           and start_time<=#{alarmTime} | 
|           and view_time is null | 
|     </update> | 
|     <update id="updateArdAlarmStealelec" parameterType="ArdAlarmStealelec"> | 
|         update ard_alarm_stealelec | 
|         <trim prefix="SET" suffixOverrides=","> | 
|             <if test="name != null">name = #{name},</if> | 
|             <if test="describe != null">describe = #{describe},</if> | 
|             <if test="catalogText != null">catalog_text = #{catalogText},</if> | 
|             <if test="description != null">description = #{description},</if> | 
|             <if test="startTime != null">start_time = #{startTime},</if> | 
|             <if test="endTime != null">end_time = #{endTime},</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> | 
|     <insert id="insertArdAlarmStealelec" parameterType="ArdAlarmStealelec"> | 
|         insert into ard_alarm_stealelec(<include refid="Base_Column_List"/>) | 
|         values (#{id}, #{name},#{describe},#{catalogText},#{description}, #{startTime}, #{endTime}, | 
|         #{viewTime},#{longitude},#{latitude},#{altitude},#{createBy},#{createTime},#{userId},#{deptId}) | 
|     </insert> | 
| </mapper> |