<?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.kxs.stat.biz.mapper.KxsLkbTradeMapper">

    <resultMap type="com.kxs.stat.api.model.KxsLkbTrade" id="KxsLkbTradeMap">
        <result column="id" property="id"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
        <result column="del_flag" property="delFlag"/>
        <result column="version" property="version"/>
        <result column="trade_date" property="tradeDate"/>
        <result column="trade_month" property="tradeMonth"/>
        <result column="trade_amt" property="tradeAmt"/>
        <result column="act_trade_amt" property="actTradeAmt"/>
        <result column="user_id" property="userId"/>
        <result column="brand_id" property="brandId"/>
        <result column="total_type" property="totalType"/>

    </resultMap>
    <select id="getUserTradeMonthList" resultType="com.kxs.stat.api.model.KxsLkbTrade" fetchSize="1000">
        SELECT SUM(trade_amt) as trade_amt, SUM(act_trade_amt) as act_trade_amt, user_id
        FROM kxs_lkb_trade
        <where>
            and total_type = 1
            and trade_month = #{tradeMonth}
        </where>
        GROUP BY user_id
    </select>
    <select id="getLkbTrade" resultType="com.kxs.stat.api.vo.TotalTradeAmtVO">
        SELECT SUM(trade_amt) as lkbAmt, SUM(act_trade_amt) lkbActAmt
        FROM kxs_lkb_trade
        <where>
            and user_id = #{userId}
            and total_type = #{totalType}
            <if test="date != null and date.toString().length() == 6">
                and trade_month = #{date}
            </if>
            <if test="date != null and date.toString().length() == 8">
                and trade_date = #{date}
            </if>
        </where>
    </select>

</mapper>
