diff --git a/QCPShow.pro b/QCPShow.pro index dbafbdc..b0f4a5e 100644 --- a/QCPShow.pro +++ b/QCPShow.pro @@ -9,6 +9,8 @@ QT += serialport network websockets greaterThan(QT_MAJOR_VERSION, 4): QT += widgets +CONFIG += C++11 + TARGET = QCPShow TEMPLATE = app diff --git a/QCPShow.pro.user b/QCPShow.pro.user index 1ea09b4..d46a439 100644 --- a/QCPShow.pro.user +++ b/QCPShow.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/httpservice.cpp b/httpservice.cpp index 9a338a4..40bddfe 100644 --- a/httpservice.cpp +++ b/httpservice.cpp @@ -153,14 +153,72 @@ void HttpService::updateStatus(QString firstAidId, QString status) jdoc = QJsonDocument::fromJson(result, &jerror); if (jerror.error != QJsonParseError::NoError || !jdoc.isObject() || !jdoc.object().contains("code")) { - qDebug() << QString::fromUtf8("请求失败"); + qDebug() << QString::fromUtf8("updateStatus请求失败"); return; } jobj = jdoc.object(); int resCode = jobj.take("code").toInt(); if(resCode == 200){ - qDebug() << "updateStatus请求成功"; + qDebug() << "updateStatus请求成功"; }else{ qDebug() << "updateStatus失败:" << resCode; } } + +void HttpService::sendIdcardInfo(QString idcard,QString name, QString sex, QString nation) +{ + //构造参数 + QString rawJson = "{\"param\":{\"idcard\":\"%1\",\"name\":\"%2\",\"sex\":\"%3\",\"nation\":\"%4\"}}"; + QString json = rawJson.arg(idcard).arg(name).arg(sex).arg(nation); + + //发送请求 + QByteArray result = postJson(MainConfig::sendUserInfoUrl,json.toUtf8()); + qDebug() << result; + + //解析响应 + QJsonParseError jerror; + QJsonDocument jdoc; + QJsonObject jobj; + jdoc = QJsonDocument::fromJson(result, &jerror); + if (jerror.error != QJsonParseError::NoError || !jdoc.isObject() || !jdoc.object().contains("code")) + { + qDebug() << QString::fromUtf8("sendIdcardInfo请求失败"); + return; + } + jobj = jdoc.object(); + int resCode = jobj.take("code").toInt(); + if(resCode == 200){ + qDebug() << "sendIdcardInfo请求成功"; + }else{ + qDebug() << "sendIdcardInfo失败:" << resCode; + } +} + +void HttpService::oneKeyStart(QString idcard) +{ + //构造参数 + QString rawJson = "{\"param\":{\"idcard\":\"%1\"}}"; + QString json = rawJson.arg(idcard); + + //发送请求 + QByteArray result = postJson(MainConfig::sendUserInfoUrl,json.toUtf8()); + qDebug() << result; + + //解析响应 + QJsonParseError jerror; + QJsonDocument jdoc; + QJsonObject jobj; + jdoc = QJsonDocument::fromJson(result, &jerror); + if (jerror.error != QJsonParseError::NoError || !jdoc.isObject() || !jdoc.object().contains("code")) + { + qDebug() << QString::fromUtf8("oneKeyStart请求失败"); + return; + } + jobj = jdoc.object(); + int resCode = jobj.take("code").toInt(); + if(resCode == 200){ + qDebug() << "oneKeyStart请求成功"; + }else{ + qDebug() << "oneKeyStart失败:" << resCode; + } +} diff --git a/httpservice.h b/httpservice.h index 793e1af..6465e61 100644 --- a/httpservice.h +++ b/httpservice.h @@ -11,7 +11,6 @@ public: explicit HttpService(QObject *parent = 0); QByteArray get(QUrl url, quint32 timeoutInMs = 5000); QByteArray postJson(QUrl url,const QByteArray &json, quint32 timeoutInMs = 5000); -// void sendIdcardInfo(); private: QNetworkAccessManager *mManager; @@ -20,6 +19,8 @@ signals: public slots: void login(QString username,QString password); void updateStatus(QString firstAidId,QString status); + void sendIdcardInfo(QString idcard,QString name,QString sex,QString nation); + void oneKeyStart(QString idcard); }; #endif // HTTPSERVICE_H diff --git a/mainconfig.cpp b/mainconfig.cpp index e5a1c79..01acabd 100644 --- a/mainconfig.cpp +++ b/mainconfig.cpp @@ -13,6 +13,8 @@ QString MainConfig::oneKeyStartUrl = "https://test.tall.wiki/gateway/qcp/v3.0/bu QString MainConfig::serviceStatusChangedUrl = "https://test.tall.wiki/gateway/qcp/v3.0/button/updateStatus"; QString MainConfig::wsUrl = "wss://test.tall.wiki/websocket/message/v4.0/ws"; QString MainConfig::wsHeartInterval = "10"; +QString MainConfig::maxPatientNum = "5"; +QString MainConfig::switchPatientInterval = "5"; MainConfig::MainConfig(QObject *parent) : QObject(parent) { @@ -39,7 +41,11 @@ void MainConfig::createConfigFileWithDefaultValues() // iniFile->setValue("password", password); // iniFile->endGroup(); - QString content = "[USER]\n"; + QString content = "[MAIN]\n"; + content.append(";最大患者数量\n").append("maxPatientNum = ").append(maxPatientNum).append("\n"); + content.append(";切换病人时间(s)\n").append("switchPatientInterval = ").append(switchPatientInterval).append("\n"); + content.append("\n"); + content.append("[USER]\n"); content.append(";登录用户名\n").append("username = ").append(username).append("\n"); content.append(";登录密码\n").append("password = ").append(password).append("\n"); content.append("\n"); @@ -70,6 +76,12 @@ void MainConfig::readConfigFile(){ qDebug().noquote()<<"fileName:"<contains("MAIN/maxPatientNum")){ + maxPatientNum = iniFile->value("MAIN/maxPatientNum").toString(); + } + if(iniFile->contains("MAIN/switchPatientInterval")){ + switchPatientInterval = iniFile->value("MAIN/switchPatientInterval").toString(); + } if(iniFile->contains("USER/username")){ username = iniFile->value("USER/username").toString(); } @@ -94,7 +106,8 @@ void MainConfig::readConfigFile(){ if(iniFile->contains("WEBSOCKET/wsHeartInterval")){ wsHeartInterval = iniFile->value("WEBSOCKET/wsHeartInterval").toString(); } - qDebug() << username << password << "\n" + qDebug() << maxPatientNum << "\n" + << username << password << "\n" << loginUrl << sendUserInfoUrl << oneKeyStartUrl << serviceStatusChangedUrl << "\n" << wsUrl << wsHeartInterval ; } diff --git a/mainconfig.h b/mainconfig.h index 7b3d2a6..ae932f7 100644 --- a/mainconfig.h +++ b/mainconfig.h @@ -25,6 +25,8 @@ public: static QString serviceStatusChangedUrl; static QString wsUrl; static QString wsHeartInterval; + static QString maxPatientNum; + static QString switchPatientInterval; signals: public slots: diff --git a/mainwidget.cpp b/mainwidget.cpp index d6e40f6..7885384 100644 --- a/mainwidget.cpp +++ b/mainwidget.cpp @@ -1,13 +1,41 @@ #include "mainwidget.h" #include "ui_mainwidget.h" #include -#include "httpservice.h" +#include "mainconfig.h" MainWidget::MainWidget(QWidget *parent) : QWidget(parent), ui(new Ui::MainWidget) { ui->setupUi(this); + m_patientIndex = 0; + m_wsConnectedStatus = 0; + m_maxPatientNum = MainConfig::maxPatientNum.toInt(); + m_switchPatientInterval = MainConfig::switchPatientInterval.toInt(); + + //1s倒计时 + m_countDownTimer.setInterval(1000); + m_countDownTimer.start(); + connect(&m_countDownTimer, &QTimer::timeout,[=](){ + for(PatientEmergencyInfo *info : m_patientEmergencyInfos){ + if(info->realCountDownInSeconds > 0){ + info->realCountDownInSeconds--; + } + } + }); + + //切换病人 + m_switchPatientTimer.setInterval(5000); + m_switchPatientTimer.start(); + connect(&m_switchPatientTimer, &QTimer::timeout,[=](){ + if(++m_patientIndex >= m_patientEmergencyInfos.length()){ + m_patientIndex = 0; + } + updateUi(); + }); + + //显示连接状态 + ui->statusLabel->setText("Not Connected"); } MainWidget::~MainWidget() @@ -15,13 +43,50 @@ MainWidget::~MainWidget() delete ui; } +void MainWidget::updateUi() +{ + ui->statusLabel->setText(QString("%1 | %2") + .arg(m_wsConnectedStatus == 0 ? "未连接" : "已经连") + .arg(m_patientEmergencyInfos.length()) + ); + + if(m_patientEmergencyInfos.length() == 0){ + //不显示 + ui->textLabel->setText(""); + ui->countdownLabel->setText(""); + return; + } + + //获取当前病人 + if(m_patientIndex >= m_patientEmergencyInfos.length()){ + m_patientIndex = 0; + } + PatientEmergencyInfo *pInfo = m_patientEmergencyInfos[m_patientIndex]; + + //显示文本 + ui->textLabel->setText(pInfo->text); + + //显示倒计时 + int hour,min,sec,nTotalSecs; + nTotalSecs = pInfo->realCountDownInSeconds; + sec = nTotalSecs % 60; + min = nTotalSecs / 60 % 60; + hour = nTotalSecs / 3600; + QString str = QString("%1:%2").arg(min,2,10,QLatin1Char('0')).arg(sec,2,10,QLatin1Char('0')); + ui->countdownLabel->setText(str); +} + void MainWidget::onWsConnectedStatusChanged(int status) { qDebug() << "MainWidget::onWsConnectedStatusChanged " << status; + updateUi(); } void MainWidget::onNewPatientMergencyInfo(QString firstAidId, QString name, QString content, quint64 realCountDownInSeconds) { + //TODO 此处是否需要加锁处理 + PatientEmergencyInfo *pInfo = new PatientEmergencyInfo(firstAidId,name,content,realCountDownInSeconds); + addPatientToList(pInfo); qDebug() << "MainWidget::onNewPatientMergencyInfo " << firstAidId << name << content << realCountDownInSeconds; } @@ -42,6 +107,32 @@ void MainWidget::onPatientMergencyStatusChanged(QString firstAidId,QString time, if(status == 1){ //进行中(拍了一下按键) }else if(status == 2){//服务环节结束 + deletePatientFromList(firstAidId); + } +} + +void MainWidget::addPatientToList(PatientEmergencyInfo *info) +{ + //1.如果有就删除,以保证同一个病人按两次应该重新开始计时 + deletePatientFromList(info->id); + //2.如果超过长度,就删除第一个,取后来的 + if(m_patientEmergencyInfos.length() >= m_maxPatientNum){ + delete m_patientEmergencyInfos[0]; + m_patientEmergencyInfos.pop_front(); + } + + //3.加入链表 + m_patientEmergencyInfos.push_back(info); +} + +void MainWidget::deletePatientFromList(QString firstAidId) +{ + for(int i=0;iid == firstAidId){ + delete m_patientEmergencyInfos[i]; + m_patientEmergencyInfos.removeAt(i); + break; + } } } diff --git a/mainwidget.h b/mainwidget.h index 0a91c2b..c58b13b 100644 --- a/mainwidget.h +++ b/mainwidget.h @@ -2,6 +2,8 @@ #define MAINWIDGET_H #include +#include "patientemergencyinfo.h" +#include namespace Ui { class MainWidget; @@ -17,11 +19,20 @@ public: private: Ui::MainWidget *ui; + QList m_patientEmergencyInfos; + qint32 m_maxPatientNum,m_switchPatientInterval; + qint32 m_patientIndex; + QTimer m_countDownTimer; + QTimer m_switchPatientTimer; + int m_wsConnectedStatus; public slots: + void updateUi(); void onWsConnectedStatusChanged(int); void onNewPatientMergencyInfo(QString firstAidId,QString name,QString content,quint64 realCountDownInSeconds); void onPatientMergencyStatusChanged(QString firstAidId,QString time,QString status); + void addPatientToList(PatientEmergencyInfo *); + void deletePatientFromList(QString firstAidId); signals: statusChanged(QString firstAidId,QString status); diff --git a/mainwidget.h.G10556 b/mainwidget.h.G10556 new file mode 100644 index 0000000..76671d9 --- /dev/null +++ b/mainwidget.h.G10556 @@ -0,0 +1,34 @@ +#ifndef MAINWIDGET_H +#define MAINWIDGET_H + +#include +#include "patientemergencyinfo.h" + +namespace Ui { +class MainWidget; +} + +class MainWidget : public QWidget +{ + Q_OBJECT + +public: + explicit MainWidget(QWidget *parent = 0); + ~MainWidget(); + +private: + Ui::MainWidget *ui; + QList m_patientEmergencyInfos; + int m_maxPatientNum; + +public slots: + void onWsConnectedStatusChanged(int); + void onNewPatientMergencyInfo(QString firstAidId,QString name,QString content,quint64 realCountDownInSeconds); + void onPatientMergencyStatusChanged(QString firstAidId,QString time,QString status); + void addPatientToList(const PatientEmergencyInfo *); + void deletePatientFromList(QString firstAidId); +signals: + statusChanged(QString firstAidId,QString status); +}; + +#endif // MAINWIDGET_H diff --git a/mainwidget.ui b/mainwidget.ui index f96e990..f5ccf4c 100644 --- a/mainwidget.ui +++ b/mainwidget.ui @@ -1,20 +1,59 @@ + MainWidget - - + + 0 0 - 400 - 300 + 1135 + 426 - + MainWidget + + + + 210 + 75 + 721 + 61 + + + + textLabel + + + + + + 390 + 160 + 721 + 61 + + + + countdownLabel + + + + + + 1010 + 390 + 91 + 20 + + + + statusLabel + + - - + diff --git a/patientemergencyinfo.cpp b/patientemergencyinfo.cpp index 7b69366..2d857c2 100644 --- a/patientemergencyinfo.cpp +++ b/patientemergencyinfo.cpp @@ -6,3 +6,9 @@ PatientEmergencyInfo::PatientEmergencyInfo( { } + +PatientEmergencyInfo::PatientEmergencyInfo(QString id,QObject *parent) + :id(id),QObject(parent) +{ + +} diff --git a/patientemergencyinfo.h b/patientemergencyinfo.h index ce6f333..2a492b7 100644 --- a/patientemergencyinfo.h +++ b/patientemergencyinfo.h @@ -9,6 +9,7 @@ class PatientEmergencyInfo : public QObject public: explicit PatientEmergencyInfo( QString id,QString name,QString text,quint64 realCountDownInSeconds,QObject *parent = 0); + PatientEmergencyInfo(QString id,QObject *parent = 0); QString id; QString name; QString text;