|
@ -1,4 +1,6 @@ |
|
|
using Hangfire; |
|
|
using Hangfire; |
|
|
|
|
|
using Magicodes.ExporterAndImporter.Excel; |
|
|
|
|
|
using Microsoft.AspNetCore.Authorization; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -7,7 +9,7 @@ using Microsoft.AspNetCore.Mvc; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.EntityFrameworkCore; |
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.Configuration; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
|
|
|
|
|
using System; |
|
|
using System; |
|
|
using System.IO; |
|
|
using System.IO; |
|
|
using System.Linq.Expressions; |
|
|
using System.Linq.Expressions; |
|
@ -21,6 +23,8 @@ namespace TaskManager.Controllers |
|
|
{ |
|
|
{ |
|
|
//[ApiController]
|
|
|
//[ApiController]
|
|
|
//[Route("[controller]")]
|
|
|
//[Route("[controller]")]
|
|
|
|
|
|
|
|
|
|
|
|
[AllowAnonymous] |
|
|
public class TaskConifgureController : ControllerBase |
|
|
public class TaskConifgureController : ControllerBase |
|
|
{ |
|
|
{ |
|
|
private readonly JobDbContext _context; |
|
|
private readonly JobDbContext _context; |
|
@ -34,6 +38,15 @@ namespace TaskManager.Controllers |
|
|
_configuration = configuration; |
|
|
_configuration = configuration; |
|
|
_repository = repository; |
|
|
_repository = repository; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected async Task<FileStreamResult> ExportFile<T>(ICollection<T> dtos, string fileName) where T : class, new() |
|
|
|
|
|
{ |
|
|
|
|
|
var excelExporter = HttpContext.RequestServices.GetRequiredService<IExcelExporter>(); |
|
|
|
|
|
var res = await excelExporter.ExportAsByteArray(dtos); |
|
|
|
|
|
return new FileStreamResult(new MemoryStream(res), "application/octet-stream") { FileDownloadName = DateTime.Now.ToString("yyyyMMddHHmm") + "_" + fileName }; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 请除所有任务
|
|
|
/// 请除所有任务
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
@ -72,6 +85,34 @@ namespace TaskManager.Controllers |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public async Task<FileStreamResult> Export([FromQuery] int pageNumber = 1, |
|
|
|
|
|
[FromQuery] int pageSize = 10, |
|
|
|
|
|
[FromQuery] string sortBy = "", |
|
|
|
|
|
[FromQuery] bool isAscending = true, |
|
|
|
|
|
[FromQuery] Dictionary<string, string> filters = null) |
|
|
|
|
|
{ |
|
|
|
|
|
var pagingParams = new PagingParams |
|
|
|
|
|
{ |
|
|
|
|
|
PageNumber = pageNumber, |
|
|
|
|
|
PageSize = pageSize, |
|
|
|
|
|
SortBy = sortBy, |
|
|
|
|
|
IsAscending = isAscending, |
|
|
|
|
|
Filters = filters |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 可以在这里构建表达式树过滤条件
|
|
|
|
|
|
Expression<Func<TaskConifgure, bool>> filter = null; |
|
|
|
|
|
|
|
|
|
|
|
var pagedResult = await _repository.GetPagedAsync(null, pagingParams); |
|
|
|
|
|
return await ExportFile<TaskConifgure>(pagedResult.Data, Guid.NewGuid().ToString() + ".xlsx"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// 执行铁定任务
|
|
|
/// 执行铁定任务
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|