From 637610bcf851d70657c2dcf251d6daed2429a9a5 Mon Sep 17 00:00:00 2001
From: wumu <mayi@mayi.com>
Date: 星期三, 26 二月 2025 22:59:54 +0800
Subject: [PATCH] 0226

---
 showinfomessage.ui  |   18 +++
 showinfomessage.h   |    3 
 historydata.h       |   12 ++
 getstocklist.cpp    |   77 +++++++++------
 showinfomessage.cpp |    7 +
 historydata.cpp     |  123 ++++++++++++++++++++++++
 historydata.ui      |    9 +
 7 files changed, 213 insertions(+), 36 deletions(-)

diff --git a/getstocklist.cpp b/getstocklist.cpp
index 4d3f1aa..c1b5066 100644
--- a/getstocklist.cpp
+++ b/getstocklist.cpp
@@ -991,56 +991,68 @@
 
 void GetStockList::showHistoryModelData(QVector<QVector<QString>> &model) // 浠庡巻鍙查偅杈瑰皢鏁版嵁鍙戣繃鏉�
 {
-    m_model->setRowCount(model.size());
+    qDebug()<<QDateTime::currentDateTime();
+    m_model->setRowCount(0);
     for(int i=0;i<model.size();++i){
-        qDebug()<<"i="<<i;
+        //qDebug()<<"i="<<i;
+        QList<QStandardItem*> items;
+        m_codeNames[model[i][1]] = model[i][0];
         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{
+            items.append(new QStandardItem(model[i][j]));
 
-                m_model->setItem(i,j+1,new QStandardItem(model[i][j]));
+            if(j==2){
+                items.append(new QStandardItem(model[i][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()<<"鍘嗗彶鍒颁俊鎭祴鍊煎畬鎴�";
+    qDebug()<<"鍘嗗彶鍒颁俊鎭祴鍊煎畬鎴� 琛屾暟:"<<m_model->rowCount();
+    qDebug()<<QDateTime::currentDateTime();
 }
 
 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;
+//    qDebug()<<QDateTime::currentDateTime();
+//    //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();
+//        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()<<"鍘嗗彶鍒颁俊鎭祴鍊煎畬鎴�";
+//        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()<<QDateTime::currentDateTime();
     m_model->setRowCount(0);
-    for(int i=0;i<vec.size();++i){
+    for(int i=0;i<model->rowCount();++i){
         QList<QStandardItem*> items;
-        for(int j=0;j<vec.at(0).size();++j){
-            items.append(new QStandardItem(vec.at(i).at(j)));
+        m_codeNames[model->item(i,1)->text()] = model->item(i,0)->text();
+        for(int j=0;j<model->columnCount();++j){
+            items.append(new QStandardItem(model->item(i,j)->text()));
             if(j==2){
-                items.append(new QStandardItem(vec.at(i).at(j)));
+                items.append(new QStandardItem(model->item(i,j)->text()));
             }
             if(j==3){
                 QStandardItem *percentItem =  items.back();
@@ -1057,5 +1069,6 @@
         }
         m_model->appendRow(items);
     }
+    qDebug()<<"鍘嗗彶鍒颁俊鎭祴鍊煎畬鎴� 鏉℃暟:"<<m_model->rowCount();
     qDebug()<<QDateTime::currentDateTime();
 }
diff --git a/historydata.cpp b/historydata.cpp
index 8dd2e2b..e066017 100644
--- a/historydata.cpp
+++ b/historydata.cpp
@@ -25,6 +25,8 @@
 
     // ui鐩稿叧
     ui->dateEdit->setDate(QDate::currentDate());
+    ui->dateEdit_2->setDate(QDate::currentDate());
+
     m_model = new QStandardItemModel(1,9,this);
 
     m_customModel = new CustomSortProxyModel; // 鍙嚜瀹氫箟鎺掑簭鐨勬ā鍨�
@@ -66,7 +68,19 @@
     // 鍘昏姹傞椤�
     m_manager.get(m_request);
 
+    // 鑲$エ姹犵浉鍏�
+    m_poolModel = new QStandardItemModel(1,9,this);
 
+    QStringList poolLabel;
+    poolLabel<<"id"<<"鑲$エ鍚嶅瓧"<<"鑲$エ浠e彿"<<"鐩戞帶璁板綍鏃堕棿"<<"鐩戞帶涔板叆浠锋牸"<<"褰撳墠浠锋牸"<<"鐩堜簭鐧惧垎姣�"<<"鐩戞帶鍗栧嚭浠锋牸"<<"鐩戞帶鍗栧嚭鏃堕棿";
+    m_poolModel->setHorizontalHeaderLabels(poolLabel);
+    ui->tableView_2->setModel(m_poolModel);
+
+
+    // 鑲$エ姹犲畾鏃跺埛鏂�
+    m_poolTimer = new QTimer(this);
+    connect(m_poolTimer,SIGNAL(timeout()),this,SLOT(poolTimerSlot()));
+    m_poolTimer->start(10*1000);
 }
 
 HistoryData::~HistoryData()
@@ -110,9 +124,10 @@
 {
     // 鎶�5000鏀偂绁ㄦ尐涓幏鍙栧埌锛岀劧鍚庤繘琛屾暟鎹繚瀛橈紝瀛樺埌琛ㄦ牸涓�
     // 鏇存柊鐨勬椂鍊欙紝榛樿鏀寔10骞寸殑鏁版嵁鏌ヨ
+    if(m_days <= 0) return;
 
     QString time_tar=QString::number(QDateTime::currentMSecsSinceEpoch());
-    QString dayCnt=QString::number(3000);
+    QString dayCnt=QString::number(m_days);
     QString type = "day"; // day week month
     for(auto code:m_codeNames.keys()){
         QString url = QString("https://stock.xueqiu.com/v5/stock/chart/kline.json?symbol=%1&begin=%2&period=%3&type=before&count=-%4&indicator=kline,pe,market_capital,ma").arg(code)
@@ -123,6 +138,15 @@
         m_manager.get(m_request);
         //break; // 娴嬭瘯鐢�
 
+    }
+    // 鏇存柊鏃堕棿
+    QString curDate = QDate::currentDate().toString("yyyy-MM-dd");
+    QString sql = QString("insert into days_info (log_time) values ('%1')").arg(curDate);
+    QSqlQuery que(db);
+    if(que.exec(sql)){
+        qDebug()<<"update log time ok:"<<curDate;
+    }else{
+        qDebug()<<"update log time fail:"<<curDate;
     }
     
 }
@@ -215,9 +239,9 @@
 
         QSqlQuery que(db);
         if(que.exec(sql)){
-            qDebug()<<"intsert ok";
+            qDebug()<<"insert ok";
         }else{
-            qDebug()<<"intsert fail"<<que.lastError().text();
+            qDebug()<<"insert fail"<<que.lastError().text();
         }
     }
 
@@ -298,3 +322,96 @@
     //emit sendHistoryModel(m_modelDatas); // 缁欎俊鎭睍绀哄彂妯″瀷
     emit sendHistoryModel(m_model);
 }
+
+void HistoryData::on_pushButton_addStock_clicked()
+{
+    QString name = ui->lineEdit->text();
+    QString code = ui->lineEdit_2->text();
+    QString price = ui->lineEdit_3->text();
+    QString in_date = ui->dateEdit_2->text();
+    qDebug()<<name<<code<<price<<in_date;
+
+    QString sql = QString("insert into stock_pool (name,code,in_price,in_time) values('%1','%2',%3,'%4')").arg(name).arg(code).arg(price).arg(in_date);
+    qDebug()<<"sql:"<<sql;
+
+    QSqlQuery que(db);
+    if(que.exec(sql)){
+        qDebug()<<"insert ok";
+        poolTimerSlot(); // 绔嬮┈鍒锋柊鑲$エ姹犵殑妯″瀷锛屽埛鏂拌鍥�
+    }else{
+        qDebug()<<"insert fail";
+    }
+}
+
+void HistoryData::poolTimerSlot()
+{
+    QString sql = "select * from stock_pool where state=1";
+    QSqlQuery que(db);
+    if(que.exec(sql)){
+        qDebug()<<"select ok:"<<QDateTime::currentDateTime();
+        m_poolModel->setRowCount(0);
+        while (que.next()) {
+            QList<QStandardItem*> items;
+            for(int i=0;i<9;++i){
+                QString item = que.value(i).toString();
+                QStandardItem *it = new QStandardItem(item);
+                if(i==6){
+                    if(item.toDouble() > 0){
+                        it->setData(QColor("red"),Qt::DecorationRole); // 娣诲姞涓�涓楗扮殑棰滆壊涓虹孩鑹�
+                        it->setData(QColor("red"),Qt::TextColorRole);  // 灏嗗瓧浣撻鑹茶缃负绾㈣壊
+                        items.at(1)->setData(QColor("red"),Qt::TextColorRole);  // 灏嗚偂绁ㄥ悕瀛楄缃负绾㈣壊
+                    }else if(item.toDouble() < 0){
+                        it->setData(QColor("green"),Qt::BackgroundColorRole);
+                        items.at(1)->setData(QColor("green"),Qt::TextColorRole);
+                    }
+                }
+                items.append(it);
+            }
+            m_poolModel->appendRow(items); // 鏁磋娣诲姞 鏁堢巼鏇撮珮
+
+        }
+    }else{
+        qDebug()<<"select fail";
+    }
+    m_poolTimer->setInterval(60*1000);
+}
+
+void HistoryData::on_checkBox_clicked()
+{
+    QString dt = "2025-02-10";
+    QString sql = "select log_time from days_info order by log_time desc";
+    QSqlQuery que(db);
+    if(que.exec(sql)){
+        if (que.next()) {
+            dt = que.value(0).toString();
+        }else{
+            qDebug()<<"鏌ヨ缁撴灉闆嗕负绌�";
+            return;
+        }
+    }else{
+        qDebug()<<"鏌ヨ澶辫触";
+        return ;
+    }
+
+    if(ui->checkBox->isChecked()){
+        ui->pushButton_update->setEnabled(true);
+    }else{
+        ui->pushButton_update->setEnabled(false);
+    }
+
+
+
+    QDate d1 = QDate::fromString(dt,"yyyy-MM-dd");
+    QDate d2 = QDate::currentDate();
+    int days = 0; // 缁忚繃浜嗗灏戜釜鍛ㄥ唴鐨勫ぉ鏁�
+    for(QDate begin = d1.addDays(1);begin <= d2;begin = begin.addDays(1)){
+        if(begin.dayOfWeek() != Qt::Saturday && begin.dayOfWeek() != Qt::Sunday){
+            days++;
+        }
+    }
+    qDebug()<<"days:"<<days;
+    m_days = days; // 鍒锋柊鏃堕棿
+
+
+
+}
diff --git a/historydata.h b/historydata.h
index bd8ac49..cda1807 100644
--- a/historydata.h
+++ b/historydata.h
@@ -10,6 +10,7 @@
 #include <QSqlQuery>
 #include <QStandardItemModel>
 #include "customsortproxymodel.h"
+#include <QTimer>
 
 namespace Ui {
 class HistoryData;
@@ -43,6 +44,12 @@
 
     void on_pushButton_2_clicked();
 
+    void on_pushButton_addStock_clicked();
+
+    void poolTimerSlot(); // 鑲$エ姹犲埛鏂扮殑瀹氭椂鍣ㄦЫ
+
+    void on_checkBox_clicked();
+
 private:
     Ui::HistoryData *ui;
 
@@ -56,8 +63,13 @@
 
     QStandardItemModel *m_model;
     CustomSortProxyModel *m_customModel; // 鐢ㄤ簬鎺掑簭鐨勮嚜瀹氫箟妯″瀷
+    QStandardItemModel *m_poolModel; // 鑲$エ姹犳ā鍨�
 
     QVector<QVector<QString>> m_modelDatas; // 琛屽垪瀛樺偍
+
+    QTimer *m_poolTimer; // 鍒锋柊鑲$エ姹犵殑瀹氭椂鍣�
+
+    int m_days=0; // 涓婃鏇存柊鍒扮幇鍦ㄧ粡杩囩殑澶╂暟
 };
 
 #endif // HISTORYDATA_H
diff --git a/historydata.ui b/historydata.ui
index adb986f..04be64a 100644
--- a/historydata.ui
+++ b/historydata.ui
@@ -40,6 +40,13 @@
            </property>
           </widget>
          </item>
+         <item>
+          <widget class="QCheckBox" name="checkBox">
+           <property name="text">
+            <string>鏇村埌鏈�鏂�</string>
+           </property>
+          </widget>
+         </item>
         </layout>
        </item>
        <item row="1" column="0">
@@ -127,7 +134,7 @@
               </widget>
              </item>
              <item>
-              <widget class="QPushButton" name="pushButton_3">
+              <widget class="QPushButton" name="pushButton_addStock">
                <property name="text">
                 <string>娣诲姞</string>
                </property>
diff --git a/showinfomessage.cpp b/showinfomessage.cpp
index 5b7f01c..7306094 100644
--- a/showinfomessage.cpp
+++ b/showinfomessage.cpp
@@ -1,5 +1,6 @@
 锘�#include "showinfomessage.h"
 #include "ui_showinfomessage.h"
+#include <QTextCursor>
 
 ShowInfoMessage::ShowInfoMessage(QWidget *parent) :
     QMainWindow(parent),
@@ -17,3 +18,9 @@
 {
     ui->textBrowser->append(info);
 }
+
+void ShowInfoMessage::on_pushButton_clicked()
+{
+    QString text = ui->lineEdit->text();
+    //ui->textBrowser->moveCursor();
+}
diff --git a/showinfomessage.h b/showinfomessage.h
index 36cdf58..b3e2349 100644
--- a/showinfomessage.h
+++ b/showinfomessage.h
@@ -17,6 +17,9 @@
 
 public slots:
     void showInfo(QString info);
+private slots:
+    void on_pushButton_clicked();
+
 private:
     Ui::ShowInfoMessage *ui;
 };
diff --git a/showinfomessage.ui b/showinfomessage.ui
index d2b3ca9..f58c5ad 100644
--- a/showinfomessage.ui
+++ b/showinfomessage.ui
@@ -16,6 +16,24 @@
   <widget class="QWidget" name="centralwidget">
    <layout class="QGridLayout" name="gridLayout">
     <item row="0" column="0">
+     <layout class="QHBoxLayout" name="horizontalLayout">
+      <item>
+       <widget class="QLineEdit" name="lineEdit">
+        <property name="placeholderText">
+         <string>杈撳叆瑕佹煡鎵剧殑鍐呭</string>
+        </property>
+       </widget>
+      </item>
+      <item>
+       <widget class="QPushButton" name="pushButton">
+        <property name="text">
+         <string>鏌ユ壘</string>
+        </property>
+       </widget>
+      </item>
+     </layout>
+    </item>
+    <item row="1" column="0">
      <widget class="QTextBrowser" name="textBrowser"/>
     </item>
    </layout>

--
Gitblit v1.8.0