User operation log, v1
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLineEdit>
|
#include <QLineEdit>
|
||||||
#include <src/event/EventCenter.h>
|
#include <src/event/EventCenter.h>
|
||||||
|
#include <src/log/UserOperationLog.h>
|
||||||
#include "db/SQLHelper.h"
|
#include "db/SQLHelper.h"
|
||||||
#include "models/User.h"
|
#include "models/User.h"
|
||||||
AccountFormDialog::AccountFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
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, [=](){
|
connect(btn_Logout, &QAbstractButton::clicked, [=](){
|
||||||
this->accept();
|
this->accept();
|
||||||
|
LOG_USER_OPERATION(Logout);
|
||||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr);
|
EventCenter::Default()->triggerEvent(GUIEvents::RequestLogin, nullptr, nullptr);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -96,5 +98,9 @@ bool AccountFormDialog::updateReferenceData() {
|
|||||||
if (!this->userNameChanged) return true;
|
if (!this->userNameChanged) return true;
|
||||||
User::Current()->setUserName(m_NewUserName);
|
User::Current()->setUserName(m_NewUserName);
|
||||||
bool ret = User::Current()->submitChange();
|
bool ret = User::Current()->submitChange();
|
||||||
|
if(ret)
|
||||||
|
{
|
||||||
|
LOG_USER_OPERATION(ChangeUserName);
|
||||||
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QtWidgets/QLineEdit>
|
#include <QtWidgets/QLineEdit>
|
||||||
#include <src/models/User.h>
|
#include <src/models/User.h>
|
||||||
|
#include <src/log/UserOperationLog.h>
|
||||||
#include "ChangePasswordFormDialog.h"
|
#include "ChangePasswordFormDialog.h"
|
||||||
|
|
||||||
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
ChangePasswordFormDialog::ChangePasswordFormDialog(QWidget *parent, Qt::WindowFlags f) : GUIFormBaseDialog(parent, f) {
|
||||||
@@ -87,5 +88,6 @@ bool ChangePasswordFormDialog::updateReferenceData() {
|
|||||||
User::Current()->restorePassword(encryptPwd);
|
User::Current()->restorePassword(encryptPwd);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
LOG_USER_OPERATION(ChangePassword);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <qdebug.h>
|
#include <qdebug.h>
|
||||||
|
#include <src/log/UserOperationLog.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#else
|
#else
|
||||||
@@ -209,21 +210,21 @@ ScanFormWidget::ScanFormWidget(QWidget *parent) : TabFormWidget(parent) {
|
|||||||
patient_information->setPatientInformation((PatientInformation*)data);
|
patient_information->setPatientInformation((PatientInformation*)data);
|
||||||
});
|
});
|
||||||
connect(btnRefresh,&QToolButton::clicked,[=](){
|
connect(btnRefresh,&QToolButton::clicked,[=](){
|
||||||
qDebug()<<"Get patient Json string start!";
|
|
||||||
QString patientInf(patient_information->getCurrentPatientJsonString(false));
|
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));
|
EventCenter::Default()->triggerEvent(GUIEvents::RequestEmptyScan, nullptr, (QObject*)(&patientInf));
|
||||||
});
|
});
|
||||||
connect(btnPreview,&QToolButton::clicked,[=](){
|
connect(btnPreview,&QToolButton::clicked,[=](){
|
||||||
|
LOG_USER_OPERATION(StartPreview);
|
||||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestPreviewScan, nullptr, nullptr);
|
EventCenter::Default()->triggerEvent(GUIEvents::RequestPreviewScan, nullptr, nullptr);
|
||||||
});
|
});
|
||||||
connect(btnScan,&QToolButton::clicked,[=](){
|
connect(btnScan,&QToolButton::clicked,[=](){
|
||||||
qDebug()<<"Get patient Json string start!";
|
|
||||||
QString patientInf(patient_information->getCurrentPatientJsonString(false));
|
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));
|
EventCenter::Default()->triggerEvent(GUIEvents::RequestPatientScan, nullptr, (QObject*)(&patientInf));
|
||||||
});
|
});
|
||||||
connect(btnStop,&QToolButton::clicked,[=](){
|
connect(btnStop,&QToolButton::clicked,[=](){
|
||||||
|
LOG_USER_OPERATION(Stop);
|
||||||
EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr);
|
EventCenter::Default()->triggerEvent(GUIEvents::RequestStop, nullptr, nullptr);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
#include "event/EventCenter.h"
|
#include "event/EventCenter.h"
|
||||||
#include "AccountFormDialog.h"
|
#include "AccountFormDialog.h"
|
||||||
#include <qDebug>
|
#include <qDebug>
|
||||||
|
#include "log/UserOperationLog.h"
|
||||||
|
|
||||||
#define ADD_CENTER_ITEM(row,col,text)\
|
#define ADD_CENTER_ITEM(row,col,text)\
|
||||||
item = new QTableWidgetItem(text);\
|
item = new QTableWidgetItem(text);\
|
||||||
@@ -137,7 +138,8 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
});
|
});
|
||||||
connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){
|
connect(edit_patient, &EditPatientForm::editAccept,[=](PatientInformation* inf){
|
||||||
int selectedRow = currentRow;
|
int selectedRow = currentRow;
|
||||||
if (inf->PatientUID.isEmpty()) {
|
bool isAdd = inf->PatientUID.isEmpty();
|
||||||
|
if (isAdd) {
|
||||||
selectedRow = model->rowCount();
|
selectedRow = model->rowCount();
|
||||||
inf->PatientUID = QUuid::createUuid().toString();
|
inf->PatientUID = QUuid::createUuid().toString();
|
||||||
printf(inf->PatientUID.toStdString().data());
|
printf(inf->PatientUID.toStdString().data());
|
||||||
@@ -155,6 +157,13 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
else{
|
else{
|
||||||
//TODO:add some error handle logic
|
//TODO:add some error handle logic
|
||||||
}
|
}
|
||||||
|
if(isAdd){
|
||||||
|
LOG_USER_OPERATION(AddPatient);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
LOG_USER_OPERATION(ChangePatientInfo);
|
||||||
|
}
|
||||||
btnSelect->setEnabled(true);
|
btnSelect->setEnabled(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -175,6 +184,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
EDIT_PATIENT()
|
EDIT_PATIENT()
|
||||||
#undef ADD_PATIENT_PROPERTY
|
#undef ADD_PATIENT_PROPERTY
|
||||||
edit_patient->setPatientInformation(&pat);
|
edit_patient->setPatientInformation(&pat);
|
||||||
|
LOG_USER_OPERATION(DeletePatient);
|
||||||
} else{
|
} else{
|
||||||
currentRow=-1;
|
currentRow=-1;
|
||||||
}
|
}
|
||||||
@@ -188,6 +198,7 @@ SelectFormWidget::SelectFormWidget(QWidget *parent) :
|
|||||||
connect(btnSelect, &QToolButton::clicked,[=](){
|
connect(btnSelect, &QToolButton::clicked,[=](){
|
||||||
if (currentRow<0)return;
|
if (currentRow<0)return;
|
||||||
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr,edit_patient->getPatientInformation()->Copy());
|
EventCenter::Default()->triggerEvent(GUIEvents::PatientSelected, nullptr,edit_patient->getPatientInformation()->Copy());
|
||||||
|
LOG_USER_OPERATION(SelectPatient);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(btnAccount, &QToolButton::clicked,[=](){
|
connect(btnAccount, &QToolButton::clicked,[=](){
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "log/UserOperationLog.h"
|
||||||
#include "guimessagedialog.h"
|
#include "guimessagedialog.h"
|
||||||
#include "ui_guimessagedialog.h"
|
#include "ui_guimessagedialog.h"
|
||||||
#include "event/EventCenter.h"
|
#include "event/EventCenter.h"
|
||||||
@@ -86,6 +87,7 @@ void GUIMessageDialog::showExitButton() {
|
|||||||
timerID = -1;
|
timerID = -1;
|
||||||
}
|
}
|
||||||
accept();
|
accept();
|
||||||
|
LOG_USER_OPERATION(ConfirmError);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
src/log/UserOperationLog.cpp
Normal file
47
src/log/UserOperationLog.cpp
Normal 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;
|
||||||
|
}
|
||||||
62
src/log/UserOperationLog.h
Normal file
62
src/log/UserOperationLog.h
Normal 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
|
||||||
@@ -11,8 +11,7 @@
|
|||||||
#include "db/SQLHelper.h"
|
#include "db/SQLHelper.h"
|
||||||
#include "InputObject.h"
|
#include "InputObject.h"
|
||||||
#include "models/User.h"
|
#include "models/User.h"
|
||||||
|
#include "log/UserOperationLog.h"
|
||||||
#define splitFlag QString("-")
|
|
||||||
|
|
||||||
LoginWindow::LoginWindow(QWidget* parent)
|
LoginWindow::LoginWindow(QWidget* parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
@@ -111,14 +110,6 @@ void LoginWindow::init()
|
|||||||
|
|
||||||
void LoginWindow::initUserList()
|
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()
|
void LoginWindow::clearInputData()
|
||||||
@@ -144,38 +135,14 @@ void LoginWindow::doLogin()
|
|||||||
QString sql = QString("select UserCode from Account where UserCode='%1' and Password='%2'")
|
QString sql = QString("select UserCode from Account where UserCode='%1' and Password='%2'")
|
||||||
.arg(strUserCode).arg(encryptPwd);
|
.arg(strUserCode).arg(encryptPwd);
|
||||||
if(User::QueryUser(strUserCode,encryptPwd))
|
if(User::QueryUser(strUserCode,encryptPwd))
|
||||||
// if (SQLHelper::QueryCount(sql) > 0)
|
|
||||||
{
|
{
|
||||||
accept();
|
accept();
|
||||||
|
LOG_USER_OPERATION(Login);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
warn->setVisible(true);
|
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);
|
|
||||||
// }
|
|
||||||
//}
|
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include "log/UserOperationLog.h"
|
||||||
|
|
||||||
QString loadFontFromFile(QString path)
|
QString loadFontFromFile(QString path)
|
||||||
{
|
{
|
||||||
@@ -54,6 +55,7 @@ int main(int argc, char* argv[])
|
|||||||
InputObject* obj = new InputObject();
|
InputObject* obj = new InputObject();
|
||||||
a.installEventFilter(obj);
|
a.installEventFilter(obj);
|
||||||
SQLHelper::Open();
|
SQLHelper::Open();
|
||||||
|
UserOperationLog::Default()->init();
|
||||||
MainWindow w;
|
MainWindow w;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user