# Seven-Dimension Cognitive Game Assessment — Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Add a game-based cognitive assessment system that measures seven cognitive dimensions — perception, focus, memory, logic, spatial reasoning, processing speed, and language expression — via interactive mini-games in the mini-program, with scores written to the existing `DanAssessmentResult` entity.
**Architecture:** Seven standalone cognitive test pages live in `pages/cognitive-test/`, each implementing a distinct game type. Scores post to the existing `POST /api/cognitive/self-test` endpoint, which already handles both new-record creation and updates to `DanAssessmentResult`. One new database column (`language_score`) is added for the new language dimension; the other five dimensions already have columns. A central portal page (`cognitive-hall.vue`) lists all seven tests with completion status.
**Tech Stack:** Java 8 / Spring Boot 2.7.18 / MyBatis-Plus (backend); uni-app Vue 2 Options API (frontend); MySQL 8.0.
**Spec:** This plan implements the design described in the brainstorming session (2026-09-19): seven cognitive dimensions, one game per dimension, results written to existing `dan_assessment_results` via the existing self-test API. No new backend endpoints are required.
## Global Constraints
- Backend uses `@PostMapping` only — no `@GetMapping`, `@PutMapping`, `@DeleteMapping`.
- All DI uses `@Resource`, field names must match default Bean Name.
- All DB migrations are idempotent — wrapped in try-catch.
- All DDL changes must be mirrored in `schema.sql`.
- Frontend uses Vue 2 Options API — no Composition API.
- Frontend cannot use optional chaining (`?.`), CSS Grid, or `:key` expressions — use methods instead.
- All time display uses `yyyy-MM-dd HH:mm:ss` (full) or `yyyy-MM-dd` (date only).
- Page titles must be set in `pages.json` via `navigationBarTitleText`, not in templates.
- Existing 5 cognitive test pages (`perception-test`, `logic-test`, `memory-test`, `spatial-test`, `speed-test`) must remain untouched.
- The new `language-test` page follows the same pattern as `memory-test.vue` (intro → play → result → submit).
---
## File Map
| Action | Path | Responsibility |
|--------|------|----------------|
| Modify | `cfc-backend/src/main/java/com/etotem/cfc/entity/DanAssessmentResult.java` | Add `languageScore` field |
| Modify | `cfc-backend/src/main/java/com/etotem/cfc/service/CognitiveService.java` | Add `languageScore` case to `submitSelfTestScore()` switch |
| Modify | `cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java` | Add migration 323 to add `language_score` column |
| Modify | `cfc-backend/src/main/resources/schema.sql` | Add `language_score` column to `dan_assessment_results` CREATE TABLE |
| Create | `cfc-frontend/pages/cognitive-test/language-test.vue` | Language expression game (4 questions, word-relation matching) |
| Modify | `cfc-frontend/pages.json` | Register `language-test` page in the existing `pages/cognitive-test` subpackage |
| Create | `cfc-frontend/pages/cognitive-hall.vue` | Central portal listing all 7 tests with completion status |
| Modify | `cfc-frontend/pages/wisdom/cognitive-report.vue` | Add `languageScore` dimension row to the report bar chart |
---
### Task 1: Backend — Entity + Migration + Service
**Files:**
- Modify: `cfc-backend/src/main/java/com/etotem/cfc/entity/DanAssessmentResult.java`
- Modify: `cfc-backend/src/main/java/com/etotem/cfc/service/CognitiveService.java`
- Modify: `cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java`
- Modify: `cfc-backend/src/main/resources/schema.sql`
**Interfaces:**
- Consumes: existing `DanAssessmentResult` fields and `CognitiveService.submitSelfTestScore()` method
- Produces: new `languageScore` field on entity; migration 323 that is idempotent
- [ ] **Step 1: Add `languageScore` to `DanAssessmentResult`**
In `cfc-backend/src/main/java/com/etotem/cfc/entity/DanAssessmentResult.java`, add after the existing `processingSpeedScore` field (around line 46):
```java
private Integer languageScore; // 语言表达得分 (0-100)
```
The field goes between `processingSpeedScore` (line 46) and the `// === EMI 心理子维度` comment (line 48).
- [ ] **Step 2: Add `languageScore` case to `CognitiveService.submitSelfTestScore()`**
In `cfc-backend/src/main/java/com/etotem/cfc/service/CognitiveService.java`, within the `switch (dimension)` block starting around line 117, add before the `default:` case:
```java
case "languageScore":
latest.setLanguageScore(score);
break;
```
Also update the overall score calculation loop (lines 139–144) to include `languageScore`:
```java
for (Integer s : Arrays.asList(
latest.getAttentionScore(), latest.getFocusScore(),
latest.getMemoryScore(), latest.getLogicScore(),
latest.getPerceptionScore(), latest.getSpatialScore(),
latest.getProcessingSpeedScore(), latest.getLanguageScore())) {
```
- [ ] **Step 3: Add migration 323 to `DatabaseInitializer.java`**
In `cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java`, insert **before** the closing `}` of the `runMigrations()` method (which ends at line 11133, right before line 11135's `/**`).
Add these lines (use the exact pattern from existing migrations):
```java
// 迁移323: dan_assessment_results 添加 language_score 列(游戏化认知测评:语言表达维度)
ensureColumn("dan_assessment_results", "language_score", "INT COMMENT '语言表达得分'");
log.info("迁移323: 已确保 language_score 列存在于 dan_assessment_results");
```
- [ ] **Step 4: Update `schema.sql`**
In `cfc-backend/src/main/resources/schema.sql`, find the `dan_assessment_results` CREATE TABLE (around line 421). After the `processing_speed_score` column definition (line 437), add:
```sql
language_score INT COMMENT '语言表达得分',
```
- [ ] **Step 5: Compile verification**
Run: `cd cfc-backend && mvn clean compile`
Expected: exit code 0, no errors.
- [ ] **Step 6: Commit**
```bash
git add cfc-backend/src/main/java/com/etotem/cfc/entity/DanAssessmentResult.java
git add cfc-backend/src/main/java/com/etotem/cfc/service/CognitiveService.java
git add cfc-backend/src/main/java/com/etotem/cfc/config/DatabaseInitializer.java
git add cfc-backend/src/main/resources/schema.sql
git commit -m "feat: add language_score dimension to cognitive assessment (migration 323)"
```
---
### Task 2: Frontend — Language Test Page (`language-test.vue`)
**Files:**
- Create: `cfc-frontend/pages/cognitive-test/language-test.vue`
- Modify: `cfc-frontend/pages.json`
**Interfaces:**
- Consumes: `submitCognitiveSelfTest(memberId, 'languageScore', score)` from `utils/api.js`
- Produces: a new quiz page matching the visual and interaction style of existing cognitive tests
- [ ] **Step 1: Write the page**
Create `cfc-frontend/pages/cognitive-test/language-test.vue` with this exact content:
```vue
🗣️语言表达测试观察每组词语,找出与其他词语关系不同的那个。测试你的语言理解和词汇联想能力。共 6 题每题限时 12 秒测评维度:语言表达第 {{ currentQ + 1 }}/{{ totalQ }} 题{{ timerSeconds }}s{{ currentQuestion.prompt }}{{ opt }}{{ feedbackMessage }}{{ score }}分{{ scoreComment }}答对题数{{ correctCount }} / {{ totalQ }}测评维度语言表达
```
- [ ] **Step 2: Register the page in `pages.json`**
In `cfc-frontend/pages.json`, find the `pages/cognitive-test` subpackage entry (around line 328). Add the new page entry **inside** that subpackage's `pages` array, after the existing entries:
```json
{
"path": "language-test",
"style": {
"navigationBarTitleText": "语言表达测试"
}
}
```
Insert before the closing `]` of that subpackage's pages array (which currently ends at line 361 with the `speed-test` entry).
- [ ] **Step 3: Verify syntax**
Run: `node --check cfc-frontend/pages/cognitive-test/language-test.vue` is not valid — Vue files don't support `--check`. Instead, verify the JS in the `
```
- [ ] **Step 2: Register in `pages.json`**
Add the new page to the main `pages` array in `cfc-frontend/pages.json`. Insert **before** the first subpackage entry. Find a good spot — add it near the other wisdom-related pages or as a standalone entry:
```json
{
"path": "pages/cognitive-hall",
"style": {
"navigationBarTitleText": "认知能力测评"
}
}
```
- [ ] **Step 3: Verify JSON**
```bash
node -e "JSON.parse(require('fs').readFileSync('cfc-frontend/pages.json','utf8')); console.log('pages.json OK')"
```
Expected: `pages.json OK`
- [ ] **Step 4: Commit**
```bash
git add cfc-frontend/pages/cognitive-hall.vue
git add cfc-frontend/pages.json
git commit -m "feat: add cognitive assessment hall portal (七维认知能力总览)"
```
---
### Task 4: Frontend — Cognitive Report Update
**Files:**
- Modify: `cfc-frontend/pages/wisdom/cognitive-report.vue`
**Interfaces:**
- Consumes: existing `dimensions` array and `report` object
- Produces: a report showing all 7 dimensions including the new `languageScore`
- [ ] **Step 1: Add language dimension to the report**
In `cfc-frontend/pages/wisdom/cognitive-report.vue`, in the `data()` function, find the `dimensions` array (around line 89) and add the new language dimension at the end:
```javascript
{ key: 'languageScore', label: '语言表达', icon: '🗣️', desc: '词汇理解与语言组织能力' }
```
The full updated array should be:
```javascript
dimensions: [
{ key: 'perceptionScore', label: '感知能力', icon: '👁️', desc: '感官信息处理能力' },
{ key: 'focusScore', label: '专注力', icon: '🎯', desc: '持续集中和抗干扰能力' },
{ key: 'memoryScore', label: '记忆力', icon: '🧠', desc: '信息编码和回忆能力' },
{ key: 'logicScore', label: '逻辑思维', icon: '💡', desc: '推理和问题解决能力' },
{ key: 'spatialScore', label: '空间思维', icon: '🗺️', desc: '空间想象和方位判断' },
{ key: 'processingSpeedScore', label: '加工速度', icon: '⚡', desc: '信息处理和反应速度' },
{ key: 'languageScore', label: '语言表达', icon: '🗣️', desc: '词汇理解与语言组织能力' }
]
```
- [ ] **Step 2: Update the empty state message**
In the same file, find the empty state text around line 73 and update the description to mention 7 dimensions:
Change:
```html
完成 DAN 认知评估后,可在此查看详细的六维认知分析报告
```
To:
```html
完成认知能力游戏测评或DAN评估后,可在此查看详细的七维认知分析报告
```
- [ ] **Step 3: Commit**
```bash
git add cfc-frontend/pages/wisdom/cognitive-report.vue
git commit -m "feat: add language dimension to cognitive report (七维认知报告)"
```
---
### Task 5: Compile & Verification
- [ ] **Step 1: Backend compilation**
Run: `cd cfc-backend && mvn clean compile`
Expected: exit code 0, no compilation errors.
- [ ] **Step 2: Frontend JSON validation**
Run: `node -e "JSON.parse(require('fs').readFileSync('cfc-frontend/pages.json','utf8')); console.log('pages.json OK')"`
Expected: `pages.json OK`
- [ ] **Step 3: Quick JS syntax check on new Vue files**
```bash
node -e "
var fs = require('fs');
['cfc-frontend/pages/cognitive-test/language-test.vue','cfc-frontend/pages/cognitive-hall.vue'].forEach(function(f) {
var content = fs.readFileSync(f, 'utf8');
var scriptMatch = content.match(/