<?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.branch.mapper.TFileMapper">

    <resultMap type="TFile" id="TFileResult">
        <result property="id"    column="id"    />
        <result property="url"    column="url"    />
        <result property="name"    column="name"    />
        <result property="remarks"    column="remarks"    />
        <result property="status"    column="status"    />
        <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="creater"    column="nick_name"    />
        <result property="tableId"    column="table_id"    />
        <result property="tableName"    column="table_name"    />
    </resultMap>

    <sql id="selectTFileVo">
        select u.id, u.url, u.name, u.remarks, u.status, u.del_flag, u.creater_code, u.createdate, u.updater_code, u.updatedate, u.dept_id from t_file u left join sys_dept d on u.dept_id = d.dept_id
    </sql>

    <select id="selectTFileList" parameterType="TFile" resultMap="TFileResult">
        select u.id, u.url, u.name, u.remarks, u.status, u.del_flag, u.creater_code, u.createdate, u.updater_code, u.updatedate, u.dept_id,u.table_id,u.table_name,su.nick_name from t_file u left join sys_dept d on u.dept_id = d.dept_id
        left join sys_user su on u.creater_code=su.user_id
        <where>
            <if test="url != null  and url != ''">and u.url = #{url}</if>
            <if test="name != null  and name != ''">and u.name like concat(concat('%',#{name}),'%')</if>
            <if test="tableId != null">and u.table_id=#{tableId}</if>
            <if test="tableName != null  and tableName != ''">and u.table_name like concat(concat('%',#{tableName}),'%')</if>
            <if test="remarks != null  and remarks != ''">and u.remarks = #{remarks}</if>
            <if test="status != null ">and u.status = #{status}</if>
            <if test="createrCode != null  and createrCode != ''">and u.creater_code = #{createrCode}</if>
            <if test="createdate != null ">and u.createdate = #{createdate}</if>
            <if test="updaterCode != null ">and u.updater_code = #{updaterCode}</if>
            <if test="updatedate != null ">and u.updatedate = #{updatedate}</if>
            <if test="deptId != null ">and u.dept_id = #{deptId}</if>
            <if test="filesId != null ">and id in
                <foreach item="id" collection="filesId" open="(" separator="," close=")">
                    #{id}
                </foreach>
            </if>
            and u.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTFileById" parameterType="Long" resultMap="TFileResult">
        <include refid="selectTFileVo"/>
        where u.id = #{id}
        and u.del_flag = 0
    </select>

    <insert id="insertTFile" parameterType="TFile" useGeneratedKeys="true" keyProperty="id">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_file.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="url != null">url,</if>
            <if test="name != null">name,</if>
            <if test="remarks != null">remarks,</if>
            <if test="status != null">status,</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="tableId != null">table_id,</if>
            <if test="tableName != null">table_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="url != null">#{url},</if>
            <if test="name != null">#{name},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="status != null">#{status},</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="tableId != null">#{tableId},</if>
            <if test="tableName != null">#{tableName},</if>
         </trim>
    </insert>

    <update id="updateTFile" parameterType="TFile">
        update t_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="url != null">url = #{url},</if>
            <if test="name != null">name = #{name},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="status != null">status = #{status},</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="tableId != null">table_id=#{tableId},</if>
            <if test="tableName != null">table_name=#{tableName},</if>
        </trim>
        where id = #{id}
    </update>

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

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