using Furion.DependencyInjection; using Furion.DynamicApiController; using Furion.FriendlyException; using GDZZ.Core.Entity; using Mapster; using Microsoft.AspNetCore.Mvc; using System.Threading.Tasks; namespace GDZZ.Core.Service; /// /// 职位服务 /// [ApiDescriptionSettings(Name = "Pos", Order = 147)] public class SysPosService : ISysPosService, IDynamicApiController, ITransient { private readonly SqlSugarRepository _sysPosRep; // 职位表仓储 private readonly ISysEmpPosService _sysEmpPosService; private readonly ISysEmpExtOrgPosService _sysEmpExtOrgPosService; public SysPosService(SqlSugarRepository sysPosRep, ISysEmpPosService sysEmpPosService, ISysEmpExtOrgPosService sysEmpExtOrgPosService) { _sysPosRep = sysPosRep; _sysEmpPosService = sysEmpPosService; _sysEmpExtOrgPosService = sysEmpExtOrgPosService; } /// /// 分页获取职位 /// /// /// [HttpGet("/sysPos/page")] public async Task QueryPosPageList([FromQuery] PosInput input) { var pos = await _sysPosRep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name.Trim())) .WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code.Contains(input.Code.Trim())) .Where(u => u.Status == CommonStatus.ENABLE).OrderBy(u => u.Sort) .ToPagedListAsync(input.PageNo, input.PageSize); return pos.XnPagedResult(); } /// /// 获取职位列表 /// /// [HttpGet("/sysPos/list")] public async Task GetPosList([FromQuery] PosInput input) { return await _sysPosRep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code.Contains(input.Code.Trim())) .Where(u => u.Status != CommonStatus.DELETED) .OrderBy(u => u.Sort).ToListAsync(); } /// /// 增加职位 /// /// /// [HttpPost("/sysPos/add")] public async Task AddPos(AddPosInput input) { var isExist = await _sysPosRep.AnyAsync(u => u.Name == input.Name || u.Code == input.Code); if (isExist) throw Oops.Oh(ErrorCode.D6000); var pos = input.Adapt(); await _sysPosRep.InsertAsync(pos); } /// /// 删除职位 /// /// /// [HttpPost("/sysPos/delete")] public async Task DeletePos(DeletePosInput input) { // 该职位下是否有员工 var hasPosEmp = await _sysEmpPosService.HasPosEmp(input.Id); if (hasPosEmp) throw Oops.Oh(ErrorCode.D6001); // 该附属职位下是否有员工 var hasExtPosEmp = await _sysEmpExtOrgPosService.HasExtPosEmp(input.Id); if (hasExtPosEmp) throw Oops.Oh(ErrorCode.D6001); await _sysPosRep.DeleteAsync(u => u.Id == input.Id); } /// /// 更新职位 /// /// /// [HttpPost("/sysPos/edit")] public async Task UpdatePos(UpdatePosInput input) { var isExist = await _sysPosRep.AnyAsync(u => (u.Name == input.Name || u.Code == input.Code) && u.Id != input.Id); if (isExist) throw Oops.Oh(ErrorCode.D6000); var pos = input.Adapt(); await _sysPosRep.AsUpdateable(pos).IgnoreColumns(ignoreAllNullColumns: true).ExecuteCommandAsync(); } /// /// 获取职位 /// /// /// [HttpGet("/sysPos/detail")] public async Task GetPos([FromQuery] QueryPosInput input) { return await _sysPosRep.FirstOrDefaultAsync(u => u.Id == input.Id); } }