92 lines
3.3 KiB
C++
92 lines
3.3 KiB
C++
#include "LoginAndCheckAccountsScript.h"
|
||
|
||
#include <QThread>
|
||
|
||
#include "adb/AdbUtils.h"
|
||
#include "dao/MaterialDAO.h"
|
||
#include "dao/BankProfileDAO.h"
|
||
#include "dao/DeviceDAO.h"
|
||
#include "AppLogger.h"
|
||
#include "GetCardInfoScript.h"
|
||
|
||
namespace Ozon {
|
||
|
||
LoginAndCheckAccountsScript::LoginAndCheckAccountsScript(
|
||
QString deviceId,
|
||
QString appCode,
|
||
QObject *parent,
|
||
bool fetchProfileOnly,
|
||
bool pinCheckOnly
|
||
) : CommonScript(parent),
|
||
m_deviceId(std::move(deviceId)),
|
||
m_appCode(std::move(appCode)),
|
||
m_fetchProfileOnly(fetchProfileOnly),
|
||
m_pinCheckOnly(pinCheckOnly) {
|
||
}
|
||
|
||
LoginAndCheckAccountsScript::~LoginAndCheckAccountsScript() = default;
|
||
|
||
|
||
void LoginAndCheckAccountsScript::doStart() {
|
||
// m_deviceId = ADB serial, device.id = android_id (для БД)
|
||
DeviceInfo device = DeviceDAO::getDeviceById(m_deviceId); if (device.id.isEmpty()) device = DeviceDAO::findByAdbSerial(m_deviceId); if (!device.adbSerial.isEmpty()) m_deviceId = device.adbSerial;
|
||
const BankProfileInfo app = BankProfileDAO::getApplication(device.id, m_appCode);
|
||
|
||
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(m_deviceId, app.package, app.pinCode, device.screenWidth, device.screenHeight)) {
|
||
m_error = "Cant open the home screen: " + m_deviceId + " " + m_appCode;
|
||
qWarning() << m_error;
|
||
AppLogger::log("ozon/LoginAndCheck", m_deviceId, m_error,
|
||
AdbUtils::captureScreenshotBytes(m_deviceId), "FETCH_PROFILE");
|
||
BankProfileDAO::updateComment(app.id,
|
||
"Не прошла проверка " + QDateTime::currentDateTime().toString("dd.MM.yyyy HH:mm:ss"));
|
||
|
||
AdbUtils::tryToKillApplication(m_deviceId, app.package);
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
} else {
|
||
if (m_pinCheckOnly) {
|
||
emit finishedWithResult(m_error);
|
||
return;
|
||
}
|
||
|
||
// Создаём bank profile если ещё не создан
|
||
createBankProfileIfNeeded(device.id, m_appCode);
|
||
|
||
if (goToAllProducts(m_deviceId, device.screenWidth, device.screenHeight)) {
|
||
QList<QPair<MaterialInfo, Node> > accounts = xmlScreenParser.parseAccountsInfo();
|
||
for (auto &[account, node]: accounts) {
|
||
account.deviceId = device.id;
|
||
account.appCode = m_appCode;
|
||
if (!MaterialDAO::upsertAccount(account)) {
|
||
m_error = "Not updated: " + account.lastNumbers;
|
||
qCritical() << m_error;
|
||
}
|
||
}
|
||
|
||
if (!m_fetchProfileOnly) {
|
||
postAccountsData(accounts);
|
||
}
|
||
} else {
|
||
qWarning() << "Cant go to all products: " << m_deviceId << " " << m_appCode;
|
||
}
|
||
|
||
if (!m_fetchProfileOnly) {
|
||
// Запускаем сканирование баланса, данных карт и отправку на сервер (синхронно)
|
||
GetCardInfoScript cardScript(m_deviceId, m_appCode, "");
|
||
cardScript.start();
|
||
}
|
||
}
|
||
|
||
emit finishedWithResult(m_error);
|
||
}
|
||
|
||
} // namespace Ozon
|