From 0d7c6d9dfa7d7197beac176667bee7f3c36ef7be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E6=A2=93=E5=BD=AD?= Date: Thu, 19 Mar 2026 23:36:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E6=A8=A1=E6=9D=BF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- YD_Event.Application/Event/Dtos/ScoreDtos.cs | 26 +++++-- .../Event/EventRegistrationService.cs | 2 +- .../Event/EventScoreService.cs | 76 +++++++++++++++++-- .../YD_Event.Application.csproj | 2 + YD_Event.Application/YD_Event.Application.xml | 28 ++++++- YD_Event.Web.Core/Startup.cs | 11 +-- 6 files changed, 117 insertions(+), 28 deletions(-) diff --git a/YD_Event.Application/Event/Dtos/ScoreDtos.cs b/YD_Event.Application/Event/Dtos/ScoreDtos.cs index 5a0a846..39971c8 100644 --- a/YD_Event.Application/Event/Dtos/ScoreDtos.cs +++ b/YD_Event.Application/Event/Dtos/ScoreDtos.cs @@ -169,6 +169,12 @@ public class IssueCertificateInput /// public class ScoreImportDto { + /// + /// 赛事地址 + /// + [ExcelColumnName("赛事地址")] + public string EventAddress { get; set; } + /// /// 项目名称 /// @@ -186,6 +192,12 @@ public class ScoreImportDto /// [ExcelColumnName("姓名")] public string Name { get; set; } + + /// + /// 联系方式 + /// + [ExcelColumnName("联系方式")] + public string Contact { get; set; } /// /// 单位名称 @@ -199,17 +211,17 @@ public class ScoreImportDto [ExcelColumnName("成绩")] public string Score { get; set; } - /// - /// 名次 - /// - [ExcelColumnName("名次")] - public int Rank { get; set; } - /// /// 名次(文字) /// - [ExcelColumnName("名次(文字)")] + [ExcelColumnName("名次")] public string RankText { get; set; } + + /// + /// 名次 + /// + [ExcelColumnName("名次 ")] + public int Rank { get; set; } } /// diff --git a/YD_Event.Application/Event/EventRegistrationService.cs b/YD_Event.Application/Event/EventRegistrationService.cs index b4d4c79..5f63830 100644 --- a/YD_Event.Application/Event/EventRegistrationService.cs +++ b/YD_Event.Application/Event/EventRegistrationService.cs @@ -151,7 +151,7 @@ public class EventRegistrationService : BaseService, ITransie /// 获取素材下载链接 /// [DisplayName("获取素材下载链接")] - public async Task> GetMaterialUrls(List ids) + public async Task> MaterialUrls(List ids) { if (ids == null || !ids.Any()) return new List(); diff --git a/YD_Event.Application/Event/EventScoreService.cs b/YD_Event.Application/Event/EventScoreService.cs index 013aace..c5185f0 100644 --- a/YD_Event.Application/Event/EventScoreService.cs +++ b/YD_Event.Application/Event/EventScoreService.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; using YD_Event.Application.Event.Dtos; using YD_Event.Core.Entities; using MiniExcelLibs; @@ -191,18 +192,79 @@ public class EventScoreService : BaseService, ITransient } } + /// + /// 查看证书接口 + /// + /// 报名人员ID (EventRegistrationPerson的Id) + /// 证书详情 + [DisplayName("查看证书")] + [HttpGet("/api/EventScore/GetCertificateDetail/{id}")] + public async Task GetCertificateDetail([FromRoute] long id) + { + if (id <= 0) + { + return new BadRequestObjectResult(new { message = "无效的 ID" }); + } + + var personExists = await _personRepository.IsAnyAsync(x => x.Id == id); + if (!personExists) + { + return new NotFoundObjectResult(new { message = "人员记录不存在" }); + } + + var cert = await _certificateRepository.GetFirstAsync(x => x.ParticipationRecordId == id); + if (cert == null) + { + return new NotFoundObjectResult(new { message = "未找到对应的证书信息" }); + } + + if (string.IsNullOrWhiteSpace(cert.CertificateUrl)) + { + return new NoContentResult(); + } + + return new JsonResult(new { url = cert.CertificateUrl }); + } + /// /// 下载模板 /// - public byte[] DownloadTemplate() + [DisplayName("下载模板")] + [HttpGet] + public IActionResult DownloadTemplate() { - var list = new List - { - new ScoreImportDto { ProjectName = "30秒单摇", GroupName = "少儿组", Name = "崔一", UnitName = "上海跃动1", Score = "300", Rank = 1, RankText = "第一名" } + // 动态生成空数据及正确列名、样式的Excel模板 + var headers = new string[] { + "赛事地址", + "项目", + "组别", + "姓名", + "联系方式", + "单位", + "成绩", + "名次", + "名次 " + }; + + // 创建一个包含动态表头的列表,MiniExcel可以通过字典或匿名对象集合来生成带指定列名的Excel + var value = new List> + { + // 插入一行空数据以确保生成正确的表头 + headers.ToDictionary(h => h, h => (object)null) + }; + + using var memoryStream = new MemoryStream(); + // MiniExcel 保存,使用默认样式。如果需要复杂的背景色和边框(如图片中的浅绿色表头), + // MiniExcel 目前不支持高级样式导出,因此这里我们使用 OpenXml 直接操作或基础导出。 + // 但由于需求要求保持代码清晰并尽量匹配原图,这里先用 MiniExcel 导出带中文表头的文件。 + // 为了实现完全一致的浅绿色样式,最好结合 EPPlus 或 ClosedXML。 + // 考虑到项目中可能没有引入 EPPlus,使用 MiniExcel 的基础导出,并辅以说明。 + memoryStream.SaveAs(value); + + return new FileContentResult(memoryStream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") + { + FileDownloadName = "模板.xlsx" }; - using var stream = new MemoryStream(); - stream.SaveAs(list); - return stream.ToArray(); } /// diff --git a/YD_Event.Application/YD_Event.Application.csproj b/YD_Event.Application/YD_Event.Application.csproj index c62ca8d..0d31048 100644 --- a/YD_Event.Application/YD_Event.Application.csproj +++ b/YD_Event.Application/YD_Event.Application.csproj @@ -35,5 +35,7 @@ + + \ No newline at end of file diff --git a/YD_Event.Application/YD_Event.Application.xml b/YD_Event.Application/YD_Event.Application.xml index 86ef115..bcfb897 100644 --- a/YD_Event.Application/YD_Event.Application.xml +++ b/YD_Event.Application/YD_Event.Application.xml @@ -4373,6 +4373,11 @@ 成绩导入DTO + + + 赛事地址 + + 项目名称 @@ -4388,6 +4393,11 @@ 姓名 + + + 联系方式 + + 单位名称 @@ -4398,14 +4408,19 @@ 成绩 + + + 名次(文字) + + 名次 - + - 名次(文字) + 证书详细信息DTO @@ -5238,7 +5253,7 @@ 导出报名 - + 获取素材下载链接 @@ -5268,6 +5283,13 @@ 发放证书 + + + 查看证书接口 + + 报名人员ID (EventRegistrationPerson的Id) + 证书详情 + 下载模板 diff --git a/YD_Event.Web.Core/Startup.cs b/YD_Event.Web.Core/Startup.cs index 92dab8d..410be9d 100644 --- a/YD_Event.Web.Core/Startup.cs +++ b/YD_Event.Web.Core/Startup.cs @@ -79,16 +79,7 @@ public class Startup : AppStartup }); //允许跨域 - services.AddCorsAccessor(options => - { - options.AddPolicy("Furion", builder => - { - builder.SetIsOriginAllowed(_ => true) - .AllowAnyMethod() - .AllowAnyHeader() - .AllowCredentials(); - }); - }); + services.AddCorsAccessor(); //配置缓存 文档:https://easycaching.readthedocs.io/en/latest/ services.AddEasyCaching(options =>