GradeService.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 年级信息服务
  5. /// </summary>
  6. public class GradeService : IGradeService, ITransient
  7. {
  8. private readonly IRepository<Grade> _rep;
  9. private readonly ISemesterService _semesterService;
  10. private readonly IEducationStageYearsService _educationStageYearsService;
  11. public GradeService(IRepository<Grade> rep, ISemesterService semesterService, IEducationStageYearsService educationStageYearsService)
  12. {
  13. _rep = rep;
  14. _semesterService = semesterService;
  15. _educationStageYearsService = educationStageYearsService;
  16. }
  17. /// <summary>
  18. /// 根据ID获取年级信息
  19. /// </summary>
  20. /// <param name="id"></param>
  21. /// <returns></returns>
  22. public async Task<GradeOutput> GetById(int id)
  23. {
  24. var item = await _rep.DetachedEntities.FirstOrDefaultAsync(t => t.Id == id) ?? throw Oops.Oh(ErrorCode.E2001);
  25. return item.Adapt<GradeOutput>();
  26. }
  27. /// <summary>
  28. /// 根据学段获取年级列表
  29. /// </summary>
  30. /// <param name="stage"></param>
  31. /// <returns></returns>
  32. public async Task<List<GradeOutput>> GetListByEducationStage(EducationStage stage)
  33. {
  34. var items = await _rep.DetachedEntities.Where(t => t.EducationStage == stage & t.Status == CommonStatus.ENABLE).ProjectToType<GradeOutput>().ToListAsync();
  35. return items;
  36. }
  37. /// <summary>
  38. /// 根据学期和学段获取年级年份
  39. /// </summary>
  40. /// <param name="input"></param>
  41. /// <returns></returns>
  42. public async Task<List<GradeYearOutput>> QueryGradeYearList(QueryGradeYearInput input)
  43. {
  44. var semester = await _semesterService.GetById(input.SemesterId);
  45. var grades = await _rep.DetachedEntities.Where(t => t.EducationStage == input.EducationStage & t.Status == CommonStatus.ENABLE).ProjectToType<GradeYearOutput>().ToListAsync();
  46. var ey = await _educationStageYearsService.GetByEducationStage(input.EducationStage);
  47. foreach (var grade in grades)
  48. {
  49. grade.GradeBeginYear = (short)(semester.BeginYear - grade.GradeNumber2 + 1);
  50. grade.GradeEndYear = (short)(semester.BeginYear + ey.EducationYears - grade.GradeNumber2 + 1);
  51. grade.EducationYears = ey.EducationYears;
  52. }
  53. return grades;
  54. }
  55. /// <summary>
  56. /// 获取全部年级列表
  57. /// </summary>
  58. /// <returns></returns>
  59. public async Task<List<GradeOutput>> GetAllList()
  60. {
  61. var items = await _rep.DetachedEntities.Where(t => t.Status == CommonStatus.ENABLE).ProjectToType<GradeOutput>().ToListAsync();
  62. return items;
  63. }
  64. }