From 1671840ca676ddd79a484f17f6f149e3ef7e423e Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Tue, 1 Apr 2025 16:22:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=95=E4=B8=AA=E9=99=84=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E5=AD=A6=E4=B9=A0=E6=97=B6=E9=95=BF=E6=9C=80?= =?UTF-8?q?=E5=A4=9A=E4=B8=8D=E8=B6=85=E8=BF=87=E9=99=84=E4=BB=B6=E8=AE=BE?= =?UTF-8?q?=E5=AE=9A=E6=97=B6=E9=95=BF=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ghre/Ghre_StudyRecordServices.cs | 30 ++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index 16b73fb3..c702131e 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -1687,10 +1687,23 @@ WHERE A.Id = '{id}'"; //var sql = $"UPDATE Ghre_StudyRecord SET StudyDuration = ISNULL(StudyDuration, 0)+{duration} WHERE Id='{studyRecordId}' AND StaffId='{staffId}'"; //await Db.Ado.ExecuteCommandAsync(sql); - await Db.Updateable() - .SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true) - .Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId) - .ExecuteCommandAsync(); + var standDuration = await Db.Queryable() + .Where(x => x.Id == attachmentId) + .Select(x => x.LearnDuration) + .FirstAsync() ?? 1000000000; + + var studyDuration = await Db.Queryable() + .Where(x => x.StudyRecordId == studyRecordId && x.CourseWareAttachmentId == attachmentId) + .SumAsync(it => it.StudyDuration); + + if (standDuration < (studyDuration + duration)) + duration = standDuration - studyDuration; + + if (duration > 0) + await Db.Updateable() + .SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true) + .Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId) + .ExecuteCommandAsync(); await Task.Factory.StartNew(async () => await GenerateStaffStudyRecord(Db, studyRecordId, duration.Value, attachmentId)); @@ -1700,7 +1713,7 @@ WHERE A.Id = '{id}'"; public async Task GenerateStaffStudyRecord(ISqlSugarClient Db, long studyRecordId, decimal duration, long attachmentId) { - //_logger.LogInformation($"【记录学习时长】GenerateStaffStudyRecord"); + _logger.LogInformation($"【记录学习时长】GenerateStaffStudyRecord"); var record = await Db.Queryable().FirstAsync(x => x.Id == studyRecordId); @@ -1726,7 +1739,7 @@ WHERE A.Id = '{id}'"; #endregion decimal studyProgress = 0; - //_logger.LogInformation($"【记录学习时长】studyProgress:{studyProgress}"); + _logger.LogInformation($"【记录学习时长】studyProgress:{studyProgress}"); var sql = $@"SELECT SUM(ISNULL (A.Hours, 0) * 60 + A.Minutes) Minutes FROM Ghre_CourseWare A @@ -1747,11 +1760,14 @@ WHERE A.Id = '{id}'"; if (mins > 0) { duration = record.StudyDuration ?? 0; + + + studyProgress = (duration / mins) * 100; if (studyProgress > 100) studyProgress = 100; } - //_logger.LogInformation($"【记录学习时长】studyProgress1:{studyProgress}"); + _logger.LogInformation($"【记录学习时长】studyProgress1:{studyProgress}");