Add timeout handling and process kill logic for ADB operations. Refine date and time validation in transaction fetching. Adjust EventHandler to handle "ozon" bank accounts separately. Use blocking queued connection for stopping EventHandler.
This commit is contained in:
parent
0c1d2675b3
commit
14ca8348c3
@ -358,12 +358,25 @@ void GetLastTransactionsScript::searchTransaction(const DeviceInfo &device, int
|
||||
if (!txTime.isValid()) txTime = QDateTime::fromString(dtStr, "dd.MM.yyyy,HH:mm");
|
||||
if (txTime.isValid()) txTime.setTimeZone(msk);
|
||||
|
||||
// Проверяем что дата совпадает (тот же день)
|
||||
if (txTime.isValid() && txTime.date() != searchDate) {
|
||||
qDebug() << "[FetchTransactions] Wrong date:" << dtStr << "expected" << searchDate;
|
||||
AdbUtils::goBack(m_deviceId);
|
||||
QThread::msleep(1000);
|
||||
continue;
|
||||
// Проверяем что дата и время совпадают (±1 час от m_searchTime)
|
||||
if (txTime.isValid()) {
|
||||
if (txTime.date() != searchDate) {
|
||||
qDebug() << "[FetchTransactions] Wrong date:" << dtStr << "expected" << searchDate;
|
||||
AdbUtils::goBack(m_deviceId);
|
||||
QThread::msleep(1000);
|
||||
continue;
|
||||
}
|
||||
if (m_searchTime.isValid()) {
|
||||
const qint64 diffSecs = qAbs(txTime.toUTC().secsTo(m_searchTime.toUTC()));
|
||||
if (diffSecs > 3600) {
|
||||
qDebug() << "[FetchTransactions] Time mismatch:" << dtStr
|
||||
<< "expected" << searchMsk.toString("dd.MM.yyyy, HH:mm")
|
||||
<< "diff=" << diffSecs << "sec";
|
||||
AdbUtils::goBack(m_deviceId);
|
||||
QThread::msleep(1000);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Нашли!
|
||||
|
||||
2
main.cpp
2
main.cpp
@ -103,7 +103,7 @@ void startEventHandler(const QCoreApplication &app) {
|
||||
QObject::connect(eventHandler, &EventHandler::finished, eventHandler, &QObject::deleteLater);
|
||||
QObject::connect(thread, &QThread::finished, thread, &QThread::deleteLater);
|
||||
QObject::connect(&app, &QCoreApplication::aboutToQuit, [=]() {
|
||||
eventHandler->stop();
|
||||
QMetaObject::invokeMethod(eventHandler, "stop", Qt::BlockingQueuedConnection);
|
||||
});
|
||||
thread->start();
|
||||
}
|
||||
|
||||
@ -455,6 +455,8 @@ QByteArray DeviceScreener::takeScreenshot(const QString &deviceId) {
|
||||
|
||||
if (!process.waitForFinished(5000)) {
|
||||
qWarning() << "ADB скриншот не завершился для" << deviceId;
|
||||
process.kill();
|
||||
process.waitForFinished(1000);
|
||||
return {};
|
||||
}
|
||||
|
||||
@ -477,7 +479,12 @@ QList<QPair<QString, QString> > DeviceScreener::readAdbDevices() {
|
||||
qWarning() << "[DeviceScreener] Failed to start adb devices:" << process.errorString();
|
||||
return {};
|
||||
}
|
||||
process.waitForFinished(10000);
|
||||
if (!process.waitForFinished(10000)) {
|
||||
qWarning() << "[DeviceScreener] adb devices timeout";
|
||||
process.kill();
|
||||
process.waitForFinished(1000);
|
||||
return {};
|
||||
}
|
||||
|
||||
const QString output = process.readAllStandardOutput();
|
||||
QList<QPair<QString, QString> > devices;
|
||||
|
||||
@ -281,26 +281,35 @@ void EventHandler::updateEventThread(const QString &key, const EventInfo &event,
|
||||
|
||||
QJsonValue taskData;
|
||||
if (event.type == EventType::FetchProfile) {
|
||||
// Отправляем суммы всех материалов устройства для этого банка
|
||||
const QList<MaterialInfo> allAccounts = MaterialDAO::getAccounts(event.deviceId, event.bankName);
|
||||
if (!allAccounts.isEmpty()) {
|
||||
QJsonArray accountsArr;
|
||||
for (const auto &acc : allAccounts) {
|
||||
const int accCurrency = currencyCodes.value(acc.currency.toUpper(), 643);
|
||||
QJsonObject accObj;
|
||||
accObj["bank_account_id"] = acc.materialId;
|
||||
accObj["amount"] = static_cast<int>(acc.amount * 100);
|
||||
accObj["currency"] = accCurrency;
|
||||
accountsArr.append(accObj);
|
||||
}
|
||||
taskData = accountsArr;
|
||||
} else {
|
||||
if (event.bankName == "ozon") {
|
||||
EventDAO::updateEventAmount(event.id, account.amount);
|
||||
QJsonObject obj;
|
||||
obj["bank_account_id"] = account.materialId;
|
||||
obj["amount"] = static_cast<int>(account.amount * 100);
|
||||
obj["currency"] = currencyCode;
|
||||
taskData = obj;
|
||||
} else {
|
||||
// Отправляем суммы всех материалов устройства для этого банка
|
||||
const QList<MaterialInfo> allAccounts = MaterialDAO::getAccounts(event.deviceId, event.bankName);
|
||||
if (!allAccounts.isEmpty()) {
|
||||
QJsonArray accountsArr;
|
||||
for (const auto &acc : allAccounts) {
|
||||
const int accCurrency = currencyCodes.value(acc.currency.toUpper(), 643);
|
||||
QJsonObject accObj;
|
||||
accObj["bank_account_id"] = acc.materialId;
|
||||
accObj["amount"] = static_cast<int>(acc.amount * 100);
|
||||
accObj["currency"] = accCurrency;
|
||||
accountsArr.append(accObj);
|
||||
}
|
||||
taskData = accountsArr;
|
||||
} else {
|
||||
EventDAO::updateEventAmount(event.id, account.amount);
|
||||
QJsonObject obj;
|
||||
obj["bank_account_id"] = account.materialId;
|
||||
obj["amount"] = static_cast<int>(account.amount * 100);
|
||||
obj["currency"] = currencyCode;
|
||||
taskData = obj;
|
||||
}
|
||||
}
|
||||
} else if (event.type == EventType::FetchTransactions) {
|
||||
QList<TransactionInfo> txList = TransactionDAO::getTransactionsWithinHours(event.accountId, 24);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user