# Optional Administrative Class Mode 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:** Deliver one configurable multi-school product in which standard schools use administrative classes while Zhujian teachers directly maintain teaching-class rosters. **Architecture:** Add a one-to-one school product configuration and require all organization-dependent backend rules to read it server-side. Reuse `SchoolClass` for teaching classes and `TeachingClassStudent` for membership; in `TEACHING_CLASS_ONLY` mode the membership has no administrative-class snapshot. The Vue client loads the same configuration to filter navigation and switch the teacher roster workflow, while backend checks remain authoritative. **Tech Stack:** Java 8, Spring Boot 2.7, MyBatis XML, MySQL 8, JUnit 5 + Mockito, Vue 3, Vue Router 4, Pinia, Element Plus, Vite, Node `assert` static tests. ## Global Constraints - Keep one repository, deployment line, and database schema for every school; do not add a Zhujian branch or controller copy. - `organization_mode` is exactly `ADMIN_CLASS_ENABLED` or `TEACHING_CLASS_ONLY`. - `student_roster_owner` is exactly `SCHOOL_ADMIN`, `TEACHER`, or reserved `EXTERNAL_SYNC`. - All existing schools default to `ADMIN_CLASS_ENABLED` + `SCHOOL_ADMIN`. - A student identity is unique by `userinfo.school_id + userinfo.username`; `username` is the existing student-number/login-name field. - `teaching_class_student.admin_class_id` is nullable only for `TEACHING_CLASS_ONLY` schools. - A teacher may only operate a `TEACHING` class where `school_class.created_by` equals the authenticated teacher ID and the class belongs to that teacher's school. - Removing a class member changes only the membership status to `EXITED`; never delete the student account or historical work. - Student task, score, AI evaluation, and progress requests must use an explicit `teachingClassId` when a student belongs to multiple teaching classes. --- ## File structure | Path | Responsibility | | --- | --- | | `link_commerce/docs/sql/2026-07-30-school-product-config.sql` | Idempotent schema migration and default configuration backfill. | | `link_commerce/src/main/java/.../entity/SchoolProductConfig.java` | One school configuration record. | | `link_commerce/src/main/java/.../mapper/SchoolProductConfigMapper.java` and `resources/mappers/SchoolProductConfigMapper.xml` | Configuration persistence. | | `link_commerce/src/main/java/.../service/SchoolProductConfigService.java` and `service/impl/SchoolProductConfigServiceImpl.java` | Canonical configuration lookup and organization-mode guards. | | `link_commerce/src/main/java/.../controller/platformadmin/PlatformAdminController.java` | Platform-only school configuration lifecycle endpoints. | | `link_commerce/src/main/java/.../controller/stu/UserController.java` | Teacher roster endpoints and organization-mode-specific import/creation behavior. | | `link_commerce/src/main/java/.../controller/schooladmin/SchoolAdminController.java` | Server-side rejection of unavailable school-admin modules. | | `link_commerce/src/main/java/.../mapper/TeachingClassStudentMapper.java` and XML | Multi-teaching-class-safe membership lookup and write operations. | | `e-commerce-internet/src/api/platformAdmin.js` and `src/api/schoolProductConfig.js` | Platform configuration CRUD and current-school configuration calls. | | `e-commerce-internet/src/store/modules/user.js`, `src/permission.js`, `src/router/index.js`, `src/layout/components/Sidebar/index.vue` | Cached configuration, deep-link guard, and feature-filtered navigation. | | `e-commerce-internet/src/views/platformAdmin/school/index.vue` | School create/edit form with organization mode. | | `e-commerce-internet/src/views/teacherEnd/student/index.vue` | Standard versus teacher-maintained roster UI and templates. | | `link_commerce/src/test/java/...` and `e-commerce-internet/tests/optional-administrative-class.static.test.cjs` | Backend behavior tests and frontend source-level regression checks. | ### Task 1: Persist and expose the school product configuration **Files:** - Create: `link_commerce/docs/sql/2026-07-30-school-product-config.sql` - Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/SchoolProductConfig.java` - Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/mapper/SchoolProductConfigMapper.java` - Create: `link_commerce/src/main/resources/mappers/SchoolProductConfigMapper.xml` - Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/SchoolProductConfigService.java` - Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/impl/SchoolProductConfigServiceImpl.java` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/service/impl/SchoolProductConfigServiceImplTest.java` **Interfaces:** - Produces `SchoolProductConfig getRequiredConfig(String schoolId)`; it throws `ServiceException(HttpStatus.BAD_REQUEST, "学校组织配置不存在")` for a missing record. - Produces `boolean requiresAdminClass(String schoolId)` and `boolean isTeacherRosterManaged(String schoolId)`. - Produces `void requireAdminClassEnabled(String schoolId)`; it throws `ServiceException(HttpStatus.BAD_REQUEST, "当前学校未启用行政班")` for `TEACHING_CLASS_ONLY`. - [ ] **Step 1: Write the failing service tests** ```java @Test void teacherRosterModeDoesNotRequireAdministrativeClass() { SchoolProductConfig config = config("school-zj", "TEACHING_CLASS_ONLY", "TEACHER"); when(mapper.selectByPrimaryKey("school-zj")).thenReturn(config); assertFalse(service.requiresAdminClass("school-zj")); assertTrue(service.isTeacherRosterManaged("school-zj")); } @Test void missingConfigurationIsRejected() { when(mapper.selectByPrimaryKey("missing")).thenReturn(null); assertThrows(ServiceException.class, () -> service.getRequiredConfig("missing")); } ``` - [ ] **Step 2: Run the new test file and verify it fails** Run: `mvn -q -Dtest=SchoolProductConfigServiceImplTest test` from `link_commerce`. Expected: compilation failure because `SchoolProductConfigService` and its implementation do not exist. - [ ] **Step 3: Add the migration and minimal persistence model** ```sql CREATE TABLE IF NOT EXISTS school_product_config ( school_id VARCHAR(64) NOT NULL PRIMARY KEY, organization_mode VARCHAR(32) NOT NULL DEFAULT 'ADMIN_CLASS_ENABLED', student_roster_owner VARCHAR(32) NOT NULL DEFAULT 'SCHOOL_ADMIN', create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP ) COMMENT='school product capability configuration'; INSERT INTO school_product_config (school_id, organization_mode, student_roster_owner) SELECT school_id, 'ADMIN_CLASS_ENABLED', 'SCHOOL_ADMIN' FROM school ON DUPLICATE KEY UPDATE school_id = VALUES(school_id); ALTER TABLE teaching_class_student MODIFY admin_class_id VARCHAR(64) NULL; ``` Implement the Java entity and MyBatis mapper with `selectByPrimaryKey`, `insert`, `updateByPrimaryKey`, and `upsertDefaultForSchool` methods. Validate enum values in the service before writes. - [ ] **Step 4: Implement the service contract** ```java public boolean requiresAdminClass(String schoolId) { return "ADMIN_CLASS_ENABLED".equals(getRequiredConfig(schoolId).getOrganizationMode()); } public boolean isTeacherRosterManaged(String schoolId) { return "TEACHER".equals(getRequiredConfig(schoolId).getStudentRosterOwner()); } ``` - [ ] **Step 5: Run the focused tests and inspect SQL** Run: `mvn -q -Dtest=SchoolProductConfigServiceImplTest test` from `link_commerce`. Expected: PASS. Review the SQL manually against a disposable MySQL schema before applying it to any shared environment. - [ ] **Step 6: Commit the persistence unit** ```bash git -C link_commerce add docs/sql/2026-07-30-school-product-config.sql src/main/java/com/sztzjy/linkCommerce/entity/SchoolProductConfig.java src/main/java/com/sztzjy/linkCommerce/mapper/SchoolProductConfigMapper.java src/main/java/com/sztzjy/linkCommerce/service/SchoolProductConfigService.java src/main/java/com/sztzjy/linkCommerce/service/impl/SchoolProductConfigServiceImpl.java src/main/resources/mappers/SchoolProductConfigMapper.xml src/test/java/com/sztzjy/linkCommerce/service/impl/SchoolProductConfigServiceImplTest.java git -C link_commerce commit -m "feat: add school product configuration" ``` ### Task 2: Add platform-controlled configuration lifecycle and current-school read access **Files:** - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/platformadmin/PlatformAdminController.java` - Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/SchoolProductConfigController.java` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/platformadmin/PlatformAdminControllerTest.java` - Create: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/SchoolProductConfigControllerTest.java` **Interfaces:** - Produces `GET /api/platform-admin/schools/{schoolId}/product-config` and `PUT /api/platform-admin/schools/{schoolId}/product-config` for role 1 only. - Produces `GET /api/school-product-config/current` for authenticated users; it derives `schoolId` from JWT, never from a query parameter. - Consumes Task 1 `SchoolProductConfigService`. - [ ] **Step 1: Write controller tests for authorization and server-derived school scope** ```java @Test void currentConfigServiceUsesTheAuthenticatedUsersSchool() { JwtUser user = jwtUser("teacher-1", 3, "school-zj"); when(mapper.selectByPrimaryKey("school-zj")).thenReturn(teacherManagedConfig()); SchoolProductConfig result = service.getForAuthenticatedSchool(user); assertEquals("school-zj", result.getSchoolId()); verify(mapper).selectByPrimaryKey("school-zj"); } ``` - [ ] **Step 2: Run controller tests and verify they fail** Run: `mvn -q -Dtest=PlatformAdminControllerTest,SchoolProductConfigControllerTest test` from `link_commerce`. Expected: compilation failure because the endpoints and controller do not exist. - [ ] **Step 3: Create configuration records together with schools and expose the endpoints** In `PlatformAdminController.addSchool`, call `schoolProductConfigService.createDefault(school.getSchoolId())` only after the school insert succeeds. Add `/product-config` get/put methods that call the existing `requirePlatformAdmin(request)` before every access. The PUT body accepts only `organizationMode` and `studentRosterOwner`; reject any other mode/owner pair. ```java @PutMapping("/schools/{schoolId}/product-config") public ResultEntity updateProductConfig(@PathVariable String schoolId, @RequestBody SchoolProductConfig config, HttpServletRequest request) { requirePlatformAdmin(request); requireSchool(schoolId); config.setSchoolId(schoolId); schoolProductConfigService.updateControlledConfig(config); return new ResultEntity(HttpStatus.OK, "保存成功"); } ``` `SchoolProductConfigController.current` must reject unauthenticated, platform-admin-without-school, and malformed JWT requests with the existing security error convention. - [ ] **Step 4: Add mode-switch protection tests and implementation** Write a test where a school has an `ADMIN` class or `userinfo.school_class_id` data; `updateControlledConfig` must throw `ServiceException(HttpStatus.BAD_REQUEST, "学校已有组织数据,不能直接切换组织模式")`. Implement the check through `SchoolClassMapper` and `UserinfoMapper` count queries before updating a different `organizationMode`. - [ ] **Step 5: Run the focused backend tests** Run: `mvn -q -Dtest=PlatformAdminControllerTest,SchoolProductConfigControllerTest,SchoolProductConfigServiceImplTest test` from `link_commerce`. Expected: PASS, including role-1-only write access and rejected unsafe switching. - [ ] **Step 6: Commit the configuration API** ```bash git -C link_commerce add src/main/java/com/sztzjy/linkCommerce/controller/platformadmin/PlatformAdminController.java src/main/java/com/sztzjy/linkCommerce/controller/SchoolProductConfigController.java src/main/java/com/sztzjy/linkCommerce/service/impl/SchoolProductConfigServiceImpl.java src/test/java/com/sztzjy/linkCommerce/controller/platformadmin/PlatformAdminControllerTest.java src/test/java/com/sztzjy/linkCommerce/controller/SchoolProductConfigControllerTest.java git -C link_commerce commit -m "feat: manage school organization mode" ``` ### Task 3: Make teaching-class membership multi-class-safe and support teacher-managed roster imports **Files:** - Create: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/importDto/TeacherRosterStudentImportDTO.java` - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/mapper/TeachingClassStudentMapper.java` - Modify: `link_commerce/src/main/resources/mappers/TeachingClassStudentMapper.xml` - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTest.java` - Create: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherRosterImportTest.java` **Interfaces:** - Produces `POST /api/user/teaching-classes/{teachingClassId}/students/import` with an Excel file and no caller-supplied school or teacher ID. - Produces `POST /api/user/teaching-classes/{teachingClassId}/students` with `{name, username, sex, phone, email}`. - Produces `GET /api/user/teaching-classes/{teachingClassId}/students`. - `TeachingClassStudentMapper` must expose `List selectActiveTeachingClassesByStudentUserId(String studentUserId)`; retain the existing single-row method until every legacy caller is migrated. - [ ] **Step 1: Write failing tests for Zhujian roster creation, duplicate matching, and ownership** ```java @Test void teacherRosterImportCreatesSchoolStudentAndNullAdminMembership() { when(configService.isTeacherRosterManaged("school-zj")).thenReturn(true); when(userinfoMapper.selectBySchoolIdAndUsername("school-zj", "20260001")).thenReturn(null); ResultEntity result = controller.importTeacherRoster(rows("张三", "20260001"), "teach-1", requestFor("teacher-1", "school-zj")); assertEquals(HttpStatus.OK, result.getStatusCode()); verify(teachingClassStudentMapper).insertSelective(argThat(member -> member.getAdminClassId() == null)); } @Test void addingToOneTeachingClassDoesNotExitOtherMemberships() { controller.upsertActiveTeachingClassMember("teach-2", student("student-1"), null, "IMPORT"); verify(teachingClassStudentMapper, never()).exitActiveByStudentUserIdExceptClass(anyString(), anyString()); } ``` - [ ] **Step 2: Run the focused tests and verify they fail** Run: `mvn -q -Dtest=UserControllerTest,TeacherRosterImportTest test` from `link_commerce`. Expected: compilation failure because the teacher roster endpoints, configuration dependency, and list mapper method are absent. - [ ] **Step 3: Implement the nullable and multi-class membership behavior** Add `selectActiveTeachingClassesByStudentUserId` as a list-returning mapper query without `limit 1`; retain the existing `selectActiveByStudentUserId` method for legacy callers until Task 5 migrates them. In `upsertActiveTeachingClassMember`, remove the call to `exitActiveByStudentUserIdExceptClass`; the unique key already prevents duplicate membership within the same teaching class. ```java private void upsertActiveTeachingClassMember(String classId, Userinfo student, String adminClassId, String reason) { TeachingClassStudent existing = teachingClassStudentMapper .selectByStudentUserIdAndTeachingClassId(student.getUserId(), classId); if (existing == null) { TeachingClassStudent member = new TeachingClassStudent(); member.setId(UUID.randomUUID().toString()); member.setTeachingClassId(classId); member.setStudentUserId(student.getUserId()); member.setAdminClassId(adminClassId); member.setStatus("IN_PROGRESS"); member.setJoinReason(reason); member.setJoinTime(new Date()); teachingClassStudentMapper.insertSelective(member); } else { teachingClassStudentMapper.updateMembershipToActive(student.getUserId(), classId, adminClassId, reason); } } ``` - [ ] **Step 4: Implement the teacher-managed import path** Add `TeacherRosterStudentImportDTO` with `name`, `username`, `sex`, `phone`, and `email` Excel headers. Authenticate with `TokenProvider.getJWTUser(request)`, load the class, require class type `TEACHING`, require matching school ID and `createdBy`, then require `isTeacherRosterManaged(schoolId)`. For each row, validate nonblank `name` and `username`, find by `(schoolId, username)`, create a role-4 `Userinfo` only when absent, and call `upsertActiveTeachingClassMember(classId, student, null, "TEACHER_ROSTER_IMPORT")`. For the standard path retain the existing administrative-class and major validation. For Zhujian, do not call `findAdminClassStudent`, `validateTeachingClassImportRowsByMajor`, or any faculty/major lookup. - [ ] **Step 5: Test duplicate and error semantics** Add test rows covering: existing same-school student joins a second teaching class; duplicate row in one upload is returned in the response `skippedRows`; same username with a different name returns `conflictRows` and commits no new identity; a teacher operating another teacher's class receives a rejected result. Run the two focused test files. Run: `mvn -q -Dtest=UserControllerTest,TeacherRosterImportTest test` from `link_commerce`. Expected: PASS. - [ ] **Step 6: Commit roster backend changes** ```bash git -C link_commerce add src/main/java/com/sztzjy/linkCommerce/entity/importDto/TeacherRosterStudentImportDTO.java src/main/java/com/sztzjy/linkCommerce/mapper/TeachingClassStudentMapper.java src/main/resources/mappers/TeachingClassStudentMapper.xml src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTest.java src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherRosterImportTest.java git -C link_commerce commit -m "feat: support teacher managed teaching rosters" ``` ### Task 4: Enforce organization-mode restrictions on existing school-admin APIs **Files:** - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/schooladmin/SchoolAdminController.java` - Create: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/schooladmin/SchoolAdminOrganizationModeTest.java` **Interfaces:** - Consumes Task 1 `SchoolProductConfigService.requireAdminClassEnabled(String schoolId)`. - The school-admin faculty, major, administrative-class, student-list, and student-import endpoints reject `TEACHING_CLASS_ONLY` with a 400 business error. - School information and teacher management endpoints remain available. - [ ] **Step 1: Write failing authorization tests** ```java @Test void teacherRosterSchoolCannotCreateAdministrativeClass() { when(schoolAdminService.requireSchoolAdmin(user)).thenReturn("school-zj"); doThrow(new ServiceException(HttpStatus.BAD_REQUEST, "当前学校未启用行政班")) .when(configService).requireAdminClassEnabled("school-zj"); assertThrows(ServiceException.class, () -> controller.addClass(new SchoolClass(), requestFor(user))); } @Test void teacherRosterSchoolStillListsTeachers() { when(schoolAdminService.requireSchoolAdmin(user)).thenReturn("school-zj"); controller.listTeachers(1, 10, null, requestFor(user)); verifyNoInteractions(configService); } ``` - [ ] **Step 2: Run the test file and verify it fails** Run: `mvn -q -Dtest=SchoolAdminOrganizationModeTest test` from `link_commerce`. Expected: compilation failure because the controller has no configuration service or guard. - [ ] **Step 3: Add a single controller guard and apply it to scoped methods** ```java private void requireAdminClassManagement(HttpServletRequest request) { schoolProductConfigService.requireAdminClassEnabled(currentSchoolId(request)); } ``` Call this method at the beginning of every `/faculties`, `/majors`, `/classes`, `/students`, and `/students/import` handler, including list and mutation handlers. Do not call it for `/school` or `/teachers` handlers. - [ ] **Step 4: Run focused tests and compile the backend** Run: `mvn -q -Dtest=SchoolAdminOrganizationModeTest,SchoolAdminControllerTest test` from `link_commerce`. Expected: PASS. Then run `mvn -q -DskipTests compile` from `link_commerce`; expected: BUILD SUCCESS. - [ ] **Step 5: Commit server-side feature enforcement** ```bash git -C link_commerce add src/main/java/com/sztzjy/linkCommerce/controller/schooladmin/SchoolAdminController.java src/test/java/com/sztzjy/linkCommerce/controller/schooladmin/SchoolAdminOrganizationModeTest.java git -C link_commerce commit -m "feat: restrict admin-class modules by school mode" ``` ### Task 5: Make multi-teaching-class selection explicit for student workflows **Files:** - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java` - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/impl/ScoreServiceImpl.java` - Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/impl/AiTrainingEvaluationServiceImpl.java` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTest.java` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/service/impl/ScoreRankServiceImplTeachingClassTest.java` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/service/impl/AiTrainingEvaluationServiceImplTest.java` **Interfaces:** - `POST /api/user/selectCurrentTeachingClass` returns a class only when the student has exactly one active teaching-class membership. - For multiple active memberships it returns `HttpStatus.CONFLICT` and message `请指定教学班`. - Task/score/evaluation services consume the caller-provided `teachingClassId` and verify the student has an active membership in that exact class. - [ ] **Step 1: Write failing plurality tests** ```java @Test void currentTeachingClassIsAmbiguousWhenStudentHasTwoActiveClasses() { when(mapper.selectActiveTeachingClassesByStudentUserId("student-1")) .thenReturn(Arrays.asList(member("teach-1"), member("teach-2"))); ResultEntity result = controller.selectCurrentTeachingClass("student-1"); assertEquals(HttpStatus.CONFLICT, result.getStatusCode()); } ``` - [ ] **Step 2: Run the listed backend tests and verify the new assertion fails** Run: `mvn -q -Dtest=UserControllerTest,ScoreRankServiceImplTeachingClassTest,AiTrainingEvaluationServiceImplTest test` from `link_commerce`. Expected: FAIL because the existing mapper returns one arbitrary membership. - [ ] **Step 3: Implement explicit membership validation** Update `selectCurrentTeachingClass` to use Task 3's `selectActiveTeachingClassesByStudentUserId` lookup: return no class for zero records, the sole class for one record, and `CONFLICT` for more than one. In score/evaluation code, when a `teachingClassId` is supplied, load `selectByStudentUserIdAndTeachingClassId` and require `status=IN_PROGRESS`; never fall back to `userinfo.schoolClassId` for a teaching-class decision. - [ ] **Step 4: Run regression tests** Run: `mvn -q -Dtest=UserControllerTest,ScoreRankServiceImplTeachingClassTest,AiTrainingEvaluationServiceImplTest test` from `link_commerce`. Expected: PASS for zero, one, and multiple active memberships. - [ ] **Step 5: Commit explicit class-context behavior** ```bash git -C link_commerce add src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java src/main/java/com/sztzjy/linkCommerce/service/impl/ScoreServiceImpl.java src/main/java/com/sztzjy/linkCommerce/service/impl/AiTrainingEvaluationServiceImpl.java src/test/java/com/sztzjy/linkCommerce/controller/stu/UserControllerTest.java src/test/java/com/sztzjy/linkCommerce/service/impl/ScoreRankServiceImplTeachingClassTest.java src/test/java/com/sztzjy/linkCommerce/service/impl/AiTrainingEvaluationServiceImplTest.java git -C link_commerce commit -m "fix: require explicit teaching class context" ``` ### Task 6: Load product configuration in Vue and guard navigation **Files:** - Create: `e-commerce-internet/src/api/schoolProductConfig.js` - Modify: `e-commerce-internet/src/store/modules/user.js` - Modify: `e-commerce-internet/src/permission.js` - Modify: `e-commerce-internet/src/router/index.js` - Modify: `e-commerce-internet/src/layout/components/Sidebar/index.vue` - Create: `e-commerce-internet/tests/optional-administrative-class.static.test.cjs` **Interfaces:** - Produces `getCurrentSchoolProductConfig(): Promise<{organizationMode, studentRosterOwner}>`. - Produces `userStore.loadSchoolProductConfig()` and `userStore.hasAdminClassCapability`. - Routes that require administration-class capability set `meta.requiresAdminClass = true`. - [ ] **Step 1: Write failing static assertions** ```js assert.match(userStore, /loadSchoolProductConfig/, "user store must load server-owned school configuration"); assert.match(router, /requiresAdminClass:\s*true/, "organization routes must declare the administrative-class capability"); assert.match(permission, /hasAdminClassCapability/, "deep links must be rejected using the loaded capability"); assert.match(sidebar, /requiresAdminClass/, "sidebar must filter unavailable organization routes"); ``` - [ ] **Step 2: Run the static test and verify it fails** Run: `node tests/optional-administrative-class.static.test.cjs` from `e-commerce-internet`. Expected: assertion failure because no product-configuration client or feature metadata exists. - [ ] **Step 3: Add configuration loading and route metadata** Implement `getCurrentSchoolProductConfig` as `GET /api/school-product-config/current`. Add `schoolProductConfig` to the Pinia state, clear it on logout, and make `loadSchoolProductConfig` reuse the cached object after its first successful request. Mark school-admin faculty, major, class, and student routes with `meta: { requiresAdminClass: true }`. In the router guard, await `userStore.loadSchoolProductConfig()` for signed-in users with a school; redirect a forbidden deep link to `/index` and show `当前学校未启用该功能`. In `Sidebar`, filter routes whose own `meta` or only child `meta` has `requiresAdminClass` when `hasAdminClassCapability` is false. - [ ] **Step 4: Run static tests and build the frontend** Run: `node tests/optional-administrative-class.static.test.cjs` from `e-commerce-internet`. Expected: PASS. Run: `npm run build:prod` from `e-commerce-internet`. Expected: Vite production build completes without unresolved imports. - [ ] **Step 5: Commit frontend configuration gating** ```bash git -C e-commerce-internet add src/api/schoolProductConfig.js src/store/modules/user.js src/permission.js src/router/index.js src/layout/components/Sidebar/index.vue tests/optional-administrative-class.static.test.cjs git -C e-commerce-internet commit -m "feat: gate organization UI by school configuration" ``` ### Task 7: Add the platform configuration form and adapt the teacher student screen **Files:** - Modify: `e-commerce-internet/src/api/platformAdmin.js` - Modify: `e-commerce-internet/src/views/platformAdmin/school/index.vue` - Modify: `e-commerce-internet/src/api/teacher.js` - Modify: `e-commerce-internet/src/views/teacherEnd/student/index.vue` - Modify: `e-commerce-internet/src/layout/components/AppMain.vue` - Test: `e-commerce-internet/tests/optional-administrative-class.static.test.cjs` **Interfaces:** - Produces `getPlatformSchoolProductConfig(schoolId)` and `updatePlatformSchoolProductConfig(schoolId, data)`. - Produces `importTeachingClassRoster(teachingClassId, formData)` against Task 3's endpoint. - Teacher roster UI has two explicit variants based on `userStore.schoolProductConfig.organizationMode`. - [ ] **Step 1: Extend the failing static test for both UI variants** ```js assert.match(platformSchool, /organizationMode/, "platform school form must select an organization mode"); assert.match(teacherStudent, /TEACHING_CLASS_ONLY/, "teacher roster view must render the Zhujian branch"); assert.match(teacherStudent, /importTeachingClassRoster/, "Zhujian import must target the teaching-class roster endpoint"); assert.match(teacherStudent, /const rosterRules[\s\S]*isTeacherRosterMode[\s\S]*name[\s\S]*userName/, "Zhujian validation must require only name and student number"); ``` - [ ] **Step 2: Run static tests and verify they fail** Run: `node tests/optional-administrative-class.static.test.cjs` from `e-commerce-internet`. Expected: assertion failure because the existing student view is administrative-class-only. - [ ] **Step 3: Implement the platform form** In `platformAdmin/school/index.vue`, load the config when opening an existing school and show a required Element Plus select with labels `标准组织(行政班 + 教学班)` and `教学班制(无行政班)`. On save, first save the school, then PUT the config with the matching ownership: standard maps to `SCHOOL_ADMIN`; teaching-class-only maps to `TEACHER`. If the backend rejects a mode switch, leave the select unchanged and display the server message. - [ ] **Step 4: Implement the teacher roster branch** In `teacherEnd/student/index.vue`, retain current UI only for `ADMIN_CLASS_ENABLED`. For `TEACHING_CLASS_ONLY`: ```js const isTeacherRosterMode = computed(() => userStore.schoolProductConfig?.organizationMode === "TEACHING_CLASS_ONLY"); const rosterRules = computed(() => isTeacherRosterMode.value ? { name: [{ required: true, message: "请输入学生姓名", trigger: "blur" }], userName: [{ required: true, message: "请输入学号", trigger: "blur" }] } : standardRules); ``` Show a teaching-class selector limited to the current teacher's `TEACHING` classes. Remove faculty, major, and administrative-class selectors and columns in this mode. Build an Excel template with only `姓名、学号、性别、手机、邮箱`; send it with the selected `teachingClassId` to `importTeachingClassRoster`. Keep delete as a membership removal request with that teaching class ID. - [ ] **Step 5: Make class context explicit in AppMain** When `/api/user/selectCurrentTeachingClass` returns conflict, do not cache an arbitrary ID. Preserve a user-selected `currentTeachingClassId` only after confirming it belongs to the student; otherwise navigate to the class-selection screen and require selection before task pages execute. - [ ] **Step 6: Run static tests and production build** Run: `node tests/optional-administrative-class.static.test.cjs` from `e-commerce-internet`. Expected: PASS. Run: `npm run build:prod` from `e-commerce-internet`. Expected: PASS. - [ ] **Step 7: Commit teacher and platform UI** ```bash git -C e-commerce-internet add src/api/platformAdmin.js src/views/platformAdmin/school/index.vue src/api/teacher.js src/views/teacherEnd/student/index.vue src/layout/components/AppMain.vue tests/optional-administrative-class.static.test.cjs git -C e-commerce-internet commit -m "feat: configure and manage teacher rosters" ``` ### Task 8: Run end-to-end regression checks and publish rollout notes **Files:** - Modify: `link_commerce/docs/superpowers/specs/2026-07-30-optional-administrative-class-design.md` - Modify: `link_commerce/docs/sql/2026-07-30-school-product-config.sql` - Test: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherRosterImportTest.java` - Test: `e-commerce-internet/tests/optional-administrative-class.static.test.cjs` **Interfaces:** - Confirms one migration script can be applied before the backend release. - Confirms user-facing rollout sequence: migrate, configure Zhujian, smoke test teacher import, then enable production traffic. - [ ] **Step 1: Add final regression scenarios to the backend test suite** ```java @Test void standardSchoolStillRejectsTeachingRosterImport() { when(configService.isTeacherRosterManaged("school-standard")).thenReturn(false); ResultEntity result = controller.importTeacherRoster(rows("张三", "20260001"), "teach-1", requestFor("teacher-1", "school-standard")); assertEquals(HttpStatus.BAD_REQUEST, result.getStatusCode()); } @Test void removingZhujianMemberDoesNotDeleteStudentIdentity() { controller.deleteStudent("student-1", "teacher-1", "teach-1"); verify(teachingClassStudentMapper).deleteByStudentUserIdAndTeachingClassId("student-1", "teach-1"); verify(userinfoMapper, never()).deleteByPrimaryKey("student-1"); } ``` - [ ] **Step 2: Run complete backend and frontend verification** Run: `mvn -q test` from `link_commerce`. Expected: PASS. Run: `node tests/optional-administrative-class.static.test.cjs` from `e-commerce-internet`. Expected: PASS. Run: `npm run build:prod` from `e-commerce-internet`. Expected: PASS. - [ ] **Step 3: Perform manual release smoke tests against a non-production database** 1. Apply `2026-07-30-school-product-config.sql`. 2. Set one disposable school to `TEACHING_CLASS_ONLY` + `TEACHER`. 3. Log in as its teacher, create a teaching class, import two students, then import one of them into a second teaching class. 4. Verify both memberships remain active with `admin_class_id IS NULL`. 5. Log in as its school admin and verify faculty, major, class, and student URLs return the configured rejection. 6. Log in to a default standard school and create/import a student through the existing administrative-class flow. - [ ] **Step 4: Add rollout and rollback instructions to the design document** Document that rollback is application-only until a confirmed migration rollback is prepared; do not drop `school_product_config` or restore `admin_class_id NOT NULL` while a Zhujian membership exists. Include the SQL query that must return zero before any destructive rollback: ```sql SELECT COUNT(*) AS zhujian_memberships_without_admin_class FROM teaching_class_student tcs JOIN school_product_config cfg ON cfg.school_id = ( SELECT school_id FROM school_class sc WHERE sc.school_class_id = tcs.teaching_class_id ) WHERE cfg.organization_mode = 'TEACHING_CLASS_ONLY' AND tcs.admin_class_id IS NULL AND tcs.status = 'IN_PROGRESS'; ``` - [ ] **Step 5: Commit verification and rollout documentation** ```bash git -C link_commerce add docs/superpowers/specs/2026-07-30-optional-administrative-class-design.md docs/sql/2026-07-30-school-product-config.sql src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherRosterImportTest.java git -C link_commerce commit -m "test: verify optional administrative class rollout" git -C e-commerce-internet add tests/optional-administrative-class.static.test.cjs git -C e-commerce-internet commit -m "test: verify school mode frontend" ```