|
|
@ -7,12 +7,15 @@ using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.EntityFrameworkCore; |
|
|
|
using Microsoft.Extensions.Configuration; |
|
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; |
|
|
|
using System; |
|
|
|
using System.IO; |
|
|
|
using System.Linq.Expressions; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using TaskManager.Controllers; |
|
|
|
using TaskManager.Entity; |
|
|
|
using TaskManager.EntityFramework; |
|
|
|
using TaskManager.EntityFramework.Repository; |
|
|
|
|
|
|
|
namespace TaskManager.Controllers |
|
|
|
{ |
|
|
@ -23,11 +26,13 @@ namespace TaskManager.Controllers |
|
|
|
private readonly JobDbContext _context; |
|
|
|
private readonly IServiceProvider _builder; |
|
|
|
private readonly IConfiguration _configuration; |
|
|
|
public TaskConifgureController(JobDbContext context, IServiceProvider builder, IConfiguration configuration) |
|
|
|
private readonly IRepository<TaskConifgure> _repository; |
|
|
|
public TaskConifgureController(JobDbContext context, IServiceProvider builder, IConfiguration configuration, IRepository<TaskConifgure> repository) |
|
|
|
{ |
|
|
|
_builder = builder; |
|
|
|
_context = context; |
|
|
|
_configuration = configuration; |
|
|
|
_repository = repository; |
|
|
|
} |
|
|
|
/// <summary>
|
|
|
|
/// 请除所有任务
|
|
|
@ -49,7 +54,7 @@ namespace TaskManager.Controllers |
|
|
|
/// </summary>
|
|
|
|
/// <param name="taskName"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpPost(Name = "ExecuteTask")] |
|
|
|
[NonAction] |
|
|
|
public async Task ExecuteTask(string taskName) |
|
|
|
{ |
|
|
|
var first = await _context.TaskConifgure.FirstOrDefaultAsync(p => p.TaskName == taskName); |
|
|
@ -72,7 +77,7 @@ namespace TaskManager.Controllers |
|
|
|
/// </summary>
|
|
|
|
/// <param name="taskName"></param>
|
|
|
|
/// <returns></returns>
|
|
|
|
[HttpGet(Name = "testTask")] |
|
|
|
[NonAction] |
|
|
|
public async Task testTask(string taskName) |
|
|
|
{ |
|
|
|
var first = await _context.TaskConifgure.FirstOrDefaultAsync(p => p.TaskName == taskName); |
|
|
@ -93,9 +98,6 @@ namespace TaskManager.Controllers |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public async Task RefreshTaskConfig() |
|
|
|
{ |
|
|
|
|
|
|
@ -568,6 +570,74 @@ namespace TaskManager.Controllers |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet] |
|
|
|
public async Task<ActionResult<IEnumerable<TaskConifgure>>> GetAll() |
|
|
|
{ |
|
|
|
return await _repository.GetAllAsync() as List<TaskConifgure>; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpGet("{id}")] |
|
|
|
public async Task<ActionResult<TaskConifgure>> GetById(int id) |
|
|
|
{ |
|
|
|
var entity = await _repository.GetByIdAsync(id); |
|
|
|
if (entity == null) return NotFound(); |
|
|
|
return entity; |
|
|
|
} |
|
|
|
|
|
|
|
[HttpPost] |
|
|
|
public async Task<ActionResult<TaskConifgure>> Create(TaskConifgure 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(TaskConifgure 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<TaskConifgure>>> 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<TaskConifgure, bool>> filter = null; |
|
|
|
|
|
|
|
var pagedResult = await _repository.GetPagedAsync(filter, pagingParams); |
|
|
|
return Ok(pagedResult); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 使用 Hangfire 注册定时任务
|
|
|
|
// Console.WriteLine($"已注册定时任务: {task.TaskName}, Cron: {task.Corn}");
|
|
|
|