<?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="cn.com.ctop.alarm.modules.mapper.AlarmEventRuleMapper">

    <select id="selectListPage" parameterType="cn.com.ctop.alarm.modules.entity.AlarmEventRule"
            resultType="cn.com.ctop.alarm.modules.entity.AlarmEventRule">
        SELECT DISTINCT
        t1.*,t3.realname AS 'createrName',t2.user_id,t2.user_name,t2.auth_name AS 'accountName' FROM
        ctop_alarm_event_rule t1
        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
        LEFT JOIN sys_user t3 ON t1.creater_id = t3.id
        <where>
            <if test="eventRuleStatus != null and eventRuleStatus !='' ">
                AND t1.event_rule_status = #{eventRuleStatus}
            </if>
            <if test="checkFrequency != null and checkFrequency !='' ">
                AND t1.check_frequency = #{checkFrequency}
            </if>
            <if test="unitId != null and unitId !='' ">
                AND t1.event_rule_id != #{unitId}
            </if>
            <if test="accountId != null and accountId !='' ">
                AND t1.account_id = #{accountId}
            </if>
            <if test="eventRuleName != null and eventRuleName !='' ">
                AND t1.event_rule_name = #{eventRuleName}
            </if>
        </where>
        order by t1.create_time desc
    </select>
    <select id="queryRunningRecordPage" parameterType="cn.com.ctop.alarm.modules.entity.AlarmEventRule"
            resultType="cn.com.ctop.alarm.modules.entity.AlarmEventRule">
        SELECT t1.*,
        t3.user_id,t2.create_time AS 'runningTime',
        t3.auth_name AS 'accountName',
        t2.alarm_condition AS 'alarmCondition',
        t3.user_name AS 'userName',t4.realname AS 'createrName'
        FROM ctop_alarm_event_rule t1
        INNER JOIN ctop_alarm_event_send t2 ON t1.event_rule_id = t2.event_rule_id
        LEFT JOIN ctop_user_allocation t3 ON t1.account_id = t3.account_id
        LEFT JOIN sys_user t4 ON t1.creater_id = t4.id
        WHERE t1.event_rule_status = '1'
        <if test="eventRuleId!=null">
            AND t1.event_rule_id = #{eventRuleId}
        </if>
        <if test="eventRuleName!=null">
            AND t1.event_rule_name LIKE CONCAT('%',#{eventRuleName},'%')
        </if>
        ORDER BY t2.create_time DESC
    </select>
    <select id="queryById" resultType="cn.com.ctop.alarm.modules.entity.AlarmEventRule">
       SELECT DISTINCT t1.*,
       t3.realname AS 'createrName',t2.user_id,t2.user_name,t2.auth_name AS accountName
       FROM
        ctop_alarm_event_rule t1
        LEFT JOIN ctop_user_allocation t2 ON t1.account_id = t2.account_id
         LEFT JOIN sys_user t3 ON t1.creater_id = t3.id
        WHERE t1.event_rule_id = #{id}
    </select>
</mapper>