Browse Source

fix and updates

Yao 2 tuần trước cách đây
mục cha
commit
fb680b2137

+ 1 - 1
CMakeLists.txt

@@ -140,7 +140,7 @@ add_executable(${PROJECT_NAME}
     serialgpsthread.h serialgpsthread.cpp
     worker/timeupdatethread.h worker/timeupdatethread.cpp
     logo.rc
-    loadingdialog.h loadingdialog.cpp
+
     logger.h
     logger.cpp
     loadingWidget.h

+ 3 - 3
blastProject/blastprojectpage.cpp

@@ -42,7 +42,7 @@ BlastProjectPage::BlastProjectPage(QWidget *parent) :
     connect(dialog, &ProjectDialog::validateDetNum, this, &BlastProjectPage::insertPlan);
     connect(dialog, &ProjectDialog::validateDetNumUpdate, this, &BlastProjectPage::updateProject);
 
-    client = MqttClient::getInstance();
+    mqttClient = MqttClient::getInstance();
 
 
 }
@@ -273,8 +273,8 @@ void BlastProjectPage::insertPlan(const QMap<QString, QString> &data)
         QJsonDocument jsonDoc(jsonArray);
         QByteArray jsonData = jsonDoc.toJson(QJsonDocument::Indented);
 
-        client->sendMessage("hxgc/companycode/pro/B", jsonData);
-        qDebug() <<"mqtt单例:"<< client;
+        mqttClient->sendMessage("hxgc/companycode/pro/B", jsonData);
+        qDebug() <<"mqtt单例:"<< mqttClient;
     }
 
 }

+ 1 - 1
blastProject/blastprojectpage.h

@@ -54,7 +54,7 @@ private:
     HProjectDao dao;
     QJsonArray dataArray;
     QJsonArray dataArrayAddress;
-    MqttClient *client;
+    MqttClient *mqttClient;
     int pageSize;  //每页显示的记录数量
     int currentPage;      //当前页面
     int totalCount;

+ 1 - 1
blastRecord/hblastrecorddao.cpp

@@ -49,7 +49,7 @@ bool HBlastRecordDao::addHBlastRecord(const HBlastRecord& record)
     query.bindValue(":equipment_count", record.getEquipmentCount());
     query.bindValue(":reg_det_count", record.getRegDetCount());
     query.bindValue(":error_det_count", record.getErrorDetCount());
-    query.bindValue(":blast_at", record.getBlastAt());
+    query.bindValue(":blast_at", record.getBlastAt().toString(Qt::ISODateWithMs));
     query.bindValue(":created_at", record.getCreatedAt().toString(Qt::ISODateWithMs));
     query.bindValue(":create_by", record.getCreateBy());
     qDebug() << "created_at:" << record.getCreatedAt();

+ 1 - 1
blastRegRecord/hblastregrecorddao.cpp

@@ -2,7 +2,7 @@
 
 HBlastRegRecordDao::HBlastRegRecordDao(QSqlDatabase db) : database(db) {}
 
