<?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.CmsArticleFileMapper">

    <resultMap type="CmsArticleFile" id="CmsArticleFileResult">
        <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="fileDesc" column="FILE_DESC"/>
        <result property="downTimes" column="DOWN_TIMES"/>
    </resultMap>

    <sql id="selectCmsArticleFileVo">
        select FILE_ID, AID, FILE_TYPE, FILE_NAME, FILE_SIZE, FILE_PATH, FILE_DESC, DOWN_TIMES
        from BIZ_CMS_ARTICLE_FILE
    </sql>

    <select id="selectCmsArticleFileList" parameterType="CmsArticleFile" resultMap="CmsArticleFileResult">
        <include refid="selectCmsArticleFileVo"/>
        <where>
            <if test="aid != null and aid != ''">
                and AID = #{aid}
            </if>
            <if test="fileType != null and fileType != ''">
                and FILE_TYPE = #{fileType}
            </if>
        </where>
        order by FILE_ID
    </select>

    <select id="selectCmsArticleFileById" parameterType="String" resultMap="CmsArticleFileResult">
        <include refid="selectCmsArticleFileVo"/>
        where FILE_ID = #{fileId}
    </select>

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

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

    <delete id="deleteByAid" parameterType="String">
        delete from BIZ_CMS_ARTICLE_FILE where AID = #{aid}
    </delete>

    <insert id="insertCmsArticleFile" parameterType="CmsArticleFile">
        insert into BIZ_CMS_ARTICLE_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="fileDesc != null">FILE_DESC,</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="fileDesc != null">#{fileDesc},</if>
            <if test="downTimes != null">#{downTimes},</if>
        </trim>
    </insert>

    <update id="updateCmsArticleFile" parameterType="CmsArticleFile">
        update BIZ_CMS_ARTICLE_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="fileDesc != null">FILE_DESC = #{fileDesc},</if>
            <if test="downTimes != null">DOWN_TIMES = #{downTimes},</if>
        </trim>
        where FILE_ID = #{fileId}
    </update>

</mapper>
