fix: 正常请求ruoyi系统数据;解析动量数据

master
Laixingyu 3 years ago
parent 193c196a8e
commit 1edf66f10e

@ -22,3 +22,8 @@ UserInfo BaseDataManager::Login(const QString &userName, const QString &password
{ {
return UserInfo(); return UserInfo();
} }
void BaseDataManager::GetTrends(QDate date,const QString& token)
{
}

@ -4,6 +4,7 @@
#include <QObject> #include <QObject>
#include <QPixmap> #include <QPixmap>
#include "structs.h" #include "structs.h"
#include <QDate>
class BaseDataManager : public QObject class BaseDataManager : public QObject
{ {
@ -14,6 +15,7 @@ public:
virtual QPixmap GetVerificationCode(); virtual QPixmap GetVerificationCode();
virtual UserInfo Login(const QString& userName,const QString& password,const QString& code); virtual UserInfo Login(const QString& userName,const QString& password,const QString& code);
virtual void GetTrends(QDate date,const QString& token);
signals: signals:
//请求结束 ret 返回值 0成功 非0失败 //请求结束 ret 返回值 0成功 非0失败

@ -20,6 +20,8 @@ int main(int argc, char *argv[])
if(login.exec() == QDialog::Accepted) if(login.exec() == QDialog::Accepted)
{ {
MainWindow w; MainWindow w;
w.SetUserInfo(login.GetUserInfo());
w.LoadTrendsData();
w.show(); w.show();
return app.exec(); return app.exec();
} }

@ -12,6 +12,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->setupUi(this); ui->setupUi(this);
this->setWindowTitle("mojin"); this->setWindowTitle("mojin");
InitTradeTable(); InitTradeTable();
m_UserData.SetManagerType(ManagerType::Ruoyi);
} }
MainWindow::~MainWindow() MainWindow::~MainWindow()
@ -24,6 +25,11 @@ void MainWindow::SetUserInfo(UserInfo user)
m_UserInfo = user; m_UserInfo = user;
} }
void MainWindow::LoadTrendsData()
{
m_UserData.GetTrends(QDate(),m_UserInfo.token);
}
void MainWindow::InitTradeTable() void MainWindow::InitTradeTable()
{ {
// m_pTradesModel = new TradeTableModel(ui->tradeTableView); // m_pTradesModel = new TradeTableModel(ui->tradeTableView);
@ -54,14 +60,14 @@ void MainWindow::on_addTrade_pushButton_clicked()
AddTradeDialog ad; AddTradeDialog ad;
ad.setWindowTitle("添加记录"); ad.setWindowTitle("添加记录");
ad.exec(); ad.exec();
for (int row = 0; row < 4; ++row) // for (int row = 0; row < 4; ++row)
{ // {
m_pTradeStandardModel->insertRow(row); // m_pTradeStandardModel->insertRow(row);
for (int column = 0; column < 3; ++column) { // for (int column = 0; column < 3; ++column) {
QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column)); // QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
m_pTradeStandardModel->setItem(row, column, item); // m_pTradeStandardModel->setItem(row, column, item);
} // }
} // }
} }

@ -3,6 +3,7 @@
#include <QMainWindow> #include <QMainWindow>
#include "structs.h" #include "structs.h"
#include "userdata.h"
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; } namespace Ui { class MainWindow; }
@ -18,6 +19,9 @@ public:
MainWindow(QWidget *parent = nullptr); MainWindow(QWidget *parent = nullptr);
~MainWindow(); ~MainWindow();
void SetUserInfo(UserInfo user); void SetUserInfo(UserInfo user);
//临时使用,后续需要重新创建
void SetUserData();
void LoadTrendsData();
private: private:
void InitTradeTable(); void InitTradeTable();
@ -28,6 +32,7 @@ private slots:
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;
UserInfo m_UserInfo; UserInfo m_UserInfo;
UserData m_UserData;
// TradeTableModel* m_pTradesModel; // TradeTableModel* m_pTradesModel;
QStandardItemModel* m_pTradeStandardModel; QStandardItemModel* m_pTradeStandardModel;
}; };

