66 lines
3.1 KiB
Markdown
66 lines
3.1 KiB
Markdown
|
|
# 开发日志 - 2026-03-19
|
|||
|
|
|
|||
|
|
## Service 层重构
|
|||
|
|
|
|||
|
|
### 背景
|
|||
|
|
|
|||
|
|
根据项目统一开发规范要求,Service 层应采用 **接口 + 实现类** 的结构:
|
|||
|
|
|
|||
|
|
```
|
|||
|
|
service/
|
|||
|
|
├── XxxService.java ← 接口,继承 IService<Entity>
|
|||
|
|
└── impl/
|
|||
|
|
└── XxxServiceImpl.java ← 实现类,继承 ServiceImpl 并实现接口
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
### 重构内容
|
|||
|
|
|
|||
|
|
将以下 5 个服务类从实现类拆分为接口 + 实现类结构:
|
|||
|
|
|
|||
|
|
| 服务类 | 接口文件 | 实现类文件 | 状态 |
|
|||
|
|
|--------|---------|-----------|------|
|
|||
|
|
| `ThemeService` | `service/ThemeService.java` | `service/impl/ThemeServiceImpl.java` | ✅ |
|
|||
|
|
| `ResourceLibraryService` | `service/ResourceLibraryService.java` | `service/impl/ResourceLibraryServiceImpl.java` | ✅ |
|
|||
|
|
| `CourseLessonService` | `service/CourseLessonService.java` | `service/impl/CourseLessonServiceImpl.java` | ✅ |
|
|||
|
|
| `CourseCollectionService` | `service/CourseCollectionService.java` | `service/impl/CourseCollectionServiceImpl.java` | ✅ |
|
|||
|
|
| `FileStorageService` | 无需拆分(纯工具类) | 保持原结构 | ✅ |
|
|||
|
|
|
|||
|
|
### 重构详情
|
|||
|
|
|
|||
|
|
#### 1. ThemeService
|
|||
|
|
- **接口方法**:`findAll()`, `findById()`, `create()`, `update()`, `delete()`, `reorder()`
|
|||
|
|
- **实现类**:`ThemeServiceImpl` 继承 `ServiceImpl<ThemeMapper, Theme>` 并实现 `ThemeService` 接口
|
|||
|
|
|
|||
|
|
#### 2. ResourceLibraryService
|
|||
|
|
- **接口方法**:`findAllLibraries()`, `findLibraryById()`, `createLibrary()`, `updateLibrary()`, `deleteLibrary()`, `findAllItems()`, `findItemById()`, `createItem()`, `updateItem()`, `deleteItem()`, `batchDeleteItems()`, `getStats()`
|
|||
|
|
- **实现类**:`ResourceLibraryServiceImpl` 继承 `ServiceImpl<ResourceLibraryMapper, ResourceLibrary>` 并实现 `ResourceLibraryService` 接口
|
|||
|
|
|
|||
|
|
#### 3. CourseLessonService
|
|||
|
|
- **接口方法**:`findByCourseId()`, `findById()`, `findByType()`, `create()`, `update()`, `delete()`, `reorder()`, `findSteps()`, `createStep()`, `updateStep()`, `deleteStep()`, `reorderSteps()`, `findCourseLessonsForTeacher()`
|
|||
|
|
- **实现类**:`CourseLessonServiceImpl` 继承 `ServiceImpl<CourseLessonMapper, CourseLesson>` 并实现 `CourseLessonService` 接口
|
|||
|
|
|
|||
|
|
#### 4. CourseCollectionService
|
|||
|
|
- **接口方法**:`findTenantCollections()`, `getCollectionDetail()`, `pageCollections()`, `getPackagesByCollection()`, `createCollection()`, `setCollectionPackages()`, `updateCollection()`, `deleteCollection()`, `publishCollection()`, `archiveCollection()`, `republishCollection()`, `withdrawCollection()`, `submitCollection()`, `rejectCollection()`, `renewTenantCollection()`
|
|||
|
|
- **实现类**:`CourseCollectionServiceImpl` 继承 `ServiceImpl<CourseCollectionMapper, CourseCollection>` 并实现 `CourseCollectionService` 接口
|
|||
|
|
- **依赖注入**:注入 `CourseLessonService` 用于查询课程环节
|
|||
|
|
|
|||
|
|
### 验证结果
|
|||
|
|
|
|||
|
|
```bash
|
|||
|
|
export JAVA_HOME="/f/Java/jdk-17"
|
|||
|
|
mvn compile -DskipTests
|
|||
|
|
```
|
|||
|
|
|
|||
|
|
**编译结果**:✅ BUILD SUCCESS
|
|||
|
|
|
|||
|
|
### 影响范围
|
|||
|
|
|
|||
|
|
- Controller 层引用保持不变(Spring 自动注入接口实现)
|
|||
|
|
- 其他服务层调用保持不变
|
|||
|
|
- 无数据库变更
|
|||
|
|
- 无 API 变更
|
|||
|
|
|
|||
|
|
### 备注
|
|||
|
|
|
|||
|
|
- `FileStorageService` 是纯工具类服务,不涉及数据库操作,无需继承 `IService`,保持当前结构即可
|