8.0 KiB
Teacher-Owned Student Management 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 teacher-side student management, initialization, import, and export to the current teacher's teaching-class members.
Architecture: UserController derives roster-mode read scope from operatorId, resolves only teaching classes whose createdBy is that teacher, and converts their membership rows into student IDs. The Vue student page passes the operator, exposes only owned teaching classes, requires a selected class for write actions, and uses the dedicated two-column roster import endpoint.
Tech Stack: Spring MVC, MyBatis Example mappers, JUnit 5 + Mockito; Vue 3, Element Plus, SheetJS, Node static tests.
Global Constraints
- Roster-mode read, export, import, and initialization scope is enforced on the server.
- A teacher may view the union of members in all owned teaching classes, or filter to one owned teaching class.
- Import headers are exactly
学生姓名and学号; teaching class is selected in the page. - Existing organization-structure student flow remains unchanged.
- No database schema changes;
TeachingClassStudentstays the membership authority.
Task 1: Restrict roster-mode student reads and exports in the backend
Files:
- Modify:
link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java:964-1031,1505-1530 - Modify:
link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTeacherAdminTest.java
Interfaces:
-
Consumes:
selectStudent(schoolId, schoolClassId, name, userName, index, size, operatorId)andTeachingClassStudentMapper.selectByTeachingClassId. -
Produces: roster-mode list and export whose
UserinfoExampleincludes only IDs from the operator's owned teaching classes; a non-owned selected class returnsBAD_REQUEST. -
Step 1: Write failing backend tests
Add tests that configure a roster-mode teacher, two teaching classes (one
createdBy = teacher-1, one owned by another teacher), and member rows. CaptureUserinfoExampleand assert the list query contains only the owned member ID. Add a selected foreign class test assertingBAD_REQUESTanduserinfoMapper.selectByExampleis never called.ResultEntity<PageInfo<Userinfo>> result = controller.selectStudent( "school-1", "owned-class", null, null, 1, 10, "teacher-1"); assertEquals(HttpStatus.OK, result.getStatusCode()); assertTrue(hasUserCondition(capturedExample, "user_id in", Collections.singletonList("student-owned"))); -
Step 2: Run the focused test and observe RED
mvn -q -Dtest=UserControllerTeacherAdminTest testExpected: compilation failure because
selectStudenthas nooperatorId; after its signature is introduced, scope assertions fail until membership resolution is implemented. -
Step 3: Implement a single owned-roster resolver and use it for list/export
Add a private helper that accepts
operatorIdand optionalteachingClassId:private List<String> resolveOwnedRosterStudentIds(Userinfo operator, String teachingClassId) { // selected class: require isOwnedTeachingClass // no selection: query SchoolClassExample by schoolId, createdBy, classType=TEACHING // collect nonblank TeachingClassStudent.studentUserId into a de-duplicated list }In
selectStudent, whenoperatorIdbelongs to a teacher andisTeacherRosterMode(operator.getSchoolId())is true, ignore caller-supplied school ID, use the operator school, applyandUserIdIn(ids)(use__empty__when none), and reject a selected non-owned teaching class. Preserve the existing path for all other modes.Extend
exportStudentUserInfowith optionaloperatorIdandschoolClassId; in roster mode apply the same resolver beforeFilePortUtil.exportExcel. The Vue request must pass both values. -
Step 4: Run focused backend tests and commit
mvn -q -Dtest=UserControllerTeacherAdminTest test git add src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTeacherAdminTest.java git commit -m "feat: scope teacher student roster"
Task 2: Align roster-mode student page actions and template
Files:
- Modify:
e-commerce-internet/src/api/teacher.js:438-520 - Modify:
e-commerce-internet/src/views/teacherEnd/student/index.vue:1-510 - Create:
e-commerce-internet/tests/teacher-owned-student-management.static.test.cjs
Interfaces:
-
Consumes: student list row fields
className,name,username; list APIoperatorId;POST /api/user/teaching-classes/{id}/students/import; existing per-student initialization API. -
Produces: roster-mode picker limited to
teachingClassOptions, selected-class gated import/initialization, and a two-column workbook. -
Step 1: Write a failing static test
Assert the student page includes all required contracts:
assert(page.includes("operatorId: currentUserId.value")); assert(page.includes("isTeacherRosterMode.value ? teachingClassOptions.value : adminClassList.value")); assert(page.includes("请选择自己的教学班后再导入学生")); assert(page.includes("initializeTeachingClassStudentTrainingData")); assert(page.includes('["学生姓名", "学号"]')); assert(api.includes("/api/user/teaching-classes/${teachingClassId}/students/import")); -
Step 2: Run the static test and observe RED
node tests/teacher-owned-student-management.static.test.cjsExpected: FAIL because the list does not pass
operatorId, the picker uses administrative classes, and import/template still use the legacy fields. -
Step 3: Implement roster-mode UI branches
Add
studentClassOptionscomputed as:const studentClassOptions = computed(() => isTeacherRosterMode.value ? teachingClassOptions.value : adminClassList.value );Use it for the picker. Pass
operatorIdthroughgetListand through export along with the selected class. In roster mode, makecanOperateStudentreturn true only for a selected class owned by the current teacher.In
uploadStudents, require the selected class, buildFormDatawith only the file, and callimportTeacherRosterMembers(selectedClassId, formData); retainimportTeacherStudentsfor non-roster mode. Add a row-level数据初始化action callinginitializeTeachingClassStudentTrainingDatawith the selected class and student ID.In
downloadTemplate, return early in roster mode after writing one SheetJS worksheet:const sheet = XLSX.utils.aoa_to_sheet([ ["学生姓名", "学号"], ["张三", "20260001"], ]);Keep the legacy workbook builder unchanged for organization mode.
-
Step 4: Run static tests and commit
node tests/teacher-owned-student-management.static.test.cjs node tests/teacher-student-roster-mode.static.test.cjs git add src/api/teacher.js src/views/teacherEnd/student/index.vue tests/teacher-owned-student-management.static.test.cjs git commit -m "feat: align teacher student roster page"
Task 3: Verify integrated behavior
Files:
- Verify only: both feature worktrees.
Interfaces:
-
Consumes: Tasks 1 and 2.
-
Produces: full regression evidence.
-
Step 1: Run backend suite
mvn -q testExpected: exit code 0.
-
Step 2: Run all frontend static checks
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: Build production frontend and inspect changes
npm run build:prod git diff --check git status --shortExpected: build exits 0 and
git diff --checkprints no whitespace errors.