<?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.bonus.zlpt.home.mapper.BmTopicInfoMapper">

    <sql id="selectBmTopicVo">
        select id, topic_name, type, view_num, content, is_active, creator, create_time
        from bm_topic_info
    </sql>

    <insert id="insertConfig">
        insert into bm_topic_info (
        <if test="topicName != null and topicName != '' ">topic_name,</if>
        <if test="type != null and type != '' ">type,</if>
        <if test="viewNum != null and viewNum != '' ">view_num,</if>
        <if test="content != null and content != '' ">content,</if>
        <if test="creator != null and creator != ''">creator,</if>
        create_time
        )values(
        <if test="topicName != null and topicName != ''">#{topicName},</if>
        <if test="type != null and type != ''">#{type},</if>
        <if test="viewNum != null and viewNum != ''">#{openUrl},</if>
        <if test="content != null and content != ''">#{content},</if>
        <if test="creator != null and creator != ''">#{creator},</if>
        sysdate()
        )
    </insert>

    <update id="update">
        update bm_topic_info
        <set>
            <if test="id != null and id != ''">id = #{id},</if>
            <if test="topicName != null and topicName != ''">topic_name = #{topicName},</if>
            <if test="type != null and type != ''">type = #{type},</if>
            <if test="viewNum != null and viewNum != ''">view_num = #{viewNum},</if>
            <if test="content != null and content != ''">content = #{content},</if>
        </set>
    </update>

    <delete id="deleteById">
        update bm_topic_info set is_active = '0' where id = #{id}
    </delete>

    <select id="selectListById" resultType="java.lang.Integer">
        <include refid="selectBmTopicVo"/>
        where id = #{id}
    </select>

    <select id="selectSpecialInfoList" resultType="com.bonus.zlpt.home.pojo.BmTopicInfo">
        <include refid="selectBmTopicVo"/>
        <where>
            <if test="topicName != null and topicName != ''">
                AND topic_name like concat('%', #{topicName}, '%')
            </if>
            <if test="beginTime != null and beginTime != '' and endTime != null and endTime != ''">
                and date_format( create_time, '%Y-%m-%d' )
                BETWEEN date_format( #{beginTime}, '%Y-%m-%d' )
                and date_format( #{endTime}, '%Y-%m-%d' )
            </if>
        </where>
    </select>
</mapper>