<?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.TRcauditMapper">

    <resultMap type="TRcaudit" id="TRcauditResult">
        <result property="id"    column="id"    />
        <result property="plantCode"    column="plant_code"    />
        <result property="rcCode"    column="rc_code"    />
        <result property="menuid"    column="menuid"    />
        <result property="nameCn"    column="name_cn"    />
        <result property="nameEn"    column="name_en"    />
        <result property="yes"    column="yes"    />
        <result property="no"    column="no"    />
        <result property="na"    column="na"    />
        <result property="link"    column="link"    />
        <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="deptId"    column="dept_id"    />
        <result property="deptName" column="dept_name" />
        <result property="fileNum" column="file_num" />
    </resultMap>

    <sql id="selectTRcauditVo">
        select p.name_cn as menuName, d.id, d.plant_code, d.rc_code, d.menuid, d.name_cn, d.name_en, d.yes, d.no, d.na, d.link, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.remarks, d.dept_id ,s.dept_name, d.file_num from t_rcaudit d
      left join sys_dept s on s.dept_id = d.dept_id
      left join t_rcauditmenu p on p.serial_num = d.menuid
    </sql>

    <select id="selectTRcauditList" parameterType="TRcaudit" resultMap="TRcauditResult">
        <include refid="selectTRcauditVo"/>
        <where>
            <if test="menuid != null  and menuid != ''"> and menuid = #{menuid}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
        ORDER BY d.menuid asc, d.rc_code asc
    </select>

    <select id="selectTRcauditById" parameterType="Long" resultMap="TRcauditResult">
        <include refid="selectTRcauditVo"/>
        where d.id = #{id}
    </select>

    <insert id="insertTRcaudit" parameterType="TRcaudit">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_rcaudit.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_rcaudit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="plantCode != null and plantCode != ''">plant_code,</if>
            <if test="rcCode != null and rcCode != ''">rc_code,</if>
            <if test="menuid != null and menuid != ''">menuid,</if>
            <if test="nameCn != null and nameCn != ''">name_cn,</if>
            <if test="nameEn != null">name_en,</if>
            <if test="yes != null">yes,</if>
            <if test="no != null">no,</if>
            <if test="na != null">na,</if>
            <if test="link != null">link,</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="fileNum != null">file_num,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="plantCode != null and plantCode != ''">#{plantCode},</if>
            <if test="rcCode != null and rcCode != ''">#{rcCode},</if>
            <if test="menuid != null and menuid != ''">#{menuid},</if>
            <if test="nameCn != null and nameCn != ''">#{nameCn},</if>
            <if test="nameEn != null">#{nameEn},</if>
            <if test="yes != null">#{yes},</if>
            <if test="no != null">#{no},</if>
            <if test="na != null">#{na},</if>
            <if test="link != null">#{link},</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="fileNum != null">#{fileNum},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTRcaudit" parameterType="TRcaudit">
        update t_rcaudit
        <trim prefix="SET" suffixOverrides=",">
            <if test="plantCode != null and plantCode != ''">plant_code = #{plantCode},</if>
            <if test="rcCode != null and rcCode != ''">rc_code = #{rcCode},</if>
            <if test="menuid != null and menuid != ''">menuid = #{menuid},</if>
            <if test="nameCn != null and nameCn != ''">name_cn = #{nameCn},</if>
            <if test="nameEn != null">name_en = #{nameEn},</if>
            <if test="yes != null">yes = #{yes},</if>
            <if test="no != null">no = #{no},</if>
            <if test="na != null">na = #{na},</if>
            <if test="yes == null">yes = NULL,</if>
            <if test="no == null">no = NULL,</if>
            <if test="na == null">na = NULL,</if>
            <if test="link != null">link = #{link},</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="fileNum != null">file_num = #{fileNum},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

    <select id="selectNaData" resultType="com.ruoyi.project.common.domain.DataEntity">
        SELECT count(1) as dataNum FROM t_rcaudit d
        <where>
            and d.del_flag = 0
            <if test="yes == 1">and yes is not null</if>
            <if test="yes == 2">and no is not null</if>
            <if test="yes == 3">and na is not null</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

</mapper>
