ReportController.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model;
  5. using Ropin.Inspection.Model.SearchModel;
  6. using Ropin.Inspection.Model.ViewModel;
  7. using Ropin.Inspection.Service.Interface;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Linq;
  11. using System.Threading.Tasks;
  12. namespace Ropin.Inspection.Api.Controllers
  13. {
  14. public class ReportController : BaseController
  15. {
  16. public ILogger<ReportController> _logger { get; }
  17. private readonly IReportService _service;
  18. /// <summary>
  19. /// 构造函数
  20. /// </summary>
  21. /// <param name="service"></param>
  22. /// <param name="logger"></param>
  23. public ReportController(IReportService service, ILogger<ReportController> logger)
  24. {
  25. _service = service;
  26. _logger = logger;
  27. }
  28. /// <summary>
  29. /// 通过ID获取报表信息
  30. /// </summary>
  31. /// <param name="id"></param>
  32. /// <returns></returns>
  33. [HttpGet("GetReportDataAsync/{id}")]
  34. public async Task<ApiResult> GetReportDataAsync(Guid id)
  35. {
  36. if (Guid.Empty == id)
  37. {
  38. return new ApiResult(ReturnCode.GeneralError);
  39. }
  40. try
  41. {
  42. object Report = await _service.GetReportDataByIdAsync(id);
  43. return new ApiResult<object>(Report);
  44. }
  45. catch (Exception ex)
  46. {
  47. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  48. }
  49. }
  50. /// <summary>
  51. /// 条件获取报表记录,不包含报表数据,带分页
  52. /// </summary>
  53. /// <param name="searchModel"></param>
  54. /// <returns></returns>
  55. [HttpPost("GetWithoutReportData")]
  56. public async Task<ApiResult> GetWithoutReportData(ReportSearchModel searchModel)
  57. {
  58. if (searchModel == null)
  59. {
  60. return new ApiResult(ReturnCode.ArgsError);
  61. }
  62. try
  63. {
  64. var reportList = await _service.GetWithoutReportData(searchModel);
  65. return new ApiResult<PagesModel<ReportViewModel>>(new PagesModel<ReportViewModel>(reportList?.ToList(), searchModel));
  66. }
  67. catch (Exception ex)
  68. {
  69. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  70. }
  71. }
  72. /// <summary>
  73. /// 更新巡检记录
  74. /// </summary>
  75. /// <param name="id"></param>
  76. /// <param name="updateModel"></param>
  77. /// <returns></returns>
  78. [HttpPut("UpdateReportAsync/{id}")]
  79. public async Task<ApiResult> UpdateReportAsync(Guid id, ReportUpdateViewModel updateModel)
  80. {
  81. if (Guid.Empty == id|| updateModel == null)
  82. {
  83. return new ApiResult(ReturnCode.GeneralError);
  84. }
  85. try
  86. {
  87. await _service.UpdateAsync(id, updateModel);
  88. }
  89. catch (Exception ex)
  90. {
  91. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  92. }
  93. return new ApiResult(ReturnCode.Success);
  94. }
  95. /// <summary>
  96. /// 删除
  97. /// </summary>
  98. /// <param name="id"></param>
  99. /// <returns></returns>
  100. [HttpDelete("DeleteReportAsync/{id}")]
  101. public async Task<ApiResult> DeleteReportAsync(Guid id)
  102. {
  103. if (Guid.Empty == id)
  104. {
  105. return new ApiResult(ReturnCode.GeneralError);
  106. }
  107. try
  108. {
  109. await _service.DeleteAsync(id);
  110. }
  111. catch (Exception ex)
  112. {
  113. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  114. }
  115. return new ApiResult(ReturnCode.Success);
  116. }
  117. }
  118. }