TsecRecordController.cs 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using Microsoft.AspNetCore.Mvc;
  2. using Microsoft.Extensions.Logging;
  3. using Ropin.Inspection.Api.Common;
  4. using Ropin.Inspection.Model.ViewModel;
  5. using Ropin.Inspection.Service.Interface;
  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. /// <summary>
  13. /// 安检记录
  14. /// </summary>
  15. public class TsecRecordController : BaseController
  16. {
  17. private readonly ILogger<TsecRecordController> _logger;
  18. private readonly ITsecRecordService _tsecRecordService;
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. /// <param name="tsecRecordService"></param>
  23. /// <param name="logger"></param>
  24. public TsecRecordController(ITsecRecordService tsecRecordService, ILogger<TsecRecordController> logger)
  25. {
  26. _tsecRecordService = tsecRecordService;
  27. _logger = logger;
  28. }
  29. /// <summary>
  30. /// 通过ID获取安检记录信息
  31. /// </summary>
  32. /// <param name="id"></param>
  33. /// <returns></returns>
  34. [HttpGet("GetRecordAsync/{id}")]
  35. public async Task<ApiResult> GetRecordAsync(Guid id)
  36. {
  37. if (Guid.Empty == id)
  38. {
  39. return new ApiResult(ReturnCode.GeneralError);
  40. }
  41. try
  42. {
  43. var spot = await _tsecRecordService.GetByIdAsync(id);
  44. return new ApiResult<TsecRecordViewModel>(spot);
  45. }
  46. catch (Exception ex)
  47. {
  48. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  49. }
  50. }
  51. ///// <summary>
  52. ///// 获取所有安检记录
  53. ///// </summary>
  54. ///// <returns></returns>
  55. //[HttpGet("GetRecordsAsync")]
  56. //public async Task<ApiResult> GetRecordsAsync()
  57. //{
  58. // try
  59. // {
  60. // var spotList = await _tsecRecordService.GetAllAsync();
  61. // return new ApiResult<IEnumerable<TsecRecordViewModel>>(spotList);
  62. // }
  63. // catch (Exception ex)
  64. // {
  65. // return new ApiResult(ReturnCode.GeneralError, ex.Message);
  66. // }
  67. //}
  68. /// <summary>
  69. /// 创建安检记录
  70. /// </summary>
  71. /// <param name="spot"></param>
  72. /// <returns></returns>
  73. [Route("CreateRecordAsync")]
  74. [HttpPost]
  75. public async Task<ApiResult> CreateRecordAsync([FromBody] TsecRecordViewModel spot)
  76. {
  77. if (spot == null)
  78. {
  79. return new ApiResult(ReturnCode.ArgsError);
  80. }
  81. try
  82. {
  83. await _tsecRecordService.CreateOneAsync(spot);
  84. }
  85. catch (Exception ex)
  86. {
  87. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  88. }
  89. return new ApiResult(ReturnCode.Success);
  90. }
  91. /// <summary>
  92. /// 删除安检记录
  93. /// </summary>
  94. /// <param name="id"></param>
  95. /// <returns></returns>
  96. [HttpDelete("DeleteRecordAsync/{id}")]
  97. public async Task<ApiResult> DeleteRecordAsync(Guid id)
  98. {
  99. if (Guid.Empty == id)
  100. {
  101. return new ApiResult(ReturnCode.GeneralError);
  102. }
  103. try
  104. {
  105. await _tsecRecordService.DeleteAsync(id);
  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. /// <param name="updateModel"></param>
  118. /// <returns></returns>
  119. [HttpPut("UpdateRecordAsync/{id}")]
  120. public async Task<ApiResult> UpdateRecordAsync(Guid id, TsecRecordUpdateViewModel updateModel)
  121. {
  122. if (Guid.Empty == id)
  123. {
  124. return new ApiResult(ReturnCode.GeneralError);
  125. }
  126. try
  127. {
  128. await _tsecRecordService.UpdateAsync(id, updateModel);
  129. }
  130. catch (Exception ex)
  131. {
  132. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  133. }
  134. return new ApiResult(ReturnCode.Success);
  135. }
  136. }
  137. }