| | |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Microsoft.AspNetCore.Mvc.RazorPages; |
| | | using Quartz; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Threading.Tasks; |
| | | using Utility.Entity; |
| | | using Utility; |
| | | using Model.ModelVm; |
| | | using Microsoft.AspNetCore.Authorization; |
| | | |
| | | namespace Wms.Controllers |
| | | { |
| | | /// <summary> |
| | | /// 任务调度 |
| | | /// </summary> |
| | | [Route("api/[controller]/[Action]")] |
| | | [EnableCors("AllowSameDomain")] //允许跨域 |
| | | [Route("api/[controller]/[action]")] |
| | | [ApiController] |
| | | [Authorize] |
| | | [ServiceFilter(typeof(ApiResponseActionFilter))] |
| | | public class JobController : ControllerBase |
| | | { |
| | |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<string> AddJob([FromBody] ScheduleEntity entity) |
| | | public async Task<string> AddJob(ScheduleEntity entity) |
| | | { |
| | | if (entity.TriggerType == TriggerTypeEnum.Cron && |
| | | entity.Cron == "* * * * * ?") |
| | | { |
| | | return "不允许过频繁执行任务!"; |
| | | } |
| | | |
| | | return await scheduler.AddScheduleJobAsync(entity); |
| | | } |
| | | |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<string> StopJob([FromBody] JobKey job) |
| | | public async Task<string> StopJob(JobVm job) |
| | | { |
| | | return await scheduler.StopOrDelScheduleJobAsync(job.Group, job.Name); |
| | | } |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<string> RemoveJob([FromBody] JobKey job) |
| | | public async Task<string> RemoveJob(JobVm job) |
| | | { |
| | | return await scheduler.StopOrDelScheduleJobAsync(job.Group, job.Name, true); |
| | | } |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<string> ResumeJob([FromBody] JobKey job) |
| | | public async Task<string> ResumeJob(JobVm job) |
| | | { |
| | | return await scheduler.ResumeJobAsync(job.Group, job.Name); |
| | | } |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<ScheduleEntity> QueryJob([FromBody] JobKey job) |
| | | public async Task<ScheduleEntity> QueryJob(JobVm job) |
| | | { |
| | | return await scheduler.QueryJobAsync(job.Group, job.Name); |
| | | } |
| | |
| | | /// <param name="entity"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<string> ModifyJob([FromBody] ModifyJobInput entity) |
| | | public async Task<string> ModifyJob(ModifyJobInput entity) |
| | | { |
| | | var jobKey = new JobKey(entity.OldScheduleEntity.JobName, entity.OldScheduleEntity.JobGroup); |
| | | var runNumber = await scheduler.GetRunNumberAsync(jobKey); |
| | | long runNumber = 0; |
| | | try |
| | | { |
| | | runNumber = await scheduler.GetRunNumberAsync(jobKey); |
| | | } |
| | | catch (Exception) |
| | | { |
| | | |
| | | } |
| | | await scheduler.StopOrDelScheduleJobAsync(entity.OldScheduleEntity.JobGroup, entity.OldScheduleEntity.JobName, true); |
| | | await scheduler.AddScheduleJobAsync(entity.NewScheduleEntity, runNumber); |
| | | return "修改计划任务成功!"; |
| | |
| | | /// <param name="job"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<bool> TriggerJob([FromBody] JobKey job) |
| | | public async Task<bool> TriggerJob(JobVm job) |
| | | { |
| | | await scheduler.TriggerJobAsync(job); |
| | | JobKey modKey = new JobKey(job.Name, job.Group); |
| | | await scheduler.TriggerJobAsync(modKey); |
| | | return true; |
| | | } |
| | | |
| | |
| | | /// <param name="jobKey"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | public async Task<List<string>> GetJobLogs([FromBody] JobKey jobKey) |
| | | public async Task<List<string>> GetJobLogs(JobVm job) |
| | | { |
| | | var logs = await scheduler.GetJobLogsAsync(jobKey); |
| | | JobKey modKey = new JobKey(job.Name, job.Group); |
| | | var logs = await scheduler.GetJobLogsAsync(modKey); |
| | | logs?.Reverse(); |
| | | return logs; |
| | | } |
| | |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | public async Task<List<JobInfoEntity>> GetAllJob() |
| | | public async Task<List<JobInfo>> GetAllJob() |
| | | { |
| | | return await scheduler.GetAllJobAsync(); |
| | | var list = await scheduler.GetAllJobAsync(); |
| | | var listJob = new List<JobInfo>(); |
| | | foreach (var mod in list) |
| | | { |
| | | mod.JobInfoList.ForEach(s => s.GroupName = mod.GroupName); |
| | | listJob.AddRange(mod.JobInfoList); |
| | | } |
| | | return listJob; |
| | | } |
| | | |
| | | /// <summary> |