<?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.xxfc.platform.order.mapper.StaffStatisticsMapper">

    <!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.order.entity.StaffStatistics" id="staffstatisticsMap">
       <result property="id" column="id"/>
        <result property="year" column="year"/>
        <result property="month" column="month"/>
        <result property="date" column="date"/>
        <result property="weekOfYear" column="week_of_year"/>
        <result property="companyId" column="company_id"/>
        <result property="companyName" column="company_name"/>
        <result property="userId" column="user_id"/>
        <result property="userPostionId" column="user_postion_id"/>
        <result property="postionName" column="postion_name"/>
        <result property="rentVehicleOrderNum" column="rent_vehicle_order_num"/>
        <result property="rentVehicleAmount" column="rent_vehicle_amount"/>
        <result property="travelOrderNum" column="travel_order_num"/>
        <result property="travelAmount" column="travel_amount"/>
        <result property="memberOrderNum" column="member_order_num"/>
        <result property="memberAmount" column="member_amount"/>
        <result property="sellAmount" column="sell_amount"/>
        <result property="royaltyAmount" column="royalty_amount"/>
    </resultMap>

    <select id="statistics" resultType="com.xxfc.platform.order.pojo.bo.StaffStatisticsTotalBo">
     select count(`user_id`) as `staffNum`,sum(`sell_amount`) as `totalSellAmount`,sum(`royalty_amount`) as `totalRoyaltyAmount` from `staff_statistics`
    </select>

    <select id="selectStaffStatistics" resultMap="staffstatisticsMap">
        select * from  `staff_statistics` where 1=1
        <if test="userPostionId!=null">
            and `user_postion_id`=#{userPostionId}
        </if>
        <if test="companyName!=null and companyName!=''">
            and `company_name` like CONCAT('%',#{companyName},'%')
        </if>
        <if test="companyIds!=null and companyIds.size!=0">
            and `company_id` IN
            <foreach collection="companyIds" item="compnayId" separator="," open="(" close=")">
                #{compnayId}
            </foreach>
        </if>
        <if test="startDate!=null and endDate!=null">
          and `date` between #{startDate} and #{endDate}
        </if>

        <if test="startDate!=null and endDate==null">
          and  <![CDATA[
           `date` >=#{startDate}
          ]]>
        </if>

        <if test="startDate==null and endDate!=null">
            and  <![CDATA[
           `date` <=#{endDate}
          ]]>
        </if>
    </select>


</mapper>