SvrReportController.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel.DataAnnotations;
  4. using System.Data.Entity;
  5. using System.Data.Entity.Migrations;
  6. using System.Data.SqlClient;
  7. using System.IO;
  8. using System.Linq;
  9. using System.Text;
  10. using System.Threading.Tasks;
  11. using System.Web.Http;
  12. using DevExpress.XtraBars;
  13. using Serilog;
  14. using XdCxRhDW.App.Model;
  15. using XdCxRhDW.App.Service;
  16. using XdCxRhDW.Dto;
  17. using XdCxRhDW.WebApi;
  18. namespace XdCxRhDW.App.Controllers
  19. {
  20. /// <summary>
  21. /// 服务状态上报接口
  22. /// </summary>
  23. public class SvrReportController : BaseController
  24. {
  25. FileWriterService _service;
  26. public SvrReportController(FileWriterService service)
  27. {
  28. _service = service;
  29. }
  30. /// <summary>
  31. /// 服务状态上报
  32. /// </summary>
  33. /// <param name="dto">服务状态信息</param>
  34. /// <returns></returns>
  35. [HttpPost]
  36. public async Task<AjaxResult> Report(SvrStateReportDto dto)
  37. {
  38. try
  39. {
  40. if (!string.IsNullOrWhiteSpace(dto.BaseHttpAddr))
  41. {
  42. if (dto.BaseHttpAddr.EndsWith("/"))
  43. dto.BaseHttpAddr = dto.BaseHttpAddr + "api/";
  44. else
  45. dto.BaseHttpAddr = dto.BaseHttpAddr + "/api/";
  46. }
  47. if (dto.ModuleType == EnumModuleType.Soft)
  48. {
  49. Messenger.Defalut.Pub("服务状态改变", dto);
  50. }
  51. if (dto.ID == 0)
  52. _service.WriteStateRes(dto);
  53. return Success();
  54. }
  55. catch (Exception ex)
  56. {
  57. await LogHelper.Error("服务状态上报处理出错!", ex);
  58. return Error("服务状态上报处理出错");
  59. }
  60. }
  61. }
  62. }