From b395ed41a50775faa6e8b55f7c9f566f9cde8557 Mon Sep 17 00:00:00 2001 From: slava Date: Wed, 25 Mar 2026 16:05:27 +0700 Subject: [PATCH] Add bank profile toggling in `DeviceWidget` and enhance error handling in `EventHandler` - Implemented `sendBankStatus` logic with `NetworkService` and threading for bank profile enable/disable functionality. - Improved error handling in `EventHandler` by logging and updating events when bank profiles are disabled. --- services/EventHandler.cpp | 8 +++++++- views/device/DeviceWidget.cpp | 21 +++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/services/EventHandler.cpp b/services/EventHandler.cpp index fc333c6..8886b38 100644 --- a/services/EventHandler.cpp +++ b/services/EventHandler.cpp @@ -450,7 +450,13 @@ void EventHandler::processNextTask(const QString &deviceId) { const AccountInfo account = AccountDAO::getAccountById(event.accountId); const ApplicationInfo app = ApplicationDAO::getApplication(deviceId, account.appCode); - if (app.status != "active") break; + if (app.status != "active") { + qWarning() << "[EventHandler] Bank profile disabled for" << account.appCode << "device:" << deviceId; + EventDAO::updateEvent(event.id, EventStatus::Error, "Bank profile is disabled"); + sendTaskError(eventTypeToString(event.type), event.externalId, event.bankName, + "Bank profile is disabled: " + account.appCode); + continue; + } if (!EventDAO::updateEvent(event.id, EventStatus::InProgress, "")) { qCritical() << "[EventHandler] Failed to set InProgress, event id:" << event.id; diff --git a/views/device/DeviceWidget.cpp b/views/device/DeviceWidget.cpp index f212692..fbce54e 100644 --- a/views/device/DeviceWidget.cpp +++ b/views/device/DeviceWidget.cpp @@ -16,6 +16,8 @@ #include "dao/ApplicationDAO.h" #include "dao/DeviceDAO.h" #include "db/ApplicationInfo.h" +#include "net/NetworkService.h" +#include QString getColorByStatus(const ApplicationInfo &app) { @@ -35,8 +37,23 @@ QString getColorByStatus(const ApplicationInfo &app) { } void sendBankStatus(const QString &deviceId, const QString &code, const QString &status) { - Q_UNUSED(deviceId) Q_UNUSED(code) Q_UNUSED(status) - // TODO: заменить на новый API + const ApplicationInfo app = ApplicationDAO::getApplication(deviceId, code); + if (app.bankProfileId.isEmpty()) { + qWarning() << "[DeviceWidget] sendBankStatus: no bankProfileId for" << code; + return; + } + + const bool enable = (status == "active"); + auto *thread = new QThread; + auto *net = new NetworkService; + net->moveToThread(thread); + net->addExtra("bank_profile_id", app.bankProfileId); + net->addExtra("enable", enable); + QObject::connect(thread, &QThread::started, net, &NetworkService::toggleBankProfile); + QObject::connect(net, &NetworkService::finished, thread, &QThread::quit); + QObject::connect(net, &NetworkService::finished, net, &QObject::deleteLater); + QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater); + thread->start(); } void DeviceWidget::buildBankRow(const ApplicationInfo &app, QWidget *rowWidget, QWidget *parent, bool isOffline) {