TsysPostController.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 TsysPostController : BaseController
  16. {
  17. public ILogger<TsysPostController> _logger { get; }
  18. private readonly ITsysPostService _tsysPostService;
  19. /// <summary>
  20. /// 构造函数
  21. /// </summary>
  22. /// <param name="tsysPostService"></param>
  23. /// <param name="logger"></param>
  24. public TsysPostController(ITsysPostService tsysPostService, ILogger<TsysPostController> logger)
  25. {
  26. _tsysPostService = tsysPostService;
  27. _logger = logger;
  28. }
  29. /// <summary>
  30. /// 通过岗位ID获取岗位信息
  31. /// </summary>
  32. /// <param name="PostId"></param>
  33. /// <returns></returns>
  34. [HttpGet("GetPostAsync/{PostId}")]
  35. public async Task<ApiResult> GetPostAsync(Guid PostId)
  36. {
  37. if (Guid.Empty == PostId)
  38. {
  39. return new ApiResult(ReturnCode.GeneralError);
  40. }
  41. try
  42. {
  43. var Post = await _tsysPostService.GetByIdAsync(PostId);
  44. return new ApiResult<TsysPostViewModel>(Post);
  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("GetPostsAsync")]
  56. public async Task<ApiResult> GetPostsAsync()
  57. {
  58. try
  59. {
  60. var PostList = await _tsysPostService.GetAllAsync();
  61. return new ApiResult<IEnumerable<TsysPostViewModel>>(PostList?.ToList());
  62. }
  63. catch (Exception ex)
  64. {
  65. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  66. }
  67. }
  68. /// <summary>
  69. /// 创建岗位
  70. /// </summary>
  71. /// <param name="Post"></param>
  72. /// <returns></returns>
  73. [Route("CreatePostAsync")]
  74. [HttpPost]
  75. public async Task<ApiResult> CreatePostAsync(TsysPostViewModel Post)
  76. {
  77. if (Post == null)
  78. {
  79. return new ApiResult(ReturnCode.ArgsError);
  80. }
  81. try
  82. {
  83. await _tsysPostService.CreateOneAsync(Post);
  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="PostId"></param>
  95. /// <returns></returns>
  96. [HttpDelete("DeletePostAsync/{PostId}")]
  97. public async Task<ApiResult> DeletePostAsync(Guid PostId)
  98. {
  99. if (Guid.Empty == PostId)
  100. {
  101. return new ApiResult(ReturnCode.GeneralError);
  102. }
  103. try
  104. {
  105. await _tsysPostService.DeleteAsync(PostId);
  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="PostId"></param>
  117. /// <param name="updatePost"></param>
  118. /// <returns></returns>
  119. [HttpPut("UpdatePostAsync/{PostId}")]
  120. public async Task<ApiResult> UpdatePostAsync(Guid PostId, TsysPostUpdateViewModel updatePost)
  121. {
  122. if (Guid.Empty == PostId)
  123. {
  124. return new ApiResult(ReturnCode.GeneralError);
  125. }
  126. try
  127. {
  128. await _tsysPostService.UpdateAsync(PostId, updatePost);
  129. }
  130. catch (Exception ex)
  131. {
  132. return new ApiResult(ReturnCode.GeneralError, ex.Message);
  133. }
  134. return new ApiResult(ReturnCode.Success);
  135. }
  136. }
  137. }