|
|
|
@ -14,6 +14,7 @@ using Microsoft.AspNetCore.Http; |
|
|
|
|
using Tiobon.Core.Common.UserManager; |
|
|
|
|
using Tiobon.Core.Common.Helper; |
|
|
|
|
using AgileObjects.AgileMapper; |
|
|
|
|
using static Tiobon.Core.Model.Consts; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
@ -266,7 +267,7 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
|
|
|
|
|
public async Task<ServiceResult> UpdateStatus(long[] ids, string status) |
|
|
|
|
{ |
|
|
|
|
if (status != "Released" && status != "Disabled" && status != "Draft") |
|
|
|
|
if (status != Consts.DIC_COURSE_STATUS.RELEASED && status != Consts.DIC_COURSE_STATUS.DISABLED && status != Consts.DIC_COURSE_STATUS.DRAFT) |
|
|
|
|
throw new Exception("无效的状态"); |
|
|
|
|
|
|
|
|
|
HttpRequest request = UserContext.Context.Request; |
|
|
|
@ -281,25 +282,60 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
|
|
|
|
|
var entity = await BaseDal.QueryById(id); |
|
|
|
|
|
|
|
|
|
if (entity.Status == "Released") |
|
|
|
|
#region 关联数据有效性验证 |
|
|
|
|
if (entity.Status == Consts.DIC_COURSE_STATUS.DRAFT && status == Consts.DIC_COURSE_STATUS.RELEASED) |
|
|
|
|
{ |
|
|
|
|
var examPaper = await Db.Queryable<Ghre_ExamPaper>().FirstAsync(x => x.LinkId == id && x.LinkType == "CourseId" && x.Status != "Disabled"); |
|
|
|
|
if (!entity.CourseClassId.IsNull()) |
|
|
|
|
{ |
|
|
|
|
var CourseClassIds = JsonConvert.DeserializeObject<List<long>>(entity.CourseClassId); |
|
|
|
|
if (CourseClassIds != null && CourseClassIds.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < CourseClassIds.Count; i++) |
|
|
|
|
{ |
|
|
|
|
if (!await Db.Queryable<Ghre_CourseClass>().AnyAsync(x => x.Id == CourseClassIds[i])) |
|
|
|
|
throw new Exception($"课程关联的课程分类已失效,请修正数据后继续发布!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!entity.CourseSceneId.IsNull()) |
|
|
|
|
if (!await Db.Queryable<Ghre_CourseScene>().AnyAsync(x => x.Id == entity.CourseSceneId)) |
|
|
|
|
return ServiceResult.OprateFailed($"课程关联的课程场景已失效,请修正数据后继续发布!"); |
|
|
|
|
|
|
|
|
|
if (!entity.ExamPaperId.IsNull()) |
|
|
|
|
{ |
|
|
|
|
var ExamPaperIds = JsonConvert.DeserializeObject<List<long>>(entity.ExamPaperId); |
|
|
|
|
if (ExamPaperIds != null && ExamPaperIds.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < ExamPaperIds.Count; i++) |
|
|
|
|
{ |
|
|
|
|
if (!await Db.Queryable<Ghre_ExamPaper>().AnyAsync(x => x.Id == ExamPaperIds[0] && x.Status == DIC_EXAM_PAPER_STATUS.RELEASED)) |
|
|
|
|
return ServiceResult.OprateFailed($"课程关联的试卷已失效,请修正数据后继续发布!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
#endregion |
|
|
|
|
|
|
|
|
|
if (entity.Status == Consts.DIC_COURSE_STATUS.RELEASED) |
|
|
|
|
{ |
|
|
|
|
var examPaper = await Db.Queryable<Ghre_ExamPaper>().FirstAsync(x => x.LinkId == id && x.LinkType == "CourseId" && x.Status != Consts.DIC_COURSE_STATUS.DISABLED); |
|
|
|
|
if (examPaper != null) |
|
|
|
|
return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】已与试卷【{examPaper.PaperName}({examPaper.PaperName})】关联,暂不可{(status == "Draft" ? "取消发布" : "停用")}"); |
|
|
|
|
return ServiceResult.OprateFailed($"课程【{entity.CourseName}({entity.CourseNo})】已与试卷【{examPaper.PaperName}({examPaper.PaperName})】关联,暂不可{(status == Consts.DIC_COURSE_STATUS.DRAFT ? "取消发布" : "停用")}"); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BasePoco ent = entity; |
|
|
|
|
ent.UpdateIP = ip; |
|
|
|
|
ent.UpdateProg = api; |
|
|
|
|
if (status == "Released" || status == "Disabled" || status == "Draft") |
|
|
|
|
if (status == Consts.DIC_COURSE_STATUS.RELEASED || status == Consts.DIC_COURSE_STATUS.DISABLED || status == Consts.DIC_COURSE_STATUS.DRAFT) |
|
|
|
|
{ |
|
|
|
|
entity.Status = status; |
|
|
|
|
entities.Add(entity); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region 生成课程快照 |
|
|
|
|
if (status == "Released") |
|
|
|
|
if (status == Consts.DIC_COURSE_STATUS.RELEASED) |
|
|
|
|
{ |
|
|
|
|
var sql = $"UPDATE Ghre_CourseSnap SET IsEnable = 0 WHERE CourseId = '{id}' AND IsEnable = 1"; |
|
|
|
|
await Db.Ado.ExecuteCommandAsync(sql); |
|
|
|
@ -315,9 +351,9 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var result = await BaseDal.Update(entities); |
|
|
|
|
if (status == "Released") |
|
|
|
|
if (status == Consts.DIC_COURSE_STATUS.RELEASED) |
|
|
|
|
return ServiceResult.OprateSuccess("发布成功!"); |
|
|
|
|
else if (status == "Draft") |
|
|
|
|
else if (status == Consts.DIC_COURSE_STATUS.DRAFT) |
|
|
|
|
return ServiceResult.OprateSuccess("已启用成功,请进入草稿箱查看!"); |
|
|
|
|
else |
|
|
|
|
return ServiceResult.OprateSuccess("停用成功!"); |
|
|
|
@ -328,7 +364,7 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
{ |
|
|
|
|
entity.ExamPaperId = JsonHelper.ObjToJson(entity.ExamPaperIds); |
|
|
|
|
entity.CourseClassId = JsonHelper.ObjToJson(entity.CourseClassIds); |
|
|
|
|
entity.Status = "Draft"; |
|
|
|
|
entity.Status = Consts.DIC_COURSE_STATUS.DRAFT; |
|
|
|
|
entity.DefaultCoverImageName = entity.DefaultCoverImageName ?? "defaultCourseCover1"; |
|
|
|
|
entity.UseDefaultCoverImage = entity.UseDefaultCoverImage ?? true; |
|
|
|
|
return await base.Add(entity); |
|
|
|
@ -339,6 +375,38 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
|
|
|
|
|
editModel.ExamPaperId = JsonHelper.ObjToJson(editModel.ExamPaperIds); |
|
|
|
|
editModel.CourseClassId = JsonHelper.ObjToJson(editModel.CourseClassIds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!editModel.CourseClassId.IsNull()) |
|
|
|
|
{ |
|
|
|
|
var CourseClassIds = JsonConvert.DeserializeObject<List<long>>(editModel.CourseClassId); |
|
|
|
|
if (CourseClassIds != null && CourseClassIds.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < CourseClassIds.Count; i++) |
|
|
|
|
{ |
|
|
|
|
if (!await Db.Queryable<Ghre_CourseClass>().AnyAsync(x => x.Id == CourseClassIds[i])) |
|
|
|
|
throw new Exception($"课程关联的课程分类已失效,请修正数据后继续发布!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!editModel.CourseSceneId.IsNull()) |
|
|
|
|
if (!await Db.Queryable<Ghre_CourseScene>().AnyAsync(x => x.Id == editModel.CourseSceneId)) |
|
|
|
|
throw new Exception($"课程关联的课程场景已失效,请修正数据后继续发布!"); |
|
|
|
|
|
|
|
|
|
if (!editModel.ExamPaperId.IsNull()) |
|
|
|
|
{ |
|
|
|
|
var ExamPaperIds = JsonConvert.DeserializeObject<List<long>>(editModel.ExamPaperId); |
|
|
|
|
if (ExamPaperIds != null && ExamPaperIds.Any()) |
|
|
|
|
{ |
|
|
|
|
for (int i = 0; i < ExamPaperIds.Count; i++) |
|
|
|
|
{ |
|
|
|
|
if (!await Db.Queryable<Ghre_ExamPaper>().AnyAsync(x => x.Id == ExamPaperIds[i] && x.Status == DIC_EXAM_PAPER_STATUS.RELEASED)) |
|
|
|
|
throw new Exception($"课程关联的试卷已失效,请修正数据后继续发布!"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return await base.Update(Id, editModel); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -370,7 +438,7 @@ public class Ghre_CourseServices : BaseServices<Ghre_Course, Ghre_CourseDto, Ins |
|
|
|
|
]; |
|
|
|
|
TableColumn.Add(searchItem); |
|
|
|
|
|
|
|
|
|
sql = $"SELECT Id, CourseNo , CourseName FROM Ghre_Course WHERE Status ='Released' AND IsEnable=1"; |
|
|
|
|
sql = $"SELECT Id, CourseNo , CourseName FROM Ghre_Course WHERE Status ='{Consts.DIC_COURSE_STATUS.RELEASED}' AND IsEnable=1"; |
|
|
|
|
if (!string.IsNullOrWhiteSpace(keyWords)) |
|
|
|
|
sql += $"AND ( CourseNo like '%{keyWords}%' or CourseName like '%{keyWords}%')"; |
|
|
|
|
|
|
|
|
|