All checks were successful
continuous-integration/drone/push Build is passing
82 lines
2.5 KiB
C#
82 lines
2.5 KiB
C#
using MiAssessment.Core.Interfaces;
|
||
using MiAssessment.Model.Data;
|
||
using MiAssessment.Model.Models.Report;
|
||
using Microsoft.EntityFrameworkCore;
|
||
|
||
namespace MiAssessment.Api.Pages.Report;
|
||
|
||
/// <summary>
|
||
/// 学习的关键能力分析页 PageModel
|
||
/// 路由:/report/learning-abilities?recordId=3
|
||
/// CategoryType=5 的5种能力:学习专注力、学习思考力、学习转化力、学习记忆力、学习动机力
|
||
/// </summary>
|
||
public class LearningAbilitiesModel : ReportPageModelBase
|
||
{
|
||
/// <summary>
|
||
/// 能力列表(按 CategoryId 排序,雷达图用)
|
||
/// </summary>
|
||
public List<CategoryResultDataDto> Items { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// 按分数降序排列(柱状图用)
|
||
/// </summary>
|
||
public List<CategoryResultDataDto> ItemsByScore { get; set; } = new();
|
||
|
||
/// <summary>
|
||
/// 最弱能力名称
|
||
/// </summary>
|
||
public string WeakestName { get; set; } = "";
|
||
|
||
/// <summary>
|
||
/// 结论内容
|
||
/// </summary>
|
||
public string ConclusionContent { get; set; } = "";
|
||
|
||
private readonly MiAssessmentDbContext _dbContext;
|
||
|
||
public LearningAbilitiesModel(IReportDataService reportDataService, MiAssessmentDbContext dbContext)
|
||
: base(reportDataService)
|
||
{
|
||
_dbContext = dbContext;
|
||
}
|
||
|
||
protected override async Task OnDataLoadedAsync()
|
||
{
|
||
if (ReportData?.ResultsByType == null ||
|
||
!ReportData.ResultsByType.TryGetValue(5, out var allItems))
|
||
{
|
||
ErrorMessage = "缺少学习关键能力数据";
|
||
return;
|
||
}
|
||
|
||
Items = allItems.OrderBy(x => x.CategoryId).ToList();
|
||
|
||
if (Items.Count == 0)
|
||
{
|
||
ErrorMessage = "未找到学习关键能力数据";
|
||
return;
|
||
}
|
||
|
||
ItemsByScore = Items.OrderByDescending(x => x.Score).ToList();
|
||
|
||
// 加载最弱能力结论
|
||
var weakest = ItemsByScore.Last();
|
||
WeakestName = weakest.CategoryName;
|
||
|
||
if (ReportData.ConclusionsByCategory.TryGetValue(weakest.CategoryId, out var wc) && wc.Content != null)
|
||
{
|
||
ConclusionContent = wc.Content;
|
||
}
|
||
else
|
||
{
|
||
var template = await _dbContext.ReportConclusions
|
||
.AsNoTracking()
|
||
.FirstOrDefaultAsync(t =>
|
||
t.CategoryId == weakest.CategoryId &&
|
||
t.ConclusionType == 4 &&
|
||
!t.IsDeleted);
|
||
ConclusionContent = template?.Content ?? "";
|
||
}
|
||
}
|
||
}
|