AdController.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using AdService.Service;
  2. namespace AdService.Controllers
  3. {
  4. /// <summary>
  5. /// 采集接口
  6. /// </summary>
  7. public class AdController : BaseController
  8. {
  9. ILogger logger { get; set; }
  10. private AdcService AdcService { get; set; }
  11. /// <summary>
  12. /// 开始采集
  13. /// </summary>
  14. /// <returns></returns>
  15. [HttpPost]
  16. public async Task<AjaxResult<AdcResultDto>> StartAd(List<AdSatChDto> dtos)
  17. {
  18. try
  19. {
  20. if (!dtos.Any())
  21. {
  22. return new AjaxResult<AdcResultDto>();
  23. }
  24. var res = await AdcService.Instance.StartTestAsync(dtos);
  25. return Success(res);
  26. }
  27. catch (Exception ex)
  28. {
  29. logger.LogError("开始采集异常:"+ex.Message);
  30. return Error<AdcResultDto>("开始采集异常");
  31. }
  32. }
  33. /// <summary>
  34. /// 停止采集
  35. /// </summary>
  36. [HttpPost]
  37. public async Task<AjaxResult> StopAdc()
  38. {
  39. var res = await Task.Run(() =>
  40. {
  41. try
  42. {
  43. AdcService.Instance.StopAd();
  44. return Success();
  45. }
  46. catch (Exception ex)
  47. {
  48. logger.LogError("停止采集异常:" + ex.Message);
  49. return Error("停止采集异常");
  50. }
  51. });
  52. return res;
  53. }
  54. }
  55. }