SELECT CC.CUSTOMER_ID AS customerId
FROM CCMS_FULL.CAMPAIGN_CUSTOMER CC
    LEFT JOIN CCMS_FULL.RECEIVE_CUST_LOG CL ON CC.CUSTOMER_ID = CL.CUSTOMER_ID
    LEFT JOIN ACD_FULL.AGENTS AG ON CC.AGENT_ID = AG.AGENT_ID AND CC.CAMPAIGN_ID = AG.CURRENT_CAMPAIGN_ID
WHERE CC.CAMPAIGN_ID = :campaignId
  AND CC.COMPANY_SITE_ID = :companySiteId
  AND CC.IN_CAMPAIGN_STATUS = 1
  AND CL.CUSTOMER_ID IS NULL
  AND CL.END_TIME IS NULL
  AND EXISTS(SELECT 1
        FROM CCMS_FULL.CAMPAIGN_COMPLETE_CODE CCC
        WHERE CC.STATUS = CCC.COMPLETE_VALUE
          AND STATUS = 1
          AND IS_RECALL = 1
          AND COMPLETE_TYPE = 2
          AND COMPANY_SITE_ID = :companySiteId)
  AND CC.RECALL_TIME <= SYSDATE
  AND CC.RECALL_TIME + NUMTODSINTERVAL(:dungSai, 'MINUTE') >= SYSDATE
  AND (AG.CAMPAIGN_SYSTEM_STATUS IS NULL OR AG.CAMPAIGN_SYSTEM_STATUS <> 'AVAILABLE')
