<?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.ruoyi.system.mapper.AppVersionMapper">
    
    <resultMap type="AppVersion" id="AppVersionResult">
        <result property="id"    column="id"    />
        <result property="version"    column="version"    />
        <result property="versionCode"    column="version_code"    />
        <result property="platform"    column="platform"    />
        <result property="downloadUrl"    column="download_url"    />
        <result property="description"    column="description"    />
        <result property="forceUpdate"    column="force_update"    />
        <result property="fileSize"    column="file_size"    />
        <result property="md5"    column="md5"    />
        <result property="minVersion"    column="min_version"    />
        <result property="createdAt"    column="created_at"    />
        <result property="updatedAt"    column="updated_at"    />
        <result property="status"    column="status"    />
    </resultMap>

    <sql id="selectAppVersionVo">
        select id, version, version_code, platform, download_url, description, force_update, file_size, md5, min_version, created_at, updated_at, status from app_version
    </sql>

    <select id="selectAppVersionList" parameterType="AppVersion" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        <where>  
            <if test="version != null  and version != ''"> and version = #{version}</if>
            <if test="versionCode != null "> and version_code = #{versionCode}</if>
            <if test="platform != null  and platform != ''"> and platform = #{platform}</if>
            <if test="downloadUrl != null  and downloadUrl != ''"> and download_url = #{downloadUrl}</if>
            <if test="description != null  and description != ''"> and description = #{description}</if>
            <if test="forceUpdate != null "> and force_update = #{forceUpdate}</if>
            <if test="fileSize != null "> and file_size = #{fileSize}</if>
            <if test="md5 != null  and md5 != ''"> and md5 = #{md5}</if>
            <if test="minVersion != null  and minVersion != ''"> and min_version = #{minVersion}</if>
            <if test="createdAt != null "> and created_at = #{createdAt}</if>
            <if test="updatedAt != null "> and updated_at = #{updatedAt}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>
    
    <select id="selectAppVersionById" parameterType="Long" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        where id = #{id}
    </select>
    <select id="getLatestVersion" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        order by created_at desc limit 1

    </select>

    <insert id="insertAppVersion" parameterType="AppVersion" useGeneratedKeys="true" keyProperty="id">
        insert into app_version
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="version != null and version != ''">version,</if>
            <if test="versionCode != null">version_code,</if>
            <if test="platform != null and platform != ''">platform,</if>
            <if test="downloadUrl != null and downloadUrl != ''">download_url,</if>
            <if test="description != null and description != ''">description,</if>
            <if test="forceUpdate != null">force_update,</if>
            <if test="fileSize != null">file_size,</if>
            <if test="md5 != null">md5,</if>
            <if test="minVersion != null">min_version,</if>
            <if test="createdAt != null">created_at,</if>
            <if test="updatedAt != null">updated_at,</if>
            <if test="status != null">status,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="version != null and version != ''">#{version},</if>
            <if test="versionCode != null">#{versionCode},</if>
            <if test="platform != null and platform != ''">#{platform},</if>
            <if test="downloadUrl != null and downloadUrl != ''">#{downloadUrl},</if>
            <if test="description != null and description != ''">#{description},</if>
            <if test="forceUpdate != null">#{forceUpdate},</if>
            <if test="fileSize != null">#{fileSize},</if>
            <if test="md5 != null">#{md5},</if>
            <if test="minVersion != null">#{minVersion},</if>
            <if test="createdAt != null">#{createdAt},</if>
            <if test="updatedAt != null">#{updatedAt},</if>
            <if test="status != null">#{status},</if>
         </trim>
    </insert>

    <update id="updateAppVersion" parameterType="AppVersion">
        update app_version
        <trim prefix="SET" suffixOverrides=",">
            <if test="version != null and version != ''">version = #{version},</if>
            <if test="versionCode != null">version_code = #{versionCode},</if>
            <if test="platform != null and platform != ''">platform = #{platform},</if>
            <if test="downloadUrl != null and downloadUrl != ''">download_url = #{downloadUrl},</if>
            <if test="description != null and description != ''">description = #{description},</if>
            <if test="forceUpdate != null">force_update = #{forceUpdate},</if>
            <if test="fileSize != null">file_size = #{fileSize},</if>
            <if test="md5 != null">md5 = #{md5},</if>
            <if test="minVersion != null">min_version = #{minVersion},</if>
            <if test="createdAt != null">created_at = #{createdAt},</if>
            <if test="updatedAt != null">updated_at = #{updatedAt},</if>
            <if test="status != null">status = #{status},</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>