feat 导出

This commit is contained in:
2025-04-18 16:06:16 +08:00
parent 4f9cd67fea
commit b68a6c471f
14 changed files with 391 additions and 10 deletions

View File

@@ -24,6 +24,7 @@
<ProjectReference Include="..\Dlhis.Basic.Api\Dlhis.Basic.Api.csproj" />
<ProjectReference Include="..\Dlhis.Constants\Dlhis.Constants.csproj" />
<ProjectReference Include="..\Dlhis.Entity\Dlhis.Entity.csproj" />
<ProjectReference Include="..\Dlhis.ExcelHelper\Dlhis.ExcelHelper.csproj" />
<ProjectReference Include="..\Dlhis.Sys.Api\Dlhis.Sys.Api.csproj" />
</ItemGroup>

View File

@@ -12,8 +12,10 @@ ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Src/Dlhis.Canteen/Dlhis.Canteen.csproj", "Src/Dlhis.Canteen/"]
COPY ["Src/Dlhis.Basic.Api/Dlhis.Basic.Api.csproj", "Src/Dlhis.Basic.Api/"]
COPY ["Src/Dlhis.Constants/Dlhis.Constants.csproj", "Src/Dlhis.Constants/"]
COPY ["Src/Dlhis.Entity/Dlhis.Entity.csproj", "Src/Dlhis.Entity/"]
COPY ["Src/Dlhis.DataPermission.Model/Dlhis.DataPermission.Model.csproj", "Src/Dlhis.DataPermission.Model/"]
COPY ["Src/Dlhis.ExcelHelper/Dlhis.ExcelHelper.csproj", "Src/Dlhis.ExcelHelper/"]
COPY ["Src/Dlhis.Sys.Api/Dlhis.Sys.Api.csproj", "Src/Dlhis.Sys.Api/"]
RUN dotnet restore "./Src/Dlhis.Canteen/Dlhis.Canteen.csproj"
COPY . .

View File

@@ -0,0 +1,43 @@
using Dlhis.ExcelHelper;
using Kurisu.AspNetCore.DataAccess.Dto;
using Kurisu.AspNetCore.UnifyResultAndValidation.Abstractions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
namespace Dlhis.Canteen;
/// <summary>
/// 忽略响应<see cref="IApiResult"/>.Data的自动camelCase
/// </summary>
[AttributeUsage(AttributeTargets.Method)]
public class ExcelResultAttribute : Attribute, IAsyncActionFilter
{
private readonly string _fileName;
public ExcelResultAttribute(string fileName)
{
_fileName = fileName;
}
/// <inheritdoc />
public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
var r = await next();
var or = r.Result as ObjectResult;
var v = or.Value;
var type = or.DeclaredType.GenericTypeArguments[0];
if (or.DeclaredType.IsGenericType && or.DeclaredType.GetGenericTypeDefinition() == typeof(Pagination<>))
{
v = v.GetType().GetProperty("Data").GetValue(v, null);
}
var method = typeof(ExcelExtensions).GetMethod(nameof(ExcelExtensions.ToExcelBytesAsync));
var task = (Task<byte[]>)method.MakeGenericMethod(type).Invoke(null, new[] { v });
var data = await task;
r.Result = new FileContentResult(data, "application/vnd.ms-excel")
{
FileDownloadName = _fileName
};
}
}

View File

@@ -42,6 +42,7 @@ public class BalancesController : ControllerBase
/// <param name="request"></param>
/// <returns></returns>
[HttpGet("export")]
[ExcelResult("员工账务明细")]
[IgnoreTenant]
public async Task<List<BalanceRecordResponse>> GetPageToExportAsync([FromQuery] BalanceRecordPageRequest request)
{

View File

@@ -1,11 +1,13 @@
using Dlhis.Entity.Canteen.Enums;
using Dlhis.ExcelHelper;
using Kurisu.AspNetCore.Utils.Converters;
using Kurisu.AspNetCore.Utils.Extensions;
using Newtonsoft.Json;
namespace Dlhis.Canteen.Order.Response;
public class BalanceRecordResponse
[Excel("BalanceRecords")]
public class BalanceRecordResponse : IExcelExportable
{
public long Id { get; set; }
@@ -27,34 +29,40 @@ public class BalanceRecordResponse
/// <summary>
/// 姓名
/// </summary>
[Excel("姓名")]
public string Name { get; set; }
/// <summary>
/// 学工号
/// </summary>
[Excel("工号")]
public string UserCode { get; set; }
/// <summary>
/// 部门号
/// </summary>
[Excel("部门号")]
public string DepartmentNo { get; set; }
/// <summary>
/// 部门
/// </summary>
[Excel("部门名称")]
public string DepartmentName { get; set; }
/// <summary>
/// 所属成本日期
/// </summary>
[Excel("营业日期", "yyyy-MM-dd")]
[JsonConverter(typeof(ToDateJsonConverter))]
public DateTime CostDate { get; set; }
/// <summary>
/// 备注
/// 记录产生时间
/// </summary>
public string Remark { get; set; }
[Excel("消费时间", "yyyy-MM-dd HH:mm:ss")]
public DateTime CostDateTime { get; set; }
/// <summary>
/// 来源
@@ -64,6 +72,7 @@ public class BalanceRecordResponse
/// <summary>
/// 消费识别来源
/// </summary>
[Excel("消费来源")]
public string SourceDesc => Source.GetDescription();
/// <summary>
@@ -76,11 +85,13 @@ public class BalanceRecordResponse
/// <summary>
/// 金额
/// </summary>
[Excel("消费金额", "0.00")]
public decimal Amount { get; set; }
/// <summary>
/// 营业点
/// </summary>
[Excel("营业点")]
public string BusinessPlaceName { get; set; }
/// <summary>
@@ -91,6 +102,7 @@ public class BalanceRecordResponse
/// <summary>
/// 餐次
/// </summary>
[Excel("场次")]
public string ShiftTypeDesc => ShiftType?.GetDescription();
/// <summary>
@@ -103,11 +115,6 @@ public class BalanceRecordResponse
/// </summary>
public string CostId { get; set; }
/// <summary>
/// 消费者所在基地
/// </summary>
public string OriginTenantId { get; set; }
/// <summary>
/// 数据状态
/// </summary>
@@ -116,20 +123,30 @@ public class BalanceRecordResponse
/// <summary>
/// 数据状态描述
/// </summary>
[Excel("数据状态")]
public string StatusDesc => Status.GetDescription();
/// <summary>
/// 记录产生时间
/// 消费者所在基地
/// </summary>
public DateTime CostDateTime { get; set; }
[Excel("在职厂区")]
public string OriginTenantId { get; set; }
/// <summary>
/// 厂区
/// </summary>
[Excel("消费厂区")]
public string Factory { get; set; }
/// <summary>
/// 人事范围
/// </summary>
[Excel("人事范围")]
public string Werks { get; set; }
/// <summary>
/// 备注
/// </summary>
[Excel("备注")]
public string Remark { get; set; }
}