<?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.HwAlarmLevelMapper">
    
    <resultMap type="HwAlarmLevel" id="HwAlarmLevelResult">
        <result property="alarmLevelId"    column="alarm_level_id"    />
        <result property="alarmLevelName"    column="alarm_level_name"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="sceneId"    column="scene_id"    />
        <result property="languageCode"    column="language_code"    />
        <result property="commonFlag"    column="common_flag"    />
        <result property="levelNumber"    column="level_number"    />
        <result property="levelStatus"    column="level_status"    />
        <result property="defaultNotifyMode"    column="default_notify_mode"    />
        <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="alarmLevelField"    column="alarm_level_field"    />
    </resultMap>

    <sql id="selectHwAlarmLevelVo">
        select alarm_level_id, alarm_level_name, tenant_id, scene_id, language_code, common_flag, level_number, level_status, default_notify_mode, remark, create_by, create_time, update_by, update_time, alarm_level_field from hw_alarm_level
    </sql>

    <select id="selectHwAlarmLevelList" parameterType="HwAlarmLevel" resultMap="HwAlarmLevelResult">
        <include refid="selectHwAlarmLevelVo"/>
        <where>  
            <if test="alarmLevelName != null  and alarmLevelName != ''"> and alarm_level_name like concat('%', #{alarmLevelName}, '%')</if>
            <if test="tenantId != null "> and tenant_id = #{tenantId}</if>
            <if test="sceneId != null "> and scene_id = #{sceneId}</if>
            <if test="languageCode != null  and languageCode != ''"> and language_code = #{languageCode}</if>
            <if test="commonFlag != null  and commonFlag != ''"> and common_flag = #{commonFlag}</if>
            <if test="levelNumber != null "> and level_number = #{levelNumber}</if>
            <if test="levelStatus != null  and levelStatus != ''"> and level_status = #{levelStatus}</if>
            <if test="defaultNotifyMode != null  and defaultNotifyMode != ''"> and default_notify_mode = #{defaultNotifyMode}</if>
            <if test="alarmLevelField != null  and alarmLevelField != ''"> and alarm_level_field = #{alarmLevelField}</if>
        </where>
    </select>
    
    <select id="selectHwAlarmLevelByAlarmLevelId" parameterType="Long" resultMap="HwAlarmLevelResult">
        <include refid="selectHwAlarmLevelVo"/>
        where alarm_level_id = #{alarmLevelId}
    </select>
        
    <insert id="insertHwAlarmLevel" parameterType="HwAlarmLevel" useGeneratedKeys="true" keyProperty="alarmLevelId">
        insert into hw_alarm_level
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="alarmLevelName != null and alarmLevelName != ''">alarm_level_name,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="sceneId != null">scene_id,</if>
            <if test="languageCode != null">language_code,</if>
            <if test="commonFlag != null and commonFlag != ''">common_flag,</if>
            <if test="levelNumber != null">level_number,</if>
            <if test="levelStatus != null and levelStatus != ''">level_status,</if>
            <if test="defaultNotifyMode != null">default_notify_mode,</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="alarmLevelField != null">alarm_level_field,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="alarmLevelName != null and alarmLevelName != ''">#{alarmLevelName},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="sceneId != null">#{sceneId},</if>
            <if test="languageCode != null">#{languageCode},</if>
            <if test="commonFlag != null and commonFlag != ''">#{commonFlag},</if>
            <if test="levelNumber != null">#{levelNumber},</if>
            <if test="levelStatus != null and levelStatus != ''">#{levelStatus},</if>
            <if test="defaultNotifyMode != null">#{defaultNotifyMode},</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="alarmLevelField != null">#{alarmLevelField},</if>
         </trim>
    </insert>

    <update id="updateHwAlarmLevel" parameterType="HwAlarmLevel">
        update hw_alarm_level
        <trim prefix="SET" suffixOverrides=",">
            <if test="alarmLevelName != null and alarmLevelName != ''">alarm_level_name = #{alarmLevelName},</if>
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="sceneId != null">scene_id = #{sceneId},</if>
            <if test="languageCode != null">language_code = #{languageCode},</if>
            <if test="commonFlag != null and commonFlag != ''">common_flag = #{commonFlag},</if>
            <if test="levelNumber != null">level_number = #{levelNumber},</if>
            <if test="levelStatus != null and levelStatus != ''">level_status = #{levelStatus},</if>
            <if test="defaultNotifyMode != null">default_notify_mode = #{defaultNotifyMode},</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="alarmLevelField != null">alarm_level_field = #{alarmLevelField},</if>
        </trim>
        where alarm_level_id = #{alarmLevelId}
    </update>

    <delete id="deleteHwAlarmLevelByAlarmLevelId" parameterType="Long">
        delete from hw_alarm_level where alarm_level_id = #{alarmLevelId}
    </delete>

    <delete id="deleteHwAlarmLevelByAlarmLevelIds" parameterType="String">
        delete from hw_alarm_level where alarm_level_id in 
        <foreach item="alarmLevelId" collection="array" open="(" separator="," close=")">
            #{alarmLevelId}
        </foreach>
    </delete>
</mapper>