This commit is contained in:
tanglong 2025-07-07 14:56:38 +08:00
parent c13e3a8ca3
commit d42a18c64c
5 changed files with 176 additions and 87 deletions

View File

@ -163,7 +163,7 @@ namespace VOL.Ai.IServices
/// <summary>
/// 心率成绩上传
/// </summary>
void HeartRateResultUpload(AddHeartRateResultUploadRequest paramDto);
Task HeartRateResultUpload(AddHeartRateResultUploadRequest paramDto);
/// <summary>
/// 新增课堂记录

View File

@ -114,7 +114,7 @@ namespace VOL.Ai.Services
}).FirstOrDefaultAsync();
if (res == null)
throw new ArgumentNullException(nameof(res));
return new Ai_SchoolDto();
var gIds = await _studentRepository.DbContext.Set<S_SchoolAssocGrade>().Where(x => x.SchoolCode == res.SchoolCode).Select(x => x.GradeId).ToListAsync();
@ -247,71 +247,79 @@ namespace VOL.Ai.Services
public async Task<Ai_StudentFaceInfo> StudentFace(GetFaceParam paramDto)
{
var body = await ALiYunFace.SearchFace(paramDto.Base64);
var faces = await ALiYunFace.SearchFace(paramDto.Base64, false);
if (body != null && body.Confidence >= 72.62)
foreach (var body in faces)
{
var student = await (from s in _studentRepository.FindAsIQueryable(x => x.SchoolCode == paramDto.SchoolCode && x.StudentNo == body.EntityId)
join c in _studentRepository.DbContext.Set<S_Class>() on s.ClassId equals c.Id
select new Ai_StudentFaceInfo
{
ClassId = c.Id,
ClassName = c.ClassName,
Age = s.Age,
Sex = s.Sex,
StudentName = s.StudentName,
StudentCode = s.StudentNo,
GradeId = c.GradeId,
GradeName = c.GradeName,
Photo = s.Photo
}).FirstOrDefaultAsync();
if (body != null && body.Confidence >= 72.62)
{
var student = await (from s in _studentRepository.FindAsIQueryable(x => x.SchoolCode == paramDto.SchoolCode && x.StudentNo == body.EntityId)
join c in _studentRepository.DbContext.Set<S_Class>() on s.ClassId equals c.Id
select new Ai_StudentFaceInfo
{
ClassId = c.Id,
ClassName = c.ClassName,
Age = s.Age,
Sex = s.Sex,
StudentName = s.StudentName,
StudentCode = s.StudentNo,
GradeId = c.GradeId,
GradeName = c.GradeName,
Photo = s.Photo
}).FirstOrDefaultAsync();
if (student == null)
throw new Exception("未查询到学生信息");
if (student != null)
return student;
}
}
throw new Exception("未查询到学生信息"); ;
throw new Exception("未查询到学生信息");
}
public async Task<Ai_TeacherFaceInfo> TeacherFace(GetFaceParam paramDto)
{
var body = await ALiYunFace.SearchFace(paramDto.Base64, false);
var faces = await ALiYunFace.SearchFace(paramDto.Base64, false);
if (body != null && body.Confidence >= 72.62)
foreach (var body in faces)
{
var teacher = await _teacherRepository.FindAsIQueryable(x => x.SchoolCode == paramDto.SchoolCode && x.TeacherStatus != TeacherStatus.Depart && x.TeacherPhoneNo == body.EntityId)
.Select(x =>
new Ai_TeacherFaceInfo()
{
Id = x.Id,
Age = x.Age,
//SchoolCode = x.SchoolCode,
Sex = x.Sex,
Phone = x.TeacherPhoneNo,
TeacherName = x.TeacherName,
Photo = x.TeacherPhoto,
}).FirstOrDefaultAsync();
if (body != null && body.Confidence >= 72.62)
{
var teacher = await _teacherRepository.FindAsIQueryable(x => x.SchoolCode == paramDto.SchoolCode && x.TeacherStatus != TeacherStatus.Depart && x.TeacherPhoneNo == body.EntityId)
.Select(x =>
new Ai_TeacherFaceInfo()
{
Id = x.Id,
Age = x.Age,
//SchoolCode = x.SchoolCode,
Sex = x.Sex,
Phone = x.TeacherPhoneNo,
TeacherName = x.TeacherName,
Photo = x.TeacherPhoto,
}).FirstOrDefaultAsync();
if (teacher == null)
throw new Exception("未查询到老师信息");
if (teacher == null)
continue;
var grades = await (
from t in _studentRepository.DbContext.Set<S_ClassAssocTeacher>()
join c in _studentRepository.DbContext.Set<S_Class>() on t.ClassId equals c.Id into classGroup
from c in classGroup.DefaultIfEmpty()
where t.TeacherId == teacher.Id && c != null
select new Classes()
{
Id = c.Id,
Name = $"{c.GradeName}-{c.ClassName}",
}).ToListAsync();
var grades = await (
from t in _studentRepository.DbContext.Set<S_ClassAssocTeacher>()
join c in _studentRepository.DbContext.Set<S_Class>() on t.ClassId equals c.Id into classGroup
from c in classGroup.DefaultIfEmpty()
where t.TeacherId == teacher.Id && c != null
select new Classes()
{
Id = c.Id,
Name = $"{c.GradeName}-{c.ClassName}",
}).ToListAsync();
teacher.GradeAndClassList = grades;
teacher.GradeAndClassList = grades;
return teacher;
return teacher;
}
}
throw new Exception("人脸识别失败!");
throw new Exception("未查询到老师信息");
}
public async Task<List<Ai_StudentListDto>> Ai_StudentList(Ai_StudentListRequest paramDto)
@ -320,6 +328,8 @@ namespace VOL.Ai.Services
join c in _studentRepository.DbContext.Set<S_Class>() on s.ClassId equals c.Id
join g in _studentRepository.DbContext.Set<S_Grade>() on c.GradeId equals g.Id
where s.SchoolCode == paramDto.SchoolCode && s.ClassId == paramDto.Id && s.StudentStatus == StudentStatus.Normal
orderby s.OrderNo ascending
select new Ai_StudentListDto()
{
Code = paramDto.Code,
@ -373,8 +383,7 @@ namespace VOL.Ai.Services
select new Ai_ItemTypeModel()
{
ItemCode = s.Id,
ItemTypeName = s.SpecialName,
ImageUrl = s.ImageUrl
ItemTypeName = s.SpecialName
}).ToListAsync();
return list;
@ -386,7 +395,10 @@ namespace VOL.Ai.Services
public async Task<Ai_TeachingItemsDetailModel> TeachingItemsDetail(Ai_TeachingItemsRequest paramDto)
{
if (paramDto == null || paramDto.ItemCode <= 0)
throw new Exception("参数错误");
{
Console.WriteLine("参数为空,跳过...");
return new Ai_TeachingItemsDetailModel();
}
var result = await (
from s in _studentRepository.DbContext.Set<Ai_Special>()
@ -703,7 +715,10 @@ namespace VOL.Ai.Services
//await _studentRepository.SaveChangesAsync();
if (paramDto == null)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空,跳过...");
return;
}
var entity = _mapper.Map<Ai_TrainingData>(paramDto);
@ -720,7 +735,10 @@ namespace VOL.Ai.Services
public async Task SportsTestResultUpload(SportsTestResultUploadRequest paramDto)
{
if (paramDto == null)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空,跳过...");
return;
}
var entity = _mapper.Map<Ai_SportsTestData>(paramDto);
@ -737,7 +755,10 @@ namespace VOL.Ai.Services
}).FirstOrDefaultAsync();
if (student == null)
throw new ArgumentNullException($"未找到学生信息");
{
Console.WriteLine("未找到学生信息,跳过...");
return;
}
SemesterDto semesterDto = new SemesterDto();
entity.Year = semesterDto.Year;
@ -752,6 +773,7 @@ namespace VOL.Ai.Services
entity.ClassName = student.ClassName;
entity.StudentName = student.StudentName;
entity.Sex = student.Sex;
entity.IsDisplay = true;
var categoryEnum = Tool.GetEnumNameByValue(paramDto.CategoryValue);
var healthStandards = await _healthStandardsRepository.FindAsync(x => x.CategoryEnum == categoryEnum);
@ -785,7 +807,10 @@ namespace VOL.Ai.Services
public async Task ActivitiestResultUpload(Ai_ActivitiestResultUploadRequest paramDto)
{
if (paramDto == null)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空,跳过...");
return;
}
var entity = _mapper.Map<Ai_ActivitiestData>(paramDto);
@ -806,7 +831,10 @@ namespace VOL.Ai.Services
public async Task LevelExamResultUpload(LevelExamDataUploadRequest paramDto)
{
if (paramDto == null)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空,跳过...");
return;
}
var entity = _mapper.Map<Ai_LevelExamData>(paramDto);
@ -826,7 +854,11 @@ namespace VOL.Ai.Services
}).FirstOrDefaultAsync();
if (student == null)
throw new ArgumentNullException($"未找到学生信息");
{
Console.WriteLine("未找到学生信息,跳过...");
return;
}
entity.ScoreTime = paramDto.StartTime;
entity.StartTime = paramDto.StartTime;
@ -837,6 +869,7 @@ namespace VOL.Ai.Services
entity.ClassName = student.ClassName;
entity.StudentName = student.StudentName;
entity.Sex = student.Sex;
entity.IsDisplay = true;
await _levelExamDataRepository.AddAsync(entity);
await _levelExamDataRepository.SaveChangesAsync();
@ -848,16 +881,22 @@ namespace VOL.Ai.Services
/// <param name="paramDto"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public async void HeartRateResultUpload(AddHeartRateResultUploadRequest paramDto)
public async Task HeartRateResultUpload(AddHeartRateResultUploadRequest paramDto)
{
if (paramDto == null || paramDto.Datas == null || paramDto.Datas.Count == 0)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空或数据为空,跳过处理。");
return;
}
var heartRateDatas = _mapper.Map<List<Ai_HeartRateData>>(paramDto.Datas);
heartRateDatas = heartRateDatas.Where(data => data.Value != 0).ToList();
var classIds = paramDto.Datas.Select(x => x.ClassId).ToList();
var classList = await _classRepository.FindAsync(x => x.SchoolCode == paramDto.SchoolCode && classIds.Contains(x.Id));
var timeNow = DateTime.Now;
heartRateDatas.ForEach(heartRateData =>
{
var classInfo = classList.Where(x => x.Id == heartRateData.ClassId).First();
@ -868,11 +907,13 @@ namespace VOL.Ai.Services
heartRateData.TeacherId = paramDto.TeacherId;
heartRateData.GradeId = classInfo.GradeId;
heartRateData.GradeName = classInfo.GradeName;
heartRateData.ScoreTime = DateTime.Now;
HeartRateQueueData.Add(heartRateData);
heartRateData.ScoreTime = timeNow;
heartRateData.IsDisplay = true;
//HeartRateQueueData.Add(heartRateData);
});
await _heartRateDataRepository.AddRangeAsync(heartRateDatas);
await _heartRateDataRepository.SaveChangesAsync();
}
/// <summary>
@ -884,7 +925,10 @@ namespace VOL.Ai.Services
public async Task FastJumpRopeResultUpload(AddFastJumpRopeResultUploadRequest paramDto)
{
if (paramDto == null || paramDto.Datas == null || paramDto.Datas.Count == 0)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空或数据为空,跳过处理。");
return;
}
var fastJumpRopeDatas = _mapper.Map<List<Ai_FastJumpRopeData>>(paramDto.Datas);
@ -898,6 +942,7 @@ namespace VOL.Ai.Services
data.Code = paramDto.Code;
data.SchoolCode = paramDto.SchoolCode;
data.ClassRoomRecordId = paramDto.ClassRoomRecordId;
data.GroupId = paramDto.GroupId;
data.TeacherId = paramDto.TeacherId;
data.GradeId = classInfo.GradeId;
data.GradeName = classInfo.GradeName;
@ -907,7 +952,6 @@ namespace VOL.Ai.Services
data.ModelName = paramDto.ModeType.GetDescription();
data.UniqueId = paramDto.UniqueId;
});
await _fastJumpRopeDataRepository.AddRangeAsync(fastJumpRopeDatas);
await _fastJumpRopeDataRepository.SaveChangesAsync();
}
@ -922,16 +966,17 @@ namespace VOL.Ai.Services
{
var res = new PageDataDto<Ai_FastJumpRopeDto>();
// 查询数据并根据 UniqueId 分组
var groupedQuery = from a in _fastJumpRopeDataRepository.FindAsIQueryable(x =>
//x.ClassId == paramDto.ClassId &&
x.SchoolCode == paramDto.SchoolCode)
x.SchoolCode == paramDto.SchoolCode &&
(paramDto.ClassRoomRecordId == null || paramDto.ClassRoomRecordId <= 0 || x.ClassRoomRecordId == paramDto.ClassRoomRecordId))
group a by a.GroupId into g
select new
{
GroupId = g.Key,
ModelName = g.FirstOrDefault().ModelName,
MotionDuration = g.FirstOrDefault().MotionDuration,
g.FirstOrDefault().MotionDuration,
g.FirstOrDefault().ModeType,
g.FirstOrDefault().ModelName,
//MotionDuration = g.FirstOrDefault().MotionDuration,
ScoreTime = g.Max(x => x.ScoreTime),
TestItem = Ai_TrainingModuleEnum.FastJumpRope.GetDescription()
};
@ -947,6 +992,7 @@ namespace VOL.Ai.Services
.Select(x => new Ai_FastJumpRopeDto
{
GroupId = x.GroupId,
ModeType = x.ModeType,
ModelName = x.ModelName,
MotionDuration = x.MotionDuration,
ScoreTime = x.ScoreTime,
@ -969,11 +1015,16 @@ namespace VOL.Ai.Services
{
var res = new PageDataDto<Ai_FastJumpRopeStudentList>();
// 构建查询
//var query = _fastJumpRopeDataRepository.FindAsIQueryable(x =>
// x.ClassRoomRecordId == paramDto.ClassRoomRecordId &&
// x.SchoolCode == paramDto.SchoolCode &&
// (paramDto.ModeType != Ai_FastJumpRopeModeEnum.FollowMode || x.GroupId == paramDto.GroupId)
// );
var query = _fastJumpRopeDataRepository.FindAsIQueryable(x =>
x.ClassRoomRecordId == paramDto.ClassRoomRecordId &&
x.SchoolCode == paramDto.SchoolCode);
x.ClassRoomRecordId == paramDto.ClassRoomRecordId &&
x.SchoolCode == paramDto.SchoolCode && x.GroupId == paramDto.GroupId);
// 异步获取数据列表
var rawData = await query.ToListAsync();
@ -1022,7 +1073,10 @@ namespace VOL.Ai.Services
public async Task<Ai_ClassRoomRecordDto> AddClassRoomRecord(Ai_ClassRoomRecordRequest paramDto)
{
if (paramDto == null)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空或数据为空,跳过处理。");
return new Ai_ClassRoomRecordDto();
}
var entity = _mapper.Map<Ai_ClassRoomRecord>(paramDto);
@ -1032,7 +1086,10 @@ namespace VOL.Ai.Services
var classInfos = await _classRepository.FindAsync(x => ids.Contains(x.Id) && x.SchoolCode == paramDto.SchoolCode);
var classInfo = classInfos.FirstOrDefault(x => x.Id == paramDto.ClassId);
if (classInfo == null)
throw new ArgumentNullException($"班级信息为空");
{
Console.WriteLine("班级信息数据为空,跳过处理。");
return new Ai_ClassRoomRecordDto();
}
entity.ClassName = classInfo.ClassName;
entity.GradeId = classInfo.GradeId;
@ -1046,7 +1103,10 @@ namespace VOL.Ai.Services
{
var StuClass = classInfos.First(x => x.Id == student.ClassId);
if (StuClass == null)
throw new ArgumentNullException($"班级信息为空");
{
Console.WriteLine("班级信息数据为空,跳过处理。");
return new Ai_ClassRoomRecordDto();
}
student.ClassName = StuClass.ClassName;
student.GradeId = StuClass.GradeId;
@ -1072,7 +1132,11 @@ namespace VOL.Ai.Services
public async Task EndTeaching(EndTeachingRequest paramDto)
{
if (paramDto == null)
throw new ArgumentNullException($"参数为空");
{
Console.WriteLine("参数为空,跳过...");
return;
}
var entity = await _classRoomRecordRepository.FindAsyncFirst(x => x.Id == paramDto.ClassRoomRecordId && x.SchoolCode == paramDto.SchoolCode);

View File

@ -134,9 +134,9 @@ namespace VOL.Core.Utilities
catch (Exception _error)
{
TeaException error = new TeaException(new Dictionary<string, object>
{
{ "message", _error.Message }
});
{
{ "message", _error.Message }
});
throw new Exception($"系统异常:人脸数据添加失败。可能原因包括图片格式或内容不符合要求。请确保图片为正面人脸清晰无遮挡,分辨率不少于 640x480大小不超过 2MB。错误详情{error.Message}");
}
@ -146,7 +146,7 @@ namespace VOL.Core.Utilities
/// </summary>
/// <param name="faceDbName"></param>
/// <returns></returns>
public static async Task<SearchFaceResponseBodyDataMatchListFaceItems> SearchFace(string base64, bool isStudent = true)
public static async Task<List<SearchFaceResponseBodyDataMatchListFaceItems>> SearchFace(string base64, bool isStudent = true)
{
AlibabaCloud.SDK.Facebody20191230.Client client = CreateClient();
try
@ -161,7 +161,7 @@ namespace VOL.Core.Utilities
var searchFaceAdvanceRequest = new SearchFaceAdvanceRequest
{
ImageUrlObject = stream,
Limit = 1,
Limit = 10,
DbName = isStudent ? AppSetting.ALiYunFaceDetect.StudeneDb : AppSetting.ALiYunFaceDetect.TeacherDb
};
@ -169,7 +169,7 @@ namespace VOL.Core.Utilities
var res = await client.SearchFaceAdvanceAsync(searchFaceAdvanceRequest, runtime);
return res.Body.Data.MatchList.Count > 0 && res.Body.Data.MatchList[0].FaceItems.Count > 0 ? res.Body.Data.MatchList[0].FaceItems[0] : null;
return res.Body.Data.MatchList.Count > 0 && res.Body.Data.MatchList[0].FaceItems.Count > 0 ? res.Body.Data.MatchList[0].FaceItems : null;
}
}
catch (TeaException error)

View File

@ -48,6 +48,7 @@ namespace VOL.Model.Ai.Request
public DateTime? TodayTime { get; set; }
}
/// <summary>
/// Ai速度跳绳成绩排行
/// </summary>
@ -64,9 +65,9 @@ namespace VOL.Model.Ai.Request
public string SchoolCode { get; set; }
/// <summary>
/// 班级Id
/// 课堂记录Id
/// </summary>
//public int ClassId { get; set; }
public int? ClassRoomRecordId { get; set; }
}
@ -85,9 +86,24 @@ namespace VOL.Model.Ai.Request
/// </summary>
public string SchoolCode { get; set; }
/// <summary>
/// GroupId
/// </summary>
public string GroupId { get; set; }
/// <summary>
/// 课堂记录Id
/// </summary>
public int ClassRoomRecordId { get; set; }
/// <summary>
/// 模式类型
/// </summary>
//public Ai_FastJumpRopeModeEnum ModeType { get; set; }
/// <summary>
///运动时长/分钟
/// </summary>
//public int? MotionDuration { get; set; }
}
}

View File

@ -34,12 +34,16 @@ namespace VOL.Model.Ai
/// </summary>
public string StudentNo { get; set; }
}
/// <summary>
/// Ai速度跳绳
/// </summary>
public class Ai_FastJumpRopeDto
{
/// <summary>
/// 设备上传成绩时唯一标识
/// </summary>
//public string UniqueId { get; set; }
/// <summary>
/// GroupId
/// </summary>
@ -60,6 +64,11 @@ namespace VOL.Model.Ai
/// </summary>
public int? MotionDuration { get; set; }
/// <summary>
/// 模式类型
/// </summary>
public Ai_FastJumpRopeModeEnum ModeType { get; set; }
/// <summary>
/// 模式名称
/// </summary>