Commit f70e4984 by NitefullWind

1. 从配置文件读取OLTP的dll所在路径,并copy到程序所在目录。 2. 修复支付、退款返回的打印信息错误Bug。

parent 5a7ad5ee
#include "fmp_settings.h"
#include "global.h"
#include "DataProcess/tools.h"
#include <QSettings>
#include <QDebug>
/**
* @brief The FMPSettings class
*/
FMPSettings::FMPSettings(QObject *parent)
: QObject(parent),
d_ptr(new FMPSettingsPrivate(parent))
{
}
FMPSettings::~FMPSettings()
{
if (d_ptr) {
delete d_ptr;
d_ptr = nullptr;
}
}
QVariant FMPSettings::GetValue(const QString &k, QVariant default_val)
{
Q_D(FMPSettings);
return d->GetValue(k, default_val);
}
bool FMPSettings::SetValue(const QString &k, QVariant v)
{
Q_D(FMPSettings);
return d->SetValue(k, v);
}
/**
***************************************************************
*/
FMPSettingsPrivate::FMPSettingsPrivate(QObject *parent)
: QObject(parent)
{
char path[MAX_PATH] = {0};
ToolS::GetProcPath(path);
_sets = new QSettings(QString::fromLocal8Bit("%1/%2").arg(path).arg(USERCONFIG_NAME), QSettings::IniFormat);
}
QVariant FMPSettingsPrivate::GetValue(const QString &k, QVariant default_val)
{
return _sets->value(k, default_val);
}
bool FMPSettingsPrivate::SetValue(const QString &k, QVariant v)
{
_sets->setValue(k, v);
return (_sets->value(k) == v);
}
#ifndef FMP_SETTINGS_H
#define FMP_SETTINGS_H
#include <QObject>
class FMPSettingsPrivate;
/**
* @brief The FMPSettings class
*/
class FMPSettings : public QObject
{
Q_OBJECT
Q_DECLARE_PRIVATE(FMPSettings)
public:
explicit FMPSettings(QObject *parent = nullptr);
virtual ~FMPSettings();
public:
QVariant GetValue(const QString &k, QVariant default_val);
bool SetValue(const QString&k, QVariant v);
private:
FMPSettingsPrivate *d_ptr;
};
class QSettings;
/**
* @brief The FMPSettingsPrivate class
*/
class FMPSettingsPrivate:public QObject
{
Q_OBJECT
Q_DECLARE_PUBLIC(FMPSettings)
public:
explicit FMPSettingsPrivate(QObject *parent = nullptr);
QVariant GetValue(const QString &k, QVariant default_val);
bool SetValue(const QString&k, QVariant v);
public:
FMPSettings *q_ptr;
QSettings *_sets;
};
#endif // FMP_SETTINGS_H
......@@ -11,7 +11,7 @@
#define PRINT_FILE_NAME "print.txt"
//#define USERCONFIG_NAME "config.ini"
#define USERCONFIG_NAME "config.ini"
#define ENCODE_FIRST "encode/first"
#define ENCODE_END "encode/end"
......
......@@ -227,6 +227,7 @@ void HostWidget::ShowWiteJson(bool flag, QJsonObject object, QString error)
ui->btn_find_check->show();
_label_find_timer->stop();
_need_exit = true;
QLOG_INFO() << object;
......@@ -281,35 +282,35 @@ void HostWidget::ShowWiteJson(bool flag, QJsonObject object, QString error)
QWidget *pWdg = new QWidget(ui->tableWidget);
QHBoxLayout *hLayout = new QHBoxLayout(pWdg);
QPushButton * pBtn = new QPushButton(pWdg);
pBtn->setFixedSize(70, 30);
pBtn->setFocusPolicy(Qt::NoFocus);
pBtn->setProperty("orderId", tmp[JSON_KEY_FMID].toString());
pBtn->setText(QString::fromLocal8Bit("打印"));
hLayout->addWidget(pBtn);
hLayout->setMargin(0);
pWdg->setLayout(hLayout);
ui->tableWidget->setCellWidget(0, 4, pWdg); // 操作按钮
pBtn->setStyleSheet("border:0px;border-radius:2px;background-color: rgb(0, 179, 238);font: 75 20px \"Microsoft YaHei UI Light\";");
qDebug() << "********************-----------*******************" << tmp;
if(tmp[JSON_KEYT_STATE].toString().toInt() != 1)
{
pBtn->setEnabled(false);
pBtn->setStyleSheet("border:0px;border-radius:2px;background-color: rgb(208, 208, 208);font: 75 20px \"Microsoft YaHei UI Light\";");
}
connect(pBtn, &QPushButton::clicked, this, [this, pBtn]()
{
QStringList list;
list.append(pBtn->property("orderId").toString());
on_btn_printagain_clicked();
emit RequestWithType(againprint, list);
});
// QWidget *pWdg = new QWidget(ui->tableWidget);
// QHBoxLayout *hLayout = new QHBoxLayout(pWdg);
// QPushButton * pBtn = new QPushButton(pWdg);
// pBtn->setFixedSize(70, 30);
// pBtn->setFocusPolicy(Qt::NoFocus);
// pBtn->setProperty("orderId", tmp[JSON_KEY_FMID].toString());
// pBtn->setText(QString::fromLocal8Bit("打印"));
// hLayout->addWidget(pBtn);
// hLayout->setMargin(0);
// pWdg->setLayout(hLayout);
// ui->tableWidget->setCellWidget(0, 4, pWdg); // 操作按钮
// pBtn->setStyleSheet("border:0px;border-radius:2px;background-color: rgb(0, 179, 238);font: 75 20px \"Microsoft YaHei UI Light\";");
// qDebug() << "********************-----------*******************" << tmp;
// if(tmp[JSON_KEYT_STATE].toString().toInt() != 1)
// {
// pBtn->setEnabled(false);
// pBtn->setStyleSheet("border:0px;border-radius:2px;background-color: rgb(208, 208, 208);font: 75 20px \"Microsoft YaHei UI Light\";");
// }
// connect(pBtn, &QPushButton::clicked, this, [this, pBtn]()
// {
// QStringList list;
// list.append(pBtn->property("orderId").toString());
// on_btn_printagain_clicked();
// emit RequestWithType(againprint, list);
// });
}
ui->tableWidget->sortByColumn(2, Qt::DescendingOrder);
......
......@@ -6,6 +6,7 @@
#include <qwinwidget.h>
#include <QMessageBox>
#include <QDateTime>
#include <windows.h>
#include "control.h"
#include "global.h"
......@@ -13,12 +14,52 @@
#include "requestmodel.h"
#include "fmtool.h"
#include "rspfactory.h"
#include "fmp_settings.h"
#include <QDir>
EXTERN_C IMAGE_DOS_HEADER __ImageBase;
static bool CopyApiDll(QString &errorString)
{
// char path[MAX_PATH] = {0};
// ToolS::GetProcPath(path);
QString localDllPath = QString::fromLocal8Bit("%1/StarbucksAPI.dll").arg(qApp->applicationDirPath());
QFileInfo localFileInfo(localDllPath);
FMPSettings setting;
QString configDllPath = setting.GetValue("STARBUCKSAPIURL", ".").toString();
QFileInfo configFileInfo(configDllPath);
if(!configFileInfo.isFile()) {
configFileInfo = QFileInfo(configDllPath+"/StarbucksAPI.dll");
}
if(!configFileInfo.exists()) {
errorString = "Config dll path: " + configDllPath + " does not exist.";
QLOG_ERROR() << errorString;
return false;
}
if(!localFileInfo.exists() || localFileInfo.lastModified() < configFileInfo.lastModified()) {
QFile localDllFile(localFileInfo.absoluteFilePath());
if(localDllFile.exists()) {
localDllFile.remove();
}
QFile configDllFile(configFileInfo.absoluteFilePath());
if(!configDllFile.copy(localDllPath)) {
errorString = "Can't copy StarbucksAPI.dll: " + configDllFile.errorString();
QLOG_ERROR() << errorString;
return false;
}
}
return true;
}
BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/ )
{
static bool ownApplication = FALSE;
......@@ -64,6 +105,12 @@ extern "C" __declspec(dllexport) void Start(const char *indata, char *outdata)
QsLogging::DestinationPtr consleDest(QsLogging::DestinationFactory::MakeDebugOutputDestination());
logger.addDestination(consleDest);
QString errorString;
if(!CopyApiDll(errorString)) {
errorString = QString::fromLocal8Bit("{\"statusCode\":23, \"message\":\"%1\"}").arg(errorString);
strcpy(outdata, errorString.toLocal8Bit());
return;
}
static RollBack rollback;
Control control(&win);
......@@ -365,7 +412,7 @@ int main(int argc, char *argv[])
//char as[] = "ak10dh171300000000000 *#dhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh";
char b[MAX_BUF_LEN] = {0};
control.Start(as, b);
// control.Start(as, b);
char spccIn[MAX_BUF_LEN] = "{\"fmId\":\"0123456789012345678\",\"reqType\":351,\"storeId\":\"1713\",\"stationId\":\"1\",\"partnerId\":1443,\"operatorId\":\"sssaw\",\"transId\":\"52342342323806\",\"transAmount\":8000,\"partnerOrderId\":\"909911039993720192019\",\"businessDate\":\"20170508\",\"products\":[{\"pid\":\"123\",\"name\":\"中杯拿铁\",\"price\":321,\"salesType\":\"NORMAL\"}]}";
control.Start(spccIn, b);
......
......@@ -145,7 +145,7 @@ private:
{
response[JSON_KEY_STATUSCODE] = FMTool::GetJsonValue(json, JSON_KEY_STATUSCODE).toInt();
response[JSON_KEY_MESSAGE] = FMTool::GetJsonValue(json, JSON_KEY_MESSAGE).toString();
response[JSON_KEY_EXT] = FMTool::GetJsonValue(json, JSON_KEY_EXT).toString();
response[JSON_KEY_EXT] = FMTool::GetJsonValue(json, JSON_KEY_EXT).toObject();
response[JSON_KEY_FMID] = FMTool::GetJsonValue(json, JSON_KEY_FMID).toString();
response[JSON_KEY_PAYACCOUNT] = FMTool::GetJsonValue(json, JSON_KEY_PAYACCOUNT).toString();
response[JSON_KEY_PAYTRANSID] = FMTool::GetJsonValue(json, JSON_KEY_PAYTRANSID).toString();
......@@ -195,7 +195,7 @@ private:
{
response[JSON_KEY_STATUSCODE] = FMTool::GetJsonValue(json, JSON_KEY_STATUSCODE).toInt();
response[JSON_KEY_MESSAGE] = FMTool::GetJsonValue(json, JSON_KEY_MESSAGE).toString();
response[JSON_KEY_EXT] = FMTool::GetJsonValue(json, JSON_KEY_EXT).toString();
response[JSON_KEY_EXT] = FMTool::GetJsonValue(json, JSON_KEY_EXT).toObject();
response[JSON_KEY_FMID] = FMTool::GetJsonValue(json, JSON_KEY_FMID).toString();
return true;
}
......
......@@ -16,9 +16,9 @@ include("./DataProcess/DataProcess.pri")
LIBS += -L"C:/openssl2/openssl-1.0.2l/out32dll" -llibeay32
LIBS += -L"C:/openssl2/openssl-1.0.2l/out32dll" -lssleay32
CONFIG += C++11 SBKDLL
CONFIG += C++11 SBKDLL1
#DEFINES += MOCK
DEFINES += MOCK
include($$PWD/qtwinmigrate/src/qtwinmigrate.pri)
......@@ -40,7 +40,8 @@ release {
SOURCES += main.cpp\
hostwidget.cpp \
control.cpp \
labelstimer.cpp
labelstimer.cpp \
fmp_settings.cpp
HEADERS += hostwidget.h \
fmp_window.h \
......@@ -53,7 +54,8 @@ HEADERS += hostwidget.h \
jsonfactory.h \
labelstimer.h \
rspfactory.h \
reqfactory.h
reqfactory.h \
fmp_settings.h
FORMS += hostwidget.ui
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment