<?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.fs.store.mapper.FsAppVersionMapper">
    
    <resultMap type="FsAppVersion" id="FsAppVersionResult">
        <result property="versionId"    column="version_id"    />
        <result property="versionName"    column="version_name"    />
        <result property="versionCode"    column="version_code"    />
        <result property="note"    column="note"    />
        <result property="url"    column="url"    />
        <result property="type"    column="type"    />
        <result property="isForce"    column="is_force"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectFsAppVersionVo">
        select version_id, version_name, version_code, note, url, type, is_force, create_time from fs_app_version
    </sql>

    <select id="selectFsAppVersionList" parameterType="FsAppVersion" resultMap="FsAppVersionResult">
        <include refid="selectFsAppVersionVo"/>
        <where>  
            <if test="versionName != null  and versionName != ''"> and version_name like concat('%', #{versionName}, '%')</if>
            <if test="versionCode != null "> and version_code = #{versionCode}</if>
            <if test="note != null  and note != ''"> and note = #{note}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="isForce != null "> and is_force = #{isForce}</if>
        </where>
        order by version_id desc
    </select>
    
    <select id="selectFsAppVersionById" parameterType="Long" resultMap="FsAppVersionResult">
        <include refid="selectFsAppVersionVo"/>
        where version_id = #{versionId}
    </select>
        
    <insert id="insertFsAppVersion" parameterType="FsAppVersion" useGeneratedKeys="true" keyProperty="versionId">
        insert into fs_app_version
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="versionName != null">version_name,</if>
            <if test="versionCode != null">version_code,</if>
            <if test="note != null">note,</if>
            <if test="url != null">url,</if>
            <if test="type != null">type,</if>
            <if test="isForce != null">is_force,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="versionName != null">#{versionName},</if>
            <if test="versionCode != null">#{versionCode},</if>
            <if test="note != null">#{note},</if>
            <if test="url != null">#{url},</if>
            <if test="type != null">#{type},</if>
            <if test="isForce != null">#{isForce},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateFsAppVersion" parameterType="FsAppVersion">
        update fs_app_version
        <trim prefix="SET" suffixOverrides=",">
            <if test="versionName != null">version_name = #{versionName},</if>
            <if test="versionCode != null">version_code = #{versionCode},</if>
            <if test="note != null">note = #{note},</if>
            <if test="url != null">url = #{url},</if>
            <if test="type != null">type = #{type},</if>
            <if test="isForce != null">is_force = #{isForce},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where version_id = #{versionId}
    </update>

    <delete id="deleteFsAppVersionById" parameterType="Long">
        delete from fs_app_version where version_id = #{versionId}
    </delete>

    <delete id="deleteFsAppVersionByIds" parameterType="String">
        delete from fs_app_version where version_id in 
        <foreach item="versionId" collection="array" open="(" separator="," close=")">
            #{versionId}
        </foreach>
    </delete>
    
</mapper>