<?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.house365.ws.dao.mapper.StatisticReportMapper">
    <select id="getStatisticSummary"  resultType="java.util.HashMap">
        <![CDATA[
        SELECT(
        SELECT FORMAT(count(id),0) from customer_merge as c where c.is_delete = 0 AND c.STATUS in(11,0,99) and  manager_id = #{managerId}
                       and c.bind_time>=#{startTime} and c.bind_time<=#{endTime} and (c.isWaitCall=0 OR c.isWaitCall IS NULL)) as allCount,
        (SELECT FORMAT(count(id),0) from customer as c where c.STATUS in(11,0,99)  and isWaitCall = 1 and c.is_delete = 0 and manager_id = #{managerId}
                       and c.bind_time>=#{startTime} and c.bind_time<=#{endTime}) as waitCount,
        (SELECT FORMAT(count(id),0) FROM customer_merge c inner join (select customer_id,count((substr(ccl.manager_name,1,5)!='CRM用户' and ccl.manager_id!=0) or null) as count
                       from customer_callback_log ccl  group by customer_id having count>0) n on c.id=n.customer_id where 1=1
                       and manager_id = #{managerId} and c.bind_time>=#{startTime} and c.bind_time<=#{endTime}
                       AND c.last_call_time is not null AND c.is_delete = 0 AND c.STATUS IN ( 11, 0, 99)
                       AND ( c.isWaitCall = 0 OR c.isWaitCall IS NULL)) as callCount,
        (SELECT FORMAT(count(id),0) from customer_merge as c where c.is_delete = 0 and manager_id = #{managerId}
                        and c.bind_time>=#{startTime} and c.bind_time<=#{endTime} and (c.isWaitCall = 0 OR c.isWaitCall IS NULL)
                        AND c.STATUS IN ( 11, 0, 99 ) and c.customer_source_type=7) as cloudSent,
        (select FORMAT(count(id),0) FROM customer_merge c inner join (select m.customer_id from customer_callback_log m inner join
                       (select customer_id,count(*) as count from customer_callback_log  group by customer_id) n
                       on n.count=1 and m.customer_id=n.customer_id and m.manager_id=0) c2 on c.id=c2.customer_id
                        where 1=1 AND c.is_delete = 0 and manager_id = #{managerId} and c.bind_time>=#{startTime} and c.bind_time<=#{endTime}
                        AND c.STATUS IN ( 11, 0, 99 ) and c.customer_source_type=7) as cloudWait
        ]]>
    </select>

</mapper>