TdevDevSpotController.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Api.Controllers;
  5. using Ropin.Inspection.Model;
  6. using Ropin.Inspection.Service;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Threading.Tasks;
  11. namespace Ropin.Inspection.Api
  12. {
  13. public class TdevDevSpotController : BaseController
  14. {
  15. public ILogger<TdevDevSpotController> _logger { get; }
  16. private readonly ITdevDevSpotService _TdevDevSpotService;
  17. /// <summary>
  18. /// 构造函数
  19. /// </summary>
  20. /// <param name="TdevDevSpotService"></param>
  21. /// <param name="logger"></param>
  22. public TdevDevSpotController(ITdevDevSpotService TdevDevSpotService, ILogger<TdevDevSpotController> logger)
  23. {
  24. _TdevDevSpotService = TdevDevSpotService;
  25. _logger = logger;
  26. }
  27. /// <summary>
  28. /// 通过id获取业主设备点信息
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. [HttpGet("GetDevSpotAsync/{id}")]
  33. public async Task<ApiResult> GetDevSpotAsync(string id)
  34. {
  35. if (string.IsNullOrEmpty(id))
  36. {
  37. return new ApiResult(ReturnCode.GeneralError);
  38. }
  39. try
  40. {
  41. var content = await _TdevDevSpotService.GetConditionAsync(new TdevDevSpotSearchModel { C_ID = id });
  42. return new ApiResult<TdevDevSpotViewModel>(content.FirstOrDefault());
  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("GetDevSpotsAsync")]
  54. public async Task<ApiResult> GetDevSpotsAsync()
  55. {
  56. try
  57. {
  58. var contentList = await _TdevDevSpotService.GetAllAsync();
  59. return new ApiResult<IEnumerable<TdevDevSpotViewModel>>(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("GetDevSpotsByAsync")]
  72. public async Task<ApiResult> GetDevSpotsByAsync(TdevDevSpotSearchModel 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 _TdevDevSpotService.GetConditionAsync(searchModel);
  82. return new ApiResult<PagesModel<TdevDevSpotViewModel>>(new PagesModel<TdevDevSpotViewModel>(contentList, searchModel));
  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("CreateDevSpotAsync")]
  95. public async Task<ApiResult> CreateDevSpotAsync(TdevDevSpotViewModel content)
  96. {
  97. if (content == null)
  98. {
  99. return new ApiResult(ReturnCode.ArgsError);
  100. }
  101. try
  102. {
  103. await _TdevDevSpotService.CreateOneAsync(content);
  104. }
  105. catch (Exception ex)
  106. {
  107. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  108. }
  109. return new ApiResult(ReturnCode.Success);
  110. }
  111. /// <summary>
  112. /// 删除业主设备点
  113. /// </summary>
  114. /// <param name="id"></param>
  115. /// <returns></returns>
  116. [HttpDelete("DeleteDevSpotAsync/{id}")]
  117. public async Task<ApiResult> DeleteDevSpotAsync(string id)
  118. {
  119. if (string.IsNullOrEmpty(id))
  120. {
  121. return new ApiResult(ReturnCode.GeneralError);
  122. }
  123. try
  124. {
  125. await _TdevDevSpotService.DeleteAsync(id);
  126. }
  127. catch (Exception ex)
  128. {
  129. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  130. }
  131. return new ApiResult(ReturnCode.Success);
  132. }
  133. /// <summary>
  134. /// 更新业主设备点
  135. /// </summary>
  136. /// <param name="id"></param>
  137. /// <param name="updateModel"></param>
  138. /// <returns></returns>
  139. [HttpPut("UpdateDevSpotAsync/{id}")]
  140. public async Task<ApiResult> UpdateDevSpotAsync(string id, TdevDevSpotUpdateModel updateModel)
  141. {
  142. if (string.IsNullOrEmpty(id))
  143. {
  144. return new ApiResult(ReturnCode.GeneralError);
  145. }
  146. try
  147. {
  148. await _TdevDevSpotService.UpdateAsync(id, updateModel);
  149. }
  150. catch (Exception ex)
  151. {
  152. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  153. }
  154. return new ApiResult(ReturnCode.Success);
  155. }
  156. /// <summary>
  157. /// 更新业主设备点列表
  158. /// </summary>
  159. /// <param name="updateModel"></param>
  160. /// <returns></returns>
  161. [HttpPost("UpdateDevSpotAsync")]
  162. public async Task<ApiResult> UpdateDevSpotAsync(TdevDevSpotsUpdateModel updateModel)
  163. {
  164. if (updateModel == null || updateModel.SpotCodeList == null)
  165. {
  166. return new ApiResult(ReturnCode.ArgsError);
  167. }
  168. try
  169. {
  170. await _TdevDevSpotService.UpdateDevSpotAsync(updateModel);
  171. }
  172. catch (Exception ex)
  173. {
  174. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  175. }
  176. return new ApiResult(ReturnCode.Success);
  177. }
  178. }
  179. }