升龙物业 老版本 ocx IPO, 加密狗 转值班电话

SubjectRepository.cpp 10KB

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