From fcde59fa8bc6eb149f67d3c9cb7b6c8402031115 Mon Sep 17 00:00:00 2001 From: noberumotto Date: Sat, 17 Sep 2022 14:17:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=97=B6=E9=95=BF=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Core/Servicers/Instances/Data.cs | 83 +++++++++++------------------- Core/Servicers/Instances/Main.cs | 6 ++- Core/Servicers/Interfaces/IData.cs | 14 ++--- UI/Properties/AssemblyInfo.cs | 2 +- 4 files changed, 37 insertions(+), 68 deletions(-) diff --git a/Core/Servicers/Instances/Data.cs b/Core/Servicers/Instances/Data.cs index b678bf1..b359b07 100644 --- a/Core/Servicers/Instances/Data.cs +++ b/Core/Servicers/Instances/Data.cs @@ -19,7 +19,7 @@ namespace Core.Servicers.Instances { this.appData = appData; } - public void Set(string processName, string processDescription, string file, int seconds, DateTime? time_ = null) + public void Set(string processName, int seconds, DateTime? time_ = null) { DateTime time = !time_.HasValue ? DateTime.Now : time_.Value; var today = time.Date; @@ -31,7 +31,6 @@ namespace Core.Servicers.Instances { return; } - processDescription = processDescription == null ? string.Empty : processDescription; AppModel app = appData.GetApp(processName); @@ -70,6 +69,15 @@ namespace Core.Servicers.Instances if (hourslog == null) { // 没有时创建 + + if (seconds > 3600) + { + int overflowSeconds = seconds - 3600; + Set(processName, overflowSeconds, nowtime.AddHours(1)); + + seconds = 3600; + } + db.HoursLog.Add(new Models.HoursLogModel() { DataTime = nowtime, @@ -79,7 +87,18 @@ namespace Core.Servicers.Instances } else { - hourslog.Time += seconds; + if (hourslog.Time + seconds > 3600) + { + hourslog.Time = 3600; + + int overflowSeconds = hourslog.Time + seconds - 3600; + + Set(processName, overflowSeconds, nowtime.AddHours(1)); + } + else + { + hourslog.Time += seconds; + } } // 统计使用时长 @@ -91,6 +110,7 @@ namespace Core.Servicers.Instances } } + public List GetTodaylogList() { @@ -189,57 +209,6 @@ namespace Core.Servicers.Instances return GetDateRangelogList(weekStartDate, weekEndDate); } - public void Set(string processName, int seconds, DateTime? time_ = null) - { - DateTime time = !time_.HasValue ? DateTime.Now : time_.Value; - var today = time.Date; - - // 当前时段 - var nowtime = new DateTime(today.Year, today.Month, today.Day, time.Hour, 0, 0); - - if (string.IsNullOrEmpty(processName) || seconds <= 0) - { - return; - } - - AppModel app = appData.GetApp(processName); - if (app == null) - { - return; - } - - using (var db = new TaiDbContext()) - { - var res = db.DailyLog.SingleOrDefault(m => m.Date == today && m.AppModelID == app.ID); - if (res != null) - { - res.Time += seconds; - } - - // 分时段记录数据 - - var hourslog = db.HoursLog.SingleOrDefault( - m => - m.DataTime == nowtime - && m.AppModelID == app.ID); - if (hourslog != null) - { - hourslog.Time += seconds; - } - - - // 统计使用时长 - - app.TotalTime += seconds; - - appData.UpdateApp(app); - - - db.SaveChanges(); - } - - } - public List GetProcessMonthLogList(int appID, DateTime month) { //var app = appData.GetApp(processName); @@ -276,6 +245,12 @@ namespace Core.Servicers.Instances m.AppModelID == appID && m.Date.Year == month.Year && m.Date.Month == month.Month)); + + db.HoursLog.RemoveRange( + db.HoursLog.Where(m => m.AppModelID == appID + && m.DataTime.Year == month.Year + && m.DataTime.Month == month.Month)); + db.SaveChanges(); } } diff --git a/Core/Servicers/Instances/Main.cs b/Core/Servicers/Instances/Main.cs index ef99cbd..cad5bee 100644 --- a/Core/Servicers/Instances/Main.cs +++ b/Core/Servicers/Instances/Main.cs @@ -275,11 +275,13 @@ namespace Core.Servicers.Instances if (isCheck && sleepStatus != SleepStatus.Sleep) { + if (activeProcess == null) + { + activeStartTime = DateTime.Now; + } activeProcess = processName; activeProcessDescription = description; activeProcessFile = file; - - activeStartTime = DateTime.Now; } else { diff --git a/Core/Servicers/Interfaces/IData.cs b/Core/Servicers/Interfaces/IData.cs index e697f51..77c9a69 100644 --- a/Core/Servicers/Interfaces/IData.cs +++ b/Core/Servicers/Interfaces/IData.cs @@ -14,11 +14,9 @@ namespace Core.Servicers.Interfaces /// /// 设置进程数据 /// - /// - /// - /// - /// - void Set(string processName, string processDescription, string file, int seconds, DateTime? time = null); + /// 进程名称 + /// 时长(秒) + void Set(string processName, int seconds, DateTime? time = null); /// /// 获取今天的数据 @@ -43,12 +41,6 @@ namespace Core.Servicers.Interfaces /// /// IEnumerable GetLastWeeklogList(); - /// - /// 设置进程数据(仅通过进程名可能会出现重复的问题 - /// - /// - /// - void Set(string processName, int seconds, DateTime? time = null); /// /// 获取指定进程某个月的数据 diff --git a/UI/Properties/AssemblyInfo.cs b/UI/Properties/AssemblyInfo.cs index f524fca..f0f3cbd 100644 --- a/UI/Properties/AssemblyInfo.cs +++ b/UI/Properties/AssemblyInfo.cs @@ -51,5 +51,5 @@ using System.Windows; //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 //通过使用 "*",如下所示: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.4")] +[assembly: AssemblyVersion("1.0.0.5")] [assembly: AssemblyFileVersion("1.0.0.0")] -- GitLab