From 5494b32cd0b01071b9822c5b37408693c17882a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BC=8D=E6=BD=9C?= <1620556043@qq.com> Date: Tue, 25 Mar 2025 00:11:57 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=80=83=E7=94=9F=E8=8E=B7?= =?UTF-8?q?=E5=8F=96=E5=8E=86=E5=8F=B2=E8=80=83=E8=AF=95=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E3=80=81=E8=80=83=E7=94=9F=E6=96=B0=E5=A2=9E=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E9=80=BB=E8=BE=91=EF=BC=8C=E5=AE=8C=E5=96=84?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E8=80=83=E8=AF=95=E7=9A=84=E6=A0=A1=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/ClientService.cs | 3 ++ .../Implementations/ExamPaperService.cs | 6 +++ .../Implementations/StudentService.cs | 42 +++++++------------ 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/Src/CodeSpirit.ExamApi/Services/ClientService.cs b/Src/CodeSpirit.ExamApi/Services/ClientService.cs index 7336a6d..122c39d 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 99af8e1..dc05fab 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 ca2d501..7a6a89a 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(); -- Gitee