namespace Admin.NET.Core.Service; /// /// 系统职位服务 /// [ApiDescriptionSettings(Order = 460)] public class SysPosService : IDynamicApiController, ITransient { private readonly SqlSugarRepository _sysPosRep; private readonly SysUserExtOrgService _sysUserExtOrgService; public SysPosService(SqlSugarRepository sysPosRep, SysUserExtOrgService sysUserExtOrgService) { _sysPosRep = sysPosRep; _sysUserExtOrgService = sysUserExtOrgService; } /// /// 获取职位列表 /// /// /// [DisplayName("获取职位列表")] public async Task> GetList([FromQuery] PosInput input) { return await _sysPosRep.AsQueryable() .WhereIF(!string.IsNullOrWhiteSpace(input.Name), u => u.Name.Contains(input.Name)) .WhereIF(!string.IsNullOrWhiteSpace(input.Code), u => u.Code.Contains(input.Code)) .OrderBy(u => u.OrderNo).ToListAsync(); } /// /// 增加职位 /// /// /// [ApiDescriptionSettings(Name = "Add"), HttpPost] [DisplayName("增加职位")] public async Task AddPos(AddPosInput input) { var isExist = await _sysPosRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code); if (isExist) throw Oops.Oh(ErrorCodeEnum.D6000); await _sysPosRep.InsertAsync(input.Adapt()); } /// /// 更新职位 /// /// /// [ApiDescriptionSettings(Name = "Update"), HttpPost] [DisplayName("更新职位")] public async Task UpdatePos(UpdatePosInput input) { var isExist = await _sysPosRep.IsAnyAsync(u => u.Name == input.Name && u.Code == input.Code && u.Id != input.Id); if (isExist) throw Oops.Oh(ErrorCodeEnum.D6000); await _sysPosRep.AsUpdateable(input.Adapt()).IgnoreColumns(true).ExecuteCommandAsync(); } /// /// 删除职位 /// /// /// [ApiDescriptionSettings(Name = "Delete"), HttpPost] [DisplayName("删除职位")] public async Task DeletePos(DeletePosInput input) { // 该职位下是否有用户 var hasPosEmp = await _sysPosRep.ChangeRepository>() .IsAnyAsync(u => u.PosId == input.Id); if (hasPosEmp) throw Oops.Oh(ErrorCodeEnum.D6001); // 该附属职位下是否有用户 var hasExtPosEmp = await _sysUserExtOrgService.HasUserPos(input.Id); if (hasExtPosEmp) throw Oops.Oh(ErrorCodeEnum.D6001); await _sysPosRep.DeleteAsync(u => u.Id == input.Id); } }