#pragma once #include #include #include #include #include "threadcontroller.h" #define LH_HTTPAPI_SUCC 0 const int LHHTTPAPI_BUFFER_SIZE = 1024*1024; // 用New #define LHAPI_BUFFER_SIZE_NEW 2048000 #define LHAPI_BUFFER_SIZE_ARY 4096 // token 超时 #define TOKENTIME 20*60 extern int g_nHttpTimeOut; // 操作类型【1查询 2更新 3删除 4插入 5存储过程】 enum enDBOperatorType { EDBOT_Select = 1, EDBOT_Update, EDBOT_Delete, EDBOT_Insert, EDBOT_Procedure, EDBOT_Batch, /* 单动作批量操作,失败全部回滚 */ EDBOT_BatchTransAction /* 多动作批量操作,失败回滚,请求[{op1}, {op2}, ...], 回复 { "code":0, "data":[{ "key":"1", "value":{ "code":0, "result":1 } }, { "key":"2", "value":{ "code":0, "result":[{ "counT(*)":0 }] } }] }" */ }; /** * 单个查询语句多条不同的变量,适合批量查询,paraName是变量名 EDBOT_Batch { "opName":"TMS_GetExecPlanOneTemplateList", "paraName":[ 1, 2, 3 ] } 多个不同语句集合,适合插入数据,Key表示的是这一个语句的唯一值,用于区分插入操作的 EDBOT_BatchTransAction [ { "opName":"TMS_InsertExecPlanOneTemplateList", "Key":"1", "paramList": { "channelID":1, "templateName":"测试模版1", "templateType":0 } }, { "opName":"TMS_InsertExecPlanOneTemplateList", "paramList": { "channelID":2, "templateName":"测试模版2", "templateType":0 } } ] */ class lhhttpapi : public QObject { Q_OBJECT public: typedef void* (*FunDBInit)(const char* lpUrl,bool bismulti); typedef int (*FunDBLogin)(const char *plocalip,const char *pSerid, const char* CType, char *pszUserToken, int nSize,bool bismulti, void* phttpip); typedef int (*FunDBGetServerList)(char *pszList, int nSize,bool bismulti, void* phttpip); typedef int (*FunDBGetChannelList)(const char* pSerid,char *pszList, int nSize,bool bismulti, void* phttpip); typedef int (*FunDBDoInterface)(const char* pSerid,const char* CType,const char* strtoken,int nOperatorType, const char * strParamXml, char *strRetXml, int nSize,bool bismulti, void* phttpip); typedef int64_t (*FunDoGetHttpFileSize)(const char* pHttAddr); typedef int64_t (*FunDoGetHttpFileContent)(const char* lpHttpAddr, char *pszContent, int nSize); typedef int (*FunDoUploadFtpFile)(const char* pszLocalFilePath, const char* pszFtpFilePath); typedef int (*FunDoUploadFtpFileContent)(const char * szFileContent, int nSize, const char* strFtpFilePath); typedef int (*FunDoCurlDeleteFtpFile)(const char* user, const char* pwd, const char* pszFtpFile); typedef int (*FunDoCurlUploadFtpFile)(const char* user, const char* pwd, const char* pszLocalFilePath, const char* pszFtpFile); typedef int (*FunDoCurlUploadFtpFileContent)(const char* user, const char* pwd, const char* pszFileContent, int nSize, const char* pszFtpFile); // typedef int (*FunUnInit)(); typedef int (*FunDoGetLastError)(char *pError, int nLen, int *nErrorCode); typedef int (*FunDoRelease)(bool bismulti, void* phttpip); public: explicit lhhttpapi(QObject *parent = nullptr); ~lhhttpapi(); public: QLibrary *m_pQLib; FunDoRelease fnDoRelease; FunDBInit fnDBInit; FunDBLogin fnDBLogin; FunDBGetServerList fnDBGettServerList; FunDBGetChannelList fnDBGetChannelList; FunDBDoInterface fnDBDoInterface; FunDoGetHttpFileSize fnDoGetHttpFileSize; FunDoGetHttpFileContent fnDoGetHttpFileContent; FunDoUploadFtpFile fnDoUploadFtpFile; FunDoUploadFtpFileContent fnDoUploadFtpFileContent; FunDoCurlDeleteFtpFile fnDoCurlDeleteFtpFile; FunDoCurlUploadFtpFile fnDoCurlUploadFtpFile; FunDoCurlUploadFtpFileContent fnDoCurlUploadFtpFileContent; // FunUnInit fnUnInit; FunDoGetLastError fnGetLastError; QMutex m_mutexWorkerDestroy; QWaitCondition m_Condition; public: bool Load(QString file); bool Load(); bool UnLoad(); int DoRelease(bool bismulti = false, void* phttpip=nullptr); void* DBInit (const char *lpUrl,bool bismulti = false); int DBLogin(const QString& pLocalip,const QString &pSerid,const QString &appType, QString &pszUserToken,bool bismulti = false, void* phttpip=nullptr); int DoGetToken(QString &szToken,bool bismulti = false, void* phttpip=nullptr); // void DoGetTokenAgain(); int DBGetServerList(char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr); int DBGetChannelList(const char* pSerid,char *pszList, int nSize,bool bismulti = false, void* phttpip=nullptr); // int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool wait = false, bool bismulti = false, void* phttpip=nullptr); int DBDoInterface(int nOperatorType, const QString &strParamXml, QString &strRetXml, bool bismulti = false); int DoGetLastError(char *pError, int nLen, int *nErrorCode); QString DoGetLastError(int *nErrorCode); int64_t DoGetHttpFileSize(const QString &url); int64_t DoGetHttpFileContent(const QString &url, char *pszContent, int nSize); // int64_t DoGetHttpPNGFile(const QString &url, QPixmap &outPixmap); bool DoUploadFtpFile(const QString &localFilePath, const QString &ftpFilePath); bool DoUploadFtpFileContent(const char * szFileContent, int nSize, const QString &ftpFilePath); bool DoCurlDeleteFtpFile(const QString &targetFilePath); bool DoCurlDeleteFtpFile(const QString &user, const QString &pwd, const QString &targetFilePath); bool DoCurlUploadFtpFile(const QString &localFilePath, const QString &destFilePath); bool DoCurlUploadFtpFile(const QString &user, const QString &pwd, const QString &localFilePath, const QString &destFilePath); bool DoCurlUploadFtpFileContent(const char * szFileContent, int nSize, const QString &destFilePath); bool DoCurlUploadFtpFileContent(const QString &user, const QString &pwd, const char * szFileContent, int nSize, const QString &destFilePath); private slots: void OnWorkerFinished(); private: QString m_Localip; // localip QString m_Serid; // 当前服务数据库id QString m_appType; // 设备类型 QString m_strtoken;// token QDateTime m_lasttimer; // 最后一个获取token的时间 void* m_phttpip = nullptr; }; class DoInterfaceObject : public ThreadWorker { Q_OBJECT public: explicit DoInterfaceObject(lhhttpapi *pApi, const QString &strToken, int nOperatorType, const QString &strParamXml,bool bismulti = false,void* phttpip=nullptr); virtual ~DoInterfaceObject() override {} QString GetRetXML() const {return m_strRetXml;} int GetResult() const {return m_nResult;} public slots: virtual void DoInit() override {} virtual void DoWork() override; signals: void sig_WorkFinished(); public: lhhttpapi *m_pApi; QString m_strToken; int m_nOperatorType; QString m_strParamXml; QString m_strRetXml; int m_nResult; bool m_bismulti; void* m_phttpip; };