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

    <resultMap type="com.kxs.stat.api.model.KxsUserNewTrade" id="KxsUserNewTradeMap">
        <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="user_id" property="userId" />
        <result column="total_type" property="totalType" />
        <result column="new_count" property="newCount" />

    </resultMap>
    <select id="getAddUserTrend" resultType="com.kxs.stat.api.vo.myUser.UserAddTrendVO">
        select sum(new_count) as num,
        <if test="dateType != null and dateType == 0">
            trade_month as time
        </if>
        <if test="dateType != null and dateType == 1">
            trade_date as time
        </if>
        from kxs_user_new_trade
        <where>
            and user_id = #{userId}
            and total_type = #{totalType}
            <if test="dateType != null and dateType == 0">
                and trade_month in
                <foreach collection="times" item="time" open="(" separator="," close=")">
                    #{time}
                </foreach>
            </if>
            <if test="dateType != null and dateType == 1">
                and trade_date in
                <foreach collection="times" item="time" open="(" separator="," close=")">
                    #{time}
                </foreach>
            </if>
        </where>
        <if test="dateType != null and dateType == 0">
            group by trade_month
        </if>
        <if test="dateType != null and dateType == 1">
            group by trade_date
        </if>
    </select>
    <select id="selectToDayOrMonthCount" resultType="java.lang.Integer">
        select IFNULL(SUM(new_count), 0) from kxs_user_new_trade
        <where>
            and total_type = #{totalType}
            and user_id = #{userId}
            <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>
