From 508bb62898312ac80f30bd1c52df0a0d9c251317 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Fri, 21 Feb 2025 15:36:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E7=8F=ADEss=E7=AB=AF=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=8E=A5=E5=8F=A3=E5=BC=80=E5=8F=91=20=E5=BC=80?= =?UTF-8?q?=E7=8F=ADEss=E9=A1=B5=E9=9D=A2=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ghre/Ghre_OpenClassController.cs | 2 +- Tiobon.Core.Services/CommonServices.cs | 3 +- .../Ghre/Ghre_CourseServices.cs | 3 +- .../Ghre/Ghre_OpenClassServices.cs | 10 +- .../Ghre/Ghre_StudyRecordServices.cs | 327 ++++++++++++++++-- 5 files changed, 312 insertions(+), 33 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Ghre/Ghre_OpenClassController.cs b/Tiobon.Core.Api/Controllers/Ghre/Ghre_OpenClassController.cs index bc20d34b..a1cb68b9 100644 --- a/Tiobon.Core.Api/Controllers/Ghre/Ghre_OpenClassController.cs +++ b/Tiobon.Core.Api/Controllers/Ghre/Ghre_OpenClassController.cs @@ -120,7 +120,7 @@ public class Ghre_OpenClassController : BaseController TransferPublished(long Id) => await _service.UpdateStatus([Id], "Publish"); [HttpPost, Route("TransferPublished")] - public async Task TransferPublished([FromBody] List Ids) => await _service.UpdateStatus(Ids, "Publish"); + public async Task TransferPublished([FromBody] List Ids) => await _service.UpdateStatus(Ids, "Publish", "TransferPublished"); #endregion #region 取消发布 diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 8b5df98d..a0d3d028 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -1049,7 +1049,8 @@ public partial class CommonServices : BaseServices>, ICommon case "F_CourseClassification": case "F_CourseScene": index = result.JM_PageControlT1.Toolbar.FindIndex(x => x.fnKey == "BatchUpdateYN"); - result.JM_PageControlT1.Toolbar.RemoveAt(index); + if (index >= 0) + result.JM_PageControlT1.Toolbar.RemoveAt(index); result.JM_PageControlT1.Toolbar.Insert(0, new Toolbar() { diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index aab3e8b5..e407a83c 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -285,7 +285,8 @@ public class Ghre_CourseServices : BaseServices classsIds.Contains(x.Id)); var courseSceneIds = new List(); - courseSceneIds = courseSceneIds.Concat(JsonConvert.DeserializeObject>(DT_TableDataT1.CourseSceneIds)).ToList(); + if (DT_TableDataT1.CourseSceneIds.IsNotEmptyOrNull()) + courseSceneIds = courseSceneIds.Concat(JsonConvert.DeserializeObject>(DT_TableDataT1.CourseSceneIds)).ToList(); courseSceneIds = courseSceneIds.Distinct().ToList(); var courseScenes = await Db.Queryable().Where(x => courseSceneIds.Contains(x.Id)).ToListAsync(); diff --git a/Tiobon.Core.Services/Ghre/Ghre_OpenClassServices.cs b/Tiobon.Core.Services/Ghre/Ghre_OpenClassServices.cs index fe8005e8..b262960e 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_OpenClassServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_OpenClassServices.cs @@ -133,7 +133,7 @@ public class Ghre_OpenClassServices : BaseServices x.RelativePath).ToList(); + var paths = entity.Attachments.Select(x => x.RelativePath.Replace("/Advanced", null)).ToList(); await Db.Updateable() .SetColumns(it => new Ghre_Attachment() { TableName = result.ObjToString(), AttachmentGroupID = 1 }) .Where(it => paths.Contains(it.RelativePath)) @@ -176,7 +176,7 @@ public class Ghre_OpenClassServices : BaseServices x.RelativePath).ToList(); + var paths = entity.Attachments.Select(x => x.RelativePath.Replace("/Advanced", null)).ToList(); await Db.Updateable() .SetColumns(it => new Ghre_Attachment() { TableName = Id.ObjToString(), AttachmentGroupID = 1 }) .Where(it => paths.Contains(it.RelativePath)) @@ -222,7 +222,7 @@ public class Ghre_OpenClassServices : BaseServices InsertStaff(long Id, List staffIds) { - var staffIds1 = await Db.Queryable().Select(s => s.StaffId).ToListAsync(); + var staffIds1 = await Db.Queryable().Where(x => x.OpenClassId == Id).Select(s => s.StaffId).ToListAsync(); var inserts = staffIds.Where(x => !staffIds1.Contains(x)) .Select(x => new InsertGhre_OpenClassStaffInput() { @@ -298,7 +298,7 @@ public class Ghre_OpenClassServices : BaseServices x.RelativePath).ToList(); + var paths = entity.Attachments.Select(x => x.RelativePath.Replace("/Advanced", null)).ToList(); await Db.Updateable() .SetColumns(it => new Ghre_Attachment() { TableName = Id.ObjToString(), AttachmentGroupID = 2 }) .Where(it => paths.Contains(it.RelativePath)) @@ -315,7 +315,7 @@ public class Ghre_OpenClassServices : BaseServices ids.Contains(x.Id)); diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index a317798f..0c73d183 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -855,19 +855,38 @@ public class Ghre_StudyRecordServices : BaseServices public async Task> QueryESS(QueryBody filter, string condition, bool? IsEnable = true) { - if (await QueryCompanyCode() == "Ushio" && string.IsNullOrWhiteSpace(filter.orderBy)) - { - filter.orderBy = "CoursePublishTime DESC"; - } + + string courseType = "Required"; + if (filter.jsonParam != null) + foreach (JProperty jProperty in filter.jsonParam.Properties()) + { + var name = jProperty.Name; + var value = jProperty.Value.ToString(); + + if (name == "CourseType") + { + var jsonParam = JsonConvert.DeserializeObject(value); + courseType = jsonParam.columnValue.ObjToString(); + + continue; + } + } + + if (courseType == "OpenClass") + return await QueryOpenClass(filter, condition, IsEnable); + else - if (string.IsNullOrWhiteSpace(filter.orderBy)) - filter.orderBy = "JoinTime DESC"; + { + if (await QueryCompanyCode() == "Ushio" && string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "CoursePublishTime DESC"; + else if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "JoinTime 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 A.Id, + var countSql = @$" SELECT COUNT(1) FROM Ghre_StudyRecord_V"; + var sql = @$" SELECT A.Id, A.StaffId, A.CourseSnapId, A.CourseId, @@ -892,12 +911,277 @@ public class Ghre_StudyRecordServices : BaseServices(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 == "CourseType") + { + var jsonParam = JsonConvert.DeserializeObject(value); + + var value1 = jsonParam.columnValue; + conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; + + continue; + } + + if (name == "CourseStatus") + { + var jsonParam = JsonConvert.DeserializeObject(value); + var dtTime = DateTime.Now; + var value1 = jsonParam.columnValue; + switch (value1) + { + case "In": + conditions += $" AND '{DateTimeHelper.ConvertToSecondString(dtTime)}' BETWEEN CourseBeginTime AND CourseEndTime"; + break; + case "Over": + conditions += $" AND CourseEndTime >'{DateTimeHelper.ConvertToSecondString(dtTime)}'"; + break; + case "NOStart": + conditions += $" AND CourseBeginTime >'{DateTimeHelper.ConvertToSecondString(dtTime)}'"; + break; + default: + break; + } + continue; + } + + if (!string.IsNullOrWhiteSpace(value)) + { + 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; + } + } + } + + 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 += " 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); + + 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.StudyProgress < 100 || x.ExamId.IsNull()) + x.DisableExamBtn = true; + if (x.FeedbackOrderId.IsNull()) + x.ShowFeedbackBtn = false; + + #region 处理学习进度 + + 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.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); + } + } + + public async Task> QueryOpenClass(QueryBody filter, string condition, bool? IsEnable = true) + { + if (string.IsNullOrWhiteSpace(filter.orderBy)) + filter.orderBy = "PublishTime DESC"; + + if (filter.pageSize == 0) + filter.pageSize = 10000; + + var staffId = App.User.StaffId; + var sql = @$"SELECT A.Id, + A.StartTime CourseBeginDate, + A.EndTime CourseEndDate, + A.RegisterStartTime, + A.RegisterEndTime, + A.ExamStartTime ExamBeginDate, + A.ExamEndTime ExamEndDate, + isnull (C.CourseName, D.SceneName) CourseName, + isnull (C.StandardHour, D.StandardHour) StandardHour, + isnull + ( + C.CoverUrl, + '/File/UploadPath/41_20240807204236365_Snipaste_2024-08-07_20-41-44.png') CoverUrl, + C.UseDefaultCoverImage, + C.DefaultCoverImageName, + isnull (C.CreditPoints, D.CreditPoints) CreditPoints, + 'ExamDate' ExamDateType, + A.ExamId, + E.Status ExamStatus, A.CreateTime PublishTime +FROM Ghre_OpenClass A + JOIN Ghre_StaffGroup B ON A.StaffGroupId = B.Id + LEFT JOIN Ghre_Course C ON A.LinkId = C.Id + LEFT JOIN Ghre_CourseScene D ON A.LinkId = D.Id + LEFT JOIN Ghre_Exam E ON A.ExamId = E.Id +WHERE EXISTS ( + SELECT 1 + FROM Ghra_Staff A + WHERE A.StaffID = '{staffId}' + AND A.StaffID IN ( + SELECT value + FROM OPENJSON(B.StaffId) + ) + AND A.StaffID NOT IN ( + SELECT value + FROM OPENJSON(B.ExclStaffId) + ) + AND A.StaffType1 IN ( + SELECT value + FROM OPENJSON(B.StaffType1) + ) + AND A.StaffType2 IN ( + SELECT value + FROM OPENJSON(B.StaffType2) + ) + AND A.ZoneId IN ( + SELECT value + FROM OPENJSON(B.ZoneId) + ) + AND A.ZoneId NOT IN ( + SELECT value + FROM OPENJSON(B.ExclZoneId) + ) + AND A.DeptId IN ( + SELECT value + FROM OPENJSON(B.DeptId) + ) + AND A.DeptId NOT IN ( + SELECT value + FROM OPENJSON(B.ExclDeptId) + ) + AND A.TitleId IN ( + SELECT value + FROM OPENJSON(B.TitleId) + ) + AND A.TitleId NOT IN ( + SELECT value + FROM OPENJSON(B.ExclTitleId) + ) + AND A.GradeId IN ( + SELECT value + FROM OPENJSON(B.GradeId) + ) + AND A.GradeId NOT IN ( + SELECT value + FROM OPENJSON(B.ExclGradeId) + ) + AND A.JobId IN ( + SELECT value + FROM OPENJSON(B.JobId) + ) + AND A.JobId NOT IN ( + SELECT value + FROM OPENJSON(B.ExclJobId) + ) + ) + OR EXISTS ( + SELECT 1 + FROM Ghre_OpenClassStaff C + WHERE C.OpenClassId = A.ID + AND c.StaffId = '{staffId}' + )"; + + string conditions = $""; if (!string.IsNullOrWhiteSpace(condition)) conditions += " AND " + condition; @@ -925,14 +1209,7 @@ public class Ghre_StudyRecordServices : BaseServices(value); - - var value1 = jsonParam.columnValue; - conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; - continue; - } if (name == "CourseStatus") { @@ -998,8 +1275,9 @@ public class Ghre_StudyRecordServices : BaseServices(filter.pageNum, total, filter.pageSize, entitys); - } #endregion