using YBEE.EQM.Core;
namespace YBEE.EQM.Application;
///
/// 监测抽样学生管理服务
///
public class ExamSampleStudentService : IExamSampleStudentService, ITransient
{
private readonly IRepository _rep;
public ExamSampleStudentService(IRepository rep)
{
_rep = rep;
}
///
/// 分页查询抽样学生信息
///
///
///
public async Task> QueryPageList(ExamSampleStudentPageInput input)
{
// 抽样方案
var examSample = await _rep.Change().DetachedEntities
.FirstOrDefaultAsync(t => t.Id == input.ExamSampleId &&
t.ExamPlan.IsFixedExamSample == true &&
t.Status == ExamSampleStatus.SUCCESSFUL &&
t.IsSelected == true
) ?? throw Oops.Oh(ErrorCode.E2001);
var name = !string.IsNullOrEmpty(input.Name?.Trim());
var idNumber = !string.IsNullOrEmpty(input.IdNumber?.Trim());
var examNumber = !string.IsNullOrEmpty(input.ExamNumber?.Trim());
var ret = await _rep.DetachedEntities.Where(t => t.ExamSampleId == examSample.Id && t.ExamStudent.SysOrgId == CurrentSysUserInfo.SysOrgId)
.Where((name, u => EF.Functions.Like(u.ExamStudent.Name, $"%{input.Name.Trim()}%")))
.Where((idNumber, u => EF.Functions.Like(u.ExamStudent.IdNumber, $"%{input.IdNumber.Trim()}%")))
.Where((examNumber, u => EF.Functions.Like(u.ExamNumber, $"%{input.ExamNumber.Trim()}%")))
.Where(input.ExamSampleType.HasValue, t => t.ExamSampleType == input.ExamSampleType)
.Where(input.CertificateType.HasValue, t => t.ExamStudent.CertificateType == input.CertificateType)
.Where(input.GradeId.HasValue, t => t.ExamStudent.GradeId == input.GradeId)
.Where(input.ClassNumber.HasValue, t => t.ExamStudent.ClassNumber == input.ClassNumber)
.Where(input.SysOrgBranchId.HasValue, t => t.ExamStudent.SchoolClass.SysOrgBranchId == input.SysOrgBranchId)
.ProjectToType()
.OrderBy(t => t.ExamStudent.SysOrgBranchId).ThenBy(t => t.ExamStudent.GradeId).ThenBy(t => t.ExamSampleType).ThenBy(t => t.Sequence)
.ToADPagedListAsync(input.PageIndex, input.PageSize);
return ret;
}
///
/// 根据监测号查询已发布监测方案中当前机构下学生信息
///
/// 监测计划ID
/// 监测号
///
public async Task GetByExamNumber(int examPlanId, string examNumber)
{
var item = await _rep.DetachedEntities.Include(t => t.ExamStudent)
.FirstOrDefaultAsync(t => t.ExamStudent.ExamPlanId == examPlanId &&
t.ExamStudent.SysOrgId == CurrentSysUserInfo.SysOrgId &&
t.ExamSample.IsSelected == true &&
t.ExamNumber == examNumber);
return item.Adapt();
}
///
/// 查询监测学生信息
///
///
///
public async Task QueryExamSampleStudent(QueryExamSampleStudentInput input)
{
var item = await _rep.DetachedEntities.Include(t => t.ExamStudent)
.FirstOrDefaultAsync(t => t.ExamStudent.ExamPlanId == input.ExamPlanId &&
t.ExamStudent.SysOrgId == CurrentSysUserInfo.SysOrgId &&
t.ExamStudent.SysOrgBranchId == input.SysOrgBranchId &&
t.ExamSample.IsSelected == true &&
t.ExamStudent.ExamGradeId == input.ExamGradeId &&
t.ExamStudent.ClassNumber == input.ClassNumber &&
t.ExamNumber == input.ExamNumber);
return item.Adapt();
}
}