From 637610bcf851d70657c2dcf251d6daed2429a9a5 Mon Sep 17 00:00:00 2001 From: wumu <mayi@mayi.com> Date: 星期三, 26 二月 2025 22:59:54 +0800 Subject: [PATCH] 0226 --- historydata.cpp | 123 ++++++++++++++++++++++++++++++++++++++++- 1 files changed, 120 insertions(+), 3 deletions(-) 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; // 鍒锋柊鏃堕棿 + + + +} -- Gitblit v1.8.0