<?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.mk.store.MkStoreCampMinusDao">

    <resultMap type="com.kmall.admin.entity.mk.store.MkStoreCampMinusEntity" id="mkStoreCampMinusMap">
        <result property="campMinusId" column="camp_minus_id"/>
        <result property="campName" column="camp_name"/>
        <result property="thirdMerchSn" column="third_merch_sn"/>
        <result property="storeId" column="store_id"/>
        <result property="storeTopicId" column="store_topic_id"/>
        <result property="campBegTime" column="camp_beg_time"/>
        <result property="campEndTime" column="camp_end_time"/>
        <result property="campMinusType" column="camp_minus_type"/>
        <result property="minusMode" column="minus_mode"/>
        <result property="applyType" column="apply_type"/>
        <result property="advImgUrl" column="adv_img_url"/>
        <result property="advDesc" column="adv_desc"/>
        <result property="isValid" column="is_valid"/>
        <result property="isPast" column="is_past"/>
        <result property="isStoreShow" column="is_store_show"/>
        <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"/>
        <result property="goodsBizType" column="goods_biz_type"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.mk.store.MkStoreCampMinusEntity">
		select
			`camp_minus_id`,
			`camp_name`,
			`third_merch_sn`,
			`store_id`,
			`store_topic_id`,
			`camp_beg_time`,
			`camp_end_time`,
			`camp_minus_type`,
			`minus_mode`,
			`apply_type`,
			`adv_img_url`,
			`adv_desc`,
			`is_valid`,
			`is_past`,
			`is_store_show`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			`goods_biz_type`
		from mk_store_camp_minus
		where camp_minus_id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.mk.store.MkStoreCampMinusEntity">
		SELECT
		s.store_name 'storeName',
		t.submit_order_num 'submitNum',
		t.browse_num 'browseNum',
		t.act_money 'actMoney',
		m.`camp_minus_id`,
		m.`camp_name`,
		m.`third_merch_sn`,
		m.`store_id`,
		m.`store_topic_id`,
		m.`camp_beg_time`,
		m.`camp_end_time`,
		m.`camp_minus_type`,
		m.`minus_mode`,
		m.`apply_type`,
		m.`adv_img_url`,
		m.`adv_desc`,
		m.`is_valid`,
		m.`is_past`,
		m.`is_store_show`,
		m.`note`,
		m.`creater_sn`,
		m.`create_time`,
		m.`moder_sn`,
		m.`mod_time`,
		m.`tstm`,
		m.`goods_biz_type`
		FROM
		mk_store_camp_minus m
		LEFT JOIN mall_store s ON m.store_id = s.id
		LEFT JOIN mk_store_topic_stat t ON t.store_topic_id = m.store_topic_id
		LEFT JOIN third_merchant_biz tb ON s.third_party_merch_code = tb.third_party_merch_code
		WHERE 1=1
		<if test="campName != null and campName.trim() != ''">
			AND m.camp_name LIKE concat('%',#{campName},'%')
		</if>
		<if test="isPast != null and isPast != ''">
			AND m.is_past = #{isPast}
		</if>
		<if test="storeId != null and storeId != ''">
			AND t.store_id = #{storeId}
		</if>
		<if test="thirdMerchSn != null and thirdMerchSn != ''">
			AND s.third_merch_sn = #{thirdMerchSn}
		</if>
		<if test="thirdPartyMerchCode != null and thirdPartyMerchCode != ''">
			AND tb.third_party_merch_code = #{thirdPartyMerchCode}
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by camp_minus_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		SELECT count(*)
		FROM
		mk_store_camp_minus m
		LEFT JOIN mall_store s ON m.store_id = s.id
		LEFT JOIN mk_store_topic_stat t ON t.store_topic_id = m.store_topic_id
		LEFT JOIN third_merchant_biz tb ON s.third_party_merch_code = tb.third_party_merch_code
		WHERE 1=1
		<if test="campName != null and campName.trim() != ''">
			AND m.camp_name LIKE concat('%',#{campName},'%')
		</if>
		<if test="isPast != null and isPast != ''">
			AND m.is_past = #{isPast}
		</if>
		<if test="storeId != null and storeId != ''">
			AND t.store_id = #{storeId}
		</if>
		<if test="thirdMerchSn != null and thirdMerchSn != ''">
			AND s.third_merch_sn = #{thirdMerchSn}
		</if>
		<if test="thirdPartyMerchCode != null and thirdPartyMerchCode != ''">
			AND tb.third_party_merch_code = #{thirdPartyMerchCode}
		</if>
	</select>
	 
	<insert id="save" parameterType="com.kmall.admin.entity.mk.store.MkStoreCampMinusEntity" useGeneratedKeys="true" keyProperty="campMinusId">
		insert into mk_store_camp_minus(
			`camp_name`,
			`third_merch_sn`,
			`store_id`,
			`store_topic_id`,
			`camp_beg_time`,
			`camp_end_time`,
			`camp_minus_type`,
			`minus_mode`,
			`apply_type`,
			`adv_img_url`,
			`adv_desc`,
			`is_valid`,
			`is_past`,
			`is_store_show`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			`goods_biz_type`)
		values(
			#{campName},
			#{thirdMerchSn},
			#{storeId},
			#{storeTopicId},
			#{campBegTime},
			#{campEndTime},
			#{campMinusType},
			#{minusMode},
			#{applyType},
			#{advImgUrl},
			#{advDesc},
			#{isValid},
			#{isPast},
			#{isStoreShow},
			#{note},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm},
			#{goodsBizType})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.mk.store.MkStoreCampMinusEntity">
		update mk_store_camp_minus 
		<set>
			<if test="campName != null">`camp_name` = #{campName}, </if>
			<if test="thirdMerchSn != null">`third_merch_sn` = #{thirdMerchSn}, </if>
			<if test="storeId != null">`store_id` = #{storeId}, </if>
			<if test="storeTopicId != null">`store_topic_id` = #{storeTopicId}, </if>
			<if test="campBegTime != null">`camp_beg_time` = #{campBegTime}, </if>
			<if test="campEndTime != null">`camp_end_time` = #{campEndTime}, </if>
			<if test="campMinusType != null">`camp_minus_type` = #{campMinusType}, </if>
			<if test="minusMode != null">`minus_mode` = #{minusMode}, </if>
			<if test="applyType != null">`apply_type` = #{applyType}, </if>
			<if test="advImgUrl != null">`adv_img_url` = #{advImgUrl}, </if>
			<if test="advDesc != null">`adv_desc` = #{advDesc}, </if>
			<if test="isValid != null">`is_valid` = #{isValid}, </if>
			<if test="isPast != null">`is_past` = #{isPast}, </if>
			<if test="isStoreShow != null">`is_store_show` = #{isStoreShow}, </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>
			<if test="goodsBizType != null">`goods_biz_type` = #{goodsBizType}</if>
		</set>
		where camp_minus_id = #{campMinusId}
	</update>
	
	<delete id="delete">
		delete from mk_store_camp_minus where camp_minus_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mk_store_camp_minus where camp_minus_id in 
		<foreach item="campMinusId" collection="array" open="(" separator="," close=")">
			#{campMinusId}
		</foreach>
	</delete>

</mapper>