<?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="getUserAddTrend" resultType="com.kxs.stat.api.vo.statUser.TrendTimesVO">
        select
            sum(new_count) as total
        <if test="type == 1">
            ,trade_date
        </if>
        <if test="type == 2">
            ,trade_month
        </if>
        from kxs_user_new_trade
        where
            del_flag != 1
        and user_id = #{userId}
        <if test="type == 1">
            and trade_date in
            <foreach collection="times" item="time" open="(" separator="," close=")">
                #{time}
            </foreach>
        </if>
        <if test="type == 2">
            and trade_month in
            <foreach collection="times" item="time" open="(" separator="," close=")">
                #{time}
            </foreach>
        </if>
        and total_type = #{totalType}
        GROUP BY
        <if test="type == 1">
            trade_date
        </if>
        <if test="type == 2">
            trade_month
        </if>
    </select>
    <select id="getUserAllTrend" resultType="java.lang.Integer">
        select sum(new_count) as totalCount
        from kxs_user_new_trade
        where
            del_flag != 1
        and user_id = #{userId}
        and total_type = #{type}
    </select>

</mapper>
