<?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.project.system.mapper.TAlarmtypeMapper">

    <resultMap type="TAlarmtype" id="TAlarmtypeResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="tableName"    column="table_name"    />
        <result property="fieldName"    column="field_name"    />
        <result property="firstlevel"    column="firstlevel"    />
        <result property="secondlevel"    column="secondlevel"    />
        <result property="thirdlevel"    column="thirdlevel"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="createdate"    column="createdate"    />
        <result property="updaterCode"    column="updater_code"    />
        <result property="updatedate"    column="updatedate"    />
        <result property="deptId"    column="dept_id"    />
        <result property="remarks"    column="remarks"    />
        <result property="isOpen"    column="is_open"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTAlarmtypeVo">
        select d.id, d.plant_code, d.table_name, d.field_name, d.firstlevel, d.secondlevel, d.thirdlevel, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id, d.remarks, d.is_open ,s.dept_name from t_alarmtype d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTAlarmtypeList" parameterType="TAlarmtype" resultMap="TAlarmtypeResult">
        <include refid="selectTAlarmtypeVo"/>
        <where>
            <if test="tableName != null  and tableName != ''"> and table_name like concat(concat('%', #{tableName}), '%')</if>
            <if test="fieldName != null  and fieldName != ''"> and field_name like concat(concat('%', #{fieldName}), '%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTAlarmtypeById" parameterType="Long" resultMap="TAlarmtypeResult">
        <include refid="selectTAlarmtypeVo"/>
        where id = #{id}
    </select>

    <insert id="insertTAlarmtype" parameterType="TAlarmtype">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_alarmtype.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_alarmtype
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="tableName != null">table_name,</if>
            <if test="fieldName != null">field_name,</if>
            <if test="firstlevel != null">firstlevel,</if>
            <if test="secondlevel != null">secondlevel,</if>
            <if test="thirdlevel != null">thirdlevel,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="createdate != null">createdate,</if>
            <if test="updaterCode != null">updater_code,</if>
            <if test="updatedate != null">updatedate,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="isOpen != null">is_open,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="tableName != null">#{tableName},</if>
            <if test="fieldName != null">#{fieldName},</if>
            <if test="firstlevel != null">#{firstlevel},</if>
            <if test="secondlevel != null">#{secondlevel},</if>
            <if test="thirdlevel != null">#{thirdlevel},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="createdate != null">#{createdate},</if>
            <if test="updaterCode != null">#{updaterCode},</if>
            <if test="updatedate != null">#{updatedate},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="isOpen != null">#{isOpen},</if>
         </trim>
    </insert>

    <update id="updateTAlarmtype" parameterType="TAlarmtype">
        update t_alarmtype
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="firstlevel != null">firstlevel = #{firstlevel},</if>
            <if test="secondlevel != null">secondlevel = #{secondlevel},</if>
            <if test="thirdlevel != null">thirdlevel = #{thirdlevel},</if>
            <if test="firstlevel == null">firstlevel = NULL,</if>
            <if test="secondlevel == null">secondlevel = NULL,</if>
            <if test="thirdlevel == null">thirdlevel = NULL,</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="createdate != null">createdate = #{createdate},</if>
            <if test="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateIsOpen" parameterType="TAlarmtype">
        update t_alarmtype
        <trim prefix="SET" suffixOverrides=",">
            <if test="isOpen != null">is_open = #{isOpen},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTAlarmtypeById" parameterType="Long">
        update t_alarmtype set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTAlarmtypeByIds" parameterType="String">
        update t_alarmtype set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

</mapper>
