|
|
@ -1,7 +1,8 @@ |
|
|
|
|
|
|
|
|
|
|
|
using System.Data; |
|
|
|
using System.Data; |
|
|
|
using System.Net.Mail; |
|
|
|
|
|
|
|
using Newtonsoft.Json; |
|
|
|
using Newtonsoft.Json; |
|
|
|
|
|
|
|
using Newtonsoft.Json.Linq; |
|
|
|
|
|
|
|
using NPOI.Util.Collections; |
|
|
|
using Tiobon.Core.Common; |
|
|
|
using Tiobon.Core.Common; |
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
using Tiobon.Core.Common.Caches; |
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
|
using Tiobon.Core.IRepository.Base; |
|
|
@ -10,97 +11,129 @@ using Tiobon.Core.Model; |
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
using Tiobon.Core.Model.Models; |
|
|
|
using Tiobon.Core.Services.BASE; |
|
|
|
using Tiobon.Core.Services.BASE; |
|
|
|
|
|
|
|
|
|
|
|
namespace Tiobon.Core.Services |
|
|
|
namespace Tiobon.Core.Services; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary> |
|
|
|
|
|
|
|
/// 课件 (服务) |
|
|
|
|
|
|
|
/// </summary> |
|
|
|
|
|
|
|
public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_CourseWareDto, InsertGhre_CourseWareInput, EditGhre_CourseWareInput>, IGhre_CourseWareServices |
|
|
|
{ |
|
|
|
{ |
|
|
|
/// <summary> |
|
|
|
private readonly IBaseRepository<Ghre_CourseWare> _dal; |
|
|
|
/// 课件 (服务) |
|
|
|
private IGhre_CourseServices _ghre_CourseServices; |
|
|
|
/// </summary> |
|
|
|
private IGhre_CourseWareAttachmentServices _ghre_CourseWareAttachmentServices; |
|
|
|
public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_CourseWareDto, InsertGhre_CourseWareInput, EditGhre_CourseWareInput>, IGhre_CourseWareServices |
|
|
|
|
|
|
|
|
|
|
|
public Ghre_CourseWareServices(ICaching caching, |
|
|
|
|
|
|
|
IGhre_CourseServices ghre_CourseServices, |
|
|
|
|
|
|
|
IGhre_CourseWareAttachmentServices ghre_CourseWareAttachmentServices, |
|
|
|
|
|
|
|
IBaseRepository<Ghre_CourseWare> dal) |
|
|
|
{ |
|
|
|
{ |
|
|
|
private readonly IBaseRepository<Ghre_CourseWare> _dal; |
|
|
|
this._dal = dal; |
|
|
|
private IGhre_CourseServices _ghre_CourseServices; |
|
|
|
base.BaseDal = dal; |
|
|
|
private IGhre_CourseWareAttachmentServices _ghre_CourseWareAttachmentServices; |
|
|
|
base._caching = caching; |
|
|
|
|
|
|
|
_ghre_CourseServices = ghre_CourseServices; |
|
|
|
public Ghre_CourseWareServices(ICaching caching, |
|
|
|
_ghre_CourseWareAttachmentServices = ghre_CourseWareAttachmentServices; |
|
|
|
IGhre_CourseServices ghre_CourseServices, |
|
|
|
} |
|
|
|
IGhre_CourseWareAttachmentServices ghre_CourseWareAttachmentServices, |
|
|
|
|
|
|
|
IBaseRepository<Ghre_CourseWare> dal) |
|
|
|
public override async Task<long> Add(InsertGhre_CourseWareInput entity) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (entity.CourseIds2.Any()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
this._dal = dal; |
|
|
|
entity.CourseIds = JsonConvert.SerializeObject(entity.CourseIds2); |
|
|
|
base.BaseDal = dal; |
|
|
|
var courses = await _ghre_CourseServices.Query(x => entity.CourseIds2.Contains(x.Id)); |
|
|
|
base._caching = caching; |
|
|
|
entity.CourseNames = string.Join(",", courses.Select(x => x.CourseName)); |
|
|
|
_ghre_CourseServices = ghre_CourseServices; |
|
|
|
|
|
|
|
_ghre_CourseWareAttachmentServices = ghre_CourseWareAttachmentServices; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var result = await base.Add(entity); |
|
|
|
|
|
|
|
entity.Attachments.ForEach(x => x.CourseWareId = result); |
|
|
|
|
|
|
|
await _ghre_CourseWareAttachmentServices.Add(entity.Attachments); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override async Task<long> Add(InsertGhre_CourseWareInput entity) |
|
|
|
public override async Task<bool> Update(long Id, EditGhre_CourseWareInput editModel) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (editModel.CourseIds2.Any()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (entity.CourseIds2.Any()) |
|
|
|
editModel.CourseIds = JsonConvert.SerializeObject(editModel.CourseIds2); |
|
|
|
{ |
|
|
|
var courses = await _ghre_CourseServices.Query(x => editModel.CourseIds2.Contains(x.Id)); |
|
|
|
entity.CourseIds = JsonConvert.SerializeObject(entity.CourseIds2); |
|
|
|
editModel.CourseNames = string.Join(",", courses.Select(x => x.CourseName)); |
|
|
|
var courses = await _ghre_CourseServices.Query(x => entity.CourseIds2.Contains(x.Id)); |
|
|
|
|
|
|
|
entity.CourseNames = string.Join(",", courses.Select(x => x.CourseName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
var result = await base.Add(entity); |
|
|
|
|
|
|
|
entity.Attachments.ForEach(x => x.CourseWareId = result); |
|
|
|
|
|
|
|
await _ghre_CourseWareAttachmentServices.Add(entity.Attachments); |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public override async Task<bool> Update(long Id, EditGhre_CourseWareInput editModel) |
|
|
|
await _ghre_CourseWareAttachmentServices.Delete(x => x.CourseWareId == Id); |
|
|
|
{ |
|
|
|
editModel.Attachments.ForEach(x => x.CourseWareId = Id); |
|
|
|
if (editModel.CourseIds2.Any()) |
|
|
|
await _ghre_CourseWareAttachmentServices.Add(editModel.Attachments); |
|
|
|
{ |
|
|
|
|
|
|
|
editModel.CourseIds = JsonConvert.SerializeObject(editModel.CourseIds2); |
|
|
|
|
|
|
|
var courses = await _ghre_CourseServices.Query(x => editModel.CourseIds2.Contains(x.Id)); |
|
|
|
|
|
|
|
editModel.CourseNames = string.Join(",", courses.Select(x => x.CourseName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await _ghre_CourseWareAttachmentServices.Delete(x => x.CourseWareId == Id); |
|
|
|
return await base.Update(Id, editModel); |
|
|
|
editModel.Attachments.ForEach(x => x.CourseWareId = Id); |
|
|
|
} |
|
|
|
await _ghre_CourseWareAttachmentServices.Add(editModel.Attachments); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await base.Update(Id, editModel); |
|
|
|
public override async Task<ServiceFormResult<Ghre_CourseWareDto>> QueryForm(QueryForm body) |
|
|
|
} |
|
|
|
{ |
|
|
|
|
|
|
|
var result = await base.QueryForm(body); |
|
|
|
|
|
|
|
string courseIds = result.result.DT_TableDataT1[0].CourseIds; |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(courseIds)) |
|
|
|
|
|
|
|
result.result.DT_TableDataT1[0].CourseIds2 = JsonConvert.DeserializeObject<List<long>>(courseIds); |
|
|
|
|
|
|
|
|
|
|
|
public override async Task<ServiceFormResult<Ghre_CourseWareDto>> QueryForm(QueryForm body) |
|
|
|
else result.result.DT_TableDataT1[0].CourseIds2 = new List<long>(); |
|
|
|
{ |
|
|
|
|
|
|
|
var result = await base.QueryForm(body); |
|
|
|
|
|
|
|
string courseIds = result.result.DT_TableDataT1[0].CourseIds; |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(courseIds)) |
|
|
|
|
|
|
|
result.result.DT_TableDataT1[0].CourseIds2 = JsonConvert.DeserializeObject<List<long>>(courseIds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else result.result.DT_TableDataT1[0].CourseIds2 = new List<long>(); |
|
|
|
result.result.DT_TableDataT1[0].Attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == body.id); |
|
|
|
|
|
|
|
|
|
|
|
result.result.DT_TableDataT1[0].Attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId == body.id); |
|
|
|
if (body.doType == "Copy") |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
result.result.DT_TableDataT1[0].CourseWareNo = null; |
|
|
|
|
|
|
|
result.result.DT_TableDataT1[0].CourseWareName = null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
if (body.doType == "Copy") |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override async Task<ServicePageResult<Ghre_CourseWareDto>> QueryFilterPage(QueryBody filter) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
bool? IsAllowDownload = null; |
|
|
|
|
|
|
|
if (filter.jsonParam != null) |
|
|
|
|
|
|
|
foreach (JProperty jProperty in filter.jsonParam.Properties()) |
|
|
|
{ |
|
|
|
{ |
|
|
|
result.result.DT_TableDataT1[0].CourseWareNo = null; |
|
|
|
var name = jProperty.Name; |
|
|
|
result.result.DT_TableDataT1[0].CourseWareName = null; |
|
|
|
var value = jProperty.Value.ToString(); |
|
|
|
} |
|
|
|
if (name != "IsAllowDownload") |
|
|
|
return result; |
|
|
|
continue; |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(value)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
switch (name) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
case "IsAllowDownload": |
|
|
|
|
|
|
|
IsAllowDownload = Convert.ToBoolean(jsonParam.columnValue); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
string condition = string.Empty; |
|
|
|
|
|
|
|
if (IsAllowDownload != null) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
string sql = @$"SELECT DISTINCT B.Id
|
|
|
|
|
|
|
|
FROM Ghre_CourseWareAttachment A |
|
|
|
|
|
|
|
JOIN Ghre_CourseWare B ON A.CourseWareId = B.Id AND B.IsEnable = 1 |
|
|
|
|
|
|
|
WHERE A.IsEnable = 1 AND A.IsAllowDownload = '{IsAllowDownload}'";
|
|
|
|
|
|
|
|
var entitys = await Db.Ado.SqlQueryAsync<long>(sql); |
|
|
|
|
|
|
|
if (entitys.Any()) |
|
|
|
|
|
|
|
condition = "Id IN (" + string.Join(",", entitys.Select(x => x)) + ")"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var result = await base.QueryFilterPage(filter, condition); |
|
|
|
public override async Task<ServicePageResult<Ghre_CourseWareDto>> QueryFilterPage(QueryBody body) |
|
|
|
var data = result.result.DT_TableDataT1; |
|
|
|
|
|
|
|
var attachmentIds = data.Select(x => x.Id).ToList(); |
|
|
|
|
|
|
|
var attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId != null && attachmentIds.Contains(x.CourseWareId.Value)); |
|
|
|
|
|
|
|
data.ForEach(async x => |
|
|
|
{ |
|
|
|
{ |
|
|
|
var result = await base.QueryFilterPage(body); |
|
|
|
if (!string.IsNullOrWhiteSpace(x.CourseIds)) |
|
|
|
var data = result.result.DT_TableDataT1; |
|
|
|
x.CourseIds2 = JsonConvert.DeserializeObject<List<long>>(x.CourseIds); |
|
|
|
var attachmentIds = data.Select(x => x.Id).ToList(); |
|
|
|
|
|
|
|
var attachments = await _ghre_CourseWareAttachmentServices.Query(x => x.CourseWareId != null && attachmentIds.Contains(x.CourseWareId.Value)); |
|
|
|
|
|
|
|
data.ForEach(async x => |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(x.CourseIds)) |
|
|
|
|
|
|
|
x.CourseIds2 = JsonConvert.DeserializeObject<List<long>>(x.CourseIds); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x.StudyDuration = $"{x.Hours}小时{x.Minutes}分钟"; |
|
|
|
x.StudyDuration = $"{x.Hours}小时{x.Minutes}分钟"; |
|
|
|
x.SourceLabel = await GetParaLabel("CourseWareSource", x.Source); |
|
|
|
x.SourceLabel = await GetParaLabel("CourseWareSource", x.Source); |
|
|
|
x.Attachments = attachments.Where(a=> a.CourseWareId == x.Id).ToList(); |
|
|
|
x.Attachments = attachments.Where(a => a.CourseWareId == x.Id).ToList(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
result.result.DT_TableDataT1 = data; |
|
|
|
result.result.DT_TableDataT1 = data; |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |