151 lines
6.6 KiB
C++
151 lines
6.6 KiB
C++
#include "LoginAndCheckAccountsBirbankScript.h"
|
||
|
||
#include <QThread>
|
||
|
||
#include "adb/AdbUtils.h"
|
||
#include "dao/AccountDAO.h"
|
||
#include "dao/ApplicationDAO.h"
|
||
#include "dao/DeviceDAO.h"
|
||
#include "dao/TransactionDAO.h"
|
||
#include "time/DateUtils.h"
|
||
|
||
LoginAndCheckAccountsBirbankScript::LoginAndCheckAccountsBirbankScript(
|
||
QString deviceId,
|
||
QString appCode,
|
||
QObject *parent
|
||
) : CommonBirbankScript(parent),
|
||
m_deviceId(std::move(deviceId)), m_appCode(std::move(appCode)) {
|
||
}
|
||
|
||
LoginAndCheckAccountsBirbankScript::~LoginAndCheckAccountsBirbankScript() = default;
|
||
|
||
|
||
void LoginAndCheckAccountsBirbankScript::doStart() {
|
||
const DeviceInfo device = DeviceDAO::getDeviceById(m_deviceId);
|
||
const ApplicationInfo app = ApplicationDAO::getApplication(m_deviceId, m_appCode);
|
||
|
||
|
||
if (false) {
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node cardText = xmlScreenParser.findTextNode("2480");
|
||
if (!cardText.isEmpty()) {
|
||
AdbUtils::makeTap(device.id, cardText.x(), cardText.y());
|
||
QThread::msleep(2000);
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
Node cardTitleText = xmlScreenParser.findTextNode("2480");
|
||
Node cardHistory = xmlScreenParser.findTextNode("История платежей");
|
||
if (!cardTitleText.isEmpty() && !cardHistory.isEmpty()) {
|
||
QList<TransactionInfo> transactions = xmlScreenParser.parsePositiveTransactions();
|
||
|
||
QList<TransactionInfo> savedTransactions = TransactionDAO::getTransactions(89);
|
||
for (TransactionInfo &transaction: transactions) {
|
||
bool isSaved = false;
|
||
for (TransactionInfo &savedTransaction: savedTransactions) {
|
||
if (savedTransaction.amount == transaction.amount
|
||
&& savedTransaction.bankTime == transaction.bankTime) {
|
||
isSaved = true;
|
||
break;
|
||
}
|
||
}
|
||
if (!isSaved) {
|
||
TransactionInfo tr;
|
||
tr.accountId = 89;
|
||
tr.description = transaction.description;
|
||
tr.bankTime = transaction.bankTime;
|
||
tr.bankName = transaction.bankName;
|
||
tr.amount = transaction.amount;
|
||
tr.phone = transaction.phone;
|
||
tr.updateTime = DateUtils::getUtcNow();
|
||
tr.fee = transaction.fee;
|
||
tr.name = transaction.name;
|
||
tr.bankTrExternalId = transaction.bankTrExternalId;
|
||
tr.status = TransactionStatus::Complete;
|
||
tr.type = TransactionType::Card;
|
||
tr.completeTime = transaction.completeTime;
|
||
tr.id = TransactionDAO::insertTransaction(tr);
|
||
|
||
if (tr.id == -1) {
|
||
qDebug() << "--- saveAndPostNewTransactionData failed";
|
||
}
|
||
AccountInfo account = AccountDAO::getAccountById(89);
|
||
postNewTransactionData(account, tr);
|
||
|
||
// if (!saveAndPostNewTransactionData(m_account, transaction, TransactionStatus::Complete)) {
|
||
// qDebug() << "--- saveAndPostNewTransactionData failed";
|
||
// }
|
||
}
|
||
}
|
||
} else {
|
||
m_error = "Card page not found: " + m_deviceId + " " + m_appCode;
|
||
qWarning() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
} else {
|
||
m_error = "Card not found: " + m_deviceId + " " + m_appCode;
|
||
qWarning() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
} else {
|
||
// "Maraqlı deyil" - не интересно
|
||
if (device.id.isEmpty() || app.id == -1) {
|
||
m_error = "Device or app not found: " + m_deviceId + " " + m_appCode;
|
||
qCritical() << m_error;
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
|
||
if (!runAppAndGoToHomeScreen(device.id, app.package, app.pinCode, device.screenWidth, device.screenHeight)) {
|
||
m_error = "Cant open the home screen: " + m_deviceId + " " + m_appCode;
|
||
qWarning() << m_error;
|
||
if (!ApplicationDAO::updatePinCodeStatus(app.id, "no", "Не прошла проверка [дата]")) {
|
||
qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode;
|
||
}
|
||
|
||
AdbUtils::tryToKillApplication(m_deviceId, app.package);
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
} else {
|
||
if (!ApplicationDAO::updatePinCodeStatus(app.id, "yes", "")) {
|
||
qWarning() << "Cant update the pincode: " << m_deviceId << " " << m_appCode;
|
||
}
|
||
|
||
QThread::msleep(2000);
|
||
xmlScreenParser.parseAndSaveXml(AdbUtils::getScreenDumpAsXml(m_deviceId, ++m_counter));
|
||
QList<AccountInfo> oldAccounts = AccountDAO::getAccounts(m_deviceId, m_appCode);
|
||
QMap<QString, AccountInfo> accountMap;
|
||
for (AccountInfo &oldAccount: oldAccounts) {
|
||
if (oldAccount.status == AccountStatus::Active) {
|
||
accountMap.insert(oldAccount.lastNumbers, oldAccount);
|
||
}
|
||
}
|
||
|
||
QList<AccountInfo> accounts = xmlScreenParser.parseAccountsInfo();
|
||
for (auto account: accounts) {
|
||
if (accountMap.contains(account.lastNumbers)) {
|
||
account.deviceId = m_deviceId;
|
||
account.appCode = m_appCode;
|
||
account.currency = accountMap[account.lastNumbers].currency;
|
||
account.description = accountMap[account.lastNumbers].description;
|
||
account.status = AccountStatus::Active;
|
||
if (!AccountDAO::upsertAccount(account)) {
|
||
m_error = "Not updated: " + account.lastNumbers;
|
||
qCritical() << m_error;
|
||
}
|
||
}
|
||
}
|
||
|
||
QList<AccountInfo> savedAccounts = AccountDAO::getAccounts(m_deviceId, m_appCode);
|
||
postAccountsData(savedAccounts);
|
||
}
|
||
|
||
AdbUtils::tryToKillApplication(m_deviceId, app.package);
|
||
}
|
||
emit finishedWithResult(m_error);
|
||
}
|