Filter bank profiles by profile country and sync material statuses with server:
- Add `m_pathProfileGetInfo` to retrieve profile country and currency during login. - Update bank profile filtering logic in `BankProfileDAO`, `DeviceSettingsWindow`, and `DeviceWidget` to match the profile country from `SettingsDAO`. - Synchronize material statuses with the server in `toggleMaterial`.
This commit is contained in:
parent
377844e94b
commit
afe83e17c2
@ -9,8 +9,8 @@ version=0.0.9
|
||||
dbPath=./database/app_data.db
|
||||
|
||||
[net]
|
||||
#apiBase=http://93.183.75.134:8005
|
||||
apiBase=http://127.0.0.1:8888
|
||||
apiBase=http://93.183.75.134:8005
|
||||
#apiBase=http://127.0.0.1:8888
|
||||
pathAuthLogin=/api/v1/auth/login
|
||||
pathAuthRefresh=/api/v1/auth/refresh_token
|
||||
pathBankProfile=/api/v1/profile/bank_profile
|
||||
@ -24,17 +24,20 @@ pathMonitoringDump=/monitoring/dump
|
||||
[black]
|
||||
android_package_name=app.blackwallet.ar
|
||||
currency=ARS
|
||||
country=argentina
|
||||
name=Black
|
||||
phone_code=54
|
||||
|
||||
[ozon]
|
||||
android_package_name=ru.ozon.fintech.finance
|
||||
currency=RUB
|
||||
country=russia
|
||||
name=Ozon
|
||||
phone_code=7
|
||||
|
||||
[dushanbe_city_bank]
|
||||
android_package_name=tj.dc.next1
|
||||
currency=TJS
|
||||
country=tajikistan
|
||||
name=Dushanbe City
|
||||
phone_code=992
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <QRegularExpression>
|
||||
#include "BankProfileDAO.h"
|
||||
#include "DatabaseManager.h"
|
||||
#include "SettingsDAO.h"
|
||||
#include "db/BankProfileInfo.h"
|
||||
|
||||
bool BankProfileDAO::upsertApplication(const BankProfileInfo &info) {
|
||||
@ -325,6 +326,21 @@ bool BankProfileDAO::checkInstalledApps(const QString &deviceId, const QSet<QStr
|
||||
const QSettings settings("config.ini", QSettings::IniFormat);
|
||||
QStringList banks = settings.value("apps/list", QStringList()).toStringList();
|
||||
|
||||
// Фильтруем банки по стране профиля (если страна задана)
|
||||
const QString profileCountry = SettingsDAO::get("country");
|
||||
if (!profileCountry.isEmpty()) {
|
||||
QStringList filtered;
|
||||
for (const QString &raw : banks) {
|
||||
const QString b = raw.trimmed();
|
||||
if (b.isEmpty()) continue;
|
||||
const QString bankCountry = settings.value(b + "/country").toString();
|
||||
if (bankCountry.compare(profileCountry, Qt::CaseInsensitive) == 0) {
|
||||
filtered << b;
|
||||
}
|
||||
}
|
||||
banks = filtered;
|
||||
}
|
||||
|
||||
// Сбросить install = 'no' для банков которых нет в текущем apps/list
|
||||
if (!banks.isEmpty()) {
|
||||
QStringList placeholders;
|
||||
|
||||
@ -63,6 +63,7 @@ NetworkService::NetworkService(QObject *parent) : QObject(parent) {
|
||||
m_pathMonitoringLog = settings.value("net/pathMonitoringLog", "/monitoring/log").toString();
|
||||
m_pathMonitoringDump = settings.value("net/pathMonitoringDump", "/monitoring/dump").toString();
|
||||
m_pathCurrentProfile = settings.value("net/pathCurrentProfile", "/api/v1/profile/current_profile").toString();
|
||||
m_pathProfileGetInfo = settings.value("net/pathProfileGetInfo", "/api/v1/profile/get_info").toString();
|
||||
m_manager = new QNetworkAccessManager(this);
|
||||
m_token = settings.value("common/token").toString();
|
||||
m_accessToken = SettingsDAO::get("access_token");
|
||||
@ -327,6 +328,17 @@ void NetworkService::loginAndSetup() {
|
||||
const qint64 expiresIn = static_cast<qint64>(loginData["expires_in"].toDouble());
|
||||
SettingsDAO::setLong("token_expires_at", QDateTime::currentSecsSinceEpoch() + expiresIn);
|
||||
|
||||
// Шаг 1.5: получаем страну/валюту профиля
|
||||
const QJsonValue infoResult = getJson(m_apiBase + m_pathProfileGetInfo, true);
|
||||
if (infoResult.isObject()) {
|
||||
const QJsonObject info = infoResult.toObject();
|
||||
const QString country = info["country"].toString();
|
||||
const QString currency = info["currency"].toString();
|
||||
if (!country.isEmpty()) SettingsDAO::set("country", country);
|
||||
if (!currency.isEmpty()) SettingsDAO::set("currency", currency);
|
||||
qDebug() << "[loginAndSetup] profile info: country=" << country << "currency=" << currency;
|
||||
}
|
||||
|
||||
// Шаг 2: получаем актуальный desktop с сервера
|
||||
QString desktopId = SettingsDAO::get("desktop_id");
|
||||
|
||||
@ -1013,11 +1025,25 @@ void NetworkService::toggleMaterial() {
|
||||
const QString enableStr = enable ? "true" : "false";
|
||||
const QString path = m_apiBase + m_pathMaterial + "/" + materialId + "/" + enableStr;
|
||||
const QJsonValue result = patchJson(path, QJsonObject(), true);
|
||||
if (result.isNull() && result.isUndefined()) {
|
||||
if (result.isNull() || result.isUndefined()) {
|
||||
qWarning() << "[NetworkService] toggleMaterial failed:" << materialId;
|
||||
emit finishedWithResult(-1);
|
||||
} else {
|
||||
qDebug() << "[NetworkService] toggleMaterial done:" << materialId << "enable=" << enable;
|
||||
const QJsonArray materials = result.toArray();
|
||||
for (const QJsonValue &v : materials) {
|
||||
const QJsonObject mat = v.toObject();
|
||||
const QString matId = mat["id"].toString();
|
||||
const QString serverState = mat["state"].toString();
|
||||
if (matId.isEmpty()) continue;
|
||||
const MaterialInfo local = MaterialDAO::findByMaterialId(matId);
|
||||
if (local.id < 0) continue;
|
||||
const QString newStatus = (serverState == "disabled") ? "off" : "active";
|
||||
if (materialStatusToString(local.status) != newStatus) {
|
||||
MaterialDAO::updateStatus(local.id, newStatus);
|
||||
}
|
||||
}
|
||||
qDebug() << "[NetworkService] toggleMaterial done:" << materialId << "enable=" << enable
|
||||
<< "synced" << materials.size() << "materials";
|
||||
emit finishedWithResult(0);
|
||||
}
|
||||
|
||||
@ -1039,7 +1065,7 @@ void NetworkService::toggleBankProfile() {
|
||||
const QString enableStr = enable ? "true" : "false";
|
||||
const QString path = m_apiBase + m_pathBankProfile + "/" + bankProfileId + "/" + enableStr;
|
||||
const QJsonValue result = patchJson(path, QJsonObject(), true);
|
||||
if (result.isNull() && result.isUndefined()) {
|
||||
if (result.isNull() || result.isUndefined()) {
|
||||
qWarning() << "[NetworkService] toggleBankProfile failed:" << bankProfileId;
|
||||
emit finishedWithResult(-1);
|
||||
} else {
|
||||
|
||||
@ -102,6 +102,7 @@ private:
|
||||
QString m_pathMonitoringLog;
|
||||
QString m_pathMonitoringDump;
|
||||
QString m_pathCurrentProfile;
|
||||
QString m_pathProfileGetInfo;
|
||||
bool m_fetchingTasks = false;
|
||||
|
||||
QNetworkAccessManager *m_manager;
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include "bank/AccountSettingsWindow.h"
|
||||
#include "bank/BankSetupWizard.h"
|
||||
#include "dao/BankProfileDAO.h"
|
||||
#include "dao/SettingsDAO.h"
|
||||
#include "db/BankProfileInfo.h"
|
||||
|
||||
static QString formatStatus(const BankProfileInfo &app) {
|
||||
@ -67,8 +68,22 @@ DeviceSettingsWindow::DeviceSettingsWindow(QWidget *parent, const QString &devic
|
||||
void DeviceSettingsWindow::reloadContent(QTableWidget *tableWidget) {
|
||||
QList<BankProfileInfo> apps = BankProfileDAO::getAllApplicationsByDeviceId(m_deviceId);
|
||||
|
||||
// Дополняем список банками из config.ini, которых нет в БД
|
||||
const QSettings configSettings("config.ini", QSettings::IniFormat);
|
||||
const QString profileCountry = SettingsDAO::get("country");
|
||||
|
||||
// Фильтруем уже сохранённые в БД банки по стране профиля
|
||||
if (!profileCountry.isEmpty()) {
|
||||
for (auto it = apps.begin(); it != apps.end();) {
|
||||
const QString bankCountry = configSettings.value(it->code + "/country").toString();
|
||||
if (bankCountry.compare(profileCountry, Qt::CaseInsensitive) != 0) {
|
||||
it = apps.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Дополняем список банками из config.ini, которых нет в БД
|
||||
const QStringList banks = configSettings.value("apps/list").toStringList();
|
||||
QSet<QString> existingCodes;
|
||||
for (const BankProfileInfo &a : apps) {
|
||||
@ -77,6 +92,10 @@ void DeviceSettingsWindow::reloadContent(QTableWidget *tableWidget) {
|
||||
for (const QString &rawBank : banks) {
|
||||
const QString bank = rawBank.trimmed();
|
||||
if (bank.isEmpty() || existingCodes.contains(bank)) continue;
|
||||
if (!profileCountry.isEmpty()) {
|
||||
const QString bankCountry = configSettings.value(bank + "/country").toString();
|
||||
if (bankCountry.compare(profileCountry, Qt::CaseInsensitive) != 0) continue;
|
||||
}
|
||||
BankProfileInfo stub;
|
||||
stub.id = -1;
|
||||
stub.deviceId = m_deviceId;
|
||||
|
||||
@ -627,6 +627,21 @@ DeviceWidget::DeviceWidget(const DeviceInfo &device, QWidget *parent): QWidget(p
|
||||
const bool isOffline = device.status != "device";
|
||||
|
||||
QList<BankProfileInfo> apps = BankProfileDAO::getApplicationsByDeviceId(device.id);
|
||||
|
||||
// Фильтр по стране профиля
|
||||
const QString profileCountry = SettingsDAO::get("country");
|
||||
if (!profileCountry.isEmpty()) {
|
||||
const QSettings configSettings("config.ini", QSettings::IniFormat);
|
||||
for (auto it = apps.begin(); it != apps.end();) {
|
||||
const QString bankCountry = configSettings.value(it->code + "/country").toString();
|
||||
if (bankCountry.compare(profileCountry, Qt::CaseInsensitive) != 0) {
|
||||
it = apps.erase(it);
|
||||
} else {
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (BankProfileInfo &app: apps) {
|
||||
if (app.install) {
|
||||
auto *rowWidget = new QWidget(appsView);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user