From 6cb18541abd700ae1ecc9191ea0536a4c70a3c98 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=A9=AC=E5=B7=A7?= <625215135@qq.com>
Date: Mon, 13 Oct 2025 10:19:04 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=93=E5=86=8C=E6=8A=A5?=
=?UTF-8?q?=E8=A1=A8=E4=B8=AD=E2=80=9D=E9=97=A8=E8=AF=8A=E5=8F=B7/?=
=?UTF-8?q?=E4=BD=8F=E9=99=A2=E5=8F=B7=E2=80=9C=E5=AD=97=E6=AE=B5=E5=8F=96?=
=?UTF-8?q?=E5=80=BC=E7=94=B1order=5Finfo=E4=B8=AD=E7=9A=84patient=5Fno?=
=?UTF-8?q?=E6=94=B9=E4=B8=BApatient=5Fid.=E4=BF=AE=E6=94=B9=E8=87=AA?=
=?UTF-8?q?=E5=8A=A8=E9=80=80=E5=87=BA?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
DM_Weight/App.config | 2 +-
DM_Weight/Report/GridReportUtil.cs | 2 +-
DM_Weight/ViewModels/HomeWindowViewModel.cs | 64 +++++++++++++++------
DM_Weight/util/CheckComputerFreeState.cs | 27 +++++++--
4 files changed, 73 insertions(+), 22 deletions(-)
diff --git a/DM_Weight/App.config b/DM_Weight/App.config
index f365411..8763c2e 100644
--- a/DM_Weight/App.config
+++ b/DM_Weight/App.config
@@ -37,7 +37,7 @@
-
+
diff --git a/DM_Weight/Report/GridReportUtil.cs b/DM_Weight/Report/GridReportUtil.cs
index 534b032..70262a6 100644
--- a/DM_Weight/Report/GridReportUtil.cs
+++ b/DM_Weight/Report/GridReportUtil.cs
@@ -450,7 +450,7 @@ namespace DM_Weight.Report
string p_machine_id = (ConfigurationManager.AppSettings["machineId"] ?? "DM1");
string SQL = $@" SELECT ac.create_time as operationTime, ac.manu_no as manuNo,
ac.eff_date as effDate,ac.department as dept,oi.p_name as pName,oi.sex as sex,oi.age as age,oi.id_number as idNumber,
- oi.patient_no as zyh,'' mkh,oi.disease as disease,ac.out_quantity as outQuantity,od.empty_bottle_batch as ftph,oi.doctor_name as doctorName,oi.order_no as orderNo,od.empty_bottle_submitter kptjr,
+ oi.patient_id as zyh,'' mkh,oi.disease as disease,ac.out_quantity as outQuantity,od.empty_bottle_batch as ftph,oi.doctor_name as doctorName,oi.order_no as orderNo,od.empty_bottle_submitter kptjr,
di.drug_id as drugId,di.drug_name as drugName,di.drug_spec as drugSpec,di.big_unit AS bigUnit,u1.user_name as operatorName,u2.user_name as reviewerName,db.baseQuantity
FROM account_book_g2 ac inner join order_info oi on ac.invoice_no=oi.order_no inner join order_detail od on oi.order_no=od.order_no
left join drug_info di on ac.drug_id=di.drug_id left join drug_base db on di.drug_id=db.DrugId and db.machine_id='DM1'
diff --git a/DM_Weight/ViewModels/HomeWindowViewModel.cs b/DM_Weight/ViewModels/HomeWindowViewModel.cs
index ccff892..2fd0d71 100644
--- a/DM_Weight/ViewModels/HomeWindowViewModel.cs
+++ b/DM_Weight/ViewModels/HomeWindowViewModel.cs
@@ -467,28 +467,60 @@ namespace DM_Weight.ViewModels
int stopRecord = Convert.ToInt32(ConfigurationManager.AppSettings["stopRecord"] ?? "0");
if (autoExit > 0)
{
- System.Timers.Timer timer = new System.Timers.Timer();
- timer.Interval = 1000;
- timer.Elapsed += (sender, e) =>
+ logger.Info("启动自动退出检测");
+ //int interval = autoExit * 1000;
+ new PromiseUtil().taskAsyncLoop(1, 0, async (options, next, stop) =>
{
- // 串口无人操作
- if (!_portUtil.Operate)
+ try
{
- // 30秒内无人操作鼠标键盘
- if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
+ if (!_portUtil.Operate)
{
- logger.Info($"设备30秒内无人操作,用户【{Operator?.Nickname}】自动退出登录");
- Operator = null;
- Reviewer = null;
- Application.Current.Dispatcher.Invoke(() =>
+ // 无人操作鼠标键盘
+ if ((DateTime.Now - _portUtil.dateTime).TotalSeconds > autoExit && CheckComputerFreeState.GetLastInputTime() > autoExit)
{
- _regionManager.RequestNavigate("MainRegion", "LoginWindow");
- timer.Stop();
- });
+ logger.Info($"设备{autoExit}内无人操作,用户【{Operator?.Nickname}】自动退出登录,_portUtil.Operate:{_portUtil.Operate},totalSecond:{(DateTime.Now - _portUtil.dateTime).TotalSeconds},lastInputTime:{CheckComputerFreeState.GetLastInputTime()},autoExit:{autoExit}");
+
+ Operator = null;
+ Reviewer = null;
+ //Application.Current.Dispatcher.Invoke(() =>
+ //{
+ stop();
+ System.Windows.Application.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Send, new Action(() =>
+ {
+ if (DialogHost.IsDialogOpen("RootDialog"))
+ {
+ DialogHost.Close("RootDialog");
+ }
+ _regionManager.RequestNavigate("MainRegion", "LoginWindow");
+ }));
+ //});
+ //timer.Dispose();
+ }
+ else
+ {
+ if (Operator == null)
+ {
+ logger.Info("自动退出检测已停止");
+ stop();
+ }
+ else
+ {
+ logger.Info($"停止操作时间{_portUtil.dateTime},自动退出时间{autoExit},运算结果{(DateTime.Now - _portUtil.dateTime).TotalSeconds},用户上次使用系统到现在的时间间隔{CheckComputerFreeState.GetLastInputTime()}");
+ next();
+ }
+ }
+ }
+ else
+ {
+ _portUtil.dateTime = DateTime.Now;
+ next();
}
}
- };
- timer.Start();
+ catch (Exception ex)
+ {
+ logger.Info($"自动退出异常:{ex.Message}");
+ }
+ });
}
//if (stopRecord > 0)
//{
diff --git a/DM_Weight/util/CheckComputerFreeState.cs b/DM_Weight/util/CheckComputerFreeState.cs
index 1c3f789..853be48 100644
--- a/DM_Weight/util/CheckComputerFreeState.cs
+++ b/DM_Weight/util/CheckComputerFreeState.cs
@@ -1,4 +1,6 @@
-using System;
+using log4net;
+using log4net.Repository.Hierarchy;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
@@ -9,6 +11,7 @@ namespace DM_Weight.util
{
public class CheckComputerFreeState
{
+ private static readonly ILog logger = LogManager.GetLogger(typeof(CheckComputerFreeState));
///
/// 创建结构体用于返回捕获时间
///
@@ -44,9 +47,25 @@ namespace DM_Weight.util
}
else
{
- var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime;
- var icount = count / 1000;
- return icount;
+ //var count = (Environment.TickCount & Int32.MaxValue) - (long)vLastInputInfo.dwTime;
+ //var icount = count / 1000;
+ //return icount;
+
+ // 使用 64 位 TickCount 避免回绕问题
+ long currentTick = Environment.TickCount64;
+ long lastInputTick = vLastInputInfo.dwTime;
+
+ logger.Info($"获取用户未操作时间间隔{currentTick}-{lastInputTick}");
+ // 处理可能的回绕(虽然使用 64 位后极不可能发生)
+ if (currentTick < lastInputTick)
+ {
+ // 发生了回绕,调整计算
+ lastInputTick -= uint.MaxValue + 1L;
+ }
+ long elapsedMilliseconds = currentTick - lastInputTick;
+ long seconds = elapsedMilliseconds / 1000;
+ logger.Info($"获取用户未操作时间间隔{currentTick}-{lastInputTick}-{elapsedMilliseconds}-{seconds}-{Math.Max(0, seconds)}");
+ return Math.Max(0, seconds);
}
}
}