|
|
@@ -1,12 +1,19 @@
|
|
|
#include "processthread.h"
|
|
|
+#include "api/configapi.h"
|
|
|
#include "appevent.h"
|
|
|
#include "processmodel.h"
|
|
|
#include "qjsonarray.h"
|
|
|
#include "qjsonobject.h"
|
|
|
#include <cwf/sqldatabasestorage.h>
|
|
|
+#include <optional>
|
|
|
|
|
|
#include "api/processapi.h"
|
|
|
#include "qjsonvalue.h"
|
|
|
+#include "qlist.h"
|
|
|
+#include "qmessagebox.h"
|
|
|
+#include "qnamespace.h"
|
|
|
+
|
|
|
+#include "basemainTr.h"
|
|
|
|
|
|
CWF::SqlDatabaseStorage storage("QSQLITE", "localhost", "postgres", "postgres", "1234", 5432);
|
|
|
|
|
|
@@ -25,8 +32,32 @@ static qint64 fileTimeToUnixTimestamp(FILETIME ft)
|
|
|
}
|
|
|
return ull.QuadPart / 10000000LL;
|
|
|
}
|
|
|
+QString convertSecondsToTimeFormat(int totalSeconds)
|
|
|
+{
|
|
|
+ int days = totalSeconds / (24 * 3600); // 计算天数
|
|
|
+ int hours = (totalSeconds % (24 * 3600)) / 3600; // 计算小时
|
|
|
+ int minutes = (totalSeconds % 3600) / 60; // 计算分钟
|
|
|
+ int seconds = totalSeconds % 60; // 计算秒数
|
|
|
|
|
|
-void sendExitTime(qint64 updataTime)
|
|
|
+ // 返回格式化后的字符串,并使用 tr() 标记可翻译的文本
|
|
|
+ return QString(Tr::tr("%1days%2hours%3minutes%4seconds"))
|
|
|
+ .arg(days)
|
|
|
+ .arg(hours)
|
|
|
+ .arg(minutes)
|
|
|
+ .arg(seconds);
|
|
|
+}
|
|
|
+///
|
|
|
+/// \brief 转换到分钟
|
|
|
+/// \param totalSeconds
|
|
|
+/// \return
|
|
|
+///
|
|
|
+QString convertSecondsToMinutesTimeFormat(int totalSeconds)
|
|
|
+{
|
|
|
+ // 只计算分钟
|
|
|
+ int minutes = totalSeconds / 60;
|
|
|
+ return QString::number(minutes);
|
|
|
+}
|
|
|
+void ProcessThread::sendExitTime(qint64 updataTime)
|
|
|
{
|
|
|
ProcessModel processModel{storage};
|
|
|
// 在数据库 获取 不是这个更新日期的数据
|
|
|
@@ -77,8 +108,67 @@ void sendExitTime(qint64 updataTime)
|
|
|
time = timeVariant.toLongLong();
|
|
|
} else {
|
|
|
// 服务器时间
|
|
|
+ TC::ConfigApi configApi("swrunTime");
|
|
|
+ std::optional<QVariant> value = configApi.get();
|
|
|
+ if (value.has_value()) {
|
|
|
+ time = value.value().toInt();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QVariant messageBoxPointX = QVariant();
|
|
|
+ QVariant messageBoxPointY = QVariant();
|
|
|
+ QVariant messageText = QVariant("");
|
|
|
+ QVariant messageTitle = QVariant(Tr::tr("Tips"));
|
|
|
+ {
|
|
|
+ TC::ConfigApi configApi("messageBoxPointX");
|
|
|
+ std::optional<QVariant> value = configApi.get();
|
|
|
+ if (value.has_value()) {
|
|
|
+ messageBoxPointX = value.value().toInt();
|
|
|
+ }
|
|
|
}
|
|
|
+ {
|
|
|
+ TC::ConfigApi configApi("messageBoxPointY");
|
|
|
+ std::optional<QVariant> value = configApi.get();
|
|
|
+ if (value.has_value()) {
|
|
|
+ messageBoxPointY = value.value().toInt();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ TC::ConfigApi configApi("messageText");
|
|
|
+ std::optional<QVariant> value = configApi.get();
|
|
|
+ if (value.has_value()) {
|
|
|
+ messageText = value.value().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ {
|
|
|
+ TC::ConfigApi configApi("messageTitle");
|
|
|
+ std::optional<QVariant> value = configApi.get();
|
|
|
+ if (value.has_value()) {
|
|
|
+ messageTitle = value.value().toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ QMap<QString, QString> messageProcessName;
|
|
|
|
|
|
+ TC::ProcessNameApi processNameApi;
|
|
|
+ QJsonArray array = processNameApi.get();
|
|
|
+ for (const auto item : array) {
|
|
|
+ if (item.isObject()) {
|
|
|
+ const auto object = item.toObject();
|
|
|
+
|
|
|
+ const QString name = object["name"].toString();
|
|
|
+ const QString zhName = object["chinese_name"].toString();
|
|
|
+ if (object.contains("is_prompt")) {
|
|
|
+ if (object["is_prompt"].toInt() == 2) {
|
|
|
+ messageProcessName[name] = zhName;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // messageProcessName["WeChat.exe"] = "WeChat.exe";
|
|
|
+
|
|
|
+ // 提示
|
|
|
+ // SELECT * FROM ProcessTime WHERE (updataTime - lastAlertTime) > 1565;
|
|
|
if (time > 0) {
|
|
|
CWF::SqlQueryManager qry(storage);
|
|
|
qry.select("*", processModel.getTableName())
|
|
|
@@ -86,9 +176,46 @@ void sendExitTime(qint64 updataTime)
|
|
|
qry.prepare();
|
|
|
QJsonObject jsonObject = qry.exec();
|
|
|
QJsonArray jsonArray = qry.toJson();
|
|
|
+
|
|
|
+ const QStringList keys = messageProcessName.keys();
|
|
|
+
|
|
|
+ for (const auto &value : jsonArray) {
|
|
|
+ // SLDWORKS.exe
|
|
|
+
|
|
|
+ const QJsonObject object = value.toObject();
|
|
|
+ const QString processName = object["processName"].toString();
|
|
|
+ const qint64 runTime = object["exitTime"].toVariant().toLongLong()
|
|
|
+ - object["creationTime"].toVariant().toLongLong();
|
|
|
+
|
|
|
+ for (const QString &key : keys) {
|
|
|
+ if (processName.compare(key, Qt::CaseSensitivity::CaseInsensitive) == 0) {
|
|
|
+ // QVariant messageBoxPointX = QVariant();
|
|
|
+ // QVariant messageBoxPointY = QVariant();
|
|
|
+ // QVariant messageText = QVariant("");
|
|
|
+ // QVariant messageTitle = QVariant(Tr::tr("Tips"));
|
|
|
+ // Program A has been used for 20 minutes, please exercise
|
|
|
+
|
|
|
+ // const QString text = QString(tr("program %1 %3 run time :%2")
|
|
|
+ // .arg(messageProcessName[key])
|
|
|
+ // .arg(convertSecondsToTimeFormat(runTime))
|
|
|
+ // .arg(messageText.toString()));
|
|
|
+
|
|
|
+ const QString text = QString(tr("Program %1 has been used for %2 minutes%3")
|
|
|
+ .arg(messageProcessName[key])
|
|
|
+ .arg(convertSecondsToMinutesTimeFormat(runTime))
|
|
|
+ .arg(messageText.toString()));
|
|
|
+ emit messageBox(text, messageBoxPointX, messageBoxPointY, messageTitle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新 lastAlertTime
|
|
|
+ ProcessModel processModel{storage};
|
|
|
+ processModel.buildFromJson(object);
|
|
|
+ // 更新 消息时间
|
|
|
+ processModel.setLastAlertTime(updataTime);
|
|
|
+ processModel.save();
|
|
|
+ }
|
|
|
}
|
|
|
- // 提示
|
|
|
- // SELECT * FROM ProcessTime WHERE (updataTime - lastAlertTime) > 1565;
|
|
|
}
|
|
|
|
|
|
bool ProcessThread::upDataProcessSql()
|
|
|
@@ -137,7 +264,7 @@ bool ProcessThread::upDataProcessSql()
|
|
|
processModel.save();
|
|
|
}
|
|
|
}
|
|
|
- qDebug().noquote().nospace() << jsonObject << qry.toJson();
|
|
|
+ // qDebug().noquote().nospace() << jsonObject << qry.toJson();
|
|
|
|
|
|
// jsonObject.insert("begin_time", object["creationTime"]);
|
|
|
// jsonObject.insert("end_time", object["exitTime"]);
|