<?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.slodon.b2b2c.dao.read.statistics.MemberDayReadMapper">
  <resultMap id="resultMap" type="com.slodon.b2b2c.statistics.pojo.MemberDay">
    <id column="stats_id" property="statsId" />
    <result column="stats_time" property="statsTime" />
    <result column="web_site" property="webSite" />
    <result column="member_id" property="memberId" />
    <result column="member_name" property="memberName" />
    <result column="register_time" property="registerTime" />
    <result column="recharge_amount" property="rechargeAmount" />
    <result column="order_submit_num" property="orderSubmitNum" />
    <result column="order_submit_amount" property="orderSubmitAmount" />
    <result column="order_pay_num" property="orderPayNum" />
    <result column="order_pay_amount" property="orderPayAmount" />
    <result column="return_num" property="returnNum" />
    <result column="return_amount" property="returnAmount" />
  </resultMap>
  <!--按照主键值进行操作-->
  <sql id="pkWhere">
    WHERE `stats_id` = #{primaryKey}
  </sql>
  <!--操作条件-->
  <sql id="whereCondition">
    <if test="example != null">
      <trim prefix="WHERE" prefixOverrides="AND|OR">
        <if test="example.statsIdNotEquals != null">
          AND `stats_id` != #{example.statsIdNotEquals}
        </if>
        <if test="example.statsIdIn != null">
          AND `stats_id` in (${example.statsIdIn})
        </if>
        <if test="example.statsTimeAfter != null">
          AND `stats_time` <![CDATA[ >= ]]> #{example.statsTimeAfter}
        </if>
        <if test="example.statsTimeBefore != null">
          AND `stats_time` <![CDATA[ <= ]]> #{example.statsTimeBefore}
        </if>
        <if test="example.webSite != null">
          AND `web_site` = #{example.webSite}
        </if>
        <if test="example.memberId != null">
          AND `member_id` = #{example.memberId}
        </if>
        <if test="example.memberName != null">
          AND `member_name` = #{example.memberName}
        </if>
        <if test="example.memberNameLike != null">
          AND `member_name` like concat('%',#{example.memberNameLike},'%')
        </if>
        <if test="example.registerTimeAfter != null">
          AND `register_time` <![CDATA[ >= ]]> #{example.registerTimeAfter}
        </if>
        <if test="example.registerTimeBefore != null">
          AND `register_time` <![CDATA[ <= ]]> #{example.registerTimeBefore}
        </if>
        <if test="example.rechargeAmount != null">
          AND `recharge_amount` = #{example.rechargeAmount}
        </if>
        <if test="example.orderSubmitNum != null">
          AND `order_submit_num` = #{example.orderSubmitNum}
        </if>
        <if test="example.orderSubmitAmount != null">
          AND `order_submit_amount` = #{example.orderSubmitAmount}
        </if>
        <if test="example.orderPayNum != null">
          AND `order_pay_num` = #{example.orderPayNum}
        </if>
        <if test="example.orderPayAmount != null">
          AND `order_pay_amount` = #{example.orderPayAmount}
        </if>
        <if test="example.returnNum != null">
          AND `return_num` = #{example.returnNum}
        </if>
        <if test="example.returnAmount != null">
          AND `return_amount` = #{example.returnAmount}
        </if>
      </trim>
    </if>
  </sql>
  <!--排序条件-->
  <sql id="orderBy">
    ORDER BY `stats_id` DESC
  </sql>
  <sql id="orderByOther">
    order by ${example.orderBy}
  </sql>
  <!--分组条件-->
  <sql id="groupBy">
    group by ${example.groupBy}
  </sql>
  <!--分页条件-->
  <sql id="limit">
    <if test="size != null and size &gt; 0">
      limit #{startRow},#{size}
    </if>
  </sql>
  <!--查询符合条件的记录数-->
  <select id="countByExample" parameterType="com.slodon.b2b2c.statistics.example.MemberDayExample" resultType="java.lang.Integer">
    SELECT
      COUNT(*)
    FROM `stats_member_day`
    <include refid="whereCondition" />
  </select>
  <!--根据主键查询记录-->
  <select id="getByPrimaryKey" resultMap="resultMap">
    SELECT
      *
    FROM `stats_member_day`
    <include refid="pkWhere" />
  </select>
  <!--查询符合条件的记录(所有字段)-->
  <select id="listByExample" resultMap="resultMap">
    SELECT
      *
    FROM `stats_member_day`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(所有字段)-->
  <select id="listPageByExample" resultMap="resultMap">
    SELECT
      *
    FROM `stats_member_day`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的记录(指定字段)-->
  <select id="listFieldsByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `stats_member_day`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
  </select>
  <!--分页查询符合条件的记录(指定字段)-->
  <select id="listFieldsPageByExample" resultMap="resultMap">
    SELECT
      ${fields}
    FROM `stats_member_day`
    <include refid="whereCondition" />
    <if test="example.groupBy != null">
      <include refid="groupBy" />
    </if>
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
  <!--查询符合条件的分组记录数-->
  <select id="getMemberCount" parameterType="com.slodon.b2b2c.statistics.example.MemberDayExample" resultType="java.lang.Integer">
    SELECT
    COUNT(DISTINCT member_id)
    FROM `stats_member_day`
    <include refid="whereCondition" />
  </select>
  <select id="getMemberList" resultType="com.slodon.b2b2c.statistics.pojo.base.MemberBase">
    select
    member_id AS memberId,
    member_name AS memberName,
    register_time AS registerTime,
    sum( recharge_amount ) AS rechargeAmount,
    sum( order_submit_num ) AS orderSubmitNum,
    sum( order_submit_amount ) AS orderSubmitAmount,
    sum( order_pay_num ) AS orderPayNum,
    sum( order_pay_amount ) AS orderPayAmount,
    sum( return_num ) AS returnNum,
    sum( return_amount ) AS returnAmount
    FROM `stats_member_day`
    <include refid="whereCondition"/>
    group by memberId, memberName, registerTime
    <choose>
      <when test="example.orderBy != null">
        <include refid="orderByOther" />
      </when>
      <otherwise>
        <include refid="orderBy" />
      </otherwise>
    </choose>
    <include refid="limit" />
  </select>
</mapper>