1
0
forked from BRT/arc

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.

This commit is contained in:
slava 2026-05-27 15:09:59 +05:00
parent 07399670c0
commit 942d6137e9
7 changed files with 54 additions and 14 deletions

View File

@ -324,6 +324,23 @@ QList<BankProfileInfo> BankProfileDAO::findAllByBankProfileId(const QString &ban
return list; 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) { bool BankProfileDAO::activateAppsForDevice(const QString &deviceId) {
QSqlQuery query(DatabaseManager::instance().database()); QSqlQuery query(DatabaseManager::instance().database());
query.prepare(R"( query.prepare(R"(

View File

@ -50,6 +50,8 @@ public:
[[nodiscard]] static bool checkInstalledApps(const QString &deviceId, const QSet<QString> &apps); [[nodiscard]] static bool checkInstalledApps(const QString &deviceId, const QSet<QString> &apps);
[[nodiscard]] static QStringList getActiveBankProfileIds();
[[nodiscard]] static bool activateAppsForDevice(const QString &deviceId); [[nodiscard]] static bool activateAppsForDevice(const QString &deviceId);
[[nodiscard]] static bool deactivateAppsForDevice(const QString &deviceId); [[nodiscard]] static bool deactivateAppsForDevice(const QString &deviceId);

View File

@ -68,6 +68,24 @@ QList<QString> DeviceDAO::getOnlineDeviceCodes() {
return codes; 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) { DeviceInfo DeviceDAO::getDeviceById(const QString &deviceId) {
QSqlQuery query(DatabaseManager::instance().database()); QSqlQuery query(DatabaseManager::instance().database());

View File

@ -24,5 +24,7 @@ public:
[[nodiscard]] static QList<QString> getOnlineDeviceCodes(); [[nodiscard]] static QList<QString> getOnlineDeviceCodes();
[[nodiscard]] static QStringList getOnlineDeviceApiIds();
[[nodiscard]] static bool deleteDevice(const QString &deviceId); [[nodiscard]] static bool deleteDevice(const QString &deviceId);
}; };

View File

@ -60,9 +60,9 @@ void EventHandler::start() {
if (!materialIds.isEmpty()) { if (!materialIds.isEmpty()) {
m_network->getTasks(materialIds); m_network->getTasks(materialIds);
} else { } else {
qDebug() << "[EventHandler] No free materials to poll." // qDebug() << "[EventHandler] No free materials to poll."
<< "busyDevices:" << busyDevices // << "busyDevices:" << busyDevices
<< "onlineDevices:" << onlineDevices; // << "onlineDevices:" << onlineDevices;
} }
}); });
m_pollTimer->start(); m_pollTimer->start();

View File

@ -1049,16 +1049,17 @@ bool NetworkService::syncCurrentProfile() {
bool NetworkService::doPingProfile() { bool NetworkService::doPingProfile() {
if (!ensureValidToken()) return false; if (!ensureValidToken()) return false;
const QString desktopId = SettingsDAO::get("desktop_id"); QJsonArray devicesArr;
if (desktopId.isEmpty()) { for (const QString &id : DeviceDAO::getOnlineDeviceApiIds())
qWarning() << "[NetworkService] pingProfile: desktop_id is empty, skip"; devicesArr.append(id);
return false;
} QJsonArray bankProfilesArr;
for (const QString &id : BankProfileDAO::getActiveBankProfileIds())
bankProfilesArr.append(id);
const QSettings settings("config.ini", QSettings::IniFormat);
QJsonObject body; QJsonObject body;
body["desktop_id"] = desktopId; body["bank_profiles"] = bankProfilesArr;
body["version"] = settings.value("common/version").toString(); body["devices"] = devicesArr;
const QJsonValue result = postJson(m_apiBase + m_pathProfilePing, body, true); const QJsonValue result = postJson(m_apiBase + m_pathProfilePing, body, true);
Q_UNUSED(result); Q_UNUSED(result);

View File

@ -1,7 +1,7 @@
{ {
"bank_profiles": [ "bank_profiles": [
{ {
"id": "9b2f1a38-190c-4cb0-b026-eef721db36ed", "id": "c64542d9-9185-42e4-98e4-e84b2c5c6741",
"bank_name": "ozon", "bank_name": "ozon",
"state": "enabled", "state": "enabled",
"phone_number": "+79538038318", "phone_number": "+79538038318",
@ -9,11 +9,11 @@
"middle_name": null, "middle_name": null,
"last_name": "Терехина", "last_name": "Терехина",
"currency": 643, "currency": 643,
"device_id": "cca4ec91-26e4-42e0-81ce-5226382b6cbc", "device_id": "a6049cd1-ce26-4a58-8421-cac3fdd18930",
"device_label": "Pixel 7", "device_label": "Pixel 7",
"materials": [ "materials": [
{ {
"id": "e1234f11-b99d-4930-9f86-75148601f683", "id": "d49d3d02-ecce-4e00-97d5-0c52da6fd0db",
"state": "enabled", "state": "enabled",
"card_number": "2204321035207919", "card_number": "2204321035207919",
"currency": 643 "currency": 643