课件是否可下载

master
xiaochanghai 1 year ago
parent 32a3e38392
commit 86fd25292b
  1. 3
      Tiobon.Core.Api/Controllers/Base/BaseController.cs
  2. 4
      Tiobon.Core.Model/ViewModels/Menu.cs
  3. 7
      Tiobon.Core.Services/BASE/BaseServices.cs
  4. 3
      Tiobon.Core.Services/CommonServices.cs
  5. 55
      Tiobon.Core.Services/Ghre/Ghre_CourseWareServices.cs

@ -1,5 +1,4 @@
using System.Reflection;
using NPOI.HPSF;
namespace Tiobon.Core.Controllers;
@ -231,7 +230,7 @@ public class BaseController<IServiceBase, TEntity, TEntityDto, TInsertDto, TEdit
#endregion
#region Excel下载
[HttpGet("DownloadExcel"), AllowAnonymous]
[HttpGet("DownExcelTemplate"), AllowAnonymous]
public async Task<IActionResult> DownloadExcel()
{
var result = (await InvokeServiceAsync("DownloadExcel", [])) as ServiceResult<string>;

@ -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; }
}

@ -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<TEntity, TEntityDto, TInsertDto, TEditDto> : 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))
{

@ -852,7 +852,8 @@ public partial class CommonServices : BaseServices<RootEntityTkey<int>>, 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");
}
}

@ -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,13 +11,13 @@ using Tiobon.Core.Model;
using Tiobon.Core.Model.Models;
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>
/// 课件 (服务)
/// </summary>
public class Ghre_CourseWareServices : BaseServices<Ghre_CourseWare, Ghre_CourseWareDto, InsertGhre_CourseWareInput, EditGhre_CourseWareInput>, IGhre_CourseWareServices
{
private readonly IBaseRepository<Ghre_CourseWare> _dal;
private IGhre_CourseServices _ghre_CourseServices;
private IGhre_CourseWareAttachmentServices _ghre_CourseWareAttachmentServices;
@ -83,9 +84,42 @@ namespace Tiobon.Core.Services
}
public override async Task<ServicePageResult<Ghre_CourseWareDto>> QueryFilterPage(QueryBody body)
public override async Task<ServicePageResult<Ghre_CourseWareDto>> QueryFilterPage(QueryBody filter)
{
bool? IsAllowDownload = null;
if (filter.jsonParam != null)
foreach (JProperty jProperty in filter.jsonParam.Properties())
{
var name = jProperty.Name;
var value = jProperty.Value.ToString();
if (name != "IsAllowDownload")
continue;
if (!string.IsNullOrWhiteSpace(value))
{
var jsonParam = JsonConvert.DeserializeObject<JsonParam>(value);
switch (name)
{
var result = await base.QueryFilterPage(body);
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);
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));
@ -96,11 +130,10 @@ namespace Tiobon.Core.Services
x.StudyDuration = $"{x.Hours}小时{x.Minutes}分钟";
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;
return result;
}
}
}
Loading…
Cancel
Save