You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
257 lines
15 KiB
Markdown
257 lines
15 KiB
Markdown
|
1 month ago
|
# Teacher Score Scope and Six-Module Weights 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:** Restrict all teacher score views and actions to the teacher's own teaching classes, and calculate those classes using the six configured training projects.
|
||
|
|
|
||
|
|
**Architecture:** Introduce a focused teacher-score service that derives ownership from the JWT user, loads teaching-class memberships, enabled task allocations, and AI assessment scores, then returns score summaries and chart data. Persist a six-project weight profile per teaching class; make the existing score centre and teacher home call the scoped APIs, while leaving legacy school-level five-weight APIs unchanged for compatibility.
|
||
|
|
|
||
|
|
**Tech Stack:** Spring MVC, MyBatis, Spring JDBC, JUnit 5 + Mockito; Vue 3, Element Plus, ECharts, Node static tests.
|
||
|
|
|
||
|
|
## Global Constraints
|
||
|
|
|
||
|
|
- A permitted class must be `TEACHING`, in the current teacher's school, and have `created_by` equal to the current JWT user's ID.
|
||
|
|
- Authorization is enforced from `TokenProvider.getJWTUser(request)`; client-supplied user, school, and class scope values are not trusted.
|
||
|
|
- No query, export, detail, chart, or score-update route may fall back to school-wide data for a teacher.
|
||
|
|
- Six class-specific weights are exactly: 10%, 30%, 10%, 10%, 20%, and 20%, totaling 100%.
|
||
|
|
- Existing school-level `weight` data and legacy student APIs remain unchanged.
|
||
|
|
|
||
|
|
---
|
||
|
|
|
||
|
|
### Task 1: Add class-specific six-module score data and aggregation service
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/TeachingClassScoreWeight.java`
|
||
|
|
- Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/dto/TeacherClassScoreSummary.java`
|
||
|
|
- Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/dto/TeacherScoreStatistics.java`
|
||
|
|
- Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/mapper/TeachingClassScoreWeightMapper.java`
|
||
|
|
- Create: `link_commerce/src/main/resources/mappers/TeachingClassScoreWeightMapper.xml`
|
||
|
|
- Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/TeacherScoreService.java`
|
||
|
|
- Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/impl/TeacherScoreServiceImpl.java`
|
||
|
|
- Create: `link_commerce/src/test/java/com/sztzjy/linkCommerce/service/impl/TeacherScoreServiceImplTest.java`
|
||
|
|
|
||
|
|
**Interfaces:**
|
||
|
|
- Consumes: `JwtUser`, `SchoolClass.createdBy`, `TeachingClassStudentMapper`, `SchoolDefaultTaskService.resolveForTeachingClass`, `StudentTrainingAnswerMapper`, and `TrainingTaskMapper`.
|
||
|
|
- Produces: `TeacherScoreService.listOwnedClasses(JwtUser)`, `requireOwnedClass(JwtUser, String)`, `getOrCreateWeight(JwtUser, String)`, `saveWeight(JwtUser, String, TeachingClassScoreWeight)`, `listScores(JwtUser, String, String, String, int, int)`, and `summarize(JwtUser, String)`.
|
||
|
|
|
||
|
|
- [ ] **Step 1: Write failing service tests for ownership, default weight, and project scoring**
|
||
|
|
|
||
|
|
Mock one owned teaching class, one foreign class, enabled task allocations from all six project names, and submitted student answers with `aiAssessmentScore`. Assert that foreign-class access raises `ServiceException(FORBIDDEN)`, an absent profile becomes `10/30/10/10/20/20`, and a student total is the weighted sum of each project average.
|
||
|
|
|
||
|
|
```java
|
||
|
|
TeachingClassScoreWeight weight = service.getOrCreateWeight(teacher("teacher-1", "school-1"), "class-1");
|
||
|
|
|
||
|
|
assertEquals(new BigDecimal("0.10"), weight.getFoundationWeight());
|
||
|
|
assertEquals(new BigDecimal("0.30"), weight.getMarketInsightWeight());
|
||
|
|
assertThrows(ServiceException.class,
|
||
|
|
() -> service.requireOwnedClass(teacher("teacher-1", "school-1"), "class-foreign"));
|
||
|
|
```
|
||
|
|
|
||
|
|
- [ ] **Step 2: Run the focused test and observe RED**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -q -Dtest=TeacherScoreServiceImplTest test
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: compilation failure because the class-specific weight model and service do not yet exist.
|
||
|
|
|
||
|
|
- [ ] **Step 3: Implement class weight persistence and deterministic aggregation**
|
||
|
|
|
||
|
|
Create `teaching_class_score_weight` with `teaching_class_id` primary key and decimal columns `foundation_weight`, `market_insight_weight`, `planning_design_weight`, `development_validation_weight`, `launch_operation_weight`, and `comprehensive_training_weight`. Use the mapper to insert the six defaults lazily.
|
||
|
|
|
||
|
|
In `TeacherScoreServiceImpl`, derive owned classes with:
|
||
|
|
|
||
|
|
```java
|
||
|
|
example.createCriteria()
|
||
|
|
.andSchoolIdEqualTo(user.getSchoolId())
|
||
|
|
.andCreatedByEqualTo(user.getUserId())
|
||
|
|
.andClassTypeEqualTo("TEACHING");
|
||
|
|
```
|
||
|
|
|
||
|
|
Resolve enabled tasks for the requested class, group them by `projectName`, load each class member's `StudentTrainingAnswer.aiAssessmentScore`, treat missing assessments as zero, calculate each project's task average, then calculate `sum(projectAverage * projectWeight)`. Include all six fixed project names even when the class currently has no enabled tasks so returned fields and defaults remain stable.
|
||
|
|
|
||
|
|
- [ ] **Step 4: Run the focused test and commit**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -q -Dtest=TeacherScoreServiceImplTest test
|
||
|
|
git add src/main/java/com/sztzjy/linkCommerce/entity/TeachingClassScoreWeight.java src/main/java/com/sztzjy/linkCommerce/entity/dto/TeacherClassScoreSummary.java src/main/java/com/sztzjy/linkCommerce/entity/dto/TeacherScoreStatistics.java src/main/java/com/sztzjy/linkCommerce/mapper/TeachingClassScoreWeightMapper.java src/main/resources/mappers/TeachingClassScoreWeightMapper.xml src/main/java/com/sztzjy/linkCommerce/service/TeacherScoreService.java src/main/java/com/sztzjy/linkCommerce/service/impl/TeacherScoreServiceImpl.java src/test/java/com/sztzjy/linkCommerce/service/impl/TeacherScoreServiceImplTest.java
|
||
|
|
git commit -m "feat: add scoped teacher score aggregation"
|
||
|
|
```
|
||
|
|
|
||
|
|
### Task 2: Expose JWT-scoped score centre and home-chart APIs
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/TeaScoreController.java:56-312`
|
||
|
|
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/ScoreController.java:264-353`
|
||
|
|
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/RankController.java:59-70`
|
||
|
|
- Create: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherScoreScopeControllerTest.java`
|
||
|
|
|
||
|
|
**Interfaces:**
|
||
|
|
- Consumes: `TeacherScoreService`, JWT user from `TokenProvider.getJWTUser(request)`, and the old `/api/weight` and `/api/score` request routes.
|
||
|
|
- Produces: teacher-only score list, score detail, export, update, weight read/save, trend, and statistics responses.
|
||
|
|
|
||
|
|
- [ ] **Step 1: Write failing controller tests for every guarded entry point**
|
||
|
|
|
||
|
|
Mock `TokenProvider`-derived teacher context through a request and the score service. Verify a foreign class returns `FORBIDDEN`, a missing class on list/export resolves to the owned-class union, statistics use only the owned set, and `doRankOne` rejects a missing or foreign `teachingClassId`.
|
||
|
|
|
||
|
|
```java
|
||
|
|
ResultEntity<?> result = controller.selectStuRankAndScore(
|
||
|
|
"foreign-class", null, null, 1, 10, requestFor("teacher-1"));
|
||
|
|
|
||
|
|
assertEquals(HttpStatus.FORBIDDEN, result.getStatusCode());
|
||
|
|
verify(teacherScoreService, never()).listScores(any(), eq("foreign-class"), any(), any(), anyInt(), anyInt());
|
||
|
|
```
|
||
|
|
|
||
|
|
- [ ] **Step 2: Run the focused controller test and observe RED**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -q -Dtest=TeacherScoreScopeControllerTest test
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: test compilation or assertions fail because the legacy controller trusts school/class parameters.
|
||
|
|
|
||
|
|
- [ ] **Step 3: Replace teacher-facing legacy scope with service-backed scope**
|
||
|
|
|
||
|
|
Add `HttpServletRequest` to teacher-facing methods and obtain the current user with `TokenProvider.getJWTUser(request)`. Replace `TeaScoreController` list, detail, export, weight read/save, and update routes with calls to `TeacherScoreService`; only pass class ID after `requireOwnedClass` succeeds. The weight routes accept `teachingClassId` and never update the school-level `weight` table.
|
||
|
|
|
||
|
|
Change `/api/score/getTeaScoreTrend` and `/api/score/getTeaScoreAnalysis` to derive the teacher from JWT and call the same owned-class aggregation. For a blank selected class, aggregate all owned classes; for a selected class, require ownership. Update `/api/rank/doRankOne` so teachers must provide an owned teaching class and route recalculation through its class score aggregation; preserve non-teacher behavior only where separately authorized.
|
||
|
|
|
||
|
|
- [ ] **Step 4: Run focused tests and commit**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -q -Dtest=TeacherScoreScopeControllerTest,TeacherScoreServiceImplTest test
|
||
|
|
git add src/main/java/com/sztzjy/linkCommerce/controller/stu/TeaScoreController.java src/main/java/com/sztzjy/linkCommerce/controller/stu/ScoreController.java src/main/java/com/sztzjy/linkCommerce/controller/stu/RankController.java src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherScoreScopeControllerTest.java
|
||
|
|
git commit -m "feat: enforce teacher score class scope"
|
||
|
|
```
|
||
|
|
|
||
|
|
### Task 3: Update teacher score centre for self-owned classes and six weights
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Modify: `e-commerce-internet/src/api/teacher.js:615-670`
|
||
|
|
- Modify: `e-commerce-internet/src/views/teacherEnd/score/index.vue:1-269`
|
||
|
|
- Create: `e-commerce-internet/tests/teacher-score-scope.static.test.cjs`
|
||
|
|
|
||
|
|
**Interfaces:**
|
||
|
|
- Consumes: scoped `/api/weight` responses, `teachingClassId`, and six `TeachingClassScoreWeight` fields.
|
||
|
|
- Produces: a self-owned class selector, six-field per-class weight dialog, and list/detail/export/update requests whose scope is server-authorized.
|
||
|
|
|
||
|
|
- [ ] **Step 1: Write the failing frontend static test**
|
||
|
|
|
||
|
|
Assert the score page no longer derives its class dropdown from all school classes, supplies a selected teaching class to weight requests, and renders each specified project label and default field name.
|
||
|
|
|
||
|
|
```js
|
||
|
|
assert(page.includes("getOwnedTeachingClasses"));
|
||
|
|
assert(page.includes("teachingClassId: scoreParams.value.classId"));
|
||
|
|
assert(page.includes("互联网产品开发基础认知"));
|
||
|
|
assert(page.includes("综合实训"));
|
||
|
|
assert(page.includes("foundationWeight"));
|
||
|
|
assert(page.includes("comprehensiveTrainingWeight"));
|
||
|
|
```
|
||
|
|
|
||
|
|
- [ ] **Step 2: Run the static test and observe RED**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
node tests/teacher-score-scope.static.test.cjs
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: FAIL because the page currently loads every school teaching class and has five historical weight inputs.
|
||
|
|
|
||
|
|
- [ ] **Step 3: Implement the scoped score centre UI**
|
||
|
|
|
||
|
|
Add API wrappers for teacher-owned class list and the revised score/weight endpoints. Load only the current teacher's classes, remove the school-wide list source, and disable weight setup and score update until an owned class is selected.
|
||
|
|
|
||
|
|
Replace the five form items and validation map with six exact labels: `互联网产品开发基础认知` (`foundationWeight`), `市场洞察与需求分析` (`marketInsightWeight`), `产品规划与设计` (`planningDesignWeight`), `产品开发与测试验证` (`developmentValidationWeight`), `产品上线与运营推广` (`launchOperationWeight`), and `综合实训` (`comprehensiveTrainingWeight`). Convert percent input to decimals on save, require a 100% total using a tolerance-safe decimal check, and reload the selected class after successful recalculation.
|
||
|
|
|
||
|
|
- [ ] **Step 4: Run focused frontend checks and commit**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
node tests/teacher-score-scope.static.test.cjs
|
||
|
|
git add src/api/teacher.js src/views/teacherEnd/score/index.vue tests/teacher-score-scope.static.test.cjs
|
||
|
|
git commit -m "feat: scope teacher score centre"
|
||
|
|
```
|
||
|
|
|
||
|
|
### Task 4: Scope teacher-home trends and statistics
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Modify: `e-commerce-internet/src/api/teacher.js:212-234`
|
||
|
|
- Modify: `e-commerce-internet/src/views/teacherEnd/index.vue:1-210`
|
||
|
|
- Modify: `e-commerce-internet/tests/teacher-score-scope.static.test.cjs`
|
||
|
|
|
||
|
|
**Interfaces:**
|
||
|
|
- Consumes: JWT-authorized trend and statistics APIs plus the owned teaching-class list.
|
||
|
|
- Produces: chart queries that use an owned class selection or the teacher's owned-class aggregate without sending a school-wide scope.
|
||
|
|
|
||
|
|
- [ ] **Step 1: Extend the failing static test for dashboard contracts**
|
||
|
|
|
||
|
|
Add assertions that dashboard class options originate from the owned-class API and that trend/statistics requests do not send `schoolId` or a caller-selected `userId` as authorization scope.
|
||
|
|
|
||
|
|
```js
|
||
|
|
assert(home.includes("getOwnedTeachingClasses"));
|
||
|
|
assert(!home.includes("getClasses({ schoolMajorId: userStore.userInfo.schoolId })"));
|
||
|
|
assert(!home.includes("getAverageScoreTrend({ schoolId: userStore.userInfo.schoolId, userId: userStore.userInfo.userId })"));
|
||
|
|
```
|
||
|
|
|
||
|
|
- [ ] **Step 2: Run the static test and observe RED**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
node tests/teacher-score-scope.static.test.cjs
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: FAIL because the homepage currently uses school-level class and chart parameters.
|
||
|
|
|
||
|
|
- [ ] **Step 3: Implement owned-class chart loading and empty state**
|
||
|
|
|
||
|
|
Load the owned teaching classes once, use them for the statistics selector, request trend data without client-provided authorization identifiers, and request statistics with only the optional selected owned `classId` and time. When the owned list is empty, clear ECharts series, retain zero-valued statistic cards, and do not issue a school-wide fallback request.
|
||
|
|
|
||
|
|
- [ ] **Step 4: Run frontend checks and commit**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
node tests/teacher-score-scope.static.test.cjs
|
||
|
|
npm run build:prod
|
||
|
|
git add src/api/teacher.js src/views/teacherEnd/index.vue tests/teacher-score-scope.static.test.cjs
|
||
|
|
git commit -m "feat: scope teacher score dashboard"
|
||
|
|
```
|
||
|
|
|
||
|
|
### Task 5: Full regression and migration verification
|
||
|
|
|
||
|
|
**Files:**
|
||
|
|
- Verify only: backend and frontend feature worktrees.
|
||
|
|
|
||
|
|
**Interfaces:**
|
||
|
|
- Consumes: all previous tasks.
|
||
|
|
- Produces: evidence that legacy suites and the production build remain valid.
|
||
|
|
|
||
|
|
- [ ] **Step 1: Run all backend tests**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
mvn -q test
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: exit code 0.
|
||
|
|
|
||
|
|
- [ ] **Step 2: Run all frontend static tests**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
Get-ChildItem -Path tests -Filter '*.cjs' | Sort-Object Name | ForEach-Object { node $_.FullName; if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } }
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: exit code 0.
|
||
|
|
|
||
|
|
- [ ] **Step 3: Inspect final changes and migration idempotence**
|
||
|
|
|
||
|
|
```powershell
|
||
|
|
git diff --check
|
||
|
|
rg -n "teaching_class_score_weight|foundation_weight|comprehensive_training_weight" src/main/java src/main/resources
|
||
|
|
git status --short
|
||
|
|
```
|
||
|
|
|
||
|
|
Expected: no whitespace errors; mapper, entity, and service all reference the six class-specific fields; only intentional feature files are staged or committed.
|
||
|
|
|
||
|
|
## Self-Review
|
||
|
|
|
||
|
|
- Scope coverage: Task 2 blocks foreign classes for every backend read/write/chart route; Tasks 3 and 4 restrict selectors and remove school-wide client fallbacks.
|
||
|
|
- Weight coverage: Task 1 defines persisted per-class six weights and aggregation; Task 3 exposes the exact six labels and total validation.
|
||
|
|
- Compatibility coverage: the global constraints and Task 2 leave the old school-level weight paths available to legacy consumers while moving the teacher UI to new scoped APIs.
|
||
|
|
- Placeholder scan: no deferred implementation or unspecified validation remains.
|
||
|
|
- Type consistency: all controller and Vue tasks consume the `TeacherScoreService`/`TeachingClassScoreWeight` contracts defined in Task 1.
|