diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs index f0bacfe6..f0b61767 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_StudyRecordController.cs @@ -39,6 +39,19 @@ public class Ghre_StudyRecordController : BaseController + /// 获取学习记录 + /// + /// + /// + [HttpPost, Route("QueryStaff")] + public async Task> QueryStaff([FromBody] QueryBody body) + { + return await _service.QueryStaff(body); + } + #endregion + #region 获取课程 /// /// 获取课程 @@ -79,4 +92,10 @@ public class Ghre_StudyRecordController : BaseController> ExportStaffExcel([FromBody] QueryExport body) + { + return await _service.ExportStaffExcel(body); + } } \ No newline at end of file diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 2680aa80..675be4a8 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -991,6 +991,13 @@ + + + 获取学习记录 + + + + 获取课程 diff --git a/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs b/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs index 75498464..ea96f67b 100644 --- a/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs +++ b/Tiobon.Core.IServices/Ghre/IGhre_StudyRecordServices.cs @@ -15,11 +15,15 @@ namespace Tiobon.Core.IServices Task> QueryESS(QueryBody filter, string condition, bool? IsEnable = true); + Task> QueryStaff(QueryBody filter); + Task> QueryCourse(QueryBody body, long id); Task Join(long courseId); Task RecordDuration(long studyRecordId, decimal? duration); + + Task> ExportStaffExcel(QueryExport body); } } \ No newline at end of file diff --git a/Tiobon.Core.Model/ViewModels/Menu.cs b/Tiobon.Core.Model/ViewModels/Menu.cs index 56a1e101..6fede184 100644 --- a/Tiobon.Core.Model/ViewModels/Menu.cs +++ b/Tiobon.Core.Model/ViewModels/Menu.cs @@ -56,8 +56,8 @@ public class ModuleReturn public class ModuleESSReturn { public JM_PageControlT1 JM_PageControlT1 { get; set; } = new JM_PageControlT1(); - public JM_TableColumnT1 DT_TableColumnT1 { get; set; } = new JM_TableColumnT1(); - public JM_TableColumnT1 DT_TableDataSearchT1 { get; set; } = new JM_TableColumnT1(); + public List DT_TableColumnT1 { get; set; } = new List(); + public List DT_TableDataSearchT1 { get; set; } = new List(); public List DT_PageMutiMsg { get; set; } public DT_Procedure DT_Procedure { get; set; } = new DT_Procedure(); @@ -120,6 +120,7 @@ public class TableColumn public object searchColumnDefaultValue { get; set; } = ""; public string AppColumnType { get; set; } public int pageColumnID { get; set; } + public int IsRange { get; set; } = 0; } public class searchOperator { diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 7575d38a..7f96760f 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -279,14 +279,14 @@ public partial class CommonServices : BaseServices>, ICommon AND b.elementType = 'FnKey') order by fnKeySeq"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - result.JM_PageControlT1.Toolbar = await Db.Ado.SqlQueryAsync(sql); + result.JM_PageControlT1.Toolbar = DbAccess.QueryList(sql); #endregion #region 定义表格页面的栏位, 含 表格栏位, 常用查询栏位, 高级查询栏位,可编辑栏位 - await Db.Ado.BeginTranAsync(); + Db.Ado.BeginTran(); sql = @"IF OBJECT_ID('tempdb.[dbo].[#TmpInitPageSettingQuery]') IS NOT NULL DROP TABLE [dbo].[#TmpInitPageSettingQuery] CREATE TABLE [dbo].[#TmpInitPageSettingQuery](pageColumnID int) alter TABLE [dbo].[#TmpInitPageSettingQuery] add [elementType] [nvarchar](1000) , [field] [nvarchar](1000) ,[label] [nvarchar](1000) , @@ -300,7 +300,7 @@ public partial class CommonServices : BaseServices>, ICommon [selfDefine] [nvarchar](2000) , [selectUI] [nvarchar](1000) , [isPrimaryKey] [nvarchar](1000) , isSorted nvarchar(10),isHidden nvarchar(10),isSearched nvarchar(10),sortNo int, [searchOperator] nvarchar(max),searchColumnDefaultValue nvarchar(1000),AppColumnType nvarchar(100)"; - int count = await Db.Ado.ExecuteCommandAsync(sql); + int count = Db.Ado.ExecuteCommand(sql); sql = @"SELECT count (1) UserHasSetting @@ -312,7 +312,7 @@ public partial class CommonServices : BaseServices>, ICommon AND a.IsEnable = 1 AND a.PageSettingQueryId = b.PageSettingQueryId"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - int UserHasSetting = await Db.Ado.GetIntAsync(sql); + int UserHasSetting = Db.Ado.GetInt(sql); if (UserHasSetting == 0) { sql = @"INSERT INTO [dbo].[#TmpInitPageSettingQuery] @@ -367,7 +367,7 @@ public partial class CommonServices : BaseServices>, ICommon AND IsEnable = 1 ORDER BY SortNo"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - count = await Db.Ado.ExecuteCommandAsync(sql); + count = Db.Ado.ExecuteCommand(sql); } else { @@ -491,7 +491,7 @@ public partial class CommonServices : BaseServices>, ICommon AND kk.elementtype = Ghrs_PageSettingQuery.elementtype) ORDER BY SortNo "; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - count = await Db.Ado.ExecuteCommandAsync(sql); + count = Db.Ado.ExecuteCommand(sql); } @@ -791,7 +791,7 @@ public partial class CommonServices : BaseServices>, ICommon SET width = 50 WHERE elementType = 'FnKey' OR field = 'Muti';"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - count = await Db.Ado.ExecuteCommandAsync(sql); + count = Db.Ado.ExecuteCommand(sql); sql = @"select pageColumnID,elementType, field,label,meky, multipleSelect, dataType, required, palceholder, dataSourceType,dataSource, sortable, sortOrder, @@ -811,7 +811,7 @@ public partial class CommonServices : BaseServices>, ICommon from [dbo].[#TmpInitPageSettingQuery] order by sortno asc"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - var TableColumn = await Db.Ado.SqlQueryAsync(sql); + var TableColumn = Db.Ado.SqlQuery(sql); result.JM_TableColumnT1.TableColumn = Mapper.Map(TableColumn).ToANew>(); result.JM_TableColumnT1.TableColumn = result.JM_TableColumnT1.TableColumn.Where(x => x.field != "DetailYN" && x.field != "Muti").ToList(); result.JM_TableColumnT1.TableColumn.ForEach(x => @@ -823,7 +823,7 @@ public partial class CommonServices : BaseServices>, ICommon if (x.multipleSearchValue == "true") x.searchColumnDefaultValue = new List(); }); - await Db.Ado.CommitTranAsync(); + Db.Ado.CommitTran(); sql = @"SELECT Langkey field, CASE {2} @@ -842,11 +842,11 @@ public partial class CommonServices : BaseServices>, ICommon WHERE IsEnable = 1 AND (LangKey LIKE 'GHR_Page%' OR LangKey LIKE 'GHR_Common%')"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - result.DT_PageMutiMsg = await Db.Ado.SqlQueryAsync(sql); + result.DT_PageMutiMsg = Db.Ado.SqlQuery(sql); sql = "select QueryProcedure, EditProcedure, IUDProcedure from Ghrs_Menu where MenuNo='{0}'"; sql = string.Format(sql, param.menuName, App.User.ID, param.langId); - DataTable dt = await Db.Ado.GetDataTableAsync(sql); + DataTable dt = Db.Ado.GetDataTable(sql); if (dt.Rows.Count > 0) { result.DT_Procedure.QueryProcedure = dt.Rows[0]["QueryProcedure"].ToString(); @@ -1085,7 +1085,7 @@ public partial class CommonServices : BaseServices>, ICommon AND A.IsEnable = 1 AND B.IsEnable = 1 AND B.RoleNo = 'TrainingExamScore'"; - var toolbarRoles = await Db.Ado.SqlQueryAsync(sql); + var toolbarRoles = DbAccess.QueryList(sql); if (toolbarRoles != null && toolbarRoles.Any()) result.JM_PageControlT1.Toolbar.Add(new Toolbar() { @@ -1121,6 +1121,10 @@ public partial class CommonServices : BaseServices>, ICommon }); break; + case "F_ESS_StudyRecord": + result.DT_Procedure.ExportExcel = "/api/Ghre_StudyRecord/ExportStaffExcel"; + + break; } #endregion @@ -1138,12 +1142,18 @@ public partial class CommonServices : BaseServices>, ICommon var result1 = await GetModuleInfoAsync(param); result.JM_PageControlT1 = result1.Data.JM_PageControlT1; - result.DT_TableColumnT1 = result1.Data.JM_TableColumnT1; + result.DT_TableColumnT1 = result1.Data.JM_TableColumnT1.TableColumn; result.DT_PageMutiMsg = result1.Data.DT_PageMutiMsg; result.DT_Procedure = result1.Data.DT_Procedure; - result.DT_TableDataSearchT1 = result.DT_TableColumnT1; + result.DT_TableDataSearchT1 = result.DT_TableColumnT1.ToList(); - result.DT_TableDataSearchT1.TableColumn = result.DT_TableDataSearchT1.TableColumn.Where(x => x.searchable == true).ToList(); + result.DT_TableDataSearchT1 = result.DT_TableDataSearchT1.OrderBy(x => x.searchColumnSeq).Where(x => x.searchable == true).ToList(); + + result.DT_TableDataSearchT1.ForEach(x => + { + if (x.searchOperator != null && x.searchOperator.Where(o => o.@operator == "Range").Any()) + x.IsRange = 1; + }); return new ServiceResult() { Success = true, Message = "查询成功", Data = result, }; } #endregion diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index 85a434e5..4b22e225 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -11,202 +11,259 @@ using Newtonsoft.Json; using Tiobon.Core.Common.Helper; using SqlSugar; using static Tiobon.Core.Model.Consts; -using Tiobon.Core.Common.DB.Dapper.Extensions; -using MongoDB.Driver.Linq; -namespace Tiobon.Core.Services +namespace Tiobon.Core.Services; + +/// +/// 培训记录 (服务) +/// +public class Ghre_StudyRecordServices : BaseServices, IGhre_StudyRecordServices { - /// - /// 培训记录 (服务) - /// - public class Ghre_StudyRecordServices : BaseServices, IGhre_StudyRecordServices + private readonly IBaseRepository _dal; + public Ghre_StudyRecordServices(ICaching caching, IBaseRepository dal) { - private readonly IBaseRepository _dal; - public Ghre_StudyRecordServices(ICaching caching, IBaseRepository dal) - { - this._dal = dal; - base.BaseDal = dal; - base._caching = caching; - } - public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) - { - if (string.IsNullOrWhiteSpace(filter.orderBy)) - filter.orderBy = "CreateTime1 DESC"; + this._dal = dal; + base.BaseDal = dal; + base._caching = caching; + } + public override async Task> QueryFilterPage(QueryBody filter, string condition, bool? IsEnable = true) + { + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "CreateTime1 DESC"; - if (filter.pageSize == 0) - filter.pageSize = 10000; + if (filter.pageSize == 0) + filter.pageSize = 10000; - var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; - var sql = @$" SELECT * + var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; + var sql = @$" SELECT * FROM Ghre_StudyRecord_V A"; - string conditions = " WHERE 1=1 "; + string conditions = " WHERE 1=1 "; - if (IsEnable == true) - conditions += " AND IsEnable = 1"; - else if (IsEnable == false) - conditions += " AND IsEnable = 0"; + if (IsEnable == true) + conditions += " AND IsEnable = 1"; + else if (IsEnable == false) + conditions += " AND IsEnable = 0"; - if (!string.IsNullOrWhiteSpace(condition)) - conditions += " AND " + condition; + if (!string.IsNullOrWhiteSpace(condition)) + conditions += " AND " + condition; - if (filter.jsonParam != null) - foreach (JProperty jProperty in filter.jsonParam.Properties()) + if (filter.jsonParam != null) + foreach (JProperty jProperty in filter.jsonParam.Properties()) + { + var name = jProperty.Name; + var value = jProperty.Value.ToString(); + if (name == "page" || name == "pageSize") + continue; + if (name == "Date") { - var name = jProperty.Name; - var value = jProperty.Value.ToString(); - if (name == "page" || name == "pageSize") - continue; - if (name == "Date") - { - var jsonParam = JsonConvert.DeserializeObject(value); - conditions += $" AND (Date BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}')"; + var jsonParam = JsonConvert.DeserializeObject(value); + conditions += $" AND ((ExamDate BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}') OR (CourseBeginTime BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}') OR (CourseEndTime BETWEEN '{jsonParam.columnValue[0]}' AND '{jsonParam.columnValue[1]}'))"; - continue; - } - if (!string.IsNullOrWhiteSpace(value)) - conditions = DealConditions(conditions, name, value); + continue; } - sql += conditions; - countSql += conditions; - int total = await Db.Ado.GetIntAsync(countSql); + if (name == "IsPass" || name == "Source") + { + value = value.Replace("Include", "Equal"); + } + if (!string.IsNullOrWhiteSpace(value)) + conditions = DealConditions(conditions, name, value); + } - sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; - sql += ") A ) B ) C"; + sql += conditions; + countSql += conditions; + int total = await Db.Ado.GetIntAsync(countSql); - sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; + sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; + sql += ") A ) B ) C"; - var entitys = await Db.Ado.SqlQueryAsync(sql); + sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; + + var entitys = await Db.Ado.SqlQueryAsync(sql); + + entitys.ForEach(entity => + { + if (!string.IsNullOrWhiteSpace(entity.Indate)) + entity.Indate = DateTimeHelper.ConvertToDayString(entity.Indate); + entity.ExamDate = DateTimeHelper.ConvertToDayString(entity.ExamDate); - entitys.ForEach(entity => + if (entity.ActualBeginTime != null && entity.ActualEndTime != null) { - if (!string.IsNullOrWhiteSpace(entity.Indate)) - entity.Indate = DateTimeHelper.ConvertToDayString(entity.Indate); - entity.ExamDate = DateTimeHelper.ConvertToDayString(entity.ExamDate); + TimeSpan timeDifference = entity.ActualEndTime.Value - entity.ActualBeginTime.Value; + entity.ExamDuration = StringHelper.TrimNumber(Convert.ToDecimal(timeDifference.TotalMinutes), 2); + } + }); - if (entity.ActualBeginTime != null && entity.ActualEndTime != null) - { - TimeSpan timeDifference = entity.ActualEndTime.Value - entity.ActualBeginTime.Value; - entity.ExamDuration = StringHelper.TrimNumber(Convert.ToDecimal(timeDifference.TotalMinutes), 2); - } - }); + return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); - return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); + } - } + public async Task> QueryStaff(QueryBody filter) + { + return await QueryFilterPage(filter, $"UserId={App.User.ID}", true); + } + public async Task> ExportStaffExcel(QueryExport body) + { + QueryBody filter = new QueryBody(); + filter.pageNum = 1; + filter.pageSize = 1000000; + filter.langId = body.langId; - public override async Task Add(InsertGhre_StudyRecordInput entity) - { - if (await Db.Queryable() - .WhereIF(!entity.CourseId.IsNullOrEmpty(), x => x.CourseId == entity.CourseId) - .WhereIF(!entity.CourseSceneId.IsNullOrEmpty(), x => x.CourseSceneId == entity.CourseSceneId) - .AnyAsync(x => x.StaffId == entity.StaffId)) - throw new Exception("该用户存在相同学习记录!"); + var ids = new List(); + if (body.exportSet.SelectRowKeys != null && body.exportSet.SelectRowKeys.Any()) + ids = body.exportSet.SelectRowKeys; - if (entity.BeginTime != null && entity.EndTime != null) - { - if (entity.EndTime < entity.BeginTime) - throw new Exception("学习结束时间需大于学习开始时间!"); + var data = await QueryFilterPage(filter, $"UserId={App.User.ID}", true); - if (entity.EndTime > DateTime.Now) - throw new Exception("学习结束时间需小于当前时间!"); - TimeSpan timeDifference = entity.EndTime.Value - entity.BeginTime.Value; - entity.StudyDuration = (decimal)timeDifference.TotalMinutes; - } - var snap = await Db.Queryable().FirstAsync(x => x.CourseId == entity.CourseId); - entity.CourseSnapId = snap?.Id; - entity.CourseType = "ManualInsert"; - var result = await base.Add(entity); + string sql = $@"SELECT * + FROM Ghrs_PageSettingQuery + WHERE IsEnable = 1 + AND PageNo = '{body.menuName}' + AND (defaultHidden = 'false' or defaultHidden is null) + ORDER BY SortNo ASC"; + + var columns = await Db.Ado.SqlQueryAsync(sql); - var examRecord = new Ghre_ExamRecord() + var fieldDescs = new Dictionary(); + if (body.exportSet.ExFields.Any()) + body.exportSet.ExFields.ForEach(x => { - StudyRecordId = result, - StaffId = entity.StaffId, - CourseSnapId = snap?.Id, - Score = entity.Score, - AdjustScore = entity.AdjustScore, - ExamDate = entity.ExamDate, - IsPass = entity.IsPass, - }; - await Db.Insertable(examRecord).ExecuteCommandAsync(); - - return result; - } + if (columns.Any(o => o.field == x)) + fieldDescs.Add(x, columns.FirstOrDefault(o => o.field == x)?.label); + }); + else + fieldDescs = columns.ToDictionary(item => item.field, item => item.label); + var dt = ToDataTable(data.result.DT_TableDataT1, fieldDescs, null); + // 获取所有列名 + var dtColumns = dt.Columns; + + var id = SnowFlakeSingle.instance.getID(); + var physicsPath = $"{Environment.CurrentDirectory}{Path.DirectorySeparatorChar}wwwroot"; + var path = $"{$"{Path.DirectorySeparatorChar}files{Path.DirectorySeparatorChar}export{Path.DirectorySeparatorChar}{id}{Path.DirectorySeparatorChar}"}"; + if (!Directory.Exists(physicsPath + path)) + Directory.CreateDirectory(physicsPath + path); + + path = path + body.exportSet.TitleName + ".xlsx"; + NPOIHelper.ExportExcel(dt, body.exportSet.TitleName, "sheet1", physicsPath + path); + var result = new ExcelData(); + result.filePath = path; + result.fileName = body.exportSet.TitleName + ".xlsx"; + return ServiceResult.OprateSuccess("导出成功", result); + } + + public override async Task Add(InsertGhre_StudyRecordInput entity) + { + if (await Db.Queryable() + .WhereIF(!entity.CourseId.IsNullOrEmpty(), x => x.CourseId == entity.CourseId) + .WhereIF(!entity.CourseSceneId.IsNullOrEmpty(), x => x.CourseSceneId == entity.CourseSceneId) + .AnyAsync(x => x.StaffId == entity.StaffId)) + throw new Exception("该用户存在相同学习记录!"); - public override async Task Update(long Id, EditGhre_StudyRecordInput editModel) + if (entity.BeginTime != null && entity.EndTime != null) { - if (await Db.Queryable() - .WhereIF(!editModel.CourseId.IsNullOrEmpty(), x => x.CourseId == editModel.CourseId) - .WhereIF(!editModel.CourseSceneId.IsNullOrEmpty(), x => x.CourseSceneId == editModel.CourseSceneId) - .AnyAsync(x => x.StaffId == editModel.StaffId && x.Id != Id)) - throw new Exception("该用户存在相同学习记录!"); + if (entity.EndTime < entity.BeginTime) + throw new Exception("学习结束时间需大于学习开始时间!"); - if (editModel.BeginTime != null && editModel.EndTime != null) - { - if (editModel.EndTime < editModel.BeginTime) - throw new Exception("学习结束时间需大于学习开始时间!"); + if (entity.EndTime > DateTime.Now) + throw new Exception("学习结束时间需小于当前时间!"); + TimeSpan timeDifference = entity.EndTime.Value - entity.BeginTime.Value; + entity.StudyDuration = (decimal)timeDifference.TotalMinutes; + } - if (editModel.EndTime > DateTime.Now) - throw new Exception("学习结束时间需小于当前时间!"); - TimeSpan timeDifference = editModel.EndTime.Value - editModel.BeginTime.Value; - editModel.StudyDuration = (decimal)timeDifference.TotalMinutes; - } + var snap = await Db.Queryable().FirstAsync(x => x.CourseId == entity.CourseId); + entity.CourseSnapId = snap?.Id; + entity.CourseType = "ManualInsert"; + var result = await base.Add(entity); - var snap = await Db.Queryable().FirstAsync(x => x.CourseId == editModel.CourseId); - editModel.CourseSnapId = snap?.Id; - editModel.CourseType = "ManualInsert"; - var result = await base.Update(Id, editModel); - var snapId = snap?.Id; - await Db.Updateable() - .SetColumns(it => new Ghre_ExamRecord() - { - StaffId = editModel.StaffId, - CourseSnapId = snapId, - Score = editModel.Score, - AdjustScore = editModel.AdjustScore, - ExamDate = editModel.ExamDate, - IsPass = editModel.IsPass - }) - .Where(it => it.StudyRecordId == Id) - .ExecuteCommandAsync(); - - return result; - } + var examRecord = new Ghre_ExamRecord() + { + StudyRecordId = result, + StaffId = entity.StaffId, + CourseSnapId = snap?.Id, + Score = entity.Score, + AdjustScore = entity.AdjustScore, + ExamDate = entity.ExamDate, + IsPass = entity.IsPass, + }; + await Db.Insertable(examRecord).ExecuteCommandAsync(); + + return result; + } - public override async Task> QueryForm(QueryForm body) + public override async Task Update(long Id, EditGhre_StudyRecordInput editModel) + { + if (await Db.Queryable() + .WhereIF(!editModel.CourseId.IsNullOrEmpty(), x => x.CourseId == editModel.CourseId) + .WhereIF(!editModel.CourseSceneId.IsNullOrEmpty(), x => x.CourseSceneId == editModel.CourseSceneId) + .AnyAsync(x => x.StaffId == editModel.StaffId && x.Id != Id)) + throw new Exception("该用户存在相同学习记录!"); + + if (editModel.BeginTime != null && editModel.EndTime != null) { - var result = await base.QueryForm(body); + if (editModel.EndTime < editModel.BeginTime) + throw new Exception("学习结束时间需大于学习开始时间!"); + + if (editModel.EndTime > DateTime.Now) + throw new Exception("学习结束时间需小于当前时间!"); + TimeSpan timeDifference = editModel.EndTime.Value - editModel.BeginTime.Value; + editModel.StudyDuration = (decimal)timeDifference.TotalMinutes; + } - var DT_TableDataT1 = result.result.DT_TableDataT1; - for (int i = 0; i < DT_TableDataT1.Count; i++) + var snap = await Db.Queryable().FirstAsync(x => x.CourseId == editModel.CourseId); + editModel.CourseSnapId = snap?.Id; + editModel.CourseType = "ManualInsert"; + var result = await base.Update(Id, editModel); + var snapId = snap?.Id; + await Db.Updateable() + .SetColumns(it => new Ghre_ExamRecord() { - var record = await Db.Queryable().FirstAsync(x => x.StudyRecordId == DT_TableDataT1[i].Id); + StaffId = editModel.StaffId, + CourseSnapId = snapId, + Score = editModel.Score, + AdjustScore = editModel.AdjustScore, + ExamDate = editModel.ExamDate, + IsPass = editModel.IsPass + }) + .Where(it => it.StudyRecordId == Id) + .ExecuteCommandAsync(); + + return result; + } - if (record != null) - { - DT_TableDataT1[i].Score = record.Score; - DT_TableDataT1[i].AdjustScore = record.AdjustScore; - if (record.ExamDate != null) - DT_TableDataT1[i].ExamDate = record.ExamDate.Value.ToString(); - if (record.IsPass != null) - DT_TableDataT1[i].IsPass = record.IsPass == true ? "true" : "false"; - } + public override async Task> QueryForm(QueryForm body) + { + var result = await base.QueryForm(body); + var DT_TableDataT1 = result.result.DT_TableDataT1; + for (int i = 0; i < DT_TableDataT1.Count; i++) + { + var record = await Db.Queryable().FirstAsync(x => x.StudyRecordId == DT_TableDataT1[i].Id); + + if (record != null) + { + DT_TableDataT1[i].Score = record.Score; + DT_TableDataT1[i].AdjustScore = record.AdjustScore; + if (record.ExamDate != null) + DT_TableDataT1[i].ExamDate = record.ExamDate.Value.ToString(); + if (record.IsPass != null) + DT_TableDataT1[i].IsPass = record.IsPass == true ? "true" : "false"; } - result.result.DT_TableDataT1 = DT_TableDataT1; - return result; + } + result.result.DT_TableDataT1 = DT_TableDataT1; + return result; + } - #region 获取ESS查询条件 - public async Task> QueryESSSearchFields(QueryBody body) - { - var entity = new CoursePublicSearch(); - string sql = @"SELECT Langkey field, + #region 获取ESS查询条件 + public async Task> QueryESSSearchFields(QueryBody body) + { + var entity = new CoursePublicSearch(); + string sql = @"SELECT Langkey field, CASE {2} WHEN 1 THEN isnull (Value01, LangValue) WHEN 2 THEN isnull (Value02, LangValue) @@ -222,79 +279,79 @@ namespace Tiobon.Core.Services FROM Ghrs_LangKey WHERE IsEnable = 1 AND (LangKey LIKE 'GHR_Page%' OR LangKey LIKE 'GHR_Common%')"; - sql = string.Format(sql, body.menuName, App.User.ID, body.langId); - entity.DT_PageMutiMsg = await Db.Ado.SqlQueryAsync(sql); - entity.SearchFields.Add(new CoursePublicSearchField() - { - label = "课程编号/名称", - field = "CourseNoOrName", - elementType = "Input", - editable = true, - required = false, - multipleSelect = false, - }); - entity.SearchFields.Add(new CoursePublicSearchField() - { - label = "课程分类", - field = "CourseClassId", - elementType = "ApiSelect", - dataSource = "CommonList_TrainingCourseClass", - editable = true, - required = false, - multipleSelect = false, - }); - entity.SearchFields.Add(new CoursePublicSearchField() - { - label = "课程场景", - field = "CourseSceneId", - elementType = "ApiSelect", - dataSource = "CommonList_TrainingCourseScene", - editable = true, - required = false, - multipleSelect = false, - }); - entity.SearchFields.Add(new CoursePublicSearchField() - { - label = "课程状态", - field = "CourseStatus", - elementType = "ApiSelect", - dataSource = "TBParaDetail_Train_CourseIsOpen", - editable = true, - required = false, - multipleSelect = false, - }); - entity.SearchFields.Add(new CoursePublicSearchField() - { - label = "学习状态", - field = "StudyStatus", - elementType = "ApiSelect", - dataSource = "TBParaDetail_Train_TrainingStudyStatus", - editable = true, - required = false, - multipleSelect = false, - }); - return ServiceResult.OprateSuccess("", entity); - } - #endregion - - #region 获取我的学习 - /// - /// - /// - /// - /// - /// - /// - public async Task> QueryESS(QueryBody filter, string condition, bool? IsEnable = true) + sql = string.Format(sql, body.menuName, App.User.ID, body.langId); + entity.DT_PageMutiMsg = await Db.Ado.SqlQueryAsync(sql); + entity.SearchFields.Add(new CoursePublicSearchField() + { + label = "课程编号/名称", + field = "CourseNoOrName", + elementType = "Input", + editable = true, + required = false, + multipleSelect = false, + }); + entity.SearchFields.Add(new CoursePublicSearchField() + { + label = "课程分类", + field = "CourseClassId", + elementType = "ApiSelect", + dataSource = "CommonList_TrainingCourseClass", + editable = true, + required = false, + multipleSelect = false, + }); + entity.SearchFields.Add(new CoursePublicSearchField() { - if (string.IsNullOrWhiteSpace(filter.orderBy)) - filter.orderBy = "JoinTime DESC"; + label = "课程场景", + field = "CourseSceneId", + elementType = "ApiSelect", + dataSource = "CommonList_TrainingCourseScene", + editable = true, + required = false, + multipleSelect = false, + }); + entity.SearchFields.Add(new CoursePublicSearchField() + { + label = "课程状态", + field = "CourseStatus", + elementType = "ApiSelect", + dataSource = "TBParaDetail_Train_CourseIsOpen", + editable = true, + required = false, + multipleSelect = false, + }); + entity.SearchFields.Add(new CoursePublicSearchField() + { + label = "学习状态", + field = "StudyStatus", + elementType = "ApiSelect", + dataSource = "TBParaDetail_Train_TrainingStudyStatus", + editable = true, + required = false, + multipleSelect = false, + }); + return ServiceResult.OprateSuccess("", entity); + } + #endregion - if (filter.pageSize == 0) - filter.pageSize = 10000; + #region 获取我的学习 + /// + /// + /// + /// + /// + /// + /// + public async Task> QueryESS(QueryBody filter, string condition, bool? IsEnable = true) + { + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "JoinTime DESC"; + + if (filter.pageSize == 0) + filter.pageSize = 10000; - var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; - var sql = @$" SELECT A.Id, + var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; + var sql = @$" SELECT A.Id, A.StaffId, A.CourseSnapId, A.CourseId, @@ -319,165 +376,165 @@ namespace Tiobon.Core.Services A.ExamId,A.ExamStatus FROM Ghre_StudyRecord_V A"; - string conditions = $" WHERE UserId={App.User.ID} "; + string conditions = $" WHERE UserId={App.User.ID} "; - if (IsEnable == true) - conditions += " AND IsEnable = 1"; - else if (IsEnable == false) - conditions += " AND IsEnable = 0"; + if (IsEnable == true) + conditions += " AND IsEnable = 1"; + else if (IsEnable == false) + conditions += " AND IsEnable = 0"; - if (!string.IsNullOrWhiteSpace(condition)) - conditions += " AND " + condition; + if (!string.IsNullOrWhiteSpace(condition)) + conditions += " AND " + condition; - if (filter.jsonParam != null) - foreach (JProperty jProperty in filter.jsonParam.Properties()) + if (filter.jsonParam != null) + foreach (JProperty jProperty in filter.jsonParam.Properties()) + { + var name = jProperty.Name; + var value = jProperty.Value.ToString(); + if (name == "page" || name == "pageSize") + continue; + if (name == "CourseNoOrName") { - var name = jProperty.Name; - var value = jProperty.Value.ToString(); - if (name == "page" || name == "pageSize") - continue; - if (name == "CourseNoOrName") - { - var jsonParam = JsonConvert.DeserializeObject(value); - conditions += $" AND CourseName LIKE '%{jsonParam.columnValue}%'"; + var jsonParam = JsonConvert.DeserializeObject(value); + conditions += $" AND CourseName LIKE '%{jsonParam.columnValue}%'"; - continue; - } - if (name == "CourseClassId") - { - var jsonParam = JsonConvert.DeserializeObject(value); - conditions += $" AND CourseClassId LIKE '%{jsonParam.columnValue}%' "; + continue; + } + if (name == "CourseClassId") + { + var jsonParam = JsonConvert.DeserializeObject(value); + conditions += $" AND CourseClassId LIKE '%{jsonParam.columnValue}%' "; - continue; - } - if (name == "CourseType") - { - var jsonParam = JsonConvert.DeserializeObject(value); + continue; + } + if (name == "CourseType") + { + var jsonParam = JsonConvert.DeserializeObject(value); - var value1 = jsonParam.columnValue; - conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; + var value1 = jsonParam.columnValue; + conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; - continue; - } - if (!string.IsNullOrWhiteSpace(value)) + continue; + } + if (!string.IsNullOrWhiteSpace(value)) + { + var jsonParam = JsonConvert.DeserializeObject(value); + + switch (jsonParam.operationKey) { - var jsonParam = JsonConvert.DeserializeObject(value); - - switch (jsonParam.operationKey) - { - case "Include": - conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; - break; - case "NotInclude": - conditions += $" AND {name} NOT LIKE '%{jsonParam.columnValue}%'"; - break; - case "IsNull": - conditions += $" AND {name} IS NULL"; - break; - case "NotNull": - conditions += $" AND {name} IS NOT NULL"; - break; - case "Equal": - conditions += $" AND {name} ='{jsonParam.columnValue}'"; - break; - case "NotEqual": - conditions += $" AND {name} !='{jsonParam.columnValue}'"; - break; - case "GreaterOrEqual"://大于等于 - conditions += $" AND {name} >='{jsonParam.columnValue}'"; - break; - case "Greater"://大于 - conditions += $" AND {name} >'{jsonParam.columnValue}'"; - break; - case "LessOrEqual"://小于等于 - conditions += $" AND {name} <='{jsonParam.columnValue}'"; - break; - case "Less"://小于 - conditions += $" AND {name} <'{jsonParam.columnValue}'"; - break; - default: - break; - } + case "Include": + conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; + break; + case "NotInclude": + conditions += $" AND {name} NOT LIKE '%{jsonParam.columnValue}%'"; + break; + case "IsNull": + conditions += $" AND {name} IS NULL"; + break; + case "NotNull": + conditions += $" AND {name} IS NOT NULL"; + break; + case "Equal": + conditions += $" AND {name} ='{jsonParam.columnValue}'"; + break; + case "NotEqual": + conditions += $" AND {name} !='{jsonParam.columnValue}'"; + break; + case "GreaterOrEqual"://大于等于 + conditions += $" AND {name} >='{jsonParam.columnValue}'"; + break; + case "Greater"://大于 + conditions += $" AND {name} >'{jsonParam.columnValue}'"; + break; + case "LessOrEqual"://小于等于 + conditions += $" AND {name} <='{jsonParam.columnValue}'"; + break; + case "Less"://小于 + conditions += $" AND {name} <'{jsonParam.columnValue}'"; + break; + default: + break; } } + } - sql += conditions; - countSql += conditions; - int total = await Db.Ado.GetIntAsync(countSql); + sql += conditions; + countSql += conditions; + int total = await Db.Ado.GetIntAsync(countSql); - sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; - sql += ") A ) B ) C"; + sql = "SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY " + filter.orderBy + ") NUM FROM (SELECT * FROM (" + sql + " "; + sql += ") A ) B ) C"; - sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; + sql += " WHERE NUM <= " + filter.pageNum * filter.pageSize + " AND NUM >" + (filter.pageNum - 1) * filter.pageSize; - var entitys = await Db.Ado.SqlQueryAsync(sql); - var dt = DateTime.Now.Date; - entitys.ForEach(x => - { - if (x.CourseBeginDate != null && x.CourseEndDate != null) - x.CourseDateString = DateTimeHelper.ConvertToDayString(x.CourseBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.CourseEndDate); + var entitys = await Db.Ado.SqlQueryAsync(sql); + var dt = DateTime.Now.Date; + entitys.ForEach(x => + { + if (x.CourseBeginDate != null && x.CourseEndDate != null) + x.CourseDateString = DateTimeHelper.ConvertToDayString(x.CourseBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.CourseEndDate); - if (!x.ExamId.IsNull()) - { - if (x.ExamBeginDate != null && x.ExamEndDate != null) - x.ExamDateString = DateTimeHelper.ConvertToDayString(x.ExamBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.ExamEndDate); - else x.ExamDateString = $"学完{x.AfterHowLong}天"; - } + if (!x.ExamId.IsNull()) + { + if (x.ExamBeginDate != null && x.ExamEndDate != null) + x.ExamDateString = DateTimeHelper.ConvertToDayString(x.ExamBeginDate) + "~" + DateTimeHelper.ConvertToDayString(x.ExamEndDate); + else x.ExamDateString = $"学完{x.AfterHowLong}天"; + } - //if (x.CourseBeginDate != null && x.CourseEndDate != null) - // if (x.StudyProgress >= 100 || !(x.CourseBeginDate.Value.Date <= DateTime.Now.Date && x.CourseEndDate.Value.Date >= DateTime.Now.Date)) - // x.DisableStudyBtn = true; + //if (x.CourseBeginDate != null && x.CourseEndDate != null) + // if (x.StudyProgress >= 100 || !(x.CourseBeginDate.Value.Date <= DateTime.Now.Date && x.CourseEndDate.Value.Date >= DateTime.Now.Date)) + // x.DisableStudyBtn = true; - if (x.StudyProgress < 100 || x.ExamId.IsNull()) - x.DisableExamBtn = true; - if (x.FeedbackOrderId.IsNull()) - x.ShowFeedbackBtn = false; + if (x.StudyProgress < 100 || x.ExamId.IsNull()) + x.DisableExamBtn = true; + if (x.FeedbackOrderId.IsNull()) + x.ShowFeedbackBtn = false; - #region 处理学习进度 + #region 处理学习进度 - if (x.ExamId.IsNull()) - x.ShowExamBtn = false; + if (x.ExamId.IsNull()) + x.ShowExamBtn = false; - if (!x.ExamId.IsNull() && x.FeedbackOrderId.IsNull()) - { - if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT || x.ExamStatus.IsNull()) - x.StudyProgress = x.StudyProgress / 2; - else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING) - x.StudyProgress = 75; - else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END) - x.StudyProgress = 100; - } + if (!x.ExamId.IsNull() && x.FeedbackOrderId.IsNull()) + { + if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT || x.ExamStatus.IsNull()) + x.StudyProgress = x.StudyProgress / 2; + else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING) + x.StudyProgress = 75; + else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END) + x.StudyProgress = 100; + } - if (!x.ExamId.IsNull() && !x.FeedbackOrderId.IsNull()) - { - if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT) - x.StudyProgress = x.StudyProgress / 3; - else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING) - x.StudyProgress = 45; - else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END) - x.StudyProgress = 60; - } - #endregion - }); + if (!x.ExamId.IsNull() && !x.FeedbackOrderId.IsNull()) + { + if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.WAIT) + x.StudyProgress = x.StudyProgress / 3; + else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAMING) + x.StudyProgress = 45; + else if (x.ExamStatus == DIC_EXAM_RECORD_STATUS.EXAM_END) + x.StudyProgress = 60; + } + #endregion + }); - return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); + return new ServicePageResult(filter.pageNum, total, filter.pageSize, entitys); - } + } - #endregion + #endregion - #region 获取课程 - /// - /// 获取课程 - /// - /// - /// - public async Task> QueryCourse(QueryBody body, long id) - { - var course = new Ghre_StudyRecordCourse(); + #region 获取课程 + /// + /// 获取课程 + /// + /// + /// + public async Task> QueryCourse(QueryBody body, long id) + { + var course = new Ghre_StudyRecordCourse(); - string sql = @$"SELECT A.Id, + string sql = @$"SELECT A.Id, A.CourseId, A.CourseSceneId, ISNULL (B.CourseName, G.SceneName) CourseName, @@ -526,59 +583,59 @@ namespace Tiobon.Core.Services LEFT JOIN Ghre_School F ON B.SchoolId = F.Id LEFT JOIN Ghre_CourseScene G ON A.CourseSceneId = G.Id WHERE A.Id = '{id}'"; - course = await Db.Ado.SqlQuerySingleAsync(sql); - if (course.IsNull()) - return ServiceResult.OprateFailed("无效的学习记录ID!"); + course = await Db.Ado.SqlQuerySingleAsync(sql); + if (course.IsNull()) + return ServiceResult.OprateFailed("无效的学习记录ID!"); - if (course.CourseSceneId.IsNull()) - { - sql = @$"SELECT A.Id, A.Source, A.Link + if (course.CourseSceneId.IsNull()) + { + sql = @$"SELECT A.Id, A.Source, A.Link FROM Ghre_CourseWare A WHERE A.CourseIds LIKE '%{course.CourseId}%' AND A.IsEnable = 1"; - course.CourseWareList = await Db.Ado.SqlQueryAsync(sql); + course.CourseWareList = await Db.Ado.SqlQueryAsync(sql); - course.CourseWareList.ForEach(x => - { - x.CourseId = course.CourseId; - x.CourseName = course.CourseName; - }); - course.CourseTeacherList = - [ - new Ghre_StudyRecordCourseTeacher() { - TeacherName = course.TeacherName, - TeacherEName = course.TeacherEName, - TeacherPhotoUrl = course.TeacherPhotoUrl, - DeptOrSchoolName = course.DeptOrSchoolName, - TeacherRemarkSz = course.TeacherRemarkSz - } - ]; - } - else + course.CourseWareList.ForEach(x => { - course.CourseWareList = new List(); - course.CourseTeacherList = new List(); - var courses = await Db.Queryable().Where(x => x.CourseSceneId == course.CourseSceneId && x.Status == Consts.DIC_COURSE_STATUS.RELEASED).ToListAsync(); + x.CourseId = course.CourseId; + x.CourseName = course.CourseName; + }); + course.CourseTeacherList = + [ + new Ghre_StudyRecordCourseTeacher() { + TeacherName = course.TeacherName, + TeacherEName = course.TeacherEName, + TeacherPhotoUrl = course.TeacherPhotoUrl, + DeptOrSchoolName = course.DeptOrSchoolName, + TeacherRemarkSz = course.TeacherRemarkSz + } + ]; + } + else + { + course.CourseWareList = new List(); + course.CourseTeacherList = new List(); + var courses = await Db.Queryable().Where(x => x.CourseSceneId == course.CourseSceneId && x.Status == Consts.DIC_COURSE_STATUS.RELEASED).ToListAsync(); - for (int i = 0; i < courses.Count; i++) - { - var course1 = courses[i]; + for (int i = 0; i < courses.Count; i++) + { + var course1 = courses[i]; - sql = @$"SELECT A.Id, A.Source, A.Link + sql = @$"SELECT A.Id, A.Source, A.Link FROM Ghre_CourseWare A WHERE A.CourseIds LIKE '%{course1.Id}%' AND A.IsEnable = 1"; - var courseWareList = await Db.Ado.SqlQueryAsync(sql); - courseWareList.ForEach(x => - { - x.CourseId = course.CourseId; - x.CourseName = course.CourseName; - }); - course.CourseWareList.AddRange(courseWareList); + var courseWareList = await Db.Ado.SqlQueryAsync(sql); + courseWareList.ForEach(x => + { + x.CourseId = course.CourseId; + x.CourseName = course.CourseName; + }); + course.CourseWareList.AddRange(courseWareList); - sql = $@"SELECT a.ID, + sql = $@"SELECT a.ID, C.TeacherName, CASE A.InOrOut WHEN 'In' THEN B.StaffEname @@ -607,127 +664,126 @@ namespace Tiobon.Core.Services LEFT JOIN Ghre_School D ON C.SchoolId = D.Id WHERE a.id = '{course1.Id}'"; - course.CourseTeacherList.Add(await Db.Ado.SqlQuerySingleAsync(sql)); + course.CourseTeacherList.Add(await Db.Ado.SqlQuerySingleAsync(sql)); - } } + } - for (int j = 0; j < course.CourseWareList.Count; j++) - { - course.CourseWareList[j].Attachments = await Db.Queryable().Where(x => x.CourseWareId == course.CourseWareList[j].Id).ToListAsync(); - } + for (int j = 0; j < course.CourseWareList.Count; j++) + { + course.CourseWareList[j].Attachments = await Db.Queryable().Where(x => x.CourseWareId == course.CourseWareList[j].Id).ToListAsync(); + } - if (course.CourseBeginTime != null && course.CourseEndTime != null) - course.CourseDateString = DateTimeHelper.ConvertToDayString(course.CourseBeginTime) + "~" + DateTimeHelper.ConvertToDayString(course.CourseEndTime); + if (course.CourseBeginTime != null && course.CourseEndTime != null) + course.CourseDateString = DateTimeHelper.ConvertToDayString(course.CourseBeginTime) + "~" + DateTimeHelper.ConvertToDayString(course.CourseEndTime); - if (course.CourseStandardDuration.IsNull()) - { - sql = $@"SELECT ISNULL (A.Hours, 0) * 60 + A.Minutes Minutes + if (course.CourseStandardDuration.IsNull()) + { + 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 = '{course.CourseId}' OR CourseSceneId = '{course.CourseSceneId}' AND IsEnable = 1)"; - var mins = await Db.Ado.GetDecimalAsync(sql); + var mins = await Db.Ado.GetDecimalAsync(sql); - course.CourseStandardDuration = mins; - } - if (course.StudyDuration.IsNull()) course.StudyDuration = 0; - return ServiceResult.OprateSuccess("查询成功!", course); + course.CourseStandardDuration = mins; } + if (course.StudyDuration.IsNull()) course.StudyDuration = 0; + return ServiceResult.OprateSuccess("查询成功!", course); + } - #endregion + #endregion - #region 加入学习 - public async Task Join(long courseId) + #region 加入学习 + public async Task Join(long courseId) + { + var staffId = GetStaffId(); + if (!await base.AnyAsync(x => x.CourseId == courseId && x.StaffId == staffId)) { - var staffId = GetStaffId(); - if (!await base.AnyAsync(x => x.CourseId == courseId && x.StaffId == staffId)) + var course = await Db.Queryable().Where(x => x.Id == courseId && x.Status == DIC_COURSE_STATUS.RELEASED).FirstAsync(); + if (course.IsNull()) + return ServiceResult.OprateFailed("无效的课程!"); + + DateTime courseTime = Db.GetDate(); + var snap = await Db.Queryable().FirstAsync(x => x.CourseId == courseId); + + var exam = await Db.Queryable() + .Where(x => x.Status == DIC_EXAM_STATUS.RELEASED && + x.CourseId == courseId + && ((x.DateType == DicExamDateType.EXAM_DATE + && x.BeginTime.Value.Date <= DateTime.Now.Date && x.EndTime.Value.Date >= DateTime.Now.Date) || x.DateType == DicExamDateType.AFTER_HOW_LONG)) + .FirstAsync(); + await base.Add(new InsertGhre_StudyRecordInput { - var course = await Db.Queryable().Where(x => x.Id == courseId && x.Status == DIC_COURSE_STATUS.RELEASED).FirstAsync(); - if (course.IsNull()) - return ServiceResult.OprateFailed("无效的课程!"); - - DateTime courseTime = Db.GetDate(); - var snap = await Db.Queryable().FirstAsync(x => x.CourseId == courseId); - - var exam = await Db.Queryable() - .Where(x => x.Status == DIC_EXAM_STATUS.RELEASED && - x.CourseId == courseId - && ((x.DateType == DicExamDateType.EXAM_DATE - && x.BeginTime.Value.Date <= DateTime.Now.Date && x.EndTime.Value.Date >= DateTime.Now.Date) || x.DateType == DicExamDateType.AFTER_HOW_LONG)) - .FirstAsync(); - await base.Add(new InsertGhre_StudyRecordInput - { - StaffId = staffId, - CourseSnapId = snap?.Id, - CourseId = courseId, - JoinTime = courseTime, - CourseBeginTime = courseTime.Date, - CourseEndTime = courseTime.Date.AddMonths(snap?.ValidityPeriod ?? 1), - CourseType = "ManualElective", - CourseStatus = DIC_STUDY_RECORD_COURSE_STATUS_IN, - StudyStatus = DIC_STUDY_RECORD_STUDY_STATUS.NO_JOIN, - ExamId = exam?.Id - }); - } - return ServiceResult.OprateSuccess("加入成功!"); + StaffId = staffId, + CourseSnapId = snap?.Id, + CourseId = courseId, + JoinTime = courseTime, + CourseBeginTime = courseTime.Date, + CourseEndTime = courseTime.Date.AddMonths(snap?.ValidityPeriod ?? 1), + CourseType = "ManualElective", + CourseStatus = DIC_STUDY_RECORD_COURSE_STATUS_IN, + StudyStatus = DIC_STUDY_RECORD_STUDY_STATUS.NO_JOIN, + ExamId = exam?.Id + }); } - #endregion + 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); + #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)); + await Task.Factory.StartNew(async () => await GenerateStaffStudyRecord(Db, studyRecordId)); - return ServiceResult.OprateSuccess("记录成功!"); - } + return ServiceResult.OprateSuccess("记录成功!"); + } - public async Task GenerateStaffStudyRecord(ISqlSugarClient Db, long studyRecordId) - { - var record = await Db.Queryable().FirstAsync(x => x.Id == studyRecordId); + 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 + 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); + var mins = await Db.Ado.GetDecimalAsync(sql); - if (mins > 0) - { - var duration = record.StudyDuration ?? 0; - studyProgress = (duration / mins) * 100; - if (studyProgress > 100) - studyProgress = 100; - } + if (mins > 0) + { + var duration = record.StudyDuration ?? 0; + studyProgress = (duration / mins) * 100; + if (studyProgress > 100) + studyProgress = 100; + } - var studyStatus = DIC_STUDY_RECORD_STUDY_STATUS.NO_FINISH; - if (studyProgress == 100) - studyStatus = DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH; + var studyStatus = DIC_STUDY_RECORD_STUDY_STATUS.NO_FINISH; + if (studyProgress == 100) + studyStatus = DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH; - sql = $"UPDATE Ghre_StudyRecord SET StudyProgress = {studyProgress},StudyStatus='{studyStatus}',StandardDuration='{mins}' WHERE Id='{studyRecordId}'"; - if (studyProgress > 0) await Db.Ado.ExecuteCommandAsync(sql); - sql = $"UPDATE Ghre_StudyRecord SET BeginTime=GETDATE(),StudyStatus='{studyStatus}' WHERE BeginTime IS NULL AND Id='{studyRecordId}'"; - await Db.Ado.ExecuteCommandAsync(sql); + sql = $"UPDATE Ghre_StudyRecord SET StudyProgress = {studyProgress},StudyStatus='{studyStatus}',StandardDuration='{mins}' WHERE Id='{studyRecordId}'"; + if (studyProgress > 0) await Db.Ado.ExecuteCommandAsync(sql); + sql = $"UPDATE Ghre_StudyRecord SET BeginTime=GETDATE(),StudyStatus='{studyStatus}' WHERE BeginTime IS NULL AND Id='{studyRecordId}'"; + await Db.Ado.ExecuteCommandAsync(sql); - if (studyProgress == 100) - { - sql = $"UPDATE Ghre_StudyRecord SET EndTime=GETDATE() WHERE EndTime IS NULL AND Id='{studyRecordId}'"; - await Db.Ado.ExecuteCommandAsync(sql); - } - return true; + if (studyProgress == 100) + { + sql = $"UPDATE Ghre_StudyRecord SET EndTime=GETDATE() WHERE EndTime IS NULL AND Id='{studyRecordId}'"; + await Db.Ado.ExecuteCommandAsync(sql); } - #endregion + return true; } + #endregion } \ No newline at end of file diff --git a/Tiobon.Core/Tiobon.Core.xml b/Tiobon.Core/Tiobon.Core.xml index 2680aa80..675be4a8 100644 --- a/Tiobon.Core/Tiobon.Core.xml +++ b/Tiobon.Core/Tiobon.Core.xml @@ -991,6 +991,13 @@ + + + 获取学习记录 + + + + 获取课程