-bool HBlastRegRecordDao::addHBlastRegRecord(const HBlastRegRecord& record) {
+bool HBlastRegRecordDao::saveHBlastRegRecord(const HBlastRegRecord& record) {
     QSqlQuery query;
     query.prepare("INSERT INTO h_blast_reg_record (uuid, equip_sn, equip_version, reg_deto_count, error_deto_count, after_test_bus_v, after_test_bus_i, bus_leakage_current_i, net_charged_v, net_charged_i, before_blasting_v, before_blasting_i, record_uuid, created_at, updated_at, deleted_at, create_by, update_by) "
                   "VALUES (:uuid, :equip_sn, :equip_version, :reg_deto_count, :error_deto_count, :after_test_bus_v, :after_test_bus_i, :bus_leakage_current_i, :net_charged_v, :net_charged_i, :before_blasting_v, :before_blasting_i, :record_uuid, :created_at, :updated_at, :deleted_at, :create_by, :update_by)");

+ 1 - 1
blastRegRecord/hblastregrecorddao.h

@@ -12,7 +12,7 @@ class HBlastRegRecordDao
 public:
     HBlastRegRecordDao(QSqlDatabase db);
 
-     bool addHBlastRegRecord(const HBlastRegRecord& record);
+     bool saveHBlastRegRecord(const HBlastRegRecord& record);
      bool updateHBlastRegRecord(const HBlastRegRecord& record);
      bool deleteHBlastRegRecord(qint64 id);
      // HBlastRegRecord getHBlastRegRecordById(qint64 id);

+ 9 - 8
blastopepage.cpp

@@ -39,7 +39,7 @@ void BlastOpePage::showDownWidget(QString uuid,const QString &topic,const QStrin
 void BlastOpePage::InitFace()
 {
     Logger::getInstance().info("start init face verification");
-    LoadingWidget::showLoading(nullptr, "请求创建人脸识别...");
+    LoadingWidget::showLoading(this, "请求创建人脸识别...");
     layout = new QVBoxLayout(this);
     view = new QWebEngineView(this);
     view->setAttribute(Qt::WA_OpaquePaintEvent);
@@ -53,12 +53,11 @@ void BlastOpePage::InitFace()
     });
 
     Logger::getInstance().info("FaceVerification: connect");
-    // QUrl postUrl("http://192.168.1.234:8000/api/v1/h-face-verify/pc");
     QUrl postUrl(g_url.resolved(QUrl("h-face-verify/pc")));
     QJsonObject response = sendPostRequest(postUrl, metaInfo);
     QString certifyUrl;
     if (response.contains("data") && response["data"].isObject()) {
-        LoadingWidget::showLoading(nullptr, "正在打开人脸识别界面...");
+        LoadingWidget::showLoading(this, "正在打开人脸识别界面...");
         QJsonObject dataObject = response["data"].toObject();
         if (dataObject.contains("ResultObject") && dataObject["ResultObject"].isObject()) {
             QJsonObject resultObject = dataObject["ResultObject"].toObject();
@@ -103,8 +102,9 @@ void BlastOpePage::closeWebViewAndRestoreUI()
 
 // 槽函数:处理 URL 改变事件
 void BlastOpePage::onUrlChanged(const QUrl &newUrl) {
+    qDebug() << "newUrl: "<<newUrl ;
+    LoadingWidget::showLoading(this, "跳转验证页...");
     if (newUrl.scheme() == "https" && newUrl.host() == "www.baidu.com") {
-        LoadingWidget::showLoading(nullptr, "跳转验证页...");
         closeWebViewAndRestoreUI();
         QNetworkAccessManager manager;
         QUrl requestUrl(g_url.resolved(QUrl(QString("h-face-verify/certifyId/%1").arg(certifyId))));
@@ -151,6 +151,7 @@ void BlastOpePage::onUrlChanged(const QUrl &newUrl) {
         reply->deleteLater();
         LoadingWidget::hideLoading();
     }
+    LoadingWidget::hideLoading();
 }
 
 
@@ -697,21 +698,21 @@ void BlastOpePage::handleSelect(QString uuid){
             QByteArray data = "\r\nENABLE_BUTTON\r\n";
             bool success = serialTool->sendData(data);
             if (success) {
-
-                qDebug() << "Data sent successfully";
+                Logger::getInstance().info("blast triggered.");
             } else {
-                qDebug() << "Failed to send data";
+                Logger::getInstance().warn("blast trigger failed.");
             }
             connect(serialTool, &SerialTool::enableButtonReceived,this, [this]() {
-
                 for (const auto& row : uuidMap.keys()) {
                     qDebug() << "Key:" << row;
                     onUpdateBlastStatus(10,row);
                 }
             }, Qt::SingleShotConnection);
 
+            // TODO: receive blast record
         }else {
             qDebug() << "serialTool Not fond.";
+            QMessageBox::critical(nullptr, "错误", "trigger button devices not found");
 
         }
     } else {

+ 3 - 2
databasemanager.cpp

@@ -10,7 +10,8 @@ DatabaseManager& DatabaseManager::getInstance() {
 
 // 创建一个新的数据库连接
 DatabaseManager::DatabaseManager() : db(QSqlDatabase::addDatabase("QMYSQL")) {
-    db.setHostName("192.168.1.234");
+    QString host("192.168.1.160");
+    db.setHostName(host);
     db.setDatabaseName("pc_system");
     db.setUserName("root");
     db.setPassword("123456");
@@ -18,7 +19,7 @@ DatabaseManager::DatabaseManager() : db(QSqlDatabase::addDatabase("QMYSQL")) {
     if (!db.open()) {
         qDebug() << "Failed to open database: " << db.lastError().text();
     }
-    Logger::getInstance().info("Mysql Connected");
+    Logger::getInstance().info(QString("Mysql Connected. host: %1").arg(host));
 
 }
 

+ 0 - 1
detInfo/detinfopage.cpp

@@ -15,7 +15,6 @@ DetInfoPage::DetInfoPage(QWidget *parent) :
     currentPage = 1;
     ui->verticalLayout_4->addWidget(m_pPageWidget);
     loadAndRefreshData();
-    loadingDialog = new LoadingDialog(this);
 
 
 }

+ 0 - 2
detInfo/detinfopage.h

@@ -17,7 +17,6 @@
 #include "../global.h"
 #include "../PageWidget.h"
 #include "../HttpClient.h"
-#include "../loadingdialog.h"
 
 namespace Ui {
 class DetInfoPage;
@@ -58,7 +57,6 @@ private:
     QStandardItemModel *model;
     QJsonArray dataArray;
     QLabel *loadingLabel;  // 用于显示加载图片的标签
-    LoadingDialog *loadingDialog; // 新增成员变量
     QPoint lastPos;
 
 };

+ 4 - 1
equipment/equipmentpage.ui

@@ -124,6 +124,9 @@
              <height>16777215</height>
             </size>
            </property>
+           <property name="autoFillBackground">
+            <bool>true</bool>
+           </property>
           </widget>
          </item>
          <item>
@@ -142,7 +145,7 @@
         </layout>
        </widget>
       </item>
-      <item alignment="">
+      <item>
        <widget class="QFrame" name="frame">
         <property name="minimumSize">
          <size>

+ 41 - 31
fireWidget/firingwidget.cpp

@@ -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();
-   //   }
 }

+ 5 - 4
fireWidget/firingwidget.h

@@ -50,11 +50,12 @@ private slots:
     //双键按下
     void onButtonPressedReceived(const QString &topic,const QString &message);
     void onLastStageChanged(int newStage);
-    void updateWebData(const QJsonObject &data);
+    void saveProjDataAndUpload(const QJsonObject &data);
 private:
-    bool addRegData(const QJsonObject &jsonObj);
-    bool addDetData(const QJsonObject &jsonObj);
-    bool danUpload(const QJsonObject &jsonObj);
+    bool addRegRecords(const QJsonObject &jsonObj);
+    bool handleBlastFinishedMsg(const QJsonObject &jsonObj);
+    bool uploadToDanLing(const QJsonObject &jsonObj);
+    void saveDataToLocalD(const QJsonObject &jsonObj);
     void sendMqttMessage(const QString &topic, const QByteArray &message);
     void startBlasting();
 

+ 1 - 1
global.cpp

@@ -1,6 +1,6 @@
 #include "global.h"
 
-QUrl g_url("http://192.168.1.234:8000/api/v1/");  // 定义并初始化全局变量
+QUrl g_url("http://114.55.233.194:8088/api/v1/");  // 定义并初始化全局变量
 QString labLat("未知");
 QString labLon("未知");
 QString globalAuthority;

+ 1 - 0
global.h

@@ -4,6 +4,7 @@
 #include <QUrl>
 #include <QUrlQuery>
 #include <QString>
+#include "logger.h"
 
 extern QUrl g_url;  // 声明全局变量
 extern QString labLat;  // 新增的全局变量声明

+ 1 - 1
loadingWidget.cpp

@@ -97,6 +97,6 @@ void LoadingWidget::updatePosition()
         // 如果没有父窗口,居中显示在屏幕
         QRect screenGeometry = QApplication::primaryScreen()->geometry();
         resize(screenGeometry.size());
-        //move(screenGeometry.center() - rect().center());
+        move(screenGeometry.center() - rect().center());
     }
 }

+ 0 - 45
loadingdialog.cpp

@@ -1,45 +0,0 @@
-#include "loadingdialog.h"
-#include <QVBoxLayout>
-
-LoadingDialog::LoadingDialog(QWidget *parent) : QDialog(parent)
-{
-    // 设置对话框无边框且模态显示
-    setWindowFlags(Qt::FramelessWindowHint | Qt::Dialog);
-    // setModal(true);
-    // 设置对话框背景透明
-    setAttribute(Qt::WA_TranslucentBackground, true);
-
-    // 创建垂直布局
-    QVBoxLayout *layout = new QVBoxLayout(this);
-
-    // 初始化加载图片标签
-    loadingLabel = new QLabel(this);
-
-    // 创建 QMovie 对象并设置动图文件
-    loadingMovie = new QMovie(":/icons/icons/loading-un.gif");  // 替换为实际的加载图片路径
-    if (loadingMovie->isValid()) {
-        // 设置动图的显示大小
-        int targetWidth = 200;  // 可根据需要调整宽度
-        int targetHeight = 200; // 可根据需要调整高度
-        loadingMovie->setScaledSize(QSize(targetWidth, targetHeight));
-
-        // 将 QMovie 对象设置给 QLabel
-        loadingLabel->setMovie(loadingMovie);
-        loadingLabel->setAlignment(Qt::AlignCenter);
-
-        // 开始播放动图
-        loadingMovie->start();
-    }
-
-    // 将加载图片标签添加到布局中
-    layout->addWidget(loadingLabel, 0, Qt::AlignCenter);
-
-    // 设置布局
-    setLayout(layout);
-}
-
-LoadingDialog::~LoadingDialog()
-{
-    delete loadingMovie;
-    delete loadingLabel;
-}

+ 0 - 20
loadingdialog.h

@@ -1,20 +0,0 @@
-#ifndef LOADINGDIALOG_H
-#define LOADINGDIALOG_H
-
-#include <QDialog>
-#include <QLabel>
-#include <QMovie>
-
-class LoadingDialog : public QDialog
-{
-    Q_OBJECT
-public:
-    explicit LoadingDialog(QWidget *parent = nullptr);
-    ~LoadingDialog();
-
-private:
-    QLabel *loadingLabel;
-    QMovie *loadingMovie;
-};
-
-#endif // LOADINGDIALOG_H

+ 15 - 7
main.cpp

@@ -10,18 +10,27 @@
 
 int main(int argc, char *argv[])
 {
-    QApplication a(argc, argv);
+    QApplication app(argc, argv);
 
-    //TODO: 确认硬件配置,是否需要使用GPU及设备是否安装驱动
-    //QCoreApplication::setAttribute(Qt::AA_UseOpenGLES); // 强制使用 ANGLE (OpenGL ES over DirectX/Vulkan)
     QQuickWindow::setSceneGraphBackend("software"); // 兼容性: 禁用GPU
 
+    /*TODO: delete
+     * QString jsonString = "{\"app_version\":\"1.52\",\"blast_latitude\":\"30.21122186731856\",\"blast_longitude\":\"120.22146062951883\",\"blast_time\":\"2025-05-29 16:02:32\",\"company_code\":\"3701234300003\",\"equipment_sn\":\"F34A0000001\",\"error_deto_count\":\"0\",\"operator_identity\":\"330781198509079292\",\"operator_name\":\"栋工\",\"phone\":\"18611112222\",\"project_htid\":\"\",\"project_name\":\"sidf\",\"project_xmbh\":\"\",\"reg_deto_count\":\"2\",\"regs\":[{\"after_test_bus_i\":\"41\",\"after_test_bus_v\":\"8006\",\"before_blasting_i\":\"49\",\"before_blasting_v\":\"13492\",\"bus_leakage_current_i\":\"0\",\"dets\":[{\"delay_time\":\"0.0\",\"freq\":\"0\",\"in_code\":\"005AC8360A4C01A7\",\"out_code\":\"2411104F18000\",\"status\":\"0x00\",\"tag\":\"1-1-1\",\"uid\":\"24211104F18000\"},{\"delay_time\":\"80.0\",\"freq\":\"0\",\"in_code\":\"015AC8360A4C014E\",\"out_code\":\"2411104F18001\",\"status\":\"0x00\",\"tag\":\"1-2-1\",\"uid\":\"24211104F18001\"}],\"equipment_sn\":\"null\",\"equipment_version\":\"null\",\"error_deto_count\":\"0\",\"net_charged_i\":\"49\",\"net_charged_v\":\"13501\",\"reg_deto_count\":\"2\"}]}";
+    // 使用 QJsonDocument::fromJson 直接解析 QByteArray 并获取 QJsonObject
+    // 这是一个非常简洁的单行操作,假设你知道顶层是 JSON 对象且不关心详细的错误信息
+    QJsonObject myJsonObject = QJsonDocument::fromJson(jsonString.toUtf8()).object();
+    qDebug() <<"debug" << QDateTime::fromString(myJsonObject["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss").toString();
+    qDebug() <<"debug" << QDateTime::fromString(myJsonObject["blast_time"].toString(), "yyyy-MM-dd hh:mm:ss").toString(Qt::ISODateWithMs);
+     */
+
+
+
     // 加载 QSS 文件
     QFile styleFile(":/qss/qss/tableview.qss");
     if (styleFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
         QTextStream stream(&styleFile);
         QString styleSheet = stream.readAll();
-        a.setStyleSheet(styleSheet);
+        app.setStyleSheet(styleSheet);
         styleFile.close();
     }
     // // 获取屏幕信息
@@ -33,7 +42,6 @@ int main(int argc, char *argv[])
     // logger
     Logger::getInstance("application.log");
 
-    // Optional: Set logger configurations
     Logger::getInstance().setMaxFileSize(2 * 1024 * 1024); // 2 MB
     Logger::getInstance().setMaxBackupFiles(3);           // Keep 3 backup files
     Logger::getInstance().info("Application started from main.");
@@ -45,9 +53,9 @@ int main(int argc, char *argv[])
     LoginWindow w;
      //loginWindow.show();
     // 设置应用程序图标
-    a.setWindowIcon(QIcon(":/icons/icons/l634z-aceaj-001.ico"));
+    app.setWindowIcon(QIcon(":/icons/icons/l634z-aceaj-001.ico"));
     // w.resize(screenWidth * 1, screenHeight * 0.95);
     // firingWidget w;
     w.show();
-    return a.exec();
+    return app.exec();
 }

+ 1 - 3
mainwindow.cpp

@@ -131,8 +131,7 @@ void MainWindow::messageAndTopicReceived(const QByteArray &message, const QMqttT
         if (jsonObj.contains("uuid")&& jsonObj.contains("status")) {
             QJsonValue uuidValue = jsonObj["uuid"];
             QJsonValue statusValue = jsonObj["status"];
-            if (statusValue.isString() && statusValue.toString() == "1") {
-
+            if (statusValue.isString() && statusValue.toString() == "1") { // "1" 未注册
                 if (uuidValue.isNull()) {
                     qDebug() << "uuid 的值为 null";
                 } else {
@@ -143,7 +142,6 @@ void MainWindow::messageAndTopicReceived(const QByteArray &message, const QMqttT
             }
         }
     }
-
 }
 
 void MainWindow::setStyleSheets(QPushButton  *selectedButton)

+ 9 - 6
mqtt/mqttclient.cpp

@@ -1,6 +1,8 @@
 #include "mqttclient.h"
 #include <QJsonDocument>
 #include <QJsonObject>
+#include "../logger.h"
+#include <QMessageBox>
 
 
 MqttClient* MqttClient::instance = nullptr;
@@ -16,7 +18,7 @@ MqttClient::MqttClient(QObject *parent)
     connect(mqClient, &QMqttClient::messageReceived, this, &MqttClient::onMessageReceived);
 
     connect(mqClient, &QMqttClient::errorChanged, this, [this](QMqttClient::ClientError error) {
-        qDebug() << "MQTT Error:" << error;
+        Logger::getInstance().error(QString("MQTT error: %1").arg(error));
     });
 
     connect(mqClient, &QMqttClient::connected, this, &MqttClient::connected);
@@ -57,8 +59,6 @@ void MqttClient::connectToMqttBroker()
 
 void MqttClient::connectToMqttBroker(const QString& hostname, quint16 port, const QString& username, const QString& password, const QString& clientId,const QStringList& topicsToSubscribe)
 {
-    qDebug() << "MQTT 1511: " ;
-
     mqClient->setHostname(hostname);
     mqClient->setPort(port);
 
@@ -75,6 +75,7 @@ void MqttClient::connectToMqttBroker(const QString& hostname, quint16 port, cons
 }
 void MqttClient::onConnected()
 {
+    Logger::getInstance().debug("MQTT conncted");
     subscribeToTopics(m_subscribeTopics);
 }
 
@@ -99,20 +100,20 @@ void MqttClient::subscribeToTopic(const QString &topic)
 void MqttClient:: sendMessage(const QString& topic, const QByteArray& message)
 {
     if (mqClient->state() == QMqttClient::Connected) {
-        auto pub = mqClient->publish(QMqttTopicName(topic), message);
+        quint8 qos = 1;
+        auto pub = mqClient->publish(QMqttTopicName(topic), message, qos, true);
         if (pub == -1)
             qDebug() << "Could not publish message";
         else
             qDebug() << "Message published"<<message;
     } else {
         qDebug() << "Not connected to MQTT server";
+
     }
 }
 
 void MqttClient::onMessageReceived(const QByteArray &message, const QMqttTopicName &topic)
 {
-
-
     if (topic.name() == "hxgc/companycode/pro/P") {
         emit proMessageReceived(message,topic);
     }else{
@@ -125,7 +126,9 @@ void MqttClient::onStateChanged(QMqttClient::ClientState state)
 {
     switch (state) {
     case QMqttClient::ClientState::Disconnected:
+        QMessageBox::information(nullptr, "提示", "MQTT连接已断开,请重新登录");
         qDebug() << "MQTT 客户端状态: 断开连接";
+        Logger::getInstance().info("Start init Mqtt server.");
         break;
     case QMqttClient::ClientState::Connecting:
         qDebug() << "MQTT 客户端状态: 正在连接";

+ 19 - 0
qss/tableview.qss

@@ -1,3 +1,22 @@
+QWidget {
+    background-color: #ffffff;
+    color: rgb(48, 65, 86);
+    /*border: 1px solid rgb(48, 65, 86);*/
+    font-weight: bold;
+}
+QPushButton {
+    background-color: #222222;
+    color: #ffffff;
+    border: 2px solid #ffffff;
+}
+QLineEdit, QComboBox {
+    color: rgb(48, 65, 86);
+}
+QLabel {
+    color:rgb(48, 65, 86);
+    font-weight: bold;
+}
+
 /* 表格视图样式 */
 QTableView {
     border: none; /* 无外边框 */