TispRegionController.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model.SearchModel;
  5. using Ropin.Inspection.Model.ViewModel;
  6. using Ropin.Inspection.Service.Interface;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Api.Controllers
  12. {
  13. public class TispRegionController : BaseController
  14. {
  15. public ILogger<TispRegionController> _logger { get; }
  16. private readonly ITispRegionService _tispRegionService;
  17. /// <summary>
  18. /// 构造函数
  19. /// </summary>
  20. /// <param name="tispRegionService"></param>
  21. /// <param name="logger"></param>
  22. public TispRegionController(ITispRegionService tispRegionService, ILogger<TispRegionController> logger)
  23. {
  24. _tispRegionService = tispRegionService;
  25. _logger = logger;
  26. }
  27. /// <summary>
  28. /// 通过ID获取巡检区域信息
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. [HttpGet("GetRegionAsync/{id}")]
  33. public async Task<ApiResult> GetRegionAsync(Guid id)
  34. {
  35. if (Guid.Empty == id)
  36. {
  37. return new ApiResult(ReturnCode.GeneralError);
  38. }
  39. try
  40. {
  41. var content = await _tispRegionService.GetByIdAsync(id);
  42. return new ApiResult<TispRegionViewModel>(content);
  43. }
  44. catch (Exception ex)
  45. {
  46. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  47. }
  48. }
  49. /// <summary>
  50. /// 获取所有巡检区域
  51. /// </summary>
  52. /// <returns></returns>
  53. [HttpGet("GetRegionsAsync")]
  54. public async Task<ApiResult> GetRegionsAsync()
  55. {
  56. try
  57. {
  58. var contentList = await _tispRegionService.GetAllAsync();
  59. return new ApiResult<IEnumerable<TispRegionViewModel>>(contentList);
  60. }
  61. catch (Exception ex)
  62. {
  63. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  64. }
  65. }
  66. /// <summary>
  67. /// 通过巡检区域名称条件查询
  68. /// </summary>
  69. /// <param name="searchModel"></param>
  70. /// <returns></returns>
  71. [HttpPost("GetRegionsByAsync")]
  72. public async Task<ApiResult> GetRegionsByAsync(TispRegionSearchModel searchModel)
  73. {
  74. if (searchModel == null)
  75. {
  76. return new ApiResult(ReturnCode.ArgsError);
  77. }
  78. searchModel.IsPagination = false;
  79. try
  80. {
  81. var contentList = await _tispRegionService.GetRegionsConditionAsync(searchModel);
  82. return new ApiResult<IEnumerable<TispRegionViewModel>>(contentList);
  83. }
  84. catch (Exception ex)
  85. {
  86. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  87. }
  88. }
  89. /// <summary>
  90. /// 创建巡检区域
  91. /// </summary>
  92. /// <param name="content"></param>
  93. /// <returns></returns>
  94. [HttpPost("CreateRegionAsync")]
  95. public async Task<ApiResult> CreateRegionAsync(TispRegionCreateViewModel content)
  96. {
  97. if (content == null)
  98. {
  99. return new ApiResult(ReturnCode.ArgsError);
  100. }
  101. try
  102. {
  103. TispRegionViewModel mode = new TispRegionViewModel { C_Name = content.C_Name, C_ImageUrl = content.C_ImageUrl, C_Remark = content.C_Remark };
  104. await _tispRegionService.CreateOneAsync(mode);
  105. }
  106. catch (Exception ex)
  107. {
  108. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  109. }
  110. return new ApiResult(ReturnCode.Success);
  111. }
  112. /// <summary>
  113. /// 删除巡检区域
  114. /// </summary>
  115. /// <param name="id"></param>
  116. /// <returns></returns>
  117. [HttpDelete("DeleteRegionAsync/{id}")]
  118. public async Task<ApiResult> DeleteRegionAsync(Guid id)
  119. {
  120. if (Guid.Empty == id)
  121. {
  122. return new ApiResult(ReturnCode.GeneralError);
  123. }
  124. try
  125. {
  126. await _tispRegionService.DeleteAsync(id);
  127. }
  128. catch (Exception ex)
  129. {
  130. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  131. }
  132. return new ApiResult(ReturnCode.Success);
  133. }
  134. /// <summary>
  135. /// 更新巡检区域
  136. /// </summary>
  137. /// <param name="id"></param>
  138. /// <param name="updateModel"></param>
  139. /// <returns></returns>
  140. [HttpPut("UpdateRegionAsync/{id}")]
  141. public async Task<ApiResult> UpdateRegionAsync(Guid id, TispRegionUpdateViewModel updateModel)
  142. {
  143. if (Guid.Empty == id)
  144. {
  145. return new ApiResult(ReturnCode.GeneralError);
  146. }
  147. try
  148. {
  149. await _tispRegionService.UpdateAsync(id, updateModel);
  150. }
  151. catch (Exception ex)
  152. {
  153. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  154. }
  155. return new ApiResult(ReturnCode.Success);
  156. }
  157. }
  158. }