WxAdoImpl.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /************************************************************************/
  2. /* Copyright (C), 2016-2020, [IT], 保留所有权利;
  3. /* 模 块 名:;
  4. /* 描 述:;
  5. /*
  6. /* 版 本:[V];
  7. /* 作 者:[IT];
  8. /* 日 期:[9/20/2016];
  9. /*
  10. /*
  11. /* 注 意:;
  12. /*
  13. /* 修改记录:[IT];
  14. /* 修改日期:;
  15. /* 修改版本:;
  16. /* 修改内容:;
  17. /************************************************************************/
  18. #ifndef __ODBCPTR_20160920__
  19. #define __ODBCPTR_20160920__
  20. //class CDatabase;
  21. #include "IWxAdoInterface.h"
  22. #include "CUniqueId.h"
  23. #pragma once
  24. class /*AFX_EXT_CLASS*/ CWxAdoImpl:public IWxAdoInterface
  25. {
  26. CWxAdoImpl(void);
  27. public:
  28. ~CWxAdoImpl(void);
  29. ULONG STDMETHODCALLTYPE AddRef( );
  30. ULONG STDMETHODCALLTYPE Release( );
  31. HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refiid, void **ppvObject);
  32. // 获取实例指针;
  33. static CWxAdoImpl* GetInstance(){
  34. if ( m_pInstance == NULL )
  35. m_pInstance = new CWxAdoImpl;
  36. return m_pInstance;
  37. }
  38. private:
  39. volatile LONG m_nRef;
  40. volatile LONG m_nObjRef;
  41. // 单例实例;
  42. static CWxAdoImpl* m_pInstance;
  43. CUniqueId m_uniqueid;
  44. void SolveDBError( IN CONST DWORD &dwError, IN LPVOID pDBConn);
  45. public:
  46. // 获取唯一的ID值;
  47. TString GetUID()
  48. {
  49. // 如果存在, 或者异常,新建spid;
  50. TCHAR szUid[50] = { 0 };
  51. _ui64tot_s(m_uniqueid.get_unique_id(), szUid, 50, 10);
  52. return szUid;
  53. }
  54. // 将字符串形式的UTC时间转成本地时间;
  55. static TString UTCToLocaltime(LPCTSTR lpszUTCTime)
  56. {
  57. struct tm t;
  58. memset(&t, 0, sizeof(t));
  59. t.tm_year = atoi(lpszUTCTime) - 1900;
  60. t.tm_mon = atoi(lpszUTCTime + 5) - 1;
  61. t.tm_mday = atoi(lpszUTCTime + 8);
  62. t.tm_hour = atoi(lpszUTCTime + 11);
  63. t.tm_min = atoi(lpszUTCTime + 14);
  64. t.tm_sec = atoi(lpszUTCTime + 17);
  65. TString local_time_str = _T("");
  66. time_t tt = _mkgmtime64(&t);
  67. if (tt != -1)
  68. {
  69. t = *localtime(&tt);
  70. TCHAR szlocaltime[36] = { 0 };
  71. _stprintf_s(szlocaltime, _T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"), t.tm_year + 1900,
  72. t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min,
  73. t.tm_sec);
  74. local_time_str.append(szlocaltime);
  75. }
  76. return local_time_str;
  77. }
  78. static TString LocaltimeToUTC()
  79. {
  80. }
  81. // 获取当前时间,以UTC字符串返回;
  82. static TString GetCurrentUTC()
  83. {
  84. // 获取今年年份;
  85. __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
  86. struct tm utc = { 0 };
  87. gmtime_s(&utc, &gmt); // 时间戳转成UTC时间(也叫GMT时间);
  88. TString UTC = _T("");
  89. TCHAR szUTCTime[36] = { 0 };
  90. _stprintf_s(szUTCTime, _T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"), utc.tm_year + 1900,
  91. utc.tm_mon + 1, utc.tm_mday, utc.tm_hour, utc.tm_min,utc.tm_sec);
  92. UTC.append(szUTCTime);
  93. return UTC;
  94. }
  95. static TString GetCurrentLocalTime()
  96. {
  97. // 获取今年年份;
  98. __time64_t gmt = time(NULL);// 获取当前日历时间(1900-01-01开始的Unix时间戳);
  99. struct tm _localtime = { 0 };
  100. localtime_s(&_localtime, &gmt); // 时间戳转成本地时间;
  101. TString local_time_str = _T("");
  102. TCHAR szlocaltime[36] = { 0 };
  103. _stprintf_s(szlocaltime, _T("%.4d-%.2d-%.2d %.2d:%.2d:%.2d"), _localtime.tm_year + 1900,
  104. _localtime.tm_mon + 1, _localtime.tm_mday, _localtime.tm_hour, _localtime.tm_min, _localtime.tm_sec);
  105. local_time_str.append(szlocaltime);
  106. return local_time_str;
  107. }
  108. public:
  109. // 初始化所有连接;
  110. DWORD InitializePool(
  111. IN LPCTSTR lpDBType,
  112. IN LPCTSTR lpDBSource,
  113. IN CONST DWORD &dwDBPort,
  114. IN LPCTSTR lpDBAccount,
  115. IN LPCTSTR lpPassWord,
  116. IN LPCTSTR lpDBName,
  117. IN CONST INT &nMinConn = 1,
  118. IN CONST INT &nMaxConn = 5
  119. );
  120. // 关闭所有连接;
  121. void ReleasePool();
  122. BOOL ExecuteSQL( IN LPCTSTR lpExcuteSQL, IN CONST DWORD &dwTimeOut = 30000 );
  123. BOOL IsUserExist( IN LPCTSTR lpPhone, IN LPCTSTR lpPassword, OUT LPVOID lpOutValue,IN CONST DWORD &dwTimeOut = 3000 );
  124. INT QueryUserDetail(IN LPCTSTR lpPhone, IN LPVOID lpOutValue, IN CONST DWORD& dwTimeOut = 3000);
  125. INT QueryRecordOfType(IN LPCTSTR lpCustomerId, IN LPVOID lpOutValue, IN CONST DWORD& dwTimeOut = 3000);
  126. INT QueryRecordOfReply(IN LPCTSTR lpCustomerId, IN LPCTSTR lpTypeId, IN LPVOID lpOutValue, IN CONST DWORD& dwTimeOut = 3000);
  127. BOOL AddCustomer(IN LPVOID lpCustomerInfo, IN CONST DWORD& dwTimeOut = 3000);
  128. BOOL AddType(IN LPVOID lpTypeInfo, IN CONST DWORD& dwTimeOut = 3000);
  129. BOOL AddReply(IN LPVOID lpReplyInfo, IN CONST DWORD& dwTimeOut = 3000);
  130. BOOL UpdateCustomer(IN LPVOID lpCustomerInfo, IN CONST DWORD& dwTimeOut = 3000);
  131. };
  132. #endif