Merge branch 'dev' of http://8.153.108.90:3000/YD/YD_SmartSports.Api into dev
This commit is contained in:
commit
1c402b2869
@ -91,7 +91,7 @@ namespace VOL.Business.IServices.School
|
||||
/// <param name="classId"></param>
|
||||
/// <param name="studentNo"></param>
|
||||
/// <returns></returns>
|
||||
Task<string> UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string studentName);
|
||||
Task<string> UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string? studentName);
|
||||
|
||||
/// <summary>
|
||||
/// 批量导入学生头像
|
||||
|
||||
@ -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<S_Student>(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}的学生已存在!");
|
||||
|
||||
@ -676,7 +690,7 @@ namespace VOL.Business.Services.School
|
||||
/// <summary>
|
||||
/// 上传学生头像
|
||||
/// </summary>
|
||||
public async Task<string> UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string studentName)
|
||||
public async Task<string> UploadPhoto(IFormFile file, int gradeId, int classId, string studentNo, string? studentName)
|
||||
{
|
||||
const long maxFileSize = 2 * 1024 * 1024;
|
||||
|
||||
@ -686,6 +700,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<S_Student>()
|
||||
.AsNoTracking()
|
||||
.Where(x => x.SchoolCode == UserContext.Current.TenantId && x.StudentNo == studentNo)
|
||||
.Select(x => x.StudentName)
|
||||
.FirstOrDefaultAsync();
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(studentName))
|
||||
throw new Exception("学生姓名不能为空");
|
||||
|
||||
|
||||
@ -179,6 +179,7 @@ namespace VOL.WebApi.Controllers.Business
|
||||
/// <param name="gradeId">年级Id</param>
|
||||
/// <param name="classId">班级Id</param>
|
||||
/// <param name="studentNo">学生学号</param>
|
||||
/// <param name="studentName">学生姓名;编辑已有学生时可不传</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost(nameof(UploadPhoto))]
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user