Add for send zip file every 5 mins

CigaretteSH
Flamingo 9 months ago
parent 51f65124ab
commit ccf44a00d3

@ -1,6 +1,11 @@
#include "exportData.h" #include "exportData.h"
#include "QtCore\qfile.h" #include "QtCore\qfile.h"
#include "QtCore\qtextstream.h" #include "QtCore\qtextstream.h"
#include <QTimer>
#include <QFileInfoList>
#include <QDir>
#include <QFileInfo>
#include <QProcess>
#include <string> #include <string>
//#include <ftpManager.h> //#include <ftpManager.h>
#include <wininet.h> #include <wininet.h>
@ -17,6 +22,7 @@ extern SysConf g_sys_conf; //系统配置参数
ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent) ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
{ {
/* Move to init()
//第一步执行 //第一步执行
cg->read_conf(g_conf_path); cg->read_conf(g_conf_path);
for (int index = 0; index < NumberOfSupportedCameras; index++) for (int index = 0; index < NumberOfSupportedCameras; index++)
@ -40,12 +46,14 @@ ExportDataThread::ExportDataThread(QObject* parent) : QThread(parent)
} }
if (!ConnectFtp(&ip, &port, &username, &userpwd)) if (!ConnectFtp(&ip, &port, &username, &userpwd))
qDebug() << "First connect FTP failed because " << GetLastError(); qDebug() << "First connect FTP failed because " << GetLastError();
*/
readyToSendZip = false;
} }
void ExportDataThread::init(string ip_, int port_, string username_, string userpwd_) void ExportDataThread::init(string ip_, int port_, string username_, string userpwd_)
{ {
//第三部执行 //初始化FTP连接信息
ip = ip_; ip = ip_;
port = port_; port = port_;
username = username_; username = username_;
@ -55,6 +63,34 @@ void ExportDataThread::init(string ip_, int port_, string username_, string user
b_quit = false; b_quit = false;
flag = false; flag = false;
timer = new QTimer(this);
timer->setTimerType(Qt::PreciseTimer);
timer->setSingleShot(true);
//第一步执行
cg->read_conf(g_conf_path);
for (int index = 0; index < NumberOfSupportedCameras; index++)
{
XMLError error;
pDocument[index] = new tinyxml2::XMLDocument();
QString xmlPath = QString(EXPORTDATA_FILE).arg(index);
QString filePath = g_conf_path.config_path + "/" + xmlPath;
error = pDocument[index]->LoadFile(filePath.toLocal8Bit().constData());
if (error != XML_SUCCESS) {
XMLDeclaration* declaration = pDocument[index]->NewDeclaration();
pDocument[index]->InsertFirstChild(declaration);
}
}
//init(ip, port, username, userpwd);
cout << "11111111111111";
hint = InternetOpen(0, INTERNET_OPEN_TYPE_PRECONFIG, 0, 0, 0);
if (hint == NULL) {
return;
}
if (!ConnectFtp(&ip, &port, &username, &userpwd))
qDebug() << "First connect FTP failed because " << GetLastError();
} }
void ExportDataThread::start_work() void ExportDataThread::start_work()
@ -81,16 +117,15 @@ bool ExportDataThread::ConnectFtp(string *ip_, int *port_, string *username_, st
//string userName = "FTP2"; //string userName = "FTP2";
///* 密码 */ ///* 密码 */
//string pwd = "123"; //string pwd = "123";
int ftpport =*port_; cout << "222ftp ip =" << ip_ << "| prot =" << *port_ << endl;
cout << "222ftp ip =" << ip << "| prot =" << port << endl; cout << "222username =" << username_ << "| pwd =" << userpwd_ << endl;
cout << "222username =" << username << "| pwd =" << userpwd << endl;
if (hftp != NULL) { if (hftp != NULL) {
InternetCloseHandle(hftp); InternetCloseHandle(hftp);
hftp = NULL; hftp = NULL;
} }
// 创建ftp连接 // 创建ftp连接
// hftp = InternetConnectA(hint, ftpServer.c_str(), port, userName.c_str(), pwd.c_str(), INTERNET_SERVICE_FTP, 0, 0); // hftp = InternetConnectA(hint, ftpServer.c_str(), port, userName.c_str(), pwd.c_str(), INTERNET_SERVICE_FTP, 0, 0);
hftp = InternetConnectA(hint, ip_->c_str(), ftpport, username_->c_str(), userpwd_->c_str(), INTERNET_SERVICE_FTP, 0, 0); hftp = InternetConnectA(hint, ip_->c_str(), *port_, username_->c_str(), userpwd_->c_str(), INTERNET_SERVICE_FTP, 0, 0);
if (hftp == NULL) { if (hftp == NULL) {
qDebug() << "ftp connect failed because " << GetLastError(); qDebug() << "ftp connect failed because " << GetLastError();
return false; return false;
@ -265,6 +300,58 @@ void ExportDataThread::run()
QString remotePath = "/tmp/" + xmlPath; QString remotePath = "/tmp/" + xmlPath;
ConnectServer(filePath, remotePath); ConnectServer(filePath, remotePath);
} }
if (readyToSendZip) {
QString remotePath;
QStringList zipFilePaths;
QString zipFilePath;
QString okStr = "ok";
QProcess process(0);
QDateTime now_ts = QDateTime::currentDateTime();
zipFilePaths.append(g_conf_path.save_pics_path + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "ng.zip");
zipFilePaths.append(g_conf_path.save_pics_path + now_ts.toString("yyyy-MM-dd_HH-mm-ss_zzz_") + "ok.zip");
remotePath = listToZip[0].mid(listToZip[0].indexOf("image") - 1);
QStringList argsNg;
QStringList argsOk;
argsNg.append("a");
argsNg.append(zipFilePaths[0]);
argsOk.append("a");
argsOk.append(zipFilePaths[1]);
// create zip file
for (int i = 0; i < listToZip.size(); i++) {
QStringList strList = listToZip[i].split("_");
strList = strList[strList.size() - 1].split(".");
int index = listToZip[i].lastIndexOf("/\\", 0);
if (strList[0] == okStr) {
argsOk.append(listToZip[i]);
}
else {
argsNg.append(listToZip[i]);
}
/*
QDir dir;
if (!dir.exists(listToZip[i].mid(index - 1)))
{
dir.mkpath(listToZip[i].mid(index - 1));
}
*/
}
argsNg.append("-mx=3");
argsOk.append("-mx=3");
for (int i = 0; i < zipFilePaths.size(); i++) {
process.start(QApplication::applicationDirPath() + "/7z.exe", i == 0 ? argsNg : argsOk);
process.waitForStarted();
process.waitForFinished();
ConnectServer(zipFilePaths[i], remotePath);
}
readyToSendZip = false;
}
} }
flag = false; flag = false;
@ -349,8 +436,20 @@ void ExportDataThread::ConnectServer(QString srcPath, QString destPath) {
void ExportDataThread::GetDataFromSaveThread(QString filePath) { void ExportDataThread::GetDataFromSaveThread(QString filePath) {
QString remotePath; QString remotePath;
remotePath = filePath.mid(filePath.indexOf("image") - 1);
ConnectServer(filePath, remotePath); if (timer->isActive()) {
tmpListToZip.append(filePath);
}
else {
listToZip = tmpListToZip;
tmpListToZip.clear();
tmpListToZip.append(filePath);
readyToSendZip = true;
//remotePath = filePath.mid(filePath.indexOf("image") - 1);
//ConnectServer(filePath, remotePath);
timer->start(1000 * 60 * 5); // 5min
}
} }
//*****************************************已经调试好,没有理清逻辑前不要动********************** //*****************************************已经调试好,没有理清逻辑前不要动**********************

@ -115,6 +115,11 @@ public:
quit(); quit();
wait(); wait();
} }
QTimer* timer;
QStringList listToZip;
QStringList tmpListToZip;
BOOLEAN readyToSendZip;
void init(string ip_, int port_, string username_, string userpwd_); void init(string ip_, int port_, string username_, string userpwd_);
void start_work(); void start_work();

Loading…
Cancel
Save