ExternalAPI_NET8/Web.Core.Services/Myschool/StudentService.cs
2026-05-21 17:23:36 +08:00

53 lines
1.3 KiB
C#

#region
using AutoMapper;
using Web.Core.Common.Attributes;
using Web.Core.IRepository.Base;
using Web.Core.IRepository.Myschool;
using Web.Core.IServices.Myschool;
using Web.Core.Model.DTO;
using Web.Core.Model.Entity;
using Web.Core.Services.Base;
#endregion
namespace Web.Core.Services.Myschool;
public class StudentService : BaseServices<Student>, IStudentService
{
private readonly IStudentRepository _studentRepository;
private readonly IMapper _mapper;
public StudentService(IBaseRepository<Student> baseDal, IStudentRepository studentRepository, IMapper mapper) :
base(baseDal)
{
_studentRepository = studentRepository;
_mapper = mapper;
}
public async Task<List<Student>> GetStudent()
{
return await _studentRepository.Query();
}
[Caching(AbsoluteExpiration = 30)] //缓存秒数
public async Task<Student> GetStudentById(int id)
{
return await _studentRepository.QueryByID(id);
}
public async Task<StudentDto> GetStudentDetails(int id)
{
var student = await _studentRepository.QueryByID(id);
if (student != null)
{
var dto = _mapper.Map<StudentDto>(student);
dto.Birthday = "1987-01-01";
return dto;
}
else
{
return null;
}
}
}