<?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.kmall.admin.dao.TopicDao">

    <resultMap type="com.kmall.admin.entity.TopicEntity" id="topicMap">
        <result property="id" column="id"/>
        <result property="title" column="title"/>
        <result property="content" column="content"/>
        <result property="itemPicUrl" column="item_pic_url"/>
        <result property="subtitle" column="subtitle"/>
        <result property="promTypeId" column="prom_type_id"/>
        <result property="priceInfo" column="price_info"/>
        <result property="readCount" column="read_count"/>
        <result property="scenePicUrl" column="scene_pic_url"/>
        <result property="topicTemplateId" column="topic_template_id"/>
        <result property="topicTagId" column="topic_tag_id"/>
        <result property="storeId" column="store_id"/>
        <result property="thirdMerchSn" column="third_merch_sn"/>
        <result property="isValid" column="is_valid"/>
        <result property="note" column="note"/>
        <result property="createrSn" column="creater_sn"/>
        <result property="createTime" column="create_time"/>
        <result property="moderSn" column="moder_sn"/>
        <result property="modTime" column="mod_time"/>
        <result property="tstm" column="tstm"/>
    </resultMap>

    <select id="queryObject" resultType="com.kmall.admin.entity.TopicEntity">
        select
        `id`,
        `title`,
        `content`,
        `item_pic_url`,
        `subtitle`,
        `prom_type_id`,
        `price_info`,
        `read_count`,
        `scene_pic_url`,
        `topic_template_id`,
        `topic_tag_id`,
        `store_id`,
        `third_merch_sn`,
        `is_valid`,
        `note`,
        `creater_sn`,
        `create_time`,
        `moder_sn`,
        `mod_time`,
        `tstm`
        from mall_topic
        where id = #{id}
    </select>

    <select id="queryList" resultType="com.kmall.admin.entity.TopicEntity">
        select
        `id`,
        `title`,
        `content`,
        `item_pic_url`,
        `subtitle`,
        `prom_type_id`,
        `price_info`,
        `read_count`,
        `scene_pic_url`,
        `topic_template_id`,
        `topic_tag_id`,
        `store_id`,
        `third_merch_sn`,
        `is_valid`,
        `note`,
        `creater_sn`,
        `create_time`,
        `moder_sn`,
        `mod_time`,
        `tstm`
        from mall_topic
        WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
            <otherwise>
                order by id desc
            </otherwise>
        </choose>
        <if test="offset != null and limit != null">
            limit #{offset}, #{limit}
        </if>
    </select>

    <select id="queryTotal" resultType="int">
        select count(*) from mall_topic
        WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
    </select>

    <insert id="save" parameterType="com.kmall.admin.entity.TopicEntity" useGeneratedKeys="true" keyProperty="id">
        insert into mall_topic(
        `title`,
        `content`,
        `item_pic_url`,
        `subtitle`,
        `prom_type_id`,
        `price_info`,
        `read_count`,
        `scene_pic_url`,
        `topic_template_id`,
        `topic_tag_id`,
        `store_id`,
        `third_merch_sn`,
        `is_valid`,
        `note`,
        `creater_sn`,
        `create_time`,
        `moder_sn`,
        `mod_time`,
        `tstm`)
        values(
        #{title},
        #{content},
        #{itemPicUrl},
        #{subtitle},
        #{promTypeId},
        #{priceInfo},
        #{readCount},
        #{scenePicUrl},
        #{topicTemplateId},
        #{topicTagId},
        #{storeId},
        #{thirdMerchSn},
        #{isValid},
        #{note},
        #{createrSn},
        #{createTime},
        #{moderSn},
        #{modTime},
        #{tstm})
    </insert>

    <update id="update" parameterType="com.kmall.admin.entity.TopicEntity">
        update mall_topic
        <set>
            <if test="title != null">`title` = #{title}, </if>
            <if test="content != null">`content` = #{content}, </if>
            <if test="itemPicUrl != null">`item_pic_url` = #{itemPicUrl}, </if>
            <if test="subtitle != null">`subtitle` = #{subtitle}, </if>
            <if test="promTypeId != null">`prom_type_id` = #{promTypeId}, </if>
            <if test="priceInfo != null">`price_info` = #{priceInfo}, </if>
            <if test="readCount != null">`read_count` = #{readCount}, </if>
            <if test="scenePicUrl != null">`scene_pic_url` = #{scenePicUrl}, </if>
            <if test="topicTemplateId != null">`topic_template_id` = #{topicTemplateId}, </if>
            <if test="topicTagId != null">`topic_tag_id` = #{topicTagId}, </if>
            <if test="storeId != null">`store_id` = #{storeId}, </if>
            <if test="thirdMerchSn != null">`third_merch_sn` = #{thirdMerchSn}, </if>
            <if test="isValid != null">`is_valid` = #{isValid}, </if>
            <if test="note != null">`note` = #{note}, </if>
            <if test="createrSn != null">`creater_sn` = #{createrSn}, </if>
            <if test="createTime != null">`create_time` = #{createTime}, </if>
            <if test="moderSn != null">`moder_sn` = #{moderSn}, </if>
            <if test="modTime != null">`mod_time` = #{modTime}, </if>
            <if test="tstm != null">`tstm` = #{tstm}</if>
        </set>
        where id = #{id}
    </update>

    <delete id="delete">
        delete from mall_topic where id = #{value}
    </delete>

    <delete id="deleteBatch">
        delete from mall_topic where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>