lhhttpapi.h_ 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #pragma once
  2. #include <QString>
  3. #include <QObject>
  4. #include <QLibrary>
  5. #include <QDateTime>
  6. #include <QMutex>
  7. #include <QWaitCondition>
  8. // #include "Common/singleton.h"
  9. #include "threadcontroller.h"
  10. #define LH_HTTPAPI_SUCC 0
  11. // 用New
  12. #define LHAPI_BUFFER_SIZE_NEW 2048000
  13. #define LHAPI_BUFFER_SIZE_ARY 4096
  14. extern int g_nHttpTimeOut;
  15. // 操作类型【1查询 2更新 3删除 4插入 5存储过程】
  16. enum enDBOperatorType
  17. {
  18. EDBOT_Select = 1,
  19. EDBOT_Update,
  20. EDBOT_Delete,
  21. EDBOT_Insert,
  22. EDBOT_Procedure,
  23. EDBOT_Batch, // 单动作批量操作,失败全部回滚
  24. EDBOT_BatchTransAction // 多动作批量操作,失败回滚
  25. };
  26. class lhhttpapi : public QObject
  27. {
  28. Q_OBJECT
  29. public:
  30. typedef int (*FunDBInit)(const char* lpUrl);
  31. typedef int (*FunDBLogin)(const char *pLocalIP, const char *pSerid, const char* CType, char *pszUserToken, int nSize);
  32. typedef int (*FunDBGetServerList)(char *pszList, int nSize);
  33. typedef int (*FunDBGetServerInfo)(const char* pSerid, const char* pszUserToken, char* pServerInfo, int nSize);
  34. typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize);
  35. typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParam, char *strRet, int nSize);
  36. typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode);
  37. typedef int (*FunSetHttpTimeOut)(int nTimeout);
  38. // 获取网络文件大小,返回文件大小
  39. typedef int64_t (*FunDoGetHttpFileSize)(const char *pszHttpAddr);
  40. // 获取网络文件内容,返回内容大小
  41. typedef int64_t (*FunDoGetHttpFileContent)(const char* pHttpAddr, char *pszContent, int nSize);
  42. // 获取汉字拼音首字母,空格、数字等其它字符保持不动
  43. typedef int (*FunDoWord2Pyjc)(const char* pszWord, char *pszContent, int nSize);
  44. // 文件上传FTP
  45. typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath);
  46. typedef int (*FunDoUploadFtpFileContent)(const char* pszFileContent, int size, const char* pszFtpFilePath);
  47. // FTP
  48. typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile);
  49. typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile);
  50. typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile);
  51. // 获取数据库信息
  52. typedef int (*FunDoGetDBInfo)(const char* strSerid, const char* strtoken, char* pDBInfo, int nsize);
  53. public:
  54. explicit lhhttpapi(QObject *parent = nullptr);
  55. ~lhhttpapi();
  56. public:
  57. QLibrary *m_pQLib;
  58. FunDBInit fnDBInit;
  59. FunDBLogin fnDBLogin;
  60. FunDBGetServerList fnDBGettServerList;
  61. FunDBGetChannelList fnDBGetChannelList;
  62. FunDBGetServerInfo fnDBGetServerInfo;
  63. FunSetHttpTimeOut fnSetHttpTimeOut;
  64. FunDoGetHttpFileSize fnGetHttpFileSize;
  65. FunDoGetHttpFileContent fnGetHttpFileContent;
  66. FunDoGetLastError fnGetLastError;
  67. FunDoWord2Pyjc fnDoWord2Pyjc;
  68. FunDoUploadFtpFile fnDoUploadFtpFile;
  69. FunDoUploadFtpFileContent fnDoUploadFtpFileContent;
  70. FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile;
  71. FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile;
  72. FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent;
  73. FunDoGetDBInfo fnDoGetDBInfo;
  74. QMutex m_mutexWorkerDestroy;
  75. QWaitCondition m_Condition;
  76. FunDBDoInterface fnDBDoInterface;
  77. public:
  78. bool Load(QString file);
  79. bool UnLoad();
  80. int SetHttpTimeOut(int nTimeout);
  81. QString DoGetLastError(int *nErrorCode);
  82. QString GetServerID() const {return m_serID;}
  83. QString GetClientType() const {return m_clientType;}
  84. int DBQInit(QString strUrl);
  85. int DBQGetServerList(QString& serverList);
  86. int DBQGetServerInfo(const QString& serid, QString& serverInfo);
  87. /**
  88. * @brief 登录数据库
  89. *
  90. * @param LocalIP
  91. * @param Serid
  92. * @param CType
  93. * @param strUserToken 传出参数
  94. * @return int
  95. */
  96. int DBQLogin(QString LocalIP, QString Serid, QString CType, QString &strUserToken);
  97. int DBQDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = true);
  98. private slots:
  99. void OnWorkerFinished();
  100. private:
  101. QString m_token;
  102. QMutex m_mtx;
  103. QString m_serID;
  104. QString m_clientType;
  105. QTimer* m_tUpToken;
  106. };
  107. class DoInterfaceObject : public ThreadWorker
  108. {
  109. Q_OBJECT
  110. public:
  111. explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml);
  112. virtual ~DoInterfaceObject() override {}
  113. QString GetRetXML() const {return m_strRetXml;}
  114. int GetResult() const {return m_nResult;}
  115. public slots:
  116. void DoInit() override {}
  117. void DoWork() override;
  118. signals:
  119. void sig_WorkFinished();
  120. public:
  121. lhhttpapi *m_pApi;
  122. QString m_strToken;
  123. int m_nOperatorType;
  124. QString m_strParamXml;
  125. QString m_strRetXml;
  126. int m_nResult;
  127. };