12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- using YBEE.EQM.Core;
- namespace YBEE.EQM.Application;
- /// <summary>
- /// 监测年级管理服务
- /// </summary>
- public class ExamGradeService : IExamGradeService, ITransient
- {
- private readonly IRepository<ExamGrade> _rep;
- public ExamGradeService(IRepository<ExamGrade> rep)
- {
- _rep = rep;
- }
- /// <summary>
- /// 批量添加监测年级
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task AddList(AddExamGradeListInput input)
- {
- var egradeids = await _rep.DetachedEntities.Where(t => t.ExamPlanId == input.ExamPlanId).Select(t => t.GradeId).ToListAsync();
- var newgradeids = input.GradeList.Where(t => !egradeids.Contains(t.GradeId));
- if (!newgradeids.Any())
- {
- return;
- }
- List<ExamGrade> items = new();
- foreach (var ng in newgradeids)
- {
- var item = ng.Adapt<ExamGrade>();
- item.ExamPlanId = input.ExamPlanId;
- items.Add(item);
- }
- await _rep.InsertAsync(items);
- }
- /// <summary>
- /// 移出监测年级
- /// </summary>
- /// <param name="input"></param>
- /// <returns></returns>
- public async Task Remove(DelExamGradeInput input)
- {
- var roleUsers = await _rep.Where(t => input.IdList.Contains(t.Id)).ToListAsync();
- await _rep.DeleteAsync(roleUsers);
- }
- /// <summary>
- /// 根据ID获取监测年级
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public async Task<ExamGradeOutput> GetById(int id)
- {
- var item = await _rep.DetachedEntities.Include(t => t.Grade).FirstOrDefaultAsync(t => t.Id == id);
- return item.Adapt<ExamGradeOutput>();
- }
- /// <summary>
- /// 根据监测计划ID获取全部监测年级
- /// </summary>
- /// <param name="examPlanId"></param>
- /// <returns></returns>
- public async Task<List<ExamGradeOutput>> GetListByExamPlanId(int examPlanId)
- {
- var items = await _rep.DetachedEntities.Where(t => t.ExamPlanId == examPlanId).ProjectToType<ExamGradeOutput>().ToListAsync();
- return items;
- }
- /// <summary>
- /// 根据监测计划和年级ID获取监测年级信息
- /// </summary>
- /// <param name="examPlanId"></param>
- /// <param name="gradeId"></param>
- /// <returns></returns>
- public async Task<ExamGradeOutput> GetByExamPlanGradeId(int examPlanId, int gradeId)
- {
- var item = await _rep.DetachedEntities.Include(t => t.Grade).FirstOrDefaultAsync(t => t.ExamPlanId == examPlanId && t.GradeId == gradeId);
- return item.Adapt<ExamGradeOutput>();
- }
- }
|