<?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.zbf.system.mapper.AppVersionsMapper">

    <resultMap type="AppVersions" id="AppVersionsResult">
        <result property="id"    column="id"    />
        <result property="version"    column="version"    />
        <result property="downloadUrl"    column="download_url"    />
        <result property="changelog"    column="changelog"    />
        <result property="releaseDate"    column="release_date"    />
        <result property="hversion"    column="hversion"    />
    </resultMap>

    <sql id="selectAppVersionsVo">
        select id, version, download_url, changelog, release_date, hversion from app_versions
    </sql>

    <select id="selectAppVersionsList" parameterType="AppVersions" resultMap="AppVersionsResult">
        <include refid="selectAppVersionsVo"/>
        <where>
            <if test="version != null  and version != ''"> and version = #{version}</if>
            <if test="downloadUrl != null  and downloadUrl != ''"> and download_url = #{downloadUrl}</if>
            <if test="changelog != null  and changelog != ''"> and changelog = #{changelog}</if>
            <if test="releaseDate != null "> and release_date = #{releaseDate}</if>
            <if test="hversion != null  and hversion != ''"> and hversion = #{hversion}</if>
        </where>
    </select>

    <select id="selectAppVersionsById" parameterType="Long" resultMap="AppVersionsResult">
        <include refid="selectAppVersionsVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppVersions" parameterType="AppVersions" useGeneratedKeys="true" keyProperty="id">
        insert into app_versions
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="version != null">version,</if>
            <if test="downloadUrl != null">download_url,</if>
            <if test="changelog != null and changelog != ''">changelog,</if>
            <if test="releaseDate != null">release_date,</if>
            <if test="hversion != null">hversion,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="version != null">#{version},</if>
            <if test="downloadUrl != null">#{downloadUrl},</if>
            <if test="changelog != null and changelog != ''">#{changelog},</if>
            <if test="releaseDate != null">#{releaseDate},</if>
            <if test="hversion != null">#{hversion},</if>
        </trim>
    </insert>

    <update id="updateAppVersions" parameterType="AppVersions">
        update app_versions
        <trim prefix="SET" suffixOverrides=",">
            <if test="version != null">version = #{version},</if>
            <if test="downloadUrl != null">download_url = #{downloadUrl},</if>
            <if test="changelog != null and changelog != ''">changelog = #{changelog},</if>
            <if test="releaseDate != null">release_date = #{releaseDate},</if>
            <if test="hversion != null">hversion = #{hversion},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableAppVersionsByIds" parameterType="String">
        update app_versions set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledAppVersionsByIds" parameterType="String">
        update app_versions set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteAppVersionsById" parameterType="Long">
        delete from app_versions  where id = #{id}
    </delete>

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