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

    <resultMap type="com.kmall.api.entity.mk.MkStorePromStatVo" id="mkStorePromStatMap">
        <result property="promStatId" column="prom_stat_id"/>
        <result property="promId" column="prom_id"/>
        <result property="storeId" column="store_id"/>
        <result property="browseNum" column="browse_num"/>
        <result property="visitNum" column="visit_num"/>
        <result property="relaBrowseNum" column="rela_browse_num"/>
        <result property="relaVisitorNum" column="rela_visitor_num"/>
        <result property="aveStopTime" column="ave_stop_time"/>
        <result property="aveVisitorNum" column="ave_visitor_num"/>
        <result property="visitPageDeep" column="visit_page_deep"/>
        <result property="transVisitorNum" column="trans_visitor_num"/>
        <result property="transNum" column="trans_num"/>
        <result property="payOrderNum" column="pay_order_num"/>
        <result property="relaPayOrderNum" column="rela_pay_order_num"/>
        <result property="payerNum" column="payer_num"/>
        <result property="relaPayerNum" column="rela_payer_num"/>
        <result property="payCaseNum" column="pay_case_num"/>
        <result property="relaPayCaseNum" column="rela_pay_case_num"/>
        <result property="receivMoney" column="receiv_money"/>
        <result property="relaReceivMoney" column="rela_receiv_money"/>
        <result property="actMoney" column="act_money"/>
        <result property="relaActMoney" column="rela_act_money"/>
        <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"/>
		<result property="referrer" column="referrer"/>
		<result property="submitOrderNum" column="submit_order_num"/>
		<result property="submitNum" column="submit_num"/>
		<result property="goodsId" column="goods_id"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.api.entity.mk.MkStorePromStatVo">
		select
			`prom_stat_id`,
			`prom_id`,
			`store_id`,
			`browse_num`,
			`visit_num`,
			`rela_browse_num`,
			`rela_visitor_num`,
			`ave_stop_time`,
			`ave_visitor_num`,
			`visit_page_deep`,
			`trans_visitor_num`,
			`trans_num`,
			`pay_order_num`,
			`rela_pay_order_num`,
			`payer_num`,
			`rela_payer_num`,
			`pay_case_num`,
			`rela_pay_case_num`,
			`receiv_money`,
			`rela_receiv_money`,
			`act_money`,
			`rela_act_money`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,referrer,submit_num,submit_order_num
		from mk_store_prom_stat
		where prom_stat_id = #{id}
	</select>

	<select id="queryStatDataByCartIdAndGoodsId" resultType="com.kmall.api.entity.mk.MkStorePromStatVo">
		SELECT
			r.prom_order_real_id,
			r.prom_id,
			s.prom_stat_id,
			s.`browse_num`,
			s.`visit_num`,
			s.`rela_browse_num`,
			s.`rela_visitor_num`,
			s.`ave_stop_time`,
			s.`ave_visitor_num`,
			s.`visit_page_deep`,
			s.`trans_visitor_num`,
			s.`trans_num`,
			s.`pay_order_num`,
			s.`rela_pay_order_num`,
			s.`payer_num`,
			s.`rela_payer_num`,
			s.`pay_case_num`,
			s.`rela_pay_case_num`,
			s.`receiv_money`,
			s.`rela_receiv_money`,
			s.`act_money`,
			s.`rela_act_money`,
			s.submit_num,
			s.submit_order_num,
			p.goods_id
		FROM
			mk_store_prom_stat s
			LEFT JOIN mk_store_prom_order_real r ON s.prom_id = r.prom_id
			left join mk_store_prom p on s.prom_id = p.prom_id
		WHERE
			r.cart_id = #{cartId} and p.goods_id = #{goodsId}
	</select>

	<select id="queryObjectByPromId" resultType="com.kmall.api.entity.mk.MkStorePromStatVo">
		select
		`prom_stat_id`,
		`prom_id`,
		`store_id`,
		`browse_num`,
		`visit_num`,
		`rela_browse_num`,
		`rela_visitor_num`,
		`ave_stop_time`,
		`ave_visitor_num`,
		`visit_page_deep`,
		`trans_visitor_num`,
		`trans_num`,
		`pay_order_num`,
		`rela_pay_order_num`,
		`payer_num`,
		`rela_payer_num`,
		`pay_case_num`,
		`rela_pay_case_num`,
		`receiv_money`,
		`rela_receiv_money`,
		`act_money`,
		`rela_act_money`,
		`is_valid`,
		`note`,
		`creater_sn`,
		`create_time`,
		`moder_sn`,
		`mod_time`,
		`tstm`,referrer,submit_num,submit_order_num
		from mk_store_prom_stat
		where prom_id = #{promId}
	</select>

	<select id="queryList" resultType="com.kmall.api.entity.mk.MkStorePromStatVo">
		select
    		`prom_stat_id`,
    		`prom_id`,
    		`store_id`,
    		`browse_num`,
    		`visit_num`,
    		`rela_browse_num`,
    		`rela_visitor_num`,
    		`ave_stop_time`,
    		`ave_visitor_num`,
    		`visit_page_deep`,
    		`trans_visitor_num`,
    		`trans_num`,
    		`pay_order_num`,
    		`rela_pay_order_num`,
    		`payer_num`,
    		`rela_payer_num`,
    		`pay_case_num`,
    		`rela_pay_case_num`,
    		`receiv_money`,
    		`rela_receiv_money`,
    		`act_money`,
    		`rela_act_money`,
    		`is_valid`,
    		`note`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`,referrer,submit_num,submit_order_num
		from mk_store_prom_stat
		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 prom_stat_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_prom_stat
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>

	<insert id="save" parameterType="com.kmall.api.entity.mk.MkStorePromStatVo">
		insert into mk_store_prom_stat(
			`prom_stat_id`,
			`prom_id`,
			`store_id`,
			`browse_num`,
			`visit_num`,
			`rela_browse_num`,
			`rela_visitor_num`,
			`ave_stop_time`,
			`ave_visitor_num`,
			`visit_page_deep`,
			`trans_visitor_num`,
			`trans_num`,
			submit_order_num,
			submit_num,
			`pay_order_num`,
			`rela_pay_order_num`,
			`payer_num`,
			`rela_payer_num`,
			`pay_case_num`,
			`rela_pay_case_num`,
			`receiv_money`,
			`rela_receiv_money`,
			`act_money`,
			`rela_act_money`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,
			referrer)
		values(
			#{promStatId},
			#{promId},
			#{storeId},
			#{browseNum},
			#{visitNum},
			#{relaBrowseNum},
			#{relaVisitorNum},
			#{aveStopTime},
			#{aveVisitorNum},
			#{visitPageDeep},
			#{transVisitorNum},
			#{transNum},
			#{submitOrderNum},
			#{submitNum},
			#{payOrderNum},
			#{relaPayOrderNum},
			#{payerNum},
			#{relaPayerNum},
			#{payCaseNum},
			#{relaPayCaseNum},
			#{receivMoney},
			#{relaReceivMoney},
			#{actMoney},
			#{relaActMoney},
			#{isValid},
			#{note},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm},
			#{referrer})
	</insert>
	 
	<update id="update" parameterType="com.kmall.api.entity.mk.MkStorePromStatVo">
		update mk_store_prom_stat 
		<set>
			<if test="promId != null">`prom_id` = #{promId}, </if>
			<if test="storeId != null">`store_id` = #{storeId}, </if>
			<if test="browseNum != null">`browse_num` = #{browseNum}, </if>
			<if test="visitNum != null">`visit_num` = #{visitNum}, </if>
			<if test="relaBrowseNum != null">`rela_browse_num` = #{relaBrowseNum}, </if>
			<if test="relaVisitorNum != null">`rela_visitor_num` = #{relaVisitorNum}, </if>
			<if test="aveStopTime != null">`ave_stop_time` = #{aveStopTime}, </if>
			<if test="aveVisitorNum != null">`ave_visitor_num` = #{aveVisitorNum}, </if>
			<if test="visitPageDeep != null">`visit_page_deep` = #{visitPageDeep}, </if>
			<if test="transVisitorNum != null">`trans_visitor_num` = #{transVisitorNum}, </if>
			<if test="transNum != null">`trans_num` = #{transNum}, </if>
			<if test="submitOrderNum != null">`submit_order_num` = #{submitOrderNum}, </if>
			<if test="submitNum != null">`submit_num` = #{submitNum}, </if>
			<if test="payOrderNum != null">`pay_order_num` = #{payOrderNum}, </if>
			<if test="relaPayOrderNum != null">`rela_pay_order_num` = #{relaPayOrderNum}, </if>
			<if test="payerNum != null">`payer_num` = #{payerNum}, </if>
			<if test="relaPayerNum != null">`rela_payer_num` = #{relaPayerNum}, </if>
			<if test="payCaseNum != null">`pay_case_num` = #{payCaseNum}, </if>
			<if test="relaPayCaseNum != null">`rela_pay_case_num` = #{relaPayCaseNum}, </if>
			<if test="receivMoney != null">`receiv_money` = #{receivMoney}, </if>
			<if test="relaReceivMoney != null">`rela_receiv_money` = #{relaReceivMoney}, </if>
			<if test="actMoney != null">`act_money` = #{actMoney}, </if>
			<if test="relaActMoney != null">`rela_act_money` = #{relaActMoney}, </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>
			<if test="referrer != null">`referrer` = #{referrer}</if>
		</set>
		where prom_stat_id = #{promStatId}
	</update>
	
	<delete id="delete">
		delete from mk_store_prom_stat where prom_stat_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mk_store_prom_stat where prom_stat_id in 
		<foreach item="promStatId" collection="array" open="(" separator="," close=")">
			#{promStatId}
		</foreach>
	</delete>

</mapper>