From 942d6137e917dfb5a54891d9b582f1f5ff03b310 Mon Sep 17 00:00:00 2001 From: slava Date: Wed, 27 May 2026 15:09:59 +0500 Subject: [PATCH] Add `getOnlineDeviceApiIds` and `getActiveBankProfileIds` to DAO layers, refactor `NetworkService::doPingProfile` to include device and bank profile details. Comment out unused debug statement in `EventHandler`. Update mock server profile data for testing. --- database/dao/BankProfileDAO.cpp | 17 +++++++++++++++++ database/dao/BankProfileDAO.h | 2 ++ database/dao/DeviceDAO.cpp | 18 ++++++++++++++++++ database/dao/DeviceDAO.h | 2 ++ services/EventHandler.cpp | 6 +++--- services/net/NetworkService.cpp | 17 +++++++++-------- tests/mock_server/default_profile.json | 6 +++--- 7 files changed, 54 insertions(+), 14 deletions(-) diff --git a/database/dao/BankProfileDAO.cpp b/database/dao/BankProfileDAO.cpp index f8f0d8a..21cd676 100644 --- a/database/dao/BankProfileDAO.cpp +++ b/database/dao/BankProfileDAO.cpp @@ -324,6 +324,23 @@ QList BankProfileDAO::findAllByBankProfileId(const QString &ban return list; } +QStringList BankProfileDAO::getActiveBankProfileIds() { + QStringList ids; + QSqlQuery query(DatabaseManager::instance().database()); + query.prepare(R"( + SELECT bank_profile_id FROM bank_profiles + WHERE status = 'active' AND bank_profile_id IS NOT NULL AND bank_profile_id != '' + )"); + if (!query.exec()) { + qWarning() << "Ошибка при получении активных bank_profile_id:" << query.lastError().text(); + return ids; + } + while (query.next()) { + ids.append(query.value(0).toString()); + } + return ids; +} + bool BankProfileDAO::activateAppsForDevice(const QString &deviceId) { QSqlQuery query(DatabaseManager::instance().database()); query.prepare(R"( diff --git a/database/dao/BankProfileDAO.h b/database/dao/BankProfileDAO.h index bb1c14b..1eac238 100644 --- a/database/dao/BankProfileDAO.h +++ b/database/dao/BankProfileDAO.h @@ -50,6 +50,8 @@ public: [[nodiscard]] static bool checkInstalledApps(const QString &deviceId, const QSet &apps); + [[nodiscard]] static QStringList getActiveBankProfileIds(); + [[nodiscard]] static bool activateAppsForDevice(const QString &deviceId); [[nodiscard]] static bool deactivateAppsForDevice(const QString &deviceId); diff --git a/database/dao/DeviceDAO.cpp b/database/dao/DeviceDAO.cpp index e55ae65..d09985d 100644 --- a/database/dao/DeviceDAO.cpp +++ b/database/dao/DeviceDAO.cpp @@ -68,6 +68,24 @@ QList DeviceDAO::getOnlineDeviceCodes() { return codes; } +QStringList DeviceDAO::getOnlineDeviceApiIds() { + QStringList apiIds; + QSqlQuery query(DatabaseManager::instance().database()); + query.prepare(R"( + SELECT api_id FROM devices + WHERE image IS NOT NULL AND status = 'device' + AND api_id IS NOT NULL AND api_id != '' + )"); + if (!query.exec()) { + qWarning() << "Ошибка при получении api_id онлайн-устройств:" << query.lastError().text(); + return apiIds; + } + while (query.next()) { + apiIds.append(query.value(0).toString()); + } + return apiIds; +} + DeviceInfo DeviceDAO::getDeviceById(const QString &deviceId) { QSqlQuery query(DatabaseManager::instance().database()); diff --git a/database/dao/DeviceDAO.h b/database/dao/DeviceDAO.h index c9bbe71..a66f9fa 100644 --- a/database/dao/DeviceDAO.h +++ b/database/dao/DeviceDAO.h @@ -24,5 +24,7 @@ public: [[nodiscard]] static QList getOnlineDeviceCodes(); + [[nodiscard]] static QStringList getOnlineDeviceApiIds(); + [[nodiscard]] static bool deleteDevice(const QString &deviceId); }; diff --git a/services/EventHandler.cpp b/services/EventHandler.cpp index 6286450..590103e 100644 --- a/services/EventHandler.cpp +++ b/services/EventHandler.cpp @@ -60,9 +60,9 @@ void EventHandler::start() { if (!materialIds.isEmpty()) { m_network->getTasks(materialIds); } else { - qDebug() << "[EventHandler] No free materials to poll." - << "busyDevices:" << busyDevices - << "onlineDevices:" << onlineDevices; + // qDebug() << "[EventHandler] No free materials to poll." + // << "busyDevices:" << busyDevices + // << "onlineDevices:" << onlineDevices; } }); m_pollTimer->start(); diff --git a/services/net/NetworkService.cpp b/services/net/NetworkService.cpp index c845ebf..2546d20 100644 --- a/services/net/NetworkService.cpp +++ b/services/net/NetworkService.cpp @@ -1049,16 +1049,17 @@ bool NetworkService::syncCurrentProfile() { bool NetworkService::doPingProfile() { if (!ensureValidToken()) return false; - const QString desktopId = SettingsDAO::get("desktop_id"); - if (desktopId.isEmpty()) { - qWarning() << "[NetworkService] pingProfile: desktop_id is empty, skip"; - return false; - } + QJsonArray devicesArr; + for (const QString &id : DeviceDAO::getOnlineDeviceApiIds()) + devicesArr.append(id); + + QJsonArray bankProfilesArr; + for (const QString &id : BankProfileDAO::getActiveBankProfileIds()) + bankProfilesArr.append(id); - const QSettings settings("config.ini", QSettings::IniFormat); QJsonObject body; - body["desktop_id"] = desktopId; - body["version"] = settings.value("common/version").toString(); + body["bank_profiles"] = bankProfilesArr; + body["devices"] = devicesArr; const QJsonValue result = postJson(m_apiBase + m_pathProfilePing, body, true); Q_UNUSED(result); diff --git a/tests/mock_server/default_profile.json b/tests/mock_server/default_profile.json index 0519d5c..6348111 100644 --- a/tests/mock_server/default_profile.json +++ b/tests/mock_server/default_profile.json @@ -1,7 +1,7 @@ { "bank_profiles": [ { - "id": "9b2f1a38-190c-4cb0-b026-eef721db36ed", + "id": "c64542d9-9185-42e4-98e4-e84b2c5c6741", "bank_name": "ozon", "state": "enabled", "phone_number": "+79538038318", @@ -9,11 +9,11 @@ "middle_name": null, "last_name": "Терехина", "currency": 643, - "device_id": "cca4ec91-26e4-42e0-81ce-5226382b6cbc", + "device_id": "a6049cd1-ce26-4a58-8421-cac3fdd18930", "device_label": "Pixel 7", "materials": [ { - "id": "e1234f11-b99d-4930-9f86-75148601f683", + "id": "d49d3d02-ecce-4e00-97d5-0c52da6fd0db", "state": "enabled", "card_number": "2204321035207919", "currency": 643