mirror of https://gitee.com/stylefeng/roses
【7.0.4】【config】更新系统初始化
parent
9bf96b07bf
commit
0ab618220a
|
@ -0,0 +1,48 @@
|
||||||
|
/*
|
||||||
|
* Copyright [2020-2030] [https://www.stylefeng.cn]
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
* Guns采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
|
||||||
|
*
|
||||||
|
* 1.请不要删除和修改根目录下的LICENSE文件。
|
||||||
|
* 2.请不要删除和修改Guns源码头部的版权声明。
|
||||||
|
* 3.请保留源码和相关描述文件的项目出处,作者声明等。
|
||||||
|
* 4.分发源码时候,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||||
|
* 5.在修改包名,模块名称,项目代码等时,请注明软件出处 https://gitee.com/stylefeng/guns
|
||||||
|
* 6.若您的项目无法满足以上几点,可申请商业授权
|
||||||
|
*/
|
||||||
|
package cn.stylefeng.roses.kernel.config.api;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitItem;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置初始化的策略
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 17:33
|
||||||
|
*/
|
||||||
|
public interface ConfigInitStrategyApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取需要被初始化的配置集合
|
||||||
|
*
|
||||||
|
* @return 需要被初始化的配置集合
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 17:40
|
||||||
|
*/
|
||||||
|
List<ConfigInitItem> getInitConfigs();
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,38 @@
|
||||||
|
package cn.stylefeng.roses.kernel.config.api.pojo;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化系统配置参数
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 16:38
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class ConfigInitItem {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置中文名称
|
||||||
|
*/
|
||||||
|
private String configName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置编码
|
||||||
|
*/
|
||||||
|
private String configCode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置的初始化值
|
||||||
|
*/
|
||||||
|
private String configValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 配置的描述
|
||||||
|
*/
|
||||||
|
private String configDescription;
|
||||||
|
|
||||||
|
}
|
|
@ -145,6 +145,17 @@ public class SysConfigController {
|
||||||
return new SuccessResponseData();
|
return new SuccessResponseData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取需要初始化的配置列表
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 16:36
|
||||||
|
*/
|
||||||
|
@GetResource(name = "获取需要初始化的配置列表", path = "/sysConfig/getInitConfigList")
|
||||||
|
public ResponseData getInitConfigList() {
|
||||||
|
return new SuccessResponseData(sysConfigService.getInitConfigs());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
package cn.stylefeng.roses.kernel.config.modular.service;
|
package cn.stylefeng.roses.kernel.config.modular.service;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitItem;
|
||||||
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitRequest;
|
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitRequest;
|
||||||
import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig;
|
import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig;
|
||||||
import cn.stylefeng.roses.kernel.config.modular.param.SysConfigParam;
|
import cn.stylefeng.roses.kernel.config.modular.param.SysConfigParam;
|
||||||
|
@ -114,4 +115,12 @@ public interface SysConfigService extends IService<SysConfig> {
|
||||||
*/
|
*/
|
||||||
Boolean getInitConfigFlag();
|
Boolean getInitConfigFlag();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取初始化的配置列表
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 17:49
|
||||||
|
*/
|
||||||
|
List<ConfigInitItem> getInitConfigs();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,9 +28,11 @@ import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.convert.Convert;
|
import cn.hutool.core.convert.Convert;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.ConfigInitStrategyApi;
|
||||||
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
|
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
|
||||||
import cn.stylefeng.roses.kernel.config.api.exception.ConfigException;
|
import cn.stylefeng.roses.kernel.config.api.exception.ConfigException;
|
||||||
import cn.stylefeng.roses.kernel.config.api.exception.enums.ConfigExceptionEnum;
|
import cn.stylefeng.roses.kernel.config.api.exception.enums.ConfigExceptionEnum;
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitItem;
|
||||||
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitRequest;
|
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitRequest;
|
||||||
import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig;
|
import cn.stylefeng.roses.kernel.config.modular.entity.SysConfig;
|
||||||
import cn.stylefeng.roses.kernel.config.modular.mapper.SysConfigMapper;
|
import cn.stylefeng.roses.kernel.config.modular.mapper.SysConfigMapper;
|
||||||
|
@ -48,6 +50,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
@ -60,6 +63,9 @@ import java.util.Map;
|
||||||
@Service
|
@Service
|
||||||
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {
|
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ConfigInitStrategyApi configInitStrategyApi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void add(SysConfigParam sysConfigParam) {
|
public void add(SysConfigParam sysConfigParam) {
|
||||||
|
@ -189,6 +195,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ConfigInitItem> getInitConfigs() {
|
||||||
|
return configInitStrategyApi.getInitConfigs();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取系统参数配置
|
* 获取系统参数配置
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
package cn.stylefeng.roses.kernel.config.modular.strategy;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.RandomUtil;
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.ConfigInitStrategyApi;
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitItem;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认的初始化配置策略,初始化系统一些必要的参数
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 17:47
|
||||||
|
*/
|
||||||
|
public class DefaultStrategyImpl implements ConfigInitStrategyApi {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ConfigInitItem> getInitConfigs() {
|
||||||
|
ArrayList<ConfigInitItem> configInitItems = new ArrayList<>();
|
||||||
|
configInitItems.add(new ConfigInitItem("JWT安全码", "SYS_JWT_SECRET", RandomUtil.randomString(20), "jwt-spring-boot-starter模块的秘钥,非认证用的jwt秘钥,默认20位随机字符串"));
|
||||||
|
configInitItems.add(new ConfigInitItem("JWT过期时间", "SYS_JWT_TIMEOUT_SECONDS", "" + 60 * 60 * 24, "jwt-spring-boot-starter模块的秘钥过期时间,默认1天"));
|
||||||
|
configInitItems.add(new ConfigInitItem("Linux本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_LINUX", "/tmp/tempFilePath", "本地文件存储的路径,如果没有用本地文件存储,可忽略此配置"));
|
||||||
|
configInitItems.add(new ConfigInitItem("Windows本地文件保存路径", "SYS_JWT_SECRET", "D:\\tempFilePath", "本地文件存储的路径,如果没有用本地文件存储,可忽略此配置"));
|
||||||
|
return configInitItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -24,6 +24,10 @@
|
||||||
*/
|
*/
|
||||||
package cn.stylefeng.roses.kernel.config.starter;
|
package cn.stylefeng.roses.kernel.config.starter;
|
||||||
|
|
||||||
|
import cn.stylefeng.roses.kernel.config.api.ConfigInitStrategyApi;
|
||||||
|
import cn.stylefeng.roses.kernel.config.modular.strategy.DefaultStrategyImpl;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,5 +39,16 @@ import org.springframework.context.annotation.Configuration;
|
||||||
@Configuration
|
@Configuration
|
||||||
public class GunsSysConfigAutoConfiguration {
|
public class GunsSysConfigAutoConfiguration {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认的配置初始化api
|
||||||
|
*
|
||||||
|
* @author fengshuonan
|
||||||
|
* @date 2021/7/8 17:48
|
||||||
|
*/
|
||||||
|
@Bean
|
||||||
|
@ConditionalOnMissingBean(ConfigInitStrategyApi.class)
|
||||||
|
public ConfigInitStrategyApi configInitStrategyApi() {
|
||||||
|
return new DefaultStrategyImpl();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue