From 987254bf420571a7b89391d8227569a1b5774019 Mon Sep 17 00:00:00 2001
From: wumu <mayi@mayi.com>
Date: 星期五, 21 二月 2025 23:25:48 +0800
Subject: [PATCH] 250221

---
 historydata.h        |   15 ++
 clientmainwindow.cpp |    3 
 getstocklist.cpp     |   74 ++++++++++++
 getstocklist.h       |    3 
 historydata.cpp      |   96 ++++++++++++++++
 historydata.ui       |  164 ++++++++++++++++++++++----
 6 files changed, 326 insertions(+), 29 deletions(-)

diff --git a/clientmainwindow.cpp b/clientmainwindow.cpp
index ebf0aea..6f7ac88 100644
--- a/clientmainwindow.cpp
+++ b/clientmainwindow.cpp
@@ -54,4 +54,7 @@
 
     connect(m_getStockList,SIGNAL(sendCodeNames(QMap<QString,QString>&)),m_history,SLOT(putCodeNames(QMap<QString,QString>&)));
 
+    connect(m_history,SIGNAL(sendHistoryModel(QVector<QVector<QString>> &)),m_getStockList,SLOT(showHistoryModelData(QVector<QVector<QString>> &)));
+    connect(m_history,SIGNAL(sendHistoryModel(QStandardItemModel*)),m_getStockList,SLOT(showHistoryModelData(QStandardItemModel*)));
+
 }
diff --git a/getstocklist.cpp b/getstocklist.cpp
index ffd5dc6..4d3f1aa 100644
--- a/getstocklist.cpp
+++ b/getstocklist.cpp
@@ -7,6 +7,7 @@
 #include <QJsonObject>
 #include <QJsonArray>
 #include <QLibrary> // 鐢ㄤ簬鍔犺浇dll鍔ㄦ�佸簱鐨勭被
+#include <QDateTime>
 
 
 #pragma execution_character_set("utf-8")
@@ -19,6 +20,8 @@
     ui->pushButton_get->hide();
     ui->statusbar->hide();
 
+    // 娉ㄥ唽鍏冪被鍨�
+    qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>> &");
     // 鏂规2:
     // 濡傛灉https 璁块棶鐨勬椂鍊欙紝杩樻槸鐖彇澶辫触锛屽彲浠ヤ唬鐮佸姞杞藉姩鎬佸簱鏉ユ敮鎸�
     // 鍓嶆彁鏉′欢鏄妸2涓猟ll鍔ㄦ�佸簱鎷疯礉鐨勭敓鎴愮洰褰曚腑:libeay32.dll 鍜� ssleay32.dll
@@ -985,3 +988,74 @@
 {
     on_pushButton_search_clicked();
 }
+
+void GetStockList::showHistoryModelData(QVector<QVector<QString>> &model) // 浠庡巻鍙查偅杈瑰皢鏁版嵁鍙戣繃鏉�
+{
+    m_model->setRowCount(model.size());
+    for(int i=0;i<model.size();++i){
+        qDebug()<<"i="<<i;
+        for(int j=0;j<model.at(0).size();++j){
+            //QString str = model[i][j];
+            //qDebug()<<str;
+            m_model->setItem(i,j,new QStandardItem(model[i][j]));
+            if(j<3){
+                m_model->setItem(i,j,new QStandardItem(model[i][j]));
+                if(j==2){
+                    m_model->setItem(i,j+1,new QStandardItem(model[i][j]));
+                }
+            }else{
+
+                m_model->setItem(i,j+1,new QStandardItem(model[i][j]));
+            }
+
+        }
+    }
+    qDebug()<<"鍘嗗彶鍒颁俊鎭祴鍊煎畬鎴�";
+}
+
+void GetStockList::showHistoryModelData(QStandardItemModel *model)
+{
+
+    //ui->tableView->setModel(model);
+    QVector<QVector<QString>> vec;
+    for(int i=0;i<model->rowCount();++i){
+        QString row;
+        QVector<QString> tmp;
+
+        m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text();
+
+        for(int j=0;j<model->columnCount();++j){
+            row+=model->item(i,j)->text()+" ";
+            tmp.append(model->item(i,j)->text());
+        }
+        qDebug()<<i<<row;
+        vec.append(tmp);
+    }
+    qDebug()<<"vec size:"<<vec.size();
+    qDebug()<<"鍘嗗彶鍒颁俊鎭祴鍊煎畬鎴�";
+    qDebug()<<QDateTime::currentDateTime();
+    m_model->setRowCount(0);
+    for(int i=0;i<vec.size();++i){
+        QList<QStandardItem*> items;
+        for(int j=0;j<vec.at(0).size();++j){
+            items.append(new QStandardItem(vec.at(i).at(j)));
+            if(j==2){
+                items.append(new QStandardItem(vec.at(i).at(j)));
+            }
+            if(j==3){
+                QStandardItem *percentItem =  items.back();
+                if(percentItem->text().toDouble() > 0){
+                    percentItem->setData(QColor("red"),Qt::DecorationRole); // 娣诲姞涓�涓楗扮殑棰滆壊涓虹孩鑹�
+                    percentItem->setData(QColor("red"),Qt::TextColorRole);  // 灏嗗瓧浣撻鑹茶缃负绾㈣壊
+                    items.at(0)->setData(QColor("red"),Qt::TextColorRole);  // 灏嗚偂绁ㄥ悕瀛楄缃负绾㈣壊
+                 }
+                else if(percentItem->text().toDouble() < 0){
+                    percentItem->setData(QColor("green"),Qt::BackgroundColorRole);
+                    items.at(0)->setData(QColor("green"),Qt::TextColorRole);
+                }
+            }
+        }
+        m_model->appendRow(items);
+    }
+    qDebug()<<QDateTime::currentDateTime();
+}
diff --git a/getstocklist.h b/getstocklist.h
index 9d37a25..3bffe18 100644
--- a/getstocklist.h
+++ b/getstocklist.h
@@ -77,6 +77,9 @@
 
     void on_lineEdit_search_returnPressed();
 
