Add maxCount support to GetLastTransactionsScript and UI updates for transaction limits
Implemented a `maxCount` parameter in `GetLastTransactionsScript` to limit the number of transactions retrieved. Updated `AccountSettingsWindow` to include new transaction limit options in the UI. Enhanced retrieval logic to support either time-based filtering (24 hours) or count-based limits, ensuring flexibility in transaction handling.
This commit is contained in:
parent
277f94c15a
commit
e9aaa71c56
@ -61,9 +61,10 @@ namespace Ozon {
|
|||||||
GetLastTransactionsScript::GetLastTransactionsScript(
|
GetLastTransactionsScript::GetLastTransactionsScript(
|
||||||
QString deviceId,
|
QString deviceId,
|
||||||
QString appCode,
|
QString appCode,
|
||||||
|
int maxCount,
|
||||||
QObject *parent
|
QObject *parent
|
||||||
) : CommonScript(parent),
|
) : CommonScript(parent),
|
||||||
m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)) {
|
m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)), m_maxCount(maxCount) {
|
||||||
}
|
}
|
||||||
|
|
||||||
GetLastTransactionsScript::~GetLastTransactionsScript() = default;
|
GetLastTransactionsScript::~GetLastTransactionsScript() = default;
|
||||||
@ -270,8 +271,13 @@ void GetLastTransactionsScript::doStart() {
|
|||||||
<< "phone:" << tx.phone
|
<< "phone:" << tx.phone
|
||||||
<< "amount:" << (tx.amount >= 0 ? "+" : "") + QString::number(tx.amount, 'f', 2);
|
<< "amount:" << (tx.amount >= 0 ? "+" : "") + QString::number(tx.amount, 'f', 2);
|
||||||
|
|
||||||
// Если транзакция старше 24 часов — прекращаем
|
// Если задан лимит по количеству — проверяем счётчик
|
||||||
if (tx.completeTime.isValid()) {
|
// Иначе фильтруем по 24 часам
|
||||||
|
if (m_maxCount > 0) {
|
||||||
|
if (transactions.size() + 1 >= m_maxCount) {
|
||||||
|
// Эта транзакция последняя — сохраним и выйдем после обработки
|
||||||
|
}
|
||||||
|
} else if (tx.completeTime.isValid()) {
|
||||||
const qint64 ageSecs = tx.completeTime.toUTC().secsTo(QDateTime::currentDateTimeUtc());
|
const qint64 ageSecs = tx.completeTime.toUTC().secsTo(QDateTime::currentDateTimeUtc());
|
||||||
if (ageSecs > 24 * 3600) {
|
if (ageSecs > 24 * 3600) {
|
||||||
qDebug() << "[GetLastTransactions] Transaction older than 24h, stopping";
|
qDebug() << "[GetLastTransactions] Transaction older than 24h, stopping";
|
||||||
@ -356,6 +362,14 @@ void GetLastTransactionsScript::doStart() {
|
|||||||
|
|
||||||
transactions.append(tx);
|
transactions.append(tx);
|
||||||
|
|
||||||
|
// Если достигнут лимит по количеству — выходим
|
||||||
|
if (m_maxCount > 0 && transactions.size() >= m_maxCount) {
|
||||||
|
qDebug() << "[GetLastTransactions] Reached maxCount limit:" << m_maxCount;
|
||||||
|
AdbUtils::goBack(m_deviceId);
|
||||||
|
QThread::msleep(1000);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
// Возвращаемся в список
|
// Возвращаемся в список
|
||||||
AdbUtils::goBack(m_deviceId);
|
AdbUtils::goBack(m_deviceId);
|
||||||
QThread::msleep(1500);
|
QThread::msleep(1500);
|
||||||
|
|||||||
@ -10,6 +10,7 @@ public:
|
|||||||
explicit GetLastTransactionsScript(
|
explicit GetLastTransactionsScript(
|
||||||
QString deviceId,
|
QString deviceId,
|
||||||
QString appCode,
|
QString appCode,
|
||||||
|
int maxCount = 0,
|
||||||
QObject *parent = nullptr
|
QObject *parent = nullptr
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -21,6 +22,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
const QString m_deviceId;
|
const QString m_deviceId;
|
||||||
const QString m_appCode;
|
const QString m_appCode;
|
||||||
|
const int m_maxCount; // 0 = без лимита (фильтр по 24ч), >0 = только N последних
|
||||||
QString m_error;
|
QString m_error;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -216,7 +216,8 @@ AccountSettingsWindow::AccountSettingsWindow(
|
|||||||
msgBox.setText(
|
msgBox.setText(
|
||||||
"Запустится скрипт получения последних транзакций из " + m_applicationInfo.name +
|
"Запустится скрипт получения последних транзакций из " + m_applicationInfo.name +
|
||||||
". Окно с настройками закроется.");
|
". Окно с настройками закроется.");
|
||||||
QPushButton *runBtn = msgBox.addButton(tr("Запустить"), QMessageBox::AcceptRole);
|
QPushButton *runBtn = msgBox.addButton(tr("За 24 часа"), QMessageBox::AcceptRole);
|
||||||
|
QPushButton *last5Btn = msgBox.addButton(tr("Последние 5"), QMessageBox::AcceptRole);
|
||||||
QPushButton *cancelBtn = msgBox.addButton(tr("Отмена"), QMessageBox::RejectRole);
|
QPushButton *cancelBtn = msgBox.addButton(tr("Отмена"), QMessageBox::RejectRole);
|
||||||
msgBox.setDefaultButton(cancelBtn);
|
msgBox.setDefaultButton(cancelBtn);
|
||||||
msgBox.setModal(true);
|
msgBox.setModal(true);
|
||||||
@ -224,6 +225,9 @@ AccountSettingsWindow::AccountSettingsWindow(
|
|||||||
if (msgBox.clickedButton() == runBtn) {
|
if (msgBox.clickedButton() == runBtn) {
|
||||||
startGetLastTransactions(m_applicationInfo.code);
|
startGetLastTransactions(m_applicationInfo.code);
|
||||||
close();
|
close();
|
||||||
|
} else if (msgBox.clickedButton() == last5Btn) {
|
||||||
|
startGetLastTransactions(m_applicationInfo.code, 5);
|
||||||
|
close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -345,11 +349,11 @@ void AccountSettingsWindow::startGetCardInfo(const QString &appCode) {
|
|||||||
thread->start();
|
thread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AccountSettingsWindow::startGetLastTransactions(const QString &appCode) {
|
void AccountSettingsWindow::startGetLastTransactions(const QString &appCode, int maxCount) {
|
||||||
if (appCode != "ozon") return;
|
if (appCode != "ozon") return;
|
||||||
|
|
||||||
QThread *thread = new QThread(nullptr);
|
QThread *thread = new QThread(nullptr);
|
||||||
auto *worker = new Ozon::GetLastTransactionsScript(m_deviceId, appCode, nullptr);
|
auto *worker = new Ozon::GetLastTransactionsScript(m_deviceId, appCode, maxCount, nullptr);
|
||||||
worker->moveToThread(thread);
|
worker->moveToThread(thread);
|
||||||
connect(thread, &QThread::started, worker, &Ozon::GetLastTransactionsScript::start);
|
connect(thread, &QThread::started, worker, &Ozon::GetLastTransactionsScript::start);
|
||||||
connect(worker, &Ozon::GetLastTransactionsScript::finished, thread, &QThread::quit);
|
connect(worker, &Ozon::GetLastTransactionsScript::finished, thread, &QThread::quit);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ private:
|
|||||||
|
|
||||||
void startGetCardInfo(const QString &appCode);
|
void startGetCardInfo(const QString &appCode);
|
||||||
|
|
||||||
void startGetLastTransactions(const QString &appCode);
|
void startGetLastTransactions(const QString &appCode, int maxCount = 0);
|
||||||
|
|
||||||
void reloadContent(QTableWidget *tableWidget);
|
void reloadContent(QTableWidget *tableWidget);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user