ExamAnalysisDataDto.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\DTO;
  3. /**
  4. * 学情分析数据传输对象
  5. * 封装学情分析所需的所有数据
  6. */
  7. class ExamAnalysisDataDto
  8. {
  9. public function __construct(
  10. public readonly array $paper,
  11. public readonly array $student,
  12. public readonly array $teacher,
  13. public readonly array $questions,
  14. public readonly array $mastery,
  15. public readonly array $examHitKpCodes,
  16. public readonly array $parentMasteryLevels, // 新增:父节点掌握度数据
  17. public readonly array $insights,
  18. public readonly array $recommendations,
  19. public readonly array $rawAnalysisData = [],
  20. public readonly ?string $analysisId = null
  21. ) {}
  22. /**
  23. * 从数组创建DTO
  24. */
  25. public static function fromArray(array $data): self
  26. {
  27. return new self(
  28. paper: $data['paper'] ?? [],
  29. student: $data['student'] ?? [],
  30. teacher: $data['teacher'] ?? [],
  31. questions: $data['questions'] ?? [],
  32. mastery: $data['mastery'] ?? [],
  33. examHitKpCodes: $data['exam_hit_kp_codes'] ?? [],
  34. parentMasteryLevels: $data['parent_mastery_levels'] ?? [], // 新增:父节点掌握度数据
  35. insights: $data['insights'] ?? [],
  36. recommendations: $data['recommendations'] ?? [],
  37. rawAnalysisData: $data['analysis_data'] ?? [],
  38. analysisId: $data['analysis_id'] ?? $data['analysisId'] ?? null,
  39. );
  40. }
  41. /**
  42. * 转换为数组
  43. */
  44. public function toArray(): array
  45. {
  46. return [
  47. 'paper' => $this->paper,
  48. 'student' => $this->student,
  49. 'teacher' => $this->teacher,
  50. 'questions' => $this->questions,
  51. 'mastery' => $this->mastery,
  52. 'exam_hit_kp_codes' => $this->examHitKpCodes,
  53. 'parent_mastery_levels' => $this->parentMasteryLevels, // 新增:父节点掌握度数据
  54. 'insights' => $this->insights,
  55. 'recommendations' => $this->recommendations,
  56. 'analysis_data' => $this->rawAnalysisData,
  57. 'analysis_id' => $this->analysisId,
  58. ];
  59. }
  60. /**
  61. * 获取试卷信息
  62. */
  63. public function getPaperInfo(): array
  64. {
  65. return [
  66. 'id' => $this->paper['id'] ?? null,
  67. 'name' => $this->paper['name'] ?? '',
  68. 'total_questions' => $this->paper['total_questions'] ?? 0,
  69. 'total_score' => $this->paper['total_score'] ?? 0,
  70. ];
  71. }
  72. /**
  73. * 获取学生信息
  74. */
  75. public function getStudentInfo(): array
  76. {
  77. return [
  78. 'id' => $this->student['id'] ?? '',
  79. 'name' => $this->student['name'] ?? '',
  80. 'grade' => $this->student['grade'] ?? '',
  81. 'class' => $this->student['class'] ?? '',
  82. ];
  83. }
  84. /**
  85. * 获取整体掌握度
  86. */
  87. public function getOverallMastery(): float
  88. {
  89. return $this->mastery['average'] ?? 0.0;
  90. }
  91. /**
  92. * 获取薄弱知识点
  93. */
  94. public function getWeakKnowledgePoints(): array
  95. {
  96. return $this->mastery['weak_list'] ?? [];
  97. }
  98. /**
  99. * 获取题目数量
  100. */
  101. public function getQuestionCount(): int
  102. {
  103. return count($this->questions);
  104. }
  105. /**
  106. * 判断是否有分析数据
  107. */
  108. public function hasAnalysisData(): bool
  109. {
  110. return !empty($this->insights) || !empty($this->mastery['items']);
  111. }
  112. }