将 sys_config 从 system 迁移到 infra 模块,并进行改名~

This commit is contained in:
YunaiV 2021-01-21 09:13:51 +08:00
parent 17cb37f577
commit b005e062bb
32 changed files with 339 additions and 213 deletions

View File

@ -24,7 +24,6 @@
<!-- 统一依赖管理 -->
<spring.boot.version>2.4.2</spring.boot.version>
<!-- <ruoyi.version>3.3.0</ruoyi.version>-->
<!-- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
<!-- <maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>-->
<!-- <druid.version>1.2.2</druid.version>-->
@ -48,7 +47,7 @@
<mysql-connector-java.version>5.1.46</mysql-connector-java.version>
<druid.version>1.2.4</druid.version>
<mybatis-plus.version>3.4.1</mybatis-plus.version>
<redisson.version>3.13.6</redisson.version>
<redisson.version>3.14.1</redisson.version>
<!-- 监控相关 -->
<skywalking.version>8.3.0</skywalking.version>
<!-- 工具类相关 -->
@ -142,6 +141,12 @@
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>${knife4j.version}</version>
<exclusions>
<exclusion>
<artifactId>mapstruct</artifactId>
<groupId>org.mapstruct</groupId> <!-- 避免冲突 -->
</exclusion>
</exclusions>
</dependency>
<!-- DB 相关 -->

View File

@ -1,62 +1,62 @@
import request from '@/utils/request'
// 查询参数列表
export function listConfig(query) {
return request({
url: '/system/config/page',
method: 'get',
params: query
})
}
// 查询参数详细
export function getConfig(configId) {
return request({
url: '/system/config/get?id=' + configId,
method: 'get'
})
}
// 根据参数键名查询参数值
export function getConfigKey(configKey) {
return request({
url: '/system/config/get-value-by-key?key=' + configKey,
method: 'get'
})
}
// 新增参数配置
export function addConfig(data) {
return request({
url: '/system/config/create',
method: 'post',
data: data
})
}
// 修改参数配置
export function updateConfig(data) {
return request({
url: '/system/config/update',
method: 'put',
data: data
})
}
// 删除参数配置
export function delConfig(configId) {
return request({
url: '/system/config/delete?id=' + configId,
method: 'delete'
})
}
// 导出参数
export function exportConfig(query) {
return request({
url: '/system/config/export',
method: 'get',
params: query,
responseType: 'blob'
})
}
import request from '@/utils/request'
// 查询参数列表
export function listConfig(query) {
return request({
url: '/infra/config/page',
method: 'get',
params: query
})
}
// 查询参数详细
export function getConfig(configId) {
return request({
url: '/infra/config/get?id=' + configId,
method: 'get'
})
}
// 根据参数键名查询参数值
export function getConfigKey(configKey) {
return request({
url: '/infra/config/get-value-by-key?key=' + configKey,
method: 'get'
})
}
// 新增参数配置
export function addConfig(data) {
return request({
url: '/infra/config/create',
method: 'post',
data: data
})
}
// 修改参数配置
export function updateConfig(data) {
return request({
url: '/infra/config/update',
method: 'put',
data: data
})
}
// 删除参数配置
export function delConfig(configId) {
return request({
url: '/infra/config/delete?id=' + configId,
method: 'delete'
})
}
// 导出参数
export function exportConfig(query) {
return request({
url: '/infra/config/export',
method: 'get',
params: query,
responseType: 'blob'
})
}

View File

