129 lines
5.1 KiB
C#
129 lines
5.1 KiB
C#
![]() |
using AutoMapper;
|
|||
|
using AutoMapper.Internal;
|
|||
|
using Castle.DynamicProxy.Generators;
|
|||
|
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;
|
|||
|
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.School.Response;
|
|||
|
using VOL.System.IRepositories;
|
|||
|
|
|||
|
namespace VOL.Business.Services.Norm
|
|||
|
{
|
|||
|
public class CacheQueryService : ICacheQueryService, IDependency
|
|||
|
{
|
|||
|
#region 初始化
|
|||
|
private readonly ICacheService _cacheService;
|
|||
|
private readonly IMapper _mapper;
|
|||
|
private readonly IN_SportsTestResultRepository _sportsTestResultRepository;
|
|||
|
|
|||
|
[ActivatorUtilitiesConstructor]
|
|||
|
public CacheQueryService(IMapper mapper,
|
|||
|
IN_SportsTestResultRepository sportsTestResultRepository,
|
|||
|
ICacheService cacheService)
|
|||
|
{
|
|||
|
_mapper = mapper;
|
|||
|
_sportsTestResultRepository = sportsTestResultRepository;
|
|||
|
_cacheService = cacheService;
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取体测成绩缓存
|
|||
|
/// </summary>
|
|||
|
/// <param name="queryCondition">查询条件</param>
|
|||
|
/// <param name="modeType">模式</param>
|
|||
|
/// <returns></returns>
|
|||
|
public async Task<List<SportsTestValueModel>> GeSportsTestDataCacheAsync(Func<SportsTestValueModel, bool> queryCondition, Ai_ModeEnum? modeType)
|
|||
|
{
|
|||
|
var tenantId = UserContext.Current.TenantId;
|
|||
|
var cacheKey = $"sportsTestResults_{tenantId}";
|
|||
|
|
|||
|
// 从缓存中获取数据
|
|||
|
var sportsTestResults = _cacheService.Get<List<SportsTestValueModel>>(cacheKey);
|
|||
|
|
|||
|
if (sportsTestResults == null)
|
|||
|
{
|
|||
|
var iotTestResults = await _sportsTestResultRepository
|
|||
|
.FindAsIQueryable(x => x.IsDisplay && x.SchoolCode == tenantId)
|
|||
|
.ToListAsync();
|
|||
|
var sportsIot = _mapper.Map<List<SportsTestValueModel>>(iotTestResults);
|
|||
|
|
|||
|
var aiTestResults = await _sportsTestResultRepository.DbContext.Set<Ai_SportsTestData>
|
|||
|
().Where(x => x.IsDisplay && x.SchoolCode == tenantId && x.DataType == SportsTestDataType.SportsTestData)
|
|||
|
.ToListAsync();
|
|||
|
var sportsAi = _mapper.Map<List<SportsTestValueModel>>(aiTestResults);
|
|||
|
|
|||
|
sportsTestResults = sportsIot.Concat(sportsAi).ToList();
|
|||
|
|
|||
|
sportsTestResults = sportsTestResults
|
|||
|
.GroupBy(x => new { x.StudentNo, x.CategoryValue })
|
|||
|
.Select(g =>
|
|||
|
{
|
|||
|
var latestRecord = g.OrderByDescending(x => x.ScoreTime).First();
|
|||
|
|
|||
|
latestRecord.Score = g.Average(x => x.Score);
|
|||
|
latestRecord.Value = g.Average(x => x.Value);
|
|||
|
latestRecord.MotionDuration = g.Sum(x => x.MotionDuration);
|
|||
|
|
|||
|
//添加其他需要聚合运算的字段
|
|||
|
|
|||
|
return latestRecord;
|
|||
|
})
|
|||
|
.ToList();
|
|||
|
|
|||
|
// 将结果添加到缓存,缓存时间为600秒
|
|||
|
_cacheService.AddObject(cacheKey, sportsTestResults, 3600);
|
|||
|
}
|
|||
|
|
|||
|
sportsTestResults = sportsTestResults.Where(x => queryCondition(x)).ToList();
|
|||
|
|
|||
|
// 自由模式 体测项目
|
|||
|
if (modeType != null && modeType == Ai_ModeEnum.FreeMode)
|
|||
|
{
|
|||
|
var freeModeItemTypeList = new List<int>()
|
|||
|
{
|
|||
|
(int)SportsTestItemType.Sit_And_Reach,
|
|||
|
(int)SportsTestItemType.OneMinuteJumpRope,
|
|||
|
(int)SportsTestItemType.One_Minute_Sit_Up,
|
|||
|
(int)SportsTestItemType.Pull_Up,
|
|||
|
};
|
|||
|
sportsTestResults = sportsTestResults.Where(x => freeModeItemTypeList.Contains(x.CategoryValue)).ToList();
|
|||
|
}
|
|||
|
/*
|
|||
|
// 课堂模式 体测项目
|
|||
|
else if (modeType != null && modeType == Ai_ModeEnum.ClassRoomMode)
|
|||
|
{
|
|||
|
var classRoomModeItemTypeList = new List<int>()
|
|||
|
{
|
|||
|
(int)SportsTestItemType.BMI,
|
|||
|
(int)SportsTestItemType.VitalCapacity,
|
|||
|
(int)SportsTestItemType.MeterRun_50,
|
|||
|
(int)SportsTestItemType.ShuttleRun_50x8,
|
|||
|
(int)SportsTestItemType.MeterRun_1000,
|
|||
|
(int)SportsTestItemType.MeterRun_800,
|
|||
|
// 立定跳远
|
|||
|
(int)SportsTestItemType.StandingLongJump,
|
|||
|
// AI 和 IOT 共有项目
|
|||
|
(int)SportsTestItemType.Sit_And_Reach,
|
|||
|
(int)SportsTestItemType.OneMinuteJumpRope,
|
|||
|
(int)SportsTestItemType.One_Minute_Sit_Up,
|
|||
|
(int)SportsTestItemType.Pull_Up,
|
|||
|
};
|
|||
|
}
|
|||
|
*/
|
|||
|
return sportsTestResults;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|