单个附件的实际学习时长最多不超过附件设定时长。

master
xiaochanghai 3 months ago
parent 78c5fd4bc7
commit 1671840ca6
  1. 30
      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}'"; //var sql = $"UPDATE Ghre_StudyRecord SET StudyDuration = ISNULL(StudyDuration, 0)+{duration} WHERE Id='{studyRecordId}' AND StaffId='{staffId}'";
//await Db.Ado.ExecuteCommandAsync(sql); //await Db.Ado.ExecuteCommandAsync(sql);
await Db.Updateable<Ghre_StudyRecord>() var standDuration = await Db.Queryable<Ghre_CourseWareAttachment>()
.SetColumns(it => new Ghre_StudyRecord() { StudyDuration = (it.StudyDuration ?? 0) + duration }, true) .Where(x => x.Id == attachmentId)
.Where(it => it.Id == studyRecordId && it.StaffId == App.User.StaffId) .Select(x => x.LearnDuration)
.ExecuteCommandAsync(); .FirstAsync() ?? 1000000000;
var studyDuration = await Db.Queryable<Ghre_StudyRecordDetail>()
.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<Ghre_StudyRecord>()
.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)); await Task.Factory.StartNew(async () => await GenerateStaffStudyRecord(Db, studyRecordId, duration.Value, attachmentId));
@ -1700,7 +1713,7 @@ WHERE A.Id = '{id}'";
public async Task<bool> GenerateStaffStudyRecord(ISqlSugarClient Db, long studyRecordId, decimal duration, long attachmentId) public async Task<bool> GenerateStaffStudyRecord(ISqlSugarClient Db, long studyRecordId, decimal duration, long attachmentId)
{ {
//_logger.LogInformation($"【记录学习时长】GenerateStaffStudyRecord"); _logger.LogInformation($"【记录学习时长】GenerateStaffStudyRecord");
var record = await Db.Queryable<Ghre_StudyRecord>().FirstAsync(x => x.Id == studyRecordId); var record = await Db.Queryable<Ghre_StudyRecord>().FirstAsync(x => x.Id == studyRecordId);
@ -1726,7 +1739,7 @@ WHERE A.Id = '{id}'";
#endregion #endregion
decimal studyProgress = 0; decimal studyProgress = 0;
//_logger.LogInformation($"【记录学习时长】studyProgress:{studyProgress}"); _logger.LogInformation($"【记录学习时长】studyProgress:{studyProgress}");
var sql = $@"SELECT SUM(ISNULL (A.Hours, 0) * 60 + A.Minutes) Minutes var sql = $@"SELECT SUM(ISNULL (A.Hours, 0) * 60 + A.Minutes) Minutes
FROM Ghre_CourseWare A FROM Ghre_CourseWare A
@ -1747,11 +1760,14 @@ WHERE A.Id = '{id}'";
if (mins > 0) if (mins > 0)
{ {
duration = record.StudyDuration ?? 0; duration = record.StudyDuration ?? 0;
studyProgress = (duration / mins) * 100; studyProgress = (duration / mins) * 100;
if (studyProgress > 100) if (studyProgress > 100)
studyProgress = 100; studyProgress = 100;
} }
//_logger.LogInformation($"【记录学习时长】studyProgress1:{studyProgress}"); _logger.LogInformation($"【记录学习时长】studyProgress1:{studyProgress}");

Loading…
Cancel
Save