From 86fd25292b4e9be7b418bd3279386ade51ae7633 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Tue, 25 Jun 2024 14:59:55 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BE=E4=BB=B6=E6=98=AF=E5=90=A6=E5=8F=AF?= =?UTF-8?q?=E4=B8=8B=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Base/BaseController.cs | 3 +- Tiobon.Core.Model/ViewModels/Menu.cs | 4 +- Tiobon.Core.Services/BASE/BaseServices.cs | 7 +- Tiobon.Core.Services/CommonServices.cs | 3 +- .../Ghre/Ghre_CourseWareServices.cs | 179 +++++++++++------- 5 files changed, 118 insertions(+), 78 deletions(-) diff --git a/Tiobon.Core.Api/Controllers/Base/BaseController.cs b/Tiobon.Core.Api/Controllers/Base/BaseController.cs index 85726353..b85d9e71 100644 --- a/Tiobon.Core.Api/Controllers/Base/BaseController.cs +++ b/Tiobon.Core.Api/Controllers/Base/BaseController.cs @@ -1,5 +1,4 @@ using System.Reflection; -using NPOI.HPSF; namespace Tiobon.Core.Controllers; @@ -231,7 +230,7 @@ public class BaseController DownloadExcel() { var result = (await InvokeServiceAsync("DownloadExcel", [])) as ServiceResult; diff --git a/Tiobon.Core.Model/ViewModels/Menu.cs b/Tiobon.Core.Model/ViewModels/Menu.cs index 9b3b433a..f22817e1 100644 --- a/Tiobon.Core.Model/ViewModels/Menu.cs +++ b/Tiobon.Core.Model/ViewModels/Menu.cs @@ -167,5 +167,7 @@ public class DT_Procedure public string IUDProcedure { get; set; } public string QueryProcedure { get; set; } public string ImportExcel { get; set; } - public string DownloadExcel { get; set; } + + public string DownExcelTemplate { get; set; } + public string ExportExcel { get; set; } } diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 71b59065..32ebd7b3 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; using System.Data; using System.Dynamic; using System.Linq.Expressions; @@ -740,12 +741,16 @@ public class BaseServices : IBaseServ string conditions = " WHERE IsEnable = 1"; if (!string.IsNullOrWhiteSpace(condition)) conditions += "AND " + condition; + + + var properties = entityType.GetGenericProperties(); + if (filter.jsonParam != null) foreach (JProperty jProperty in filter.jsonParam.Properties()) { var name = jProperty.Name; var value = jProperty.Value.ToString(); - if (name == "page" || name == "pageSize") + if (name == "page" || name == "pageSize" || !properties.Any(x => x.Name == name)) continue; if (!string.IsNullOrWhiteSpace(value)) { diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs index 00481833..3bc0b718 100644 --- a/Tiobon.Core.Services/CommonServices.cs +++ b/Tiobon.Core.Services/CommonServices.cs @@ -852,7 +852,8 @@ public partial class CommonServices : BaseServices>, ICommon if (!string.IsNullOrWhiteSpace(result.DT_Procedure.EditProcedure)) { result.DT_Procedure.ImportExcel = "/api" + result.DT_Procedure.EditProcedure.Replace("QueryForm", "ImportExcel"); - result.DT_Procedure.DownloadExcel = "/api" + result.DT_Procedure.EditProcedure.Replace("QueryForm", "DownloadExcel"); + result.DT_Procedure.DownExcelTemplate = "/api" + result.DT_Procedure.EditProcedure.Replace("QueryForm", "DownExcelTemplate"); + result.DT_Procedure.ExportExcel = "/api" + result.DT_Procedure.EditProcedure.Replace("QueryForm", "ExportExcel"); } } diff --git a/Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs b/Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs index d5fe5bc2..42f93363 100644 --- a/Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs +++ b/Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs @@ -1,7 +1,8 @@  using System.Data; -using System.Net.Mail; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using NPOI.Util.Collections; using Tiobon.Core.Common; using Tiobon.Core.Common.Caches; using Tiobon.Core.IRepository.Base; @@ -10,97 +11,129 @@ using Tiobon.Core.Model; using Tiobon.Core.Model.Models; using Tiobon.Core.Services.BASE; -namespace Tiobon.Core.Services +namespace Tiobon.Core.Services; + +/// +/// 课件 (服务) +/// +public class Ghre_CourseWareServices : BaseServices, IGhre_CourseWareServices { - /// - /// 课件 (服务) - /// - public class Ghre_CourseWareServices : BaseServices, IGhre_CourseWareServices + private readonly IBaseRepository _dal; + private IGhre_CourseServices _ghre_CourseServices; + private IGhre_CourseWareAttachmentServices _ghre_CourseWareAttachmentServices; + + public Ghre_CourseWareServices(ICaching caching, + IGhre_CourseServices ghre_CourseServices, + IGhre_CourseWareAttachmentServices ghre_CourseWareAttachmentServices, + IBaseRepository dal) { - private readonly IBaseRepository _dal; - private IGhre_CourseServices _ghre_CourseServices; - private IGhre_CourseWareAttachmentServices _ghre_CourseWareAttachmentServices; - - public Ghre_CourseWareServices(ICaching caching, - IGhre_CourseServices ghre_CourseServices, - IGhre_CourseWareAttachmentServices ghre_CourseWareAttachmentServices, - IBaseRepository dal) + this._dal = dal; + base.BaseDal = dal; + base._caching = caching; + _ghre_CourseServices = ghre_CourseServices; + _ghre_CourseWareAttachmentServices = ghre_CourseWareAttachmentServices; + } + + public override async Task Add(InsertGhre_CourseWareInput entity) + { + if (entity.CourseIds2.Any()) { - this._dal = dal; - base.BaseDal = dal; - base._caching = caching; - _ghre_CourseServices = ghre_CourseServices; - _ghre_CourseWareAttachmentServices = ghre_CourseWareAttachmentServices; + entity.CourseIds = JsonConvert.SerializeObject(entity.CourseIds2); + 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 Add(InsertGhre_CourseWareInput entity) + public override async Task Update(long Id, EditGhre_CourseWareInput editModel) + { + if (editModel.CourseIds2.Any()) { - if (entity.CourseIds2.Any()) - { - entity.CourseIds = JsonConvert.SerializeObject(entity.CourseIds2); - 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; + 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)); } - public override async Task Update(long Id, EditGhre_CourseWareInput editModel) - { - if (editModel.CourseIds2.Any()) - { - 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); + editModel.Attachments.ForEach(x => x.CourseWareId = Id); + await _ghre_CourseWareAttachmentServices.Add(editModel.Attachments); - await _ghre_CourseWareAttachmentServices.Delete(x => x.CourseWareId == Id); - editModel.Attachments.ForEach(x => x.CourseWareId = Id); - await _ghre_CourseWareAttachmentServices.Add(editModel.Attachments); + return await base.Update(Id, editModel); + } - return await base.Update(Id, editModel); - } + public override async Task> 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>(courseIds); - public override async Task> 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>(courseIds); + else result.result.DT_TableDataT1[0].CourseIds2 = new List(); - else result.result.DT_TableDataT1[0].CourseIds2 = new List(); + 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> QueryFilterPage(QueryBody filter) + { + bool? IsAllowDownload = null; + if (filter.jsonParam != null) + foreach (JProperty jProperty in filter.jsonParam.Properties()) { - result.result.DT_TableDataT1[0].CourseWareNo = null; - result.result.DT_TableDataT1[0].CourseWareName = null; - } - return result; + var name = jProperty.Name; + var value = jProperty.Value.ToString(); + if (name != "IsAllowDownload") + continue; + if (!string.IsNullOrWhiteSpace(value)) + { + var jsonParam = JsonConvert.DeserializeObject(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(sql); + if (entitys.Any()) + condition = "Id IN (" + string.Join(",", entitys.Select(x => x)) + ")"; } - - public override async Task> QueryFilterPage(QueryBody body) + var result = await base.QueryFilterPage(filter, condition); + 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); - 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 => - { - if (!string.IsNullOrWhiteSpace(x.CourseIds)) - x.CourseIds2 = JsonConvert.DeserializeObject>(x.CourseIds); + if (!string.IsNullOrWhiteSpace(x.CourseIds)) + x.CourseIds2 = JsonConvert.DeserializeObject>(x.CourseIds); - x.StudyDuration = $"{x.Hours}小时{x.Minutes}分钟"; - x.SourceLabel = await GetParaLabel("CourseWareSource", x.Source); - x.Attachments = attachments.Where(a=> a.CourseWareId == x.Id).ToList(); - }); - result.result.DT_TableDataT1 = data; - return result; + x.StudyDuration = $"{x.Hours}小时{x.Minutes}分钟"; + x.SourceLabel = await GetParaLabel("CourseWareSource", x.Source); + x.Attachments = attachments.Where(a => a.CourseWareId == x.Id).ToList(); + }); + result.result.DT_TableDataT1 = data; + return result; - } } } \ No newline at end of file