TispContentGroupController.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 TispContentGroupController : BaseController
  14. {
  15. public ILogger<TispContentGroupController> _logger { get; }
  16. private readonly ITispContentGroupService _service;
  17. /// <summary>
  18. /// 构造函数
  19. /// </summary>
  20. /// <param name="service"></param>
  21. /// <param name="logger"></param>
  22. public TispContentGroupController(ITispContentGroupService service, ILogger<TispContentGroupController> logger)
  23. {
  24. _service = service;
  25. _logger = logger;
  26. }
  27. /// <summary>
  28. /// 获取所有巡检内容分组
  29. /// </summary>
  30. /// <returns></returns>
  31. [HttpPost("GetContentGroupsAsync")]
  32. //[Authorize]
  33. public async Task<ApiResult> GetContentGroupsAsync(TispContentGroupsSearchModel searchModel)
  34. {
  35. if (searchModel == null || string.IsNullOrEmpty(searchModel.C_StoreCode))
  36. {
  37. return new ApiResult(ReturnCode.ArgsError);
  38. }
  39. try
  40. {
  41. var contentList = await _service.GetContentGroupsAsync(searchModel);
  42. return new ApiResult<IEnumerable<TispContentGroupViewModel>>(contentList);
  43. }
  44. catch (Exception ex)
  45. {
  46. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  47. }
  48. }
  49. ///// <summary>
  50. ///// 通过内容条件查询,不分页
  51. ///// </summary>
  52. ///// <param name="searchModel"></param>
  53. ///// <returns></returns>
  54. //[HttpPost("GetContentsByAsync")]
  55. //public async Task<ApiResult> GetContentsByAsync(TispContentSearchModel searchModel)
  56. //{
  57. // if (searchModel == null)
  58. // {
  59. // return new ApiResult(ReturnCode.ArgsError);
  60. // }
  61. // searchModel.IsPagination = false;
  62. // try
  63. // {
  64. // var contentList = await _tispContentService.GetContentsConditionAsync(searchModel);
  65. // return new ApiResult<IEnumerable<TispContentViewModel>>(contentList);
  66. // }
  67. // catch (Exception ex)
  68. // {
  69. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  70. // }
  71. //}
  72. /// <summary>
  73. /// 创建巡检内容分组
  74. /// </summary>
  75. /// <param name="content"></param>
  76. /// <returns></returns>
  77. [Route("CreateContentGroupAsync")]
  78. [HttpPost]
  79. public async Task<ApiResult> CreateContentGroupAsync(TispContentGroupViewModel content)
  80. {
  81. if (content == null)
  82. {
  83. return new ApiResult(ReturnCode.ArgsError);
  84. }
  85. try
  86. {
  87. await _service.CreateOneAsync(content);
  88. }
  89. catch (Exception ex)
  90. {
  91. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  92. }
  93. return new ApiResult(ReturnCode.Success);
  94. }
  95. /// <summary>
  96. /// 删除巡检内容分组
  97. /// </summary>
  98. /// <param name="id"></param>
  99. /// <returns></returns>
  100. [HttpDelete("DeleteContentGroupAsync/{id}")]
  101. public async Task<ApiResult> DeleteContentGroupAsync(Guid id)
  102. {
  103. if (Guid.Empty == id)
  104. {
  105. return new ApiResult(ReturnCode.GeneralError);
  106. }
  107. try
  108. {
  109. await _service.DeleteAsync(id);
  110. }
  111. catch (Exception ex)
  112. {
  113. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  114. }
  115. return new ApiResult(ReturnCode.Success);
  116. }
  117. /// <summary>
  118. /// 更新巡检内容分组
  119. /// </summary>
  120. /// <param name="id"></param>
  121. /// <param name="updateModel"></param>
  122. /// <returns></returns>
  123. [HttpPut("UpdateContentGroupAsync/{id}")]
  124. public async Task<ApiResult> UpdateContentGroupAsync(Guid id, TispContentUpdateGroupViewModel updateModel)
  125. {
  126. if (Guid.Empty == id)
  127. {
  128. return new ApiResult(ReturnCode.GeneralError);
  129. }
  130. try
  131. {
  132. await _service.UpdateAsync(id, updateModel);
  133. }
  134. catch (Exception ex)
  135. {
  136. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  137. }
  138. return new ApiResult(ReturnCode.Success);
  139. }
  140. }
  141. }