#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, IStudentService { private readonly IStudentRepository _studentRepository; private readonly IMapper _mapper; public StudentService(IBaseRepository baseDal, IStudentRepository studentRepository, IMapper mapper) : base(baseDal) { _studentRepository = studentRepository; _mapper = mapper; } public async Task> GetStudent() { return await _studentRepository.Query(); } [Caching(AbsoluteExpiration = 30)] //缓存秒数 public async Task GetStudentById(int id) { return await _studentRepository.QueryByID(id); } public async Task GetStudentDetails(int id) { var student = await _studentRepository.QueryByID(id); if (student != null) { var dto = _mapper.Map(student); dto.Birthday = "1987-01-01"; return dto; } else { return null; } } }