using Attribute; using Common; using Enums; using Filters; using Infrastructure; using Microsoft.AspNetCore.Mvc; using Middleware; using Model; using Model.Base; using Services; namespace Controllers { /// /// 岗位管理 /// [Verify] [Route("system/post")] [ApiExplorerSettings(GroupName = "sys")] public class SysPostController : BaseController { private readonly ISysPostService PostService; public SysPostController(ISysPostService postService) { PostService = postService; } /// /// 岗位列表查询 /// /// [HttpGet("list")] [ActionPermissionFilter(Permission = "system:post:list")] public IActionResult List([FromQuery] SysPost post, [FromQuery] PagerInfo pagerInfo) { var predicate = Expressionable.Create(); var list = PostService.GetPages(predicate.ToExpression(), pagerInfo, s => new { s.PostSort }); return SUCCESS(list); } /// /// 获取所有岗位列表 /// /// [HttpGet("/v1/skb/sysServer/post/list")] public IActionResult AllList() { return SUCCESS(PostService.GetList(), TIME_FORMAT_FULL); } /// /// 岗位查询 /// /// /// [HttpGet("{postId}")] [ActionPermissionFilter(Permission = "system:post:query")] public IActionResult Query(long postId = 0) { return SUCCESS(PostService.GetId(postId)); } /// /// 岗位管理 /// /// /// [HttpPost] [ActionPermissionFilter(Permission = "system:post:add")] [Log(Title = "岗位添加", BusinessType = BusinessType.INSERT)] public IActionResult Add([FromBody] SysPost post) { if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post))) { throw new CustomException($"修改岗位{post.PostName}失败,岗位名已存在"); } if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post))) { throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } post.ToCreate(HttpContext); return ToResponse(PostService.Add(post)); } /// /// 岗位管理 /// /// /// [HttpPut] [ActionPermissionFilter(Permission = "system:post:edit")] [Log(Title = "岗位编辑", BusinessType = BusinessType.UPDATE)] public IActionResult Update([FromBody] SysPost post) { if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post))) { throw new CustomException($"修改岗位{post.PostName}失败,岗位名已存在"); } if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post))) { throw new CustomException($"修改岗位{post.PostName}失败,岗位编码已存在"); } post.ToUpdate(HttpContext); return ToResponse(PostService.Update(post)); } /// /// 岗位删除 /// /// /// [HttpDelete("{id}")] [ActionPermissionFilter(Permission = "system:post:remove")] [Log(Title = "岗位删除", BusinessType = BusinessType.DELETE)] public IActionResult Delete(string id) { int[] ids = Tools.SpitIntArrary(id); return ToResponse(PostService.Delete(ids)); } /// /// 获取岗位选择框列表 /// [HttpGet("optionselect")] public IActionResult Optionselect() { List posts = PostService.GetAll(); return SUCCESS(posts); } /// /// 岗位导出 /// /// [Log(BusinessType = BusinessType.EXPORT, IsSaveResponseData = false, Title = "岗位导出")] [HttpGet("export")] [ActionPermissionFilter(Permission = "system:post:export")] public IActionResult Export() { var list = PostService.GetAll(); var result = ExportExcelMini(list, "post", "岗位列表"); return ExportExcel(result.Item2, result.Item1); } } }