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

CellBranch.cpp 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #include "StdAfx.h"
  2. #include "CellBranch.h"
  3. #include "IvrFlow.h"
  4. #include "FlowDataProvider.h"
  5. IMPLEMENT_CELL_AUTOCREATE(CCellBranch, CELL_NAME_BRANCH)
  6. CCellBranch::CCellBranch(void) : m_DefaultPos(0), m_VarName("")
  7. {
  8. }
  9. CCellBranch::CCellBranch( CCellBranch& CellBranch ) : CCellBase(CellBranch)
  10. {
  11. m_VarName = CellBranch.m_VarName;
  12. m_DefaultPos = CellBranch.m_DefaultPos;
  13. POSITION pos = CellBranch.m_BranchList.GetHeadPosition();
  14. while(pos != NULL)
  15. {
  16. BranchInfo *pBranch = CellBranch.m_BranchList.GetNext(pos);
  17. if(pBranch != NULL)
  18. {
  19. BranchInfo *pBranchTemp = new BranchInfo;
  20. if(pBranchTemp != NULL)
  21. {
  22. memset(pBranchTemp, 0, sizeof(BranchInfo));
  23. lstrcpy(pBranchTemp->Value, pBranch->Value);
  24. pBranchTemp->Pos = pBranch->Pos;
  25. m_BranchList.AddTail(pBranchTemp);
  26. }
  27. }
  28. }
  29. }
  30. CCellBranch::~CCellBranch(void)
  31. {
  32. __release();
  33. }
  34. /*****************************************************************
  35. **【函数名称】 __release
  36. **【函数功能】 释放资源
  37. **【参数】
  38. **【返回值】
  39. ****************************************************************/
  40. void CCellBranch::__release( void )
  41. {
  42. if(!m_BranchList.IsEmpty())
  43. {
  44. BranchInfo *pBranch = NULL;
  45. POSITION pos = m_BranchList.GetHeadPosition();
  46. while(pos != NULL)
  47. {
  48. pBranch = m_BranchList.GetNext(pos);
  49. if(pBranch != NULL)
  50. {
  51. delete pBranch;
  52. pBranch = NULL;
  53. }
  54. }
  55. m_BranchList.RemoveAll();
  56. }
  57. }
  58. /*****************************************************************
  59. **【函数名称】 operate
  60. **【函数功能】 节点执行函数
  61. **【参数】
  62. **【返回值】 下一个节点编号
  63. ****************************************************************/
  64. int CCellBranch::operate( void )
  65. {
  66. if(m_pIvrFlow == NULL)
  67. return CELL_OP_ERROR;
  68. CString Info;
  69. _getCellInfo(Info);
  70. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_NORMAL, _T("{Cell}: 开始执行[%s]"), Info);
  71. CString strVarValue = "";
  72. if(m_pIvrFlow->findVarValue(m_VarName, strVarValue))
  73. {
  74. POSITION pos = m_BranchList.GetHeadPosition();
  75. while(pos != NULL)
  76. {
  77. BranchInfo *pBranch = m_BranchList.GetNext(pos);
  78. if(pBranch != NULL )
  79. {
  80. if(strVarValue.Compare(pBranch->Value) == 0)
  81. return pBranch->Pos;
  82. }
  83. }
  84. }
  85. return m_DefaultPos;
  86. }
  87. /*****************************************************************
  88. **【函数名称】 copy
  89. **【函数功能】 拷贝自身
  90. **【参数】
  91. **【返回值】 拷贝副本
  92. ****************************************************************/
  93. CCellBase * CCellBranch::copy( void )
  94. {
  95. CCellBase * pCellBase = new CCellBranch(*this);
  96. return pCellBase;
  97. }
  98. /*****************************************************************
  99. **【函数名称】 fillData
  100. **【函数功能】 节点解析,填充数据
  101. **【参数】 Provider:数据提供器
  102. **【返回值】 成功true,失败false
  103. ****************************************************************/
  104. bool CCellBranch::fillData( IFlowDataProvider& Provider )
  105. {
  106. CString Data;
  107. do
  108. {
  109. if(!Provider.getData(CELL_ATTRIBUTE_POS, Data))
  110. {
  111. Data = _T("节点号");
  112. break;
  113. }
  114. else
  115. {
  116. sscanf_s(Data, _T("%d"), &m_Pos);
  117. if(m_Pos < 1)
  118. {
  119. Data = _T("节点号");
  120. break;
  121. }
  122. }
  123. if(!Provider.getData(CELL_ATTRIBUTE_VAR, m_VarName))
  124. {
  125. Data = _T("分支变量");
  126. break;
  127. }
  128. if(!Provider.getData(CELL_ATTRIBUTE_DEFAULT_POS, Data))
  129. {
  130. Data = _T("默认跳转节点");
  131. break;
  132. }
  133. else
  134. {
  135. sscanf_s(Data, _T("%d"), &m_DefaultPos);
  136. if(m_DefaultPos < 0)
  137. {
  138. Data = _T("默认跳转节点");
  139. break;
  140. }
  141. }
  142. Data.Format(_T("%s[@%s='%d']/%s"), XPATH_CELL, CELL_ATTRIBUTE_POS, m_Pos, FlOW_SUB_NODE_BRANCH);
  143. if(!Provider.getFlowBranch(Data, *this))
  144. {
  145. Data = _T("分支信息");
  146. break;
  147. }
  148. Provider.getData(CELL_ATTRIBUTE_NOTE, m_Note);
  149. return true;
  150. } while (false);
  151. ILogger::getInstance().log(LOG_CLASS_BUSI, LOG_LEVEL_ERROR, _T("{Cell}: 节点[%s]解析失败, '%s'错误"), CELL_NAME_BRANCH, Data);
  152. return false;
  153. }
  154. /*****************************************************************
  155. **【函数名称】 addBranch
  156. **【函数功能】 添加分支信息
  157. **【参数】 Value:分支匹配值
  158. Pos:跳转节点
  159. **【返回值】
  160. ****************************************************************/
  161. void CCellBranch::addBranch( const CString& Value, int Pos )
  162. {
  163. if(Pos < 0)
  164. return;
  165. BranchInfo *pBranch = new BranchInfo;
  166. if(pBranch != NULL)
  167. {
  168. memset(pBranch, 0, sizeof(BranchInfo));
  169. lstrcpy(pBranch->Value, Value);
  170. pBranch->Pos = Pos;
  171. m_BranchList.AddTail(pBranch);
  172. }
  173. }