pdf-report.blade.php 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752
  1. @php
  2. // 提取15位paper_id数字部分作为学案编号
  3. $rawPaperId = $paper['id'] ?? $paper['paper_id'] ?? 'unknown';
  4. preg_match('/paper_(\d{15})/', $rawPaperId, $matches);
  5. $reportCode = $matches[1] ?? preg_replace('/[^0-9]/', '', $rawPaperId);
  6. $averageMastery = isset($mastery['average']) ? number_format($mastery['average'] * 100, 1) . '%' : '无数据';
  7. // 【修复】从insights中获取AI分析结果(而不是从analysis_data)
  8. $questionAnalysis = $insights ?? [];
  9. // 生成时间(格式:2026年01月30日 15:04:05)
  10. $generateDateTime = now()->format('Y年m月d日 H:i:s');
  11. @endphp
  12. <!DOCTYPE html>
  13. <html lang="zh-CN">
  14. <head>
  15. <meta charset="UTF-8">
  16. <title>学情报告 - {{ $paper['name'] ?? '试卷' }}</title>
  17. <link rel="stylesheet" href="/css/katex/katex.min.css">
  18. <style>
  19. @page {
  20. size: A4;
  21. margin: 2.2cm 2cm 2.3cm 2cm;
  22. @top-left {
  23. content: "知了数学·{{ $generateDateTime }}";
  24. font-size: 13px;
  25. color: #666;
  26. }
  27. @top-center {
  28. content: "{{ $student['name'] ?? '-' }}";
  29. font-size: 13px;
  30. color: #666;
  31. }
  32. @top-right {
  33. content: "{{ $reportCode }}";
  34. font-size: 19px;
  35. font-weight: 600;
  36. font-family: "Noto Sans", "Liberation Sans", "Nimbus Sans", sans-serif;
  37. letter-spacing: 0;
  38. padding-right: 3mm;
  39. padding-top: 1.8mm;
  40. color: #222;
  41. }
  42. @bottom-left {
  43. content: "{{ $reportCode }}";
  44. font-size: 11px;
  45. color: #666;
  46. }
  47. @bottom-right {
  48. content: counter(page) "/" counter(pages);
  49. font-size: 13px;
  50. color: #666;
  51. }
  52. }
  53. * { box-sizing: border-box; }
  54. body {
  55. font-family: "SimSun", "Songti SC", serif;
  56. margin: 0;
  57. padding: 0;
  58. color: #000;
  59. background: #fff;
  60. font-size: 12px;
  61. line-height: 1.6;
  62. }
  63. h1, h2, h3 { margin: 0; color: #000; }
  64. .card { background: #fff; border: 1px solid #e5e7eb; border-radius: 8px; padding: 12px 16px; margin-bottom: 12px; box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04); break-inside: auto; page-break-inside: auto; }
  65. .header { text-align: center; margin-bottom: 1.5rem; border-bottom: 2px solid #000; padding-bottom: 1rem; }
  66. .paper-title { font-size: 22px; font-weight: bold; margin-bottom: 14px; }
  67. .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
  68. .tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; color: #374151; background: #e5e7eb; }
  69. .section-title { font-size: 16px; margin-bottom: 10px; display: flex; align-items: center; gap: 8px; }
  70. .pill { padding: 4px 10px; border-radius: 999px; font-size: 12px; }
  71. .pill.green { background: #ecfdf3; color: #15803d; }
  72. .pill.amber { background: #fef3c7; color: #b45309; }
  73. .pill.red { background: #fef2f2; color: #b91c1c; }
  74. table { width: 100%; border-collapse: collapse; font-size: 13px; }
  75. th, td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; text-align: left; vertical-align: top; }
  76. th { background: #f3f4f6; color: #111827; }
  77. .muted { color: #6b7280; font-size: 12px; }
  78. .progress-wrap { background: #f3f4f6; border-radius: 999px; overflow: hidden; height: 10px; }
  79. .progress-bar { height: 100%; background: linear-gradient(90deg, #4f46e5, #10b981); }
  80. .recommend-card { border: 1px dashed #cbd5e1; border-radius: 10px; padding: 10px 12px; margin-bottom: 8px; background: #f8fafc; }
  81. .relation-board { margin: 6px 0 10px; break-inside: auto; page-break-inside: auto; }
  82. .relation-block { margin-bottom: 10px; padding: 8px; border: 1px solid #dbeafe; border-radius: 8px; background: #fff; break-inside: auto; page-break-inside: auto; }
  83. .relation-row { display: flex; align-items: flex-start; gap: 10px; }
  84. .tree-cards { width: 100%; border-collapse: collapse; table-layout: fixed; }
  85. .tree-cards td { border: none; padding: 0; vertical-align: top; }
  86. .tree-left { width: 45%; flex: 0 0 45%; padding-right: 10px; }
  87. .tree-right { width: 55%; flex: 1; padding-left: 10px; }
  88. .tree-parent {
  89. display: inline-block;
  90. margin-bottom: 6px;
  91. padding: 4px 8px;
  92. border-radius: 999px;
  93. border: 1px solid #93c5fd;
  94. background: #dbeafe;
  95. color: #1e3a8a;
  96. font-weight: 700;
  97. font-size: 12px;
  98. }
  99. .tree-lines { margin: 0; padding-left: 14px; border-left: 2px solid #cbd5e1; }
  100. .tree-line {
  101. font-size: 11px;
  102. color: #334155;
  103. margin-bottom: 3px;
  104. white-space: normal;
  105. overflow: visible;
  106. text-overflow: clip;
  107. word-break: break-all;
  108. line-height: 1.45;
  109. }
  110. .tree-line.hit { font-weight: 600; color: #1e40af; }
  111. .tree-line-badge { display: inline-block; margin-left: 6px; padding: 1px 5px; border-radius: 999px; font-size: 10px; border: 1px solid transparent; }
  112. .tree-line-badge.high,
  113. .tree-line-badge.mid,
  114. .tree-line-badge.low,
  115. .tree-line-badge.miss { background: #f8fafc; color: #64748b; border-color: #cbd5e1; }
  116. .detail-card {
  117. border: 1px solid #e2e8f0;
  118. border-radius: 6px;
  119. background: #f8fafc;
  120. padding: 6px 8px;
  121. margin-bottom: 5px;
  122. break-inside: auto;
  123. page-break-inside: auto;
  124. }
  125. .detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
  126. .detail-title { font-size: 11px; color: #0f172a; font-weight: 700; margin-bottom: 2px; }
  127. .detail-meta { font-size: 11px; color: #475569; margin-top: 3px; }
  128. .detail-mastery { font-size: 38px; color: #0f172a; font-weight: 700; line-height: 1; margin: 0; }
  129. .detail-mastery.high { color: #16a34a; }
  130. .detail-mastery.mid { color: #d97706; }
  131. .detail-mastery.low { color: #dc2626; }
  132. .node-tags { margin-top: 2px; }
  133. .node-tag {
  134. display: inline-block;
  135. margin: 0 6px 6px 0;
  136. padding: 1px 7px;
  137. border-radius: 999px;
  138. font-size: 10px;
  139. line-height: 1.4;
  140. color: #475569;
  141. background: #f1f5f9;
  142. border: 1px solid #cbd5e1;
  143. }
  144. .suggest-tags { display: inline; }
  145. .suggest-tag {
  146. display: inline-block;
  147. margin: 0 6px 6px 0;
  148. padding: 1px 7px;
  149. border-radius: 999px;
  150. font-size: 10px;
  151. line-height: 1.4;
  152. color: #334155;
  153. background: #f8fafc;
  154. border: 1px solid #d1d5db;
  155. }
  156. .weak-kp-tags { margin-top: 6px; }
  157. .weak-kp-tag {
  158. display: inline-block;
  159. margin: 0 6px 6px 0;
  160. padding: 1px 7px;
  161. border-radius: 999px;
  162. font-size: 10px;
  163. line-height: 1.45;
  164. color: #854d0e;
  165. background: #fef3c7;
  166. border: 1px solid #fcd34d;
  167. }
  168. .error-kp-tag {
  169. display: inline-block;
  170. margin: 0 6px 6px 0;
  171. padding: 1px 7px;
  172. border-radius: 999px;
  173. font-size: 10px;
  174. line-height: 1.45;
  175. color: #334155;
  176. background: #f8fafc;
  177. border: 1px solid #d1d5db;
  178. }
  179. .error-kp-tag.high-risk {
  180. color: #b91c1c;
  181. border-color: #fca5a5;
  182. background: #fff;
  183. font-weight: 600;
  184. }
  185. .detail-change-up { color: #16a34a; font-weight: 700; }
  186. .detail-change-down { color: #dc2626; font-weight: 700; }
  187. .aggregate-tip { font-size: 11px; color: #475569; margin-top: 6px; }
  188. .question-card { border:1px solid #e5e7eb; border-radius:8px; padding:6px 9px; margin-bottom:5px; background:#fff; page-break-inside: auto; break-inside: auto; }
  189. .question-block { margin-bottom: 5px; padding: 5px; border-radius: 4px; page-break-inside: auto; break-inside: auto; }
  190. .question-card,
  191. .question-card .math-content,
  192. .question-card .solution-content {
  193. font-size: 12px;
  194. line-height: 1.7;
  195. }
  196. .question-card .math-content img,
  197. .question-card img {
  198. max-width: 100% !important;
  199. width: auto !important;
  200. height: auto !important;
  201. object-fit: contain;
  202. display: block;
  203. margin: 6px auto;
  204. }
  205. .solution-content {
  206. display: block;
  207. line-height: 1.75;
  208. white-space: normal;
  209. word-break: break-word;
  210. overflow-wrap: anywhere;
  211. page-break-inside: auto;
  212. break-inside: auto;
  213. }
  214. </style>
  215. </head>
  216. <body>
  217. <div class="page">
  218. <div class="header">
  219. <h1 class="paper-title">学情分析报告</h1>
  220. @php
  221. $teacherName = trim((string) ($teacher['name'] ?? ''));
  222. $showTeacher = $teacherName !== '' && $teacherName !== '________' && $teacherName !== '未知老师';
  223. @endphp
  224. <div style="display:flex;justify-content:space-between;font-size:14px;margin-top:8px;">
  225. @if($showTeacher)
  226. <span>老师:{{ $teacherName }}</span>
  227. @endif
  228. <span>年级:@formatGrade($student['grade'] ?? '________')</span>
  229. @if(!empty($paper['assemble_type_label']) && $paper['assemble_type_label'] !== '未知类型')
  230. <span>类型:{{ $paper['assemble_type_label'] }}</span>
  231. @endif
  232. <span>姓名:{{ $student['name'] ?? '________' }}</span>
  233. <span>题目数:{{ $paper['total_questions'] ?? (is_array($questions ?? null) ? count($questions) : '-') }}</span>
  234. </div>
  235. </div>
  236. <div class="card">
  237. <div class="section-title">本次命中子知识点掌握度</div>
  238. @php
  239. // 严格口径:顶部列表来自“本卷题目关联知识点”
  240. $hitCodes = array_values(array_unique(array_filter($exam_hit_kp_codes ?? [])));
  241. $masteryByCode = [];
  242. $questionKpNameMap = [];
  243. foreach (($questions ?? []) as $q) {
  244. $code = trim((string) ($q['knowledge_point'] ?? ''));
  245. $name = trim((string) ($q['knowledge_point_name'] ?? ''));
  246. if ($code !== '' && $name !== '') {
  247. $questionKpNameMap[$code] = $name;
  248. }
  249. }
  250. foreach (($mastery['items'] ?? []) as $item) {
  251. $code = (string) ($item['kp_code'] ?? '');
  252. if ($code !== '') {
  253. $masteryByCode[$code] = $item;
  254. }
  255. }
  256. $filteredMasteryItems = [];
  257. foreach ($hitCodes as $kpCode) {
  258. if (in_array($kpCode, ['K-GENERAL', 'GENERAL', 'DEFAULT'])) {
  259. continue;
  260. }
  261. $base = $masteryByCode[$kpCode] ?? null;
  262. $filteredMasteryItems[] = [
  263. 'kp_code' => $kpCode,
  264. 'kp_name' => $questionKpNameMap[$kpCode] ?? ($base['kp_name'] ?? $kpCode),
  265. 'mastery_level' => floatval($base['mastery_level'] ?? 0),
  266. 'mastery_change' => $base['mastery_change'] ?? null,
  267. 'is_hit' => true,
  268. ];
  269. }
  270. @endphp
  271. @if(!empty($filteredMasteryItems))
  272. @foreach($filteredMasteryItems as $item)
  273. @php
  274. $pct = min(100, max(0, ($item['mastery_level'] ?? 0) * 100));
  275. $barColor = $pct >= 80 ? '#10b981' : ($pct >= 60 ? '#f59e0b' : '#ef4444');
  276. $delta = $item['mastery_change'] ?? null;
  277. $isHitItem = !empty($item['is_hit']);
  278. // 只有当有变化值时才显示变化信息
  279. $changeText = '';
  280. if ($delta !== null && $delta !== '' && abs($delta) > 0.001) {
  281. $changeText = ($delta > 0 ? '↑ ' : '↓ ') . number_format(abs($delta) * 100, 1) . '%';
  282. }
  283. @endphp
  284. <div style="margin-bottom:12px; padding: 8px; border: 1px solid #e5e7eb; border-radius: 6px;">
  285. <div style="display:flex; justify-content:space-between; align-items:center; margin-bottom: 6px;">
  286. <div style="font-weight: 600; font-size: 13px;">{{ $item['kp_name'] ?? $item['kp_code'] ?? '未知知识点' }}</div>
  287. <div style="font-weight: 600; color: {{ $barColor }}; font-size: 13px;">
  288. {{ number_format($pct, 1) }}%
  289. <span style="margin-left: 8px; color: #666; font-size: 11px;">{{ $changeText ? '子节点变化 ' . $changeText : '' }}</span>
  290. </div>
  291. </div>
  292. <div class="progress-wrap" style="height: 12px;">
  293. <div class="progress-bar" style="width: {{ $pct }}%; background: {{ $barColor }};"></div>
  294. </div>
  295. </div>
  296. @endforeach
  297. @else
  298. <div class="muted">暂无有效掌握度数据(已过滤通用知识点)</div>
  299. @endif
  300. </div>
  301. <div class="card">
  302. <div class="section-title">📊 知识点层级掌握度分析</div>
  303. @php
  304. $parentMasteryLevels = $parent_mastery_levels ?? [];
  305. $hasParentMastery = !empty($parentMasteryLevels);
  306. $childMasteryMap = [];
  307. foreach (($filteredMasteryItems ?? []) as $it) {
  308. $childMasteryMap[$it['kp_code']] = [
  309. 'level' => floatval($it['mastery_level'] ?? 0),
  310. 'delta' => isset($it['mastery_change']) ? floatval($it['mastery_change']) : null,
  311. ];
  312. }
  313. @endphp
  314. @if($hasParentMastery)
  315. <div class="relation-board">
  316. <div style="font-size:12px; color:#334155; margin-bottom:6px; font-weight:600;">父子知识点关系</div>
  317. @foreach($parentMasteryLevels as $parentData)
  318. @php
  319. $childrenAll = $parentData['children_all'] ?? [];
  320. $children = $parentData['children'] ?? []; // 命中子节点
  321. $childCount = count($childrenAll);
  322. $hitCount = count($children);
  323. $hitAvg = $parentData['children_hit_avg_mastery'] ?? null;
  324. $parentPct = number_format(floatval($parentData['mastery_percentage'] ?? 0), 1);
  325. $parentLevel = floatval($parentData['mastery_level'] ?? 0);
  326. $parentClass = $parentLevel >= 0.8 ? 'high' : ($parentLevel >= 0.6 ? 'mid' : 'low');
  327. $delta = $parentData['mastery_change'] ?? null;
  328. $hitNames = array_values(array_map(fn($c) => $c['kp_name'] ?? ($c['kp_code'] ?? ''), $children));
  329. $allChildrenPerfect = !empty($childrenAll) && count(array_filter($childrenAll, function ($c) {
  330. return floatval($c['mastery_level'] ?? 0) >= 0.999;
  331. })) === count($childrenAll);
  332. @endphp
  333. <div class="relation-block">
  334. <div class="relation-row">
  335. <div class="tree-left">
  336. <div class="tree-parent">{{ $parentData['kp_name'] ?? $parentData['kp_code'] }}</div>
  337. @if(!empty($childrenAll))
  338. <div class="tree-lines">
  339. @foreach($childrenAll as $child)
  340. @php
  341. $isHit = !empty($child['is_hit']);
  342. $m = floatval($child['mastery_level'] ?? 0);
  343. $badgeClass = $m >= 0.8 ? 'high' : ($m >= 0.6 ? 'mid' : ($m > 0 ? 'low' : 'miss'));
  344. $badgeText = number_format($m * 100, 1) . '%';
  345. @endphp
  346. <div class="tree-line {{ $isHit ? 'hit' : '' }}">
  347. └─ {{ $child['kp_name'] }}
  348. <span class="tree-line-badge {{ $badgeClass }}">{{ $badgeText }}</span>
  349. </div>
  350. @endforeach
  351. </div>
  352. @else
  353. <div class="muted">无命中子知识点</div>
  354. @endif
  355. </div>
  356. <div class="tree-right">
  357. <div class="detail-card">
  358. <div class="detail-head">
  359. <div class="detail-title">{{ $parentData['kp_name'] ?? $parentData['kp_code'] }}</div>
  360. <div class="detail-mastery {{ $parentClass }}">{{ $parentPct }}%</div>
  361. </div>
  362. <div class="detail-meta">
  363. 父节点变化:
  364. @if($delta !== null)
  365. <span class="{{ $delta >= 0 ? 'detail-change-up' : 'detail-change-down' }}">
  366. {{ $delta >= 0 ? '↑ ' : '↓ ' }}{{ number_format(abs($delta) * 100, 1) }}%
  367. </span>
  368. @else
  369. -
  370. @endif
  371. </div>
  372. <div class="detail-meta" style="margin-top: 3px;">
  373. 本次重点子节点:
  374. @if($hitCount > 0)
  375. <span class="node-tags">
  376. @foreach($hitNames as $hitName)
  377. @if(!empty(trim($hitName)))
  378. <span class="node-tag">{{ $hitName }}</span>
  379. @endif
  380. @endforeach
  381. </span>
  382. @else
  383. @endif
  384. </div>
  385. <div class="detail-meta">
  386. 子节点总数 {{ $childCount }} 个,本次命中 {{ $hitCount }} 个,命中均值 {{ $hitAvg !== null ? number_format(floatval($hitAvg) * 100, 1) . '%' : '-' }}(命中表示本次覆盖,不等于已掌握)
  387. </div>
  388. </div>
  389. </div>
  390. </div>
  391. </div>
  392. @endforeach
  393. </div>
  394. @php
  395. $allParentPerfect = !empty($parentMasteryLevels) && count(array_filter($parentMasteryLevels, function ($p) {
  396. return floatval($p['mastery_level'] ?? 0) >= 0.999;
  397. })) === count($parentMasteryLevels);
  398. $allHitChildrenPerfect = !empty($filteredMasteryItems) && count(array_filter($filteredMasteryItems, function ($it) {
  399. return floatval($it['mastery_level'] ?? 0) >= 0.999;
  400. })) === count($filteredMasteryItems);
  401. $isAllPerfect = $allParentPerfect && $allHitChildrenPerfect;
  402. // 1) 优先:本次命中子知识点中的低掌握度(<60%)
  403. $hitWeakChildren = [];
  404. $hitWeakKeys = [];
  405. foreach (($filteredMasteryItems ?? []) as $hitItem) {
  406. $level = floatval($hitItem['mastery_level'] ?? 0);
  407. $name = trim((string) ($hitItem['kp_name'] ?? $hitItem['kp_code'] ?? ''));
  408. if ($name === '' || $level >= 0.6) {
  409. continue;
  410. }
  411. $key = (string) ($hitItem['kp_code'] ?? $name);
  412. $hitWeakChildren[$key] = [
  413. 'name' => $name,
  414. 'level' => $level,
  415. ];
  416. $hitWeakKeys[$key] = true;
  417. }
  418. $hitWeakChildren = array_values($hitWeakChildren);
  419. usort($hitWeakChildren, function ($a, $b) {
  420. return $a['level'] <=> $b['level'];
  421. });
  422. // 2) 兜底:若命中子知识点都 >=60%,再从其他低掌握度子知识点补
  423. $otherWeakChildren = [];
  424. foreach (($parentMasteryLevels ?? []) as $pData) {
  425. foreach (($pData['children_all'] ?? []) as $child) {
  426. $level = floatval($child['mastery_level'] ?? 0);
  427. $name = trim((string) ($child['kp_name'] ?? $child['kp_code'] ?? ''));
  428. if ($name === '' || $level >= 0.6) {
  429. continue;
  430. }
  431. $key = ($child['kp_code'] ?? $name);
  432. if (isset($hitWeakKeys[$key])) {
  433. continue;
  434. }
  435. $otherWeakChildren[$key] = [
  436. 'name' => $name,
  437. 'level' => $level,
  438. ];
  439. }
  440. }
  441. $otherWeakChildren = array_values($otherWeakChildren);
  442. usort($otherWeakChildren, function ($a, $b) {
  443. return $a['level'] <=> $b['level'];
  444. });
  445. // 3) 最终展示:总数不超过5
  446. $globalWeakChildren = [];
  447. if (!empty($hitWeakChildren)) {
  448. $globalWeakChildren = array_slice($hitWeakChildren, 0, 5);
  449. } else {
  450. $globalWeakChildren = array_slice($otherWeakChildren, 0, 5);
  451. }
  452. @endphp
  453. <div style="margin-top: 12px; padding: 8px; background: #fefce8; border-left: 4px solid #eab308; border-radius: 4px;">
  454. <div style="font-size: 12px; color: #854d0e; line-height: 1.6;">
  455. <strong>学习建议:</strong>
  456. @if($isAllPerfect)
  457. 本次学案表现非常出色,相关知识点掌握稳定且完整。建议继续进入新的知识点专题学习,优先选择同层级未覆盖内容或更高难度综合题,保持进阶节奏。
  458. @else
  459. 建议重点关注掌握度较低的知识点,通过专项练习提升整体学习水平。优先练习掌握度低于60%的知识点。
  460. @endif
  461. @if(!empty($globalWeakChildren))
  462. <div class="weak-kp-tags">
  463. @foreach($globalWeakChildren as $weakChild)
  464. <span class="weak-kp-tag">{{ $weakChild['name'] }}({{ number_format($weakChild['level'] * 100, 1) }}%)</span>
  465. @endforeach
  466. </div>
  467. @endif
  468. </div>
  469. </div>
  470. @else
  471. <div class="muted">暂无父节点掌握度数据</div>
  472. <div style="margin-top: 8px; font-size: 12px; color: #64748b;">
  473. 当前分析主要基于具体知识点掌握度。完整的层级掌握度分析需要在系统中建立完整的知识点层级关系。
  474. </div>
  475. @endif
  476. </div>
  477. @php
  478. $insightMap = [];
  479. foreach (($question_insights ?? []) as $insight) {
  480. $no = $insight['question_number'] ?? $insight['question_id'] ?? null;
  481. if ($no !== null) {
  482. $insightMap[$no] = $insight;
  483. }
  484. }
  485. $analysisWrongMap = [];
  486. foreach (($analysis_data['question_analysis'] ?? []) as $qa) {
  487. $qid = $qa['question_bank_id'] ?? $qa['question_id'] ?? null;
  488. if ($qid === null || $qid === '') {
  489. continue;
  490. }
  491. $rawCorrect = $qa['is_correct'] ?? null;
  492. $isWrongFromAnalysis = false;
  493. if (is_array($rawCorrect)) {
  494. $isWrongFromAnalysis = in_array(0, $rawCorrect, true);
  495. } elseif ($rawCorrect !== null) {
  496. $isWrongFromAnalysis = !boolval($rawCorrect);
  497. }
  498. if ($isWrongFromAnalysis) {
  499. $analysisWrongMap[(string)$qid] = true;
  500. }
  501. }
  502. $wrongQuestions = [];
  503. foreach (($questions ?? []) as $qItem) {
  504. $studentAnswerProbe = $qItem['student_answer'] ?? null;
  505. $correctAnswerProbe = $qItem['answer'] ?? ($qItem['correct_answer'] ?? null);
  506. $isCorrectProbe = $qItem['is_correct'] ?? null;
  507. if ($isCorrectProbe === null && !empty($studentAnswerProbe) && !empty($correctAnswerProbe)) {
  508. $isCorrectProbe = (trim((string)$studentAnswerProbe) === trim((string)$correctAnswerProbe)) ? 1 : 0;
  509. }
  510. $normalizedCorrect = $isCorrectProbe;
  511. if ($isCorrectProbe !== null) {
  512. $normalizedCorrect = is_bool($isCorrectProbe) ? ($isCorrectProbe ? 1 : 0) : intval($isCorrectProbe);
  513. }
  514. $qidProbe = (string)($qItem['question_bank_id'] ?? $qItem['question_id'] ?? '');
  515. $isWrongByAnalysis = ($qidProbe !== '' && isset($analysisWrongMap[$qidProbe]));
  516. if ($normalizedCorrect === 0 || $isWrongByAnalysis) {
  517. $wrongQuestions[] = $qItem;
  518. }
  519. }
  520. // 错题知识点聚合统计(同知识点错几题/共几题)
  521. $kpStats = [];
  522. foreach (($questions ?? []) as $qItem) {
  523. $kpName = trim((string)($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  524. if ($kpName === '') {
  525. $kpName = '未标注知识点';
  526. }
  527. if (!isset($kpStats[$kpName])) {
  528. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  529. }
  530. $kpStats[$kpName]['total']++;
  531. }
  532. foreach ($wrongQuestions as $qItem) {
  533. $kpName = trim((string)($qItem['knowledge_point_name'] ?? $qItem['knowledge_point'] ?? '未标注知识点'));
  534. if ($kpName === '') {
  535. $kpName = '未标注知识点';
  536. }
  537. if (!isset($kpStats[$kpName])) {
  538. $kpStats[$kpName] = ['total' => 0, 'wrong' => 0];
  539. }
  540. $kpStats[$kpName]['wrong']++;
  541. }
  542. $kpWrongStats = [];
  543. foreach ($kpStats as $kpName => $stat) {
  544. if (($stat['wrong'] ?? 0) <= 0) {
  545. continue;
  546. }
  547. $total = max(1, intval($stat['total'] ?? 0));
  548. $wrong = intval($stat['wrong'] ?? 0);
  549. $kpWrongStats[] = [
  550. 'kp_name' => $kpName,
  551. 'wrong' => $wrong,
  552. 'total' => $total,
  553. 'rate' => $wrong / $total,
  554. ];
  555. }
  556. usort($kpWrongStats, function ($a, $b) {
  557. if ($a['rate'] === $b['rate']) {
  558. return $b['wrong'] <=> $a['wrong'];
  559. }
  560. return $b['rate'] <=> $a['rate'];
  561. });
  562. @endphp
  563. @if(!empty($wrongQuestions))
  564. <div class="card">
  565. <div class="section-title">错题列表</div>
  566. @if(!empty($kpWrongStats))
  567. <div style="margin-bottom:8px; padding:8px; border:1px solid #e5e7eb; border-radius:6px; background:#f8fafc;">
  568. <div style="font-size:12px; font-weight:600; color:#111827; margin-bottom:6px;">知识点错误率</div>
  569. <div style="font-size:12px; color:#475569; line-height:1.7;">
  570. @foreach($kpWrongStats as $item)
  571. <span class="error-kp-tag {{ $item['rate'] > 0.5 ? 'high-risk' : '' }}">{{ $item['kp_name'] }}:{{ $item['wrong'] }}/{{ $item['total'] }}({{ number_format($item['rate'] * 100, 1) }}%)</span>
  572. @endforeach
  573. </div>
  574. </div>
  575. @endif
  576. @foreach($wrongQuestions as $q)
  577. @php
  578. // 【修复】从题目数据中获取学生答案、正确答案和判分结果
  579. $studentAnswer = $q['student_answer'] ?? $q['student_answer'] ?? null;
  580. $correctAnswer = $q['answer'] ?? $q['correct_answer'] ?? null;
  581. $isCorrect = $q['is_correct'] ?? null; // 1=正确,0=错误,null=未判
  582. // 如果未判分但有学生答案和正确答案,自动比较判断
  583. if ($isCorrect === null && !empty($studentAnswer) && !empty($correctAnswer)) {
  584. $isCorrect = (trim($studentAnswer) === trim($correctAnswer)) ? 1 : 0;
  585. }
  586. // 判分状态显示逻辑
  587. $statusText = '';
  588. $statusColor = '';
  589. if ($isCorrect === 1) {
  590. $statusText = '正确';
  591. $statusColor = '#10b981';
  592. } elseif ($isCorrect === 0) {
  593. $statusText = '错误';
  594. $statusColor = '#ef4444';
  595. }
  596. $showStatus = $statusText !== '';
  597. $insight = $insightMap[$q['question_number']] ?? ($insightMap[$q['display_number'] ?? null] ?? []);
  598. // 【修复】得分显示:答错显示实际得分,答对显示满分
  599. $fullScore = $insight['full_score'] ?? ($q['score'] ?? null);
  600. if ($isCorrect === 1) {
  601. // 答对了,显示满分
  602. $score = $fullScore;
  603. } elseif ($isCorrect === 0) {
  604. // 答错了,显示实际得分(可能为0分或其他分数)
  605. $score = $q['score_obtained'] ?? 0;
  606. } else {
  607. // 未判分或未答题,不显示得分
  608. $score = null;
  609. }
  610. $analysisRaw = $insight['analysis']
  611. ?? $insight['thinking_process']
  612. ?? $insight['feedback']
  613. ?? $insight['suggestions']
  614. ?? $insight['reason']
  615. ?? ($insight['correct_solution'] ?? null);
  616. // 若有下一步建议,追加
  617. if (empty($analysisRaw) && !empty($insight['next_steps'])) {
  618. $analysisRaw = '后续建议:' . (is_array($insight['next_steps']) ? implode(';', $insight['next_steps']) : $insight['next_steps']);
  619. }
  620. $analysis = is_array($analysisRaw) ? json_encode($analysisRaw, JSON_UNESCAPED_UNICODE) : $analysisRaw;
  621. if ($analysis === null || $analysis === '') {
  622. $analysis = '暂无解题思路,待补充';
  623. }
  624. $formatSolutionLikeGrading = function ($text) {
  625. if (!is_string($text) || trim($text) === '') {
  626. return $text;
  627. }
  628. $normalized = preg_replace('/\s*;\s*步骤\s*(\d+)/u', ";\n步骤$1", $text);
  629. $normalized = preg_replace('/\s*。\s*步骤\s*(\d+)/u', "。\n步骤$1", $normalized);
  630. $normalized = preg_replace('/(?<!^)(步骤\s*\d+\s*[::])/u', "\n$1", $normalized);
  631. $normalized = preg_replace('/(?<!^)(第\s*\d+\s*步\s*[::]?)/u', "\n$1", $normalized);
  632. $normalized = preg_replace('/\n{3,}/u', "\n\n", $normalized);
  633. // 去掉每行左侧缩进空白,避免出现“左边空好几个字符”
  634. $normalized = preg_replace('/^[\h\x{3000}]+/mu', '', $normalized);
  635. return trim($normalized);
  636. };
  637. $stepsRaw = $insight['steps'] ?? $insight['solution_steps'] ?? $insight['analysis_steps'] ?? null;
  638. $steps = [];
  639. if (is_array($stepsRaw)) {
  640. $steps = $stepsRaw;
  641. } elseif (is_string($stepsRaw) && trim($stepsRaw) !== '') {
  642. $steps = preg_split('/[\r\n]+/', trim($stepsRaw));
  643. }
  644. $typeMap = ['choice' => '选择题', 'fill' => '填空题', 'answer' => '解答题'];
  645. $typeLabel = $typeMap[$q['question_type'] ?? ''] ?? ($q['question_type'] ?? '题型未标注');
  646. $questionText = is_string($q['question_text']) ? $q['question_text'] : json_encode($q['question_text'], JSON_UNESCAPED_UNICODE);
  647. $solution = $q['solution'] ?? null;
  648. $solution = $formatSolutionLikeGrading($solution);
  649. $analysis = $formatSolutionLikeGrading($analysis);
  650. @endphp
  651. <div class="question-card">
  652. <div style="display:flex; justify-content:space-between; align-items:center; gap:8px; margin-bottom:4px;">
  653. <div style="display:flex; align-items:center; gap:8px; font-weight:600;">
  654. <span class="tag">题号 {{ $q['display_number'] ?? $q['question_number'] }} · {{ $typeLabel }}</span>
  655. @php
  656. $kpName = $q['knowledge_point_name'] ?? $q['knowledge_point'] ?? null;
  657. if (!empty($kpName) && $kpName !== '-' && $kpName !== '未标注') {
  658. echo '<span class="tag" style="background: #eef2ff; color:#4338ca;">' . e($kpName) . '</span>';
  659. }
  660. @endphp
  661. @if($showStatus)
  662. <span class="tag" style="background: {{ $statusColor }}; color:#fff;">{{ $statusText }}</span>
  663. @endif
  664. </div>
  665. @if($score !== null && $fullScore !== null)
  666. <div class="muted">得分 {{ $score }} / {{ $fullScore }}</div>
  667. @endif
  668. </div>
  669. <div class="math-content" style="margin-bottom:6px;">{!! $questionText !!}</div>
  670. {{-- 【修复】正确答案显示 --}}
  671. @if(!empty($correctAnswer))
  672. <div class="question-block" style="background:#f0fdf4; border-left:3px solid #10b981;">
  673. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:3px;">正确答案</div>
  674. <div class="math-content" style="line-height:1.7; color:#374151;">
  675. {!! is_string($correctAnswer) ? $correctAnswer : json_encode($correctAnswer, JSON_UNESCAPED_UNICODE) !!}
  676. </div>
  677. </div>
  678. @endif
  679. {{-- 【修改】解题思路显示(优先显示solution,其次显示analysis) --}}
  680. @if(!empty($solution))
  681. <div class="question-block" style="margin-top:6px; background:#eff6ff; border-left:3px solid #3b82f6;">
  682. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:4px;">解题思路</div>
  683. <div class="math-content solution-content" style="color:#374151;">
  684. {!! nl2br(e(is_array($solution) ? json_encode($solution, JSON_UNESCAPED_UNICODE) : (string) $solution)) !!}
  685. </div>
  686. </div>
  687. @elseif(!empty($analysis) && $analysis !== '暂无解题思路记录')
  688. <div class="question-block" style="margin-top:6px; background:#eff6ff; border-left:3px solid #3b82f6;">
  689. <div style="font-weight:600; font-size:12px; color:#111827; margin-bottom:4px;">解题思路</div>
  690. <div class="math-content solution-content" style="color:#374151;">{!! nl2br(e((string) $analysis)) !!}</div>
  691. </div>
  692. @endif
  693. {{-- 解题步骤(如果有) --}}
  694. @if(!empty($steps))
  695. <div style="margin-top:6px; font-size:12px;">
  696. <div style="font-weight:600; margin-bottom:3px;">解题步骤</div>
  697. <ol style="margin:0; padding-left:18px;">
  698. @foreach($steps as $s)
  699. <li style="margin-bottom:2px;">{!! nl2br(e(is_array($s) ? json_encode($s, JSON_UNESCAPED_UNICODE) : $s)) !!}</li>
  700. @endforeach
  701. </ol>
  702. </div>
  703. @endif
  704. </div>
  705. @endforeach
  706. </div>
  707. @endif
  708. </div> {{-- 闭合page div --}}
  709. <script src="/js/katex.min.js"></script>
  710. <script src="/js/auto-render.min.js"></script>
  711. <script>
  712. document.addEventListener('DOMContentLoaded', function() {
  713. try {
  714. renderMathInElement(document.body, {
  715. delimiters: [
  716. {left: "$$", right: "$$", display: true},
  717. {left: "$", right: "$", display: false},
  718. {left: "\\(", right: "\\)", display: false},
  719. {left: "\\[", right: "\\]", display: true}
  720. ],
  721. throwOnError: false,
  722. strict: false,
  723. trust: true
  724. });
  725. } catch (e) {}
  726. });
  727. </script>
  728. </body>
  729. </html>