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}的学生已存在!");