using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Threading.Tasks; using Admin.Core.Common; using Admin.Core.Common.Resource; using Admin.Core.IService.ISys; using Admin.Core.Model; using Admin.Core.Model.Sys; using Admin.Core.Repository; using Admin.Core.Tasks; using AutoMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Quartz; namespace Admin.Core.Api { /// /// 任务调度 /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class SysJobLogController : BaseApiUserController { private readonly ISysJobLogService _sysJobLogService; private readonly ISysTasksQzService _tasksQzService; private readonly IMapper _mapper; /// /// 构造函数 /// /// /// /// /// public SysJobLogController(ISysJobLogService sysJobLogService, ISysTasksQzService tasksQzService, IMapper mapper, ISysUserService sysUserService) : base(sysUserService) { _sysJobLogService = sysJobLogService; _sysUserService = sysUserService; _mapper = mapper; _tasksQzService = tasksQzService; } /// /// 分页查询 /// /// /// [HttpPost] public async Task>> GetByPage([FromBody] PageQuery pageQuery) { Expression> whereExpression = x => x.DelFlag == false; if (pageQuery.Query.TasksQz.ID != 0) { whereExpression = whereExpression.And(x => x.ID == pageQuery.Query.TasksQz.ID); } if (pageQuery.Query.TasksQz.Name.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.Name.Contains(pageQuery.Query.TasksQz.Name)); } if (pageQuery.Query.TasksQz.JobGroup.IsNotEmptyOrNull()) { whereExpression = whereExpression.And(x => x.JobGroup == pageQuery.Query.TasksQz.JobGroup); } var taskQzs = await _tasksQzService.QueryAsync(whereExpression); var taskIds = taskQzs.Select(x => x.ID).ToList(); Expression> whereExpressionLog = x => true; whereExpressionLog = whereExpressionLog.And(x => taskIds.Contains((int)x.JobID)); if (pageQuery.Query.Status.IsNotEmptyOrNull()) { whereExpressionLog = whereExpressionLog.And(x => x.Status == pageQuery.Query.Status); } if (pageQuery.DateRange.IsNotEmptyOrNull() && pageQuery.DateRange.Count > 0) { if (pageQuery.DateRange[0].IsNotEmptyOrNull()) { whereExpressionLog = whereExpressionLog.And(x => x.RunTimeStart >= pageQuery.DateRange[0]); } if (pageQuery.DateRange.Count > 1 && pageQuery.DateRange[1].IsNotEmptyOrNull()) { whereExpressionLog = whereExpressionLog.And(x => x.RunTimeEnd <= pageQuery.DateRange[1]); } } var orderBy = (pageQuery.OrderBy ?? "ID") + " " + (pageQuery.IsAsc ? "asc" : "desc"); var log = await _sysJobLogService.QueryPageAsync(whereExpressionLog, pageQuery.Page, pageQuery.PageSize, orderBy); var data = _mapper.Map>(log); data.data.ForEach(x => x.TasksQz = taskQzs.Find(m => m.ID == x.JobID)); return Success(data); } /// /// 删除日志 /// /// /// [HttpPost] public async Task> Del(List jobId) { return Success(await _sysJobLogService.DeleteByIdAsync(jobId)); } /// /// 清空日志 /// /// [HttpGet] public async Task> Clear() { return Success(await _sysJobLogService.Clear()); } } }