From bfea00c64f928786d527c016676c7223593cfc90 Mon Sep 17 00:00:00 2001 From: ltx <1006158920@qq.com> Date: Tue, 18 Aug 2026 11:49:48 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E5=AD=A6=E7=94=9F=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/School/S_StudentService.cs | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/VOL.Business/Services/School/S_StudentService.cs b/VOL.Business/Services/School/S_StudentService.cs index 2093ec2..94f4e7f 100644 --- a/VOL.Business/Services/School/S_StudentService.cs +++ b/VOL.Business/Services/School/S_StudentService.cs @@ -294,13 +294,20 @@ namespace VOL.Business.Services.School public async Task AddStudent(AddStudentParam paramDto) { - var stuExists = await _studentRepository.ExistsAsync(x => x.StudentNo == paramDto.StudentNo); + if (paramDto == null || string.IsNullOrWhiteSpace(paramDto.StudentNo)) + throw new ArgumentNullException("学生学号必填"); + + var tenantId = UserContext.Current.TenantId; + paramDto.StudentNo = paramDto.StudentNo.Trim(); + + var stuExists = await _studentRepository.ExistsAsync(x => + x.SchoolCode == tenantId && x.StudentNo == paramDto.StudentNo); if (stuExists) throw new Exception($"学号{paramDto.StudentNo}的学生已存在!"); var studentEntity = _mapper.Map(paramDto); studentEntity.StudentStatus = StudentStatus.Normal; - studentEntity.SchoolCode = UserContext.Current.TenantId; + studentEntity.SchoolCode = tenantId; studentEntity.Creator = UserContext.Current.UserId; studentEntity.CreateDate = DateTime.Now; @@ -324,16 +331,23 @@ namespace VOL.Business.Services.School } public async Task ModifyStudent(AddStudentParam paramDto) { - if (paramDto == null || string.IsNullOrEmpty(paramDto.StudentNo)) + if (paramDto == null || string.IsNullOrWhiteSpace(paramDto.StudentNo)) { throw new ArgumentNullException("学生学号必填"); } - var student = await _studentRepository.FindAsyncFirst(x => x.Id == paramDto.Id); + var tenantId = UserContext.Current.TenantId; + paramDto.StudentNo = paramDto.StudentNo.Trim(); + + var student = await _studentRepository.FindAsyncFirst(x => + x.Id == paramDto.Id && x.SchoolCode == tenantId); if (student == null) throw new ArgumentNullException("未找到要更新的数据"); - var stuExists = await _studentRepository.ExistsAsync(x => x.StudentNo == paramDto.StudentNo && x.Id != student.Id); + var stuExists = await _studentRepository.ExistsAsync(x => + x.SchoolCode == tenantId && + x.StudentNo == paramDto.StudentNo && + x.Id != student.Id); if (stuExists) throw new Exception($"学号{paramDto.StudentNo}的学生已存在!");