198 lines
6.5 KiB
C#
198 lines
6.5 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Logging;
|
|
using YD_YiLu.Api.Services.Interface;
|
|
using YD_YiLu.Commons.Dto.DeviceSync;
|
|
|
|
namespace YD_YiLu.Api.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 设备同步 HTTP 接口。
|
|
/// </summary>
|
|
[AllowAnonymous]
|
|
public class DeviceSyncController : ControllerBase
|
|
{
|
|
private readonly IDeviceSyncService _deviceSyncService;
|
|
private readonly ILogger<DeviceSyncController> _logger;
|
|
|
|
public DeviceSyncController(IDeviceSyncService deviceSyncService, ILogger<DeviceSyncController> logger)
|
|
{
|
|
_deviceSyncService = deviceSyncService;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 人员全量拉取。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/user")]
|
|
public async Task<object> UserPullFull([FromBody] DeviceSyncUserRequestDto dto)
|
|
{
|
|
return await _deviceSyncService.UserSyncAsync(dto.DeviceSerial, dto.DeviceType, dto.UserType);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 人员分页下发。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/user_page")]
|
|
public async Task<object> UserPullPage([FromBody] DeviceSyncUserPageRequestDto dto)
|
|
{
|
|
if (dto.PageSize <= 0 && !dto.FullSync)
|
|
dto.PageSize = 10;
|
|
if (dto.PageIndex < 1)
|
|
dto.PageIndex = 1;
|
|
var res = await _deviceSyncService.UserPageAsync(dto);
|
|
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// user_trace 别名。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/user_trace")]
|
|
public Task<object> UserTrace([FromBody] DeviceSyncUserPageRequestDto dto) => UserPullPage(dto);
|
|
|
|
/// <summary>
|
|
/// 获取人员详情。
|
|
/// </summary>
|
|
[HttpGet]
|
|
[Route("/device/sync/user/detail")]
|
|
public async Task<object> UserDetail([FromQuery] string deviceSerial, [FromQuery] int userId)
|
|
{
|
|
return await _deviceSyncService.GetUserDetailAsync(deviceSerial, userId);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 组织信息下发。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/organization")]
|
|
public async Task<object> Organization([FromBody] DeviceSyncOrganizationRequestDto dto)
|
|
{
|
|
return await _deviceSyncService.OrganizationAsync(dto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 人员上次成绩。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/grade/last_grade")]
|
|
public async Task<object> LastGrade([FromBody] DeviceSyncLastGradeRequestDto dto)
|
|
{
|
|
if (dto == null || string.IsNullOrWhiteSpace(dto.DeviceSerial))
|
|
return new List<DeviceSyncLastGradeItemDto>();
|
|
return await _deviceSyncService.LastGradeAsync(dto);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 成绩批量上报。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/train_push")]
|
|
public async Task<object> TrainPush([FromBody] List<DeviceSyncTrainPushRequestDto> 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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取训练详情。
|
|
/// </summary>
|
|
[HttpGet]
|
|
[Route("/device/sync/train/details")]
|
|
public async Task<object> TrainDetails([FromQuery] int trainId)
|
|
{
|
|
var res = await _deviceSyncService.TrainDetailsAsync(trainId);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 个人成绩排行榜。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/grade/order")]
|
|
public async Task<object> GradeOrder([FromBody] DeviceSyncGradeOrderRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.GradeOrderAsync(dto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 组织(班级)成绩排行榜。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/organization_grade/order")]
|
|
public async Task<object> OrganizationGradeOrder([FromBody] DeviceSyncGradeOrderRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.OrganizationGradeOrderAsync(dto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询挑战最好成绩。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/grade/best_score")]
|
|
public async Task<object> BestScore([FromBody] DeviceSyncBestScoreRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.BestScoreAsync(dto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询运动记录。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/grade/record")]
|
|
[Route("/applet/train/record_app")]
|
|
public async Task<object> RecordApp([FromBody] DeviceSyncRecordAppRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.RecordAppAsync(dto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询我的运动。
|
|
/// </summary>
|
|
[HttpPost]
|
|
[Route("/device/sync/grade/my_record")]
|
|
public async Task<object> MyRecord([FromBody] DeviceSyncMyRecordRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.MyRecordAsync(dto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 查询我的运动(壹体屏)
|
|
/// </summary>
|
|
/// <param name="dto"></param>
|
|
/// <returns></returns>
|
|
[HttpPost]
|
|
[Route("/device/sync/train/my_record/ytp")]
|
|
public async Task<object> YtpMyRecord([FromBody] DeviceSyncYtpMyRecordRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.YtpMyRecordAsync(dto);
|
|
return res;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 视频回放上传。
|
|
/// </summary>
|
|
[HttpPost("device/sync/video/upload")]
|
|
public async Task<bool> UploadVideo([FromForm] DeviceVideoUploadRequestDto dto)
|
|
{
|
|
var res = await _deviceSyncService.DeviceVideoUploadAsync(dto);
|
|
return res;
|
|
}
|
|
}
|
|
}
|