From e67a52fd21580a12a59298aa45acecb916278d4a Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Wed, 7 Aug 2024 08:59:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Ghre/Ghre_ExamServices.cs | 51 +++++++++++-------- .../Ghre/Ghre_StudyRecordServices.cs | 11 ++++ 2 files changed, 41 insertions(+), 21 deletions(-) diff --git a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs index 3399ab19..3306fee3 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_ExamServices.cs @@ -1261,30 +1261,11 @@ public class Ghre_ExamServices : BaseServices x.ExamId == id && x.Source == Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED); var inserts = new List(); - ; + var snap = await Db.Queryable().FirstAsync(x => x.CourseId == entity.CourseId); DateTime courseTime = Db.GetDate(); - for (int i = 0; i < staffs.Count; i++) - { - var staff = staffs[i]; - inserts.Add(new Ghre_StudyRecord() - { - StaffId = staff.StaffId, - ExamId = id, - CourseSnapId = snap?.Id, - CourseId = entity.CourseId, - CourseSceneId = entity.CourseSceneId, - JoinTime = courseTime, - CourseBeginTime = courseTime.Date, - CourseEndTime = courseTime.Date.AddMonths(snap?.ValidityPeriod ?? 1), - CourseType = Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED, - CourseStatus = Consts.DIC_STUDY_RECORD_COURSE_STATUS_IN, - StudyStatus = Consts.DicStudyRecordStudyStatus.NO_JOIN - }); - } - if (inserts.Any()) - await Db.Insertable(inserts).ExecuteReturnSnowflakeIdListAsync(); + #region 自动给学习记录匹配考试ID var studyRecords = await Db.Queryable() @@ -1294,6 +1275,34 @@ public class Ghre_ExamServices : BaseServices x.ExamId = entity.Id); await Db.Updateable(studyRecords).UpdateColumns(it => new { it.ExamId }).ExecuteCommandAsync(); #endregion + + for (int i = 0; i < staffs.Count; i++) + { + var staff = staffs[i]; + + var exist = await Db.Queryable() + .WhereIF(!entity.CourseId.IsNull(), x => x.CourseId == entity.CourseId) + .WhereIF(!entity.CourseSceneId.IsNull(), x => x.CourseSceneId == entity.CourseSceneId) + .Where(x => x.ExamId == id && x.StaffId == staff.StaffId ).AnyAsync(); + + if (!exist) + inserts.Add(new Ghre_StudyRecord() + { + StaffId = staff.StaffId, + ExamId = id, + CourseSnapId = snap?.Id, + CourseId = entity.CourseId, + CourseSceneId = entity.CourseSceneId, + JoinTime = courseTime, + CourseBeginTime = courseTime.Date, + CourseEndTime = courseTime.Date.AddMonths(snap?.ValidityPeriod ?? 1), + CourseType = Consts.DIC_EXAM_STAFF_SOURCE.MANUAL_REQUIRED, + CourseStatus = Consts.DIC_STUDY_RECORD_COURSE_STATUS_IN, + StudyStatus = Consts.DicStudyRecordStudyStatus.NO_JOIN + }); + } + if (inserts.Any()) + await Db.Insertable(inserts).ExecuteReturnSnowflakeIdListAsync(); } #endregion diff --git a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs index 21858ec1..0830bb2f 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_StudyRecordServices.cs @@ -241,6 +241,15 @@ namespace Tiobon.Core.Services continue; } + if (name == "CourseType") + { + var jsonParam = JsonConvert.DeserializeObject(value); + + var value1 = jsonParam.columnValue; + conditions += $" AND {name} LIKE '%{jsonParam.columnValue}%'"; + + continue; + } if (!string.IsNullOrWhiteSpace(value)) { var jsonParam = JsonConvert.DeserializeObject(value); @@ -372,6 +381,8 @@ namespace Tiobon.Core.Services 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!"); if (course.CourseSceneId.IsNull()) {