<?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.business.mapper.HwAlarmRuleMapper">
    
    <resultMap type="HwAlarmRule" id="HwAlarmRuleResult">
        <result property="alarmRuleId"    column="alarm_rule_id"    />
        <result property="alarmRuleName"    column="alarm_rule_name"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="sceneId"    column="scene_id"    />
        <result property="alarmLevelId"    column="alarm_level_id"    />
        <result property="alarmTypeId"    column="alarm_type_id"    />
        <result property="ruleType"    column="rule_type"    />
        <result property="deviceId"    column="device_id"    />
        <result property="deviceModeId"    column="device_mode_id"    />
        <result property="modeFunctionId"    column="mode_function_id"    />
        <result property="triggerCondition"    column="trigger_condition"    />
        <result property="triggerDataA"    column="trigger_data_a"    />
        <result property="triggerDataB"    column="trigger_data_b"    />
        <result property="triggerDeadzone"    column="trigger_deadzone"    />
        <result property="triggerNumber"    column="trigger_number"    />
        <result property="triggerTimeFrame"    column="trigger_time_frame"    />
        <result property="linkFlag"    column="link_flag"    />
        <result property="linkType"    column="link_type"    />
        <result property="linkDeviceId"    column="link_device_id"    />
        <result property="linkDeviceFunctionId"    column="link_device_function_id"    />
        <result property="linkDeviceFunctionData"    column="link_device_function_data"    />
        <result property="alarmRuleStatus"    column="alarm_rule_status"    />
        <result property="alarmPushFlag"    column="alarm_push_flag"    />
        <result property="alarmPushContent"    column="alarm_push_content"    />
        <result property="alarmRecoverContent"    column="alarm_recover_content"    />
        <result property="remark"    column="remark"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="alarmRuleField"    column="alarm_rule_field"    />
    </resultMap>

    <sql id="selectHwAlarmRuleVo">
        select alarm_rule_id, alarm_rule_name, tenant_id, scene_id, alarm_level_id, alarm_type_id, rule_type, device_id, device_mode_id, mode_function_id, trigger_condition, trigger_data_a, trigger_data_b, trigger_deadzone, trigger_number, trigger_time_frame, link_flag, link_type, link_device_id, link_device_function_id, link_device_function_data, alarm_rule_status, alarm_push_flag, alarm_push_content, alarm_recover_content, remark, create_by, create_time, update_by, update_time, alarm_rule_field from hw_alarm_rule
    </sql>

    <select id="selectHwAlarmRuleList" parameterType="HwAlarmRule" resultMap="HwAlarmRuleResult">
        <include refid="selectHwAlarmRuleVo"/>
        <where>  
            <if test="alarmRuleName != null  and alarmRuleName != ''"> and alarm_rule_name like concat('%', #{alarmRuleName}, '%')</if>
            <if test="tenantId != null "> and tenant_id = #{tenantId}</if>
            <if test="sceneId != null "> and scene_id = #{sceneId}</if>
            <if test="alarmLevelId != null "> and alarm_level_id = #{alarmLevelId}</if>
            <if test="alarmTypeId != null "> and alarm_type_id = #{alarmTypeId}</if>
            <if test="ruleType != null  and ruleType != ''"> and rule_type = #{ruleType}</if>
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="deviceModeId != null "> and device_mode_id = #{deviceModeId}</if>
            <if test="modeFunctionId != null "> and mode_function_id = #{modeFunctionId}</if>
            <if test="triggerCondition != null  and triggerCondition != ''"> and trigger_condition = #{triggerCondition}</if>
            <if test="triggerDataA != null  and triggerDataA != ''"> and trigger_data_a = #{triggerDataA}</if>
            <if test="triggerDataB != null  and triggerDataB != ''"> and trigger_data_b = #{triggerDataB}</if>
            <if test="triggerDeadzone != null  and triggerDeadzone != ''"> and trigger_deadzone = #{triggerDeadzone}</if>
            <if test="triggerNumber != null "> and trigger_number = #{triggerNumber}</if>
            <if test="triggerTimeFrame != null "> and trigger_time_frame = #{triggerTimeFrame}</if>
            <if test="linkFlag != null  and linkFlag != ''"> and link_flag = #{linkFlag}</if>
            <if test="linkType != null  and linkType != ''"> and link_type = #{linkType}</if>
            <if test="linkDeviceId != null "> and link_device_id = #{linkDeviceId}</if>
            <if test="linkDeviceFunctionId != null "> and link_device_function_id = #{linkDeviceFunctionId}</if>
            <if test="linkDeviceFunctionData != null  and linkDeviceFunctionData != ''"> and link_device_function_data = #{linkDeviceFunctionData}</if>
            <if test="alarmRuleStatus != null  and alarmRuleStatus != ''"> and alarm_rule_status = #{alarmRuleStatus}</if>
            <if test="alarmPushFlag != null  and alarmPushFlag != ''"> and alarm_push_flag = #{alarmPushFlag}</if>
            <if test="alarmPushContent != null  and alarmPushContent != ''"> and alarm_push_content = #{alarmPushContent}</if>
            <if test="alarmRecoverContent != null  and alarmRecoverContent != ''"> and alarm_recover_content = #{alarmRecoverContent}</if>
            <if test="alarmRuleField != null  and alarmRuleField != ''"> and alarm_rule_field = #{alarmRuleField}</if>
        </where>
    </select>
    
    <select id="selectHwAlarmRuleByAlarmRuleId" parameterType="Long" resultMap="HwAlarmRuleResult">
        <include refid="selectHwAlarmRuleVo"/>
        where alarm_rule_id = #{alarmRuleId}
    </select>
        
    <insert id="insertHwAlarmRule" parameterType="HwAlarmRule" useGeneratedKeys="true" keyProperty="alarmRuleId">
        insert into hw_alarm_rule
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="alarmRuleName != null and alarmRuleName != ''">alarm_rule_name,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="sceneId != null">scene_id,</if>
            <if test="alarmLevelId != null">alarm_level_id,</if>
            <if test="alarmTypeId != null">alarm_type_id,</if>
            <if test="ruleType != null and ruleType != ''">rule_type,</if>
            <if test="deviceId != null">device_id,</if>
            <if test="deviceModeId != null">device_mode_id,</if>
            <if test="modeFunctionId != null">mode_function_id,</if>
            <if test="triggerCondition != null and triggerCondition != ''">trigger_condition,</if>
            <if test="triggerDataA != null and triggerDataA != ''">trigger_data_a,</if>
            <if test="triggerDataB != null">trigger_data_b,</if>
            <if test="triggerDeadzone != null">trigger_deadzone,</if>
            <if test="triggerNumber != null">trigger_number,</if>
            <if test="triggerTimeFrame != null">trigger_time_frame,</if>
            <if test="linkFlag != null and linkFlag != ''">link_flag,</if>
            <if test="linkType != null">link_type,</if>
            <if test="linkDeviceId != null">link_device_id,</if>
            <if test="linkDeviceFunctionId != null">link_device_function_id,</if>
            <if test="linkDeviceFunctionData != null">link_device_function_data,</if>
            <if test="alarmRuleStatus != null and alarmRuleStatus != ''">alarm_rule_status,</if>
            <if test="alarmPushFlag != null and alarmPushFlag != ''">alarm_push_flag,</if>
            <if test="alarmPushContent != null">alarm_push_content,</if>
            <if test="alarmRecoverContent != null">alarm_recover_content,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="alarmRuleField != null">alarm_rule_field,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="alarmRuleName != null and alarmRuleName != ''">#{alarmRuleName},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="sceneId != null">#{sceneId},</if>
            <if test="alarmLevelId != null">#{alarmLevelId},</if>
            <if test="alarmTypeId != null">#{alarmTypeId},</if>
            <if test="ruleType != null and ruleType != ''">#{ruleType},</if>
            <if test="deviceId != null">#{deviceId},</if>
            <if test="deviceModeId != null">#{deviceModeId},</if>
            <if test="modeFunctionId != null">#{modeFunctionId},</if>
            <if test="triggerCondition != null and triggerCondition != ''">#{triggerCondition},</if>
            <if test="triggerDataA != null and triggerDataA != ''">#{triggerDataA},</if>
            <if test="triggerDataB != null">#{triggerDataB},</if>
            <if test="triggerDeadzone != null">#{triggerDeadzone},</if>
            <if test="triggerNumber != null">#{triggerNumber},</if>
            <if test="triggerTimeFrame != null">#{triggerTimeFrame},</if>
            <if test="linkFlag != null and linkFlag != ''">#{linkFlag},</if>
            <if test="linkType != null">#{linkType},</if>
            <if test="linkDeviceId != null">#{linkDeviceId},</if>
            <if test="linkDeviceFunctionId != null">#{linkDeviceFunctionId},</if>
            <if test="linkDeviceFunctionData != null">#{linkDeviceFunctionData},</if>
            <if test="alarmRuleStatus != null and alarmRuleStatus != ''">#{alarmRuleStatus},</if>
            <if test="alarmPushFlag != null and alarmPushFlag != ''">#{alarmPushFlag},</if>
            <if test="alarmPushContent != null">#{alarmPushContent},</if>
            <if test="alarmRecoverContent != null">#{alarmRecoverContent},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="alarmRuleField != null">#{alarmRuleField},</if>
         </trim>
    </insert>

    <update id="updateHwAlarmRule" parameterType="HwAlarmRule">
        update hw_alarm_rule
        <trim prefix="SET" suffixOverrides=",">
            <if test="alarmRuleName != null and alarmRuleName != ''">alarm_rule_name = #{alarmRuleName},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="sceneId != null">scene_id = #{sceneId},</if>
            <if test="alarmLevelId != null">alarm_level_id = #{alarmLevelId},</if>
            <if test="alarmTypeId != null">alarm_type_id = #{alarmTypeId},</if>
            <if test="ruleType != null and ruleType != ''">rule_type = #{ruleType},</if>
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="deviceModeId != null">device_mode_id = #{deviceModeId},</if>
            <if test="modeFunctionId != null">mode_function_id = #{modeFunctionId},</if>
            <if test="triggerCondition != null and triggerCondition != ''">trigger_condition = #{triggerCondition},</if>
            <if test="triggerDataA != null and triggerDataA != ''">trigger_data_a = #{triggerDataA},</if>
            <if test="triggerDataB != null">trigger_data_b = #{triggerDataB},</if>
            <if test="triggerDeadzone != null">trigger_deadzone = #{triggerDeadzone},</if>
            <if test="triggerNumber != null">trigger_number = #{triggerNumber},</if>
            <if test="triggerTimeFrame != null">trigger_time_frame = #{triggerTimeFrame},</if>
            <if test="linkFlag != null and linkFlag != ''">link_flag = #{linkFlag},</if>
            <if test="linkType != null">link_type = #{linkType},</if>
            <if test="linkDeviceId != null">link_device_id = #{linkDeviceId},</if>
            <if test="linkDeviceFunctionId != null">link_device_function_id = #{linkDeviceFunctionId},</if>
            <if test="linkDeviceFunctionData != null">link_device_function_data = #{linkDeviceFunctionData},</if>
            <if test="alarmRuleStatus != null and alarmRuleStatus != ''">alarm_rule_status = #{alarmRuleStatus},</if>
            <if test="alarmPushFlag != null and alarmPushFlag != ''">alarm_push_flag = #{alarmPushFlag},</if>
            <if test="alarmPushContent != null">alarm_push_content = #{alarmPushContent},</if>
            <if test="alarmRecoverContent != null">alarm_recover_content = #{alarmRecoverContent},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="alarmRuleField != null">alarm_rule_field = #{alarmRuleField},</if>
        </trim>
        where alarm_rule_id = #{alarmRuleId}
    </update>

    <delete id="deleteHwAlarmRuleByAlarmRuleId" parameterType="Long">
        delete from hw_alarm_rule where alarm_rule_id = #{alarmRuleId}
    </delete>

    <delete id="deleteHwAlarmRuleByAlarmRuleIds" parameterType="String">
        delete from hw_alarm_rule where alarm_rule_id in 
        <foreach item="alarmRuleId" collection="array" open="(" separator="," close=")">
            #{alarmRuleId}
        </foreach>
    </delete>
</mapper>