@ -6,6 +6,7 @@
#include <QJsonDocument> #include <QJsonDocument>
#include <QJsonParseError> #include <QJsonParseError>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonArray>
#include <QEventLoop> #include <QEventLoop>
#include <QTimer> #include <QTimer>
@ -72,6 +73,35 @@ UserInfo RuoyiDataManager::Login(const QString &userName, const QString &passwor
return m_userInfo; return m_userInfo;
} }
void RuoyiDataManager::GetTrends(QDate date,const QString& token)
{
QNetworkRequest request;
QString urlStr(m_sUrl + "/prod-api/stocksystem/trends/listSection");
QUrl url = QUrl(urlStr);
QUrlQuery query;
query.addQueryItem("Token", token.toUtf8());
query.addQueryItem("pageNum", "1");
query.addQueryItem("pageSize", "10");
query.addQueryItem("tradeDay", "2023-12-07");
query.addQueryItem("type", "20");
url.setQuery(query);
request.setUrl(url);
request.setHeader(QNetworkRequest::ContentTypeHeader,"application/json;charset=UTF-8");
request.setRawHeader("Authorization",QString("Bearer %1").arg(token).toLocal8Bit());
qDebug() << __FUNCTION__ << " rawHeader: " << QString("Bearer %1").arg(token).toLocal8Bit();
QNetworkReply *reply = m_pNetworkManager->get(request);
reply->setProperty("msgType",QVariant(int(GETTRENDS)));
connect(reply,&QNetworkReply::finished,this,&RuoyiDataManager::RequestFinished);
QEventLoop loop;
connect(this, SIGNAL(ParseReplyFinished()), &loop, SLOT(quit()));
loop.exec();
}
void RuoyiDataManager::RequestFinished() void RuoyiDataManager::RequestFinished()
{ {
QNetworkReply *reply = dynamic_cast< QNetworkReply* >(sender()); QNetworkReply *reply = dynamic_cast< QNetworkReply* >(sender());
@ -84,6 +114,10 @@ void RuoyiDataManager::RequestFinished()
{ {
ParseLogin(reply); ParseLogin(reply);
} }
else if(type == GETTRENDS)
{
ParseTrends(reply);
}
emit ParseReplyFinished(); emit ParseReplyFinished();
} }
@ -160,3 +194,73 @@ void RuoyiDataManager::ParseLogin(QNetworkReply *reply)
} }
} }
void RuoyiDataManager::ParseTrends(QNetworkReply *reply)
{
QByteArray readAllArray;
QVariant statusCode = reply->attribute(QNetworkRequest::HttpStatusCodeAttribute);
if(statusCode.isValid())
{
qDebug() << "status code=" << statusCode.toInt();
}
QNetworkReply::NetworkError err = reply->error();
if(err != QNetworkReply::NoError)
{
qDebug() << "Failed: " << reply->errorString();
}
else
{
readAllArray = reply->readAll();
qDebug() << __FUNCTION__ << readAllArray;
/**
* total:
* rows:[{title:2,sortDataList:["煤炭","营销服务"]},{title:2023-12-07,sortDataList:["1","2"]}]
* msg:""
*
* 0title
*/
QJsonParseError jsonError;
QJsonDocument document = QJsonDocument::fromJson(readAllArray,&jsonError);
if(jsonError.error == QJsonParseError::NoError && !document.isNull())
{
QList< QList<QString> > rowsList;
QList<QString> dates;
int rowCounts = 0;
QJsonObject root = document.object();
if(root.contains("total"))
{
qDebug() << __FUNCTION__ << root["total"];
rowCounts = root["total"].toInt();
}
if(root.contains("rows"))
{
QJsonArray rows = root["rows"].toArray();
for(int i = 0 ; i < rowCounts; i++)
{
QJsonObject obj = rows[i].toObject();
if(obj.contains("title"))
{
dates.append(obj["title"].toString());
}
if(obj.contains("sortDataList"))
{
QList<QString> datasList;
QJsonArray datas = obj["sortDataList"].toArray();
for(int c = 0 ; c < datas.count(); c++)
{
datasList.append(datas[c].toString());
}
rowsList.append(datasList);
}
}
rowsList.prepend(dates);
}
qDebug() << __FUNCTION__ << rowsList;
}
else
{
qDebug() << __FUNCTION__ << __LINE__ << jsonError.errorString();
}
}
}

