|
|
@ -1,22 +1,29 @@ |
|
|
|
using Azure.Core; |
|
|
|
using Dapper; |
|
|
|
using Magicodes.ExporterAndImporter.Core.Extension; |
|
|
|
using Magicodes.ExporterAndImporter.Excel; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using System.Data; |
|
|
|
using System.Drawing.Printing; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Text; |
|
|
|
using System.Text.Json; |
|
|
|
using System.Text.Json.Serialization; |
|
|
|
using TaskManager.Contracts.Dtos; |
|
|
|
using TaskManager.Entity; |
|
|
|
using TaskManager.EntityFramework; |
|
|
|
using TaskManager.EntityFramework.Repository; |
|
|
|
|
|
|
|
namespace TaskManager.Controllers |
|
|
|
{ |
|
|
|
public class CheryRecurringJobInputPageController<T,OUTPUT> : CheryRecurringJobBaseController where T : BaseEntity |
|
|
|
{ |
|
|
|
|
|
|
|
protected readonly IRepository<T> _repository; |
|
|
|
public CheryRecurringJobInputPageController(HttpClient httpClient, JobDbContext jobDbContext, LogController log, IRepository<T> repository) : base(httpClient, jobDbContext, log) |
|
|
|
{ |
|
|
|
|
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
|
|
|
|
protected override async Task DoExecutingAsync(string url, string path, string takName, string client) |
|
|
@ -165,6 +172,116 @@ namespace TaskManager.Controllers |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
public async Task<ActionResult<IEnumerable<T>>> GetAll() |
|
|
|
{ |
|
|
|
return await _repository.GetAllAsync() as List<T>; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet("{id}")] |
|
|
|
public async Task<ActionResult<T>> GetById(int id) |
|
|
|
{ |
|
|
|
var entity = await _repository.GetByIdAsync(id); |
|
|
|
if (entity == null) return NotFound(); |
|
|
|
return entity; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<ActionResult<T>> Create(T entity) |
|
|
|
{ |
|
|
|
entity.CreationTime = DateTime.Now; |
|
|
|
var createdEntity = await _repository.AddAsync(entity); |
|
|
|
return new JsonResult(new { Code = 200, Message = "创建成功!" }); ; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPut("{id}")] |
|
|
|
public async Task<IActionResult> Update(T entity) |
|
|
|
{ |
|
|
|
var _first = await _repository.GetByIdAsync(entity.UId); |
|
|
|
if (_first == null) |
|
|
|
{ |
|
|
|
return new JsonResult(new { Code = 400, Message = "修改失败!" }); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await _repository.UpdateAsync(entity); |
|
|
|
return new JsonResult(new { Code = 200, Message = "修改成功!" }); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpDelete("{id}")] |
|
|
|
public async Task<IActionResult> Delete(int id) |
|
|
|
{ |
|
|
|
await _repository.DeleteAsync(id); |
|
|
|
return new JsonResult(new { Code = 200, Message = "删除成功!" }); ; |
|
|
|
} |
|
|
|
[HttpGet] |
|
|
|
public async Task<ActionResult<PagedResult<T>>> GetPaged( |
|
|
|
[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<T, bool>> filter = null; |
|
|
|
|
|
|
|
var pagedResult = await _repository.GetPagedAsync(filter, pagingParams); |
|
|
|
return Ok(pagedResult); |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
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<T, bool>> filter = null; |
|
|
|
|
|
|
|
var pagedResult = await _repository.GetPagedAsync(null, pagingParams); |
|
|
|
|
|
|
|
var dataTable = pagedResult.Data.ToDataTable(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return await ExportFile(dataTable, Guid.NewGuid().ToString() + ".xlsx"); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
protected async Task<FileStreamResult> ExportFile(DataTable dtos, string fileName) |
|
|
|
{ |
|
|
|
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 }; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|