From 17cc9e5297d41970274676b5eeee9dfdd627fedc Mon Sep 17 00:00:00 2001 From: sunwen Date: Tue, 5 Sep 2023 16:32:38 +0800 Subject: [PATCH] Add UserOperationLog. --- src/UserOperationLogForm.cpp | 46 ++++++++++++----------- src/UserOperationLogForm.h | 7 ++-- src/dialogs/ChangePasswordFormDialog.cpp | 2 +- src/dialogs/GUIMessageDialog.cpp | 4 +- src/dialogs/GetWorkListDialog.cpp | 2 + src/forms/recon/ReconFormWidget.cpp | 8 +++- src/forms/scan/PatientInformationForm.cpp | 5 +++ src/forms/scan/PatientInformationForm.h | 1 + src/forms/select/SelectFormWidget.cpp | 7 ++-- src/forms/settings/GeneralForm.cpp | 4 ++ src/forms/settings/SettingFormWidget.cpp | 8 +++- src/json/jsonobject.cpp | 5 +++ src/json/jsonobject.h | 1 + src/log/LogFileTableModel.cpp | 2 + src/log/UserOperationLog.cpp | 42 +++++++++++++++------ src/log/UserOperationLog.h | 5 ++- src/main.cpp | 1 + src/windows/LoginDialog.cpp | 3 +- 18 files changed, 103 insertions(+), 50 deletions(-) diff --git a/src/UserOperationLogForm.cpp b/src/UserOperationLogForm.cpp index 593b955..c040ed3 100644 --- a/src/UserOperationLogForm.cpp +++ b/src/UserOperationLogForm.cpp @@ -34,12 +34,25 @@ UserOperationLogForm::UserOperationLogForm(QWidget* parent) { btn = new QPushButton(header); headerLayout->addWidget(btn, 0, Qt::AlignLeft); headerLayout->addSpacerItem(new QSpacerItem(20, 20, QSizePolicy::Expanding)); - table = new SlideTableView(this); - layout->addWidget(header); - layout->addWidget(table); + model = new LogFileTableModel(this); + model->setHeader(QStringList()<< "Operation Date" << "Operation Time" << "User" << "Operation"); + loadUserOperationLog(); + table = new SlideTableView(this); + layout->addWidget(header); + layout->addWidget(table); + table->setModel(model); + table->setAlternatingRowColors(true); + table->setSelectionMode(QAbstractItemView::NoSelection); + table->setEditTriggers(QAbstractItemView::NoEditTriggers); + table->verticalHeader()->setDefaultSectionSize(38); + table->horizontalHeader()->setStretchLastSection(true); + table->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed); + table->setColumnWidth(0, 250); + table->setColumnWidth(1, 250); + table->setColumnWidth(2, 200); //暂时先放构造函数,之后需要移除,等需要时再调用 - loadUserOperationLog(); + connect(btn, &QPushButton::clicked, [=]() { auto files = UserOperationLog::getHistoryLogFiles(); QStringList dates; @@ -75,7 +88,6 @@ UserOperationLogForm::~UserOperationLogForm() { void UserOperationLogForm::loadUserOperationLog() { QString filePath = UserOperationLog::Default()->currentLogFile(); - model->setFileName(filePath); btn->setText(fileNameToDate(filePath)); loadUserOperationLog(filePath, fileNameToDate(filePath)); selectedDateStr = fileNameToDate(filePath); @@ -83,22 +95,12 @@ void UserOperationLogForm::loadUserOperationLog() { void UserOperationLogForm::loadUserOperationLog(const QString& fileName, const QString& date) { selectedDateStr = date; - model->setFileName(dateToFileName(date)); + model->setFileName(dateToFileName(date)); btn->setText(date); - QStringList header; - header << "Operation Date" << "Operation Time" << "User" << "Operation"; - model->setHeader(header); - // UserOperationLog::getHistoryLogFiles(); - delete table; - table = new SlideTableView(this); - layout->addWidget(table); - table->setModel(model); - - table->setAlternatingRowColors(true); - table->setSelectionMode(QAbstractItemView::NoSelection); - table->setEditTriggers(QAbstractItemView::NoEditTriggers); - table->verticalHeader()->setDefaultSectionSize(38); - table->horizontalHeader()->setStretchLastSection(true); - table->setColumnWidth(0, 250); - table->setColumnWidth(1, 250); +} + +void UserOperationLogForm::showEvent(QShowEvent *aEvent) +{ + loadUserOperationLog("", selectedDateStr); + QWidget::showEvent(aEvent); } diff --git a/src/UserOperationLogForm.h b/src/UserOperationLogForm.h index 28b4827..26465e2 100644 --- a/src/UserOperationLogForm.h +++ b/src/UserOperationLogForm.h @@ -1,7 +1,3 @@ -// -// Created by Krad on 2021/11/23. -// - #ifndef GUI_USEROPERATIONLOGFORM_H #define GUI_USEROPERATIONLOGFORM_H @@ -19,6 +15,9 @@ public: void loadUserOperationLog(); void loadUserOperationLog(const QString& fileName, const QString& date); +protected: + void showEvent(QShowEvent *aEvent) override; + private: QTableView* table = nullptr; QPushButton* btn = nullptr; diff --git a/src/dialogs/ChangePasswordFormDialog.cpp b/src/dialogs/ChangePasswordFormDialog.cpp index bdd1139..5e941b6 100644 --- a/src/dialogs/ChangePasswordFormDialog.cpp +++ b/src/dialogs/ChangePasswordFormDialog.cpp @@ -100,6 +100,6 @@ bool ChangePasswordFormDialog::updateReferenceData() User::Current()->restorePassword(encryptPwd); return false; } - LOG_USER_OPERATION(ChangePassword); + LOG_USER_OPERATION("Change Password"); return true; } diff --git a/src/dialogs/GUIMessageDialog.cpp b/src/dialogs/GUIMessageDialog.cpp index 57081e3..b6ea577 100644 --- a/src/dialogs/GUIMessageDialog.cpp +++ b/src/dialogs/GUIMessageDialog.cpp @@ -95,7 +95,7 @@ void GUIMessageDialog::startLoading() { } accept(); EventCenter::Default()->triggerEvent(GUIEvents::RequestFullScanStop, nullptr, nullptr); - LOG_USER_OPERATION(Stop); + LOG_USER_OPERATION("Stop Scan"); }); mTimerID = startTimer(100); mBtnMain->setVisible(true); @@ -117,7 +117,7 @@ void GUIMessageDialog::showExitButton() { mTimerID = -1; } accept(); - LOG_USER_OPERATION(ConfirmError); + LOG_USER_OPERATION("Confirm Error"); }); } diff --git a/src/dialogs/GetWorkListDialog.cpp b/src/dialogs/GetWorkListDialog.cpp index 2ecf0de..2cf425e 100644 --- a/src/dialogs/GetWorkListDialog.cpp +++ b/src/dialogs/GetWorkListDialog.cpp @@ -15,6 +15,7 @@ #include "components/ULineEdit.h" #include "action/GetWorkListAction.h" #include "action/ActionCreator.h" +#include "log/UserOperationLog.h" GetWorkListDialog::GetWorkListDialog(QSqlTableModel* aSqlModel, QTableView* aTableView, QWidget* aParent, Qt::WindowFlags aFlags) : AsyncActionDialog(ActionCreator::getAsyncAction("GetWorkListAction"),"Work List", aParent, aFlags) @@ -254,4 +255,5 @@ void GetWorkListDialog::insertPatient(PatientInformationPointer aPatient) mErrorLabel->show(); } mTableView->selectRow(0); + LOG_USER_OPERATION(QString("Add Patient, ID:%1").arg(aPatient->ID)); } diff --git a/src/forms/recon/ReconFormWidget.cpp b/src/forms/recon/ReconFormWidget.cpp index c19acba..4231859 100644 --- a/src/forms/recon/ReconFormWidget.cpp +++ b/src/forms/recon/ReconFormWidget.cpp @@ -51,7 +51,11 @@ ReconFormWidget::ReconFormWidget(QWidget *parent) contentLayout->setContentsMargins(0, 0, 0, 0); initTableView(contentLayout); - connect(mBtnRefresh, &QToolButton::clicked, DeviceManager::Default(), &DeviceManager::updateReconState); + connect(mBtnRefresh, &QToolButton::clicked, []() + { + LOG_USER_OPERATION("Update Recon State") + DeviceManager::Default()->updateReconState(); + }); connect(DeviceManager::Default(), &DeviceManager::updateReconStateFinished, mModel, &QSqlTableModel::select); connect(DeviceManager::Default(), &DeviceManager::transferStatusUpdated, mModel, &QSqlTableModel::select); connect(mSearchWidget, &ScanSearchCriteriaForm::searchFilterUpdated, this, &ReconFormWidget::updateSearchFilter); @@ -157,7 +161,7 @@ void ReconFormWidget::deleteReconRecord() { mScanTable->selectRow(0); mModel->selectRow(0); - LOG_USER_OPERATION(DeletePatient) + LOG_USER_OPERATION(QString("Delete Recon, ID: %1").arg(mModel->index(currentRowIndex, getTableColumnIndex("PatientID")).data().toString())) } } else diff --git a/src/forms/scan/PatientInformationForm.cpp b/src/forms/scan/PatientInformationForm.cpp index f463458..5becc58 100644 --- a/src/forms/scan/PatientInformationForm.cpp +++ b/src/forms/scan/PatientInformationForm.cpp @@ -47,6 +47,11 @@ void PatientInformationForm::setProtocol(int type) { } } +QString PatientInformationForm::getPatientID() +{ + return mUI->lbl_ID->text(); +} + const char* PatientInformationForm::getCurrentPatientJsonString(bool empty) { cJSON* patientInfoObject = cJSON_CreateObject(); diff --git a/src/forms/scan/PatientInformationForm.h b/src/forms/scan/PatientInformationForm.h index 49544f6..aa000d6 100644 --- a/src/forms/scan/PatientInformationForm.h +++ b/src/forms/scan/PatientInformationForm.h @@ -17,6 +17,7 @@ public: void setPatientInformation(PatientInformation* information); void setProtocol(int type); const char * getCurrentPatientJsonString(bool emptyScan); + QString getPatientID(); private: Ui::PatientInformationForm *mUI; PatientInformation* mInfo = nullptr; diff --git a/src/forms/select/SelectFormWidget.cpp b/src/forms/select/SelectFormWidget.cpp index eb431d8..2b924d6 100644 --- a/src/forms/select/SelectFormWidget.cpp +++ b/src/forms/select/SelectFormWidget.cpp @@ -122,12 +122,13 @@ void SelectFormWidget::editPatient() { if (addFlag){ mPatTable->selectRow(0); mModel->selectRow(0); + LOG_USER_OPERATION(QString("Add Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID)) } else{ mPatTable->clicked(mPatTable->currentIndex()); setPatientDetail(mPatTable, mModel, patientDetailForm); + LOG_USER_OPERATION(QString("Edit Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID)) } - LOG_USER_OPERATION(AddPatient) mBtnSelect->setEnabled(true); } } @@ -154,7 +155,7 @@ void SelectFormWidget::delPatient() { mPatTable->selectRow(0); mModel->selectRow(0); setPatientDetail(mPatTable, mModel, patientDetailForm); - LOG_USER_OPERATION(DeletePatient) + LOG_USER_OPERATION(QString("Delete Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID)) } } else { //TODO:error handle @@ -166,7 +167,7 @@ void SelectFormWidget::delPatient() { void SelectFormWidget::selectPatient() { EventCenter::Default()->triggerEvent(PatientSelected, nullptr, patientDetailForm->getPatientInformation()->Copy()); selectedPatientUID = patientDetailForm->getPatientInformation()->PatientUID; - LOG_USER_OPERATION(SelectPatient) + LOG_USER_OPERATION(QString("Select Patient, ID: %1").arg(patientDetailForm->getPatientInformation()->ID)) } void SelectFormWidget::initDetailPanel(QHBoxLayout *contentLayout) {// prepare edit panel diff --git a/src/forms/settings/GeneralForm.cpp b/src/forms/settings/GeneralForm.cpp index 4a57ef1..cd99488 100644 --- a/src/forms/settings/GeneralForm.cpp +++ b/src/forms/settings/GeneralForm.cpp @@ -15,6 +15,7 @@ #include "utilities/LanguageSwitcher.h" #include "components/ULineEdit.h" #include "components/ListBox.h" +#include "log/UserOperationLog.h" namespace { @@ -101,6 +102,7 @@ GeneralForm::GeneralForm(QWidget* aParent) { if(DialogManager::Default()->requestAlertMessage(QString(tr("Shut down now ?")), DialogButtonMode::OkAndCancel,tr("Shut Down")) == QDialog::Accepted) { + LOG_USER_OPERATION("Shut Down") EventCenter::Default()->triggerEvent(GUIEvents::RequestShutdown, nullptr, nullptr); } }); @@ -134,6 +136,7 @@ GeneralForm::GeneralForm(QWidget* aParent) return; } second = result.ResultData.toInt(); + LOG_USER_OPERATION(QString("Set Screen Lock Time to %1 seconds").arg(second)) if(second == 0) { JsonObject::Instance()->setLockScreenTimeout(QString::number(second)); @@ -163,6 +166,7 @@ GeneralForm::GeneralForm(QWidget* aParent) JsonObject::Instance()->setDefaultLanguage(language); LanguageSwitcher::getInstance()->setDefaultLanguage(language); btnLan->setText(JsonObject::Instance()->defaultLanguage()); + LOG_USER_OPERATION(QString("Change Language to %1").arg(language)) } }); diff --git a/src/forms/settings/SettingFormWidget.cpp b/src/forms/settings/SettingFormWidget.cpp index bece12c..e4a0d3a 100644 --- a/src/forms/settings/SettingFormWidget.cpp +++ b/src/forms/settings/SettingFormWidget.cpp @@ -16,6 +16,7 @@ #include "AccountTableForm.h" #include "event/EventCenter.h" #include "AboutForm.h" +#include "UserOperationLogForm.h" SettingFormWidget::SettingFormWidget(QWidget* aParent, Qt::WindowFlags f) : TabFormWidget(aParent) @@ -27,7 +28,7 @@ SettingFormWidget::SettingFormWidget(QWidget* aParent, Qt::WindowFlags f) QListWidget* widget = new QListWidget(ui->contentWidget); widget->setFixedWidth(250); QStringList menus; - menus << tr("General") << tr("Account") << tr("System") << tr("About"); + menus << tr("General") << tr("Account") << tr("System") << tr("About") << tr("Operation Log"); widget->addItems(menus); widget->setSpacing(3); for (int i = 0; i < menus.count(); ++i) @@ -55,13 +56,16 @@ SettingFormWidget::SettingFormWidget(QWidget* aParent, Qt::WindowFlags f) AboutForm* about = new AboutForm(ui->commandWidget); stackedWidget->addWidget(about); + UserOperationLogForm* operationLog = new UserOperationLogForm(ui->commandWidget); + stackedWidget->addWidget(operationLog); + widget->setCurrentRow(0); connect(widget, &QListWidget::currentRowChanged, [=](int rowindex) { stackedWidget->setCurrentIndex(rowindex); }); connect(EventCenter::Default(), &EventCenter::ReloadLanguage, [=]() { QStringList menus; - menus << tr("General") << tr("Account") << tr("System") << tr("About"); + menus << tr("General") << tr("Account") << tr("System") << tr("About") << tr("Operation Log"); widget->clear(); widget->addItems(menus); for (int i = 0; i < menus.count(); ++i) diff --git a/src/json/jsonobject.cpp b/src/json/jsonobject.cpp index 6292538..e5c1a3f 100644 --- a/src/json/jsonobject.cpp +++ b/src/json/jsonobject.cpp @@ -549,3 +549,8 @@ bool JsonObject::isDmsSimulator() { return getBool("dms","simulator"); } + +int JsonObject::getOperationLogExpireDays() +{ + return QString(getJsonString("operatorlog", "expire")).toInt(); +} diff --git a/src/json/jsonobject.h b/src/json/jsonobject.h index da45504..2b7f73b 100644 --- a/src/json/jsonobject.h +++ b/src/json/jsonobject.h @@ -110,6 +110,7 @@ public: void setIpRouteList(const QList& list); QStringList getScreenSaverInfomation(); + int getOperationLogExpireDays(); private: diff --git a/src/log/LogFileTableModel.cpp b/src/log/LogFileTableModel.cpp index 0a81e19..9ee2546 100644 --- a/src/log/LogFileTableModel.cpp +++ b/src/log/LogFileTableModel.cpp @@ -12,6 +12,7 @@ LogFileTableModel::LogFileTableModel(QObject *parent) : QAbstractTableModel(pare } void LogFileTableModel::setFileName(QString fileName) { + beginResetModel(); if (!logdata.isEmpty())logdata.clear(); qDebug()< -#include #include "appvals/AppGlobalValues.h" #include "models/User.h" +#include + #include -#include +#include +#include - -const char * logDir = "./log"; +namespace +{ + const QString logDir = "./log"; +} void UserOperationLog::init() { QDir log_dir("./"); @@ -58,15 +61,13 @@ QString getOperationName(UserOperation operation) } -void UserOperationLog::log(UserOperation operation, bool processing) { +void UserOperationLog::log(const QString& aOperationText) +{ reloadFile(); QDateTime now = QDateTime::currentDateTime(); AppGlobalValues::setLastOperationTime(now); - AppGlobalValues::setLastOperation(operation); - QString operationName = getOperationName(operation); - AppGlobalValues::setInProcessing(processing); QString UserName = (!User::Current() || User::Current()->getUserCode().isEmpty())?"anonymous":User::Current()->getUserCode(); - out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<getOperationLogExpireDays(); + QDateTime currentDate = QDateTime::currentDateTime(); + QDateTime deleteDate = currentDate.addDays(-expireDays); + + QDir dir(logDir); + QStringList logFiles = dir.entryList(QStringList() << "*.log", QDir::Files); + for(const QString &logFile : logFiles) + { + QString filePath = logDir + "/" + logFile; + QFileInfo fileInfo(filePath); + QDateTime fileDate = fileInfo.created(); + if (fileDate <= deleteDate) + { + QFile::remove(filePath); + } + } +} diff --git a/src/log/UserOperationLog.h b/src/log/UserOperationLog.h index e9c2d94..ccdb111 100644 --- a/src/log/UserOperationLog.h +++ b/src/log/UserOperationLog.h @@ -19,7 +19,8 @@ ADD_OPERATION(ChangePatientInfo)\ ADD_OPERATION(DeletePatient)\ ADD_OPERATION(SelectPatient)\ ADD_OPERATION(StartRefresh)\ -ADD_OPERATION(Stop)\ +ADD_OPERATION(StopScan)\ +ADD_OPERATION(StopPreview)\ ADD_OPERATION(StartPreview)\ ADD_OPERATION(StartScan)\ ADD_OPERATION(ConfirmError)\ @@ -55,7 +56,7 @@ public: static QStringList getHistoryLogFiles(); - void log(UserOperation operation, bool processing = false); + void log(const QString& aOperationText); void reloadFile(); QString currentLogFile(){ return currentFileName; diff --git a/src/main.cpp b/src/main.cpp index 1b2199e..20431f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -96,6 +96,7 @@ int main(int argc, char* argv[]) QStringList app_args = a.arguments(); int ret = 0; KeyboardManager::getInstance(); + UserOperationLog::cleanHistoryLog(); if (app_args.contains("-d")) //if (true) diff --git a/src/windows/LoginDialog.cpp b/src/windows/LoginDialog.cpp index 6ce5ecd..ec22bd8 100644 --- a/src/windows/LoginDialog.cpp +++ b/src/windows/LoginDialog.cpp @@ -124,12 +124,13 @@ void LoginDialog::doLogin() { mErrorMessage->setVisible(false); accept(); - LOG_USER_OPERATION(Login); + LOG_USER_OPERATION("Login Sucessful"); JsonObject::Instance()->setDefaultUser(strUserCode); } else { + LOG_USER_OPERATION(QString("Login Failed, User Name: %1").arg(strUserCode)); mErrorMessage->setVisible(true); } }