<?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.cyksj.mapper.manage.RealGoodsOrderHandleMapper">

    <select id="selectCustomerToMonthData"
            resultType="com.cyksj.model.views.CustomerServiceHandleOrderToMonthView">
        select
        <if test="type == 1">
            before_service_name,
        </if>
        <if test="type == 2">
            after_service_name,
        </if>
        count(*) as numOfOrder,
        sum(od.money) as money
        from real_goods_order_handle ch left join order_don od on od.id = ch.order_id
        where od.status not in
        <foreach collection="list" item="item" open="(" close=")" separator=",">
            #{item}
        </foreach>
        and ch.created_time between #{begin} and #{now}
        <if test="type == 1">
            and before_service_name != ''
            group by before_service_name
            order by before_service_name
        </if>
        <if test="type == 2">
            and after_service_name != ''
            group by after_service_name
            order by after_service_name
        </if>
    </select>
</mapper>