diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs index 62b784a2..f0bacfe6 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs @@ -65,4 +65,18 @@ public class Ghre_StudyRecordController : BaseController + /// 记录学习时长 + /// + /// + /// + [HttpPost, Route("RecordDuration/{id}")] + public async Task RecordDuration([FromBody] InsertGhre_StudyRecordInput insert, long id) + { + return await _service.RecordDuration(id, insert.StudyDuration); + } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Api/Tiobon.Core.Model.xml b/Tiobon.Core.Api/Tiobon.Core.Model.xml index c40489f9..6c54ee96 100644 --- a/Tiobon.Core.Api/Tiobon.Core.Model.xml +++ b/Tiobon.Core.Api/Tiobon.Core.Model.xml @@ -3965,6 +3965,11 @@ 学习进度 + + + 学习时长(分钟) + + 课程类型 @@ -9731,6 +9736,11 @@ 学习进度 + + + 学习时长(分钟) + + 课程类型 diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 3266a6f6..252b9195 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -969,6 +969,13 @@ + + + 记录学习时长 + + + + 必选修规则(Controller) diff --git a/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs index d127e8dd..75498464 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs @@ -19,5 +19,7 @@ namespace Tiobon.Core.IServices Task Join(long courseId); + + Task RecordDuration(long studyRecordId, decimal? duration); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRecord.Dto.Base.cs b/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRecord.Dto.Base.cs index 4d5019a3..db9d3e00 100644 --- a/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRecord.Dto.Base.cs +++ b/Tiobon.Core.Model/Base/Ghre/Ghre_StudyRecord.Dto.Base.cs @@ -87,6 +87,11 @@ namespace Tiobon.Core.Model.Models /// public int? StudyProgress { get; set; } + /// + /// 学习时长(分钟) + /// + public decimal? StudyDuration { get; set; } + /// /// 课程类型 /// diff --git a/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRecord.cs b/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRecord.cs index 9dcf5110..1d7664f0 100644 --- a/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRecord.cs +++ b/Tiobon.Core.Model/Models/Ghre/Ghre_StudyRecord.cs @@ -88,6 +88,11 @@ namespace Tiobon.Core.Model.Models /// public int? StudyProgress { get; set; } + /// + /// 学习时长(分钟) + /// + public decimal? StudyDuration { get; set; } + /// /// 课程类型 /// diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index 6eef0525..8f1f2232 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -9,6 +9,9 @@ using Tiobon.Core.Common; using Tiobon.Core.Model; using Newtonsoft.Json; using Tiobon.Core.Common.Helper; +using MySqlX.XDevAPI.Common; +using SqlSugar; +using Google.Protobuf.WellKnownTypes; namespace Tiobon.Core.Services { @@ -450,8 +453,7 @@ namespace Tiobon.Core.Services #endregion - - #region 获取ESS查询条件 + #region 加入学习 public async Task Join(long courseId) { var staffId = GetStaffId(); @@ -479,5 +481,45 @@ namespace Tiobon.Core.Services return ServiceResult.OprateSuccess("加入成功!"); } #endregion + + #region 记录学习时长 + public async Task RecordDuration(long studyRecordId, decimal? duration) + { + var staffId = GetStaffId(); + var sql = $"UPDATE Ghre_StudyRecord SET StudyDuration = ISNULL(StudyDuration, 0)+{duration} WHERE Id='{studyRecordId}' AND StaffId='{staffId}'"; + await Db.Ado.ExecuteCommandAsync(sql); + + await Task.Factory.StartNew(async () => await GenerateStaffStudyRecord(Db, studyRecordId)); + + + return ServiceResult.OprateSuccess("记录成功!"); + } + + public async Task GenerateStaffStudyRecord(ISqlSugarClient Db, long studyRecordId) + { + var record = await Db.Queryable().FirstAsync(x => x.Id == studyRecordId); + decimal studyProgress = 0; + var sql = $@"SELECT ISNULL (A.Hours, 0) * 60 + A.Minutes Minutes + FROM Ghre_CourseWare A + WHERE A.Id IN + (SELECT CourseWareId + FROM Ghre_Course + WHERE Id = '{record.CourseId}' + OR CourseSceneId = '{record.CourseSceneId}' AND IsEnable = 1)"; + var mins = await Db.Ado.GetDecimalAsync(sql); + + if (mins > 0) + { + var duration = record.StudyDuration ?? 0; + studyProgress = (duration / mins)*100; + if (studyProgress > 100) + studyProgress = 100; + } + + sql = $"UPDATE Ghre_StudyRecord SET StudyProgress = ISNULL(StudyProgress, 0)+{studyProgress} WHERE Id='{studyRecordId}'"; + if (studyProgress > 0) await Db.Ado.ExecuteCommandAsync(sql); + return true; + } + #endregion } -} \ No newline at end of file +} \ No newline at end of file diff --git a/Tiobon.Core/Tiobon.Core.Model.xml b/Tiobon.Core/Tiobon.Core.Model.xml index c40489f9..6c54ee96 100644 --- a/Tiobon.Core/Tiobon.Core.Model.xml +++ b/Tiobon.Core/Tiobon.Core.Model.xml @@ -3965,6 +3965,11 @@ 学习进度 + + + 学习时长(分钟) + + 课程类型 @@ -9731,6 +9736,11 @@ 学习进度 + + + 学习时长(分钟) + + 课程类型 diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index 3266a6f6..252b9195 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -969,6 +969,13 @@ + + + 记录学习时长 + + + + 必选修规则(Controller)