Files
OnboardXAdmin/SimpleAdmin.Application/Services/Onboarding/Employee/OnboardingEmployeeService.cs
T
2026-08-27 11:09:20 +08:00

62 lines
2.4 KiB
C#

namespace SimpleAdmin.Application;
/// <summary>
/// 实现正式员工档案查询业务能力,仅展示审核通过后创建的正式员工。
/// </summary>
public class OnboardingEmployeeService : IOnboardingEmployeeService
{
private readonly SqlSugarScope _db;
public OnboardingEmployeeService()
{
_db = DbContext.DB;
}
/// <summary>
/// 分页查询审核通过后生成的正式员工档案。
/// </summary>
public Task<SqlSugarPagedList<ObEmployee>> Page(OnboardingEmployeePageInput input)
{
return _db.Queryable<ObEmployee>()
.WhereIF(
!string.IsNullOrWhiteSpace(input.EmployeeName),
item => item.EmployeeName.Contains(input.EmployeeName)
|| item.IdCardNumber.Contains(input.EmployeeName))
.WhereIF(!string.IsNullOrWhiteSpace(input.Phone), item => item.Phone.Contains(input.Phone))
.WhereIF(input.CompanyId.HasValue, item => item.CompanyId == input.CompanyId.Value)
.WhereIF(input.DepartmentId.HasValue, item => item.DepartmentId == input.DepartmentId.Value)
.WhereIF(input.PositionId.HasValue, item => item.PositionId == input.PositionId.Value)
.OrderByDescending(item => item.CreateTime)
.ToPagedListAsync(input.PageNum, input.PageSize);
}
/// <summary>
/// 查询正式员工及其来源任务、合同和审核记录。
/// </summary>
public async Task<OnboardingEmployeeDetailOutput> Detail(BaseIdInput input)
{
var employee = await _db.Queryable<ObEmployee>().InSingleAsync(input.Id)
?? throw Oops.Bah("正式员工不存在");
var task = await _db.Queryable<ObOnboardingTask>().FirstAsync(x => x.EmployeeId == employee.Id);
var contracts = task == null
? new List<ObTaskContract>()
: await _db.Queryable<ObTaskContract>()
.Where(item => item.TaskId == task.Id)
.ToListAsync();
var audits = task == null
? new List<ObTaskAudit>()
: await _db.Queryable<ObTaskAudit>()
.Where(item => item.TaskId == task.Id)
.OrderByDescending(item => item.AuditedAt)
.ToListAsync();
return new OnboardingEmployeeDetailOutput
{
Employee = employee,
Task = task,
Contracts = contracts,
Audits = audits
};
}
}