HistoryTaskProcessingController.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Configuration;
  4. using System.IO;
  5. using System.Web.Http;
  6. using XdCxRhDW.Dto;
  7. using XdCxRhDW.TaskServer.Task;
  8. using XdCxRhDW.WebApi;
  9. namespace XdCxRhDW.TaskServer.Controllers
  10. {
  11. /// <summary>
  12. ///离线任务处理接口
  13. /// </summary>
  14. public class HistoryTaskProcessingController : BaseController
  15. {
  16. public List<HistoryTaskI> allTask = new List<HistoryTaskI>();
  17. /// <summary>
  18. /// 执行离线任务
  19. /// </summary>
  20. /// <param name="dto">离线任务信息</param>
  21. /// <returns></returns>
  22. [HttpPost]
  23. public AjaxResult Run(HistoryTaskProcessingDto dto)
  24. {
  25. try
  26. {
  27. LogHelper.Info($"接收到历史任务编号:{dto.ID}");
  28. dto.StartTime = new DateTime(2024, 03, 24, 12, 00, 00);
  29. dto.DateDirFormat = "yyyyMMddHH";
  30. dto.CapDir = @"D:\\data";
  31. dto.SigType = EnumSigTypeDto.DAMA;
  32. dto.PosType = EnumPosTypeDto.X2D1;
  33. dto.DmcType = DmcTypeDto.DAMA;
  34. if (!Directory.Exists(dto.CapDir))
  35. {
  36. LogHelper.Error($"采集路径:{dto.CapDir}不存在");
  37. return Error($"采集路径:{dto.CapDir}不存在");
  38. }
  39. if (dto.PosType == EnumPosTypeDto.X2D1)
  40. {
  41. X2D1Task x2D1 = new X2D1Task();
  42. x2D1.Start(dto);
  43. allTask.Add(x2D1);
  44. }
  45. else
  46. {
  47. return Error($"历史任务不支持定位模式{dto.PosType.GetEnumDisplayName()}");
  48. }
  49. return Success();
  50. }
  51. catch (Exception ex)
  52. {
  53. Serilog.Log.Error(ex, "历史任务处理出错!");
  54. return Error("历史任务处理出错");
  55. }
  56. }
  57. /// <summary>
  58. ///
  59. /// </summary>
  60. /// <param name="TaskId"></param>
  61. /// <returns></returns>
  62. [HttpPost]
  63. public AjaxResult Stop(int TaskId)
  64. {
  65. try
  66. {
  67. LogHelper.Info($"接收停止历史任务编号:{TaskId}");
  68. var history = allTask.Find(t => t.TaskDto.ID == TaskId);
  69. if (history != null)
  70. {
  71. history.Stop();
  72. allTask.Remove(history);
  73. }
  74. return Success();
  75. }
  76. catch (Exception ex)
  77. {
  78. Serilog.Log.Error(ex, "停止历史任务处理出错!");
  79. return Error("停止历史任务处理出错");
  80. }
  81. }
  82. }
  83. }