feat(education): add module application shell
This commit is contained in:
@@ -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";
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
}
|
||||
@@ -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, "教育模块未启用,请联系管理员");
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 属于 education 模块的 web 封装
|
||||
*/
|
||||
package cn.iocoder.yudao.module.education.framework.web;
|
||||
@@ -0,0 +1,8 @@
|
||||
/**
|
||||
* education 模块,我们放教育业务。
|
||||
* 例如说:课程、练习、题库、考试等等
|
||||
*
|
||||
* 1. Controller URL:以 /education/ 开头,避免和其它 Module 冲突
|
||||
* 2. DataObject 表名:以 education_ 开头,方便在数据库中区分
|
||||
*/
|
||||
package cn.iocoder.yudao.module.education;
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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 能力");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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
|
||||
3
yudao-module-education/src/test/resources/logback.xml
Normal file
3
yudao-module-education/src/test/resources/logback.xml
Normal file
@@ -0,0 +1,3 @@
|
||||
<configuration>
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
|
||||
</configuration>
|
||||
1
yudao-module-education/src/test/resources/sql/clean.sql
Normal file
1
yudao-module-education/src/test/resources/sql/clean.sql
Normal file
@@ -0,0 +1 @@
|
||||
SELECT 1;
|
||||
@@ -0,0 +1 @@
|
||||
SELECT 1;
|
||||
Reference in New Issue
Block a user