<?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.api.dao.mk.ApiStoreTopicMapper">

    <resultMap type="com.kmall.api.entity.mk.StoreTopicVo" id="storeTopicMap">
        <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="topicPrice" column="topic_price"/>
        <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.api.entity.mk.StoreTopicVo">
		select
			`id`,
			`title`,
			`content`,
			`item_pic_url`,
			`subtitle`,
			`prom_type_id`,
			`topic_price`,
			`store_id`,
			`third_merch_sn`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`
		from mall_store_topic
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.api.entity.mk.StoreTopicVo">
		select
		d.`id`,
		d.`title`,
		d.`content`,
		d.`item_pic_url`,
		d.`subtitle`,
		d.`prom_type_id`,
		d.`topic_price`,
		d.`store_id`,
		d.`third_merch_sn`,
		d.`is_valid`,
		d.`note`,
		d.`creater_sn`,
		d.`create_time`,
		d.`moder_sn`,
		d.`mod_time`,
		d.`tstm`
		from mall_store_topic d left join third_merchant_biz t on d.third_merch_sn = t.third_merch_sn
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND title LIKE concat('%',#{name},'%')
		</if>
		<if test="storeId != null and storeId != ''">
			and d.store_id = #{storeId}
		</if>
		<if test="thirdMerchSn != null and thirdMerchSn != ''">
			and d.third_merch_sn = #{thirdMerchSn}
		</if>
		<if test="merchSn != null and merchSn != ''">
			and t.merch_sn = #{merchSn}
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by d.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_store_topic d left join third_merchant_biz t on d.third_merch_sn = t.third_merch_sn
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND title LIKE concat('%',#{name},'%')
		</if>
		<if test="storeId != null and storeId != ''">
			and d.store_id = #{storeId}
		</if>
		<if test="thirdMerchSn != null and thirdMerchSn != ''">
			and d.third_merch_sn = #{thirdMerchSn}
		</if>
		<if test="merchSn != null and merchSn != ''">
			and t.merch_sn = #{merchSn}
		</if>
	</select>
</mapper>