1
0
forked from BRT/arc
arc/database/dao/MaterialDAO.h

68 lines
3.3 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <QSet>
#include "db/MaterialInfo.h"
class MaterialDAO {
public:
[[nodiscard]] static bool upsertAccount(const MaterialInfo &info);
[[nodiscard]] static bool updateAccountById(
int id,
const QString &status,
const QString &description,
const QString &currency
);
[[nodiscard]] static bool updateStatus(int id, const QString &status);
// Атомарно делает targetId единственным активным материалом в (deviceId, appCode).
// Возвращает материалы, которые были переведены в 'off' (для синхронизации с сервером).
[[nodiscard]] static QList<MaterialInfo> activateExclusive(
const QString &deviceId, const QString &appCode, int targetId);
[[nodiscard]] static bool deleteAccount(int id);
[[nodiscard]] static bool updateCardNumber(int accountId, const QString &cardNumber);
[[nodiscard]] static bool updateMaterialId(int accountId, const QString &materialId);
// Атомарно вычитает delta из materials.amount для одного материала.
// delta > 0 — расход, delta < 0 — пополнение.
[[nodiscard]] static bool adjustAmount(int id, double delta);
// Атомарно вычитает delta из materials.amount для всех материалов
// в (deviceId, appCode) — для банков с одним счётом на все карты (Dushanbe).
[[nodiscard]] static bool adjustAmountByApp(const QString &deviceId, const QString &appCode, double delta);
// Перезаписывает materials.amount абсолютным значением для всех материалов
// в (deviceId, appCode). Используется после re-parse экрана.
[[nodiscard]] static bool setAmountByApp(const QString &deviceId, const QString &appCode, double amount);
[[nodiscard]] static QList<MaterialInfo> getAccounts(const QString &deviceId, const QString &appName);
[[nodiscard]] static MaterialInfo getAccountById(int accountId);
[[nodiscard]] static QList<MaterialInfo> getAccountsByAppCode(const QString &appCode);
[[nodiscard]] static MaterialInfo findAppAccount(
const QString &deviceId,
const QString &appName,
const QString &lastNumber
);
[[nodiscard]] static MaterialInfo findByMaterialId(const QString &materialId);
[[nodiscard]] static QStringList getActiveMaterialIds();
[[nodiscard]] static QStringList getActiveMaterialIdsExcludingDevices(const QSet<QString> &excludeDevices);
[[nodiscard]] static bool migrateDeviceId(const QString &oldDeviceId, const QString &newDeviceId);
[[nodiscard]] static bool deleteAccountsByApp(const QString &deviceId, const QString &appCode);
// Удаляет ВСЕ счета (материалы) приложения, включая синхронизированные с
// сервером (material_id задан). Транзакции и события удаляются каскадом по
// materials.id. Используется при полном удалении банковского профиля.
[[nodiscard]] static bool deleteAllAccountsByApp(const QString &deviceId, const QString &appCode);
};