ExamGradeService.cs 3.2 KB

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