#include "StdAfx.h" #include "QueueMgr.h" #include "Queue.h" #include "AgentOffice.h" #include "IncomingCall.h" #include "Agent.h" CQueueMgr::CQueueMgr(void) { } CQueueMgr::~CQueueMgr(void) { __freeQueues(); } /***************************************************************** **【函数名称】 __getQueue **【函数功能】 获取指定来电队列 **【参数】 **【返回值】 ****************************************************************/ CQueue* CQueueMgr::__getQueue( int QueueNo, bool NewWhenNull /*= false*/ ) { for(int i = 0; i < m_QueueArray.GetCount(); ++i) { CQueue* pQueue = m_QueueArray[i]; ASSERT(pQueue != NULL); if(pQueue->no() == QueueNo) return pQueue; } if(NewWhenNull) { CQueue* pQueue = new CQueue(QueueNo); m_QueueArray.Add(pQueue); return pQueue; } return NULL; } /***************************************************************** **【函数名称】 __freeQueues **【函数功能】 释放所有来电队列 **【参数】 **【返回值】 ****************************************************************/ void CQueueMgr::__freeQueues( void ) { for(int i = 0; i < m_QueueArray.GetCount(); ++i) { CQueue* pQueue = m_QueueArray[i]; ASSERT(pQueue != NULL); pQueue->clear(); delete pQueue; } m_QueueArray.RemoveAll(); } /***************************************************************** **【函数名称】 onQueueAsking **【函数功能】 IVR请求座席命令响应 **【参数】 pCmd: PDU命令内容 pAgentOffice: 关联的座席管理类 **【返回值】 ****************************************************************/ void CQueueMgr::onQueueAsking( CPduEntity* pCmd ) { UINT QueueNo = pCmd->GetDataUInt(4); CQueue* pQueue = __getQueue(QueueNo, true); ASSERT(pQueue != NULL); ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, "{Queue}: 来电请求排队, Index = %d, CallID = %lu, Group = %lu, VipLevel = %d, CallerNum = %s", pCmd->GetDataInt(1), pCmd->GetDataULong(2), QueueNo, pCmd->GetDataInt(5), pCmd->GetDataString(6)); pQueue->onQueueRequest(pCmd); } /***************************************************************** **【函数名称】 onQueueCancel **【函数功能】 IVR继续请求排队命令响应 **【参数】 pCmd: PDU命令内容 pAgentOffice: 关联的座席管理类 **【返回值】 ****************************************************************/ void CQueueMgr::onQueueCancel( CPduEntity* pCmd ) { ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, "{Queue}: 来电取消排队, Index = %d, CallId = %lu", pCmd->GetDataInt(1), pCmd->GetDataULong(2)); for(int i = 0; i < m_QueueArray.GetCount(); ++i) { if(m_QueueArray[i]->onQueueCancel(pCmd)) return; } } /***************************************************************** **【函数名称】 onQueueContinue **【函数功能】 IVR继续请求排队命令响应 **【参数】 pCmd: 命令内容 pAgentOffice: 关联的座席管理类 **【返回值】 ****************************************************************/ void CQueueMgr::onQueueContinue( CPduEntity* pCmd ) { ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, "{Queue}: 来电继续排队, Index = %d, CallId = %lu, CallerNum = %s", pCmd->GetDataInt(1), pCmd->GetDataULong(2), pCmd->GetDataString(4)); for(int i = 0; i < m_QueueArray.GetCount(); ++i) { if(m_QueueArray[i]->onQueueContinue(pCmd)) return; } } /***************************************************************** **【函数名称】 onQueuePause **【函数功能】 IVR暂停排队命令响应 **【参数】 pCmd: PDU命令内容 pAgentOffice: 关联的座席管理类 **【返回值】 ****************************************************************/ void CQueueMgr::onQueuePause( CPduEntity* pCmd ) { ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, "{Queue}: 来电暂停排队, Index = %d", pCmd->GetDataInt(0)); for(int i = 0; i < m_QueueArray.GetCount(); ++i) { if(m_QueueArray[i]->onQueuePause(pCmd)) return; } } /***************************************************************** **【函数名称】 callCount **【函数功能】 读取等待排队的来电数量 **【参数】 **【返回值】 ****************************************************************/ UINT CQueueMgr::callCount( void ) { UINT Count = 0; for(int i = 0; i < m_QueueArray.GetCount(); ++i) { Count += m_QueueArray[i]->callCount(); } return Count; } /***************************************************************** **【函数名称】 callCount **【函数功能】 读取等待排队的来电数量 **【参数】 **【返回值】 ****************************************************************/ UINT CQueueMgr::callCount( UINT QueueNo ) { CQueue* pQueue = __getQueue(QueueNo); if(pQueue != NULL) return pQueue->callCount(); else return 0; } /***************************************************************** **【函数名称】 clear **【函数功能】 释放资源 **【参数】 **【返回值】 ****************************************************************/ void CQueueMgr::clear( void ) { __freeQueues(); } /***************************************************************** **【函数名称】 getCallInfo **【函数功能】 获取指定呼叫的相关信息用于UI展现 **【参数】 **【返回值】 ****************************************************************/ bool CQueueMgr::getCallInfo( Call2Show& Info ) { for(int i = 0; i < m_QueueArray.GetCount(); ++i) { if(m_QueueArray[i]->getCallInfo(Info)) return true; } return false; } /***************************************************************** **【函数名称】 addAgent **【函数功能】 添加座席 **【参数】 **【返回值】 ****************************************************************/ void CQueueMgr::addAgent( CAgent* pAgent ) { ASSERT(pAgent != NULL); UINT GroupNo = 0; TCHAR AgentGroup[AGENT_GROUP_BUF_LEN] = { 0 }; lstrcpy(AgentGroup, pAgent->group()); AgentGroupNoList& GrouNoList = pAgent->groupNoList(); TCHAR* lpNext = NULL; TCHAR* lpToken = strtok_s(AgentGroup, AGENT_GROUP_SPLIT_FLAG, &lpNext); while(lpToken != NULL) { sscanf_s(lpToken, "%u", &GroupNo); CQueue* pQueue = __getQueue(GroupNo, true); ASSERT(pQueue != NULL); GrouNoList.AddTail(GroupNo); pQueue->addAgent(pAgent); lpToken = strtok_s(NULL, AGENT_GROUP_SPLIT_FLAG, &lpNext); } } /***************************************************************** **【函数名称】 delAgent **【函数功能】 删除座席 **【参数】 **【返回值】 ****************************************************************/ void CQueueMgr::delAgent( CAgent* pAgent ) { AgentGroupNoList& GrouNoList = pAgent->groupNoList(); POSITION Pos = GrouNoList.GetHeadPosition(); while(Pos != NULL) { UINT GroupNo = GrouNoList.GetNext(Pos); CQueue* pQueue = __getQueue(GroupNo); if(pQueue != NULL) pQueue->delAgent(pAgent); } } /***************************************************************** **【函数名称】 onAgentFree **【函数功能】 座席的处理函数 **【参数】 **【返回值】 ****************************************************************/ void CQueueMgr::onAgentFree( CAgent* pAgent ) { CQueue* pQueueDst = NULL; UINT CallCountMax = 0; AgentGroupNoList& GrouNoList = pAgent->groupNoList(); // 查找排队呼叫最多的队列 POSITION Pos = GrouNoList.GetHeadPosition(); while(Pos != NULL) { UINT GroupNo = GrouNoList.GetNext(Pos); CQueue* pQueue = __getQueue(GroupNo); ASSERT(pQueue != NULL); UINT CallCout = pQueue->callCount(); if(CallCout > CallCountMax) { pQueueDst = pQueue; CallCountMax = CallCout; } } if(CallCountMax > 0) pQueueDst->distributeAgent(); }