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

    <resultMap type="com.kmall.admin.entity.mk.store.MkStoreTicketDiscountEntity" id="mkStoreTicketDiscountMap">
        <result property="tickDiscId" column="tick_disc_id"/>
        <result property="tickDiscType" column="tick_disc_type"/>
        <result property="tickDiscSubTitle" column="tick_disc_sub_title"/>
        <result property="merchSn" column="merch_sn"/>
        <result property="thirdMerchSn" column="third_merch_sn"/>
        <result property="storeId" column="store_id"/>
        <result property="storeTopicId" column="store_topic_id"/>
        <result property="name" column="name"/>
        <result property="voucherMoney" column="voucher_money"/>
        <result property="voucherCond" column="voucher_cond"/>
        <result property="discRatio" column="disc_ratio"/>
        <result property="discCond" column="disc_cond"/>
        <result property="exchCond" column="exch_cond"/>
        <result property="effectTimeType" column="effect_time_type"/>
        <result property="fixBegTime" column="fix_beg_time"/>
        <result property="fixEndTime" column="fix_end_time"/>
        <result property="postponeNum" column="postpone_num"/>
        <result property="validDayNum" column="valid_day_num"/>
        <result property="ticketNum" column="ticket_num"/>
        <result property="applyType" column="apply_type"/>
        <result property="getEnter" column="get_enter"/>
        <result property="canShareGet" column="can_share_get"/>
        <result property="limitNum" column="limit_num"/>
        <result property="advImgUrl" column="adv_img_url"/>
        <result property="storeLogoUrl" column="store_logo_url"/>
        <result property="storeName" column="store_name"/>
        <result property="ticketColor" column="ticket_color"/>
        <result property="optDecl" column="opt_decl"/>
        <result property="discDecl" column="disc_decl"/>
        <result property="useNoti" column="use_noti"/>
        <result property="svrTel" column="svr_tel"/>
        <result property="isValid" column="is_valid"/>
		<result property="isPast" column="is_past"/>
        <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="sendType" column="send_type"/>
		<result property="discSellCount" column="disc_sell_count"/>
		<result property="discSellDoller" column="disc_sell_doller"/>
		<result property="guid" column="guid"/>
		<result property="goodsBizType" column="goods_biz_type"/>
		<result property="isStoreShow" column="is_store_show"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.admin.entity.mk.store.MkStoreTicketDiscountEntity">
		select
			`tick_disc_id`,
			`tick_disc_type`,
			`tick_disc_sub_title`,
			`merch_sn`,
			`third_merch_sn`,
			`store_id`,goods_biz_type,is_store_show,
			`store_topic_id`,
			`name`,
			`voucher_money`,
			`voucher_cond`,
			`disc_ratio`,
			`disc_cond`,
			`exch_cond`,
			`effect_time_type`,
			`fix_beg_time`,
			`fix_end_time`,
			`postpone_num`,
			`valid_day_num`,
			`ticket_num`,
			`apply_type`,
			`get_enter`,
			`can_share_get`,
			`limit_num`,
			`adv_img_url`,
			`store_logo_url`,
			`store_name`,
			`ticket_color`,
			`opt_decl`,
			`disc_decl`,
			`use_noti`,
			`svr_tel`,
			`is_valid`,
			is_past,
			disc_sell_count,
			disc_sell_doller,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			`send_type`,guid
		from mk_store_ticket_discount
		where tick_disc_id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.admin.entity.mk.store.MkStoreTicketDiscountEntity">
		select
			d.`tick_disc_id`,
			d.`tick_disc_type`,
			d.`tick_disc_sub_title`,
			d.`merch_sn`,
			d.`third_merch_sn`,
			d.`store_id`,goods_biz_type,
			d.`store_topic_id`,
			d.`name`,
			d.`voucher_money`,
			d.`voucher_cond`,
			d.`disc_ratio`,
			d.`disc_cond`,
			d.`exch_cond`,
			d.`effect_time_type`,
			d.`fix_beg_time`,
			d.`fix_end_time`,
			d.`postpone_num`,
			d.`valid_day_num`,
			d.`ticket_num`,
			d.`apply_type`,
			d.`get_enter`,
			d.`can_share_get`,
			d.`limit_num`,
			d.`adv_img_url`,
			d.`store_logo_url`,
			d.`store_name`,
			d.`ticket_color`,
			d.`opt_decl`,
			d.`disc_decl`,
			d.`use_noti`,
			d.`svr_tel`,
			d.`is_valid`,
			d.is_past,
			d.disc_sell_count,
			d.disc_sell_doller,
			d.`note`,
			d.`creater_sn`,
			d.`create_time`,
			d.`moder_sn`,
			d.`mod_time`,
			d.`tstm`,
			d.`send_type`,d.guid
		from mk_store_ticket_discount d
		LEFT JOIN third_merchant_biz b ON d.third_merch_sn = b.third_merch_sn
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND d.name 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="thirdPartyMerchCode != null and thirdPartyMerchCode != ''">
			AND b.third_party_merch_code = #{thirdPartyMerchCode}
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by d.tick_disc_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_ticket_discount d
		LEFT JOIN third_merchant_biz b ON d.third_merch_sn = b.third_merch_sn
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND d.name 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="thirdPartyMerchCode != null and thirdPartyMerchCode != ''">
			AND b.third_party_merch_code = #{thirdPartyMerchCode}
		</if>
	</select>

	<insert id="save" parameterType="com.kmall.admin.entity.mk.store.MkStoreTicketDiscountEntity" useGeneratedKeys="true" keyProperty="tickDiscId">
		insert into mk_store_ticket_discount(
			`tick_disc_type`,
			`tick_disc_sub_title`,
			`merch_sn`,
			`third_merch_sn`,
			`store_id`,
			goods_biz_type,
			`store_topic_id`,
			`name`,
			`voucher_money`,
			`voucher_cond`,
			`disc_ratio`,
			`disc_cond`,
			`exch_cond`,
			`effect_time_type`,
			`fix_beg_time`,
			`fix_end_time`,
			`postpone_num`,
			`valid_day_num`,
			`ticket_num`,
			`apply_type`,
			`get_enter`,
			`can_share_get`,
			`limit_num`,
			`adv_img_url`,
			`store_logo_url`,
			`store_name`,
			`ticket_color`,
			`opt_decl`,
			`disc_decl`,
			`use_noti`,
			`svr_tel`,
			`is_valid`,
			is_past,
			is_store_show,
			disc_sell_count,
			disc_sell_doller,
			guid,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			`send_type`)
		values(
			#{tickDiscType},
			#{tickDiscSubTitle},
			#{merchSn},
			#{thirdMerchSn},
			#{storeId},
			#{goodsBizType},
			#{storeTopicId},
			#{name},
			#{voucherMoney},
			#{voucherCond},
			#{discRatio},
			#{discCond},
			#{exchCond},
			#{effectTimeType},
			#{fixBegTime},
			#{fixEndTime},
			#{postponeNum},
			#{validDayNum},
			#{ticketNum},
			#{applyType},
			#{getEnter},
			#{canShareGet},
			#{limitNum},
			#{advImgUrl},
			#{storeLogoUrl},
			#{storeName},
			#{ticketColor},
			#{optDecl},
			#{discDecl},
			#{useNoti},
			#{svrTel},
			#{isValid},
			#{isPast},
			#{isStoreShow},
			#{discSellCount},
			#{discSellDoller},
			#{guid},
			#{note},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm},
			#{sendType})
	</insert>
	 
	<update id="update" parameterType="com.kmall.admin.entity.mk.store.MkStoreTicketDiscountEntity">
		update mk_store_ticket_discount 
		<set>
			<if test="tickDiscType != null">`tick_disc_type` = #{tickDiscType}, </if>
			<if test="tickDiscSubTitle != null">`tick_disc_sub_title` = #{tickDiscSubTitle}, </if>
			<if test="merchSn != null">`merch_sn` = #{merchSn}, </if>
			<if test="thirdMerchSn != null">`third_merch_sn` = #{thirdMerchSn}, </if>
			<if test="storeId != null">`store_id` = #{storeId}, </if>
			<if test="goodsBizType != null">`goods_biz_type` = #{goodsBizType}, </if>
			<if test="storeTopicId != null">`store_topic_id` = #{storeTopicId}, </if>
			<if test="name != null">`name` = #{name}, </if>
			<if test="voucherMoney != null">`voucher_money` = #{voucherMoney}, </if>
			<if test="voucherCond != null">`voucher_cond` = #{voucherCond}, </if>
			<if test="discRatio != null">`disc_ratio` = #{discRatio}, </if>
			<if test="discCond != null">`disc_cond` = #{discCond}, </if>
			<if test="exchCond != null">`exch_cond` = #{exchCond}, </if>
			<if test="effectTimeType != null">`effect_time_type` = #{effectTimeType}, </if>
			<if test="fixBegTime != null">`fix_beg_time` = #{fixBegTime}, </if>
			<if test="fixEndTime != null">`fix_end_time` = #{fixEndTime}, </if>
			<if test="postponeNum != null">`postpone_num` = #{postponeNum}, </if>
			<if test="validDayNum != null">`valid_day_num` = #{validDayNum}, </if>
			<if test="ticketNum != null">`ticket_num` = #{ticketNum}, </if>
			<if test="applyType != null">`apply_type` = #{applyType}, </if>
			<if test="getEnter != null">`get_enter` = #{getEnter}, </if>
			<if test="canShareGet != null">`can_share_get` = #{canShareGet}, </if>
			<if test="limitNum != null">`limit_num` = #{limitNum}, </if>
			<if test="advImgUrl != null">`adv_img_url` = #{advImgUrl}, </if>
			<if test="storeLogoUrl != null">`store_logo_url` = #{storeLogoUrl}, </if>
			<if test="storeName != null">`store_name` = #{storeName}, </if>
			<if test="ticketColor != null">`ticket_color` = #{ticketColor}, </if>
			<if test="optDecl != null">`opt_decl` = #{optDecl}, </if>
			<if test="discDecl != null">`disc_decl` = #{discDecl}, </if>
			<if test="useNoti != null">`use_noti` = #{useNoti}, </if>
			<if test="svrTel != null">`svr_tel` = #{svrTel}, </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="discSellCount != null">`disc_sell_count` = #{discSellCount}, </if>
			<if test="discSellDoller != null">`disc_sell_doller` = #{discSellDoller}, </if>
			<if test="guid != null">`guid` = #{guid}, </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="sendType != null">`send_type` = #{sendType}</if>
		</set>
		where tick_disc_id = #{tickDiscId}
	</update>
	
	<delete id="delete">
		delete from mk_store_ticket_discount where tick_disc_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mk_store_ticket_discount where tick_disc_id in 
		<foreach item="tickDiscId" collection="array" open="(" separator="," close=")">
			#{tickDiscId}
		</foreach>
	</delete>

</mapper>