SysPostController.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using Attribute;
  2. using Common;
  3. using Enums;
  4. using Filters;
  5. using Infrastructure;
  6. using Microsoft.AspNetCore.Mvc;
  7. using Middleware;
  8. using Model;
  9. using Model.Base;
  10. using Services;
  11. using Util;
  12. namespace Controllers
  13. {
  14. /// <summary>
  15. /// 岗位管理
  16. /// </summary>
  17. [Verify]
  18. public class SysPostController : BaseController
  19. {
  20. private readonly ISysPostService PostService;
  21. public SysPostController(ISysPostService postService)
  22. {
  23. PostService = postService;
  24. }
  25. /// <summary>
  26. /// 岗位列表查询
  27. /// </summary>
  28. /// <returns></returns>
  29. [HttpGet("/v1/tel/sysServer/post/page")]
  30. public IActionResult List([FromQuery] SysPost post, [FromQuery] PagerInfo pagerInfo)
  31. {
  32. var predicate = Expressionable.Create<SysPost>();
  33. predicate.AndIF(!string.IsNullOrEmpty(post.postName), u => u.postName.Contains(post.postName));
  34. var list = PostService.GetPages(predicate.ToExpression(), pagerInfo, s => new { s.postSort });
  35. return SUCCESS(list);
  36. }
  37. /// <summary>
  38. /// 获取所有岗位列表
  39. /// </summary>
  40. /// <returns></returns>
  41. [HttpGet("/v1/tel/sysServer/post/list")]
  42. public IActionResult AllList()
  43. {
  44. return SUCCESS(PostService.GetList(), TIME_FORMAT_FULL);
  45. }
  46. /// <summary>
  47. /// 岗位查询
  48. /// </summary>
  49. /// <param name="postId"></param>
  50. /// <returns></returns>
  51. [HttpGet("{postId}")]
  52. [ActionPermissionFilter(Permission = "system:post:query")]
  53. public IActionResult Query(long postId = 0)
  54. {
  55. return SUCCESS(PostService.GetId(postId));
  56. }
  57. /// <summary>
  58. /// 岗位管理
  59. /// </summary>
  60. /// <param name="post"></param>
  61. /// <returns></returns>
  62. [HttpPost("/v1/tel/sysServer/post/add")]
  63. public IActionResult Add([FromBody] SysPost post)
  64. {
  65. if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post)))
  66. {
  67. return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位名已存在");
  68. }
  69. if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post)))
  70. {
  71. return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位编码已存在");
  72. }
  73. TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
  74. post.CreateBy = loginUser.username;
  75. post.UpdateBy = loginUser.username;
  76. post.CreateTime = DateTime.Now;
  77. post.UpdateTime = DateTime.Now;
  78. post.DelFlag = "0";
  79. return SUCCESS(PostService.Add(post, true));
  80. }
  81. /// <summary>
  82. /// 岗位管理
  83. /// </summary>
  84. /// <param name="post"></param>
  85. /// <returns></returns>
  86. [HttpPut("/v1/tel/sysServer/post/update")]
  87. public IActionResult Update([FromBody] SysPost post)
  88. {
  89. if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post)))
  90. {
  91. return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位名已存在");
  92. }
  93. if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post)))
  94. {
  95. return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位编码已存在");
  96. }
  97. TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
  98. post.UpdateBy = loginUser.username;
  99. post.UpdateTime = DateTime.Now;
  100. return SUCCESS(PostService.Update(post, true));
  101. }
  102. /// <summary>
  103. /// 岗位删除
  104. /// </summary>
  105. /// <param name="id"></param>
  106. /// <returns></returns>
  107. [HttpDelete("/v1/tel/sysServer/post/removeById/{id}")]
  108. public IActionResult Delete(int id)
  109. {
  110. return SUCCESS(PostService.Delete(id));
  111. }
  112. /// <summary>
  113. /// 获取岗位选择框列表
  114. /// </summary>
  115. [HttpGet("optionselect")]
  116. public IActionResult Optionselect()
  117. {
  118. List<SysPost> posts = PostService.GetAll();
  119. return SUCCESS(posts);
  120. }
  121. /// <summary>
  122. /// 岗位导出
  123. /// </summary>
  124. /// <returns></returns>
  125. [Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "岗位导出")]
  126. [HttpGet("export")]
  127. [ActionPermissionFilter(Permission = "system:post:export")]
  128. public IActionResult Export()
  129. {
  130. var list = PostService.GetAll();
  131. var result = ExportExcelMini(list, "post", "岗位列表");
  132. return ExportExcel(result.Item2, result.Item1);
  133. }
  134. }
  135. }