华辉中间件项目(代码服务器上没有,用杨成电脑的源代码上传的)

SubjectRepository.cpp 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. #include "StdAfx.h"
  2. #include "SubjectRepository.h"
  3. #include "AgentOffice.h"
  4. #include "ExtenCtrl.h"
  5. #include "QueueMgr.h"
  6. #include "SubjectAgentState.h"
  7. #include "SubjectPhoneState.h"
  8. #include "SubjectIncomingCall.h"
  9. #include "SubjectAgentsOnSpecState.h"
  10. #include "SubjectTrunkUsageOfTask.h"
  11. CSubjectRepository::CSubjectRepository(CAgentOffice* pAgentOffice, CExtenCtrl* pExtenCtrl, CQueueMgr* pQueueMgr) :
  12. m_pAgentOffice(pAgentOffice), m_pExtenCtrl(pExtenCtrl), m_pQueueMgr(pQueueMgr)
  13. {
  14. __initSubjectMap();
  15. }
  16. CSubjectRepository::~CSubjectRepository(void)
  17. {
  18. __clearSubjectMap();
  19. }
  20. /*****************************************************************
  21. **【函数名称】 __initSubjectMap
  22. **【函数功能】 初始化主题索引表
  23. **【参数】
  24. **【返回值】
  25. ****************************************************************/
  26. void CSubjectRepository::__initSubjectMap( void )
  27. {
  28. CSubject* pSubject = NULL;
  29. // 座席状态主题
  30. pSubject = new CSubjectAgentState(this);
  31. m_SubjectMap.SetAt(SUBJECT_AGENT_STATUS, pSubject);
  32. // 分机状态主题
  33. pSubject = new CSubjectPhoneState(this);
  34. m_SubjectMap.SetAt(SUBJECT_PHONE_STATUS, pSubject);
  35. // 来电排队信息主题
  36. pSubject = new CSubjectIncomingCall(this);
  37. m_SubjectMap.SetAt(SUBJECT_CALL_QUEUED_NUM, pSubject);
  38. // 空闲座席列表主题
  39. pSubject = new CSubjectAgentsOnSpecState(this);
  40. m_SubjectMap.SetAt(SUBJECT_AGENT_FREE_LIST, pSubject);
  41. // 忙座席列表主题
  42. pSubject = new CSubjectAgentsOnSpecState(this);
  43. m_SubjectMap.SetAt(SUBJECT_AGENT_BUSY_LIST, pSubject);
  44. // 通话座席列表主题
  45. pSubject = new CSubjectAgentsOnSpecState(this);
  46. m_SubjectMap.SetAt(SUBJECT_AGENT_TALKING_LIST, pSubject);
  47. // 来电振铃座席列表主题
  48. pSubject = new CSubjectAgentsOnSpecState(this);
  49. m_SubjectMap.SetAt(SUBJECT_AGENT_ALTERING_LIST, pSubject);
  50. // 呼叫任务外线利用率主题
  51. pSubject = new CSubjectTrunkUsageOfTask(this);
  52. m_SubjectMap.SetAt(SUBJECT_TASK_TRUNK_USAGE, pSubject);
  53. // 呼叫任务外线利用率主题 ych 2018.5.5
  54. //pSubject = new CSubjectTrunkUsageOfTask(this);
  55. //m_SubjectMap.SetAt(SUBJECT_TASK_TRUNK_USAGE, pSubject);
  56. }
  57. /*****************************************************************
  58. **【函数名称】 __clearSubjectMap
  59. **【函数功能】 清空主题索引表
  60. **【参数】
  61. **【返回值】
  62. ****************************************************************/
  63. void CSubjectRepository::__clearSubjectMap( void )
  64. {
  65. POSITION pos = m_SubjectMap.GetStartPosition();
  66. while(pos != NULL)
  67. {
  68. UINT Key = 0;
  69. CSubject* pSubject = NULL;
  70. m_SubjectMap.GetNextAssoc(pos, Key, pSubject);
  71. delete pSubject;
  72. } // end while
  73. m_SubjectMap.RemoveAll();
  74. }
  75. /*****************************************************************
  76. **【函数名称】 __getSubject
  77. **【函数功能】 得到指定类型的主题
  78. **【参数】 Type: 主题类型
  79. **【返回值】
  80. ****************************************************************/
  81. CSubject* CSubjectRepository::__getSubject( SUBJECT_TYPE Type )
  82. {
  83. CSubject* pSubject = NULL;
  84. m_SubjectMap.Lookup(Type, pSubject);
  85. ASSERT(pSubject != NULL);
  86. return pSubject;
  87. }
  88. /*****************************************************************
  89. **【函数名称】 registObserver
  90. **【函数功能】 注册订阅
  91. **【参数】 AgentId: 观查者座席工号
  92. Type: 订阅的主题类型
  93. Date: 订阅参数
  94. **【返回值】
  95. ****************************************************************/
  96. void CSubjectRepository::registObserver( UINT AgentId, SUBJECT_TYPE Type, int Data )
  97. {
  98. CSubject* pSubject = NULL;
  99. m_SubjectMap.Lookup(Type, pSubject);
  100. ASSERT(pSubject != NULL);
  101. if(pSubject != NULL)
  102. {
  103. m_RegistLock.Lock();
  104. pSubject->registObserver(AgentId, Data, Type);
  105. m_RegistLock.Unlock();
  106. }
  107. }
  108. /*****************************************************************
  109. **【函数名称】 removeObserver
  110. **【函数功能】 取消订阅
  111. **【参数】 AgentId: 观查者座席工号
  112. Type: 取消订阅的主题类型
  113. Data: 取消订阅参数
  114. **【返回值】
  115. ****************************************************************/
  116. void CSubjectRepository::removeObserver( UINT AgentId, SUBJECT_TYPE Type, int Data )
  117. {
  118. CSubject* pSubject = NULL;
  119. m_SubjectMap.Lookup(Type, pSubject);
  120. ASSERT(pSubject != NULL);
  121. if(pSubject != NULL)
  122. {
  123. m_RegistLock.Lock();
  124. pSubject->removeObserver(AgentId, Data);
  125. m_RegistLock.Unlock();
  126. }
  127. }
  128. /*****************************************************************
  129. **【函数名称】 clearObserver
  130. **【函数功能】 清除指定座席的所有订阅
  131. **【参数】 AgentId: 座席工号
  132. **【返回值】
  133. ****************************************************************/
  134. void CSubjectRepository::clearObserver( UINT AgentId )
  135. {
  136. POSITION pos = m_SubjectMap.GetStartPosition();
  137. while(pos != NULL)
  138. {
  139. UINT Key = 0;
  140. CSubject* pSubject = NULL;
  141. m_SubjectMap.GetNextAssoc(pos, Key, pSubject);
  142. pSubject->removeObserver(AgentId, -1);
  143. } // end while
  144. }
  145. /*****************************************************************
  146. **【函数名称】 onAgentStateUpdated
  147. **【函数功能】 座席状态变化事件响应
  148. **【参数】 Id: 座席工号
  149. ExtId: 分机号
  150. State: 座席当前状态
  151. **【返回值】
  152. ****************************************************************/
  153. void CSubjectRepository::onAgentStateUpdated( UINT Id, UINT ExtId, int State )
  154. {
  155. EventSubject info;
  156. CSubject* pSubject = NULL;
  157. // 触发座席状态订阅事件
  158. pSubject = __getSubject(SUBJECT_AGENT_STATUS);
  159. if(pSubject != NULL)
  160. {
  161. if(pSubject->incodeEvent(Id, ExtId, SUBJECT_AGENT_STATUS, State, &info))
  162. pSubject->onEvent(&info);
  163. } // end if
  164. // 触发空闲座席列表变化事件
  165. pSubject = __getSubject(SUBJECT_AGENT_FREE_LIST);
  166. if(pSubject != NULL)
  167. {
  168. if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_FREE_LIST, 0, &info))
  169. pSubject->onEvent(&info);
  170. } // end if
  171. // 触发忙座席列表变化事件
  172. pSubject = __getSubject(SUBJECT_AGENT_BUSY_LIST);
  173. if(pSubject != NULL)
  174. {
  175. if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_BUSY_LIST, 0, &info))
  176. pSubject->onEvent(&info);
  177. } // end if
  178. // 触发来电振铃座席列表变化事件
  179. pSubject = __getSubject(SUBJECT_AGENT_ALTERING_LIST);
  180. if(pSubject != NULL)
  181. {
  182. if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_ALTERING_LIST, 0, &info))
  183. pSubject->onEvent(&info);
  184. } // end if
  185. // 触发空闲通话列表变化事件
  186. pSubject = __getSubject(SUBJECT_AGENT_TALKING_LIST);
  187. if(pSubject != NULL)
  188. {
  189. if(pSubject->incodeEvent(0, 0, SUBJECT_AGENT_TALKING_LIST, 0, &info))
  190. pSubject->onEvent(&info);
  191. } // end if
  192. }
  193. /*****************************************************************
  194. **【函数名称】 onPhoneStateUpdated
  195. **【函数功能】 分机状态变化事件响应
  196. **【参数】 Id: 分机关联座席工号
  197. ExtId: 分机号
  198. State: 分机当前状态
  199. **【返回值】
  200. ****************************************************************/
  201. void CSubjectRepository::onPhoneStateUpdated( UINT Id, UINT ExtId, int State )
  202. {
  203. // 只处理已关联座席的分机
  204. if(Id == 0)
  205. return;
  206. // 触发分机状态订阅事件
  207. EventSubject info;
  208. CSubject* pSubject = __getSubject(SUBJECT_PHONE_STATUS);
  209. if(pSubject != NULL)
  210. {
  211. if(pSubject->incodeEvent(Id, ExtId, SUBJECT_PHONE_STATUS, State, &info))
  212. pSubject->onEvent(&info);
  213. } // end if
  214. }
  215. /*****************************************************************
  216. **【函数名称】 onQueueStateUpdated
  217. **【函数功能】 排队状态变化事件响应
  218. **【参数】 Count: 等待排队的呼叫数量
  219. **【返回值】
  220. ****************************************************************/
  221. void CSubjectRepository::onQueueStateUpdated( UINT QueueNo, UINT Count )
  222. {
  223. // 触发来电呼叫数量变化订阅事件
  224. EventSubject info;
  225. CSubject* pSubject = __getSubject(SUBJECT_CALL_QUEUED_NUM);
  226. if(pSubject != NULL)
  227. {
  228. if(pSubject->incodeEvent(QueueNo, 0, SUBJECT_CALL_QUEUED_NUM, Count, &info))
  229. pSubject->onEvent(&info);
  230. } // end if
  231. }
  232. /*****************************************************************
  233. **【函数名称】 onTrunkUsageUpdated
  234. **【函数功能】 呼叫任务外线利用率变化事件响应
  235. **【参数】
  236. **【返回值】
  237. ****************************************************************/
  238. void CSubjectRepository::onTrunkUsageUpdated( UINT TaskId, UINT Usage )
  239. {
  240. // 呼叫任务外线利用率变化订阅事件
  241. EventSubject info;
  242. CSubject* pSubject = __getSubject(SUBJECT_TASK_TRUNK_USAGE);
  243. if(pSubject != NULL)
  244. {
  245. if(pSubject->incodeEvent(TaskId, 0, SUBJECT_TASK_TRUNK_USAGE, Usage, &info))
  246. pSubject->onEvent(&info);
  247. } // end if
  248. }
  249. /*****************************************************************
  250. **【函数名称】 getAgentAssoExten
  251. **【函数功能】 得到指定座席的关联分机号
  252. **【参数】 AgentId: 座席工号
  253. **【返回值】
  254. ****************************************************************/
  255. UINT CSubjectRepository::getAgentAssoExten( UINT AgentId )
  256. {
  257. return m_pAgentOffice->getAgentAssoExten(AgentId);
  258. }
  259. /*****************************************************************
  260. **【函数名称】 getAgentAssoExtStatus
  261. **【函数功能】 得到指定座席的关联分机状态
  262. **【参数】 AgentId: 座席工号
  263. **【返回值】
  264. ****************************************************************/
  265. UINT CSubjectRepository::getAgentAssoExtState( UINT AgentId )
  266. {
  267. UINT ExtId = m_pAgentOffice->getAgentAssoExten(AgentId);
  268. return m_pExtenCtrl->getExtenState(ExtId);
  269. }
  270. /*****************************************************************
  271. **【函数名称】 getAgentStatus
  272. **【函数功能】 得到指定座席的当前状态
  273. **【参数】 AgentId: 座席工号
  274. **【返回值】
  275. ****************************************************************/
  276. UINT CSubjectRepository::getAgentState( UINT AgentId )
  277. {
  278. return m_pAgentOffice->getAgentState(AgentId);
  279. }
  280. /*****************************************************************
  281. **【函数名称】 getIncomingCallCount
  282. **【函数功能】 读取等待排队的来电数量
  283. **【参数】
  284. **【返回值】
  285. ****************************************************************/
  286. UINT CSubjectRepository::getIncomingCallCount( UINT QueueNo )
  287. {
  288. return m_pQueueMgr->callCount(QueueNo);
  289. }
  290. /*****************************************************************
  291. **【函数名称】 getStateSpecAgentList
  292. **【函数功能】 获取指定订阅类型的座席列表
  293. **【参数】 Type: 订阅类型
  294. **【返回值】
  295. ****************************************************************/
  296. void CSubjectRepository::getStateSpecAgentList( SUBJECT_TYPE Type, CString& AgentList )
  297. {
  298. switch(Type)
  299. {
  300. case SUBJECT_AGENT_FREE_LIST: // 空闲座席列表
  301. m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_FREE, AgentList);
  302. break;
  303. case SUBJECT_AGENT_BUSY_LIST: // 忙座席列表
  304. m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_BUSY, AgentList);
  305. break;
  306. case SUBJECT_AGENT_ALTERING_LIST: // 来电振铃座席列表
  307. m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_ALTERING, AgentList);
  308. break;
  309. case SUBJECT_AGENT_TALKING_LIST: // 通话座席列表
  310. m_pAgentOffice->getStateSpecAgentList(AGENT_LIST_TALKING, AgentList);
  311. break;
  312. } // end switch
  313. }