<?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.mapper.TrsFileInfoMapper">
    
    <resultMap type="TrsFileInfo" id="TrsFileInfoResult">
        <result property="id"    column="id"    />
        <result property="docname"    column="docname"    />
        <result property="doccontent"    column="doccontent"    />
        <result property="doctype"    column="doctype"    />
        <result property="createtime"    column="createtime"    />
    </resultMap>

    <sql id="selectTrsFileInfoVo">
        select t.id, t.docname, t.doccontent, t.doctype, t.createtime from trs_file_info t
    </sql>

    <select id="selectTrsFileInfoList" parameterType="TrsFileInfo" resultMap="TrsFileInfoResult">
        <include refid="selectTrsFileInfoVo"/>
        <if test="params.dataScope != null and params.dataScope != ''">
            <!-- 添加部门表关联 -->
            --             LEFT JOIN sys_dept d ON t.dept_id = d.dept_id
            LEFT JOIN sys_user d ON t.user_id = d.user_id
        </if>
        <where>
            <if test="docname != null  and docname != ''"> and docname like concat('%', #{docname}, '%')</if>
            <if test="doctype != null  and doctype != ''"> and doctype = #{doctype}</if>
            <if test="params.beginCreatetime != null and params.beginCreatetime != '' and params.endCreatetime != null and params.endCreatetime != ''"> and createtime between #{params.beginCreatetime} and #{params.endCreatetime}</if>
            <!-- 数据范围过滤移动到where标签内 -->
            <if test="params.dataScope != null and params.dataScope != ''">
                ${params.dataScope}
            </if>
        </where>
    </select>
    
    <select id="selectTrsFileInfoById" parameterType="Long" resultMap="TrsFileInfoResult">
        <include refid="selectTrsFileInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertTrsFileInfo" parameterType="TrsFileInfo" useGeneratedKeys="true" keyProperty="id">
        insert into trs_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="docname != null">docname,</if>
            <if test="doccontent != null">doccontent,</if>
            <if test="doctype != null">doctype,</if>
            <if test="createtime != null">createtime,</if>
            <if test="userId != null">user_id,</if>
            <if test="deptId != null">dept_id,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="docname != null">#{docname},</if>
            <if test="doccontent != null">#{doccontent},</if>
            <if test="doctype != null">#{doctype},</if>
            <if test="createtime != null">#{createtime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="deptId != null">#{deptId},</if>
         </trim>
    </insert>

    <update id="updateTrsFileInfo" parameterType="TrsFileInfo">
        update trs_file_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="docname != null">docname = #{docname},</if>
            <if test="doccontent != null">doccontent = #{doccontent},</if>
            <if test="doctype != null">doctype = #{doctype},</if>
            <if test="createtime != null">createtime = #{createtime},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTrsFileInfoById" parameterType="Long">
        delete from trs_file_info where id = #{id}
    </delete>

    <delete id="deleteTrsFileInfoByIds" parameterType="String">
        delete from trs_file_info where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>