using Admin.Core.Model; using Admin.Core.Common.Resource; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq.Expressions; using System.Threading.Tasks; using Admin.Core.Common; using Admin.Core.IService.ISys; using Admin.Core.Model.Sys; namespace Admin.Core.Api { /// /// SysPostController /// [Route("api/[controller]/[action]")] [ApiController] [Authorize(Permissions.Name)] public class SysPostController : BaseApiController { /// /// _sysPostService /// private readonly ISysPostService _sysPostService; /// /// 构造方法 /// /// public SysPostController(ISysPostService SysPostService) { _sysPostService = SysPostService; } /// /// 分页查询 /// /// /// [HttpPost] public async Task>> GetByPage([FromBody] PageQuery pageQuery) { if (!pageQuery.Query.IsNotEmptyOrNull()) { pageQuery.Query = new SysPost(); } var data = await _sysPostService.SelectPostList(pageQuery); return SuccessPage(data); } /// /// 根据ID查询 /// /// 主键 /// [HttpGet] public async Task> GetByID(int id) { return new MessageModel() { msg = Resource_SysBase.OprateSuccess, success = true, data = await _sysPostService.SelectPostById(id) }; } /// /// 新增一条数据 /// /// SysPost /// [HttpPost] public async Task> Add([FromBody] SysPost request) { var data = new MessageModel(); if (!await _sysPostService.CheckPostNameUnique(request)) { data.success = false; data.msg = "岗位名称已存在!"; return data; } if (!await _sysPostService.CheckPostCodeUnique(request)) { data.success = false; data.msg = "岗位编码已存在!"; return data; } data.data = await _sysPostService.InsertPost(request); if (data.data > 0) { data.success = true; data.msg = Resource_SysBase.OprateSuccess; } else { data.success = false; data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 更新一条数据 /// /// SysPost /// [HttpPost] public async Task> Update([FromBody] SysPost request) { var data = new MessageModel(); if (!await _sysPostService.CheckPostNameUnique(request)) { data.success = false; data.msg = "岗位名称已存在!"; return data; } if (!await _sysPostService.CheckPostCodeUnique(request)) { data.success = false; data.msg = "岗位编码已存在!"; return data; } data.success = await _sysPostService.UpdatePost(request); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 删除一条数据 /// /// 主键 /// [HttpPost] public async Task> Del(List ids) { var data = new MessageModel(); if ((await _sysPostService.CountUserPostById(ids)) > 0) { data.success = false; data.msg = "岗位已分配用户,不可删除!"; return data; } data.success = await _sysPostService.DeletePostByIds(ids); if (data.success) { data.msg = Resource_SysBase.OprateSuccess; } else { data.msg = Resource_SysBase.OprateFail; } return data; } /// /// 数据导出 /// /// /// [HttpPost] public Task> Export(SysPost post) { return null; } /// /// 获取岗位选择框列表 /// [HttpGet] public async Task>> Optionselect() { return Success(await _sysPostService.SelectPostAll()); } } }