中间件底层,websocket

Config.cpp 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #include "StdAfx.h"
  2. #include "Config.h"
  3. #include "DBCtrl.h"
  4. #include "Logger.h"
  5. #include "CtiDataDef.h"
  6. SINGLETON_IMPLEMENT(CConfig)
  7. CConfig::CConfig(void) : m_RecFilePath(_T("")), m_RecType(RECORD_TYPE_TRUNK), m_ListenPort(CTI_LISTEN_PORT), m_DevType(DEV_TYPE_IPO), m_IvrFlowNum(0), m_RecFormat(RECORD_FORMAT_MP3)
  8. {
  9. }
  10. CConfig::~CConfig(void)
  11. {
  12. }
  13. /*****************************************************************
  14. **【函数名称】 loadConfig
  15. **【函数功能】 加载配置
  16. **【参数】
  17. **【返回值】 成功TRUE,失败FALSE
  18. ****************************************************************/
  19. bool CConfig::loadConfig()
  20. {
  21. char buff[MAX_BUFF_SIZE] = { 0 };
  22. IOtlConnection* pDbConn = IOtlConnection::getInstance();
  23. // 读取是否使用TTS
  24. //CString strTts = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'UseTts'"));
  25. //m_IsUseTts = atoi(strTts.GetBuffer(0));
  26. // 读取录音类型
  27. m_RecType = (RECORD_TYPE)pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'RecType'"));
  28. // 读取录音格式
  29. m_RecFormat = (RECORD_FORMAT)pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'RecFormat'"));
  30. // 读取录音文件路径
  31. m_RecFilePath = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'RecPath'"));
  32. if (m_RecFilePath == "") m_RecFilePath = DEFAULT_RECORD_PATH;
  33. // 读取日志文件路径
  34. m_LogFilePath = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'LogPath'"));
  35. // 读取Cti监听端口
  36. m_ListenPort = pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'CtiPort'"));
  37. m_WsServerPort = m_ListenPort;
  38. // 服务端ip
  39. m_WsServerIP = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'CtiAddr'"));
  40. // 读取底层设备类型
  41. m_DevType = (DEV_TYPE)pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'DevType'"));
  42. // 读取IVR流程个数
  43. m_IvrFlowNum = pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'IvrFlowCount'"));
  44. if (m_IvrFlowNum <= 0)
  45. {
  46. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: 获取流程数量错误"));
  47. }
  48. // 初始化或清理数据 2022-01-24
  49. pDbConn->CallStoredProc("exec proc_CTIInit");
  50. CString sql;
  51. bool ret = false;
  52. if (DB_SQLServer == IOtlConnection::getInstance()->GetDatabaseType()) {
  53. sql = "if not exists(select * from sys.columns where name='GroupId' and [object_id]=object_id(N'rep_ext_call_in'))"\
  54. "alter table rep_ext_call_in add GroupId varchar(64) null";
  55. ret = pDbConn->ExecCommand(sql);
  56. if (!ret) {
  57. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  58. }
  59. sql = "if not exists(select * from sys.columns where name='GroupId' and [object_id]=object_id(N'rep_ext_call_out')) "\
  60. "alter table rep_ext_call_out add GroupId varchar(64) null";
  61. ret = pDbConn->ExecCommand(sql);
  62. if (!ret) {
  63. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  64. }
  65. sql = "if not exists(select * from sys.columns where name='GroupId' and [object_id]=object_id(N'rep_agent_state')) "\
  66. "alter table rep_agent_state add GroupId varchar(64) null";
  67. ret = pDbConn->ExecCommand(sql);
  68. if (!ret) {
  69. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  70. }
  71. sql = "if not exists(select * from sys.columns where name='ExtId' and [object_id]=object_id(N'rep_agent_state')) "\
  72. "alter table rep_agent_state add ExtId int null";
  73. ret = pDbConn->ExecCommand(sql);
  74. if (!ret) {
  75. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  76. }
  77. sql = "if not exists (select * from sysobjects where id = object_id('rep_service') " \
  78. "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
  79. "create table rep_service(Checkin int, Conversation int )"\
  80. "end";
  81. ret = pDbConn->ExecCommand(sql);
  82. if (!ret) {
  83. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  84. }
  85. sql = "if not exists (select * from sysobjects where id = object_id('rep_wait_count') " \
  86. "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
  87. "create table rep_wait_count(id int, Count int, UpdateTime datetime , primary key (id))" \
  88. "end";
  89. ret = pDbConn->ExecCommand(sql);
  90. if (!ret) {
  91. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  92. }
  93. sql = "if not exists (select * from sysobjects where id = object_id('rep_hangup') " \
  94. "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
  95. "create table rep_hangup(CallID bigint, HangUpType int,primary key (CallID))"\
  96. "end";
  97. ret = pDbConn->ExecCommand(sql);
  98. if (!ret) {
  99. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  100. }
  101. sql = "if not exists (select * from sysobjects where id = object_id('rep_freeswitch') " \
  102. "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
  103. "create table rep_freeswitch(Id int IDENTITY (1, 1), UUId varchar(50), CallID bigint,CreateTime datetime, HupTime datetime,primary key (Id))"\
  104. "end";
  105. ret = pDbConn->ExecCommand(sql);
  106. if (!ret) {
  107. ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
  108. }
  109. }
  110. return true;
  111. }
  112. /*****************************************************************
  113. **【函数名称】 queryLastCallId
  114. **【函数功能】 从数据库查询CALLID
  115. **【参数】
  116. **【返回值】 CallId
  117. ****************************************************************/
  118. ULONG CConfig::queryLastCallId()
  119. {
  120. // 2019-12-27 更改方法,stat_callid表中的callid有可能小于rep_host中的callid
  121. /*CString strQuery = "select value from stat_callid where name = 'callid'";
  122. return IOtlConnection::getInstance()->GetSingleDataInt(strQuery);*/
  123. CString strQuery = "select MAX(CALLID) FROM rep_host";
  124. ULONG MAXCALLID = IOtlConnection::getInstance()->GetSingleDataInt(strQuery);
  125. strQuery = "select value from stat_callid where name = 'callid'";
  126. ULONG CALLID = IOtlConnection::getInstance()->GetSingleDataInt(strQuery);
  127. return MAXCALLID > CALLID ? MAXCALLID : CALLID;
  128. }
  129. /*****************************************************************
  130. **【函数名称】 updateCallId
  131. **【函数功能】 更新数据库中的CALLID
  132. **【参数】 CallId:新的CallID
  133. **【返回值】
  134. ****************************************************************/
  135. void CConfig::updateCallId(ULONG CallId)
  136. {
  137. CString strQuery;
  138. strQuery.Format("update stat_callid set value = %ld where name = 'callid'", CallId);
  139. IOtlConnection::getInstance()->ExecCommand(strQuery);
  140. }