diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs index 738b897a..3fd6f925 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseServices.cs @@ -253,7 +253,7 @@ public class Ghre_CourseServices : BaseServices UpdateStatus(long[] ids, string status) { - if (status != Consts.DIC_COURSE_STATUS.RELEASED && status != Consts.DIC_COURSE_STATUS.DISABLED && status != Consts.DIC_COURSE_STATUS.DRAFT) + if (status != DIC_COURSE_STATUS.RELEASED && status != DIC_COURSE_STATUS.DISABLED && status != DIC_COURSE_STATUS.DRAFT) throw new Exception("无效的状态"); HttpRequest request = UserContext.Context.Request; @@ -269,7 +269,7 @@ public class Ghre_CourseServices : BaseServices new { it.CourseIds }).ExecuteCommandAsync(); - } #endregion } #endregion - if (entity.Status == Consts.DIC_COURSE_STATUS.RELEASED) + if (entity.Status == DIC_COURSE_STATUS.RELEASED) { - var examPaper = await Db.Queryable().FirstAsync(x => x.LinkId == id && x.LinkType == "CourseId" && x.Status != Consts.DIC_COURSE_STATUS.DISABLED); + var examPaper = await Db.Queryable().FirstAsync(x => x.LinkId == id && x.LinkType == "CourseId" && x.Status != DIC_COURSE_STATUS.DISABLED); + if (examPaper is null && entity.CourseSceneId != null) + examPaper = await Db.Queryable().FirstAsync(x => x.LinkId == entity.CourseSceneId && x.LinkType == "CourseSceneId" && x.Status != DIC_COURSE_STATUS.DISABLED); if (examPaper != null) - return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】已与试卷【{examPaper.PaperName}({examPaper.PaperName})】关联,暂不可{(status == Consts.DIC_COURSE_STATUS.DRAFT ? "取消发布" : "停用")}"); - - if (await Db.Queryable().AnyAsync(x => x.CourseId == id && x.StudyStatus != Consts.DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH && x.CourseEndTime != null && x.CourseEndTime.Value.Date >= DateTime.Now.Date)) - return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】有学员正在学习中,暂不可{(status == Consts.DIC_COURSE_STATUS.DRAFT ? "取消发布" : "停用")}"); + return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】已与试卷【{examPaper.PaperName}({examPaper.PaperName})】关联,暂不可{(status == DIC_COURSE_STATUS.DRAFT ? "取消发布" : "停用")}"); + if (await Db.Queryable().AnyAsync(x => x.CourseId == id && x.StudyStatus != DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH && x.CourseEndTime != null && x.CourseEndTime.Value.Date >= DateTime.Now.Date) || await Db.Queryable().AnyAsync(x => x.CourseId == id && x.StudyStatus != DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH && x.CourseEndTime != null && x.CourseEndTime.Value.Date >= DateTime.Now.Date)) + return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】有学员正在学习中,暂不可{(status == DIC_COURSE_STATUS.DRAFT ? "取消发布" : "停用")}"); + else + { + if (entity.CourseWareId.IsNotEmptyOrNull()) + if (await Db.Queryable().AnyAsync(x => x.CourseSceneId == entity.CourseWareId && x.StudyStatus != DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH && x.CourseEndTime != null && x.CourseEndTime.Value.Date >= DateTime.Now.Date) || await Db.Queryable().AnyAsync(x => x.CourseId == id && x.StudyStatus != DIC_STUDY_RECORD_STUDY_STATUS.HAS_FINISH && x.CourseEndTime != null && x.CourseEndTime.Value.Date >= DateTime.Now.Date)) + return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】有学员正在学习中,暂不可{(status == DIC_COURSE_STATUS.DRAFT ? "取消发布" : "停用")}"); + } } entity.UpdateIP = ip; entity.UpdateProg = api; - if (status == Consts.DIC_COURSE_STATUS.RELEASED || status == Consts.DIC_COURSE_STATUS.DISABLED || status == Consts.DIC_COURSE_STATUS.DRAFT) + if (status == DIC_COURSE_STATUS.RELEASED || status == DIC_COURSE_STATUS.DISABLED || status == DIC_COURSE_STATUS.DRAFT) { entity.Status = status; entities.Add(entity); } #region 生成课程快照 - if (status == Consts.DIC_COURSE_STATUS.RELEASED) + if (status == DIC_COURSE_STATUS.RELEASED) { CheckCodeExist("Ghre_Course", "CourseNo", entity.CourseNo, ModifyType.Add, "【已发布】中课程编号", id, $"Status='{DIC_COURSE_STATUS.RELEASED}'"); var sql = $"UPDATE Ghre_CourseSnap SET IsEnable = 0 WHERE CourseId = '{id}' AND IsEnable = 1"; @@ -393,7 +397,7 @@ public class Ghre_CourseServices : BaseServices o.ClassName + "(" + o.ClassNo + ")")); entity1.CourseId = id; - var examPaper = await Db.Queryable().FirstAsync(x => x.LinkId == id && x.LinkType == "CourseId" && x.Status != Consts.DIC_COURSE_STATUS.DISABLED); + var examPaper = await Db.Queryable().FirstAsync(x => x.LinkId == id && x.LinkType == "CourseId" && x.Status != DIC_COURSE_STATUS.DISABLED); await _ghre_CourseSnapServices.Add(entity1); } #endregion @@ -405,8 +409,8 @@ public class Ghre_CourseServices : BaseServices() - .WhereIF(status == Consts.DIC_COURSE_STATUS.RELEASED, x => x.Id == id || (x.CourseSceneId == entity.CourseSceneId && x.Status == Consts.DIC_COURSE_STATUS.RELEASED)) - .WhereIF(status != Consts.DIC_COURSE_STATUS.RELEASED, x => x.Id != id || (x.CourseSceneId == entity.CourseSceneId && x.Status == Consts.DIC_COURSE_STATUS.RELEASED)) + .WhereIF(status == DIC_COURSE_STATUS.RELEASED, x => x.Id == id || (x.CourseSceneId == entity.CourseSceneId && x.Status == DIC_COURSE_STATUS.RELEASED)) + .WhereIF(status != DIC_COURSE_STATUS.RELEASED, x => x.Id != id || (x.CourseSceneId == entity.CourseSceneId && x.Status == DIC_COURSE_STATUS.RELEASED)) .ToListAsync(); courseScene.StandardHour = courses.Sum(x => x.StandardHour);