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

    <resultMap type="com.kxs.stat.api.model.KxsUserGdTrade" id="KxsUserGdTradeMap">
        <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="help_trade_amt" property="helpTradeAmt" />
        <result column="user_id" property="userId" />
        <result column="pro_trade_amt" property="proTradeAmt" />
        <result column="trade_amt" property="tradeAmt" />
        <result column="total_type" property="totalType" />

    </resultMap>



    <select id="getGdActCount" resultType="com.kxs.stat.api.vo.TotalTradeAmtVO">
        SELECT SUM(act_num) as gdCount
        FROM kxs_user_act_trade
        <where>
            and brand_id = 14
            and total_type = #{totalType}
            and user_id = #{userId}
            <choose>
                <when test="type == 1">
                    AND trade_date = #{date}
                </when>
                <when test="type == 2">
                    AND trade_month = #{date}
                </when>
                <when test="type == 3">
                    AND  <![CDATA[ trade_date <=  #{date} ]]>
                </when>
                <when test="type == 4">
                    AND <![CDATA[ trade_month <= #{date} ]]>
                </when>
            </choose>
        </where>
    </select>
    <select id="getGdTrade" resultType="com.kxs.stat.api.vo.TotalTradeAmtVO">
        select  SUM(trade_amt) as gdAmount from kxs_user_gd_trade
        <where>
            and total_type = #{totalType}
            and user_id = #{userId}
            <if test="type == 1">
                and trade_date = #{date}
            </if>
            <if test="type == 2">
                and trade_month = #{date}
            </if>
        </where>
    </select>

</mapper>
