<?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="name"    column="name"    />
        <result property="versionName"    column="version_name"    />
        <result property="version"    column="version"    />
        <result property="platform"    column="platform"    />
        <result property="downloadUrl"    column="download_url"    />
        <result property="introduce"    column="introduce"    />
        <result property="renew"    column="renew"    />
    </resultMap>

    <sql id="selectAppVersionVo">
        select id, name, version_name, version, platform, download_url, introduce, renew from app_version
    </sql>

    <select id="selectAppVersionList" parameterType="AppVersion" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        <where>  
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="versionName != null  and versionName != ''"> and version_name like concat('%', #{versionName}, '%')</if>
            <if test="version != null  and version != ''"> and version = #{version}</if>
            <if test="platform != null "> and platform = #{platform}</if>
            <if test="downloadUrl != null  and downloadUrl != ''"> and download_url = #{downloadUrl}</if>
            <if test="introduce != null  and introduce != ''"> and introduce = #{introduce}</if>
            <if test="renew != null "> and renew = #{renew}</if>
        </where>
        order by id desc
    </select>
    
    <select id="selectAppVersionById" parameterType="Long" resultMap="AppVersionResult">
        <include refid="selectAppVersionVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertAppVersion" parameterType="AppVersion">
        insert into app_version
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="versionName != null and versionName != ''">version_name,</if>
            <if test="version != null and version != ''">version,</if>
            <if test="platform != null">platform,</if>
            <if test="downloadUrl != null and downloadUrl != ''">download_url,</if>
            <if test="introduce != null">introduce,</if>
            <if test="renew != null">renew,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="versionName != null and versionName != ''">#{versionName},</if>
            <if test="version != null and version != ''">#{version},</if>
            <if test="platform != null">#{platform},</if>
            <if test="downloadUrl != null and downloadUrl != ''">#{downloadUrl},</if>
            <if test="introduce != null">#{introduce},</if>
            <if test="renew != null">#{renew},</if>
         </trim>
    </insert>

    <update id="updateAppVersion" parameterType="AppVersion">
        update app_version
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="versionName != null and versionName != ''">version_name = #{versionName},</if>
            <if test="version != null and version != ''">version = #{version},</if>
            <if test="platform != null">platform = #{platform},</if>
            <if test="downloadUrl != null and downloadUrl != ''">download_url = #{downloadUrl},</if>
            <if test="introduce != null">introduce = #{introduce},</if>
            <if test="renew != null">renew = #{renew},</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>