【7.0.4】【config】更新系统初始化

pull/22/head
fengshuonan 2021-07-08 20:17:28 +08:00
parent 9bf96b07bf
commit 0ab618220a
7 changed files with 160 additions and 0 deletions

View File

@ -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.
*
* GunsAPACHE 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();
}

View File

@ -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;
}

View File

@ -145,6 +145,17 @@ public class SysConfigController {
return new SuccessResponseData();
}
/**
*
*
* @author fengshuonan
* @date 2021/7/8 16:36
*/
@GetResource(name = "获取需要初始化的配置列表", path = "/sysConfig/getInitConfigList")
public ResponseData getInitConfigList() {
return new SuccessResponseData(sysConfigService.getInitConfigs());
}
}

View File

@ -24,6 +24,7 @@
*/
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.modular.entity.SysConfig;
import cn.stylefeng.roses.kernel.config.modular.param.SysConfigParam;
@ -114,4 +115,12 @@ public interface SysConfigService extends IService<SysConfig> {
*/
Boolean getInitConfigFlag();
/**
*
*
* @author fengshuonan
* @date 2021/7/8 17:49
*/
List<ConfigInitItem> getInitConfigs();
}

View File

@ -28,9 +28,11 @@ import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.util.ObjectUtil;
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.exception.ConfigException;
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.modular.entity.SysConfig;
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.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
@ -60,6 +63,9 @@ import java.util.Map;
@Service
public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig> implements SysConfigService {
@Resource
private ConfigInitStrategyApi configInitStrategyApi;
@Override
@Transactional(rollbackFor = Exception.class)
public void add(SysConfigParam sysConfigParam) {
@ -189,6 +195,11 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
}
}
@Override
public List<ConfigInitItem> getInitConfigs() {
return configInitStrategyApi.getInitConfigs();
}
/**
*
*

View File

@ -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;
}
}

View File

@ -24,6 +24,10 @@
*/
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;
/**
@ -35,5 +39,16 @@ import org.springframework.context.annotation.Configuration;
@Configuration
public class GunsSysConfigAutoConfiguration {
/**
* api
*
* @author fengshuonan
* @date 2021/7/8 17:48
*/
@Bean
@ConditionalOnMissingBean(ConfigInitStrategyApi.class)
public ConfigInitStrategyApi configInitStrategyApi() {
return new DefaultStrategyImpl();
}
}