12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using DevExpress.Utils.Extensions;
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.IO;
- using System.Linq;
- using System.Web.Http;
- using XdCxRhDW.Dto;
- using XdCxRhDW.WebApi;
- using X2D1NoRefTaskServer.Service;
- using System.Threading;
- namespace X2D1NoRefTaskServer.Controllers
- {
- /// <summary>
- ///两星一地无参任务处理接口
- /// </summary>
- public class X2D1NoRefTaskProcessingController : BaseController
- {
- /*******************
- * !!!不要在Controller中放业务逻辑的全局变量
- * !!!不要在Controller写太复杂的业务逻辑
- * Controller主要就是调用Service层的东西。Service层执行业务逻辑和调用Repository层操作数据库
- * ********************/
- private readonly TaskService _service;
- public X2D1NoRefTaskProcessingController(TaskService service)
- {
- _service = service;
- }
- /// <summary>
- /// 开始执行两星一地无参任务
- /// </summary>
- /// <param name="dto">离线任务信息</param>
- /// <returns></returns>
- [HttpPost]
- public AjaxResult Run(X2D1NoRefTaskHandleDto dto)
- {
- try
- {
- if (dto.TaskType == EnumTaskTypeDto.History)
- _service.StartHistoryAsync(dto);
- else
- _service.StarRealAsync(dto);
- return Success();
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"【任务{dto.ID}】开始执行异常!");
- return Error($"【任务{dto.ID}】开始执行异常!");
- }
- }
- /// <summary>
- /// 停止执行两星一地无参任务
- /// </summary>
- /// <param name="dto"></param>
- /// <returns></returns>
- [HttpPost]
- public AjaxResult Stop(TaskStopHandleDto dto)
- {
- try
- {
- LogHelper.Warning($"用户停止了任务,ID={dto.ID}");
- _service.Stop(dto.ID);
- return Success();
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"【任务{dto.ID}】停止执行异常!");
- return Error($"【任务{dto.ID}】停止执行异常!");
- }
- }
- }
- }
|