<?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.zhyc.module.app.mapper.AppVersionMapper">
    
    <resultMap type="AppVersion" id="AppVersionResult">
        <result property="id"    column="id"    />
        <result property="platform"    column="platform"    />
        <result property="versionCode"    column="version_code"    />
        <result property="versionName"    column="version_name"    />
        <result property="isForceUpdate"    column="is_force_update"    />
        <result property="isLatest"    column="is_latest"    />
        <result property="minVersionCode"    column="min_version_code"    />
        <result property="downloadUrl"    column="download_url"    />
        <result property="updateTitle"    column="update_title"    />
        <result property="updateContent"    column="update_content"    />
        <result property="fileSize"    column="file_size"    />
        <result property="md5Hash"    column="md5_hash"    />
        <result property="publishTime"    column="publish_time"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="isDeleted"    column="is_deleted"    />
    </resultMap>

    <sql id="selectAppVersionVo">
        select id, platform, version_code, version_name, is_force_update, is_latest, min_version_code, download_url, update_title, update_content, file_size, md5_hash, publish_time, create_time, update_time, is_deleted from app_version
    </sql>

    <select id="selectAppVersionList" parameterType="AppVersion" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        <where>  
            <if test="id != null "> and id = #{id}</if>
            <if test="platform != null  and platform != ''"> and platform = #{platform}</if>
            <if test="versionCode != null "> and version_code = #{versionCode}</if>
            <if test="versionName != null  and versionName != ''"> and version_name like concat('%', #{versionName}, '%')</if>
            <if test="isForceUpdate != null "> and is_force_update = #{isForceUpdate}</if>
            <if test="isLatest != null "> and is_latest = #{isLatest}</if>
            <if test="minVersionCode != null "> and min_version_code = #{minVersionCode}</if>
            <if test="downloadUrl != null  and downloadUrl != ''"> and download_url = #{downloadUrl}</if>
            <if test="updateTitle != null  and updateTitle != ''"> and update_title = #{updateTitle}</if>
            <if test="updateContent != null  and updateContent != ''"> and update_content = #{updateContent}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="params.beginMd5Hash != null and params.beginMd5Hash != '' and params.endMd5Hash != null and params.endMd5Hash != ''"> and md5_hash between #{params.beginMd5Hash} and #{params.endMd5Hash}</if>
            <if test="params.beginPublishTime != null and params.beginPublishTime != '' and params.endPublishTime != null and params.endPublishTime != ''"> and publish_time between #{params.beginPublishTime} and #{params.endPublishTime}</if>
            <if test="isDeleted != null "> and is_deleted = #{isDeleted}</if>
        </where>
    </select>
    
    <select id="selectAppVersionById" parameterType="Long" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppVersion" parameterType="AppVersion" useGeneratedKeys="true" keyProperty="id">
        insert into app_version
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="platform != null">platform,</if>
            <if test="versionCode != null">version_code,</if>
            <if test="versionName != null">version_name,</if>
            <if test="isForceUpdate != null">is_force_update,</if>
            <if test="isLatest != null">is_latest,</if>
            <if test="minVersionCode != null">min_version_code,</if>
            <if test="downloadUrl != null">download_url,</if>
            <if test="updateTitle != null">update_title,</if>
            <if test="updateContent != null">update_content,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="md5Hash != null">md5_hash,</if>
            <if test="publishTime != null">publish_time,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="isDeleted != null">is_deleted,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="platform != null">#{platform},</if>
            <if test="versionCode != null">#{versionCode},</if>
            <if test="versionName != null">#{versionName},</if>
            <if test="isForceUpdate != null">#{isForceUpdate},</if>
            <if test="isLatest != null">#{isLatest},</if>
            <if test="minVersionCode != null">#{minVersionCode},</if>
            <if test="downloadUrl != null">#{downloadUrl},</if>
            <if test="updateTitle != null">#{updateTitle},</if>
            <if test="updateContent != null">#{updateContent},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="md5Hash != null">#{md5Hash},</if>
            <if test="publishTime != null">#{publishTime},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="isDeleted != null">#{isDeleted},</if>
         </trim>
    </insert>

    <update id="updateAppVersion" parameterType="AppVersion">
        update app_version
        <trim prefix="SET" suffixOverrides=",">
            <if test="platform != null">platform = #{platform},</if>
            <if test="versionCode != null">version_code = #{versionCode},</if>
            <if test="versionName != null">version_name = #{versionName},</if>
            <if test="isForceUpdate != null">is_force_update = #{isForceUpdate},</if>
            <if test="isLatest != null">is_latest = #{isLatest},</if>
            <if test="minVersionCode != null">min_version_code = #{minVersionCode},</if>
            <if test="downloadUrl != null">download_url = #{downloadUrl},</if>
            <if test="updateTitle != null">update_title = #{updateTitle},</if>
            <if test="updateContent != null">update_content = #{updateContent},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="md5Hash != null">md5_hash = #{md5Hash},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="isDeleted != null">is_deleted = #{isDeleted},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppVersionById" parameterType="Long">
        delete from app_version where id = #{id}
    </delete>

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