diff --git a/src/AccountFormDialog.cpp b/src/AccountFormDialog.cpp index 8ee0feb..81c4dad 100644 --- a/src/AccountFormDialog.cpp +++ b/src/AccountFormDialog.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include "db/SQLHelper.h" #include "models/User.h" AccountFormDialog::AccountFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { @@ -84,6 +85,7 @@ AccountFormDialog::AccountFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFo connect(btn_Logout, &QAbstractButton::clicked, [=](){ this->accept(); + LOG_USER_OPERATION(Logout); EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr); }); } @@ -96,5 +98,9 @@ bool AccountFormDialog::updateReferenceData() { if (!this->userNameChanged) return true; User::Current()->setUserName(m_NewUserName); bool ret = User::Current()->submitChange(); + if(ret) + { + LOG_USER_OPERATION(ChangeUserName); + } return ret; } diff --git a/src/ChangePasswordFormDialog.cpp b/src/ChangePasswordFormDialog.cpp index b2bebc1..0c53274 100644 --- a/src/ChangePasswordFormDialog.cpp +++ b/src/ChangePasswordFormDialog.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include "ChangePasswordFormDialog.h" ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) { @@ -87,5 +88,6 @@ bool ChangePasswordFormDialog::updateReferenceData() { User::Current()->restorePassword(encryptPwd); return false; } + LOG_USER_OPERATION(ChangePassword); return true; } diff --git a/src/ScanFormWidget.cpp b/src/ScanFormWidget.cpp index 00630be..6255303 100644 --- a/src/ScanFormWidget.cpp +++ b/src/ScanFormWidget.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #ifdef WIN32 #else @@ -209,21 +210,21 @@ ScanFormWidget::ScanFormWidget(QWidget *parent) : TabFormWidget(parent) { patient_information->setPatientInformation((PatientInformation*)data); }); connect(btnRefresh,&QToolButton::clicked,[=](){ - qDebug()<<"Get patient Json string start!"; QString patientInf(patient_information->getCurrentPatientJsonString(false)); - qDebug()<<"Get patient Json string end! string:"<triggerEvent(GUIEvents::RequestEmptyScan, nullptr, (QObject*)(&patientInf)); }); connect(btnPreview,&QToolButton::clicked,[=](){ + LOG_USER_OPERATION(StartPreview); EventCenter::Default()->triggerEvent(GUIEvents::RequestPreviewScan, nullptr, nullptr); }); connect(btnScan,&QToolButton::clicked,[=](){ - qDebug()<<"Get patient Json string start!"; QString patientInf(patient_information->getCurrentPatientJsonString(false)); - qDebug()<<"Get patient Json string end! string:"<triggerEvent(GUIEvents::RequestPatientScan, nullptr, (QObject*)(&patientInf)); }); connect(btnStop,&QToolButton::clicked,[=](){ + LOG_USER_OPERATION(Stop); EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr); }); diff --git a/src/SelectFormWidget.cpp b/src/SelectFormWidget.cpp index 0184d1d..33e4d0b 100644 --- a/src/SelectFormWidget.cpp +++ b/src/SelectFormWidget.cpp @@ -15,6 +15,7 @@ #include "event/EventCenter.h" #include "AccountFormDialog.h" #include +#include "log/UserOperationLog.h" #define ADD_CENTER_ITEM(row,col,text)\ item = new QTableWidgetItem(text);\ @@ -137,7 +138,8 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : }); connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){ int selectedRow = currentRow; - if (inf->PatientUID.isEmpty()) { + bool isAdd = inf->PatientUID.isEmpty(); + if (isAdd) { selectedRow = model->rowCount(); inf->PatientUID = QUuid::createUuid().toString(); printf(inf->PatientUID.toStdString().data()); @@ -155,6 +157,13 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : else{ //TODO:add some error handle logic } + if(isAdd){ + LOG_USER_OPERATION(AddPatient); + } + else + { + LOG_USER_OPERATION(ChangePatientInfo); + } btnSelect->setEnabled(true); }); @@ -170,11 +179,12 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : table->selectRow(0); model->selectRow(0); PatientInformation pat; - #define ADD_PATIENT_PROPERTY(val)\ - pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString(); + #define ADD_PATIENT_PROPERTY(val)\ + pat. val = model->data(model->index(0,PatientInformationEnum:: val)).toString(); EDIT_PATIENT() - #undef ADD_PATIENT_PROPERTY + #undef ADD_PATIENT_PROPERTY edit_patient->setPatientInformation(&pat); + LOG_USER_OPERATION(DeletePatient); } else{ currentRow=-1; } @@ -188,6 +198,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) : connect(btnSelect, &QToolButton::clicked,[=](){ if (currentRow<0)return; EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr,edit_patient->getPatientInformation()->Copy()); + LOG_USER_OPERATION(SelectPatient); }); connect(btnAccount, &QToolButton::clicked,[=](){ diff --git a/src/guimessagedialog.cpp b/src/guimessagedialog.cpp index 887ed6f..f938cf4 100644 --- a/src/guimessagedialog.cpp +++ b/src/guimessagedialog.cpp @@ -1,3 +1,4 @@ +#include "log/UserOperationLog.h" #include "guimessagedialog.h" #include "ui_guimessagedialog.h" #include "event/EventCenter.h" @@ -86,6 +87,7 @@ void GUIMessageDialog::showExitButton() { timerID = -1; } accept(); + LOG_USER_OPERATION(ConfirmError); }); } diff --git a/src/log/UserOperationLog.cpp b/src/log/UserOperationLog.cpp new file mode 100644 index 0000000..2cc9778 --- /dev/null +++ b/src/log/UserOperationLog.cpp @@ -0,0 +1,47 @@ +// +// Created by Krad on 2021/11/19. +// + +#include "UserOperationLog.h" +#include +#include +#include "appvals/AppGlobalValues.h" +#include "models/User.h" + + +void UserOperationLog::init() { + QDir log_dir("./"); + if (!log_dir.exists("./log")) log_dir.mkdir("log"); + currentFileName = "./log/" + QDate::currentDate().toString("yyyy-MM-dd")+QString("-op.log"); + logFile.setFileName(currentFileName); + if (logFile.exists()) + { + logFile.open(QFile::OpenModeFlag::Append | QFile::OpenModeFlag::Text); + } else{ + logFile.open(QFile::OpenModeFlag::NewOnly | QFile::OpenModeFlag::Text); + } + out.setDevice(&logFile); +} + +QString getOperationName(UserOperation operation) +{ + switch (operation) { + #define ADD_OPERATION(name)\ + case name: return #name; + USER_OPERATIONS() + #undef ADD_OPERATION + default: + return "unknow error"; + } + +} + +void UserOperationLog::log(UserOperation operation, bool processing) { + QDateTime now = QDateTime::currentDateTime(); + AppGlobalValues::setLastOperationTime(now); + AppGlobalValues::setLastOperation(operation); + QString operationName = getOperationName(operation); + AppGlobalValues::setInProcessing(processing); + QString UserName = User::Current()->getUserCode().isEmpty()?"anonymous":User::Current()->getUserCode(); + out << now.toString(Qt::DateFormat::ISODateWithMs)<<"\t"< +#include +#include + +#define USER_OPERATIONS()\ +ADD_OPERATION(Login)\ +ADD_OPERATION(Logout)\ +ADD_OPERATION(ChangePassword)\ +ADD_OPERATION(ChangeUserName)\ +ADD_OPERATION(AddPatient)\ +ADD_OPERATION(ChangePatientInfo)\ +ADD_OPERATION(DeletePatient)\ +ADD_OPERATION(SelectPatient)\ +ADD_OPERATION(StartRefresh)\ +ADD_OPERATION(Stop)\ +ADD_OPERATION(StartPreview)\ +ADD_OPERATION(StartScan)\ +ADD_OPERATION(ConfirmError)\ + +#define LOG_USER_OPERATION(...)\ +UserOperationLog::Default()->log(__VA_ARGS__); + + +enum UserOperation{ +#define ADD_OPERATION(name) name,\ + + USER_OPERATIONS() +#undef ADD_OPERATION +}; +class UserOperationLog { +public: + UserOperationLog(){} + ~UserOperationLog(){ + if (logFile.isOpen()) + { + logFile.flush(); + logFile.close(); + } + } + + void init(); + static UserOperationLog* Default(){ + static UserOperationLog d; + return &d; + } + void log(UserOperation operation, bool processing = false); + +private: + QString currentFileName; + QFile logFile; + QTextStream out; +}; + + +#endif //GUI_USEROPERATIONLOG_H diff --git a/src/loginwindow.cpp b/src/loginwindow.cpp index 701cfa1..9f059d6 100644 --- a/src/loginwindow.cpp +++ b/src/loginwindow.cpp @@ -11,8 +11,7 @@ #include "db/SQLHelper.h" #include "InputObject.h" #include "models/User.h" - -#define splitFlag QString("-") +#include "log/UserOperationLog.h" LoginWindow::LoginWindow(QWidget* parent) : QDialog(parent) @@ -111,14 +110,6 @@ void LoginWindow::init() void LoginWindow::initUserList() { - // userList = UserService::queryUserInfo(""); - // for (int i = 0; i < userList.count(); i++) - // { - // QString userCode = userList.at(i)->getUserCode(); - // //QString userName = userList.at(i)->getUserName(); - // //m_pUserCodeEdit->addItem(userCode + splitFlag + userName); - // m_pUserCodeEdit->addItem(userCode); - // } } void LoginWindow::clearInputData() @@ -144,38 +135,14 @@ void LoginWindow::doLogin() QString sql = QString("select UserCode from Account where UserCode='%1' and Password='%2'") .arg(strUserCode).arg(encryptPwd); if(User::QueryUser(strUserCode,encryptPwd)) -// if (SQLHelper::QueryCount(sql) > 0) { accept(); + LOG_USER_OPERATION(Login); } else { warn->setVisible(true); } - // bool isLoginSuccess = UserService::ValidateAccount(strUserCode, encryptedPassword); - // if (isLoginSuccess) - // { - // accept(); - // emit sigUserLoginSuccessful(strUserCode); - // } - // else - // { - // EQ9MessageBox box; - // box.setMessage(tr("login failed, please check input data")); - // box.exec(); - // return; - // } + } -//void LoginWindow::onUserCodeFocusOut(QFocusEvent* e) -//{ -// Q_UNUSED(e); -// -// QString wholeText = m_pUserCodeEdit->currentText(); -// int flagPosition = wholeText.indexOf(splitFlag); -// if(flagPosition > 0) -// { -// QString userCode = wholeText.left(flagPosition); -// m_pUserCodeEdit->setCurrentText(userCode); -// } -//} diff --git a/src/main.cpp b/src/main.cpp index 8766922..6a91815 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,7 @@ #include #include #include +#include "log/UserOperationLog.h" QString loadFontFromFile(QString path) { @@ -54,6 +55,7 @@ int main(int argc, char* argv[]) InputObject* obj = new InputObject(); a.installEventFilter(obj); SQLHelper::Open(); + UserOperationLog::Default()->init(); MainWindow w;