@ -304,7 +304,10 @@ export default {
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
const queryParams = this.addDateRange(this.queryParams, [
this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
]);
this.$confirm('是否确认导出所有参数数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",

View File

@ -0,0 +1,16 @@
package cn.iocoder.dashboard.framework.apollo.core;
/**
* 针对 {@link com.ctrip.framework.apollo.core.ConfigConsts} 的补充主要增加
*
* 1. apollo.jdbc.* 配置项的枚举
*
* @author 芋道源码
*/
public class ConfigConsts {
public static final String APOLLO_JDBC_URL = "apollo.jdbc.url";
public static final String APOLLO_JDBC_USERNAME = "apollo.jdbc.username";
public static final String APOLLO_JDBC_PASSWORD = "apollo.jdbc.password";
}

View File

@ -1,8 +1,9 @@
package cn.iocoder.dashboard.framework.apollo.internals;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.dashboard.framework.apollo.core.ConfigConsts;
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
import com.ctrip.framework.apollo.Apollo;
import com.ctrip.framework.apollo.build.ApolloInjector;
import com.ctrip.framework.apollo.core.utils.ApolloThreadFactory;
@ -59,12 +60,9 @@ public class DBConfigRepository extends AbstractConfigRepository {
this.m_namespace = namespace;
this.propertiesFactory = ApolloInjector.getInstance(PropertiesFactory.class);
this.m_configUtil = ApolloInjector.getInstance(ConfigUtil.class);
// TODO 优化到配置
String url = "jdbc:mysql://127.0.1:33061/ruoyi-vue-pro?useSSL=false&useUnicode=true&characterEncoding=UTF-8&serverTimezone=CTT";
String username = "root";
String password = "123456";
// DataSource dataSource = DataSourceBuilder.create().url(url).username(username).password(password).build();
DataSource dataSource = new DriverManagerDataSource(url, username, password);
// 初始化 DB
DataSource dataSource = new DriverManagerDataSource(System.getProperty(ConfigConsts.APOLLO_JDBC_URL),
System.getProperty(ConfigConsts.APOLLO_JDBC_USERNAME), System.getProperty(ConfigConsts.APOLLO_JDBC_PASSWORD));
this.jdbcTemplate = new JdbcTemplate(dataSource);
// 初始化加载
@ -76,7 +74,7 @@ public class DBConfigRepository extends AbstractConfigRepository {
@Override
protected void sync() {
// 第一步尝试获取配置
List<SysConfigDO> configs = this.loadConfigIfUpdate(this.maxUpdateTime);
List<InfConfigDO> configs = this.loadConfigIfUpdate(this.maxUpdateTime);
if (CollUtil.isEmpty(configs)) { // 如果没有更新则返回
return;
}
@ -111,7 +109,7 @@ public class DBConfigRepository extends AbstractConfigRepository {
return ConfigSourceType.REMOTE;
}
private Properties buildProperties(List<SysConfigDO> configs) {
private Properties buildProperties(List<InfConfigDO> configs) {
Properties properties = propertiesFactory.getPropertiesInstance();
configs.stream().filter(config -> 0 == config.getDeleted()) // 过滤掉被删除的配置
.forEach(config -> properties.put(config.getKey(), config.getValue()));
@ -145,7 +143,7 @@ public class DBConfigRepository extends AbstractConfigRepository {
* @param maxUpdateTime 当前配置的最大更新时间
* @return 配置列表
*/
private List<SysConfigDO> loadConfigIfUpdate(Date maxUpdateTime) {
private List<InfConfigDO> loadConfigIfUpdate(Date maxUpdateTime) {
// 第一步判断是否要更新
boolean isUpdate = maxUpdateTime == null; // 如果更新时间为空说明 DB 一定有新数据
if (!isUpdate) {
@ -159,12 +157,12 @@ public class DBConfigRepository extends AbstractConfigRepository {
}
private boolean existsNewConfig(Date maxUpdateTime) {
return jdbcTemplate.query("SELECT id FROM sys_config WHERE update_time > ? LIMIT 1",
return jdbcTemplate.query("SELECT id FROM inf_config WHERE update_time > ? LIMIT 1",
ResultSet::next, maxUpdateTime);
}
private List<SysConfigDO> getSysConfigList() {
return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM sys_config", new BeanPropertyRowMapper<>(SysConfigDO.class));
private List<InfConfigDO> getSysConfigList() {
return jdbcTemplate.query("SELECT `key`, `value`, update_time, deleted FROM inf_config", new BeanPropertyRowMapper<>(InfConfigDO.class));
}
}

View File

@ -1 +1,13 @@
/**
* 配置中心客户端基于 Apollo Client 进行简化
*
* 差别在于我们使用 {@link cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO} 表作为配置源
* 当然功能肯定也会相对少些满足最小化诉求
*
* 1. 项目初始化时可以使用 SysConfigDO 表的配置
* 2. 使用 Spring @Value 可以注入属性
* 3. SysConfigDO 表的配置修改时注入到 @Value 的属性可以刷新
*
* 另外整个包结构会参考 Apollo 为主方便维护与理解
*/
package cn.iocoder.dashboard.framework.apollo;

View File

@ -8,6 +8,11 @@ import com.ctrip.framework.apollo.internals.ConfigRepository;
import com.ctrip.framework.apollo.internals.DefaultConfig;
import com.ctrip.framework.apollo.spi.ConfigFactory;
/**
* 基于 DB ConfigFactory 实现类
*
* @author 芋道源码
*/
public class DBConfigFactory implements ConfigFactory {
@Override
@ -21,7 +26,7 @@ public class DBConfigFactory implements ConfigFactory {
}
private ConfigRepository createDBConfigRepository(String namespace) {
return new DBConfigRepository(namespace); // TODO 芋艿看看怎么优化
return new DBConfigRepository(namespace);
}
}

View File

@ -0,0 +1,63 @@
package cn.iocoder.dashboard.framework.apollo.spring.boot;
import cn.iocoder.dashboard.framework.apollo.core.ConfigConsts;
import com.google.common.base.Strings;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.core.Ordered;
import org.springframework.core.env.ConfigurableEnvironment;
/**
* {@link com.ctrip.framework.apollo.spring.boot.ApolloApplicationContextInitializer} 的补充目前的目的有
*
* 1. 将自定义的 apollo.jdbc 设置到 System 变量中
*
* @author 芋道源码
*/
public class ApolloApplicationContextInitializer implements EnvironmentPostProcessor, Ordered {
/**
* 优先级更高要早于 Apollo ApolloApplicationContextInitializer 的初始化
*/
public static final int DEFAULT_ORDER = -1;
private int order = DEFAULT_ORDER;
private static final String[] APOLLO_SYSTEM_PROPERTIES = {ConfigConsts.APOLLO_JDBC_URL,
ConfigConsts.APOLLO_JDBC_USERNAME, ConfigConsts.APOLLO_JDBC_PASSWORD};
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
initializeSystemProperty(environment);
}
/**
* To fill system properties from environment config
*/
void initializeSystemProperty(ConfigurableEnvironment environment) {
for (String propertyName : APOLLO_SYSTEM_PROPERTIES) {
fillSystemPropertyFromEnvironment(environment, propertyName);
}
}
private void fillSystemPropertyFromEnvironment(ConfigurableEnvironment environment, String propertyName) {
if (System.getProperty(propertyName) != null) {
return;
}
String propertyValue = environment.getProperty(propertyName);
if (Strings.isNullOrEmpty(propertyValue)) {
return;
}
System.setProperty(propertyName, propertyValue);
}
@Override
public int getOrder() {
return order;
}
public void setOrder(int order) {
this.order = order;
}
}

View File

@ -1,13 +1,13 @@
package cn.iocoder.dashboard.modules.system.controller.config;
package cn.iocoder.dashboard.modules.infra.controller.config;
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.dashboard.common.pojo.CommonResult;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.excel.core.util.ExcelUtils;
import cn.iocoder.dashboard.modules.system.controller.config.vo.*;
import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.*;
import cn.iocoder.dashboard.modules.infra.convert.config.InfConfigConvert;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
import cn.iocoder.dashboard.modules.infra.service.config.InfConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
@ -21,12 +21,12 @@ import java.io.IOException;
import java.util.List;
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE;
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.CONFIG_GET_VALUE_ERROR_IF_SENSITIVE;
@Api(tags = "参数配置")
@RestController
@RequestMapping("/system/config")
public class SysConfigController {
@RequestMapping("/infra/config")
public class InfConfigController {
@Value("${demo.test}")
private String demo;
@ -42,42 +42,42 @@ public class SysConfigController {
}
@Resource
private SysConfigService configService;
private InfConfigService configService;
@ApiOperation("获取参数配置分页")
@GetMapping("/page")
// @PreAuthorize("@ss.hasPermi('system:config:list')")
public CommonResult<PageResult<SysConfigRespVO>> getConfigPage(@Validated SysConfigPageReqVO reqVO) {
PageResult<SysConfigDO> page = configService.getConfigPage(reqVO);
return success(SysConfigConvert.INSTANCE.convertPage(page));
// @PreAuthorize("@ss.hasPermi('infra:config:list')")
public CommonResult<PageResult<InfConfigRespVO>> getConfigPage(@Validated InfConfigPageReqVO reqVO) {
PageResult<InfConfigDO> page = configService.getConfigPage(reqVO);
return success(InfConfigConvert.INSTANCE.convertPage(page));
}
@ApiOperation("导出参数配置")
@GetMapping("/export")
// @Log(title = "参数管理", businessType = BusinessType.EXPORT)
// @PreAuthorize("@ss.hasPermi('system:config:export')")
public void exportSysConfig(HttpServletResponse response, @Validated SysConfigExportReqVO reqVO) throws IOException {
List<SysConfigDO> list = configService.getConfigList(reqVO);
// @PreAuthorize("@ss.hasPermi('infra:config:export')")
public void exportSysConfig(HttpServletResponse response, @Validated InfConfigExportReqVO reqVO) throws IOException {
List<InfConfigDO> list = configService.getConfigList(reqVO);
// 拼接数据
List<SysConfigExcelVO> excelDataList = SysConfigConvert.INSTANCE.convertList(list);
List<InfConfigExcelVO> excelDataList = InfConfigConvert.INSTANCE.convertList(list);
// 输出
ExcelUtils.write(response, "参数配置.xls", "配置列表",
SysConfigExcelVO.class, excelDataList);
InfConfigExcelVO.class, excelDataList);
}
@ApiOperation("获得参数配置")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@GetMapping(value = "/get")
// @PreAuthorize("@ss.hasPermi('system:config:query')")
public CommonResult<SysConfigRespVO> getConfig(@RequestParam("id") Long id) {
return success(SysConfigConvert.INSTANCE.convert(configService.getConfig(id)));
// @PreAuthorize("@ss.hasPermi('infra:config:query')")
public CommonResult<InfConfigRespVO> getConfig(@RequestParam("id") Long id) {
return success(InfConfigConvert.INSTANCE.convert(configService.getConfig(id)));
}
@ApiOperation(value = "根据参数键名查询参数值", notes = "敏感配置,不允许返回给前端")
@ApiImplicitParam(name = "key", value = "参数键", required = true, example = "yunai.biz.username", dataTypeClass = String.class)
@GetMapping(value = "/get-value-by-key")
public CommonResult<String> getConfigKey(@RequestParam("key") String key) {
SysConfigDO config = configService.getConfigByKey(key);
InfConfigDO config = configService.getConfigByKey(key);
if (config == null) {
return null;
}
@ -89,18 +89,18 @@ public class SysConfigController {
@ApiOperation("新增参数配置")
@PostMapping("/create")
// @PreAuthorize("@ss.hasPermi('system:config:add')")
// @PreAuthorize("@ss.hasPermi('infra:config:add')")
// @Log(title = "参数管理", businessType = BusinessType.INSERT)
// @RepeatSubmit
public CommonResult<Long> createConfig(@Validated @RequestBody SysConfigCreateReqVO reqVO) {
public CommonResult<Long> createConfig(@Validated @RequestBody InfConfigCreateReqVO reqVO) {
return success(configService.createConfig(reqVO));
}
@ApiOperation("修改参数配置")
@PutMapping("/update")
// @PreAuthorize("@ss.hasPermi('system:config:edit')")
// @PreAuthorize("@ss.hasPermi('infra:config:edit')")
// @Log(title = "参数管理", businessType = BusinessType.UPDATE)
public CommonResult<Boolean> edit(@Validated @RequestBody SysConfigUpdateReqVO reqVO) {
public CommonResult<Boolean> edit(@Validated @RequestBody InfConfigUpdateReqVO reqVO) {
configService.updateConfig(reqVO);
return success(true);
}
@ -108,7 +108,7 @@ public class SysConfigController {
@ApiOperation("删除参数配置")
@ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class)
@DeleteMapping("/delete")
// @PreAuthorize("@ss.hasPermi('system:config:remove')")
// @PreAuthorize("@ss.hasPermi('infra:config:remove')")
// @Log(title = "参数管理", businessType = BusinessType.DELETE)
public CommonResult<Boolean> deleteConfig(@RequestParam("id") Long id) {
configService.deleteConfig(id);

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ -13,7 +13,7 @@ import javax.validation.constraints.Size;
* 如果子 VO 存在差异的字段请不要添加到这里影响 Swagger 文档生成
*/
@Data
public class SysConfigBaseVO {
public class InfConfigBaseVO {
@ApiModelProperty(value = "参数分组", required = true, example = "biz")
@NotEmpty(message = "参数分组不能为空")

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -11,7 +11,7 @@ import javax.validation.constraints.Size;
@ApiModel("参数配置创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysConfigCreateReqVO extends SysConfigBaseVO {
public class InfConfigCreateReqVO extends InfConfigBaseVO {
@ApiModelProperty(value = "参数键名", required = true, example = "yunai.db.username")
@NotBlank(message = "参数键名长度不能为空")

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import cn.iocoder.dashboard.framework.excel.core.annotations.DictFormat;
import cn.iocoder.dashboard.framework.excel.core.convert.DictConvert;
@ -12,7 +12,7 @@ import java.util.Date;
* 参数配置 Excel 导出响应 VO
*/
@Data
public class SysConfigExcelVO {
public class InfConfigExcelVO {
@ExcelProperty("参数配置序号")
private Long id;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -11,7 +11,7 @@ import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOU
@ApiModel("参数配置导出 Request VO")
@Data
public class SysConfigExportReqVO {
public class InfConfigExportReqVO {
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
private String name;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import cn.iocoder.dashboard.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
@ -14,7 +14,7 @@ import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOU
@ApiModel("参数配置分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysConfigPageReqVO extends PageParam {
public class InfConfigPageReqVO extends PageParam {
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
private String name;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -12,7 +12,7 @@ import java.util.Date;
@ApiModel("参数配置信息 Response VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysConfigRespVO extends SysConfigBaseVO {
public class InfConfigRespVO extends InfConfigBaseVO {
@ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
private Long id;

View File

@ -1,4 +1,4 @@
package cn.iocoder.dashboard.modules.system.controller.config.vo;
package cn.iocoder.dashboard.modules.infra.controller.config.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ -10,7 +10,7 @@ import javax.validation.constraints.NotNull;
@ApiModel("参数配置创建 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
public class SysConfigUpdateReqVO extends SysConfigBaseVO {
public class InfConfigUpdateReqVO extends InfConfigBaseVO {
@ApiModelProperty(value = "参数配置序号", required = true, example = "1024")
@NotNull(message = "参数配置编号不能为空")

View File

@ -0,0 +1 @@
package cn.iocoder.dashboard.modules.infra.controller;

View File

@ -0,0 +1,29 @@
package cn.iocoder.dashboard.modules.infra.convert.config;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigExcelVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigRespVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface InfConfigConvert {
InfConfigConvert INSTANCE = Mappers.getMapper(InfConfigConvert.class);
PageResult<InfConfigRespVO> convertPage(PageResult<InfConfigDO> page);
InfConfigRespVO convert(InfConfigDO bean);
InfConfigDO convert(InfConfigCreateReqVO bean);
InfConfigDO convert(InfConfigUpdateReqVO bean);
List<InfConfigExcelVO> convertList(List<InfConfigDO> list);
}

View File

@ -0,0 +1 @@
package cn.iocoder.dashboard.modules.infra.convert;

View File

@ -1,33 +1,33 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dao.config;
package cn.iocoder.dashboard.modules.infra.dal.mysql.dao.config;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigExportReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigPageReqVO;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface SysConfigMapper extends BaseMapperX<SysConfigDO> {
public interface InfConfigMapper extends BaseMapperX<InfConfigDO> {
default PageResult<SysConfigDO> selectPage(SysConfigPageReqVO reqVO) {
default PageResult<InfConfigDO> selectPage(InfConfigPageReqVO reqVO) {
return selectPage(reqVO,
new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
new QueryWrapperX<InfConfigDO>().likeIfPresent("name", reqVO.getName())
.likeIfPresent("`key`", reqVO.getKey())
.eqIfPresent("`type`", reqVO.getType())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));
}
default SysConfigDO selectByKey(String key) {
return selectOne(new QueryWrapper<SysConfigDO>().eq("`key`", key));
default InfConfigDO selectByKey(String key) {
return selectOne(new QueryWrapper<InfConfigDO>().eq("`key`", key));
}
default List<SysConfigDO> selectList(SysConfigExportReqVO reqVO) {
return selectList(new QueryWrapperX<SysConfigDO>().likeIfPresent("name", reqVO.getName())
default List<InfConfigDO> selectList(InfConfigExportReqVO reqVO) {
return selectList(new QueryWrapperX<InfConfigDO>().likeIfPresent("name", reqVO.getName())
.likeIfPresent("`key`", reqVO.getKey())
.eqIfPresent("`type`", reqVO.getType())
.betweenIfPresent("create_time", reqVO.getBeginTime(), reqVO.getEndTime()));

View File

@ -0,0 +1 @@
package cn.iocoder.dashboard.modules.infra.dal.mysql.dao;

View File

@ -1,7 +1,7 @@
package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config;
package cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config;
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
import cn.iocoder.dashboard.modules.infra.enums.config.InfConfigTypeEnum;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@ -13,11 +13,11 @@ import lombok.ToString;
*
* @author ruoyi
*/
@TableName("sys_config")
@TableName("inf_config")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class SysConfigDO extends BaseDO {
public class InfConfigDO extends BaseDO {
/**
* 参数主键
@ -44,7 +44,7 @@ public class SysConfigDO extends BaseDO {
/**
* 参数类型
*
* 枚举 {@link SysConfigTypeEnum}
* 枚举 {@link InfConfigTypeEnum}
*/
@TableField("`type`")
private Integer type;

View File

@ -0,0 +1 @@
package cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject;

View File

@ -0,0 +1,18 @@
package cn.iocoder.dashboard.modules.infra.enums;
import cn.iocoder.dashboard.common.exception.ErrorCode;
/**
* Infra 错误码枚举类
*
* system 系统使用 1-001-000-000
*/
public interface InfErrorCodeConstants {
// ========== 参数配置 1001000000 ==========
ErrorCode CONFIG_NOT_FOUND = new ErrorCode(1001000001, "参数配置不存在");
ErrorCode CONFIG_NAME_DUPLICATE = new ErrorCode(1001000002, "参数配置 key 重复");
ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1001000003, "不能删除类型为系统内置的参数配置");
ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1001000004, "不允许获取敏感配置到前端");
}

View File

@ -1,11 +1,11 @@
package cn.iocoder.dashboard.modules.system.enums.config;
package cn.iocoder.dashboard.modules.infra.enums.config;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public enum SysConfigTypeEnum {
public enum InfConfigTypeEnum {
/**
* 系统配置

View File

@ -1,18 +1,18 @@
package cn.iocoder.dashboard.modules.system.service.config;
package cn.iocoder.dashboard.modules.infra.service.config;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigExportReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigPageReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
import java.util.List;
/**
* 参数配置 Service 接口
*/
public interface SysConfigService {
public interface InfConfigService {
/**
* 获得参数配置分页列表
@ -20,7 +20,7 @@ public interface SysConfigService {
* @param reqVO 分页条件
* @return 分页列表
*/
PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO);
PageResult<InfConfigDO> getConfigPage(InfConfigPageReqVO reqVO);
/**
* 获得参数配置列表
@ -28,7 +28,7 @@ public interface SysConfigService {
* @param reqVO 列表
* @return 列表
*/
List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO);
List<InfConfigDO> getConfigList(InfConfigExportReqVO reqVO);
/**
* 获得参数配置
@ -36,7 +36,7 @@ public interface SysConfigService {
* @param id 配置编号
* @return 参数配置
*/
SysConfigDO getConfig(Long id);
InfConfigDO getConfig(Long id);
/**
* 根据参数键获得参数配置
@ -44,7 +44,7 @@ public interface SysConfigService {
* @param key 配置键
* @return 参数配置
*/
SysConfigDO getConfigByKey(String key);
InfConfigDO getConfigByKey(String key);
/**
* 创建参数配置
@ -52,14 +52,14 @@ public interface SysConfigService {
* @param reqVO 创建信息
* @return 配置编号
*/
Long createConfig(SysConfigCreateReqVO reqVO);
Long createConfig(InfConfigCreateReqVO reqVO);
/**
* 更新参数配置
*
* @param reqVO 更新信息
*/
void updateConfig(SysConfigUpdateReqVO reqVO);
void updateConfig(InfConfigUpdateReqVO reqVO);
/**
* 删除参数配置

View File

@ -1,16 +1,16 @@
package cn.iocoder.dashboard.modules.system.service.config.impl;
package cn.iocoder.dashboard.modules.infra.service.config.impl;
import cn.iocoder.dashboard.common.exception.util.ServiceExceptionUtil;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExportReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigPageReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
import cn.iocoder.dashboard.modules.system.convert.config.SysConfigConvert;
import cn.iocoder.dashboard.modules.system.dal.mysql.dao.config.SysConfigMapper;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
import cn.iocoder.dashboard.modules.system.enums.config.SysConfigTypeEnum;
import cn.iocoder.dashboard.modules.system.service.config.SysConfigService;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigCreateReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigExportReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigPageReqVO;
import cn.iocoder.dashboard.modules.infra.controller.config.vo.InfConfigUpdateReqVO;
import cn.iocoder.dashboard.modules.infra.convert.config.InfConfigConvert;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dao.config.InfConfigMapper;
import cn.iocoder.dashboard.modules.infra.dal.mysql.dataobject.config.InfConfigDO;
import cn.iocoder.dashboard.modules.infra.enums.config.InfConfigTypeEnum;
import cn.iocoder.dashboard.modules.infra.service.config.InfConfigService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -18,64 +18,64 @@ import javax.annotation.Resource;
import java.util.List;
import static cn.iocoder.dashboard.modules.system.enums.SysErrorCodeConstants.*;
import static cn.iocoder.dashboard.modules.infra.enums.InfErrorCodeConstants.*;
/**
* 参数配置 Service 实现类
*/
@Service
@Slf4j
public class SysConfigServiceImpl implements SysConfigService {
public class InfConfigServiceImpl implements InfConfigService {
@Resource
private SysConfigMapper configMapper;
private InfConfigMapper configMapper;
@Override
public PageResult<SysConfigDO> getConfigPage(SysConfigPageReqVO reqVO) {
public PageResult<InfConfigDO> getConfigPage(InfConfigPageReqVO reqVO) {
return configMapper.selectPage(reqVO);
}
@Override
public List<SysConfigDO> getConfigList(SysConfigExportReqVO reqVO) {
public List<InfConfigDO> getConfigList(InfConfigExportReqVO reqVO) {
return configMapper.selectList(reqVO);
}
@Override
public SysConfigDO getConfig(Long id) {
public InfConfigDO getConfig(Long id) {
return configMapper.selectById(id);
}
@Override
public SysConfigDO getConfigByKey(String key) {
public InfConfigDO getConfigByKey(String key) {
return configMapper.selectByKey(key);
}
@Override
public Long createConfig(SysConfigCreateReqVO reqVO) {
public Long createConfig(InfConfigCreateReqVO reqVO) {
// 校验正确性
checkCreateOrUpdate(null, reqVO.getKey());
// 插入参数配置
SysConfigDO config = SysConfigConvert.INSTANCE.convert(reqVO);
config.setType(SysConfigTypeEnum.CUSTOM.getType());
InfConfigDO config = InfConfigConvert.INSTANCE.convert(reqVO);
config.setType(InfConfigTypeEnum.CUSTOM.getType());
configMapper.insert(config);
return config.getId();
}
@Override
public void updateConfig(SysConfigUpdateReqVO reqVO) {
public void updateConfig(InfConfigUpdateReqVO reqVO) {
// 校验正确性
checkCreateOrUpdate(reqVO.getId(), null); // 不允许更新 key
// 更新参数配置
SysConfigDO updateObj = SysConfigConvert.INSTANCE.convert(reqVO);
InfConfigDO updateObj = InfConfigConvert.INSTANCE.convert(reqVO);
configMapper.updateById(updateObj);
}
@Override
public void deleteConfig(Long id) {
// 校验配置存在
SysConfigDO config = checkConfigExists(id);
InfConfigDO config = checkConfigExists(id);
// 内置配置不允许删除
if (SysConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
if (InfConfigTypeEnum.SYSTEM.getType().equals(config.getType())) {
throw ServiceExceptionUtil.exception(CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE);
}
// 删除
@ -89,11 +89,11 @@ public class SysConfigServiceImpl implements SysConfigService {
checkConfigKeyUnique(id, key);
}
private SysConfigDO checkConfigExists(Long id) {
private InfConfigDO checkConfigExists(Long id) {
if (id == null) {
return null;
}
SysConfigDO config = configMapper.selectById(id);
InfConfigDO config = configMapper.selectById(id);
if (config == null) {
throw ServiceExceptionUtil.exception(CONFIG_NOT_FOUND);
}
@ -101,7 +101,7 @@ public class SysConfigServiceImpl implements SysConfigService {
}
private void checkConfigKeyUnique(Long id, String key) {
SysConfigDO config = configMapper.selectByKey(key);
InfConfigDO config = configMapper.selectByKey(key);
if (config == null) {
return;
}

View File

@ -0,0 +1 @@
package cn.iocoder.dashboard.modules.infra.service;

View File

@ -1,29 +0,0 @@
package cn.iocoder.dashboard.modules.system.convert.config;
import cn.iocoder.dashboard.common.pojo.PageResult;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigCreateReqVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigExcelVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigRespVO;
import cn.iocoder.dashboard.modules.system.controller.config.vo.SysConfigUpdateReqVO;
import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.config.SysConfigDO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
@Mapper
public interface SysConfigConvert {
SysConfigConvert INSTANCE = Mappers.getMapper(SysConfigConvert.class);
PageResult<SysConfigRespVO> convertPage(PageResult<SysConfigDO> page);
SysConfigRespVO convert(SysConfigDO bean);
SysConfigDO convert(SysConfigCreateReqVO bean);
SysConfigDO convert(SysConfigUpdateReqVO bean);
List<SysConfigExcelVO> convertList(List<SysConfigDO> list);
}

View File

@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.system.enums;
import cn.iocoder.dashboard.common.exception.ErrorCode;
/**
* 错误码枚举类
* System 错误码枚举类
*
* system 系统使用 1-002-000-000
*/
@ -75,9 +75,4 @@ public interface SysErrorCodeConstants {
// ========== 文件 1002009000 ==========
ErrorCode FILE_PATH_EXISTS = new ErrorCode(1002009001, "文件路径已经存在");
// ========== 参数配置 1002010000 ==========
ErrorCode CONFIG_NOT_FOUND = new ErrorCode(1002010001, "参数配置不存在");
ErrorCode CONFIG_NAME_DUPLICATE = new ErrorCode(1002010002, "参数配置 key 重复");
ErrorCode CONFIG_CAN_NOT_DELETE_SYSTEM_TYPE = new ErrorCode(1002010003, "不能删除类型为系统内置的参数配置");
ErrorCode CONFIG_GET_VALUE_ERROR_IF_SENSITIVE = new ErrorCode(1002010004, "不允许获取敏感配置到前端");
}

View File

@ -0,0 +1,2 @@
org.springframework.boot.env.EnvironmentPostProcessor=\
cn.iocoder.dashboard.framework.apollo.spring.boot.ApolloApplicationContextInitializer

View File

@ -53,6 +53,10 @@ apollo:
enabled: true # 设置 Apollo 在启动阶段生效
eagerLoad:
enabled: true # 设置 Apollo 在日志初始化前生效,可以实现日志的动态级别配置
jdbc: # 自定义的 JDBC 配置项,用于数据库的地址
url: ${spring.datasource.url}
username: ${spring.datasource.username}
password: ${spring.datasource.password}
# MyBatis Plus 的配置项
mybatis-plus: