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:
parent
07399670c0
commit
942d6137e9
@ -324,6 +324,23 @@ QList<BankProfileInfo> 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"(
|
||||
|
||||
@ -50,6 +50,8 @@ public:
|
||||
|
||||
[[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 deactivateAppsForDevice(const QString &deviceId);
|
||||
|
||||
@ -68,6 +68,24 @@ QList<QString> 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());
|
||||
|
||||
|
||||
@ -24,5 +24,7 @@ public:
|
||||
|
||||
[[nodiscard]] static QList<QString> getOnlineDeviceCodes();
|
||||
|
||||
[[nodiscard]] static QStringList getOnlineDeviceApiIds();
|
||||
|
||||
[[nodiscard]] static bool deleteDevice(const QString &deviceId);
|
||||
};
|
||||
|
||||
@ -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();
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user