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.
dianshang-houduan/docs/superpowers/plans/2026-08-01-teacher-owned-st...

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; TeachingClassStudent stays 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) and TeachingClassStudentMapper.selectByTeachingClassId.

  • Produces: roster-mode list and export whose UserinfoExample includes only IDs from the operator's owned teaching classes; a non-owned selected class returns BAD_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. Capture UserinfoExample and assert the list query contains only the owned member ID. Add a selected foreign class test asserting BAD_REQUEST and userinfoMapper.selectByExample is 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 test
    

    Expected: compilation failure because selectStudent has no operatorId; 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 operatorId and optional teachingClassId:

    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, when operatorId belongs to a teacher and isTeacherRosterMode(operator.getSchoolId()) is true, ignore caller-supplied school ID, use the operator school, apply andUserIdIn(ids) (use __empty__ when none), and reject a selected non-owned teaching class. Preserve the existing path for all other modes.

    Extend exportStudentUserInfo with optional operatorId and schoolClassId; in roster mode apply the same resolver before FilePortUtil.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 API operatorId; 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.cjs
    

    Expected: 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 studentClassOptions computed as:

    const studentClassOptions = computed(() =>
      isTeacherRosterMode.value ? teachingClassOptions.value : adminClassList.value
    );
    

    Use it for the picker. Pass operatorId through getList and through export along with the selected class. In roster mode, make canOperateStudent return true only for a selected class owned by the current teacher.

    In uploadStudents, require the selected class, build FormData with only the file, and call importTeacherRosterMembers(selectedClassId, formData); retain importTeacherStudents for non-roster mode. Add a row-level 数据初始化 action calling initializeTeachingClassStudentTrainingData with 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 test
    

    Expected: 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 --short
    

    Expected: build exits 0 and git diff --check prints no whitespace errors.