下载模板接口
This commit is contained in:
parent
318504339c
commit
0d7c6d9dfa
@ -169,6 +169,12 @@ public class IssueCertificateInput
|
||||
/// </summary>
|
||||
public class ScoreImportDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 赛事地址
|
||||
/// </summary>
|
||||
[ExcelColumnName("赛事地址")]
|
||||
public string EventAddress { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 项目名称
|
||||
/// </summary>
|
||||
@ -187,6 +193,12 @@ public class ScoreImportDto
|
||||
[ExcelColumnName("姓名")]
|
||||
public string Name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 联系方式
|
||||
/// </summary>
|
||||
[ExcelColumnName("联系方式")]
|
||||
public string Contact { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 单位名称
|
||||
/// </summary>
|
||||
@ -199,17 +211,17 @@ public class ScoreImportDto
|
||||
[ExcelColumnName("成绩")]
|
||||
public string Score { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名次
|
||||
/// </summary>
|
||||
[ExcelColumnName("名次")]
|
||||
public int Rank { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名次(文字)
|
||||
/// </summary>
|
||||
[ExcelColumnName("名次(文字)")]
|
||||
[ExcelColumnName("名次")]
|
||||
public string RankText { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 名次
|
||||
/// </summary>
|
||||
[ExcelColumnName("名次 ")]
|
||||
public int Rank { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -151,7 +151,7 @@ public class EventRegistrationService : BaseService<EventRegistration>, ITransie
|
||||
/// 获取素材下载链接
|
||||
/// </summary>
|
||||
[DisplayName("获取素材下载链接")]
|
||||
public async Task<List<string>> GetMaterialUrls(List<long> ids)
|
||||
public async Task<List<string>> MaterialUrls(List<long> ids)
|
||||
{
|
||||
if (ids == null || !ids.Any()) return new List<string>();
|
||||
|
||||
|
||||
@ -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<EventResult>, ITransient
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查看证书接口
|
||||
/// </summary>
|
||||
/// <param name="id">报名人员ID (EventRegistrationPerson的Id)</param>
|
||||
/// <returns>证书详情</returns>
|
||||
[DisplayName("查看证书")]
|
||||
[HttpGet("/api/EventScore/GetCertificateDetail/{id}")]
|
||||
public async Task<IActionResult> 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 });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载模板
|
||||
/// </summary>
|
||||
public byte[] DownloadTemplate()
|
||||
[DisplayName("下载模板")]
|
||||
[HttpGet]
|
||||
public IActionResult DownloadTemplate()
|
||||
{
|
||||
var list = new List<ScoreImportDto>
|
||||
{
|
||||
new ScoreImportDto { ProjectName = "30秒单摇", GroupName = "少儿组", Name = "崔一", UnitName = "上海跃动1", Score = "300", Rank = 1, RankText = "第一名" }
|
||||
// 动态生成空数据及正确列名、样式的Excel模板
|
||||
var headers = new string[] {
|
||||
"赛事地址",
|
||||
"项目",
|
||||
"组别",
|
||||
"姓名",
|
||||
"联系方式",
|
||||
"单位",
|
||||
"成绩",
|
||||
"名次",
|
||||
"名次 "
|
||||
};
|
||||
|
||||
// 创建一个包含动态表头的列表,MiniExcel可以通过字典或匿名对象集合来生成带指定列名的Excel
|
||||
var value = new List<Dictionary<string, object>>
|
||||
{
|
||||
// 插入一行空数据以确保生成正确的表头
|
||||
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();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -35,5 +35,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="MiniExcel" Version="1.42.0" />
|
||||
<PackageReference Include="MiniWord" Version="0.9.2" />
|
||||
<PackageReference Include="QuestPDF" Version="2026.2.3" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@ -4373,6 +4373,11 @@
|
||||
成绩导入DTO
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.EventAddress">
|
||||
<summary>
|
||||
赛事地址
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.ProjectName">
|
||||
<summary>
|
||||
项目名称
|
||||
@ -4388,6 +4393,11 @@
|
||||
姓名
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.Contact">
|
||||
<summary>
|
||||
联系方式
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.UnitName">
|
||||
<summary>
|
||||
单位名称
|
||||
@ -4398,14 +4408,19 @@
|
||||
成绩
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.RankText">
|
||||
<summary>
|
||||
名次(文字)
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.Rank">
|
||||
<summary>
|
||||
名次
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:YD_Event.Application.Event.Dtos.ScoreImportDto.RankText">
|
||||
<member name="T:YD_Event.Application.Event.Dtos.CertificateDetailDto">
|
||||
<summary>
|
||||
名次(文字)
|
||||
证书详细信息DTO
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:YD_Event.Application.Event.Dtos.CertificateExportDto">
|
||||
@ -5238,7 +5253,7 @@
|
||||
导出报名
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:YD_Event.Application.Event.EventRegistrationService.GetMaterialUrls(System.Collections.Generic.List{System.Int64})">
|
||||
<member name="M:YD_Event.Application.Event.EventRegistrationService.MaterialUrls(System.Collections.Generic.List{System.Int64})">
|
||||
<summary>
|
||||
获取素材下载链接
|
||||
</summary>
|
||||
@ -5268,6 +5283,13 @@
|
||||
发放证书
|
||||
</summary>
|
||||
</member>
|
||||
<member name="M:YD_Event.Application.Event.EventScoreService.GetCertificateDetail(System.Int64)">
|
||||
<summary>
|
||||
查看证书接口
|
||||
</summary>
|
||||
<param name="id">报名人员ID (EventRegistrationPerson的Id)</param>
|
||||
<returns>证书详情</returns>
|
||||
</member>
|
||||
<member name="M:YD_Event.Application.Event.EventScoreService.DownloadTemplate">
|
||||
<summary>
|
||||
下载模板
|
||||
|
||||
@ -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 =>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user