TispSpotContentController.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model.ViewModel;
  5. using Ropin.Inspection.Service.Interface;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. namespace Ropin.Inspection.Api.Controllers
  11. {
  12. /// <summary>
  13. /// 巡检点内容
  14. /// </summary>
  15. public class TispSpotContentController : BaseController
  16. {
  17. public ILogger<TispSpotContentController> _logger { get; }
  18. private readonly ITispSpotContentService _tispSpotContentService;
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. /// <param name="tispSpotContentService"></param>
  23. /// <param name="logger"></param>
  24. public TispSpotContentController(ITispSpotContentService tispSpotContentService, ILogger<TispSpotContentController> logger)
  25. {
  26. _tispSpotContentService = tispSpotContentService;
  27. _logger = logger;
  28. }
  29. /// <summary>
  30. /// 通过ID获取巡检点内容信息
  31. /// </summary>
  32. /// <param name="id"></param>
  33. /// <returns></returns>
  34. [HttpGet("GetSpotContentAsync/{id}")]
  35. public async Task<ApiResult> GetSpotContentAsync(Guid id)
  36. {
  37. if (Guid.Empty == id)
  38. {
  39. return new ApiResult(ReturnCode.GeneralError);
  40. }
  41. try
  42. {
  43. var content = await _tispSpotContentService.GetByIdAsync(id);
  44. return new ApiResult<TispSpotContentViewModel>(content);
  45. }
  46. catch (Exception ex)
  47. {
  48. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  49. }
  50. }
  51. /// <summary>
  52. /// 获取所有巡检点内容
  53. /// </summary>
  54. /// <returns></returns>
  55. [HttpGet("GetSpotContentsAsync")]
  56. public async Task<ApiResult> GetSpotContentsAsync()
  57. {
  58. try
  59. {
  60. var contentList = await _tispSpotContentService.GetAllAsync();
  61. return new ApiResult<IEnumerable<TispSpotContentViewModel>>(contentList);
  62. }
  63. catch (Exception ex)
  64. {
  65. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  66. }
  67. }
  68. /// <summary>
  69. /// 创建巡检点内容
  70. /// </summary>
  71. /// <param name="content"></param>
  72. /// <returns></returns>
  73. [Route("CreateSpotContentAsync")]
  74. [HttpPost]
  75. public async Task<ApiResult> CreateSpotContentAsync([FromBody] TispSpotContentViewModel content)
  76. {
  77. if (content == null)
  78. {
  79. return new ApiResult(ReturnCode.ArgsError);
  80. }
  81. try
  82. {
  83. await _tispSpotContentService.CreateOneAsync(content);
  84. }
  85. catch (Exception ex)
  86. {
  87. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  88. }
  89. return new ApiResult(ReturnCode.Success);
  90. }
  91. /// <summary>
  92. /// 删除巡检点内容
  93. /// </summary>
  94. /// <param name="id"></param>
  95. /// <returns></returns>
  96. [HttpDelete("DeleteSpotContentAsync/{id}")]
  97. public async Task<ApiResult> DeleteSpotContentAsync(Guid id)
  98. {
  99. if (Guid.Empty == id)
  100. {
  101. return new ApiResult(ReturnCode.GeneralError);
  102. }
  103. try
  104. {
  105. await _tispSpotContentService.DeleteAsync(id);
  106. }
  107. catch (Exception ex)
  108. {
  109. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  110. }
  111. return new ApiResult(ReturnCode.Success);
  112. }
  113. /// <summary>
  114. /// 更新巡检点内容
  115. /// </summary>
  116. /// <param name="id"></param>
  117. /// <param name="updateModel"></param>
  118. /// <returns></returns>
  119. [HttpPut("UpdateSpotContentAsync/{id}")]
  120. public async Task<ApiResult> UpdateSpotContentAsync(Guid id, TispSpotContentUpdateViewModel updateModel)
  121. {
  122. if (Guid.Empty == id)
  123. {
  124. return new ApiResult(ReturnCode.GeneralError);
  125. }
  126. try
  127. {
  128. await _tispSpotContentService.UpdateAsync(id, updateModel);
  129. }
  130. catch (Exception ex)
  131. {
  132. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  133. }
  134. return new ApiResult(ReturnCode.Success);
  135. }
  136. }
  137. }