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-cl...

212 lines
10 KiB
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 教师自有教学班与成员导入 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:** 在教学班专属学校中隔离教师可见班级,并用仅含姓名和学号的模板导入教学班成员。
**Architecture:** 班级分页接口接收操作人 ID,并在服务层将教学班专属学校的查询条件收敛为操作人所属学校、教学班类型和创建人。前端根据学校配置选择导入端点与模板:教学班专属模式使用已有的 JWT 教师名单接口,组织型模式保留原接口。
**Tech Stack:** Spring Boot、MyBatis Generator Example、JUnit 5/Mockito、Vue 3、Vite、Node.js 静态契约测试、SheetJS。
## Global Constraints
- 教学班专属模式由 `SchoolProductConfig.studentRosterOwner === "TEACHER"`(前端)和 `SchoolProductConfigService.isTeacherRosterManaged(schoolId)`(后端)判断。
- 教师只能读取、初始化或维护 `class_type=TEACHING` 且 `created_by=当前教师` 的班级。
- 教学班专属成员导入模板的唯一列为 `姓名` 与 `学号`;不得包含性别、手机、邮箱、院系、专业或行政班。
- 启用行政班的学校继续使用既有通用成员导入端点和模板。
---
## File structure
| File | Responsibility |
| --- | --- |
| `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/SchoolService.java` | 声明可选创建人、班级类型的分页班级查询。 |
| `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/impl/SchoolServiceImpl.java` | 将教师身份范围转为 MyBatis 查询条件。 |
| `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java` | 从操作人确定学校和教学班专属模式,并调用受限查询。 |
| `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/importDto/TeacherRosterStudentImportDTO.java` | 定义两列教师名单 Excel 表头。 |
| `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherRosterImportTest.java` | 验证两列导入不会写联系人字段。 |
| `link_commerce/src/test/java/com/sztzjy/linkCommerce/service/impl/SchoolServiceImplTest.java` | 验证教学班与创建人查询条件。 |
| `e-commerce-internet/src/api/teacher.js` | 封装教师教学班名单上传 API。 |
| `e-commerce-internet/src/views/teacherEnd/class/index.vue` | 传递操作人、按模式上传成员并生成正确模板。 |
| `e-commerce-internet/tests/teacher-owned-class-roster.static.test.cjs` | 静态验证前端的请求、模板与模式分支。 |
### Task 1: 后端班级可见范围
**Files:**
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/SchoolService.java`
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/service/impl/SchoolServiceImpl.java`
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java`
- Create: `link_commerce/src/test/java/com/sztzjy/linkCommerce/service/impl/SchoolServiceImplTest.java`
**Interfaces:**
- Consumes: `operatorId` query parameter and `SchoolProductConfigService.isTeacherRosterManaged(String schoolId)`.
- Produces: `SchoolService.seleteSchoolClass(..., String createdBy, String classType)` with both optional filters.
- [ ] **Step 1: Write the failing service test.**
```java
@Test
void selectClassesForTeacherRosterModeAddsOwnerAndTeachingClassCriteria() {
SchoolServiceImpl service = serviceWithMockMappers();
service.seleteSchoolClass(1, 10, "school-1", "", "", "", "teacher-1", "TEACHING");
ArgumentCaptor<SchoolClassExample> example = ArgumentCaptor.forClass(SchoolClassExample.class);
verify(service.schoolClassMapper).selectByExample(example.capture());
assertTrue(example.getValue().getOredCriteria().get(0).getAllCriteria().stream()
.anyMatch(c -> "createdBy =".equals(c.getCondition()) && "teacher-1".equals(c.getValue())));
assertTrue(example.getValue().getOredCriteria().get(0).getAllCriteria().stream()
.anyMatch(c -> "classType =".equals(c.getCondition()) && "TEACHING".equals(c.getValue())));
}
```
- [ ] **Step 2: Run the new test and verify it fails because the overload is absent.**
Run: `mvn -q -Dtest=SchoolServiceImplTest#selectClassesForTeacherRosterModeAddsOwnerAndTeachingClassCriteria test` from `link_commerce`.
Expected: compilation failure because the seven-argument `seleteSchoolClass` method does not exist.
- [ ] **Step 3: Implement optional owner/type filters and controller authorization.**
```java
if (StringUtils.isNotBlank(createdBy)) {
criteria.andCreatedByEqualTo(createdBy);
}
if (StringUtils.isNotBlank(classType)) {
criteria.andClassTypeEqualTo(classType);
}
if (isSchoolTeacher(operator) && isTeacherRosterMode(operator.getSchoolId())) {
return schoolService.seleteSchoolClass(index, size, operator.getSchoolId(), className,
classSn, null, operatorId, "TEACHING");
}
```
- [ ] **Step 4: Run the focused back-end test and existing initialization authorization tests.**
Run: `mvn -q -Dtest=SchoolServiceImplTest,UserControllerTeacherAdminTest test` from `link_commerce`.
Expected: all tests pass; non-owner initialization tests remain rejected and owner initialization tests pass.
### Task 2: 两列教师名单导入
**Files:**
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/entity/importDto/TeacherRosterStudentImportDTO.java`
- Modify: `link_commerce/src/main/java/com/sztzjy/linkCommerce/controller/stu/UserController.java`
- Modify: `link_commerce/src/test/java/com/sztzjy/linkCommerce/controller/stu/TeacherRosterImportTest.java`
**Interfaces:**
- Consumes: Excel headers `姓名` and `学号`.
- Produces: `importTeacherRosterRows(List<TeacherRosterStudentImportDTO>, String, String)` that creates students without contact fields.
- [ ] **Step 1: Write the failing test.**
```java
verify(controller.userinfoMapper).insertSelective(userCaptor.capture());
assertNull(userCaptor.getValue().getSex());
assertNull(userCaptor.getValue().getPhone());
assertNull(userCaptor.getValue().getEmail());
assertEquals(2, TeacherRosterStudentImportDTO.class.getDeclaredFields().length);
```
- [ ] **Step 2: Run the focused test and verify it fails because the DTO has five fields.**
Run: `mvn -q -Dtest=TeacherRosterImportTest test` from `link_commerce`.
Expected: failure reporting five declared DTO fields.
- [ ] **Step 3: Restrict the DTO and importer to the two identity fields.**
```java
public class TeacherRosterStudentImportDTO {
@ExcelProperty("姓名") private String name;
@ExcelProperty("学号") private String username;
}
student.setName(name);
student.setUsername(username);
// Do not populate sex, phone, or email from a teacher-roster import.
```
- [ ] **Step 4: Run the focused import tests.**
Run: `mvn -q -Dtest=TeacherRosterImportTest test` from `link_commerce`.
Expected: student creation/reuse and membership insertion pass with no administrative-class or contact data.
### Task 3: 前端模式化列表与成员导入
**Files:**
- Modify: `e-commerce-internet/src/api/teacher.js`
- Modify: `e-commerce-internet/src/views/teacherEnd/class/index.vue`
- Create: `e-commerce-internet/tests/teacher-owned-class-roster.static.test.cjs`
**Interfaces:**
- Consumes: `schoolProductConfig.studentRosterOwner` and the selected teaching class ID.
- Produces: `importTeacherRosterMembers(teachingClassId, FormData)` and a two-column member template in teacher-roster mode.
- [ ] **Step 1: Write the failing static contract test.**
```js
assert.match(classView, /operatorId:\s*currentUserId\.value/);
assert.match(classView, /isTeacherRosterMode\.value[\s\S]*importTeacherRosterMembers/);
assert.match(classView, /\["姓名",\s*"学号"\]/);
assert.doesNotMatch(rosterTemplateBlock, /性别|手机号|邮箱|所属院系|所属专业|行政班/);
```
- [ ] **Step 2: Run the test and verify it fails because the view uses the generic upload endpoint and eight-column template.**
Run: `node tests/teacher-owned-class-roster.static.test.cjs` from `e-commerce-internet`.
Expected: assertion failure finding `/uploadTeachingClassStudentMembers` and legacy headers in the teacher-roster branch.
- [ ] **Step 3: Implement API selection, list operation identity, and templates.**
```js
export function importTeacherRosterMembers(teachingClassId, data) {
return request({
url: `/api/user/teaching-classes/${teachingClassId}/students/import`,
method: "POST",
data,
headers: { "Content-Type": "multipart/form-data" },
});
}
const memberHeaders = isTeacherRosterMode.value
? ["姓名", "学号"]
: ["所属院系", "所属专业", "行政班", "学号", "学生姓名", "性别", "手机号", "邮箱"];
```
- [ ] **Step 4: Run the static contract test and production build.**
Run: `node tests/teacher-owned-class-roster.static.test.cjs; npm run build:prod` from `e-commerce-internet`.
Expected: contract test and Vite production build succeed.
### Task 4: Integrated verification
**Files:**
- Modify: no production files expected.
**Interfaces:**
- Consumes: all changes from Tasks 1–3.
- Produces: verified back-end and front-end deliverable.
- [ ] **Step 1: Run all directly affected back-end tests.**
Run: `mvn -q -Dtest=SchoolServiceImplTest,TeacherRosterImportTest,UserControllerTeacherAdminTest test` from `link_commerce`.
Expected: all selected tests pass.
- [ ] **Step 2: Run relevant front-end static tests and production build.**
Run: `node tests/teacher-owned-class-roster.static.test.cjs; node tests/teacher-student-roster-mode.static.test.cjs; node tests/class-table-product-config.static.test.cjs; npm run build:prod` from `e-commerce-internet`.
Expected: every command exits 0.
- [ ] **Step 3: Inspect the diff before handoff.**
Run: `git -C link_commerce diff --check; git -C e-commerce-internet diff --check; git -C link_commerce status --short; git -C e-commerce-internet status --short`.
Expected: no whitespace errors; only intended tracked-file modifications are attributed to this feature, while existing untracked user files remain untouched.