TpntAreaController.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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.Service;
  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. public class TpntAreaController : BaseController
  13. {
  14. public ILogger<TpntAreaController> _logger { get; }
  15. private readonly ITpntAreaService _TpntAreaService;
  16. /// <summary>
  17. /// 构造函数
  18. /// </summary>
  19. /// <param name="TpntAreaService"></param>
  20. /// <param name="logger"></param>
  21. public TpntAreaController(ITpntAreaService TpntAreaService, ILogger<TpntAreaController> logger)
  22. {
  23. _TpntAreaService = TpntAreaService;
  24. _logger = logger;
  25. }
  26. ///// <summary>
  27. ///// 通过ID获取区域信息
  28. ///// </summary>
  29. ///// <param name="id"></param>
  30. ///// <returns></returns>
  31. //[HttpGet("GetAreaAsync/{id}")]
  32. //public async Task<ApiResult> GetAreaAsync(Guid id)
  33. //{
  34. // if (Guid.Empty == id)
  35. // {
  36. // return new ApiResult(ReturnCode.GeneralError);
  37. // }
  38. // try
  39. // {
  40. // var content = await _TpntAreaService.GetByIdAsync(id);
  41. // return new ApiResult<TpntAreaViewModel>(content);
  42. // }
  43. // catch (Exception ex)
  44. // {
  45. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  46. // }
  47. //}
  48. /// <summary>
  49. /// 通过code获取区域信息
  50. /// </summary>
  51. /// <param name="code"></param>
  52. /// <returns></returns>
  53. [HttpGet("GetAreaAsync/{code}")]
  54. public async Task<ApiResult> GetAreaAsync(string code)
  55. {
  56. if (string.IsNullOrEmpty(code))
  57. {
  58. return new ApiResult(ReturnCode.GeneralError);
  59. }
  60. try
  61. {
  62. var content = await _TpntAreaService.GetConditionAsync(new TpntAreaSearchModel {C_Code = code });
  63. return new ApiResult<TpntAreaViewModel>(content.FirstOrDefault());
  64. }
  65. catch (Exception ex)
  66. {
  67. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  68. }
  69. }
  70. /// <summary>
  71. /// 获取所有区域
  72. /// </summary>
  73. /// <returns></returns>
  74. [HttpGet("GetAreasAsync")]
  75. public async Task<ApiResult> GetAreasAsync()
  76. {
  77. try
  78. {
  79. var contentList = await _TpntAreaService.GetAllAsync();
  80. return new ApiResult<IEnumerable<TpntAreaViewModel>>(contentList);
  81. }
  82. catch (Exception ex)
  83. {
  84. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  85. }
  86. }
  87. /// <summary>
  88. /// 通过区域名称条件查询
  89. /// </summary>
  90. /// <param name="searchModel"></param>
  91. /// <returns></returns>
  92. [HttpPost("GetAreasByAsync")]
  93. public async Task<ApiResult> GetAreasByAsync(TpntAreaSearchModel searchModel)
  94. {
  95. if (searchModel == null)
  96. {
  97. return new ApiResult(ReturnCode.ArgsError);
  98. }
  99. searchModel.IsPagination = false;
  100. try
  101. {
  102. var contentList = await _TpntAreaService.GetConditionAsync(searchModel);
  103. return new ApiResult<IEnumerable<TpntAreaViewModel>>(contentList);
  104. }
  105. catch (Exception ex)
  106. {
  107. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  108. }
  109. }
  110. /// <summary>
  111. /// 创建区域
  112. /// </summary>
  113. /// <param name="content"></param>
  114. /// <returns></returns>
  115. [HttpPost("CreateAreaAsync")]
  116. public async Task<ApiResult> CreateAreaAsync(TpntAreaViewModel content)
  117. {
  118. if (content == null)
  119. {
  120. return new ApiResult(ReturnCode.ArgsError);
  121. }
  122. try
  123. {
  124. await _TpntAreaService.CreateOneAsync(content);
  125. }
  126. catch (Exception ex)
  127. {
  128. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  129. }
  130. return new ApiResult(ReturnCode.Success);
  131. }
  132. /// <summary>
  133. /// 删除区域
  134. /// </summary>
  135. /// <param name="code"></param>
  136. /// <returns></returns>
  137. [HttpDelete("DeleteAreaAsync/{code}")]
  138. public async Task<ApiResult> DeleteAreaAsync(string code)
  139. {
  140. if (string.IsNullOrEmpty(code))
  141. {
  142. return new ApiResult(ReturnCode.GeneralError);
  143. }
  144. try
  145. {
  146. await _TpntAreaService.DeleteAsync(code);
  147. }
  148. catch (Exception ex)
  149. {
  150. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  151. }
  152. return new ApiResult(ReturnCode.Success);
  153. }
  154. /// <summary>
  155. /// 更新区域
  156. /// </summary>
  157. /// <param name="code"></param>
  158. /// <param name="updateModel"></param>
  159. /// <returns></returns>
  160. [HttpPut("UpdateAreaAsync/{code}")]
  161. public async Task<ApiResult> UpdateAreaAsync(string code, TpntAreaUpdateModel updateModel)
  162. {
  163. if (string.IsNullOrEmpty(code))
  164. {
  165. return new ApiResult(ReturnCode.GeneralError);
  166. }
  167. try
  168. {
  169. await _TpntAreaService.UpdateAsync(code, updateModel);
  170. }
  171. catch (Exception ex)
  172. {
  173. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  174. }
  175. return new ApiResult(ReturnCode.Success);
  176. }
  177. }
  178. }