+    void showHistoryModelData(QVector<QVector<QString>> &model);
+    void showHistoryModelData(QStandardItemModel *model);
+
 private:
     Ui::GetStockList *ui;
     // 杩�2涓敤浜庣埇鍙栨暟鎹殑
diff --git a/historydata.cpp b/historydata.cpp
index 1ee12b0..8dd2e2b 100644
--- a/historydata.cpp
+++ b/historydata.cpp
@@ -19,6 +19,26 @@
 {
     ui->setupUi(this);
 
+    // 娉ㄥ唽鍏冪被鍨�
+    qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>>");
+    qRegisterMetaType<QVector<QVector<QString>>>("QVector<QVector<QString>> &");
+
+    // ui鐩稿叧
+    ui->dateEdit->setDate(QDate::currentDate());
+    m_model = new QStandardItemModel(1,9,this);
+
+    m_customModel = new CustomSortProxyModel; // 鍙嚜瀹氫箟鎺掑簭鐨勬ā鍨�
+    m_customModel->setSourceModel(m_model); // 璁剧疆婧愭ā鍨�
+
+    //ui->tableView->setModel(m_model);
+    ui->tableView->setModel(m_customModel);
+    // 琛ㄦ牸鍒楁帓搴�
+    ui->tableView->setSortingEnabled(true);
+
+    QStringList labels;
+    labels<<"鑲$エ鍚嶅瓧"<<"鑲$エ浠e彿"<<"甯傚��(浜�)"<<"娑ㄨ穼骞�"<<"鏀剁洏浠�"<<"鎴愪氦棰�(浜�)"<<"鎴愪氦閲�"<<"鎹㈡墜鐜�"<<"PE_TTM";
+    m_model->setHorizontalHeaderLabels(labels);
+
     initMySQL(); // 鍒濆鍖朚ySQL
 
     // 澶勭悊鏁版嵁鐖彇鐨勬搷浣�
@@ -202,3 +222,79 @@
     }
 
 }
