<?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.schedule.dao.MkDistSellStatisMapper">

    <resultMap type="com.kmall.schedule.entity.MkDistSellStatisEntity" id="mkDistSellStatisMap">
        <result property="id" column="id"/>
        <result property="distFlag" column="dist_flag"/>
        <result property="thirdMerchSn" column="third_merch_sn"/>
        <result property="supplierId" column="supplier_id"/>
        <result property="distId" column="dist_id"/>
        <result property="goodsId" column="goods_id"/>
        <result property="goodsPrice" column="goods_price"/>
        <!--<result property="allocType" column="alloc_type"/>-->
		<result property="sellAllocHistoryId" column="sell_alloc_history_id"/>
        <result property="expendDistId" column="expend_dist_id"/>
        <result property="expendDistPrice" column="expend_dist_price"/>
        <result property="expendDistLevel" column="expend_dist_level"/>
        <result property="expendSource" column="expend_source"/>
        <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="orderSn" column="order_sn"/>
		<result property="distChnlId" column="dist_chnl_id"/>
		<result property="userId" column="user_id"/>
		<result property="orderGoodsId" column="order_goods_id"/>
		<result property="storeId" column="store_id"/>
    </resultMap>

	<select id="queryObject" resultType="com.kmall.schedule.entity.MkDistSellStatisEntity">
		select
			`id`,
			dist_chnl_id,
			`dist_flag`,
			`third_merch_sn`,
			`supplier_id`,
			`dist_id`,
			`goods_id`,
			`goods_price`,
			`alloc_type`,
			`expend_dist_id`,
			`expend_dist_price`,
			`expend_dist_level`,
			`expend_source`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`,order_sn,user_id,order_goods_id,store_id
		from mk_dist_sell_statis
		where id = #{id}
	</select>

	<select id="queryList" resultType="com.kmall.schedule.entity.MkDistSellStatisEntity">
		select
    		`id`,
			dist_chnl_id,
    		`dist_flag`,
    		`third_merch_sn`,
    		`supplier_id`,
    		`dist_id`,
    		`goods_id`,
    		`goods_price`,
    		`alloc_type`,
    		`expend_dist_id`,
    		`expend_dist_price`,
    		`expend_dist_level`,
    		`expend_source`,
    		`is_valid`,
    		`note`,
    		`creater_sn`,
    		`create_time`,
    		`moder_sn`,
    		`mod_time`,
    		`tstm`,order_sn,user_id,order_goods_id,store_id
		from mk_dist_sell_statis
		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 mk_dist_sell_statis
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>

	<insert id="save" parameterType="com.kmall.schedule.entity.MkDistSellStatisEntity" useGeneratedKeys="true" keyProperty="id">
		insert into mk_dist_sell_statis(
			`dist_flag`,
			dist_chnl_id,
			`third_merch_sn`,
			`supplier_id`,
			`dist_id`,
			user_id,
			order_goods_id,
			order_sn,
			store_id,
			`goods_id`,
			`goods_price`,
			`sell_alloc_history_id`,
			`expend_dist_id`,
			`expend_dist_price`,
			`expend_dist_level`,
			`expend_source`,
			`is_valid`,
			`note`,
			`creater_sn`,
			`create_time`,
			`moder_sn`,
			`mod_time`,
			`tstm`)
		values(
			#{distFlag},
			#{distChnlId},
			#{thirdMerchSn},
			#{supplierId},
			#{distId},
			#{userId},
			#{orderGoodsId},
			#{orderSn},
			#{storeId},
			#{goodsId},
			#{goodsPrice},
			#{sellAllocHistoryId},
			#{expendDistId},
			#{expendDistPrice},
			#{expendDistLevel},
			#{expendSource},
			#{isValid},
			#{note},
			#{createrSn},
			#{createTime},
			#{moderSn},
			#{modTime},
			#{tstm})
	</insert>

	<update id="update" parameterType="com.kmall.schedule.entity.MkDistSellStatisEntity">
		update mk_dist_sell_statis 
		<set>
			<if test="distFlag != null">`dist_flag` = #{distFlag}, </if>
			<if test="thirdMerchSn != null">`third_merch_sn` = #{thirdMerchSn}, </if>
			<if test="distChnlId != null">`dist_chnl_id` = #{distChnlId}, </if>
			<if test="supplierId != null">`supplier_id` = #{supplierId}, </if>
			<if test="distId != null">`dist_id` = #{distId}, </if>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="orderGoodsId != null">`order_goods_id` = #{orderGoodsId}, </if>
			<if test="storeId != null">`store_id` = #{storeId}, </if>
			<if test="orderSn != null">`order_sn` = #{orderSn}, </if>
			<if test="goodsId != null">`goods_id` = #{goodsId}, </if>
			<if test="goodsPrice != null">`goods_price` = #{goodsPrice}, </if>
			<if test="sellAllocHistoryId != null">`sell_alloc_history_id` = #{sellAllocHistoryId}, </if>
			<if test="expendDistId != null">`expend_dist_id` = #{expendDistId}, </if>
			<if test="expendDistPrice != null">`expend_dist_price` = #{expendDistPrice}, </if>
			<if test="expendDistLevel != null">`expend_dist_level` = #{expendDistLevel}, </if>
			<if test="expendSource != null">`expend_source` = #{expendSource}, </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 mk_dist_sell_statis where id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from mk_dist_sell_statis where id in 
		<foreach item="id" collection="array" open="(" separator="," close=")">
			#{id}
		</foreach>
	</delete>

</mapper>