63 lines
2.8 KiB
C++
63 lines
2.8 KiB
C++
#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 ¤cy
|
||
);
|
||
|
||
[[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);
|
||
};
|