Add device timezone handling in transaction filtering and refine match logic by amount and timestamp
This commit is contained in:
parent
2febc1e78c
commit
72fceb65ca
@ -358,7 +358,10 @@ void GetLastTransactionsScript::doStart() {
|
||||
qDebug() << "[Dushanbe::GetLastTransactions] Searching: amount=" << m_searchAmount
|
||||
<< "time=" << m_searchTime.toString(Qt::ISODate);
|
||||
|
||||
const QTimeZone tjTz("Asia/Dushanbe"); // UTC+5
|
||||
// Время в банковском приложении показывается в таймзоне устройства
|
||||
const QString tzName = AdbUtils::getDeviceTimezone(m_deviceId);
|
||||
QTimeZone tjTz(tzName.toUtf8());
|
||||
if (!tjTz.isValid()) tjTz = QTimeZone("Asia/Dushanbe");
|
||||
const int maxScrolls = 10;
|
||||
|
||||
for (int scroll = 0; scroll <= maxScrolls; ++scroll) {
|
||||
|
||||
@ -313,6 +313,28 @@ void EventHandler::updateEventThread(const QString &key, const EventInfo &event,
|
||||
}
|
||||
} else if (event.type == EventType::FetchTransactions) {
|
||||
QList<TransactionInfo> txList = TransactionDAO::getTransactionsWithinHours(event.accountId, 24);
|
||||
// Оставляем только совпадения по сумме
|
||||
txList.erase(std::remove_if(txList.begin(), txList.end(),
|
||||
[&](const TransactionInfo &tx) {
|
||||
return qAbs(tx.amount - event.amount) > 0.01;
|
||||
}), txList.end());
|
||||
// Если больше одной — берём ближайшую по времени к запросу сервера
|
||||
if (txList.size() > 1) {
|
||||
const QJsonObject taskJson = QJsonDocument::fromJson(event.json.toUtf8()).object();
|
||||
const QDateTime target = QDateTime::fromString(
|
||||
taskJson["body"].toObject()["created_at"].toString(), Qt::ISODate);
|
||||
if (target.isValid()) {
|
||||
auto best = std::min_element(txList.begin(), txList.end(),
|
||||
[&](const TransactionInfo &a, const TransactionInfo &b) {
|
||||
const QDateTime ta = a.completeTime.isValid() ? a.completeTime : a.timestamp;
|
||||
const QDateTime tb = b.completeTime.isValid() ? b.completeTime : b.timestamp;
|
||||
return qAbs(ta.toUTC().secsTo(target)) < qAbs(tb.toUTC().secsTo(target));
|
||||
});
|
||||
const TransactionInfo chosen = *best;
|
||||
txList.clear();
|
||||
txList.append(chosen);
|
||||
}
|
||||
}
|
||||
// Фильтруем: отправляем только транзакции с bank_transaction_id
|
||||
bool hasWithoutId = false;
|
||||
QJsonArray arr;
|
||||
@ -331,8 +353,16 @@ void EventHandler::updateEventThread(const QString &key, const EventInfo &event,
|
||||
QJsonObject extraObj;
|
||||
extraObj["fee"] = static_cast<int>(tx.fee * 100);
|
||||
txObj["extra"] = extraObj;
|
||||
const QTimeZone bankTz(event.bankName == "dushanbe_city_bank"
|
||||
? "Asia/Dushanbe" : "Europe/Moscow");
|
||||
// Банковские приложения показывают время в таймзоне устройства
|
||||
const DeviceInfo bankDevice = DeviceDAO::getDeviceById(event.deviceId);
|
||||
const QString bankAdbSerial = bankDevice.adbSerial.isEmpty()
|
||||
? event.deviceId : bankDevice.adbSerial;
|
||||
const QString bankTzName = AdbUtils::getDeviceTimezone(bankAdbSerial);
|
||||
QTimeZone bankTz(bankTzName.toUtf8());
|
||||
if (!bankTz.isValid()) {
|
||||
bankTz = QTimeZone(event.bankName == "dushanbe_city_bank"
|
||||
? "Asia/Dushanbe" : "Europe/Moscow");
|
||||
}
|
||||
// Приоритет: bankTime (время операции) > timestamp (время сохранения)
|
||||
// Сервер ожидает UTC ("Z")
|
||||
bool createdAtSet = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user