|
|
|
@ -1,7 +1,4 @@ |
|
|
|
|
using NPOI.SS.UserModel; |
|
|
|
|
using Tiobon.Core.IServices; |
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
/// 课程场景 (服务) |
|
|
|
@ -46,31 +43,70 @@ public class Ghre_CourseSceneServices : BaseServices<Ghre_CourseScene, Ghre_Cour |
|
|
|
|
|
|
|
|
|
public override async Task<long> Add(InsertGhre_CourseSceneInput entity) |
|
|
|
|
{ |
|
|
|
|
if (entity.CourseIds != null && entity.CourseIds.Any()) |
|
|
|
|
var courseIds = new List<long>(); |
|
|
|
|
if (entity.Courses != null && entity.Courses.Any()) |
|
|
|
|
{ |
|
|
|
|
courseIds = entity.Courses.Select(x => x.Id).ToList(); |
|
|
|
|
entity.CourseId = JsonHelper.ObjToJson(courseIds); |
|
|
|
|
|
|
|
|
|
entity.CourseId = JsonHelper.ObjToJson(entity.CourseIds); |
|
|
|
|
|
|
|
|
|
var list = Db.Queryable<Ghre_Course>().Where(x => entity.CourseIds.Contains(x.Id.ToString())).Select(x => x.CourseName).ToList(); |
|
|
|
|
var list = Db.Queryable<Ghre_Course>().Where(x => courseIds.Contains(x.Id)).Select(x => x.CourseName).ToList(); |
|
|
|
|
|
|
|
|
|
entity.CourseName = string.Join("、", list.Select(x => x).ToArray()); |
|
|
|
|
entity.CourseName = string.Join("、", list.ToArray()); |
|
|
|
|
} |
|
|
|
|
var id = await base.Add(entity); |
|
|
|
|
var courses = Db.Queryable<Ghre_Course>().Where(x => courseIds.Contains(x.Id)).ToList(); |
|
|
|
|
for (int i = 0; i < courses.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var courseSceneIds = new List<long>(); |
|
|
|
|
if (courses[i].CourseSceneIds.IsNotEmptyOrNull()) |
|
|
|
|
courseSceneIds = JsonHelper.JsonToObj<List<long>>(courses[i].CourseSceneIds); |
|
|
|
|
courseSceneIds.Add(id); |
|
|
|
|
courses[i].CourseSceneIds = JsonHelper.ObjToJson(courseSceneIds); |
|
|
|
|
await Db.Updateable(courses).UpdateColumns(it => new { it.CourseSceneIds }, true)//true表示追加AOP赋值列 |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
} |
|
|
|
|
return await base.Add(entity); |
|
|
|
|
return id; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public override async Task<bool> Update(long Id, EditGhre_CourseSceneInput editModel) |
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
if (editModel.CourseIds != null && editModel.CourseIds.Any()) |
|
|
|
|
var courseIds = new List<long>(); |
|
|
|
|
if (editModel.Courses != null && editModel.Courses.Any()) |
|
|
|
|
{ |
|
|
|
|
courseIds = editModel.Courses.Select(x => x.Id).ToList(); |
|
|
|
|
editModel.CourseId = JsonHelper.ObjToJson(courseIds); |
|
|
|
|
|
|
|
|
|
editModel.CourseId = JsonHelper.ObjToJson(editModel.CourseIds); |
|
|
|
|
|
|
|
|
|
var list = Db.Queryable<Ghre_Course>().Where(x => editModel.CourseIds.Contains(x.Id.ToString())).Select(x => x.CourseName).ToList(); |
|
|
|
|
var list = Db.Queryable<Ghre_Course>().Where(x => courseIds.Contains(x.Id)).Select(x => x.CourseName).ToList(); |
|
|
|
|
|
|
|
|
|
editModel.CourseName = string.Join("、", list.Select(x => x).ToArray()); |
|
|
|
|
} |
|
|
|
|
return await base.Update(Id, editModel); |
|
|
|
|
var result = await base.Update(Id, editModel); |
|
|
|
|
|
|
|
|
|
var courses = await Db.Queryable<Ghre_Course>().Where(x => x.CourseSceneIds != null && x.CourseSceneIds.Contains(Id.ObjToString())).ToListAsync(); |
|
|
|
|
|
|
|
|
|
for (int j = 0; j < courses.Count; j++) |
|
|
|
|
{ |
|
|
|
|
var courseSceneIds = new List<long>(); |
|
|
|
|
if (courses[j].CourseSceneIds.IsNotEmptyOrNull()) |
|
|
|
|
courseSceneIds = JsonHelper.JsonToObj<List<long>>(courses[j].CourseSceneIds); |
|
|
|
|
courseSceneIds = courseSceneIds.Where(x => x != Id).ToList(); |
|
|
|
|
courses[j].CourseSceneIds = JsonHelper.ObjToJson(courseSceneIds); |
|
|
|
|
await Db.Updateable(courses).UpdateColumns(it => new { it.CourseSceneIds }, true)//true表示追加AOP赋值列 |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
} |
|
|
|
|
courses = Db.Queryable<Ghre_Course>().Where(x => courseIds.Contains(x.Id)).ToList(); |
|
|
|
|
for (int i = 0; i < courses.Count; i++) |
|
|
|
|
{ |
|
|
|
|
var courseSceneIds = new List<long>(); |
|
|
|
|
if (courses[i].CourseSceneIds.IsNotEmptyOrNull()) |
|
|
|
|
courseSceneIds = JsonHelper.JsonToObj<List<long>>(courses[i].CourseSceneIds); |
|
|
|
|
courseSceneIds.Add(Id); |
|
|
|
|
courses[i].CourseSceneIds = JsonHelper.ObjToJson(courseSceneIds); |
|
|
|
|
await Db.Updateable(courses).UpdateColumns(it => new { it.CourseSceneIds }, true)//true表示追加AOP赋值列 |
|
|
|
|
.ExecuteCommandAsync(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#region Excel导入 |
|
|
|
|