using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using VOL.Business.IServices.SunshineRun;
using VOL.Core.Enums;
using VOL.Core.Filters;
using VOL.Core.Utilities;
using VOL.Model;
using VOL.Model.SunshineRun;
namespace VOL.WebApi.Controllers.Business
{
///
/// AI阳光跑运动记录。
///
[Route("api/[controller]")]
[ApiController]
[ApiExplorerSettings(GroupName = "v3")]
[TypeFilter(typeof(CustomApiResponseFilter))]
public class SunshineRunController : ControllerBase
{
private readonly ISunshineRunService _service;
public SunshineRunController(ISunshineRunService service)
{
_service = service;
}
[HttpGet(nameof(GetPageList))]
[ApiActionPermission("XW_SunshineRunTrain", ActionPermissionOptions.Search)]
public Task> GetPageList([FromQuery] SunshineRunPageParam param)
=> _service.GetPageList(param);
[HttpGet(nameof(Export))]
[ApiActionPermission("XW_SunshineRunTrain", ActionPermissionOptions.Search)]
public async Task Export([FromQuery] SunshineRunFilterParam param)
{
var rows = await _service.GetExportList(param);
var columns = new List
{
nameof(SunshineRunRecordModel.Index),
nameof(SunshineRunRecordModel.StudentName),
nameof(SunshineRunRecordModel.SexName),
nameof(SunshineRunRecordModel.ClassName),
nameof(SunshineRunRecordModel.EffectiveDistance),
nameof(SunshineRunRecordModel.EffectiveTime),
nameof(SunshineRunRecordModel.TotalDistance),
nameof(SunshineRunRecordModel.TotalTime),
nameof(SunshineRunRecordModel.StartTime),
nameof(SunshineRunRecordModel.EndTime)
};
var bytes = Tool.ExportToExcel(
new Dictionary> { ["AI阳光跑"] = rows },
columns, autoFitColumns: false);
return File(bytes, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
$"AI阳光跑{DateTime.Now:yyyyMMddHHmmss}.xlsx");
}
}
}