<?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.xinelu.manage.mapper.appfileinfo.AppFileInfoMapper">

    <resultMap type="AppFileInfo" id="AppFileInfoResult">
        <result property="id" column="id"/>
        <result property="fileName" column="file_name"/>
        <result property="fileUrl" column="file_url"/>
        <result property="fileLocalPath" column="file_local_path"/>
        <result property="fileVersion" column="file_version"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectAppFileInfoVo">
        select id,
               file_name,
               file_url,
               file_local_path,
               file_version,
               create_by,
               create_time,
               update_by,
               update_time
        from app_file_info
    </sql>

    <select id="selectAppFileInfoList" parameterType="AppFileInfo" resultMap="AppFileInfoResult">
        <include refid="selectAppFileInfoVo"/>
        <where>
            <if test="fileName != null  and fileName != ''">
                and file_name like concat('%', #{fileName}, '%')
            </if>
            <if test="fileUrl != null  and fileUrl != ''">
                and file_url = #{fileUrl}
            </if>
            <if test="fileVersion != null  and fileVersion != ''">
                and file_version = #{fileVersion}
            </if>
        </where>
    </select>

    <select id="selectAppFileInfoById" parameterType="Long"
            resultMap="AppFileInfoResult">
        <include refid="selectAppFileInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppFileInfo" parameterType="AppFileInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into app_file_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fileName != null">file_name,
            </if>
            <if test="fileUrl != null">file_url,
            </if>
            <if test="fileLocalPath != null">file_local_path,
            </if>
            <if test="fileVersion != null">file_version,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fileName != null">#{fileName},
            </if>
            <if test="fileUrl != null">#{fileUrl},
            </if>
            <if test="fileLocalPath != null">#{fileLocalPath},
            </if>
            <if test="fileVersion != null">#{fileVersion},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateAppFileInfo" parameterType="AppFileInfo">
        update app_file_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="fileName != null">file_name =
                #{fileName},
            </if>
            <if test="fileUrl != null">file_url =
                #{fileUrl},
            </if>
            <if test="fileLocalPath != null">file_local_path =
                #{fileLocalPath},
            </if>
            <if test="fileVersion != null">file_version =
                #{fileVersion},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppFileInfoById" parameterType="Long">
        delete
        from app_file_info
        where id = #{id}
    </delete>

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

    <select id="getAppFileInfoByOneId" parameterType="AppFileInfo" resultType="AppFileInfo">
        select id,
               file_name,
               file_url,
               file_local_path,
               file_version,
               create_by,
               create_time,
               update_by,
               update_time
        from app_file_info
        ORDER BY id DESC LIMIT 1
    </select>
</mapper>
