| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285 |
- #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();
- }
|