|
@@ -11,7 +11,10 @@
|
|
|
#include <QJsonArray>
|
|
|
#include <QDebug>
|
|
|
#include <QSqlQuery>
|
|
|
+#include <QMessageBox>
|
|
|
+#include <QTimeZone>
|
|
|
#include "../global.h"
|
|
|
+
|
|
|
#define ANSI_COLOR_GREEN "\x1B[32m"
|
|
|
#define ANSI_COLOR_RESET "\x1B[0m"
|
|
|
|
|
@@ -43,7 +46,7 @@ firingWidget::firingWidget(const int& row,const bool& select,const QString& uuid
|
|
|
connect(mqttThread, &MqttThread::messageAndTopicReceived, this, &firingWidget::handleMessageAndTopic);
|
|
|
|
|
|
connect(this, &firingWidget::lastStageChanged, this, &firingWidget::onLastStageChanged);
|
|
|
- connect(this, &firingWidget::updateData, this, &firingWidget::updateWebData);
|
|
|
+ connect(this, &firingWidget::updateData, this, &firingWidget::saveProjDataAndUpload);
|
|
|
startBlasting();
|
|
|
}
|
|
|
|
|
@@ -68,7 +71,6 @@ void firingWidget::sendMqttMessage(const QString& topic, const QByteArray& messa
|
|
|
|
|
|
void firingWidget::startBlasting()
|
|
|
{
|
|
|
-
|
|
|
// TODO 检测起爆器是否在线
|
|
|
QTimer::singleShot(1000, this, [this]() {
|
|
|
lastStage=0;
|
|
@@ -85,7 +87,7 @@ void firingWidget::on_pushButton_2_clicked(){
|
|
|
|
|
|
|
|
|
|
|
|
-bool firingWidget::danUpload(const QJsonObject& jsonObj){
|
|
|
+bool firingWidget::uploadToDanLing(const QJsonObject& jsonObj){
|
|
|
|
|
|
QString htid = jsonObj["project_htid"].toString();
|
|
|
QString htm = ""; //
|
|
@@ -152,7 +154,7 @@ bool firingWidget::danUpload(const QJsonObject& jsonObj){
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool firingWidget::addRegData(const QJsonObject& jsonObj) {
|
|
|
+bool firingWidget::addRegRecords(const QJsonObject& jsonObj) {
|
|
|
QJsonArray regsArray = jsonObj["regs"].toArray();
|
|
|
for (const auto& regValue : regsArray) {
|
|
|
QJsonObject regObj = regValue.toObject();
|
|
@@ -161,8 +163,8 @@ bool firingWidget::addRegData(const QJsonObject& jsonObj) {
|
|
|
recordReg.setUuid(reg_uuid);
|
|
|
recordReg.setEquipSn(regObj["equipment_sn"].toString());
|
|
|
recordReg.setEquipVersion(regObj["equipment_version"].toString());
|
|
|
- recordReg.setRegDetoCount(regObj["reg_deto_count"].toInt());
|
|
|
- recordReg.setErrorDetoCount(regObj["error_deto_count"].toInt());
|
|
|
+ recordReg.setRegDetoCount(regObj["reg_deto_count"].toString().toInt());
|
|
|
+ recordReg.setErrorDetoCount(regObj["error_deto_count"].toString().toInt());
|
|
|
recordReg.setAfterTestBusV(regObj["after_test_bus_v"].toString());
|
|
|
recordReg.setAfterTestBusI(regObj["after_test_bus_i"].toString());
|
|
|
recordReg.setBusLeakageCurrentI(regObj["bus_leakage_current_i"].toString());
|
|
@@ -173,7 +175,7 @@ bool firingWidget::addRegData(const QJsonObject& jsonObj) {
|
|
|
recordReg.setRecordUuid(blast_uuid);
|
|
|
recordReg.setCreatedAt(QDateTime::currentDateTime());
|
|
|
// 插入数据到数据库
|
|
|
- if (!daoReg.addHBlastRegRecord(recordReg)) {
|
|
|
+ if (!daoReg.saveHBlastRegRecord(recordReg)) {
|
|
|
return false;
|
|
|
} else {
|
|
|
}
|
|
@@ -181,7 +183,7 @@ bool firingWidget::addRegData(const QJsonObject& jsonObj) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-bool firingWidget::addDetData(const QJsonObject& jsonObj) {
|
|
|
+bool firingWidget::handleBlastFinishedMsg(const QJsonObject& jsonObj) {
|
|
|
QJsonArray regsArray = jsonObj["regs"].toArray();
|
|
|
for (const auto& regValue : regsArray) {
|
|
|
QJsonObject regObj = regValue.toObject();
|
|
@@ -300,7 +302,6 @@ void firingWidget::handleMessageAndTopic(const QByteArray &message, const QMqttT
|
|
|
QJsonObject dataObject = jsonObj["data"].toObject();
|
|
|
emit updateData(dataObject);
|
|
|
emit closeFiring(m_uuid);
|
|
|
-
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -417,7 +418,6 @@ void firingWidget::cancelBlasting()
|
|
|
}
|
|
|
void firingWidget::on_sendTest_4_clicked()
|
|
|
{
|
|
|
-
|
|
|
// qDebug() << "navProgress 取消流程";
|
|
|
// QString message = "取消流程";
|
|
|
// if (!message.isEmpty()) {
|
|
@@ -544,7 +544,7 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
}else{
|
|
|
qDebug() << "Failed to insert record.";
|
|
|
}
|
|
|
- if (!addDetData(jsonObj)) {
|
|
|
+ if (!handleBlastFinishedMsg(jsonObj)) {
|
|
|
qDebug() << "Insert failed for UID:"; // 假设 record 有 uid 成员
|
|
|
if (db.rollback()) {
|
|
|
qDebug() << "Transaction rolled back successfully.";
|
|
@@ -552,7 +552,7 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
}
|
|
|
}
|
|
|
- if (!addRegData(jsonObj)) {
|
|
|
+ if (!addRegRecords(jsonObj)) {
|
|
|
if (db.rollback()) {
|
|
|
qDebug() << "Transaction rolled back successfully.";
|
|
|
} else {
|
|
@@ -570,14 +570,33 @@ void firingWidget::on_sendTest_4_clicked()
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
-void firingWidget::updateWebData(const QJsonObject& jsonObj){
|
|
|
+void firingWidget::saveProjDataAndUpload(const QJsonObject& jsonObj){
|
|
|
blast_uuid =QUuid::createUuid().toString(QUuid::WithoutBraces).remove(QRegularExpression("-"));
|
|
|
lat = labLat;
|
|
|
lon = labLon;
|
|
|
+ qDebug() << "爆破记录"<< QJsonDocument( jsonObj).toJson(QJsonDocument::Indented);
|
|
|
+ Logger::getInstance().info("收到爆破完成回传记录");
|
|
|
+
|
|
|
+ saveDataToLocalDB(jsonObj);
|
|
|
+
|
|
|
+ if(lat=="定位失败"&&lat=="未知"&&lon=="定位失败"&&lon=="未知"){
|
|
|
+ // 数据出本地 不传丹灵
|
|
|
+
|
|
|
+ }
|
|
|
+ // danUpload(jsonObj);
|
|
|
+ // if (db.commit()) {
|
|
|
+ // qDebug() << "Transaction committed successfully.";
|
|
|
+ // } else {
|
|
|
+ // qDebug() << "Failed to commit transaction:" << db.lastError().text();
|
|
|
+ // }
|
|
|
+}
|
|
|
+
|
|
|
+void saveDataToLocalDB(const QJsonObject jsonObj) {
|
|
|
QSqlDatabase db = DatabaseManager::getInstance().getDatabase();
|
|
|
if (!db.transaction()) {
|
|
|
qDebug() << "Failed to start transaction:" << db.lastError().text();
|
|
|
}
|
|
|
+
|
|
|
HBlastRecord record;
|
|
|
record.setProjectName(jsonObj["project_name"].toString());
|
|
|
record.setProjectHtid(jsonObj["project_htid"].toString());
|
|
@@ -592,11 +611,13 @@ void firingWidget::updateWebData(const QJsonObject& jsonObj){
|
|
|
record.setLongitude(jsonObj["blast_longitude"].toString());
|
|
|
record.setLatitude(jsonObj["blast_latitude"].toString());
|
|
|
|
|
|
- record.setLongitude(lat);
|
|
|
- record.setLatitude(lon);
|
|
|
- record.setRegDetCount(jsonObj["reg_deto_count"].toInt());
|
|
|
- record.setErrorDetCount(jsonObj["error_deto_count"].toInt());
|
|
|
- record.setBlastAt(QDateTime::fromString(jsonObj["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss"));
|
|
|
+ //record.setLongitude(lat);
|
|
|
+ //record.setLatitude(lon);
|
|
|
+ record.setRegDetCount(jsonObj["reg_deto_count"].toString().toInt());
|
|
|
+ record.setErrorDetCount(jsonObj["error_deto_count"].toString().toInt());
|
|
|
+ QDateTime blastTime = QDateTime::fromString(jsonObj["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss +08:00");
|
|
|
+ blastTime.setTimeZone(QTimeZone(QByteArrayLiteral("Asia/Shanghai")));
|
|
|
+ record.setBlastAt(blastTime);
|
|
|
record.setCreatedAt(QDateTime::currentDateTime());
|
|
|
qDebug() << "currentDateTime."<<QDateTime::currentDateTime();
|
|
|
record.setUuid(blast_uuid);
|
|
@@ -607,14 +628,14 @@ void firingWidget::updateWebData(const QJsonObject& jsonObj){
|
|
|
qDebug() << "Failed to insert record.";
|
|
|
}
|
|
|
|
|
|
- if (!addRegData(jsonObj)) {
|
|
|
+ if (!addRegRecords(jsonObj)) {
|
|
|
if (db.rollback()) {
|
|
|
qDebug() << "Transaction rolled back successfully.";
|
|
|
} else {
|
|
|
qDebug() << "Failed to roll back transaction:" << db.lastError().text();
|
|
|
}
|
|
|
}
|
|
|
- if (!addDetData(jsonObj)) {
|
|
|
+ if (!recordDetUsages(jsonObj)) {
|
|
|
qDebug() << "Insert failed for UID:"; // 假设 record 有 uid 成员
|
|
|
if (db.rollback()) {
|
|
|
qDebug() << "Transaction rolled back successfully.";
|
|
@@ -625,15 +646,4 @@ void firingWidget::updateWebData(const QJsonObject& jsonObj){
|
|
|
|
|
|
db.commit();
|
|
|
|
|
|
-
|
|
|
- if(lat=="定位失败"&&lat=="未知"&&lon=="定位失败"&&lon=="未知"){
|
|
|
- // 数据出本地 不传丹灵
|
|
|
-
|
|
|
- }
|
|
|
- // danUpload(jsonObj);
|
|
|
- // if (db.commit()) {
|
|
|
- // qDebug() << "Transaction committed successfully.";
|
|
|
- // } else {
|
|
|
- // qDebug() << "Failed to commit transaction:" << db.lastError().text();
|
|
|
- // }
|
|
|
}
|