diff --git a/YD_YiLu.Commons/Dto/DeviceSync/DeviceSyncTrainPushDto.cs b/YD_YiLu.Commons/Dto/DeviceSync/DeviceSyncTrainPushDto.cs index 992e5eb..c0a1da7 100644 --- a/YD_YiLu.Commons/Dto/DeviceSync/DeviceSyncTrainPushDto.cs +++ b/YD_YiLu.Commons/Dto/DeviceSync/DeviceSyncTrainPushDto.cs @@ -14,7 +14,7 @@ namespace YD_YiLu.Commons.Dto.DeviceSync public string VideoSerial { get; set; } public int TrainExam { get; set; } public int? QuizId { get; set; } - public int StandardCounts { get; set; } + public double StandardCounts { get; set; } public int UnStandardCounts { get; set; } public double? TimeKeeping { get; set; } public int Duration { get; set; } diff --git a/YD_YiLu/Controllers/DeviceSyncController.cs b/YD_YiLu/Controllers/DeviceSyncController.cs index 2ebc9e3..57704d3 100644 --- a/YD_YiLu/Controllers/DeviceSyncController.cs +++ b/YD_YiLu/Controllers/DeviceSyncController.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; using YD_YiLu.Api.Services.Interface; using YD_YiLu.Commons.Dto.DeviceSync; @@ -12,10 +13,12 @@ namespace YD_YiLu.Api.Controllers public class DeviceSyncController : ControllerBase { private readonly IDeviceSyncService _deviceSyncService; + private readonly ILogger _logger; - public DeviceSyncController(IDeviceSyncService deviceSyncService) + public DeviceSyncController(IDeviceSyncService deviceSyncService, ILogger logger) { _deviceSyncService = deviceSyncService; + _logger = logger; } /// @@ -91,6 +94,13 @@ namespace YD_YiLu.Api.Controllers [Route("/device/sync/train_push")] public async Task TrainPush([FromBody] List list) { + var rawBody = HttpContext.Items["TrainPushRawBody"] as string; + _logger.LogInformation( + "TrainPush model binding result. RawBodyLength: {RawBodyLength}, MappedCount: {MappedCount}, Body: {RawBody}", + rawBody?.Length ?? 0, + list?.Count ?? 0, + rawBody); + var res = await _deviceSyncService.TrainPushAsync(list); return res; } diff --git a/YD_YiLu/Services/Impl/DeviceSyncService.cs b/YD_YiLu/Services/Impl/DeviceSyncService.cs index b91a0bf..b1c2647 100644 --- a/YD_YiLu/Services/Impl/DeviceSyncService.cs +++ b/YD_YiLu/Services/Impl/DeviceSyncService.cs @@ -57,7 +57,7 @@ namespace YD_YiLu.Api.Services.Impl Username = s.StudentNo, Nickname = s.StudentName, GradeName = "", - OrganizationId = s.Id, + OrganizationId = (int)orgId, OrganizationName = s.ClassName ?? "", FacePictureUrl = s.Photo ?? "", Identity = "学生", @@ -106,7 +106,20 @@ namespace YD_YiLu.Api.Services.Impl if (!orgId.HasValue) return new List(); string schoolCode = await _context.School.Where(x => x.Id == orgId).Select(x => x.SchoolCode).FirstAsync(); - var grades = await _context.Grade.Where(x => x.SchoolCode == schoolCode).OrderBy(x => x.Id).ToListAsync(); + + var grades = await ( + from g in _context.Grade + join sg in _context.SchoolAssocGrade + on g.Id equals sg.GradeId + where sg.SchoolCode == schoolCode + orderby g.Id + select new + { + g.Id, + g.GradeName + } + ).ToListAsync(); + var classes = await _context.Class.Where(x => x.SchoolCode == schoolCode).ToListAsync(); var result = new List(); diff --git a/YD_YiLu/SmartSportsEntitys/YL_Train.cs b/YD_YiLu/SmartSportsEntitys/YL_Train.cs index ec1d221..91a1b1a 100644 --- a/YD_YiLu/SmartSportsEntitys/YL_Train.cs +++ b/YD_YiLu/SmartSportsEntitys/YL_Train.cs @@ -66,7 +66,7 @@ namespace YD_YiLu.Api.SmartSportsEntitys /// /// 有效个数 /// - public int StandardCounts { get; set; } + public double StandardCounts { get; set; } /// /// 不合格动作数 diff --git a/YD_YiLu/Startup.cs b/YD_YiLu/Startup.cs index 4d12988..9ecdad2 100644 --- a/YD_YiLu/Startup.cs +++ b/YD_YiLu/Startup.cs @@ -325,6 +325,32 @@ namespace YD_YiLu.Api await next(); }); + app.Use(async (context, next) => + { + if (HttpMethods.IsPost(context.Request.Method) && + context.Request.Path.Equals("/device/sync/train_push", StringComparison.OrdinalIgnoreCase)) + { + context.Request.EnableBuffering(); + context.Request.Body.Position = 0; + + using (var reader = new StreamReader(context.Request.Body, leaveOpen: true)) + { + var rawBody = await reader.ReadToEndAsync(); + context.Request.Body.Position = 0; + context.Items["TrainPushRawBody"] = rawBody; + + var logger = context.RequestServices.GetRequiredService>(); + logger.LogInformation( + "TrainPush raw request received before model binding. ContentType: {ContentType}, ContentLength: {ContentLength}, Body: {RawBody}", + context.Request.ContentType, + context.Request.ContentLength, + rawBody); + } + } + + await next(); + }); + app.UseRouting(); app.UseCors(); app.UseAuthentication();