From a9d1ace2b65e4328d6537e6b43c75e2c084a0975 Mon Sep 17 00:00:00 2001 From: ltx <1006158920@qq.com> Date: Tue, 18 Aug 2026 10:56:55 +0800 Subject: [PATCH] =?UTF-8?q?update=EF=BC=9A=E4=BF=AE=E6=94=B9=E5=AD=A6?= =?UTF-8?q?=E7=94=9F=E4=BF=A1=E6=81=AF=E6=90=BA=E5=B8=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VOL.Business/IServices/School/IS_StudentService.cs | 2 +- VOL.Business/Services/School/S_StudentService.cs | 13 ++++++++++++- .../Controllers/Business/StudentController.cs | 1 + 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/VOL.Business/IServices/School/IS_StudentService.cs b/VOL.Business/IServices/School/IS_StudentService.cs index a649615..2a4b248 100644 --- a/VOL.Business/IServices/School/IS_StudentService.cs +++ b/VOL.Business/IServices/School/IS_StudentService.cs @@ -91,7 +91,7 @@ namespace VOL.Business.IServices.School /// /// /// - Task UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string studentName); + Task UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string? studentName); /// /// 批量导入学生头像 diff --git a/VOL.Business/Services/School/S_StudentService.cs b/VOL.Business/Services/School/S_StudentService.cs index 8602f10..2093ec2 100644 --- a/VOL.Business/Services/School/S_StudentService.cs +++ b/VOL.Business/Services/School/S_StudentService.cs @@ -676,7 +676,7 @@ namespace VOL.Business.Services.School /// /// 上传学生头像 /// - public async Task UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string studentName) + public async Task UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string? studentName) { const long maxFileSize = 2 * 1024 * 1024; @@ -686,6 +686,17 @@ namespace VOL.Business.Services.School throw new Exception("单张人脸照片大小不能超过2MB"); if (string.IsNullOrWhiteSpace(studentNo)) throw new Exception("学生学号不能为空"); + + // 编辑时上传组件可能只传文件和学号,此时使用当前学校已有的学生姓名。 + // 新增学生尚未入库,仍需要客户端显式传入姓名。 + if (string.IsNullOrWhiteSpace(studentName)) + { + studentName = await _studentRepository.DbContext.Set() + .AsNoTracking() + .Where(x => x.SchoolCode == UserContext.Current.TenantId && x.StudentNo == studentNo) + .Select(x => x.StudentName) + .FirstOrDefaultAsync(); + } if (string.IsNullOrWhiteSpace(studentName)) throw new Exception("学生姓名不能为空"); diff --git a/VOL.WebApi/Controllers/Business/StudentController.cs b/VOL.WebApi/Controllers/Business/StudentController.cs index 1d1a7ba..8fb19b9 100644 --- a/VOL.WebApi/Controllers/Business/StudentController.cs +++ b/VOL.WebApi/Controllers/Business/StudentController.cs @@ -179,6 +179,7 @@ namespace VOL.WebApi.Controllers.Business /// 年级Id /// 班级Id /// 学生学号 + /// 学生姓名;编辑已有学生时可不传 /// [HttpPost(nameof(UploadPhoto))]