| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- #include "StdAfx.h"
- #include "Config.h"
- #include "DBCtrl.h"
- #include "Logger.h"
- #include "CtiDataDef.h"
- SINGLETON_IMPLEMENT(CConfig)
- 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)
- {
- }
- CConfig::~CConfig(void)
- {
- }
- /*****************************************************************
- **【函数名称】 loadConfig
- **【函数功能】 加载配置
- **【参数】
- **【返回值】 成功TRUE,失败FALSE
- ****************************************************************/
- bool CConfig::loadConfig()
- {
- char buff[MAX_BUFF_SIZE] = { 0 };
- IOtlConnection* pDbConn = IOtlConnection::getInstance();
- // 读取是否使用TTS
- //CString strTts = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'UseTts'"));
- //m_IsUseTts = atoi(strTts.GetBuffer(0));
- // 读取录音类型
- m_RecType = (RECORD_TYPE)pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'RecType'"));
- // 读取录音格式
- m_RecFormat = (RECORD_FORMAT)pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'RecFormat'"));
- // 读取录音文件路径
- m_RecFilePath = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'RecPath'"));
- if (m_RecFilePath == "") m_RecFilePath = DEFAULT_RECORD_PATH;
- // 读取日志文件路径
- m_LogFilePath = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'LogPath'"));
- // 读取Cti监听端口
- m_ListenPort = pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'CtiPort'"));
- m_WsServerPort = m_ListenPort;
- // 服务端ip
- m_WsServerIP = pDbConn->GetSingleDataStr(_T("SELECT value FROM conf_system WHERE name = 'CtiAddr'"));
- // 读取底层设备类型
- m_DevType = (DEV_TYPE)pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'DevType'"));
- // 读取IVR流程个数
- m_IvrFlowNum = pDbConn->GetSingleDataStr2Int(_T("SELECT value FROM conf_system WHERE name = 'IvrFlowCount'"));
- if (m_IvrFlowNum <= 0)
- {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: 获取流程数量错误"));
- }
- // 初始化或清理数据 2022-01-24
- pDbConn->CallStoredProc("exec proc_CTIInit");
- CString sql;
- bool ret = false;
- if (DB_SQLServer == IOtlConnection::getInstance()->GetDatabaseType()) {
- sql = "if not exists(select * from sys.columns where name='GroupId' and [object_id]=object_id(N'rep_ext_call_in'))"\
- "alter table rep_ext_call_in add GroupId varchar(64) null";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists(select * from sys.columns where name='GroupId' and [object_id]=object_id(N'rep_ext_call_out')) "\
- "alter table rep_ext_call_out add GroupId varchar(64) null";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists(select * from sys.columns where name='GroupId' and [object_id]=object_id(N'rep_agent_state')) "\
- "alter table rep_agent_state add GroupId varchar(64) null";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists(select * from sys.columns where name='ExtId' and [object_id]=object_id(N'rep_agent_state')) "\
- "alter table rep_agent_state add ExtId int null";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists (select * from sysobjects where id = object_id('rep_service') " \
- "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
- "create table rep_service(Checkin int, Conversation int )"\
- "end";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists (select * from sysobjects where id = object_id('rep_wait_count') " \
- "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
- "create table rep_wait_count(id int, Count int, UpdateTime datetime , primary key (id))" \
- "end";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists (select * from sysobjects where id = object_id('rep_hangup') " \
- "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
- "create table rep_hangup(CallID bigint, HangUpType int,primary key (CallID))"\
- "end";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- sql = "if not exists (select * from sysobjects where id = object_id('rep_freeswitch') " \
- "and OBJECTPROPERTY(id, 'IsUserTable') = 1) begin " \
- "create table rep_freeswitch(Id int IDENTITY (1, 1), UUId varchar(50), CallID bigint,CreateTime datetime, HupTime datetime,primary key (Id))"\
- "end";
- ret = pDbConn->ExecCommand(sql);
- if (!ret) {
- ILogger::getInstance().log(LOG_CLASS_GENERAL, LOG_LEVEL_ERROR, _T("{Config}: sql失败[%s]sql[%s]"), pDbConn->GetLastError(), sql);
- }
- }
- return true;
- }
- /*****************************************************************
- **【函数名称】 queryLastCallId
- **【函数功能】 从数据库查询CALLID
- **【参数】
- **【返回值】 CallId
- ****************************************************************/
- ULONG CConfig::queryLastCallId()
- {
- // 2019-12-27 更改方法,stat_callid表中的callid有可能小于rep_host中的callid
- /*CString strQuery = "select value from stat_callid where name = 'callid'";
- return IOtlConnection::getInstance()->GetSingleDataInt(strQuery);*/
- CString strQuery = "select MAX(CALLID) FROM rep_host";
- ULONG MAXCALLID = IOtlConnection::getInstance()->GetSingleDataInt(strQuery);
- strQuery = "select value from stat_callid where name = 'callid'";
- ULONG CALLID = IOtlConnection::getInstance()->GetSingleDataInt(strQuery);
- return MAXCALLID > CALLID ? MAXCALLID : CALLID;
- }
- /*****************************************************************
- **【函数名称】 updateCallId
- **【函数功能】 更新数据库中的CALLID
- **【参数】 CallId:新的CallID
- **【返回值】
- ****************************************************************/
- void CConfig::updateCallId(ULONG CallId)
- {
- CString strQuery;
- strQuery.Format("update stat_callid set value = %ld where name = 'callid'", CallId);
- IOtlConnection::getInstance()->ExecCommand(strQuery);
- }
|