75 lines
2.4 KiB
C#
Raw Normal View History

2025-06-06 14:57:20 +08:00
using Microsoft.EntityFrameworkCore;
using YD_WeChatApplet.Api.SmartSportsEntitys;
using YD_WeChatApplet.Api.Utilities;
using YD_WeChatApplet.Commons.Dto;
using YD_WeChatApplet.Commons.Dto.HomeWork;
using YD_WeChatApplet.Commons.Dto.School;
using YD_WeChatApplet.Context;
using YD_WeChatApplet.Services;
namespace YD_WeChatApplet.Api.Services.Impl
{
public class StudentService : IStudentService
{
public SmartSportsContext _sportsContext;
public StudentService(SmartSportsContext sportsContext)
{
_sportsContext = sportsContext;
}
/// <summary>
/// 获取班级列表
/// </summary>
/// <returns></returns>
public async Task<List<ClassListDto>> ClassListbyTeacher()
{
string teacherPhoneNo = UserLoginContext.Current.PhoneNo;
var classList = await (
from t in _sportsContext.Teacher
join a in _sportsContext.ClassAssocTeacher on t.Id equals a.TeacherId
join c in _sportsContext.Class on a.ClassId equals c.Id
2025-06-12 15:31:20 +08:00
where t.TeacherPhoneNo == teacherPhoneNo && t.TeacherStatus == 1
2025-06-06 14:57:20 +08:00
select new ClassListDto()
{
GradeId = c.GradeId,
ClassId = c.Id,
Name = $"{c.GradeName ?? ""}-{c.ClassName ?? ""}"
}).ToListAsync();
return classList;
}
/// <summary>
/// 获取学生列表
/// </summary>
/// <param name="dto"></param>
/// <returns></returns>
public async Task<PageDataDto<StudentListDto>> StudentListByClassId(StudentListByClassIdDto dto)
{
var query = _sportsContext.Student.Where(x => x.ClassId == dto.ClassId);
var totalCount = await query.CountAsync();
var students = await query
.Select(x => new StudentListDto()
{
StudentNo = x.StudentNo,
StudentName = x.StudentName,
Sex = x.Sex,
Photo = x.Photo
})
.Skip((dto.PageIndex - 1) * dto.PageSize)
.Take(dto.PageSize)
.ToListAsync();
return new PageDataDto<StudentListDto>
{
Total = totalCount,
Datas = students
};
}
}
}