feat(education): add module application shell

This commit is contained in:
2026-07-27 16:31:39 +08:00
parent 7426579863
commit 11e9cc6854
22 changed files with 536 additions and 8 deletions

View File

@@ -0,0 +1,119 @@
# yudao-module-education
教育业务模块,提供课程、练习、题库、考试等教育业务功能。
## 当前状态:应用外壳 (Shell)
此模块目前处于**应用外壳**阶段,仅提供:
- 模块骨架与包结构
- 能力探测端点 (`/education/capability`)
- 独立的功能开关配置
- 错误码常量
- 权限与菜单种子数据(角色授权由管理员按租户完成)
- 增量 SQL 交付约定
无业务表,无虚假 CRUD。
## 功能配置
`application.yaml` 或对应 profile 中配置:
```yaml
yudao:
education:
enabled: true # 是否启用教育模块,默认 false
version: 1.0.0 # 模块版本号
```
- `yudao.education.enabled=true`启用模块Controller 注册、Swagger 分组可见)
- `yudao.education.enabled=false`(默认):禁用模块,所有教育端点不可达
## API
### 管理后台 - 能力信息
```
GET /admin-api/education/capability
```
- 权限:`education:capability`
- 响应示例:
```json
{
"code": 0,
"msg": "成功",
"data": {
"module": "education",
"enabled": true,
"version": "1.0.0",
"capabilities": ["shell"]
}
}
```
### 错误码
| 错误码 | 说明 |
|--------|------|
| 1_005_001_000 | 教育模块未启用 |
## 构建与运行
### 单独编译测试
```bash
# 编译 education 模块
mvn compile -pl yudao-module-education -am
# 运行 education 模块单元测试
mvn test -pl yudao-module-education -am
```
### 整体编译(含 server
```bash
# 编译全量member + education + system + infra + server
mvn compile -pl yudao-server -am
# 打包(跳过测试加速)
mvn package -pl yudao-server -am -DskipTests
```
### 启动验证
1. 确保 `yudao.education.enabled=true`
2. 启动 `yudao-server`
3. 访问 Swagger UI 查看 `education` 分组
4. 调用 `GET /admin-api/education/capability`
## SQL 应用
```bash
# 应用种子数据(菜单 + 权限定义;执行后由管理员为目标租户角色授权)
mysql -u root -p ruoyi-vue-pro < sql/mysql/education/000-education-seed.sql
# 回滚
mysql -u root -p ruoyi-vue-pro < sql/mysql/education/000-education-rollback.sql
```
## SQL 交付约定
- 所有 Education SQL 文件存放在 `sql/mysql/education/` 目录下
- 文件命名:`NNN-描述.sql`NNN 为三位递增序号)
- 每个正向脚本应有对应的回滚脚本
- schema 文件仅包含 DDLseed 文件仅包含 DML
- **不修改**项目根目录的 `ruoyi-vue-pro.sql` 巨量全量转储
## 前端状态
**当前工作区未检出完整的前端源码。** `yudao-ui/yudao-ui-admin-vue3/` 仅包含部分 MES 相关文件(`src/api/mes/``src/views/mes/`),缺少 `package.json``router/``store/``config/` 等核心框架文件。
因此:
- **管理后台教育菜单项**:仅在后端通过 SQL 种子数据注册了 `system_menu` 记录ID 6800-6801。前端无路由/页面组件可渲染,菜单在管理后台不会显示。
- **Student Web/H5 应用外壳**:前端源码不存在,无法建立。
**阻塞项**:完整前端源码(含 router、store、package.json是后续前端集成的必要前提。一旦前端源码就位
1. 在 Vue3 admin 的路由中添加 `/education` 路由项,绑定 Education 菜单组件
2. 添加 `src/api/education/` API 封装层
3. Student Web/H5 端如需要独立入口,需新建对应前端项目

View File

@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao</artifactId>
<version>${revision}</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yudao-module-education</artifactId>
<packaging>jar</packaging>
<name>${project.artifactId}</name>
<description>
education 模块,我们放教育业务。
例如说:课程、练习、题库、考试等等
</description>
<dependencies>
<!-- Web 与权限相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-system</artifactId>
<version>${revision}</version>
</dependency>
<!-- Test 测试相关 -->
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.education.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.validation.annotation.Validated;
/**
* 教育模块配置属性
*
* @author 恭学教育
*/
@ConfigurationProperties(prefix = "yudao.education")
@Validated
@Data
public class EducationProperties {
/**
* 是否启用教育模块
*/
private boolean enabled = false;
/**
* 教育模块版本号
*/
private String version = "1.0.0";
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.education.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.education.config.EducationProperties;
import cn.iocoder.yudao.module.education.controller.admin.vo.EducationCapabilityRespVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@Tag(name = "管理后台 - 教育模块")
@RestController
@RequestMapping("/education")
@Validated
@ConditionalOnProperty(prefix = "yudao.education", name = "enabled", havingValue = "true")
public class EducationCapabilityController {
@Resource
private EducationProperties educationProperties;
@GetMapping("/capability")
@Operation(summary = "获得教育模块能力信息")
@PreAuthorize("@ss.hasPermission('education:capability')")
public CommonResult<EducationCapabilityRespVO> getCapability() {
EducationCapabilityRespVO resp = EducationCapabilityRespVO.builder()
.module("education")
.enabled(educationProperties.isEnabled())
.version(educationProperties.getVersion())
.capabilities(List.of("shell"))
.build();
return success(resp);
}
}

View File

@@ -0,0 +1,30 @@
package cn.iocoder.yudao.module.education.controller.admin.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Schema(description = "管理后台 - 教育模块能力信息 Response VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class EducationCapabilityRespVO {
@Schema(description = "模块名称", example = "education")
private String module;
@Schema(description = "是否启用", example = "true")
private boolean enabled;
@Schema(description = "模块版本", example = "1.0.0")
private String version;
@Schema(description = "支持的能力列表")
private List<String> capabilities;
}

View File

@@ -0,0 +1,15 @@
package cn.iocoder.yudao.module.education.enums;
import cn.iocoder.yudao.framework.common.exception.ErrorCode;
/**
* Education 错误码枚举类
* <p>
* education 系统,使用 1-005-000-000 段
*/
public interface ErrorCodeConstants {
// ========== 通用模块 1-005-001-000 ==========
ErrorCode EDUCATION_DISABLED = new ErrorCode(1_005_001_000, "教育模块未启用,请联系管理员");
}

View File

@@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.education.framework.web.config;
import cn.iocoder.yudao.framework.swagger.config.YudaoSwaggerAutoConfiguration;
import cn.iocoder.yudao.module.education.config.EducationProperties;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* education 模块的 web 组件的 Configuration
*
* @author 恭学教育
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(EducationProperties.class)
public class EducationWebConfiguration {
/**
* education 模块的 API 分组
*/
@Bean
@ConditionalOnProperty(prefix = "yudao.education", name = "enabled", havingValue = "true")
public GroupedOpenApi educationGroupedOpenApi() {
return YudaoSwaggerAutoConfiguration.buildGroupedOpenApi("education");
}
}

View File

@@ -0,0 +1,4 @@
/**
* 属于 education 模块的 web 封装
*/
package cn.iocoder.yudao.module.education.framework.web;

View File

@@ -0,0 +1,8 @@
/**
* education 模块,我们放教育业务。
* 例如说:课程、练习、题库、考试等等
*
* 1. Controller URL以 /education/ 开头,避免和其它 Module 冲突
* 2. DataObject 表名:以 education_ 开头,方便在数据库中区分
*/
package cn.iocoder.yudao.module.education;

View File

@@ -0,0 +1,50 @@
package cn.iocoder.yudao.module.education.config;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.ActiveProfiles;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link EducationProperties} 的单元测试
*
* @author 恭学教育
*/
@SpringBootTest(classes = EducationPropertiesTest.Config.class,
properties = {
"yudao.education.enabled=true",
"yudao.education.version=2.0.0-test"
})
@ActiveProfiles("unit-test")
public class EducationPropertiesTest {
@Configuration
@EnableConfigurationProperties(EducationProperties.class)
static class Config {
}
@Resource
private EducationProperties properties;
@Test
public void testEnabled() {
assertTrue(properties.isEnabled(), "教育模块应启用");
}
@Test
public void testVersion() {
assertEquals("2.0.0-test", properties.getVersion(), "版本号应匹配");
}
@Test
public void testDefaults() {
EducationProperties defaults = new EducationProperties();
assertFalse(defaults.isEnabled(), "默认应禁用");
assertEquals("1.0.0", defaults.getVersion(), "默认版本应为 1.0.0");
}
}

View File

@@ -0,0 +1,54 @@
package cn.iocoder.yudao.module.education.controller.admin;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.education.config.EducationProperties;
import cn.iocoder.yudao.module.education.controller.admin.vo.EducationCapabilityRespVO;
import jakarta.annotation.Resource;
import org.junit.jupiter.api.Test;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;
import static org.junit.jupiter.api.Assertions.*;
/**
* {@link EducationCapabilityController} 的单元测试
*
* @author 恭学教育
*/
@SpringBootTest(classes = EducationCapabilityControllerTest.Config.class,
properties = {
"yudao.education.enabled=true",
"yudao.education.version=1.0.0-test"
},
webEnvironment = SpringBootTest.WebEnvironment.NONE)
@ActiveProfiles("unit-test")
public class EducationCapabilityControllerTest {
@Configuration
@EnableConfigurationProperties(EducationProperties.class)
@Import(EducationCapabilityController.class)
static class Config {
}
@Resource
private EducationCapabilityController controller;
@Test
public void testGetCapability() {
CommonResult<EducationCapabilityRespVO> result = controller.getCapability();
assertTrue(result.isSuccess(), "响应应为成功");
assertNotNull(result.getData(), "响应数据不应为空");
EducationCapabilityRespVO data = result.getData();
assertEquals("education", data.getModule(), "模块名应为 education");
assertTrue(data.isEnabled(), "模块应启用");
assertEquals("1.0.0-test", data.getVersion(), "版本应匹配");
assertNotNull(data.getCapabilities(), "能力列表不应为空");
assertTrue(data.getCapabilities().contains("shell"), "应包含 shell 能力");
}
}

View File

@@ -0,0 +1,36 @@
package cn.iocoder.yudao.module.education.framework.web.config;
import cn.iocoder.yudao.module.education.controller.admin.EducationCapabilityController;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import static org.assertj.core.api.Assertions.assertThat;
/**
* {@link EducationWebConfiguration} 的单元测试
*
* @author 恭学教育
*/
class EducationWebConfigurationTest {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withUserConfiguration(EducationWebConfiguration.class, EducationCapabilityController.class);
@Test
void shouldNotRegisterEducationWebBeansByDefault() {
contextRunner.run(context -> {
assertThat(context).doesNotHaveBean(EducationCapabilityController.class);
assertThat(context).doesNotHaveBean("educationGroupedOpenApi");
});
}
@Test
void shouldRegisterEducationWebBeansWhenEnabled() {
contextRunner.withPropertyValues("yudao.education.enabled=true")
.run(context -> {
assertThat(context).hasSingleBean(EducationCapabilityController.class);
assertThat(context).hasBean("educationGroupedOpenApi");
});
}
}

View File

@@ -0,0 +1,35 @@
spring:
main:
lazy-initialization: true # 开启懒加载,加快速度
banner-mode: off # 单元测试,禁用 Banner
--- #################### 数据库相关配置 ####################
spring:
# 数据源配置项
datasource:
name: ruoyi-vue-pro
url: jdbc:h2:mem:testdb;MODE=MYSQL;DATABASE_TO_UPPER=false;NON_KEYWORDS=value; # MODE 使用 MySQL 模式DATABASE_TO_UPPER 配置表和字段使用小写
driver-class-name: org.h2.Driver
username: sa
password:
druid:
async-init: true # 单元测试,异步初始化 Druid 连接池,提升启动速度
initial-size: 1 # 单元测试,配置为 1提升启动速度
# Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
data:
redis:
host: 127.0.0.1 # 地址
port: 16379 # 端口(单元测试,使用 16379 端口)
database: 0 # 数据库索引
mybatis:
lazy-initialization: true # 单元测试,设置 MyBatis Mapper 延迟加载,加速每个单元测试
--- #################### 恭学相关配置 ####################
# 恭学配置项,设置当前项目所有自定义的配置
yudao:
info:
base-package: cn.iocoder.yudao.module

View File

@@ -0,0 +1,3 @@
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
</configuration>

View File

@@ -0,0 +1 @@
SELECT 1;

View File

@@ -0,0 +1 @@
SELECT 1;