多数据源中间件标准版1.0

AgentOffice.cpp 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  1. #include "StdAfx.h"
  2. #include "AgentOffice.h"
  3. #include "Agent.h"
  4. #include "AcdCore.h"
  5. #include "ExtenCtrl.h"
  6. #include "MsgCenter.h"
  7. CAgentOffice::CAgentOffice(void)
  8. {
  9. }
  10. CAgentOffice::~CAgentOffice(void)
  11. {
  12. }
  13. /*****************************************************************
  14. **【函数名称】 getAgentById
  15. **【函数功能】 根据工号查找座席对象
  16. **【参数】 AgentId: 要查找的座席工号
  17. **【返回值】 对应工号的座席对象
  18. ****************************************************************/
  19. CAgent* CAgentOffice::getAgentById( UINT AgentId )
  20. {
  21. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  22. CAgent* pAgent = NULL;
  23. m_AgentMap.Lookup(AgentId, pAgent);
  24. return pAgent;
  25. }
  26. /*****************************************************************
  27. **【函数名称】 getAgentByExt
  28. **【函数功能】 根据分机号查找座席对象
  29. **【参数】
  30. **【返回值】 对应工号的座席对象
  31. ****************************************************************/
  32. CAgent* CAgentOffice::getAgentByExt( UINT AgentId, UINT ExtenId )
  33. {
  34. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  35. CAgent* pAgent = NULL;
  36. if(m_AgentMap.Lookup(AgentId, pAgent))
  37. {
  38. if(pAgent->assoExten() == ExtenId)
  39. return pAgent;
  40. }
  41. return NULL;
  42. }
  43. /*****************************************************************
  44. **【函数名称】 getAgentByIp
  45. **【函数功能】 根据工号及IP查找座席对象
  46. **【参数】 AgentId: 要查找的座席工号
  47. AgentIp: 座席IP
  48. **【返回值】 对应工号及IP的座席对象
  49. ****************************************************************/
  50. CAgent* CAgentOffice::getAgentByIp( UINT AgentId, const CString& AgentIp )
  51. {
  52. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  53. CAgent* pAgent = NULL;
  54. if(m_AgentMap.Lookup(AgentId, pAgent))
  55. {
  56. if(pAgent->ip() == AgentIp)
  57. return pAgent;
  58. }
  59. return NULL;
  60. }
  61. /*****************************************************************
  62. **【函数名称】 getAgentInfo
  63. **【函数功能】 获取坐席信息
  64. **【参数】
  65. **【返回值】
  66. ****************************************************************/
  67. BOOL CAgentOffice::getAgentInfo( Agent2Show& Info )
  68. {
  69. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  70. CAgent* pAgent = NULL;
  71. if(m_AgentMap.Lookup(Info.AgentId, pAgent))
  72. {
  73. Info.ExtId = pAgent->assoExten();
  74. Info.GroupNo = pAgent->group();
  75. Info.AgentType = pAgent->type();
  76. Info.State = pAgent->state();
  77. return TRUE;
  78. }
  79. return FALSE;
  80. }
  81. /*****************************************************************
  82. **【函数名称】 close
  83. **【函数功能】 释放资源
  84. **【参数】
  85. **【返回值】
  86. ****************************************************************/
  87. void CAgentOffice::close( void )
  88. {
  89. clearAgent();
  90. }
  91. /*****************************************************************
  92. **【函数名称】 clearAgent
  93. **【函数功能】 清理所有座席
  94. **【参数】
  95. **【返回值】
  96. ****************************************************************/
  97. void CAgentOffice::clearAgent( void )
  98. {
  99. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  100. UINT Key;
  101. CAgent* pAgent;
  102. POSITION Pos = m_AgentMap.GetStartPosition();
  103. // 清除所有座席
  104. while(Pos != NULL)
  105. {
  106. m_AgentMap.GetNextAssoc(Pos, Key, pAgent);
  107. ASSERT(pAgent != NULL);
  108. CAcdCore::GetInstance().getQueueMgr().delAgent(pAgent); // 从排队队列中删除
  109. pAgent->release(0);
  110. delete pAgent;
  111. }
  112. m_AgentMap.RemoveAll();
  113. }
  114. /*****************************************************************
  115. **【函数名称】 insertAgent
  116. **【函数功能】 座席状态变化的对应处理
  117. **【参数】 a_AgentID 座席工号
  118. a_ExtID 分机号
  119. a_GroupID 座席组号
  120. a_AgentType 座席类型
  121. a_TimeOverWork 话后处理时长
  122. a_ExtStatus 关联的分机状态
  123. **【返回值】
  124. ****************************************************************/
  125. BOOL CAgentOffice::insertAgent( UINT a_AgentID, UINT a_ExtID, LPCTSTR a_GroupID, UINT a_AgentType, UINT a_TimePostProcessing, INNER_STATE a_ExtStatus )
  126. {
  127. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  128. // 查找是否存在当前座席
  129. if(isAgentExisted(a_AgentID))
  130. return FALSE;
  131. // 保存对象
  132. CAgent* pAgent = new CAgent(a_AgentID, a_ExtID, a_GroupID, a_AgentType, a_TimePostProcessing);
  133. m_AgentMap.SetAt(pAgent->id(), pAgent); // 座席添加到全体座席索引
  134. CAcdCore::GetInstance().getQueueMgr().addAgent(pAgent);
  135. pAgent->onAssoExtStatusUpdated(a_ExtStatus);// 设置座席当前状态
  136. return TRUE;
  137. }
  138. /*****************************************************************
  139. **【函数名称】 isAgentExisted
  140. **【函数功能】 指定工号的座席是否存在
  141. **【参数】 a_AgentId: 要查找的座席工号
  142. **【返回值】
  143. ****************************************************************/
  144. BOOL CAgentOffice::isAgentExisted( UINT a_AgentId )
  145. {
  146. return getAgentById(a_AgentId) == NULL ? FALSE : TRUE;
  147. }
  148. /*****************************************************************
  149. **【函数名称】 isAgentExisted
  150. **【函数功能】 指定工号及IP的座席是否存在
  151. **【参数】 a_AgentId: 要查找的座席工号
  152. a_AgentIp: 要查找的座席IP
  153. **【返回值】
  154. ****************************************************************/
  155. BOOL CAgentOffice::isAgentExisted( UINT a_AgentId, const CString& a_AgentIp )
  156. {
  157. return getAgentByIp(a_AgentId, a_AgentIp) == NULL ? FALSE : TRUE;
  158. }
  159. /*****************************************************************
  160. **【函数名称】 removeAgent
  161. **【函数功能】 删除指定座席
  162. **【参数】 a_AgentID: 座席工号
  163. a_HostAgent: 主控制坐席工号
  164. **【返回值】
  165. ****************************************************************/
  166. BOOL CAgentOffice::removeAgent( UINT a_AgentID, UINT a_HostAgent )
  167. {
  168. CAgent* pAgent = NULL;
  169. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  170. if(m_AgentMap.Lookup(a_AgentID, pAgent))
  171. {
  172. CAcdCore::GetInstance().getQueueMgr().delAgent(pAgent);
  173. m_AgentMap.RemoveKey(a_AgentID); // 从全体座席索引中删除
  174. pAgent->release(a_HostAgent);
  175. delete pAgent;
  176. return TRUE;
  177. }
  178. return FALSE;
  179. }
  180. /*****************************************************************
  181. **【函数名称】 getAgentAssoExten
  182. **【函数功能】 查找座席对应的分机号
  183. **【参数】 a_AgentID: 座席工号
  184. **【返回值】 该座席关联的分机号
  185. ****************************************************************/
  186. UINT CAgentOffice::getAgentAssoExten( UINT a_AgentID )
  187. {
  188. CAgent* pAgent = getAgentById(a_AgentID);
  189. return pAgent == NULL ? 0 : pAgent->assoExten();
  190. }
  191. /*****************************************************************
  192. **【函数名称】 getAgentGroup
  193. **【函数功能】 查找座席对应的类型
  194. **【参数】 a_AgentID: 座席工号
  195. **【返回值】 该座席关联的类型
  196. ****************************************************************/
  197. UINT CAgentOffice::getAgentType( UINT a_AgentID )
  198. {
  199. CAgent* pAgent = getAgentById(a_AgentID);
  200. return pAgent == NULL ? 0 : pAgent->type();
  201. }
  202. /*****************************************************************
  203. **【函数名称】 getAgentState
  204. **【函数功能】 查找指定座席的当前状态
  205. **【参数】 a_AgentID: 座席工号
  206. **【返回值】 该座席当前状态
  207. ****************************************************************/
  208. UINT CAgentOffice::getAgentState( UINT a_AgentID )
  209. {
  210. CAgent* pAgent = getAgentById(a_AgentID);
  211. return pAgent == NULL ? AGENT_STATE_UNKNOWN : pAgent->state();
  212. }
  213. /*****************************************************************
  214. **【函数名称】 isAgentRepose
  215. **【函数功能】 查找指定座席是否是置忙状态
  216. **【参数】 a_AgentID: 座席工号
  217. **【返回值】
  218. ****************************************************************/
  219. BOOL CAgentOffice::isAgentRepose( UINT a_AgentID )
  220. {
  221. CAgent* pAgent = getAgentById(a_AgentID);
  222. return pAgent == NULL ? FALSE : pAgent->isRepose();
  223. }
  224. /*****************************************************************
  225. **【函数名称】 lockAgent
  226. **【函数功能】 临时对座席进行锁定
  227. **【参数】 a_AgentId: 座席工号
  228. **【返回值】
  229. ****************************************************************/
  230. BOOL CAgentOffice::lockAgent( UINT a_AgentId )
  231. {
  232. CAgent* pAgent = getAgentById(a_AgentId);
  233. if(pAgent != NULL)
  234. return pAgent->lock();
  235. else
  236. return FALSE;
  237. }
  238. /*****************************************************************
  239. **【函数名称】 setAgentState4Calling
  240. **【函数功能】 为外呼设置座席状态
  241. **【参数】 a_AgentId: 座席工号
  242. **【返回值】
  243. ****************************************************************/
  244. BOOL CAgentOffice::setAgentState4Calling(UINT a_AgentId)
  245. {
  246. CAgent* pAgent = getAgentById(a_AgentId);
  247. ASSERT(pAgent != NULL);
  248. if (pAgent == NULL)
  249. return FALSE;
  250. // 确保一下座席状态空闲
  251. // ych 2018.7.11
  252. //if (!pAgent->setState(AGENT_STATE_FREE))
  253. if(!pAgent->setFreeForAgentCall())
  254. return FALSE;
  255. return pAgent->lockForCall();
  256. //return pAgent->lock();
  257. }
  258. /*****************************************************************
  259. **【函数名称】 onExtenStateUpdated
  260. **【函数功能】 分机状态变化事件响应
  261. **【参数】 a_pCmd: PDU命令内容
  262. **【返回值】
  263. ****************************************************************/
  264. void CAgentOffice::onExtenStateUpdated( UINT a_AgentID, CPduEntity* a_pCmd )
  265. {
  266. CAgent* pAgent = getAgentByExt(a_AgentID, a_pCmd->GetDataUInt(0));
  267. if(pAgent != NULL)
  268. pAgent->onAssoExtStatusUpdated((INNER_STATE)a_pCmd->GetDataUInt(1), a_pCmd);
  269. }
  270. /*****************************************************************
  271. **【函数名称】 setAgentState
  272. **【函数功能】 设置指定座席的逻辑状态
  273. **【参数】 a_AgentId: 座席工号
  274. a_AgentState: 座席状态
  275. **【返回值】
  276. ****************************************************************/
  277. BOOL CAgentOffice::setAgentState( UINT a_AgentID, AGENT_STATE a_AgentStatus )
  278. {
  279. CAgent* pAgent = getAgentById(a_AgentID);
  280. ASSERT(pAgent != NULL);
  281. if(pAgent != NULL)
  282. return pAgent->setState(a_AgentStatus);
  283. else
  284. return FALSE;
  285. }
  286. /*****************************************************************
  287. **【函数名称】 isNoAgent
  288. **【函数功能】 是否无座席签入
  289. **【参数】
  290. **【返回值】
  291. ****************************************************************/
  292. BOOL CAgentOffice::isNoAgent( void )
  293. {
  294. return (m_AgentMap.GetCount() == 0) ? TRUE : FALSE;
  295. }
  296. /*****************************************************************
  297. **【函数名称】 getStateSpecAgentList
  298. **【函数功能】 获取指定状态的座席列表
  299. **【参数】 SpecState: 指定状态
  300. **【返回值】 座席工号字符串列表,以 | 进行分隔
  301. ****************************************************************/
  302. void CAgentOffice::getStateSpecAgentList( AGENT_LIST_SPEC_STATE SpecState, CString& AgentList )
  303. {
  304. AgentList = _T("");
  305. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  306. UINT Key;
  307. CAgent* pAgent;
  308. POSITION pos = m_AgentMap.GetStartPosition();
  309. while(pos != NULL)
  310. {
  311. bool IsInsert = false;
  312. m_AgentMap.GetNextAssoc(pos, Key, pAgent);
  313. ASSERT(pAgent != NULL);
  314. switch(SpecState)
  315. {
  316. case AGENT_LIST_FREE: // 空闲座席列表
  317. if(pAgent->state() == AGENT_STATE_FREE)
  318. IsInsert = true;
  319. break;
  320. case AGENT_LIST_BUSY: // 忙
  321. if(pAgent->state() != AGENT_STATE_FREE && pAgent->state() != AGENT_STATE_LOGOUT)
  322. IsInsert = true;
  323. break;
  324. case AGENT_LIST_TALKING: // 通话
  325. if(pAgent->state() == AGENT_STATE_BUSY)
  326. IsInsert = true;
  327. break;
  328. case AGENT_LIST_ALTERING: // 来电振铃
  329. if(CAcdCore::GetInstance().getExtenCtrl().getExtenState(pAgent->assoExten()) == INNER_STATE_ALERTING)
  330. IsInsert = true;
  331. break;
  332. } // end switch
  333. // 如果是指定状态的座席
  334. if(IsInsert)
  335. {
  336. CString block;
  337. block.Format(_T("%lu,%lu"), pAgent->id(), pAgent->assoExten());
  338. if(AgentList.GetLength() != 0)
  339. AgentList += _T("|");
  340. AgentList += block;
  341. } // end if
  342. } // end while
  343. }
  344. void CAgentOffice::getAllAgentStateList(CString & AgentList)
  345. {
  346. CSingleLock Lock(&m_Cs4AgentMap, TRUE);
  347. UINT Key;
  348. CAgent* pAgent;
  349. POSITION pos = m_AgentMap.GetStartPosition();
  350. while (pos != NULL)
  351. {
  352. m_AgentMap.GetNextAssoc(pos, Key, pAgent);
  353. CString agent;
  354. agent.Format("%d,%d,%d,%s|", pAgent->id(),pAgent->assoExten(),pAgent->state(),pAgent->group());
  355. AgentList += agent;
  356. }
  357. }
  358. std::vector<int> CAgentOffice::getAgentIDAll()
  359. {
  360. UINT id = 0;
  361. CAgent* agent = NULL;
  362. std::vector<int> VecInt;
  363. POSITION pos = m_AgentMap.GetStartPosition();
  364. while (pos)
  365. {
  366. m_AgentMap.GetNextAssoc(pos, id, agent);
  367. int AgentID = agent->id();
  368. VecInt.push_back(AgentID);
  369. }
  370. return VecInt;
  371. }