<?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.gxwebsoft.cms.mapper.CmsStatisticsMapper">

    <!-- 关联查询sql -->
    <sql id="selectSql">
        SELECT a.*
        FROM cms_statistics a
        <where>
            <if test="param.id != null">
                AND a.id = #{param.id}
            </if>
            <if test="param.websiteId != null">
                AND a.website_id = #{param.websiteId}
            </if>
            <if test="param.userCount != null">
                AND a.user_count = #{param.userCount}
            </if>
            <if test="param.orderCount != null">
                AND a.order_count = #{param.orderCount}
            </if>
            <if test="param.productCount != null">
                AND a.product_count = #{param.productCount}
            </if>
            <if test="param.totalSales != null">
                AND a.total_sales = #{param.totalSales}
            </if>
            <if test="param.monthSales != null">
                AND a.month_sales = #{param.monthSales}
            </if>
            <if test="param.todaySales != null">
                AND a.today_sales = #{param.todaySales}
            </if>
            <if test="param.yesterdaySales != null">
                AND a.yesterday_sales = #{param.yesterdaySales}
            </if>
            <if test="param.weekSales != null">
                AND a.week_sales = #{param.weekSales}
            </if>
            <if test="param.yearSales != null">
                AND a.year_sales = #{param.yearSales}
            </if>
            <if test="param.todayOrders != null">
                AND a.today_orders = #{param.todayOrders}
            </if>
            <if test="param.monthOrders != null">
                AND a.month_orders = #{param.monthOrders}
            </if>
            <if test="param.todayUsers != null">
                AND a.today_users = #{param.todayUsers}
            </if>
            <if test="param.monthUsers != null">
                AND a.month_users = #{param.monthUsers}
            </if>
            <if test="param.todayVisits != null">
                AND a.today_visits = #{param.todayVisits}
            </if>
            <if test="param.totalVisits != null">
                AND a.total_visits = #{param.totalVisits}
            </if>
            <if test="param.merchantCount != null">
                AND a.merchant_count = #{param.merchantCount}
            </if>
            <if test="param.activeUsers != null">
                AND a.active_users = #{param.activeUsers}
            </if>
            <if test="param.conversionRate != null">
                AND a.conversion_rate = #{param.conversionRate}
            </if>
            <if test="param.avgOrderAmount != null">
                AND a.avg_order_amount = #{param.avgOrderAmount}
            </if>
            <if test="param.statisticsDate != null">
                AND a.statistics_date LIKE CONCAT('%', #{param.statisticsDate}, '%')
            </if>
            <if test="param.statisticsType != null">
                AND a.statistics_type = #{param.statisticsType}
            </if>
            <if test="param.sortNumber != null">
                AND a.sort_number = #{param.sortNumber}
            </if>
            <if test="param.userId != null">
                AND a.user_id = #{param.userId}
            </if>
            <if test="param.merchantId != null">
                AND a.merchant_id = #{param.merchantId}
            </if>
            <if test="param.status != null">
                AND a.status = #{param.status}
            </if>
            <if test="param.deleted != null">
                AND a.deleted = #{param.deleted}
            </if>
            <if test="param.deleted == null">
                AND a.deleted = 0
            </if>
            <if test="param.createTimeStart != null">
                AND a.create_time &gt;= #{param.createTimeStart}
            </if>
            <if test="param.createTimeEnd != null">
                AND a.create_time &lt;= #{param.createTimeEnd}
            </if>
            <if test="param.keywords != null">
                AND (a.comments LIKE CONCAT('%', #{param.keywords}, '%')
                )
              </if>
        </where>
    </sql>

    <!-- 分页查询 -->
    <select id="selectPageRel" resultType="com.gxwebsoft.cms.entity.CmsStatistics">
        <include refid="selectSql"></include>
    </select>

    <!-- 查询全部 -->
    <select id="selectListRel" resultType="com.gxwebsoft.cms.entity.CmsStatistics">
        <include refid="selectSql"></include>
    </select>

</mapper>
