/************************************************************************/ /* Copyright (C), 2016-2020, [IT], 保留所有权利; /* 模 块 名:; /* 描 述:; /* /* 版 本:[V]; /* 作 者:[IT]; /* 日 期:[9/20/2016]; /* /* /* 注 意:; /* /* 修改记录:[IT]; /* 修改日期:; /* 修改版本:; /* 修改内容:; /************************************************************************/ #ifndef __ODBCPTR_20160920__ #define __ODBCPTR_20160920__ //class CDatabase; #include "IWxAdoInterface.h" #include "CUniqueId.h" #pragma once class /*AFX_EXT_CLASS*/ CWxAdoImpl:public IWxAdoInterface { CWxAdoImpl(void); public: ~CWxAdoImpl(void); ULONG STDMETHODCALLTYPE AddRef( ); ULONG STDMETHODCALLTYPE Release( ); HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refiid, void **ppvObject); // 获取实例指针; static CWxAdoImpl* GetInstance(){ if ( m_pInstance == NULL ) m_pInstance = new CWxAdoImpl; return m_pInstance; } private: volatile LONG m_nRef; volatile LONG m_nObjRef; // 单例实例; static CWxAdoImpl* m_pInstance; CUniqueId m_uniqueid; void SolveDBError( IN CONST DWORD &dwError, IN LPVOID pDBConn); public: // 获取唯一的ID值; TString GetUID() { // 如果存在, 或者异常,新建spid; TCHAR szUid[50] = { 0 }; _ui64tot_s(m_uniqueid.get_unique_id(), szUid, 50, 10); return szUid; } // 将字符串形式的UTC时间转成本地时间; static TString UTCToLocaltime(LPCTSTR lpszUTCTime) { struct tm t; memset(&t, 0, sizeof(t)); t.tm_year = atoi(lpszUTCTime) - 1900; t.tm_mon = atoi(lpszUTCTime + 5) - 1; t.tm_mday = atoi(lpszUTCTime + 8); t.tm_hour = atoi(lpszUTCTime + 11); t.tm_min = atoi(lpszUTCTime + 14); t.tm_sec = atoi(lpszUTCTime + 17); TString local_time_str = _T(""); time_t tt = _mkgmtime64(&t); if (tt != -1) { t = *localtime(&tt); TCHAR szlocaltime[36] = { 0 }; _stprintf_s(szlocaltime, _T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"), t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec); local_time_str.append(szlocaltime); } return local_time_str; } static TString LocaltimeToUTC() { } // 获取当前时间,以UTC字符串返回; static TString GetCurrentUTC() { // 获取今年年份; __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳); struct tm utc = { 0 }; gmtime_s(&utc, &gmt); // 时间戳转成UTC时间(也叫GMT时间); TString UTC = _T(""); TCHAR szUTCTime[36] = { 0 }; _stprintf_s(szUTCTime, _T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"), utc.tm_year + 1900, utc.tm_mon + 1, utc.tm_mday, utc.tm_hour, utc.tm_min,utc.tm_sec); UTC.append(szUTCTime); return UTC; } static TString GetCurrentLocalTime() { // 获取今年年份; __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳); struct tm _localtime = { 0 }; localtime_s(&_localtime, &gmt); // 时间戳转成本地时间; TString local_time_str = _T(""); TCHAR szlocaltime[36] = { 0 }; _stprintf_s(szlocaltime, _T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"), _localtime.tm_year + 1900, _localtime.tm_mon + 1, _localtime.tm_mday, _localtime.tm_hour, _localtime.tm_min, _localtime.tm_sec); local_time_str.append(szlocaltime); return local_time_str; } public: // 初始化所有连接; DWORD InitializePool( IN LPCTSTR lpDBType, IN LPCTSTR lpDBSource, IN CONST DWORD &dwDBPort, IN LPCTSTR lpDBAccount, IN LPCTSTR lpPassWord, IN LPCTSTR lpDBName, IN CONST INT &nMinConn = 1, IN CONST INT &nMaxConn = 5 ); // 关闭所有连接; void ReleasePool(); BOOL ExecuteSQL( IN LPCTSTR lpExcuteSQL, IN CONST DWORD &dwTimeOut = 30000 ); BOOL IsUserExist( IN LPCTSTR lpPhone, IN LPCTSTR lpPassword, OUT LPVOID lpOutValue,IN CONST DWORD &dwTimeOut = 3000 ); INT QueryUserDetail(IN LPCTSTR lpPhone, IN LPVOID lpOutValue, IN CONST DWORD& dwTimeOut = 3000); INT QueryRecordOfType(IN LPCTSTR lpCustomerId, IN LPVOID lpOutValue, IN CONST DWORD& dwTimeOut = 3000); INT QueryRecordOfReply(IN LPCTSTR lpCustomerId, IN LPCTSTR lpTypeId, IN LPVOID lpOutValue, IN CONST DWORD& dwTimeOut = 3000); BOOL AddCustomer(IN LPVOID lpCustomerInfo, IN CONST DWORD& dwTimeOut = 3000); BOOL AddType(IN LPVOID lpTypeInfo, IN CONST DWORD& dwTimeOut = 3000); BOOL AddReply(IN LPVOID lpReplyInfo, IN CONST DWORD& dwTimeOut = 3000); BOOL UpdateCustomer(IN LPVOID lpCustomerInfo, IN CONST DWORD& dwTimeOut = 3000); }; #endif