ExamGradeService.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using YBEE.EQM.Core;
  2. namespace YBEE.EQM.Application;
  3. /// <summary>
  4. /// 监测年级管理服务
  5. /// </summary>
  6. public class ExamGradeService : IExamGradeService, ITransient
  7. {
  8. private readonly IRepository<ExamGrade> _rep;
  9. public ExamGradeService(IRepository<ExamGrade> rep)
  10. {
  11. _rep = rep;
  12. }
  13. /// <summary>
  14. /// 批量添加监测年级
  15. /// </summary>
  16. /// <param name="input"></param>
  17. /// <returns></returns>
  18. public async Task AddList(AddExamGradeListInput input)
  19. {
  20. var egradeids = await _rep.DetachedEntities.Where(t => t.ExamPlanId == input.ExamPlanId).Select(t => t.GradeId).ToListAsync();
  21. var newgradeids = input.GradeList.Where(t => !egradeids.Contains(t.GradeId));
  22. if (!newgradeids.Any())
  23. {
  24. return;
  25. }
  26. List<ExamGrade> items = new();
  27. foreach (var ng in newgradeids)
  28. {
  29. var item = ng.Adapt<ExamGrade>();
  30. item.ExamPlanId = input.ExamPlanId;
  31. items.Add(item);
  32. }
  33. await _rep.InsertAsync(items);
  34. }
  35. /// <summary>
  36. /// 移出监测年级
  37. /// </summary>
  38. /// <param name="input"></param>
  39. /// <returns></returns>
  40. public async Task Remove(DelExamGradeInput input)
  41. {
  42. var roleUsers = await _rep.Where(t => input.IdList.Contains(t.Id)).ToListAsync();
  43. await _rep.DeleteAsync(roleUsers);
  44. }
  45. /// <summary>
  46. /// 根据ID获取监测年级
  47. /// </summary>
  48. /// <param name="id"></param>
  49. /// <returns></returns>
  50. public async Task<ExamGradeOutput> GetById(int id)
  51. {
  52. var item = await _rep.DetachedEntities.Include(t => t.Grade).FirstOrDefaultAsync(t => t.Id == id);
  53. return item.Adapt<ExamGradeOutput>();
  54. }
  55. /// <summary>
  56. /// 根据监测计划ID获取全部监测年级
  57. /// </summary>
  58. /// <param name="examPlanId"></param>
  59. /// <returns></returns>
  60. public async Task<List<ExamGradeOutput>> GetListByExamPlanId(int examPlanId)
  61. {
  62. var items = await _rep.DetachedEntities.Where(t => t.ExamPlanId == examPlanId).ProjectToType<ExamGradeOutput>().ToListAsync();
  63. return items;
  64. }
  65. /// <summary>
  66. /// 根据监测计划和年级ID获取监测年级信息
  67. /// </summary>
  68. /// <param name="examPlanId"></param>
  69. /// <param name="gradeId"></param>
  70. /// <returns></returns>
  71. public async Task<ExamGradeOutput> GetByExamPlanGradeId(int examPlanId, int gradeId)
  72. {
  73. var item = await _rep.DetachedEntities.Include(t => t.Grade).FirstOrDefaultAsync(t => t.ExamPlanId == examPlanId && t.GradeId == gradeId);
  74. return item.Adapt<ExamGradeOutput>();
  75. }
  76. }