<?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.gree.mall.miniapp.commonmapper.workorder.OrderBaseCMapper">

    <select id="countOrderStatus" resultType="com.gree.mall.miniapp.bean.workorder.CountOrderStatusBean">
         select
            count(DISTINCT if((is_import_excel = false and a.order_status='DJD') or (is_import_excel = true and a.is_meet = false) ,a.id,null)) 'djd',
            count(DISTINCT if(a.order_status in ('FWZ','GCSZT','BFWG','DSM','YZP','XSBH','TJXSBH','ZBBH','FZXBH','WDBH'),a.id,null)) 'fwz',
            count(DISTINCT if(a.is_exception=1,a.id,null)) 'ycd',
            count(DISTINCT if(a.order_status='DQD',a.id,null)) 'dqd',
            count(DISTINCT if(a.order_status in ('YWG','YJS','GCSZX','YWGO','WDWG') ,a.id,null)) 'ywg',
            count(DISTINCT if(a.over_time between CONCAT(CURDATE(), ' 00:00:00') and CONCAT(CURDATE(), ' 23:59:59'),a.id,null)) 'jrwg',
            count(DISTINCT if(a.order_status in ('YWG','YJS','GCSZX','YWGO','WDWG') and a.over_time > CONCAT(DATE_SUB(CURDATE(), INTERVAL 6 MONTH) , ' 00:00:00') ,a.id,null)) 'jbnwg',
            count(DISTINCT if(a.order_status not in ('YWG','YJS','GCSZX','YWGO','WDWG','DQD'),a.id,null)) 'WWG',
            COUNT(DISTINCT a.id) AS 'all'
        from pg_order_base a
        left join pg_order_worker b on a.id = b.order_base_id
    where ((b.worker_id=#{workerId} or b.worker_number=#{workerNumber}) or a.order_status = 'DQD') and a.order_status not in ('YQX','FWQX','FL','FWZT','YCGB')
    and b.websit_id = a.websit_id
    <if test="isYb != null and isYb == true">
        and a.pg_incre_order_id != ''
    </if>
    <if test="isWb != null and isWb == true">
        and a.rp_project_repair_id !=''
    </if>
    <if test="pgIncreOrderId != null and pgIncreOrderId !=''">
        and a.pg_incre_order_id = #{pgIncreOrderId}
    </if>
    and a.company_wechat_id = #{companyWechatId}

    </select>

    <select id="countPartsApply" resultType="com.gree.mall.miniapp.bean.workorder.CountOrderStatusBean">
        SELECT
            SUM(IF(a.status = 'ING', 1, 0)) AS 'ping',
            SUM(IF(a.status = 'END' AND b.order_status IN ('FWZ','YCD'), 1, 0)) AS 'pend'
        FROM
            websit_parts_apply a JOIN pg_order_base b
        WHERE
            a.create_by_id = #{userId}
            AND a.status IN ('ING', 'END')
    </select>

</mapper>