上传 N_SportsTestValue 表
This commit is contained in:
parent
227714b2f4
commit
cfd469cb79
@ -28,6 +28,12 @@ namespace VOL.Commons
|
|||||||
/// AI
|
/// AI
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[Description("XW")]
|
[Description("XW")]
|
||||||
XW = 3
|
XW = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 壹路
|
||||||
|
/// </summary>
|
||||||
|
[Description("YL")]
|
||||||
|
YL = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using VOL.Commons;
|
||||||
using VOL.Entity.DomainModels.XinWei;
|
using VOL.Entity.DomainModels.XinWei;
|
||||||
using YD_YiLu.Api.Context;
|
using YD_YiLu.Api.Context;
|
||||||
using YD_YiLu.Api.Services.Interface;
|
using YD_YiLu.Api.Services.Interface;
|
||||||
@ -6,6 +7,7 @@ using YD_YiLu.Api.SmartSportsEntitys;
|
|||||||
using YD_YiLu.Api.Utilities;
|
using YD_YiLu.Api.Utilities;
|
||||||
using YD_YiLu.Commons;
|
using YD_YiLu.Commons;
|
||||||
using YD_YiLu.Commons.Dto.DeviceSync;
|
using YD_YiLu.Commons.Dto.DeviceSync;
|
||||||
|
using YD_YiLu.Commons.Dto.Open;
|
||||||
using YD_YiLu.Commons.Utils;
|
using YD_YiLu.Commons.Utils;
|
||||||
|
|
||||||
namespace YD_YiLu.Api.Services.Impl
|
namespace YD_YiLu.Api.Services.Impl
|
||||||
@ -194,9 +196,10 @@ namespace YD_YiLu.Api.Services.Impl
|
|||||||
foreach (var normalized in normalizedItems)
|
foreach (var normalized in normalizedItems)
|
||||||
{
|
{
|
||||||
var item = normalized.Item;
|
var item = normalized.Item;
|
||||||
|
|
||||||
// 👉 3. 唯一校验(跳过已存在)
|
// 👉 3. 唯一校验(跳过已存在)
|
||||||
if (!seenSerials.Add(normalized.TrainSerial))
|
//if (!seenSerials.Add(normalized.TrainSerial))
|
||||||
continue;
|
// continue;
|
||||||
|
|
||||||
var entity = new YL_Train
|
var entity = new YL_Train
|
||||||
{
|
{
|
||||||
@ -236,7 +239,12 @@ namespace YD_YiLu.Api.Services.Impl
|
|||||||
// 👉 4. 批量入库(关键优化点)
|
// 👉 4. 批量入库(关键优化点)
|
||||||
if (newEntities.Any())
|
if (newEntities.Any())
|
||||||
{
|
{
|
||||||
|
var sportsTestValueEntities = await AddSportsTestValueEntity(orgId.Value, newEntities);
|
||||||
|
|
||||||
_context.YL_Train.AddRange(newEntities);
|
_context.YL_Train.AddRange(newEntities);
|
||||||
|
if (sportsTestValueEntities.Any())
|
||||||
|
_context.SportsTestValue.AddRange(sportsTestValueEntities);
|
||||||
|
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -270,6 +278,135 @@ namespace YD_YiLu.Api.Services.Impl
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<List<N_SportsTestValue>> AddSportsTestValueEntity(int orgId, List<YL_Train> trains)
|
||||||
|
{
|
||||||
|
var sportsTestValueEntities = new List<N_SportsTestValue>();
|
||||||
|
if (trains == null || !trains.Any())
|
||||||
|
return sportsTestValueEntities;
|
||||||
|
|
||||||
|
var userSerials = trains
|
||||||
|
.Select(x => x.UserSerial)
|
||||||
|
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var students = await _context.Student
|
||||||
|
.Where(x => userSerials.Contains(x.StudentNo))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var classIds = students
|
||||||
|
.Where(x => x.ClassId.HasValue)
|
||||||
|
.Select(x => x.ClassId.Value)
|
||||||
|
.Distinct()
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
var classes = await _context.Class
|
||||||
|
.Where(x => classIds.Contains(x.Id))
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
var healthStandards = await _context.HealthStandards.ToListAsync();
|
||||||
|
var semesterDto = new SemesterDto();
|
||||||
|
var nowTime = DateTime.Now;
|
||||||
|
|
||||||
|
var studentMap = students
|
||||||
|
.GroupBy(x => x.StudentNo)
|
||||||
|
.ToDictionary(x => x.Key, x => x.First());
|
||||||
|
|
||||||
|
var classMap = classes.ToDictionary(x => x.Id, x => x);
|
||||||
|
|
||||||
|
foreach (var train in trains)
|
||||||
|
{
|
||||||
|
var value = ResolveSportsTestValue(train);
|
||||||
|
if (value == 0)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!studentMap.TryGetValue(train.UserSerial, out var student))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
S_Class? classInfo = null;
|
||||||
|
if (student.ClassId.HasValue)
|
||||||
|
classMap.TryGetValue(student.ClassId.Value, out classInfo);
|
||||||
|
|
||||||
|
var category = ResolveSportsTestCategory(train.CourseId);
|
||||||
|
|
||||||
|
var standard = healthStandards.FirstOrDefault(x =>
|
||||||
|
x.CategoryEnum == category.CategoryEnum &&
|
||||||
|
x.GradeId == (classInfo?.GradeId ?? 0) &&
|
||||||
|
x.Sex == student.Sex &&
|
||||||
|
value >= x.MinValue &&
|
||||||
|
value < x.MaxValue);
|
||||||
|
|
||||||
|
var sportsTestValueEntity = new N_SportsTestValue
|
||||||
|
{
|
||||||
|
SchoolCode = student.SchoolCode,
|
||||||
|
Sex = student.Sex,
|
||||||
|
DataSource = DataSource.YL,
|
||||||
|
CategoryValue = category.CategoryValue,
|
||||||
|
CategoryEnum = category.CategoryEnum,
|
||||||
|
GradeId = classInfo?.GradeId ?? 0,
|
||||||
|
GradeName = classInfo?.GradeName ?? "",
|
||||||
|
ClassId = student.ClassId ?? 0,
|
||||||
|
ClassName = classInfo?.ClassName ?? student.ClassName ?? "",
|
||||||
|
TeacherId = 0,
|
||||||
|
TeacherName = "",
|
||||||
|
StudentNo = student.StudentNo,
|
||||||
|
StudentName = student.StudentName,
|
||||||
|
Value = value,
|
||||||
|
MotionDuration = train.Duration > 0 ? (int)Math.Ceiling(train.Duration / 60.0) : 0,
|
||||||
|
Consumption = 0,
|
||||||
|
Strength = 0,
|
||||||
|
Score = standard?.Score ?? 0,
|
||||||
|
Rank = standard?.Rank,
|
||||||
|
RankEnum = standard?.Score.GetRank() ?? 0,
|
||||||
|
AdditionalScore = 0,
|
||||||
|
WrongResults = train.UnStandardCounts,
|
||||||
|
Creator = orgId,
|
||||||
|
CreateDate = nowTime,
|
||||||
|
ScoreTime = train.EndTime,
|
||||||
|
Year = semesterDto.Year,
|
||||||
|
Semester = semesterDto.Semester,
|
||||||
|
IsDisplay = true
|
||||||
|
};
|
||||||
|
|
||||||
|
sportsTestValueEntities.Add(sportsTestValueEntity);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sportsTestValueEntities;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static (int CategoryValue, string CategoryEnum) ResolveSportsTestCategory(int courseId)
|
||||||
|
{
|
||||||
|
var categoryEnum = courseId switch
|
||||||
|
{
|
||||||
|
3 => nameof(SportsTestItemType.Pull_Up),
|
||||||
|
7 => nameof(SportsTestItemType.StandingLongJump),
|
||||||
|
8 => nameof(SportsTestItemType.OneMinuteJumpRope),
|
||||||
|
23 => nameof(SportsTestItemType.Sit_And_Reach),
|
||||||
|
1001 => nameof(SportsTestItemType.BMI),
|
||||||
|
1002 => nameof(SportsTestItemType.VitalCapacity),
|
||||||
|
_ => Enum.GetName(typeof(CourseType), courseId) ?? courseId.ToString()
|
||||||
|
};
|
||||||
|
|
||||||
|
return (courseId, categoryEnum);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float ResolveSportsTestValue(YL_Train train)
|
||||||
|
{
|
||||||
|
if (train.CourseId == (int)CourseType.StandingLongJump && train.Distance.HasValue)
|
||||||
|
return (float)train.Distance.Value;
|
||||||
|
|
||||||
|
if (train.TimeKeeping.HasValue && train.TimeKeeping.Value > 0)
|
||||||
|
return (float)train.TimeKeeping.Value;
|
||||||
|
|
||||||
|
if (train.StandardCounts > 0)
|
||||||
|
return (float)train.StandardCounts;
|
||||||
|
|
||||||
|
if (train.Distance.HasValue)
|
||||||
|
return (float)train.Distance.Value;
|
||||||
|
|
||||||
|
return train.Score.HasValue ? (float)train.Score.Value : 0;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<DeviceSyncTrainDetailsDto> TrainDetailsAsync(int trainId)
|
public async Task<DeviceSyncTrainDetailsDto> TrainDetailsAsync(int trainId)
|
||||||
{
|
{
|
||||||
// 1. 获取训练记录
|
// 1. 获取训练记录
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user