ExamSampleStudentService.cs 5.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 监测抽样学生管理服务
  5. /// </summary>
  6. public class ExamSampleStudentService : IExamSampleStudentService, ITransient
  7. {
  8. private readonly IRepository<ExamSampleStudent> _rep;
  9. public ExamSampleStudentService(IRepository<ExamSampleStudent> rep)
  10. {
  11. _rep = rep;
  12. }
  13. /// <summary>
  14. /// 分页查询抽样学生信息
  15. /// </summary>
  16. /// <param name="input"></param>
  17. /// <returns></returns>
  18. public async Task<PageResult<ExamSampleStudentOutput>> QueryPageList(ExamSampleStudentPageInput input)
  19. {
  20. // 抽样方案
  21. var examSample = await _rep.Change<ExamSample>().DetachedEntities
  22. .FirstOrDefaultAsync(t => t.Id == input.ExamSampleId &&
  23. t.ExamPlan.IsFixedExamSample == true &&
  24. t.Status == ExamSampleStatus.SUCCESSFUL &&
  25. t.IsSelected == true
  26. ) ?? throw Oops.Oh(ErrorCode.E2001);
  27. var name = !string.IsNullOrEmpty(input.Name?.Trim());
  28. var idNumber = !string.IsNullOrEmpty(input.IdNumber?.Trim());
  29. var examNumber = !string.IsNullOrEmpty(input.ExamNumber?.Trim());
  30. var ret = await _rep.DetachedEntities.Where(t => t.ExamSampleId == examSample.Id && t.ExamStudent.SysOrgId == CurrentSysUserInfo.SysOrgId)
  31. .Where((name, u => EF.Functions.Like(u.ExamStudent.Name, $"%{input.Name.Trim()}%")))
  32. .Where((idNumber, u => EF.Functions.Like(u.ExamStudent.IdNumber, $"%{input.IdNumber.Trim()}%")))
  33. .Where((examNumber, u => EF.Functions.Like(u.ExamNumber, $"%{input.ExamNumber.Trim()}%")))
  34. .Where(input.ExamSampleType.HasValue, t => t.ExamSampleType == input.ExamSampleType)
  35. .Where(input.CertificateType.HasValue, t => t.ExamStudent.CertificateType == input.CertificateType)
  36. .Where(input.GradeId.HasValue, t => t.ExamStudent.GradeId == input.GradeId)
  37. .Where(input.ClassNumber.HasValue, t => t.ExamStudent.ClassNumber == input.ClassNumber)
  38. .Where(input.SysOrgBranchId.HasValue, t => t.ExamStudent.SchoolClass.SysOrgBranchId == input.SysOrgBranchId)
  39. .ProjectToType<ExamSampleStudentOutput>()
  40. .OrderBy(t => t.ExamStudent.SysOrgBranchId).ThenBy(t => t.ExamStudent.GradeId).ThenBy(t => t.ExamSampleType).ThenBy(t => t.Sequence)
  41. .ToADPagedListAsync(input.PageIndex, input.PageSize);
  42. return ret;
  43. }
  44. /// <summary>
  45. /// 根据监测号查询已发布监测方案中当前机构下学生信息
  46. /// </summary>
  47. /// <param name="examPlanId">监测计划ID</param>
  48. /// <param name="examNumber">监测号</param>
  49. /// <returns></returns>
  50. public async Task<ExamSampleStudentOutput> GetByExamNumber(int examPlanId, string examNumber)
  51. {
  52. var item = await _rep.DetachedEntities.Include(t => t.ExamStudent)
  53. .FirstOrDefaultAsync(t => t.ExamStudent.ExamPlanId == examPlanId &&
  54. t.ExamStudent.SysOrgId == CurrentSysUserInfo.SysOrgId &&
  55. t.ExamSample.IsSelected == true &&
  56. t.ExamNumber == examNumber);
  57. return item.Adapt<ExamSampleStudentOutput>();
  58. }
  59. /// <summary>
  60. /// 查询监测学生信息
  61. /// </summary>
  62. /// <param name="input"></param>
  63. /// <returns></returns>
  64. public async Task<ExamSampleStudentOutput> QueryExamSampleStudent(QueryExamSampleStudentInput input)
  65. {
  66. var item = await _rep.DetachedEntities.Include(t => t.ExamStudent)
  67. .FirstOrDefaultAsync(t => t.ExamStudent.ExamPlanId == input.ExamPlanId &&
  68. t.ExamStudent.SysOrgId == CurrentSysUserInfo.SysOrgId &&
  69. t.ExamStudent.SysOrgBranchId == input.SysOrgBranchId &&
  70. t.ExamSample.IsSelected == true &&
  71. t.ExamStudent.ExamGradeId == input.ExamGradeId &&
  72. t.ExamStudent.ClassNumber == input.ClassNumber &&
  73. t.ExamNumber == input.ExamNumber);
  74. return item.Adapt<ExamSampleStudentOutput>();
  75. }
  76. }