TispContentController.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using Microsoft.AspNetCore.Authorization;
  2. using Microsoft.AspNetCore.Mvc;
  3. using Microsoft.Extensions.Logging;
  4. using Ropin.Inspection.Api.Common;
  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. /// <summary>
  15. /// 巡检内容
  16. /// </summary>
  17. public class TispContentController : BaseController
  18. {
  19. private readonly ILogger<TispContentController> _logger;
  20. private readonly ITispContentService _tispContentService;
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="tispContentService"></param>
  25. /// <param name="logger"></param>
  26. public TispContentController(ITispContentService tispContentService, ILogger<TispContentController> logger)
  27. {
  28. _tispContentService = tispContentService;
  29. _logger = logger;
  30. }
  31. /// <summary>
  32. /// 通过ID获取巡检内容信息
  33. /// </summary>
  34. /// <param name="id"></param>
  35. /// <returns></returns>
  36. [HttpGet("GetContentAsync/{id}")]
  37. public async Task<ApiResult> GetContentAsync(Guid id)
  38. {
  39. if (Guid.Empty == id)
  40. {
  41. return new ApiResult(ReturnCode.GeneralError);
  42. }
  43. try
  44. {
  45. var content = await _tispContentService.GetByIdAsync(id);
  46. return new ApiResult<TispContentViewModel>(content);
  47. }
  48. catch (Exception ex)
  49. {
  50. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  51. }
  52. }
  53. /// <summary>
  54. /// 获取所有巡检内容
  55. /// </summary>
  56. /// <returns></returns>
  57. [HttpGet("GetContentsAsync/{storeCode}")]
  58. public async Task<ApiResult> GetContentsAsync(string storeCode)
  59. {
  60. if (string.IsNullOrEmpty(storeCode))
  61. {
  62. return new ApiResult(ReturnCode.ArgsError);
  63. }
  64. try
  65. {
  66. var contentList = await _tispContentService.GetAllAsync(storeCode);
  67. return new ApiResult<IEnumerable<TispContentViewModel>>(contentList);
  68. }
  69. catch (Exception ex)
  70. {
  71. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  72. }
  73. }
  74. /// <summary>
  75. /// 通过内容条件查询,不分页
  76. /// </summary>
  77. /// <param name="searchModel"></param>
  78. /// <returns></returns>
  79. [HttpPost("GetContentsByAsync")]
  80. public async Task<ApiResult> GetContentsByAsync(TispContentSearchModel searchModel)
  81. {
  82. if (searchModel == null)
  83. {
  84. return new ApiResult(ReturnCode.ArgsError);
  85. }
  86. searchModel.IsPagination = false;
  87. try
  88. {
  89. var contentList = await _tispContentService.GetContentsConditionAsync(searchModel);
  90. return new ApiResult<IEnumerable<TispContentViewModel>>(contentList);
  91. }
  92. catch (Exception ex)
  93. {
  94. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  95. }
  96. }
  97. /// <summary>
  98. /// 创建巡检内容
  99. /// </summary>
  100. /// <param name="content"></param>
  101. /// <returns></returns>
  102. [Route("CreateContentAsync")]
  103. [HttpPost]
  104. public async Task<ApiResult> CreateContentAsync([FromBody] TispContentViewModel content)
  105. {
  106. if (content == null || string.IsNullOrEmpty(content.C_StoreCode))
  107. {
  108. return new ApiResult(ReturnCode.ArgsError);
  109. }
  110. try
  111. {
  112. await _tispContentService.CreateOneAsync(content);
  113. }
  114. catch (Exception ex)
  115. {
  116. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  117. }
  118. return new ApiResult(ReturnCode.Success);
  119. }
  120. /// <summary>
  121. /// 删除巡检内容
  122. /// </summary>
  123. /// <param name="id"></param>
  124. /// <returns></returns>
  125. [HttpDelete("DeleteContentAsync/{id}")]
  126. public async Task<ApiResult> DeleteContentAsync(Guid id)
  127. {
  128. if (Guid.Empty == id)
  129. {
  130. return new ApiResult(ReturnCode.GeneralError);
  131. }
  132. try
  133. {
  134. await _tispContentService.DeleteAsync(id);
  135. }
  136. catch (Exception ex)
  137. {
  138. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  139. }
  140. return new ApiResult(ReturnCode.Success);
  141. }
  142. /// <summary>
  143. /// 更新巡检内容
  144. /// </summary>
  145. /// <param name="id"></param>
  146. /// <param name="updateModel"></param>
  147. /// <returns></returns>
  148. [HttpPut("UpdateContentAsync/{id}")]
  149. public async Task<ApiResult> UpdateContentAsync(Guid id, TispContentUpdateViewModel updateModel)
  150. {
  151. if (Guid.Empty == id)
  152. {
  153. return new ApiResult(ReturnCode.GeneralError);
  154. }
  155. try
  156. {
  157. await _tispContentService.UpdateAsync(id, updateModel);
  158. }
  159. catch (Exception ex)
  160. {
  161. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  162. }
  163. return new ApiResult(ReturnCode.Success);
  164. }
  165. }
  166. }