| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- #include "StdAfx.h"
- #include "AgentOffice.h"
- #include "Agent.h"
- #include "AcdCore.h"
- #include "ExtenCtrl.h"
- #include "MsgCenter.h"
- CAgentOffice::CAgentOffice(void)
- {
- }
- CAgentOffice::~CAgentOffice(void)
- {
-
- }
- /*****************************************************************
- **【函数名称】 getAgentById
- **【函数功能】 根据工号查找座席对象
- **【参数】 AgentId: 要查找的座席工号
- **【返回值】 对应工号的座席对象
- ****************************************************************/
- CAgent* CAgentOffice::getAgentById( UINT AgentId )
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- CAgent* pAgent = NULL;
- m_AgentMap.Lookup(AgentId, pAgent);
- return pAgent;
- }
- /*****************************************************************
- **【函数名称】 getAgentByExt
- **【函数功能】 根据分机号查找座席对象
- **【参数】
- **【返回值】 对应工号的座席对象
- ****************************************************************/
- CAgent* CAgentOffice::getAgentByExt( UINT AgentId, UINT ExtenId )
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- CAgent* pAgent = NULL;
- if(m_AgentMap.Lookup(AgentId, pAgent))
- {
- if(pAgent->assoExten() == ExtenId)
- return pAgent;
- }
- return NULL;
- }
- /*****************************************************************
- **【函数名称】 getAgentByIp
- **【函数功能】 根据工号及IP查找座席对象
- **【参数】 AgentId: 要查找的座席工号
- AgentIp: 座席IP
- **【返回值】 对应工号及IP的座席对象
- ****************************************************************/
- CAgent* CAgentOffice::getAgentByIp( UINT AgentId, const CString& AgentIp )
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- CAgent* pAgent = NULL;
- if(m_AgentMap.Lookup(AgentId, pAgent))
- {
- if(pAgent->ip() == AgentIp)
- return pAgent;
- }
- return NULL;
- }
- /*****************************************************************
- **【函数名称】 getAgentInfo
- **【函数功能】 获取坐席信息
- **【参数】
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::getAgentInfo( Agent2Show& Info )
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- CAgent* pAgent = NULL;
- if(m_AgentMap.Lookup(Info.AgentId, pAgent))
- {
- Info.ExtId = pAgent->assoExten();
- Info.GroupNo = pAgent->group();
- Info.AgentType = pAgent->type();
- Info.State = pAgent->state();
- return TRUE;
- }
-
- return FALSE;
- }
- /*****************************************************************
- **【函数名称】 close
- **【函数功能】 释放资源
- **【参数】
- **【返回值】
- ****************************************************************/
- void CAgentOffice::close( void )
- {
- clearAgent();
- }
- /*****************************************************************
- **【函数名称】 clearAgent
- **【函数功能】 清理所有座席
- **【参数】
- **【返回值】
- ****************************************************************/
- void CAgentOffice::clearAgent( void )
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- UINT Key;
- CAgent* pAgent;
- POSITION Pos = m_AgentMap.GetStartPosition();
- // 清除所有座席
- while(Pos != NULL)
- {
- m_AgentMap.GetNextAssoc(Pos, Key, pAgent);
- ASSERT(pAgent != NULL);
- CAcdCore::GetInstance().getQueueMgr().delAgent(pAgent); // 从排队队列中删除
- pAgent->release(0);
- delete pAgent;
- }
- m_AgentMap.RemoveAll();
-
- }
- /*****************************************************************
- **【函数名称】 insertAgent
- **【函数功能】 座席状态变化的对应处理
- **【参数】 a_AgentID 座席工号
- a_ExtID 分机号
- a_GroupID 座席组号
- a_AgentType 座席类型
- a_TimeOverWork 话后处理时长
- a_ExtStatus 关联的分机状态
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::insertAgent( UINT a_AgentID, UINT a_ExtID, LPCTSTR a_GroupID, UINT a_AgentType, UINT a_TimePostProcessing, INNER_STATE a_ExtStatus )
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- // 查找是否存在当前座席
- if(isAgentExisted(a_AgentID))
- return FALSE;
- // 保存对象
- CAgent* pAgent = new CAgent(a_AgentID, a_ExtID, a_GroupID, a_AgentType, a_TimePostProcessing);
- m_AgentMap.SetAt(pAgent->id(), pAgent); // 座席添加到全体座席索引
-
- CAcdCore::GetInstance().getQueueMgr().addAgent(pAgent);
- pAgent->onAssoExtStatusUpdated(a_ExtStatus);// 设置座席当前状态
- return TRUE;
- }
- /*****************************************************************
- **【函数名称】 isAgentExisted
- **【函数功能】 指定工号的座席是否存在
- **【参数】 a_AgentId: 要查找的座席工号
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::isAgentExisted( UINT a_AgentId )
- {
- return getAgentById(a_AgentId) == NULL ? FALSE : TRUE;
- }
- /*****************************************************************
- **【函数名称】 isAgentExisted
- **【函数功能】 指定工号及IP的座席是否存在
- **【参数】 a_AgentId: 要查找的座席工号
- a_AgentIp: 要查找的座席IP
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::isAgentExisted( UINT a_AgentId, const CString& a_AgentIp )
- {
- return getAgentByIp(a_AgentId, a_AgentIp) == NULL ? FALSE : TRUE;
- }
- /*****************************************************************
- **【函数名称】 removeAgent
- **【函数功能】 删除指定座席
- **【参数】 a_AgentID: 座席工号
- a_HostAgent: 主控制坐席工号
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::removeAgent( UINT a_AgentID, UINT a_HostAgent )
- {
- CAgent* pAgent = NULL;
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- if(m_AgentMap.Lookup(a_AgentID, pAgent))
- {
- CAcdCore::GetInstance().getQueueMgr().delAgent(pAgent);
- m_AgentMap.RemoveKey(a_AgentID); // 从全体座席索引中删除
- pAgent->release(a_HostAgent);
- delete pAgent;
- return TRUE;
- }
- return FALSE;
- }
- /*****************************************************************
- **【函数名称】 getAgentAssoExten
- **【函数功能】 查找座席对应的分机号
- **【参数】 a_AgentID: 座席工号
- **【返回值】 该座席关联的分机号
- ****************************************************************/
- UINT CAgentOffice::getAgentAssoExten( UINT a_AgentID )
- {
- CAgent* pAgent = getAgentById(a_AgentID);
- return pAgent == NULL ? 0 : pAgent->assoExten();
- }
- /*****************************************************************
- **【函数名称】 getAgentGroup
- **【函数功能】 查找座席对应的类型
- **【参数】 a_AgentID: 座席工号
- **【返回值】 该座席关联的类型
- ****************************************************************/
- UINT CAgentOffice::getAgentType( UINT a_AgentID )
- {
- CAgent* pAgent = getAgentById(a_AgentID);
- return pAgent == NULL ? 0 : pAgent->type();
- }
- /*****************************************************************
- **【函数名称】 getAgentState
- **【函数功能】 查找指定座席的当前状态
- **【参数】 a_AgentID: 座席工号
- **【返回值】 该座席当前状态
- ****************************************************************/
- UINT CAgentOffice::getAgentState( UINT a_AgentID )
- {
- CAgent* pAgent = getAgentById(a_AgentID);
- return pAgent == NULL ? AGENT_STATE_UNKNOWN : pAgent->state();
- }
- /*****************************************************************
- **【函数名称】 isAgentRepose
- **【函数功能】 查找指定座席是否是置忙状态
- **【参数】 a_AgentID: 座席工号
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::isAgentRepose( UINT a_AgentID )
- {
- CAgent* pAgent = getAgentById(a_AgentID);
- return pAgent == NULL ? FALSE : pAgent->isRepose();
- }
- /*****************************************************************
- **【函数名称】 lockAgent
- **【函数功能】 临时对座席进行锁定
- **【参数】 a_AgentId: 座席工号
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::lockAgent( UINT a_AgentId )
- {
- CAgent* pAgent = getAgentById(a_AgentId);
- if(pAgent != NULL)
- return pAgent->lock();
- else
- return FALSE;
- }
- /*****************************************************************
- **【函数名称】 setAgentState4Calling
- **【函数功能】 为外呼设置座席状态
- **【参数】 a_AgentId: 座席工号
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::setAgentState4Calling(UINT a_AgentId)
- {
- CAgent* pAgent = getAgentById(a_AgentId);
- ASSERT(pAgent != NULL);
- if (pAgent == NULL)
- return FALSE;
- // 确保一下座席状态空闲
- // ych 2018.7.11
- //if (!pAgent->setState(AGENT_STATE_FREE))
- if(!pAgent->setFreeForAgentCall())
- return FALSE;
- return pAgent->lockForCall();
- //return pAgent->lock();
- }
- /*****************************************************************
- **【函数名称】 onExtenStateUpdated
- **【函数功能】 分机状态变化事件响应
- **【参数】 a_pCmd: PDU命令内容
- **【返回值】
- ****************************************************************/
- void CAgentOffice::onExtenStateUpdated( UINT a_AgentID, CPduEntity* a_pCmd )
- {
- CAgent* pAgent = getAgentByExt(a_AgentID, a_pCmd->GetDataUInt(0));
- if(pAgent != NULL)
- pAgent->onAssoExtStatusUpdated((INNER_STATE)a_pCmd->GetDataUInt(1), a_pCmd);
- }
- /*****************************************************************
- **【函数名称】 setAgentState
- **【函数功能】 设置指定座席的逻辑状态
- **【参数】 a_AgentId: 座席工号
- a_AgentState: 座席状态
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::setAgentState( UINT a_AgentID, AGENT_STATE a_AgentStatus )
- {
- CAgent* pAgent = getAgentById(a_AgentID);
- ASSERT(pAgent != NULL);
- if(pAgent != NULL)
- return pAgent->setState(a_AgentStatus);
- else
- return FALSE;
- }
- /*****************************************************************
- **【函数名称】 isNoAgent
- **【函数功能】 是否无座席签入
- **【参数】
- **【返回值】
- ****************************************************************/
- BOOL CAgentOffice::isNoAgent( void )
- {
- return (m_AgentMap.GetCount() == 0) ? TRUE : FALSE;
- }
- /*****************************************************************
- **【函数名称】 getStateSpecAgentList
- **【函数功能】 获取指定状态的座席列表
- **【参数】 SpecState: 指定状态
- **【返回值】 座席工号字符串列表,以 | 进行分隔
- ****************************************************************/
- void CAgentOffice::getStateSpecAgentList( AGENT_LIST_SPEC_STATE SpecState, CString& AgentList )
- {
- AgentList = _T("");
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- UINT Key;
- CAgent* pAgent;
- POSITION pos = m_AgentMap.GetStartPosition();
- while(pos != NULL)
- {
- bool IsInsert = false;
- m_AgentMap.GetNextAssoc(pos, Key, pAgent);
- ASSERT(pAgent != NULL);
- switch(SpecState)
- {
- case AGENT_LIST_FREE: // 空闲座席列表
- if(pAgent->state() == AGENT_STATE_FREE)
- IsInsert = true;
- break;
- case AGENT_LIST_BUSY: // 忙
- if(pAgent->state() != AGENT_STATE_FREE && pAgent->state() != AGENT_STATE_LOGOUT)
- IsInsert = true;
- break;
- case AGENT_LIST_TALKING: // 通话
- if(pAgent->state() == AGENT_STATE_BUSY)
- IsInsert = true;
- break;
- case AGENT_LIST_ALTERING: // 来电振铃
- if(CAcdCore::GetInstance().getExtenCtrl().getExtenState(pAgent->assoExten()) == INNER_STATE_ALERTING)
- IsInsert = true;
- break;
- } // end switch
- // 如果是指定状态的座席
- if(IsInsert)
- {
- CString block;
- block.Format(_T("%lu,%lu"), pAgent->id(), pAgent->assoExten());
- if(AgentList.GetLength() != 0)
- AgentList += _T("|");
- AgentList += block;
- } // end if
- } // end while
- }
- void CAgentOffice::getAllAgentStateList(CString & AgentList)
- {
- CSingleLock Lock(&m_Cs4AgentMap, TRUE);
- UINT Key;
- CAgent* pAgent;
- POSITION pos = m_AgentMap.GetStartPosition();
- while (pos != NULL)
- {
- m_AgentMap.GetNextAssoc(pos, Key, pAgent);
- CString agent;
- agent.Format("%d,%d,%d,%s|", pAgent->id(),pAgent->assoExten(),pAgent->state(),pAgent->group());
- AgentList += agent;
- }
- }
- std::vector<int> CAgentOffice::getAgentIDAll()
- {
- UINT id = 0;
- CAgent* agent = NULL;
- std::vector<int> VecInt;
- POSITION pos = m_AgentMap.GetStartPosition();
- while (pos)
- {
- m_AgentMap.GetNextAssoc(pos, id, agent);
- int AgentID = agent->id();
- VecInt.push_back(AgentID);
- }
- return VecInt;
- }
|