using Attribute;
using Common;
using Enums;
using Filters;
using Infrastructure;
using Microsoft.AspNetCore.Mvc;
using Middleware;
using Model;
using Model.Base;
using Services;
using Util;
namespace Controllers
{
///
/// 岗位管理
///
[Verify]
public class SysPostController : BaseController
{
private readonly ISysPostService PostService;
public SysPostController(ISysPostService postService)
{
PostService = postService;
}
///
/// 岗位列表查询
///
///
[HttpGet("/v1/tel/sysServer/post/page")]
public IActionResult List([FromQuery] SysPost post, [FromQuery] PagerInfo pagerInfo)
{
var predicate = Expressionable.Create();
predicate.AndIF(!string.IsNullOrEmpty(post.postName), u => u.postName.Contains(post.postName));
var list = PostService.GetPages(predicate.ToExpression(), pagerInfo, s => new { s.postSort });
return SUCCESS(list);
}
///
/// 获取所有岗位列表
///
///
[HttpGet("/v1/tel/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("/v1/tel/sysServer/post/add")]
public IActionResult Add([FromBody] SysPost post)
{
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post)))
{
return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位名已存在");
}
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post)))
{
return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位编码已存在");
}
TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
post.CreateBy = loginUser.username;
post.UpdateBy = loginUser.username;
post.CreateTime = DateTime.Now;
post.UpdateTime = DateTime.Now;
post.DelFlag = "0";
return SUCCESS(PostService.Add(post, true));
}
///
/// 岗位管理
///
///
///
[HttpPut("/v1/tel/sysServer/post/update")]
public IActionResult Update([FromBody] SysPost post)
{
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostNameUnique(post)))
{
return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位名已存在");
}
if (UserConstants.NOT_UNIQUE.Equals(PostService.CheckPostCodeUnique(post)))
{
return ToResponse(ResultCode.CUSTOM_ERROR, $"修改岗位{post.postName}失败,岗位编码已存在");
}
TokenModel loginUser = JwtUtil.GetLoginUser(HttpContext);
post.UpdateBy = loginUser.username;
post.UpdateTime = DateTime.Now;
return SUCCESS(PostService.Update(post, true));
}
///
/// 岗位删除
///
///
///
[HttpDelete("/v1/tel/sysServer/post/removeById/{id}")]
public IActionResult Delete(int id)
{
return SUCCESS(PostService.Delete(id));
}
///
/// 获取岗位选择框列表
///
[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);
}
}
}