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

    <resultMap type="TRcfile" id="TRcfileResult">
        <result property="id"    column="id"    />
        <result property="pId"    column="p_id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <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="pType"    column="p_type"    />
        <result property="fileSize"    column="file_size"    />
        <result property="pValue"    column="p_value"    />
        <result property="pDate"    column="p_date"    />
        <result property="fileType"    column="file_type"    />
        <result property="parentId"    column="parent_id"    />
        <result property="parentName" column="parent_name" />
        <result property="deptName" column="dept_name" />
        <result property="creator"    column="nick_name"    />

    </resultMap>

    <sql id="selectTRcfileVo">
        select d.id, d.p_id, d.file_name, d.file_url, d.del_flag, d.creater_code,u.nick_name, d.createdate, d.updater_code, d.updatedate, d.remarks, d.p_type, d.file_size, d.p_value, d.p_date, d.file_type, d.parent_id from t_rcfile d
        LEFT JOIN SYS_USER u on d.CREATER_CODE = u.USER_ID
    </sql>

    <select id="selectTRcfileList" parameterType="TRcfile" resultMap="TRcfileResult">
        <include refid="selectTRcfileVo"/>
        <where>
            <if test="fileName != null  and fileName != ''"> and file_name like concat(concat('%', #{fileName}), '%')</if>
            <if test="pId != null "> and p_id = #{pId}</if>
            <if test="fileType != null "> and file_type = #{fileType}</if>
            and d.del_flag = 0
        </where>
        order by parent_id , file_type desc
    </select>

    <select id="selectTRcfileById" parameterType="Long" resultMap="TRcfileResult">
        select t.id, t.p_id, t.file_name, t.file_url, t.del_flag, t.creater_code, t.createdate, t.updater_code, t.updatedate, t.remarks, t.p_type, t.file_size, t.p_value, t.p_date, t.file_type, t.parent_id, p.file_name as parent_name
        from t_rcfile t
        left join t_rcfile p on p.id = t.parent_id
        where t.id = #{id}
    </select>

    <insert id="insertTRcfile" parameterType="TRcfile">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_rcfile.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_rcfile
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="pId != null">p_id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</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="pType != null">p_type,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="pValue != null">p_value,</if>
            <if test="pDate != null">p_date,</if>
            <if test="fileType != null">file_type,</if>
            <if test="parentId != null">parent_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="pId != null">#{pId},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</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="pType != null">#{pType},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="pValue != null">#{pValue},</if>
            <if test="pDate != null">#{pDate},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="parentId != null">#{parentId},</if>
         </trim>
    </insert>

    <update id="updateTRcfile" parameterType="TRcfile">
        update t_rcfile
        <trim prefix="SET" suffixOverrides=",">
            <if test="pId != null">p_id = #{pId},</if>
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</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="pType != null">p_type = #{pType},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="pValue != null">p_value = #{pValue},</if>
            <if test="pDate != null">p_date = #{pDate},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="parentId != null">parent_id = #{parentId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
