57 lines
1.9 KiB
C#
57 lines
1.9 KiB
C#
|
|
using Dlhis.Basic.Organization.Dto;
|
|
using Dlhis.Basic.Organization.Request;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Basic.Enums;
|
|
using Kurisu.AspNetCore.DataAccess.Dto;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
|
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
|
|
|
public class OutsourceWhiteListService : IOutsourceWhiteListService
|
|
{
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public OutsourceWhiteListService(IDbContext dbContext)
|
|
{
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task AddAsync(string userCode)
|
|
{
|
|
var gainfo = await _dbContext.Queryable<GainfoEntity>().Where(x => x.Code == userCode).SingleAsync();
|
|
gainfo.ThrowIfNull("人员信息不存在");
|
|
(gainfo.Type == GainfoUserTypeEnumType.Outsource).ThrowIfFalse("人员类型不正确");
|
|
if (!await _dbContext.Queryable<OutsourceWhiteListEntity>().Where(x => x.UserCode == userCode).AnyAsync())
|
|
{
|
|
await _dbContext.InsertAsync(new OutsourceWhiteListEntity
|
|
{
|
|
UserCode = userCode
|
|
});
|
|
}
|
|
}
|
|
|
|
public async Task RemoveAsync(string userCode)
|
|
{
|
|
var whitelist = await _dbContext.Queryable<OutsourceWhiteListEntity>().Where(x => x.UserCode == userCode).SingleAsync();
|
|
if (whitelist != null)
|
|
{
|
|
await _dbContext.DeleteAsync(whitelist);
|
|
}
|
|
}
|
|
|
|
public async Task<Pagination<GainfoDto>> GetPageAsync(OutsourceWhiteListPageRequest request)
|
|
{
|
|
return await _dbContext.Queryable<OutsourceWhiteListEntity>()
|
|
.LeftJoin<GainfoEntity>((x, ga) => x.UserCode == ga.Code)
|
|
.Select((x, ga) => new GainfoDto
|
|
{
|
|
Code = ga.Code,
|
|
Name = ga.Name,
|
|
})
|
|
.ToPageListAsync(request);
|
|
}
|
|
}
|