VmcCameraTemplateController.cs 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using log4net;
  2. using Microsoft.AspNetCore.Authorization;
  3. using Microsoft.AspNetCore.Mvc;
  4. using Ropin.Inspection.Api.Common;
  5. using Ropin.Inspection.Api.Controllers.LGS;
  6. using Ropin.Inspection.Model.SearchModel.LGS;
  7. using Ropin.Inspection.Model.ViewModel.LGS;
  8. using Ropin.Inspection.Model;
  9. using Ropin.Inspection.Service.LGS.Interface;
  10. using Ropin.Inspection.Service.VMC.Interface;
  11. using System.Threading.Tasks;
  12. using System;
  13. using Ropin.Inspection.Model.ViewModel.VMC;
  14. using Ropin.Inspection.Model.SearchModel.VMC;
  15. namespace Ropin.Inspection.Api.Controllers.VMC
  16. {
  17. public class VmcCameraTemplateController : BaseController
  18. {
  19. private readonly IVmcCameraTemplateService _repository;
  20. private static readonly ILog log = LogManager.GetLogger(typeof(VmcCameraTemplateController));
  21. /// <summary>
  22. /// 构造函数
  23. /// </summary>
  24. /// <param name="repository"></param>
  25. public VmcCameraTemplateController(IVmcCameraTemplateService repository)
  26. {
  27. _repository = repository;
  28. }
  29. /// <summary>
  30. /// 创建模板
  31. /// </summary>
  32. /// <param name="content"></param>
  33. /// <returns></returns>
  34. [HttpPost("CreateTemplateAsync")]
  35. public async Task<ApiResult> CreateTemplateAsync(VmcCameraTemplateViewModel content)
  36. {
  37. if (content == null)
  38. {
  39. return new ApiResult(ReturnCode.ArgsError);
  40. }
  41. try
  42. {
  43. await _repository.CreateOneAsync(content);
  44. }
  45. catch (Exception ex)
  46. {
  47. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  48. }
  49. return new ApiResult(ReturnCode.Success);
  50. }
  51. /// <summary>
  52. /// 删除模板
  53. /// </summary>
  54. /// <param name="id"></param>
  55. /// <returns></returns>
  56. [HttpDelete("DeleteTemplateAsync/{id}")]
  57. public async Task<ApiResult> DeleteTemplateAsync(string id)
  58. {
  59. if (string.IsNullOrEmpty(id))
  60. {
  61. return new ApiResult(ReturnCode.GeneralError);
  62. }
  63. try
  64. {
  65. await _repository.DeleteAsync(id);
  66. }
  67. catch (Exception ex)
  68. {
  69. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  70. }
  71. return new ApiResult(ReturnCode.Success);
  72. }
  73. /// <summary>
  74. /// 禁用模板
  75. /// </summary>
  76. /// <param name="id"></param>
  77. /// <returns></returns>
  78. [HttpPut("ForbiddenTemplateAsync/{id}")]
  79. public async Task<ApiResult> ForbiddenTemplateAsync(string id)
  80. {
  81. if (string.IsNullOrEmpty(id))
  82. {
  83. return new ApiResult(ReturnCode.GeneralError);
  84. }
  85. try
  86. {
  87. await _repository.ForbiddenAsync(id);
  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. /// <param name="updateModel"></param>
  100. /// <returns></returns>
  101. [HttpPut("UpdateTemplateAsync/{id}")]
  102. [AllowAnonymous]
  103. public async Task<ApiResult> UpdateTemplateAsync(string id, VmcCameraTemplateViewModel updateModel)
  104. {
  105. if (string.IsNullOrEmpty(id))
  106. {
  107. return new ApiResult(ReturnCode.GeneralError);
  108. }
  109. try
  110. {
  111. await _repository.UpdateAsync(updateModel, id);
  112. }
  113. catch (Exception ex)
  114. {
  115. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  116. }
  117. return new ApiResult(ReturnCode.Success);
  118. }
  119. /// <summary>
  120. /// 获取模板列表
  121. /// </summary>
  122. /// <returns></returns>
  123. [HttpPost("PageAsync")]
  124. [AllowAnonymous]
  125. public async Task<ApiResult> PageAsync(VmcCameraTemplateSearch searchModel)
  126. {
  127. if (searchModel == null)
  128. {
  129. return new ApiResult(ReturnCode.ArgsError);
  130. }
  131. try
  132. {
  133. var contentList = await _repository.GetConditionAsync(searchModel);
  134. return new ApiResult<PagesModel<VmcCameraTemplateViewModel>>(new PagesModel<VmcCameraTemplateViewModel>(contentList, searchModel));
  135. }
  136. catch (Exception ex)
  137. {
  138. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  139. }
  140. }
  141. /// <summary>
  142. /// 通过id获取大模板详情
  143. /// </summary>
  144. /// <returns></returns>
  145. [HttpGet("DetailsAsync")]
  146. [AllowAnonymous]
  147. public async Task<ApiResult> DetailsAsync(string Id)
  148. {
  149. if (string.IsNullOrEmpty(Id))
  150. {
  151. return new ApiResult(ReturnCode.ArgsError);
  152. }
  153. try
  154. {
  155. VmcCameraTemplateViewModel data = await _repository.GetByIdAsync(Id);
  156. return new ApiResult<VmcCameraTemplateViewModel>(data);
  157. }
  158. catch (Exception ex)
  159. {
  160. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  161. }
  162. }
  163. }
  164. }