+
+void HistoryData::on_pushButton_search_clicked()
+{
+    // 鎻愮ず鏌ヨ绛夊緟
+    ui->statusbar->showMessage("鏌ヨ涓�...璇疯�愬績绛夊緟缁撴灉...");
+
+    QString searchTime = ui->dateEdit->text();
+    qDebug()<<"鏌ヨ鐨勬椂闂�:"<<searchTime;
+    QString sql = QString("select name,code,market_capital,percent,close,amount,volume,turnover_rate,pe_ttm from stock_day_info where time_trade = '%1'").arg(searchTime);
+    qDebug()<<"sql:"<<sql;
+
+    m_modelDatas.clear(); // 娓呯┖鏁扮粍涓殑鏁版嵁
+
+    qint64 tt = QDateTime::currentMSecsSinceEpoch();
+    QSqlQuery que(db);
+    if(que.exec(sql)){
+        qDebug()<<"select ok";
+        m_model->setRowCount(0); // 閲嶇疆妯″瀷琛屾暟
+        int rows = 0;
+        while (que.next()) {
+            QString name = que.value(0).toString();
+            QString code = que.value(1).toString();
+            QString market_capital = QString::number(que.value(2).toDouble()/100000000);
+            QString percent = que.value(3).toString();
+            QString close = que.value(4).toString();
+            QString amount = QString::number(que.value(5).toDouble()/100000000);
+            QString volume = que.value(6).toString();
+            QString turnover_rate = que.value(7).toString();
+            QString pe_ttm = que.value(8).toString();
+
+            m_modelDatas.append({name,code,market_capital,percent,close,amount,volume,turnover_rate,pe_ttm});
+
+            QList<QStandardItem*> items;
+            items.append(new QStandardItem(name));
+            items.append(new QStandardItem(code));
+            items.append(new QStandardItem(market_capital));
+            //items.append(new QStandardItem(percent));
+            QStandardItem *percentItem =  new QStandardItem(percent);
+            if(percent.toDouble() > 0){
+                percentItem->setData(QColor("red"),Qt::DecorationRole); // 娣诲姞涓�涓楗扮殑棰滆壊涓虹孩鑹�
+                percentItem->setData(QColor("red"),Qt::TextColorRole);  // 灏嗗瓧浣撻鑹茶缃负绾㈣壊
+                items.at(0)->setData(QColor("red"),Qt::TextColorRole);  // 灏嗚偂绁ㄥ悕瀛楄缃负绾㈣壊
+             }
+            else if(percent.toDouble() < 0){
+                percentItem->setData(QColor("green"),Qt::BackgroundColorRole);
+                items.at(0)->setData(QColor("green"),Qt::TextColorRole);
+            }
+            items.append(percentItem);
+
+            items.append(new QStandardItem(close));
+            items.append(new QStandardItem(amount));
+            items.append(new QStandardItem(volume));
+            items.append(new QStandardItem(turnover_rate));
+            items.append(new QStandardItem(pe_ttm));
+            m_model->appendRow(items);
+            rows++;
+        }
+        qDebug()<<"鏌ヨ鍒拌鏁�:"<<rows;
+
+    }else{
+        qDebug()<<"select fail"<<que.lastError().text();
+    }
+    // 鏈�鍚庢彁绀哄畬鎴�
+    qint64 need = QDateTime::currentMSecsSinceEpoch()-tt;
+    ui->statusbar->showMessage(QString("鑰楁椂:%1 姣,鏌ヨ瀹屾垚.").arg(QString::number(need)),10*1000);
+    ui->tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
+    //emit sendHistoryModel(m_modelDatas); // 缁欎俊鎭睍绀哄彂妯″瀷
+
+    ui->textBrowser->append(QString("鏌ヨ鏃ユ湡:%1 鑰楁椂: %2 姣 鏌ュ埌鏉℃暟:%3").arg(searchTime).arg(QString::number(need)).arg(QString::number(m_model->rowCount())));
+}
+
+void HistoryData::on_pushButton_2_clicked()
+{
+    //emit sendHistoryModel(m_modelDatas); // 缁欎俊鎭睍绀哄彂妯″瀷
+    emit sendHistoryModel(m_model);
+}
diff --git a/historydata.h b/historydata.h
index 1338cf3..bd8ac49 100644
--- a/historydata.h
+++ b/historydata.h
@@ -8,6 +8,8 @@
 #include <QSqlDatabase>
 #include <QSqlError>
 #include <QSqlQuery>
+#include <QStandardItemModel>
+#include "customsortproxymodel.h"
 
 namespace Ui {
 class HistoryData;
@@ -23,6 +25,10 @@
 
     void initMySQL();
 
+signals:
+    void sendHistoryModel(QVector<QVector<QString>> &); // 灏嗘ā鍨嬪彂缁欎俊鎭睍绀�
+    void sendHistoryModel(QStandardItemModel *); // 灏嗘ā鍨嬪彂缁欎俊鎭睍绀�
+
 private slots:
     void on_pushButton_clicked();
 
@@ -33,6 +39,10 @@
     void showAplyData(QNetworkReply* reply);
     void getOneStock(QByteArray &buffer);
     
+    void on_pushButton_search_clicked();
+
+    void on_pushButton_2_clicked();
+
 private:
     Ui::HistoryData *ui;
 
@@ -43,6 +53,11 @@
     QNetworkRequest m_request; // 鐢ㄤ簬绠$悊璇锋眰澶寸殑
     QString m_cookie; // 缂撳瓨
     QNetworkAccessManager m_manager; // 鐢ㄤ簬绠$悊http璇锋眰鍙婂搷搴旂殑
+
+    QStandardItemModel *m_model;
+    CustomSortProxyModel *m_customModel; // 鐢ㄤ簬鎺掑簭鐨勮嚜瀹氫箟妯″瀷
+
+    QVector<QVector<QString>> m_modelDatas; // 琛屽垪瀛樺偍
 };
 
 #endif // HISTORYDATA_H
