update:壹路运动站后台数据获取接口
This commit is contained in:
parent
d3afc6e575
commit
9b6d2d747b
15
VOL.Ai/IServices/IAiSportsStationService.cs
Normal file
15
VOL.Ai/IServices/IAiSportsStationService.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using VOL.Core.Extensions.AutofacManager;
|
||||
using VOL.Model;
|
||||
using VOL.Model.Ai.Request;
|
||||
using VOL.Model.Ai.Response;
|
||||
|
||||
namespace VOL.Ai.IServices
|
||||
{
|
||||
public interface IAiSportsStationService : IDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取壹路AI运动站列表
|
||||
/// </summary>
|
||||
Task<PageDataDto<AiSportsStationDto>> GetAiSportsStationList(AiSportsStationListRequest paramDto);
|
||||
}
|
||||
}
|
||||
179
VOL.Ai/Services/AiSportsStationService.cs
Normal file
179
VOL.Ai/Services/AiSportsStationService.cs
Normal file
@ -0,0 +1,179 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using VOL.Ai.IServices;
|
||||
using VOL.Core.EFDbContext;
|
||||
using VOL.Core.Extensions.AutofacManager;
|
||||
using VOL.Core.ManageUser;
|
||||
using VOL.Entity.DomainModels;
|
||||
using VOL.Entity.DomainModels.YiLu;
|
||||
using VOL.Entity.Enum;
|
||||
using VOL.Model;
|
||||
using VOL.Model.Ai.Request;
|
||||
using VOL.Model.Ai.Response;
|
||||
|
||||
namespace VOL.Ai.Services
|
||||
{
|
||||
public class AiSportsStationService : IAiSportsStationService, IDependency
|
||||
{
|
||||
private readonly VOLContext _dbContext;
|
||||
|
||||
private static readonly Dictionary<int, string> CourseNames = new()
|
||||
{
|
||||
{ 3, "引体向上" },
|
||||
{ 7, "立定跳远" },
|
||||
{ 8, "跳绳" },
|
||||
{ 9, "开合跳" },
|
||||
{ 10, "高抬腿" },
|
||||
{ 11, "深蹲" },
|
||||
{ 23, "坐位体前屈" },
|
||||
{ 24, "单脚跳" },
|
||||
{ 25, "动态臀桥" },
|
||||
{ 26, "左右跳" },
|
||||
{ 27, "打地鼠" },
|
||||
{ 28, "七上八下" },
|
||||
{ 29, "消灭蚊子" },
|
||||
{ 30, "石头剪刀布" },
|
||||
{ 31, "变脸" },
|
||||
{ 32, "打钉子" },
|
||||
{ 1001, "体重系数(BMI)" },
|
||||
{ 1002, "肺活量" }
|
||||
};
|
||||
|
||||
public AiSportsStationService(VOLContext dbContext)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
}
|
||||
|
||||
public async Task<PageDataDto<AiSportsStationDto>> GetAiSportsStationList(AiSportsStationListRequest paramDto)
|
||||
{
|
||||
paramDto.PageIndex = paramDto.PageIndex <= 0 ? 1 : paramDto.PageIndex;
|
||||
paramDto.PageSize = paramDto.PageSize <= 0 ? 10 : paramDto.PageSize;
|
||||
|
||||
var currentUser = UserContext.Current;
|
||||
var isAdmin = currentUser?.IsSuperAdmin == true
|
||||
|| string.Equals(currentUser?.UserName, "admin", StringComparison.OrdinalIgnoreCase);
|
||||
var schoolCode = currentUser?.TenantId;
|
||||
int? schoolId = null;
|
||||
|
||||
if (!isAdmin)
|
||||
{
|
||||
schoolId = await _dbContext.Set<S_School>()
|
||||
.Where(x => x.SchoolCode == schoolCode)
|
||||
.Select(x => (int?)x.Id)
|
||||
.FirstOrDefaultAsync();
|
||||
|
||||
if (schoolId == null)
|
||||
{
|
||||
return new PageDataDto<AiSportsStationDto>
|
||||
{
|
||||
Total = 0,
|
||||
TotalPages = 0,
|
||||
PageIndex = paramDto.PageIndex,
|
||||
PageSize = paramDto.PageSize,
|
||||
Datas = new List<AiSportsStationDto>()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
var studentName = paramDto.StudentName?.Trim();
|
||||
var projectName = paramDto.ProjectName?.Trim();
|
||||
var sex = GetSexType(paramDto.Sex);
|
||||
|
||||
var query =
|
||||
from train in _dbContext.Set<YL_Train>().AsNoTracking()
|
||||
join device in _dbContext.Set<YL_Device>().AsNoTracking()
|
||||
on train.DeviceSerial equals device.SerialNumber
|
||||
join student in _dbContext.Set<S_Student>().AsNoTracking()
|
||||
on train.UserSerial equals student.StudentNo into studentGroup
|
||||
from student in studentGroup.DefaultIfEmpty()
|
||||
select new
|
||||
{
|
||||
train.Id,
|
||||
device.OrgId,
|
||||
StudentSchoolCode = student == null ? schoolCode : student.SchoolCode,
|
||||
train.CourseId,
|
||||
train.StartTime,
|
||||
train.EndTime,
|
||||
train.UserSerial,
|
||||
StudentName = student == null ? train.UserSerial : student.StudentName,
|
||||
Sex = student == null ? (SexType?)null : student.Sex,
|
||||
ClassId = student == null ? 0 : student.ClassId,
|
||||
ClassName = student == null ? string.Empty : student.ClassName
|
||||
};
|
||||
|
||||
if (!isAdmin)
|
||||
{
|
||||
var currentSchoolId = schoolId.GetValueOrDefault();
|
||||
query = query.Where(x => x.OrgId == currentSchoolId && x.StudentSchoolCode == schoolCode);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(studentName))
|
||||
query = query.Where(x => x.StudentName.Contains(studentName));
|
||||
|
||||
if (sex.HasValue)
|
||||
query = query.Where(x => x.Sex == sex.Value);
|
||||
|
||||
if (paramDto.ClassId > 0)
|
||||
query = query.Where(x => x.ClassId == paramDto.ClassId);
|
||||
|
||||
if (paramDto.StartTime.HasValue)
|
||||
query = query.Where(x => x.StartTime >= paramDto.StartTime.Value);
|
||||
|
||||
if (paramDto.EndTime.HasValue)
|
||||
query = query.Where(x => x.StartTime <= paramDto.EndTime.Value);
|
||||
|
||||
var rows = await query
|
||||
.OrderByDescending(x => x.StartTime)
|
||||
.ThenByDescending(x => x.Id)
|
||||
.ToListAsync();
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(projectName))
|
||||
rows = rows.Where(x => GetCourseName(x.CourseId).Contains(projectName)).ToList();
|
||||
|
||||
var total = rows.Count;
|
||||
var datas = rows
|
||||
.Skip((paramDto.PageIndex - 1) * paramDto.PageSize)
|
||||
.Take(paramDto.PageSize)
|
||||
.Select((x, index) => new AiSportsStationDto
|
||||
{
|
||||
Ind = (paramDto.PageIndex - 1) * paramDto.PageSize + index + 1,
|
||||
StudentName = x.StudentName,
|
||||
Sex = GetSexName(x.Sex),
|
||||
ClassName = x.ClassName,
|
||||
ProjectName = GetCourseName(x.CourseId),
|
||||
StartTime = x.StartTime,
|
||||
EndTime = x.EndTime
|
||||
})
|
||||
.ToList();
|
||||
|
||||
return new PageDataDto<AiSportsStationDto>
|
||||
{
|
||||
Total = total,
|
||||
TotalPages = (int)Math.Ceiling(total / (double)paramDto.PageSize),
|
||||
PageIndex = paramDto.PageIndex,
|
||||
PageSize = paramDto.PageSize,
|
||||
Datas = datas
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetCourseName(int courseId)
|
||||
{
|
||||
return CourseNames.TryGetValue(courseId, out var name) ? name : courseId.ToString();
|
||||
}
|
||||
|
||||
private static SexType? GetSexType(string sex)
|
||||
{
|
||||
return sex switch
|
||||
{
|
||||
"男" => SexType.Male,
|
||||
"女" => SexType.Female,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetSexName(SexType? sex)
|
||||
{
|
||||
if (sex == null) return string.Empty;
|
||||
return sex == SexType.Male ? "男" : "女";
|
||||
}
|
||||
}
|
||||
}
|
||||
41
VOL.Model/Ai/Request/AiSportsStationRequest.cs
Normal file
41
VOL.Model/Ai/Request/AiSportsStationRequest.cs
Normal file
@ -0,0 +1,41 @@
|
||||
using System;
|
||||
using VOL.Model;
|
||||
|
||||
namespace VOL.Model.Ai.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// 壹路AI运动站列表查询
|
||||
/// </summary>
|
||||
public class AiSportsStationListRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 学生姓名
|
||||
/// </summary>
|
||||
public string StudentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 性别
|
||||
/// </summary>
|
||||
public string Sex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班级Id
|
||||
/// </summary>
|
||||
public int ClassId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 课目名称
|
||||
/// </summary>
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 运动开始时间
|
||||
/// </summary>
|
||||
public DateTime? StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 运动结束时间
|
||||
/// </summary>
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
45
VOL.Model/Ai/Response/AiSportsStationDto.cs
Normal file
45
VOL.Model/Ai/Response/AiSportsStationDto.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using System;
|
||||
|
||||
namespace VOL.Model.Ai.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// 壹路AI运动站列表数据
|
||||
/// </summary>
|
||||
public class AiSportsStationDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 序号
|
||||
/// </summary>
|
||||
public int Ind { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 学生姓名
|
||||
/// </summary>
|
||||
public string StudentName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 性别
|
||||
/// </summary>
|
||||
public string Sex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 班级名称
|
||||
/// </summary>
|
||||
public string ClassName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 课目名称
|
||||
/// </summary>
|
||||
public string ProjectName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 运动开始时间
|
||||
/// </summary>
|
||||
public DateTime? StartTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 运动结束时间
|
||||
/// </summary>
|
||||
public DateTime? EndTime { get; set; }
|
||||
}
|
||||
}
|
||||
36
VOL.WebApi/Controllers/AI/AiSportsStationController.cs
Normal file
36
VOL.WebApi/Controllers/AI/AiSportsStationController.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System.Threading.Tasks;
|
||||
using VOL.Ai.IServices;
|
||||
using VOL.Core.Filters;
|
||||
using VOL.Model;
|
||||
using VOL.Model.Ai.Request;
|
||||
using VOL.Model.Ai.Response;
|
||||
|
||||
namespace VOL.WebApi.Controllers.AI
|
||||
{
|
||||
/// <summary>
|
||||
/// 壹路AI运动站
|
||||
/// </summary>
|
||||
[Route("api/[controller]")]
|
||||
[ApiController]
|
||||
[ApiExplorerSettings(GroupName = "v6")]
|
||||
[TypeFilter(typeof(CustomApiResponseFilter))]
|
||||
public class AiSportsStationController : ControllerBase
|
||||
{
|
||||
private readonly IAiSportsStationService _aiSportsStationService;
|
||||
|
||||
public AiSportsStationController(IAiSportsStationService aiSportsStationService)
|
||||
{
|
||||
_aiSportsStationService = aiSportsStationService;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取壹路AI运动站列表
|
||||
/// </summary>
|
||||
[HttpGet(nameof(GetAiSportsStationList))]
|
||||
public async Task<PageDataDto<AiSportsStationDto>> GetAiSportsStationList([FromQuery] AiSportsStationListRequest paramDto)
|
||||
{
|
||||
return await _aiSportsStationService.GetAiSportsStationList(paramDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user