2025-06-06 16:00:39 +08:00

130 lines
4.6 KiB
C#

using AutoMapper;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VOL.Business.IServices.Norm;
using VOL.Core.CacheManager;
using VOL.Core.Extensions.AutofacManager;
using VOL.Core.ManageUser;
using VOL.Entity.DomainModels;
using VOL.Entity.Enum;
using VOL.Model;
using VOL.System.IRepositories;
using VOL.System.Repositories;
namespace VOL.Business.IServices.LevelExam
{
public class LevelExamService : ILevelExamService, IDependency
{
#region
private readonly IMapper _mapper;
private readonly IN_SportsTestCategoryRepository _sportsTestCategoryRepository;
[ActivatorUtilitiesConstructor]
public LevelExamService(IMapper mapper,
IN_SportsTestCategoryRepository sportsTestCategoryRepository
)
{
_mapper = mapper;
_sportsTestCategoryRepository = sportsTestCategoryRepository;
}
#endregion
public async Task<PageDataDto<LevelExamListModel>> GetLevelExamPageList(LevelExamPageListParam paramDto)
{
var res = new PageDataDto<LevelExamListModel>();
var query = from s in _sportsTestCategoryRepository.DbContext.Set<Ai_LevelExamData>()
join t in _sportsTestCategoryRepository.DbContext.Set<S_Teacher>() on s.TeacherId equals t.Id into teacherGroup
from t in teacherGroup.DefaultIfEmpty()
join a in _sportsTestCategoryRepository.DbContext.Set<Ai_Special>() on s.SpecialId equals a.Id into specialGroup
from a in specialGroup.DefaultIfEmpty()
where s.SchoolCode == UserContext.Current.TenantId
select new LevelExamListModel()
{
StudentNo = s.StudentNo,
StudentName = s.StudentName != null ? s.StudentName : "",
AssessmentResults = s.AssessmentResults,
GradeId = s.GradeId,
ClassId = s.ClassId,
GradeAndClassName = $"{s.GradeName}-{s.ClassName}",
SpecialId = s.SpecialId,
SpecialName = a != null ? a.SpecialName : "",
Url = s.FileUrl,
StartTime = s.StartTime,
EndTime = s.EndTime,
TeacherName = t != null ? t.TeacherName : "",
Rank = s.Rank,
Results = s.AssessmentResults.Description()
};
if (!string.IsNullOrWhiteSpace(paramDto.StudentNo))
{
query = query.Where(x => x.StudentNo.Contains(paramDto.StudentNo));
}
if (!string.IsNullOrWhiteSpace(paramDto.StudentName))
{
query = query.Where(x => x.StudentName.Contains(paramDto.StudentName));
}
if (paramDto.ClassId > 0)
{
query = query.Where(x => x.ClassId == paramDto.ClassId);
}
if (paramDto.SpecialId > 0)
{
query = query.Where(x => x.SpecialId == paramDto.SpecialId);
}
if (paramDto.Rank.HasValue)
{
query = query.Where(x => (x.Rank - 1) == paramDto.Rank);
}
if (paramDto.AssessmentResults > 0)
{
query = query.Where(x => x.AssessmentResults == paramDto.AssessmentResults);
}
if (paramDto.StartTime.HasValue)
{
query = query.Where(x => x.StartTime >= paramDto.StartTime);
}
if (paramDto.EndTime.HasValue)
{
query = query.Where(x => x.EndTime <= paramDto.EndTime);
}
res.Total = await query.CountAsync();
var list = await query
.Skip((paramDto.PageIndex - 1) * paramDto.PageSize)
.Take(paramDto.PageSize)
.ToListAsync();
res.Datas = list;
return res;
}
public async Task<List<LevelExamSpecialModel>> GetLevelExamSpecialList()
{
var res = await _sportsTestCategoryRepository.DbContext.Set<Ai_Special>().Select(x => new LevelExamSpecialModel()
{
Id = x.Id,
SpecialName = x.SpecialName
}).ToListAsync();
return res;
}
}
}