<?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.ehs.mapper.TRcauditmenuMapper">
    
    <resultMap type="TRcauditmenu" id="TRcauditmenuResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="parentId"       column="parent_id"      />
        <result property="serialNum"    column="serial_num"    />
        <result property="nameCn"    column="name_cn"    />
        <result property="nameEn"    column="name_en"    />
        <result property="deptId"    column="dept_id"    />
        <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="remarks"    column="remarks"    />
        <result property="deptName" column="dept_name" />
        <result property="itemFirst"    column="item_first"    />
        <result property="itemSecond"    column="item_second"    />
        <result property="itemThird"    column="item_third"    />
        <result property="itemFourth"    column="item_fourth"    />
    </resultMap>

    <sql id="selectTRcauditmenuVo">
        select d.id, d.plant_code, d.parent_id, d.serial_num, d.name_cn, d.name_en, d.dept_id, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.item_first, d.item_second, d.item_third, d.item_fourth ,s.dept_name from t_rcauditmenu d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTRcauditmenuList" parameterType="TRcauditmenu" resultMap="TRcauditmenuResult">
        <include refid="selectTRcauditmenuVo"/>
        <where>
            <if test="nameCn != null and nameCn != ''"> AND name_cn like concat(concat('%',#{nameCn}),'%')</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        ORDER BY d.item_first asc, d.item_second asc, d.item_third asc, d.item_fourth asc
    </select>
    
    <select id="selectTRcauditmenuById" parameterType="Long" resultMap="TRcauditmenuResult">
        <include refid="selectTRcauditmenuVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTRcauditmenu" parameterType="TRcauditmenu">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_rcauditmenu.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_rcauditmenu
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="parentId != null">parent_id,</if>
            <if test="serialNum != null and serialNum != ''">serial_num,</if>
            <if test="nameCn != null and nameCn != ''">name_cn,</if>
            <if test="nameEn != null">name_en,</if>
            <if test="deptId != null">dept_id,</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="remarks != null">remarks,</if>
            <if test="itemFirst != null">item_first,</if>
            <if test="itemSecond != null">item_second,</if>
            <if test="itemThird != null">item_third,</if>
            <if test="itemFourth != null">item_fourth,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="parentId != null">#{parentId},</if>
            <if test="serialNum != null and serialNum != ''">#{serialNum},</if>
            <if test="nameCn != null and nameCn != ''">#{nameCn},</if>
            <if test="nameEn != null">#{nameEn},</if>
            <if test="deptId != null">#{deptId},</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="remarks != null">#{remarks},</if>
            <if test="itemFirst != null">#{itemFirst},</if>
            <if test="itemSecond != null">#{itemSecond},</if>
            <if test="itemThird != null">#{itemThird},</if>
            <if test="itemFourth != null">#{itemFourth},</if>
         </trim>
    </insert>

    <update id="updateTRcauditmenu" parameterType="TRcauditmenu">
        update t_rcauditmenu
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
            <if test="serialNum != null and serialNum != ''">serial_num = #{serialNum},</if>
            <if test="nameCn != null and nameCn != ''">name_cn = #{nameCn},</if>
            <if test="nameEn != null">name_en = #{nameEn},</if>
            <if test="deptId != null">dept_id = #{deptId},</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="remarks != null">remarks = #{remarks},</if>
            <if test="itemFirst != null">item_first = #{itemFirst},</if>
            <if test="itemSecond != null">item_second = #{itemSecond},</if>
            <if test="itemThird != null">item_third = #{itemThird},</if>
            <if test="itemFourth != null">item_fourth = #{itemFourth},</if>
        </trim>
        where id = #{id}
    </update>

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

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