| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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 X2D1TaskServer.Service;
- using System.Threading;
- using System.Threading.Tasks;
- namespace X2D1TaskServer.Controllers
- {
- /// <summary>
- ///两星一地任务处理接口
- /// </summary>
- public class X2D1TaskProcessingController : BaseController
- {
- /*******************
- * !!!不要在Controller中放业务逻辑的全局变量
- * !!!不要在Controller写太复杂的业务逻辑
- * Controller主要就是调用Service层的东西。Service层执行业务逻辑和调用Repository层操作数据库
- * ********************/
- private readonly TaskHistoryService _tskHservice;
- private readonly TaskRealService _tskRservice;
- public X2D1TaskProcessingController(TaskHistoryService tskHservice, TaskRealService tskRservice)
- {
- _tskHservice = tskHservice;
- _tskRservice = tskRservice;
- }
- /// <summary>
- /// 开始执行两星一地无参任务
- /// </summary>
- /// <param name="dto">离线任务信息</param>
- /// <returns></returns>
- [HttpPost]
- public AjaxResult Run(X2D1TaskHandleDto dto)
- {
- try
- {
- if (_service.Stop(dto.ID))
- {
- Thread.Sleep(2000);
- }
- if (dto.TaskType == EnumTaskTypeDto.History)
- _tskHservice.StartAsync(dto);
- else
- _tskRservice.StartAsync(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 async Task<AjaxResult> Stop(TaskStopHandleDto dto)
- {
- try
- {
- await LogHelper.Warning($"用户停止了任务,ID={dto.ID}");
- if (dto.TaskType == EnumTaskTypeDto.History)
- _tskHservice.Stop(dto.ID);
- else
- _tskRservice.Stop(dto.ID);
- return Success();
- }
- catch (Exception ex)
- {
- Serilog.Log.Error(ex, $"【任务{dto.ID}】停止执行异常!");
- return Error($"【任务{dto.ID}】停止执行异常!");
- }
- }
- }
- }
|