| | |
| | | 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 "不允许过频繁执行任务!"; |
| | | } |
| | | |
| | | throw Oops.Bah("测试异常"); |
| | | return await scheduler.AddScheduleJobAsync(entity); |
| | | } |
| | | |
| | |
| | | /// <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 "修改计划任务成功!"; |
| | |
| | | /// </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> |