<?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.pnkx.system.mapper.SysAppMapper">

    <resultMap type="SysAppUpdateLog" id="SysAppUpdateLogResult">
        <result property="id" column="id"/>
        <result property="name" column="name"/>
        <result property="content" column="content"/>
        <result property="richText" column="rich_text"/>
        <result property="delFlag" column="del_flag"/>
        <result property="downloadUrl" column="download_url"/>
        <result property="version" column="version"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectSysAppUpdateLogVo">
        select id,
               name,
               content,
               rich_text,
               download_url,
               del_flag,
               version,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from app_update_log
    </sql>

    <!--获取最新版app信息-->
    <select id="getNewestAppInfo" resultType="com.pnkx.system.domain.SysAppUpdateLog">
        SELECT *,
               download_url downloadUrl
        FROM app_update_log
        order by version DESC limit 1
    </select>

    <select id="selectAppUpdateLogList" parameterType="SysAppUpdateLog" resultMap="SysAppUpdateLogResult">
        <include refid="selectSysAppUpdateLogVo"/>
        <where>
            del_flag = 0
            <if test="content != null  and content != ''">and content = #{content}</if>
            <if test="version != null  and version != ''">and version = #{version}</if>
        </where>
        order by version desc
    </select>

    <select id="selectAppUpdateLogById" parameterType="Long" resultMap="SysAppUpdateLogResult">
        <include refid="selectSysAppUpdateLogVo"/>
        where id = #{id} and del_flag = 0
    </select>

    <insert id="insertAppUpdateLog" parameterType="SysAppUpdateLog" useGeneratedKeys="true" keyProperty="id">
        insert into app_update_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">name,</if>
            <if test="content != null">content,</if>
            <if test="richText != null">rich_text,</if>
            <if test="downloadUrl != null">download_url,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="version != null">version,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="content != null">#{content},</if>
            <if test="richText != null">#{richText},</if>
            <if test="downloadUrl != null">#{downloadUrl},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="version != null">#{version},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateAppUpdateLog" parameterType="SysAppUpdateLog">
        update app_update_log
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">name = #{name},</if>
            <if test="content != null">content = #{content},</if>
            <if test="richText != null">rich_text = #{richText},</if>
            <if test="downloadUrl != null">download_url = #{downloadUrl},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="version != null">version = #{version},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteAppUpdateLogById" parameterType="Long">
        update app_update_log
        set del_flag = 1
        where id = #{id}
    </delete>

    <delete id="deleteAppUpdateLogByIds" parameterType="String">
        update app_update_log set del_flag = 1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
