diff --git a/Src/CodeSpirit.ExamApi/Services/ClientService.cs b/Src/CodeSpirit.ExamApi/Services/ClientService.cs index 7336a6d603ec57e89d605845adc93968daf9af14..122c39d2fbe2f891e1d0b8f39da5c58bf04f0ee7 100644 --- a/Src/CodeSpirit.ExamApi/Services/ClientService.cs +++ b/Src/CodeSpirit.ExamApi/Services/ClientService.cs @@ -103,6 +103,9 @@ public class ClientService : IClientService .Where(s => s.UserId == userId) .FirstOrDefaultAsync(); + if (student == null) + return new List(); + var examHistory = await _context.ExamRecords .Include(r => r.ExamSetting) .ThenInclude(s => s.ExamPaper) diff --git a/Src/CodeSpirit.ExamApi/Services/Implementations/ExamPaperService.cs b/Src/CodeSpirit.ExamApi/Services/Implementations/ExamPaperService.cs index 99af8e19d3558ebb9dc082aacfd33abf1df7bb77..dc05fab1e2f6aa26d83b709b1ca6240e0e382649 100644 --- a/Src/CodeSpirit.ExamApi/Services/Implementations/ExamPaperService.cs +++ b/Src/CodeSpirit.ExamApi/Services/Implementations/ExamPaperService.cs @@ -376,6 +376,12 @@ namespace CodeSpirit.ExamApi.Services.Implementations private async Task ValidateRandomExamPaperRules(GenerateRandomExamPaperDto createDto) { + // 总分与各题型分数之和必须相等 + if (createDto.TotalScore!= createDto.QuestionTypeRules.Sum(r => r.ScorePerQuestion & r.Count)) + { + throw new AppServiceException(400, "总分与各题型分数之和必须相等"); + } + // 预先检查题库是否有足够的题目 foreach (var typeRule in createDto.QuestionTypeRules) { diff --git a/Src/CodeSpirit.ExamApi/Services/Implementations/StudentService.cs b/Src/CodeSpirit.ExamApi/Services/Implementations/StudentService.cs index ca2d501aab02ae00d0254e47ad04ae7ab1d75d57..7a6a89a4bb9e9d76065e3597cc7e7628a7703dd4 100644 --- a/Src/CodeSpirit.ExamApi/Services/Implementations/StudentService.cs +++ b/Src/CodeSpirit.ExamApi/Services/Implementations/StudentService.cs @@ -171,25 +171,19 @@ public class StudentService : BaseCRUDIService x.StudentNumber == createDto.StudentNumber) - .AnyAsync(); - if (existsStudentNumber) + var existsStudentNumber = Repository.Find(x => !createDto.StudentNumber.IsNullOrWhiteSpace() && x.StudentNumber == createDto.StudentNumber); + if (!createDto.StudentNumber.IsNullOrWhiteSpace() && await existsStudentNumber.AnyAsync()) { throw new AppServiceException(400, "学号/工号已存在!"); } - var existsIdNo = await Repository - .Find(x => x.IdNo == createDto.IdNo) - .AnyAsync(); - if (existsIdNo) + var existsIdNo = Repository.Find(x => !createDto.IdNo.IsNullOrWhiteSpace() && x.IdNo == createDto.IdNo); + if (!createDto.IdNo.IsNullOrWhiteSpace() && await existsIdNo.AnyAsync()) { throw new AppServiceException(400, "该身份证已存在!"); } - var existsAdmissionTicket = await Repository - .Find(x => x.AdmissionTicket == createDto.AdmissionTicket) - .AnyAsync(); - if (existsAdmissionTicket) + var existsAdmissionTicket = Repository.Find(x => !createDto.AdmissionTicket.IsNullOrWhiteSpace() && x.AdmissionTicket == createDto.AdmissionTicket); + if (!createDto.AdmissionTicket.IsNullOrWhiteSpace() && await existsAdmissionTicket.AnyAsync()) { throw new AppServiceException(400, "该准考证已存在!"); } @@ -311,27 +305,21 @@ public class StudentService : BaseCRUDIService x.StudentNumber == updateDto.StudentNumber && x.Id != entity.Id) - .AnyAsync(); - if (existsStudentNumber) + var existsStudentNumberQueryable = Repository.Find(x => x.StudentNumber == updateDto.StudentNumber && x.Id != entity.Id); + if (!updateDto.StudentNumber.IsNullOrWhiteSpace() && await existsStudentNumberQueryable.AnyAsync()) { throw new AppServiceException(400, "学号/工号已存在!"); } - - - var existsIdNo = await Repository - .Find(x => x.IdNo == updateDto.IdNo && x.Id != entity.Id) - .AnyAsync(); - if (existsIdNo) + + var existsIdNo = Repository.Find(x => x.IdNo == updateDto.IdNo && x.Id != entity.Id); + if (!updateDto.IdNo.IsNullOrWhiteSpace() && await existsIdNo.AnyAsync()) { throw new AppServiceException(400, "该身份证已存在!"); } - var existsAdmissionTicket = await Repository - .Find(x => x.AdmissionTicket == updateDto.AdmissionTicket && x.Id != entity.Id) - .AnyAsync(); - if (existsAdmissionTicket) - { + + var existsAdmissionTicket = Repository.Find(x => x.AdmissionTicket == updateDto.AdmissionTicket && x.Id != entity.Id); + if (!updateDto.AdmissionTicket.IsNullOrWhiteSpace() && await existsAdmissionTicket.AnyAsync()) + { throw new AppServiceException(400, "该准考证已存在!"); } var entityGroups = entity.StudentGroups?.Select(x => x.StudentGroupId).ToList();