diff --git a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp index 99d464a..9391083 100644 --- a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp +++ b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp @@ -44,7 +44,6 @@ ui->tableWidget->setColumnWidth(1, 80); ui->tableWidget->setColumnWidth(2, 80); ui->tableWidget->setColumnWidth(3, 100); - cmdList = BaseCommonApi::getInstructionLib(sId); CheckItemNameList.clear(); int rowCount = 0; @@ -182,14 +181,14 @@ QString sName = ""; if(iType==0){ if(checkMode){ - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; }else{ QList result = BaseCommonApi::getTestedCatDevice(sId); if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -198,7 +197,7 @@ if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -356,14 +355,14 @@ QString sName = ""; if(iType==0){ if(checkMode){ - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; }else{ QList result = BaseCommonApi::getTestedCatDevice(sId); if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -372,7 +371,7 @@ if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } diff --git a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp index 99d464a..9391083 100644 --- a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp +++ b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp @@ -44,7 +44,6 @@ ui->tableWidget->setColumnWidth(1, 80); ui->tableWidget->setColumnWidth(2, 80); ui->tableWidget->setColumnWidth(3, 100); - cmdList = BaseCommonApi::getInstructionLib(sId); CheckItemNameList.clear(); int rowCount = 0; @@ -182,14 +181,14 @@ QString sName = ""; if(iType==0){ if(checkMode){ - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; }else{ QList result = BaseCommonApi::getTestedCatDevice(sId); if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -198,7 +197,7 @@ if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -356,14 +355,14 @@ QString sName = ""; if(iType==0){ if(checkMode){ - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; }else{ QList result = BaseCommonApi::getTestedCatDevice(sId); if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -372,7 +371,7 @@ if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } diff --git a/softwareDirectory/AutoVerScheme/syncupload.cpp b/softwareDirectory/AutoVerScheme/syncupload.cpp new file mode 100644 index 0000000..cbe5f08 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncupload.cpp @@ -0,0 +1,46 @@ + +#include "syncupload.h" + +syncupload::syncupload(QSqlDatabase cloud, QSqlDatabase local, QString tableName,QString ssql,QMap IdToSqlMap) + : cloud(cloud), local(local), tableName(tableName),ssql(ssql),IdToSqlMap(IdToSqlMap) +{} + +void syncupload::run() +{ + this->SysncUploadCount(); +} + +void syncupload::SysncUploadCount() +{ + if(syncstate==SyncRunStatus::Stopped){return;}; + while (syncstate==SyncRunStatus::Paused) { + QThread::sleep(1); + } + QSqlQuery runSql(cloud); +// for (const QString& ssql : this->sqlList) { + if (runSql.exec(IdToSqlMap.value(ssql))) { + QSqlQuery localQuery(local); + localQuery.exec("UPDATE zd_data_sync SET sync_type = 1 WHERE id= " + ssql); + qDebug() << "执行 SQL 成功"; + emit taskCompleted(2,tableName, "cg表:"+tableName); + qDebug() << "当前线程:" << QThread::currentThreadId(); + } else { + qDebug() << "执行 SQL 失败:" << runSql.lastError().text(); + emit taskCompleted(1,tableName,tableName+"|错误:"+runSql.lastError().text()); + qDebug() << "当前线程:" << QThread::currentThreadId(); + } +// } + emit TextState(); +} +void syncupload::UpdateState(int state) + { + if(state==0) + { + syncstate=SyncRunStatus::Running; + }else if(state==1){ + syncstate=SyncRunStatus::Paused; + }else{ + syncstate=SyncRunStatus::Stopped; + } + } + diff --git a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp index 99d464a..9391083 100644 --- a/softwareDirectory/AutoVerScheme/formaddrsetting.cpp +++ b/softwareDirectory/AutoVerScheme/formaddrsetting.cpp @@ -44,7 +44,6 @@ ui->tableWidget->setColumnWidth(1, 80); ui->tableWidget->setColumnWidth(2, 80); ui->tableWidget->setColumnWidth(3, 100); - cmdList = BaseCommonApi::getInstructionLib(sId); CheckItemNameList.clear(); int rowCount = 0; @@ -182,14 +181,14 @@ QString sName = ""; if(iType==0){ if(checkMode){ - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; }else{ QList result = BaseCommonApi::getTestedCatDevice(sId); if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -198,7 +197,7 @@ if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -356,14 +355,14 @@ QString sName = ""; if(iType==0){ if(checkMode){ - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; }else{ QList result = BaseCommonApi::getTestedCatDevice(sId); if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } @@ -372,7 +371,7 @@ if(result.length()>0){ sName = result[0].equipment_name; } - cmd.verification_program_id = sId; + cmd.program_id = sId; cmd.device_id = sId; cmd.device_name = sName; } diff --git a/softwareDirectory/AutoVerScheme/syncupload.cpp b/softwareDirectory/AutoVerScheme/syncupload.cpp new file mode 100644 index 0000000..cbe5f08 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncupload.cpp @@ -0,0 +1,46 @@ + +#include "syncupload.h" + +syncupload::syncupload(QSqlDatabase cloud, QSqlDatabase local, QString tableName,QString ssql,QMap IdToSqlMap) + : cloud(cloud), local(local), tableName(tableName),ssql(ssql),IdToSqlMap(IdToSqlMap) +{} + +void syncupload::run() +{ + this->SysncUploadCount(); +} + +void syncupload::SysncUploadCount() +{ + if(syncstate==SyncRunStatus::Stopped){return;}; + while (syncstate==SyncRunStatus::Paused) { + QThread::sleep(1); + } + QSqlQuery runSql(cloud); +// for (const QString& ssql : this->sqlList) { + if (runSql.exec(IdToSqlMap.value(ssql))) { + QSqlQuery localQuery(local); + localQuery.exec("UPDATE zd_data_sync SET sync_type = 1 WHERE id= " + ssql); + qDebug() << "执行 SQL 成功"; + emit taskCompleted(2,tableName, "cg表:"+tableName); + qDebug() << "当前线程:" << QThread::currentThreadId(); + } else { + qDebug() << "执行 SQL 失败:" << runSql.lastError().text(); + emit taskCompleted(1,tableName,tableName+"|错误:"+runSql.lastError().text()); + qDebug() << "当前线程:" << QThread::currentThreadId(); + } +// } + emit TextState(); +} +void syncupload::UpdateState(int state) + { + if(state==0) + { + syncstate=SyncRunStatus::Running; + }else if(state==1){ + syncstate=SyncRunStatus::Paused; + }else{ + syncstate=SyncRunStatus::Stopped; + } + } + diff --git a/softwareDirectory/AutoVerScheme/syncupload.h b/softwareDirectory/AutoVerScheme/syncupload.h new file mode 100644 index 0000000..569bb88 --- /dev/null +++ b/softwareDirectory/AutoVerScheme/syncupload.h @@ -0,0 +1,43 @@ + +#ifndef SYNCUPLOAD_H +#define SYNCUPLOAD_H +#include +#include +#include +#include "basecommonapi.h" +#include +#include +#include +#include + + + +class syncupload : public QObject, public QRunnable +{ + Q_OBJECT +public: +// syncupload(QSqlDatabase cloud, QSqlDatabase local, QString tableName,const QList& sqlList); + syncupload(QSqlDatabase cloud, QSqlDatabase local, QString tableName,QString ssql,QMap IdToSqlMap); + SyncRunStatus syncstate; + + +//signals: +// void taskCompleted(int success, QString tableName, const QString& errorMessage); + + QSqlDatabase cloud; + QSqlDatabase local; + QString tableName; +// QList idList; + QString ssql; + QMap IdToSqlMap; + void run() override; + void SysncUploadCount(); + void UpdateState(int state); +signals: + void taskCompleted(int success,QString tableName, const QString& errorMessage); + void TextState(); +}; + + + +#endif // SYNCUPLOAD_H