<?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.production.mapper.TFivesFileMapper">

    <resultMap type="TFivesFile" id="TFivesFileResult">
        <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="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTFivesFileVo">
        select d.id, d.url, d.name, d.remarks, d.status, d.del_flag, d.creater_code, d.createdate, d.updater_code, d.updatedate, d.dept_id ,s.dept_name from t_fives_file d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTFivesFileList" parameterType="TFivesFile" resultMap="TFivesFileResult">
        <include refid="selectTFivesFileVo"/>
        <where>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="name != null  and name != ''"> and name like concat(concat('%', #{name}), '%')</if>
            <if test="remarks != null  and remarks != ''"> and remarks = #{remarks}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="createrCode != null  and createrCode != ''"> and creater_code = #{createrCode}</if>
            <if test="createdate != null "> and createdate = #{createdate}</if>
            <if test="updaterCode != null "> and updater_code = #{updaterCode}</if>
            <if test="updatedate != null "> and updatedate = #{updatedate}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTFivesFileById" parameterType="Long" resultMap="TFivesFileResult">
        <include refid="selectTFivesFileVo"/>
        where id = #{id}
    </select>

    <insert id="insertTFivesFile" parameterType="TFivesFile">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_fives_file.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_fives_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>
         </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>
         </trim>
    </insert>

    <update id="updateTFivesFile" parameterType="TFivesFile">
        update t_fives_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="updaterCode != null">updater_code = #{updaterCode},</if>
            <if test="updatedate != null">updatedate = #{updatedate},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
        </trim>
        where id = #{id}
    </update>

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

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

</mapper>
