Add UserOperationLog.
This commit is contained in:
@@ -12,6 +12,7 @@ LogFileTableModel::LogFileTableModel(QObject *parent) : QAbstractTableModel(pare
|
||||
}
|
||||
|
||||
void LogFileTableModel::setFileName(QString fileName) {
|
||||
beginResetModel();
|
||||
if (!logdata.isEmpty())logdata.clear();
|
||||
qDebug()<<fileName;
|
||||
QFile f;
|
||||
@@ -25,6 +26,7 @@ void LogFileTableModel::setFileName(QString fileName) {
|
||||
logdata.push_back(in.readLine().split("\t"));
|
||||
}
|
||||
}
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
QVariant LogFileTableModel::data(const QModelIndex &index, int role) const {
|
||||
|
||||
@@ -3,15 +3,18 @@
|
||||
//
|
||||
|
||||
#include "UserOperationLog.h"
|
||||
#include <QDate>
|
||||
#include <QDir>
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "models/User.h"
|
||||
#include <json/jsonobject.h>
|
||||
|
||||
#include <QDirIterator>
|
||||
#include <qdebug.h>
|
||||
#include <QDate>
|
||||
#include <QDir>
|
||||
|
||||
|
||||
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"<<UserName<<"\t"<<operationName<<endl;
|
||||
out << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<UserName<<"\t"<<aOperationText<<endl;
|
||||
}
|
||||
|
||||
void UserOperationLog::reloadFile() {
|
||||
@@ -91,7 +92,6 @@ QStringList UserOperationLog::getHistoryLogFiles() {
|
||||
{
|
||||
iter.next();
|
||||
list << iter.fileInfo().absoluteFilePath();
|
||||
qDebug()<<iter.fileInfo().absoluteFilePath();
|
||||
}
|
||||
return list;
|
||||
}
|
||||
@@ -109,3 +109,23 @@ void UserOperationLog::loadLogFromFile(QString path, QStringList& result) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void UserOperationLog::cleanHistoryLog()
|
||||
{
|
||||
int expireDays = JsonObject::Instance()->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user