User operation log, v1

This commit is contained in:
Krad
2021-11-19 15:36:12 +08:00
parent bca10e3e60
commit 99754ab84f
9 changed files with 144 additions and 44 deletions

View File

@@ -9,6 +9,7 @@
#include <QPushButton>
#include <QLineEdit>
#include <src/event/EventCenter.h>
#include <src/log/UserOperationLog.h>
#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;
}

View File

@@ -6,6 +6,7 @@
#include <QLabel>
#include <QtWidgets/QLineEdit>
#include <src/models/User.h>
#include <src/log/UserOperationLog.h>
#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;
}

View File

@@ -14,6 +14,7 @@
#include <QImage>
#include <QPainter>
#include <qdebug.h>
#include <src/log/UserOperationLog.h>
#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:"<<patientInf;
LOG_USER_OPERATION(StartRefresh);
EventCenter::Default()->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:"<<patientInf;
LOG_USER_OPERATION(StartScan);
EventCenter::Default()->triggerEvent(GUIEvents::RequestPatientScan, nullptr, (QObject*)(&patientInf));
});
connect(btnStop,&QToolButton::clicked,[=](){
LOG_USER_OPERATION(Stop);
EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr);
});

View File

@@ -15,6 +15,7 @@
#include "event/EventCenter.h"
#include "AccountFormDialog.h"
#include <qDebug>
#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);
});
@@ -175,6 +184,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
EDIT_PATIENT()
#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,[=](){

View File

@@ -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);
});
}

View File

@@ -0,0 +1,47 @@
//
// Created by Krad on 2021/11/19.
//
#include "UserOperationLog.h"
#include <QDate>
#include <QDir>
#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"<<UserName<<"\t"<<operationName<<endl;
}

View File

@@ -0,0 +1,62 @@
//
// Created by Krad on 2021/11/19.
//
#ifndef GUI_USEROPERATIONLOG_H
#define GUI_USEROPERATIONLOG_H
#include <QDateTime>
#include <QFile>
#include <QTextStream>
#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

View File

@@ -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);
// }
//}

View File

@@ -9,6 +9,7 @@
#include <QDebug>
#include <QThread>
#include <QTimer>
#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;