using Furion.DatabaseAccessor.Extensions; using Furion.JsonSerialization; using YBEE.EQM.Core; namespace YBEE.EQM.Application; /// /// 监测科目管理服务 /// public class ExamCourseService : IExamCourseService, ITransient { private readonly IRepository _rep; public ExamCourseService(IRepository rep) { _rep = rep; } /// /// 添加监测科目 /// /// /// public async Task Add(AddExamCourseInput input) { if (await _rep.AnyAsync(t => t.ExamPlanId == input.ExamPlanId && t.ExamGradeId == input.ExamGradeId && t.CourseId == input.CourseId)) { throw Oops.Oh(ErrorCode.E2002); } var item = input.Adapt(); item.ScoreReportConfig = JSON.Serialize(input.ScoreReportConfig); await item.InsertAsync(); } /// /// 更新监测科目 /// /// /// public async Task Update(UpdateExamCourseInput input) { if (await _rep.AnyAsync(t => t.Id != input.Id && t.ExamPlanId == input.ExamPlanId && t.ExamGradeId == input.ExamGradeId && t.CourseId == input.CourseId)) { throw Oops.Oh(ErrorCode.E2002); } var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001); item.ScoreReportConfig = JSON.Serialize(input.ScoreReportConfig); await item.UpdateAsync(); } /// /// 删除监测科目 /// /// /// public async Task Del(BaseId input) { var item = await _rep.FirstOrDefaultAsync(t => t.Id == input.Id) ?? throw Oops.Oh(ErrorCode.E2001); await item.DeleteAsync(); } /// /// 根据ID获取监测科目信息 /// /// /// public async Task GetById(int id) { var item = await _rep.DetachedEntities.ProjectToType().FirstOrDefaultAsync(t => t.Id == id) ?? throw Oops.Oh(ErrorCode.E2001); return item; } /// /// 根据监测年级查询监测学科列表 /// /// /// public async Task> QueryList(QueryExamCourseInput input) { var items = await _rep.DetachedEntities.Where(t => t.ExamPlanId == input.ExamPlanId) .Where(input.GradeId.HasValue, t => t.GradeId == input.GradeId) .ProjectToType() .OrderBy(t => t.GradeId).ThenBy(t => t.CourseId) .ToListAsync(); return items; } /// /// 查询监测学科列表 /// /// /// public async Task> GetListByExamPlanId(int examPlanId) { var items = await _rep.DetachedEntities.Where(t => t.ExamPlanId == examPlanId) .ProjectToType() .OrderBy(t => t.GradeId).ThenBy(t => t.CourseId) .ToListAsync(); return items; } }