MiddleWares_YiHe 郑州颐和医院随访系统中间件

FlowTemplate.cpp 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #include "StdAfx.h"
  2. #include "FlowTemplate.h"
  3. #include "CellBase.h"
  4. #include "IFlowDataProvider.h"
  5. #include <regex>
  6. CFlowTemplate::CFlowTemplate(void) : m_Type(FLOW_UNKNOWN), m_Concurrency(1)
  7. {
  8. m_CellMap.InitHashTable(MAX_LENGTH_HASH);
  9. }
  10. CFlowTemplate::~CFlowTemplate(void)
  11. {
  12. __release();
  13. }
  14. /*****************************************************************
  15. **【函数名称】 __release
  16. **【函数功能】 释放所有cell
  17. **【参数】
  18. **【返回值】
  19. ****************************************************************/
  20. void CFlowTemplate::__release( void )
  21. {
  22. if(!m_CellMap.IsEmpty())
  23. {
  24. int Key = 0;
  25. CCellBase *pCell = NULL;
  26. POSITION pos = m_CellMap.GetStartPosition();
  27. while(pos != NULL)
  28. {
  29. m_CellMap.GetNextAssoc(pos, Key, pCell);
  30. if(pCell != NULL)
  31. delete pCell;
  32. }
  33. m_CellMap.RemoveAll();
  34. }
  35. }
  36. /*****************************************************************
  37. **【函数名称】 fillData
  38. **【函数功能】 解析流程文件为数据字段赋值
  39. **【参数】 Provider:数据提供者对象
  40. **【返回值】
  41. ****************************************************************/
  42. bool CFlowTemplate::fillData( IFlowDataProvider& Provider )
  43. {
  44. if(!Provider.getData(FLOW_ATTRIBUTE_NAME, m_Name))
  45. return false;
  46. CString Data;
  47. if(!Provider.getData(FLOW_ATTRIBUTE_TYPE, Data))
  48. return false;
  49. if(Data == FLOW_TYPE_STR_NORMAL)
  50. m_Type = FLOW_NORMAL;
  51. else if(Data == FLOW_TYPE_STR_AUTO)
  52. m_Type = FLOW_AUTO;
  53. else
  54. m_Type = FLOW_SUB;
  55. if(!Provider.getData(FLOW_ATTRIBUTE_MATCHED_NUM, m_MatchedNum))
  56. return false;
  57. if(!Provider.getData(FLOW_ATTRIBUTE_ASSO_LINE, m_MatchedLine))
  58. return false;
  59. if(m_Type == FLOW_AUTO)
  60. {
  61. if(!Provider.getData(FLOW_ATTRIBUTE_CONCURRENCY, Data))
  62. return false;
  63. else
  64. {
  65. sscanf_s(Data, _T("%d"), &m_Concurrency);
  66. if(m_Concurrency < 1)
  67. return false;
  68. }
  69. }
  70. return true;
  71. }
  72. /*****************************************************************
  73. **【函数名称】 accept
  74. **【函数功能】 填充cell map
  75. **【参数】 CellPos:节点编号
  76. pCell:节点对象
  77. **【返回值】
  78. ****************************************************************/
  79. void CFlowTemplate::accept( int CellPos, CCellBase* pCell )
  80. {
  81. ASSERT(pCell != NULL);
  82. m_CellMap.SetAt(CellPos, pCell);
  83. }
  84. /*****************************************************************
  85. **【函数名称】 getCellPos
  86. **【函数功能】 根据节点名称查找节点
  87. **【参数】 CellName:节点名称
  88. **【返回值】
  89. ****************************************************************/
  90. int CFlowTemplate::getCellPos( const CString& CellName )
  91. {
  92. int Key = 0;
  93. CCellBase *pCell = NULL;
  94. POSITION pos = m_CellMap.GetStartPosition();
  95. while(pos != NULL)
  96. {
  97. m_CellMap.GetNextAssoc(pos, Key, pCell);
  98. if(pCell->name() == CellName)
  99. return pCell->position();
  100. }
  101. return 0;
  102. }
  103. /*****************************************************************
  104. **【函数名称】 findCell
  105. **【函数功能】 根据节点编号查找节点
  106. **【参数】 CellPos:节点编号
  107. **【返回值】 节点对象
  108. ****************************************************************/
  109. CCellBase* CFlowTemplate::findCell( int CellPos )
  110. {
  111. CCellBase *pCell = NULL;
  112. m_CellMap.Lookup(CellPos, pCell);
  113. if(pCell != NULL)
  114. return pCell->copy();
  115. return NULL;
  116. }
  117. /*****************************************************************
  118. **【函数名称】 matchLine
  119. **【函数功能】 匹配线路
  120. **【参数】 TrunkId:外线Id
  121. **【返回值】 0:不匹配;1:匹配;-1为默认流程
  122. ****************************************************************/
  123. int CFlowTemplate::matchLine( UINT TrunkId )
  124. {
  125. if(m_MatchedLine.IsEmpty())
  126. return 0;
  127. if(m_MatchedLine == "|-1|" )
  128. return -1;
  129. CString Temp;
  130. Temp.Format("|%lu|", TrunkId);
  131. if(m_MatchedLine.Find(Temp) != -1)
  132. return 1;
  133. return 0;
  134. }
  135. /*****************************************************************
  136. **【函数名称】 matchCaller
  137. **【函数功能】 根据主叫号码分析流程的适用性
  138. **【参数】 Caller:主叫号码
  139. **【返回值】 匹配true,否则false
  140. ****************************************************************/
  141. bool CFlowTemplate::matchCaller( LPCTSTR Caller )
  142. {
  143. std::string CallerString(Caller);
  144. std::regex Reg(m_MatchedNum);
  145. std::smatch Res;
  146. bool IsMatched = false;
  147. IsMatched = std::regex_match(CallerString, Res, Reg);
  148. return IsMatched;
  149. }
  150. /*****************************************************************
  151. **【函数名称】 isMatchedPreCall
  152. **【函数功能】 是否适用预测呼叫
  153. **【参数】
  154. **【返回值】 匹配true,否则false
  155. ****************************************************************/
  156. bool CFlowTemplate::isMatchedPreCall( void ) const
  157. {
  158. if(m_MatchedLine.IsEmpty())
  159. return false;
  160. if(m_MatchedLine == "|-2|" )
  161. return true;
  162. else
  163. return false;
  164. }