<?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.goldenwater.slgc.mapper.DocFileMapper">

    <resultMap type="DocFile" id="DocFileResult">
        <result property="fileId" column="FILE_ID"/>
        <result property="aid" column="AID"/>
        <result property="fileType" column="FILE_TYPE"/>
        <result property="fileName" column="FILE_NAME"/>
        <result property="fileSize" column="FILE_SIZE"/>
        <result property="filePath" column="FILE_PATH"/>
        <result property="fileCate" column="FILE_CATE"/>
        <result property="fileDesc" column="FILE_DESC"/>
        <result property="fileTime" column="FILE_TIME"/>
        <result property="downTimes" column="DOWN_TIMES"/>
    </resultMap>

    <sql id="selectDocFileVo">
        select FILE_ID, AID, FILE_TYPE, FILE_NAME, FILE_SIZE, FILE_PATH, FILE_CATE,
               FILE_DESC, FILE_TIME, DOWN_TIMES
        from BIZ_DOC_FILE
    </sql>

    <select id="selectDocFileList" parameterType="DocFile" resultMap="DocFileResult">
        <include refid="selectDocFileVo"/>
        <where>
            <if test="fileName != null and fileName != ''">
                and FILE_NAME like concat('%', #{fileName}, '%')
            </if>
            <if test="fileCate != null and fileCate != ''">
                and FILE_CATE = #{fileCate}
            </if>
            <if test="fileType != null and fileType != ''">
                and FILE_TYPE = #{fileType}
            </if>
            <if test="aid != null and aid != ''">
                and AID = #{aid}
            </if>
        </where>
        order by FILE_TIME desc
    </select>

    <select id="selectDocFileById" parameterType="String" resultMap="DocFileResult">
        <include refid="selectDocFileVo"/>
        where FILE_ID = #{fileId}
    </select>

    <delete id="deleteDocFileById" parameterType="String">
        delete from BIZ_DOC_FILE where FILE_ID = #{fileId}
    </delete>

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

    <insert id="insertDocFile" parameterType="DocFile">
        insert into BIZ_DOC_FILE
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileId != null">FILE_ID,</if>
            <if test="aid != null">AID,</if>
            <if test="fileType != null">FILE_TYPE,</if>
            <if test="fileName != null">FILE_NAME,</if>
            <if test="fileSize != null">FILE_SIZE,</if>
            <if test="filePath != null">FILE_PATH,</if>
            <if test="fileCate != null">FILE_CATE,</if>
            <if test="fileDesc != null">FILE_DESC,</if>
            <if test="fileTime != null">FILE_TIME,</if>
            <if test="downTimes != null">DOWN_TIMES,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileId != null">#{fileId},</if>
            <if test="aid != null">#{aid},</if>
            <if test="fileType != null">#{fileType},</if>
            <if test="fileName != null">#{fileName},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="filePath != null">#{filePath},</if>
            <if test="fileCate != null">#{fileCate},</if>
            <if test="fileDesc != null">#{fileDesc},</if>
            <if test="fileTime != null">#{fileTime},</if>
            <if test="downTimes != null">#{downTimes},</if>
        </trim>
    </insert>

    <update id="updateDocFile" parameterType="DocFile">
        update BIZ_DOC_FILE
        <trim prefix="SET" suffixOverrides=",">
            <if test="aid != null">AID = #{aid},</if>
            <if test="fileType != null">FILE_TYPE = #{fileType},</if>
            <if test="fileName != null">FILE_NAME = #{fileName},</if>
            <if test="fileSize != null">FILE_SIZE = #{fileSize},</if>
            <if test="filePath != null">FILE_PATH = #{filePath},</if>
            <if test="fileCate != null">FILE_CATE = #{fileCate},</if>
            <if test="fileDesc != null">FILE_DESC = #{fileDesc},</if>
            <if test="fileTime != null">FILE_TIME = #{fileTime},</if>
            <if test="downTimes != null">DOWN_TIMES = #{downTimes},</if>
        </trim>
        where FILE_ID = #{fileId}
    </update>

    <update id="moveDocFile" parameterType="DocFile">
        update BIZ_DOC_FILE set FILE_CATE = #{fileCate}
        where FILE_ID in
        <foreach item="fileId" collection="fileIds" open="(" separator="," close=")">
            #{fileId}
        </foreach>
    </update>

    <update id="renameDocFile" parameterType="DocFile">
        update BIZ_DOC_FILE set FILE_NAME = #{fileName}
        where FILE_ID = #{fileId}
    </update>

</mapper>
