TispRouteController.cs 5.4 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 TispRouteController : BaseController
  14. {
  15. public ILogger<TispRouteController> _logger { get; }
  16. private readonly ITispRouteService _tispRouteService;
  17. /// <summary>
  18. /// 构造函数
  19. /// </summary>
  20. /// <param name="tispRouteService"></param>
  21. /// <param name="logger"></param>
  22. public TispRouteController(ITispRouteService tispRouteService, ILogger<TispRouteController> logger)
  23. {
  24. _tispRouteService = tispRouteService;
  25. _logger = logger;
  26. }
  27. /// <summary>
  28. /// 通过ID获取巡检路线信息
  29. /// </summary>
  30. /// <param name="id"></param>
  31. /// <returns></returns>
  32. [HttpGet("GetRouteAsync/{id}")]
  33. public async Task<ApiResult> GetRouteAsync(Guid id)
  34. {
  35. if (Guid.Empty == id)
  36. {
  37. return new ApiResult(ReturnCode.GeneralError);
  38. }
  39. try
  40. {
  41. var content = await _tispRouteService.GetByIdAsync(id);
  42. return new ApiResult<TispRouteViewModel>(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("GetRoutesAsync")]
  54. public async Task<ApiResult> GetRoutesAsync()
  55. {
  56. try
  57. {
  58. var contentList = await _tispRouteService.GetAllAsync();
  59. return new ApiResult<IEnumerable<TispRouteViewModel>>(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("GetRoutesByAsync")]
  72. public async Task<ApiResult> GetRoutesByAsync(TispRouteSearchModel searchModel)
  73. {
  74. if (searchModel == null|| string.IsNullOrEmpty(searchModel.C_StoreCode))
  75. {
  76. return new ApiResult(ReturnCode.ArgsError);
  77. }
  78. searchModel.IsPagination = false;
  79. try
  80. {
  81. var contentList = await _tispRouteService.GetRoutesConditionAsync(searchModel);
  82. return new ApiResult<IEnumerable<TispRouteViewModel>>(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. [Route("CreateRouteAsync")]
  95. [HttpPost]
  96. public async Task<ApiResult> CreateRouteAsync(TispRouteCreateViewModel content)
  97. {
  98. if (content == null && string.IsNullOrEmpty(content.C_StoreCode))
  99. {
  100. return new ApiResult(ReturnCode.ArgsError);
  101. }
  102. try
  103. {
  104. TispRouteViewModel mode = new TispRouteViewModel { C_StoreCode = content.C_StoreCode, C_Name = content.C_Name,C_ImageUrl = content.C_ImageUrl,C_Remark=content.C_Remark };
  105. await _tispRouteService.CreateOneAsync(mode);
  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. /// <returns></returns>
  118. [HttpDelete("DeleteRouteAsync/{id}")]
  119. public async Task<ApiResult> DeleteRouteAsync(Guid id)
  120. {
  121. if (Guid.Empty == id)
  122. {
  123. return new ApiResult(ReturnCode.GeneralError);
  124. }
  125. try
  126. {
  127. await _tispRouteService.DeleteAsync(id);
  128. }
  129. catch (Exception ex)
  130. {
  131. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  132. }
  133. return new ApiResult(ReturnCode.Success);
  134. }
  135. /// <summary>
  136. /// 更新巡检路线
  137. /// </summary>
  138. /// <param name="id"></param>
  139. /// <param name="updateModel"></param>
  140. /// <returns></returns>
  141. [HttpPut("UpdateRouteAsync/{id}")]
  142. public async Task<ApiResult> UpdateRouteAsync(Guid id, TispRouteUpdateViewModel updateModel)
  143. {
  144. if (Guid.Empty == id)
  145. {
  146. return new ApiResult(ReturnCode.GeneralError);
  147. }
  148. try
  149. {
  150. await _tispRouteService.UpdateAsync(id, updateModel);
  151. }
  152. catch (Exception ex)
  153. {
  154. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  155. }
  156. return new ApiResult(ReturnCode.Success);
  157. }
  158. }
  159. }