<?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.TSaiFileMapper">
    
    <resultMap type="TSaiFile" id="TSaiFileResult">
        <result property="id"    column="id"    />
        <result property="fileName"    column="file_name"    />
        <result property="fileUrl"    column="file_url"    />
        <result property="fileType"    column="file_type"    />
        <result property="devType"    column="dev_type"    />
        <result property="createrDate"    column="creater_date"    />
        <result property="createrCode"    column="creater_code"    />
        <result property="remark"    column="remark"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTSaiFileVo">
        select d.id, d.file_name, d.file_url, d.file_type, d.dev_type, d.creater_date, d.creater_code, d.remark, d.dept_id, d.del_flag ,s.dept_name from t_sai_file d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTSaiFileList" parameterType="TSaiFile" resultMap="TSaiFileResult">
        <include refid="selectTSaiFileVo"/>
        <where>  
            <if test="fileName != null  and fileName != ''"> and file_name like concat(concat('%', #{fileName}), '%')</if>
            <if test="fileUrl != null  and fileUrl != ''"> and file_url = #{fileUrl}</if>
            <if test="fileType != null "> and file_type = #{fileType}</if>
            <if test="devType != null "> and dev_type = #{devType}</if>
            <if test="createrDate != null "> and creater_date = #{createrDate}</if>
            <if test="createrCode != null "> and creater_code = #{createrCode}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>
    
    <select id="selectTSaiFileById" parameterType="Long" resultMap="TSaiFileResult">
        <include refid="selectTSaiFileVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTSaiFile" parameterType="TSaiFile">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_sai_file.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_sai_file
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="fileName != null">file_name,</if>
            <if test="fileUrl != null">file_url,</if>
            <if test="fileType != null">file_type,</if>
            <if test="devType != null">dev_type,</if>
            <if test="createrDate != null">creater_date,</if>
            <if test="createrCode != null">creater_code,</if>
            <if test="remark != null">remark,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileUrl != null">#{fileUrl},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="devType != null">#{devType},</if>
            <if test="createrDate != null">#{createrDate},</if>
            <if test="createrCode != null">#{createrCode},</if>
            <if test="remark != null">#{remark},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateTSaiFile" parameterType="TSaiFile">
        update t_sai_file
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileName != null">file_name = #{fileName},</if>
            <if test="fileUrl != null">file_url = #{fileUrl},</if>
            <if test="fileType != null">file_type = #{fileType},</if>
            <if test="devType != null">dev_type = #{devType},</if>
            <if test="createrDate != null">creater_date = #{createrDate},</if>
            <if test="createrCode != null">creater_code = #{createrCode},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

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

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