<?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.SysRealtimeNewsMapper">

    <resultMap type="SysRealtimeNews" id="SysRealtimeNewsResult">
        <result property="id"    column="id"    />
        <result property="title"    column="title"    />
        <result property="summary"    column="summary"    />
        <result property="coverImage"    column="cover_image"    />
        <result property="publishTime"    column="publish_time"    />
        <result property="contentCn"    column="content_cn"    />
        <result property="contentEn"    column="content_en"    />
        <result property="isTop"    column="is_top"    />
        <result property="status"    column="status"    />
        <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="selectSysRealtimeNewsVo">
        select id, title, summary, cover_image, publish_time, content_cn, content_en, is_top, status, create_by, create_time, update_by, update_time, remark from sys_realtime_news
    </sql>

    <select id="selectSysRealtimeNewsList" parameterType="SysRealtimeNews" resultMap="SysRealtimeNewsResult">
        <include refid="selectSysRealtimeNewsVo"/>
        <where>
            <if test="title != null  and title != ''"> and title like concat('%', #{title}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="params.beginTime != null and params.beginTime != ''">
                and date_format(publish_time,'%y%m%d') &gt;= date_format(#{params.beginTime},'%y%m%d')
            </if>
            <if test="params.endTime != null and params.endTime != ''">
                and date_format(publish_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
            </if>
        </where>
        order by is_top desc, publish_time desc
    </select>

    <select id="selectSysRealtimeNewsById" parameterType="Long" resultMap="SysRealtimeNewsResult">
        <include refid="selectSysRealtimeNewsVo"/>
        where id = #{id}
    </select>

    <insert id="insertSysRealtimeNews" parameterType="SysRealtimeNews" useGeneratedKeys="true" keyProperty="id">
        insert into sys_realtime_news
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="title != null and title != ''">title,</if>
            <if test="summary != null">summary,</if>
            <if test="coverImage != null">cover_image,</if>
            <if test="publishTime != null">publish_time,</if>
            <if test="contentCn != null">content_cn,</if>
            <if test="contentEn != null">content_en,</if>
            <if test="isTop != null">is_top,</if>
            <if test="status != null">status,</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="title != null and title != ''">#{title},</if>
            <if test="summary != null">#{summary},</if>
            <if test="coverImage != null">#{coverImage},</if>
            <if test="publishTime != null">#{publishTime},</if>
            <if test="contentCn != null">#{contentCn},</if>
            <if test="contentEn != null">#{contentEn},</if>
            <if test="isTop != null">#{isTop},</if>
            <if test="status != null">#{status},</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="updateSysRealtimeNews" parameterType="SysRealtimeNews">
        update sys_realtime_news
        <trim prefix="SET" suffixOverrides=",">
            <if test="title != null and title != ''">title = #{title},</if>
            <if test="summary != null">summary = #{summary},</if>
            <if test="coverImage != null">cover_image = #{coverImage},</if>
            <if test="publishTime != null">publish_time = #{publishTime},</if>
            <if test="contentCn != null">content_cn = #{contentCn},</if>
            <if test="contentEn != null">content_en = #{contentEn},</if>
            <if test="isTop != null">is_top = #{isTop},</if>
            <if test="status != null">status = #{status},</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>

    <update id="updateTopStatus">
        update sys_realtime_news set is_top = #{isTop} where id = #{id}
    </update>

    <delete id="deleteSysRealtimeNewsById" parameterType="Long">
        delete from sys_realtime_news where id = #{id}
    </delete>

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

</mapper>