@ -11,7 +11,8 @@ class RuoyiDataManager : public BaseDataManager
enum MsgType enum MsgType
{ {
GETVERIFICATIONCODE = 0, GETVERIFICATIONCODE = 0,
LOGIN LOGIN,
GETTRENDS,
}; };
public: public:
@ -20,6 +21,7 @@ public:
QPixmap GetVerificationCode() override; QPixmap GetVerificationCode() override;
UserInfo Login(const QString& userName,const QString& password,const QString& code) override; UserInfo Login(const QString& userName,const QString& password,const QString& code) override;
void GetTrends(QDate date,const QString& token) override;
public slots: public slots:
void RequestFinished(); void RequestFinished();
@ -29,6 +31,7 @@ signals:
private: private:
void ParseVerificationCode(QNetworkReply* reply); void ParseVerificationCode(QNetworkReply* reply);
void ParseLogin(QNetworkReply* reply); void ParseLogin(QNetworkReply* reply);
void ParseTrends(QNetworkReply* reply);
private: private:
QNetworkAccessManager* m_pNetworkManager; QNetworkAccessManager* m_pNetworkManager;

@ -107,6 +107,55 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>
<context>
<name>LoginDialog</name>
<message>
<location filename="widget/logindialog.ui" line="14"/>
<source>Dialog</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="29"/>
<source>Verification code</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="65"/>
<source>Password</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="72"/>
<source>UserName</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="85"/>
<source>admin</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="98"/>
<source>1qazse42W3</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="117"/>
<location filename="widget/logindialog.cpp" line="43"/>
<source>Login</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.ui" line="124"/>
<source>Cancel</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="widget/logindialog.cpp" line="43"/>
<source>Login Error.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context> <context>
<name>MainWindow</name> <name>MainWindow</name>
<message> <message>
@ -196,79 +245,79 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="36"/> <location filename="mainwindow.cpp" line="38"/>
<source>date</source> <source>date</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="36"/> <location filename="mainwindow.cpp" line="38"/>
<source>week</source> <source>week</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="36"/> <location filename="mainwindow.cpp" line="38"/>
<source>name</source> <source>name</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="36"/> <location filename="mainwindow.cpp" line="38"/>
<source>operate</source> <source>operate</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="36"/> <location filename="mainwindow.cpp" line="38"/>
<source>operateprice</source> <source>operateprice</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="36"/> <location filename="mainwindow.cpp" line="38"/>
<source>volume</source> <source>volume</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="37"/> <location filename="mainwindow.cpp" line="39"/>
<source>remainig</source> <source>remainig</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="37"/> <location filename="mainwindow.cpp" line="39"/>
<source>operatechange</source> <source>operatechange</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="37"/> <location filename="mainwindow.cpp" line="39"/>
<source>close</source> <source>close</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="37"/> <location filename="mainwindow.cpp" line="39"/>
<source>operateprofit</source> <source>operateprofit</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="37"/> <location filename="mainwindow.cpp" line="39"/>
<source>totalprofit</source> <source>totalprofit</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="38"/> <location filename="mainwindow.cpp" line="40"/>
<source>finalprofit</source> <source>finalprofit</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="mainwindow.cpp" line="38"/> <location filename="mainwindow.cpp" line="40"/>
<source>remark</source> <source>remark</source>
<translatorcomment></translatorcomment> <translatorcomment></translatorcomment>
<translation></translation> <translation></translation>

@ -42,3 +42,9 @@ UserInfo UserData::Login(const QString &userName, const QString &password, const
else else
return m_pDataManager->Login(userName,password,code); return m_pDataManager->Login(userName,password,code);
} }
void UserData::GetTrends(QDate date, const QString &token)
{
if(m_pDataManager != nullptr)
m_pDataManager->GetTrends(date,token);
}

@ -17,6 +17,8 @@ public:
QPixmap GetVerificationCode(); QPixmap GetVerificationCode();
//登录 获取用户信息,同步等待 //登录 获取用户信息,同步等待
UserInfo Login(const QString& userName,const QString& password,const QString& code); UserInfo Login(const QString& userName,const QString& password,const QString& code);
//获取trends
void GetTrends(QDate date,const QString& token);
private: private:
BaseDataManager* m_pDataManager; BaseDataManager* m_pDataManager;

@ -17,7 +17,7 @@ class LoginDialog : public QDialog
public: public:
explicit LoginDialog(QWidget *parent = nullptr); explicit LoginDialog(QWidget *parent = nullptr);
~LoginDialog(); ~LoginDialog();
UserInfo GetUserInfo(){return m_UserInfo;}
private: private:
//加载验证码 //加载验证码
void GetVerificationCode(); void GetVerificationCode();

Loading…
Cancel
Save