diff --git a/historydata.ui b/historydata.ui
index b857d56..adb986f 100644
--- a/historydata.ui
+++ b/historydata.ui
@@ -6,47 +6,153 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>827</width>
-    <height>711</height>
+    <width>859</width>
+    <height>779</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
   <widget class="QWidget" name="centralwidget">
-   <widget class="QPushButton" name="pushButton">
-    <property name="geometry">
-     <rect>
-      <x>540</x>
-      <y>20</y>
-      <width>101</width>
-      <height>41</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>Test</string>
-    </property>
-   </widget>
-   <widget class="QPushButton" name="pushButton_update">
-    <property name="geometry">
-     <rect>
-      <x>650</x>
-      <y>20</y>
-      <width>111</width>
-      <height>41</height>
-     </rect>
-    </property>
-    <property name="text">
-     <string>涓�閿洿鏂版暟鎹�</string>
-    </property>
-   </widget>
+   <layout class="QGridLayout" name="gridLayout_3">
+    <item row="0" column="0">
+     <widget class="QGroupBox" name="groupBox">
+      <property name="title">
+       <string>鎿嶄綔鐩稿叧</string>
+      </property>
+      <layout class="QGridLayout" name="gridLayout">
+       <item row="0" column="0">
+        <layout class="QHBoxLayout" name="horizontalLayout">
+         <item>
+          <widget class="QPushButton" name="pushButton">
+           <property name="text">
+            <string>Test</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QPushButton" name="pushButton_update">
+           <property name="enabled">
+            <bool>false</bool>
+           </property>
+           <property name="text">
+            <string>涓�閿洿鏂版暟鎹�</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+       <item row="1" column="0">
+        <layout class="QHBoxLayout" name="horizontalLayout_2">
+         <item>
+          <widget class="QDateEdit" name="dateEdit">
+           <property name="displayFormat">
+            <string>yyyy-MM-dd</string>
+           </property>
+           <property name="calendarPopup">
+            <bool>true</bool>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QPushButton" name="pushButton_search">
+           <property name="text">
+            <string>鏌ヨ</string>
+           </property>
+          </widget>
+         </item>
+         <item>
+          <widget class="QPushButton" name="pushButton_2">
+           <property name="text">
+            <string>鍙戦�佸巻鍙插埌淇℃伅灞曠ず</string>
+           </property>
+          </widget>
+         </item>
+        </layout>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item row="1" column="0">
+     <widget class="QTableView" name="tableView"/>
+    </item>
+    <item row="2" column="0">
+     <layout class="QHBoxLayout" name="horizontalLayout_3">
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout_3">
+        <item>
+         <widget class="QTextBrowser" name="textBrowser"/>
+        </item>
+        <item>
+         <widget class="QGroupBox" name="groupBox_2">
+          <property name="title">
+           <string>娣诲姞鍒扮洃娴嬭偂绁ㄦ睜</string>
+          </property>
+          <layout class="QGridLayout" name="gridLayout_2">
+           <item row="0" column="0">
+            <layout class="QVBoxLayout" name="verticalLayout">
+             <item>
+              <widget class="QLineEdit" name="lineEdit">
+               <property name="placeholderText">
+                <string>杈撳叆鑲$エ鍚嶇О</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="lineEdit_2">
+               <property name="placeholderText">
+                <string>杈撳叆鑲$エ浠e彿</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QLineEdit" name="lineEdit_3">
+               <property name="placeholderText">
+                <string>杈撳叆鑲$エ浠锋牸</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </item>
+           <item row="0" column="1">
+            <layout class="QVBoxLayout" name="verticalLayout_2">
+             <item>
+              <widget class="QDateEdit" name="dateEdit_2">
+               <property name="displayFormat">
+                <string>yyyy-MM-dd</string>
+               </property>
+               <property name="calendarPopup">
+                <bool>true</bool>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QPushButton" name="pushButton_3">
+               <property name="text">
+                <string>娣诲姞</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </item>
+          </layout>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item>
+       <widget class="QTableView" name="tableView_2"/>
+      </item>
+     </layout>
+    </item>
+   </layout>
   </widget>
   <widget class="QMenuBar" name="menubar">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>827</width>
+     <width>859</width>
      <height>26</height>
     </rect>
    </property>

--
Gitblit v1.8.0