| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- #include "StdAfx.h"
- #include "SubjectRepository.h"
- #include "AgentOffice.h"
- #include "ExtenCtrl.h"
- #include "QueueMgr.h"
- #include "SubjectAgentState.h"
- #include "SubjectPhoneState.h"
- #include "SubjectIncomingCall.h"
- #include "SubjectAgentsOnSpecState.h"
- #include "SubjectTrunkUsageOfTask.h"
- CSubjectRepository::CSubjectRepository(CAgentOffice* pAgentOffice, CExtenCtrl* pExtenCtrl, CQueueMgr* pQueueMgr) :
- m_pAgentOffice(pAgentOffice), m_pExtenCtrl(pExtenCtrl), m_pQueueMgr(pQueueMgr)
- {
- __initSubjectMap();
- }
- CSubjectRepository::~CSubjectRepository(void)
- {
- __clearSubjectMap();
- }
- /*****************************************************************
- **【函数名称】 __initSubjectMap
- **【函数功能】 初始化主题索引表
- **【参数】
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::__initSubjectMap( void )
- {
- CSubject* pSubject = NULL;
- // 座席状态主题
- pSubject = new CSubjectAgentState(this);
- m_SubjectMap.SetAt(SUBJECT_AGENT_STATUS, pSubject);
- // 分机状态主题
- pSubject = new CSubjectPhoneState(this);
- m_SubjectMap.SetAt(SUBJECT_PHONE_STATUS, pSubject);
- // 来电排队信息主题
- pSubject = new CSubjectIncomingCall(this);
- m_SubjectMap.SetAt(SUBJECT_CALL_QUEUED_NUM, pSubject);
- // 空闲座席列表主题
- pSubject = new CSubjectAgentsOnSpecState(this);
- m_SubjectMap.SetAt(SUBJECT_AGENT_FREE_LIST, pSubject);
- // 忙座席列表主题
- pSubject = new CSubjectAgentsOnSpecState(this);
- m_SubjectMap.SetAt(SUBJECT_AGENT_BUSY_LIST, pSubject);
- // 通话座席列表主题
- pSubject = new CSubjectAgentsOnSpecState(this);
- m_SubjectMap.SetAt(SUBJECT_AGENT_TALKING_LIST, pSubject);
- // 来电振铃座席列表主题
- pSubject = new CSubjectAgentsOnSpecState(this);
- m_SubjectMap.SetAt(SUBJECT_AGENT_ALTERING_LIST, pSubject);
- // 呼叫任务外线利用率主题
- pSubject = new CSubjectTrunkUsageOfTask(this);
- m_SubjectMap.SetAt(SUBJECT_TASK_TRUNK_USAGE, pSubject);
- }
- /*****************************************************************
- **【函数名称】 __clearSubjectMap
- **【函数功能】 清空主题索引表
- **【参数】
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::__clearSubjectMap( void )
- {
- POSITION pos = m_SubjectMap.GetStartPosition();
- while(pos != NULL)
- {
- UINT Key = 0;
- CSubject* pSubject = NULL;
- m_SubjectMap.GetNextAssoc(pos, Key, pSubject);
- delete pSubject;
- } // end while
- m_SubjectMap.RemoveAll();
- }
- /*****************************************************************
- **【函数名称】 __getSubject
- **【函数功能】 得到指定类型的主题
- **【参数】 Type: 主题类型
- **【返回值】
- ****************************************************************/
- CSubject* CSubjectRepository::__getSubject( SUBJECT_TYPE Type )
- {
- CSubject* pSubject = NULL;
- m_SubjectMap.Lookup(Type, pSubject);
- ASSERT(pSubject != NULL);
- return pSubject;
- }
- /*****************************************************************
- **【函数名称】 registObserver
- **【函数功能】 注册订阅
- **【参数】 AgentId: 观查者座席工号
- Type: 订阅的主题类型
- Date: 订阅参数
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::registObserver( UINT AgentId, SUBJECT_TYPE Type, int Data )
- {
- CSubject* pSubject = NULL;
- m_SubjectMap.Lookup(Type, pSubject);
- ASSERT(pSubject != NULL);
- if(pSubject != NULL)
- {
- m_RegistLock.Lock();
- pSubject->registObserver(AgentId, Data, Type);
- m_RegistLock.Unlock();
- }
- }
- /*****************************************************************
- **【函数名称】 removeObserver
- **【函数功能】 取消订阅
- **【参数】 AgentId: 观查者座席工号
- Type: 取消订阅的主题类型
- Data: 取消订阅参数
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::removeObserver( UINT AgentId, SUBJECT_TYPE Type, int Data )
- {
- CSubject* pSubject = NULL;
- m_SubjectMap.Lookup(Type, pSubject);
- ASSERT(pSubject != NULL);
- if(pSubject != NULL)
- {
- m_RegistLock.Lock();
- pSubject->removeObserver(AgentId, Data);
- m_RegistLock.Unlock();
- }
- }
- /*****************************************************************
- **【函数名称】 clearObserver
- **【函数功能】 清除指定座席的所有订阅
- **【参数】 AgentId: 座席工号
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::clearObserver( UINT AgentId )
- {
- POSITION pos = m_SubjectMap.GetStartPosition();
- while(pos != NULL)
- {
- UINT Key = 0;
- CSubject* pSubject = NULL;
- m_SubjectMap.GetNextAssoc(pos, Key, pSubject);
- pSubject->removeObserver(AgentId, -1);
- } // end while
- }
- /*****************************************************************
- **【函数名称】 onAgentStateUpdated
- **【函数功能】 座席状态变化事件响应
- **【参数】 Id: 座席工号
- ExtId: 分机号
- State: 座席当前状态
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::onAgentStateUpdated( UINT Id, UINT ExtId, int State )
- {
- EventSubject info;
- CSubject* pSubject = NULL;
- // 触发座席状态订阅事件
- pSubject = __getSubject(SUBJECT_AGENT_STATUS);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(Id, ExtId, SUBJECT_AGENT_STATUS, State, &info))
- pSubject->onEvent(&info);
- } // end if
- // 触发空闲座席列表变化事件
- pSubject = __getSubject(SUBJECT_AGENT_FREE_LIST);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_FREE_LIST, 0, &info))
- pSubject->onEvent(&info);
- } // end if
- // 触发忙座席列表变化事件
- pSubject = __getSubject(SUBJECT_AGENT_BUSY_LIST);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_BUSY_LIST, 0, &info))
- pSubject->onEvent(&info);
- } // end if
- // 触发来电振铃座席列表变化事件
- pSubject = __getSubject(SUBJECT_AGENT_ALTERING_LIST);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_ALTERING_LIST, 0, &info))
- pSubject->onEvent(&info);
- } // end if
- // 触发空闲通话列表变化事件
- pSubject = __getSubject(SUBJECT_AGENT_TALKING_LIST);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_TALKING_LIST, 0, &info))
- pSubject->onEvent(&info);
- } // end if
- }
- /*****************************************************************
- **【函数名称】 onPhoneStateUpdated
- **【函数功能】 分机状态变化事件响应
- **【参数】 Id: 分机关联座席工号
- ExtId: 分机号
- State: 分机当前状态
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::onPhoneStateUpdated( UINT Id, UINT ExtId, int State )
- {
- // 只处理已关联座席的分机
- if(Id == 0)
- return;
- // 触发分机状态订阅事件
- EventSubject info;
- CSubject* pSubject = __getSubject(SUBJECT_PHONE_STATUS);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(Id, ExtId, SUBJECT_PHONE_STATUS, State, &info))
- pSubject->onEvent(&info);
- } // end if
- }
- /*****************************************************************
- **【函数名称】 onQueueStateUpdated
- **【函数功能】 排队状态变化事件响应
- **【参数】 Count: 等待排队的呼叫数量
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::onQueueStateUpdated( UINT QueueNo, UINT Count )
- {
- // 触发来电呼叫数量变化订阅事件
- EventSubject info;
- CSubject* pSubject = __getSubject(SUBJECT_CALL_QUEUED_NUM);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(QueueNo, 0, SUBJECT_CALL_QUEUED_NUM, Count, &info))
- pSubject->onEvent(&info);
- } // end if
- }
- /*****************************************************************
- **【函数名称】 onTrunkUsageUpdated
- **【函数功能】 呼叫任务外线利用率变化事件响应
- **【参数】
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::onTrunkUsageUpdated( UINT TaskId, UINT Usage )
- {
- // 呼叫任务外线利用率变化订阅事件
- EventSubject info;
- CSubject* pSubject = __getSubject(SUBJECT_TASK_TRUNK_USAGE);
- if(pSubject != NULL)
- {
- if(pSubject->incodeEvent(TaskId, 0, SUBJECT_TASK_TRUNK_USAGE, Usage, &info))
- pSubject->onEvent(&info);
- } // end if
- }
- /*****************************************************************
- **【函数名称】 getAgentAssoExten
- **【函数功能】 得到指定座席的关联分机号
- **【参数】 AgentId: 座席工号
- **【返回值】
- ****************************************************************/
- UINT CSubjectRepository::getAgentAssoExten( UINT AgentId )
- {
- return m_pAgentOffice->getAgentAssoExten(AgentId);
- }
- /*****************************************************************
- **【函数名称】 getAgentAssoExtStatus
- **【函数功能】 得到指定座席的关联分机状态
- **【参数】 AgentId: 座席工号
- **【返回值】
- ****************************************************************/
- UINT CSubjectRepository::getAgentAssoExtState( UINT AgentId )
- {
- UINT ExtId = m_pAgentOffice->getAgentAssoExten(AgentId);
- return m_pExtenCtrl->getExtenState(ExtId);
- }
- /*****************************************************************
- **【函数名称】 getAgentStatus
- **【函数功能】 得到指定座席的当前状态
- **【参数】 AgentId: 座席工号
- **【返回值】
- ****************************************************************/
- UINT CSubjectRepository::getAgentState( UINT AgentId )
- {
- return m_pAgentOffice->getAgentState(AgentId);
- }
- /*****************************************************************
- **【函数名称】 getIncomingCallCount
- **【函数功能】 读取等待排队的来电数量
- **【参数】
- **【返回值】
- ****************************************************************/
- UINT CSubjectRepository::getIncomingCallCount( UINT QueueNo )
- {
- return m_pQueueMgr->callCount(QueueNo);
- }
- /*****************************************************************
- **【函数名称】 getStateSpecAgentList
- **【函数功能】 获取指定订阅类型的座席列表
- **【参数】 Type: 订阅类型
- **【返回值】
- ****************************************************************/
- void CSubjectRepository::getStateSpecAgentList( SUBJECT_TYPE Type, CString& AgentList )
- {
- switch(Type)
- {
- case SUBJECT_AGENT_FREE_LIST: // 空闲座席列表
- m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_FREE, AgentList);
- break;
- case SUBJECT_AGENT_BUSY_LIST: // 忙座席列表
- m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_BUSY, AgentList);
- break;
- case SUBJECT_AGENT_ALTERING_LIST: // 来电振铃座席列表
- m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_ALTERING, AgentList);
- break;
- case SUBJECT_AGENT_TALKING_LIST: // 通话座席列表
- m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_TALKING, AgentList);
- break;
- } // end switch
- }
|