mirror of https://gitee.com/stylefeng/roses
【8.3.0】【config】增加一个系统配置类型,标识本地文件存储路径
parent
6089b7c018
commit
5bee25d273
|
@ -52,4 +52,26 @@ public interface ConfigConstants {
|
|||
*/
|
||||
String CONFIG_GROUP_DICT_TYPE_CODE = "config_group";
|
||||
|
||||
/**
|
||||
* 文件存储类型的配置
|
||||
* <p>
|
||||
* 10-本地,存储到默认路径(jar所在目录)
|
||||
* 11-本地,存储到指定路径下(需要配置linux和windows的路径)
|
||||
* 20-存储到MinIO
|
||||
* 30-存储到阿里云
|
||||
* 40-存储到腾讯云
|
||||
* 50-存储到青云
|
||||
*/
|
||||
String SYS_FILE_SAVE_TYPE_CONFIG_CODE = "SYS_FILE_SAVE_TYPE";
|
||||
|
||||
/**
|
||||
* 配置编码,LINUX本地存储的目录
|
||||
*/
|
||||
String SYS_LOCAL_FILE_SAVE_PATH_LINUX = "SYS_LOCAL_FILE_SAVE_PATH_LINUX";
|
||||
|
||||
/**
|
||||
* 配置编码,windows本地文件存储的目录
|
||||
*/
|
||||
String SYS_LOCAL_FILE_SAVE_PATH_WINDOWS = "SYS_LOCAL_FILE_SAVE_PATH_WINDOWS";
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
/*
|
||||
* 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.enums;
|
||||
|
||||
import cn.hutool.core.convert.Convert;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.stylefeng.roses.kernel.rule.base.ReadableEnum;
|
||||
import com.baomidou.mybatisplus.annotation.EnumValue;
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonValue;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 文件存储配置类型
|
||||
* <p>
|
||||
* 10-本地,存储到默认路径(jar所在目录)
|
||||
* 11-本地,存储到指定路径下(需要配置linux和windows的路径)
|
||||
* 20-存储到MinIO
|
||||
* 30-存储到阿里云
|
||||
* 40-存储到腾讯云
|
||||
* 50-存储到青云
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/29 21:44
|
||||
*/
|
||||
@Getter
|
||||
public enum FileStorageTypeEnum implements ReadableEnum<FileStorageTypeEnum> {
|
||||
|
||||
/**
|
||||
* 本地,存储到默认路径(jar所在目录)
|
||||
*/
|
||||
LOCAL_DEFAULT(10, "本地,存储到默认路径(jar所在目录)"),
|
||||
|
||||
/**
|
||||
* 本地,存储到指定路径下(需要配置linux和windows的路径)
|
||||
*/
|
||||
LOCAL(11, "本地,存储到指定路径下(需要配置linux和windows的路径)"),
|
||||
|
||||
/**
|
||||
* 存储到MinIO
|
||||
*/
|
||||
MINIO(20, "存储到MinIO"),
|
||||
|
||||
/**
|
||||
* 存储到阿里云
|
||||
*/
|
||||
ALIYUN(30, "存储到阿里云"),
|
||||
|
||||
/**
|
||||
* 存储到腾讯云
|
||||
*/
|
||||
TEN_CLOUD(40, "存储到腾讯云"),
|
||||
|
||||
/**
|
||||
* 青云
|
||||
*/
|
||||
QING_CLOUD(50, "青云");
|
||||
|
||||
@EnumValue
|
||||
@JsonValue
|
||||
private final Integer code;
|
||||
|
||||
private final String message;
|
||||
|
||||
FileStorageTypeEnum(Integer code, String message) {
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2020/10/29 18:59
|
||||
*/
|
||||
@JsonCreator(mode = JsonCreator.Mode.DELEGATING)
|
||||
public static FileStorageTypeEnum codeToEnum(Integer code) {
|
||||
if (null != code) {
|
||||
for (FileStorageTypeEnum item : FileStorageTypeEnum.values()) {
|
||||
if (item.getCode().equals(code)) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getKey() {
|
||||
return this.code;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getName() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileStorageTypeEnum parseToEnum(String originValue) {
|
||||
if (ObjectUtil.isEmpty(originValue)) {
|
||||
return null;
|
||||
}
|
||||
for (FileStorageTypeEnum value : FileStorageTypeEnum.values()) {
|
||||
if (value.code.equals(Convert.toInt(originValue))) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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.modular.listener;
|
||||
|
||||
import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 处理文件存储路径为默认配置情况下,获取并设置默认位置的路径为文件保存路径
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/29 21:33
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class LocalStorageListener implements CommandLineRunner {
|
||||
|
||||
@Resource
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
@Override
|
||||
public void run(String... args) {
|
||||
this.sysConfigService.initLocalDefaultStoragePath();
|
||||
}
|
||||
|
||||
}
|
|
@ -131,4 +131,21 @@ public interface SysConfigService extends IService<SysConfig>, InitConfigApi, Co
|
|||
*/
|
||||
void updateSysConfigTypeCode(String originTypeCode, String destTypeCode);
|
||||
|
||||
/**
|
||||
* 根据配置编码获取配置值
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/29 21:35
|
||||
*/
|
||||
String getConfigValueByCode(String configCode);
|
||||
|
||||
/**
|
||||
* 初始化文件存储配置,针对本地存储的方式
|
||||
*
|
||||
* @return 初始化后的本地文件存储路径
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/29 22:16
|
||||
*/
|
||||
String initLocalDefaultStoragePath();
|
||||
|
||||
}
|
||||
|
|
|
@ -29,9 +29,11 @@ import cn.hutool.core.convert.Convert;
|
|||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import cn.stylefeng.roses.kernel.config.api.ConfigInitCallbackApi;
|
||||
import cn.stylefeng.roses.kernel.config.api.ConfigInitStrategyApi;
|
||||
import cn.stylefeng.roses.kernel.config.api.context.ConfigContext;
|
||||
import cn.stylefeng.roses.kernel.config.api.enums.FileStorageTypeEnum;
|
||||
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;
|
||||
|
@ -50,6 +52,7 @@ import cn.stylefeng.roses.kernel.rule.callback.ConfigUpdateCallback;
|
|||
import cn.stylefeng.roses.kernel.rule.constants.RuleConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.StatusEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.enums.YesOrNotEnum;
|
||||
import cn.stylefeng.roses.kernel.rule.util.JarPathUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
@ -61,6 +64,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static cn.stylefeng.roses.kernel.config.api.constants.ConfigConstants.*;
|
||||
|
||||
/**
|
||||
* 系统参数配置service接口实现类
|
||||
*
|
||||
|
@ -277,6 +282,46 @@ public class SysConfigServiceImpl extends ServiceImpl<SysConfigMapper, SysConfig
|
|||
this.update(sysConfigLambdaUpdateWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getConfigValueByCode(String configCode) {
|
||||
LambdaQueryWrapper<SysConfig> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(SysConfig::getConfigCode, configCode);
|
||||
wrapper.select(SysConfig::getConfigId, SysConfig::getConfigValue);
|
||||
SysConfig sysConfig = this.getOne(wrapper, false);
|
||||
if (sysConfig == null) {
|
||||
return "";
|
||||
} else {
|
||||
return sysConfig.getConfigValue();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String initLocalDefaultStoragePath() {
|
||||
// 1. 获取文件存储的配置类型,是否为默认,还是指定位置存储
|
||||
String configValueByCode = this.getConfigValueByCode(SYS_FILE_SAVE_TYPE_CONFIG_CODE);
|
||||
Integer configValue = Convert.toInt(configValueByCode);
|
||||
|
||||
// 2. 如果不是存储到默认路径,直接跳过本类执行
|
||||
if (ObjectUtil.notEqual(configValue, FileStorageTypeEnum.LOCAL_DEFAULT.getCode())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 3. 获取当前jar启动的位置的目录
|
||||
String currentJarPath = JarPathUtil.getJarPath();
|
||||
if (StrUtil.isBlank(currentJarPath)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. 获取当前系统的类型,是windows还是linux
|
||||
if (SystemUtil.getOsInfo().isWindows()) {
|
||||
this.updateConfigByCode(SYS_LOCAL_FILE_SAVE_PATH_WINDOWS, currentJarPath);
|
||||
} else {
|
||||
this.updateConfigByCode(SYS_LOCAL_FILE_SAVE_PATH_LINUX, currentJarPath);
|
||||
}
|
||||
|
||||
return currentJarPath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取系统参数配置
|
||||
*
|
||||
|
|
|
@ -2,8 +2,14 @@ package cn.stylefeng.roses.kernel.config.modular.strategy;
|
|||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import cn.stylefeng.roses.kernel.config.api.ConfigInitStrategyApi;
|
||||
import cn.stylefeng.roses.kernel.config.api.constants.ConfigConstants;
|
||||
import cn.stylefeng.roses.kernel.config.api.enums.FileStorageTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.config.api.pojo.ConfigInitItem;
|
||||
import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -19,6 +25,9 @@ import java.util.List;
|
|||
@Component
|
||||
public class DefaultStrategyImpl implements ConfigInitStrategyApi {
|
||||
|
||||
@Resource
|
||||
private SysConfigService sysConfigService;
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return "系统参数";
|
||||
|
@ -37,14 +46,29 @@ public class DefaultStrategyImpl implements ConfigInitStrategyApi {
|
|||
configInitItems.add(new ConfigInitItem("auth认证用的jwt秘钥", "SYS_AUTH_JWT_SECRET", RandomUtil.randomString(30), "用于校验登录token,已随机生成一个30位密钥,请放心使用"));
|
||||
configInitItems.add(new ConfigInitItem("Druid控制台账号", "SYS_DRUID_ACCOUNT", "admin", "Druid控制台账号"));
|
||||
configInitItems.add(new ConfigInitItem("Druid控制台账号密码", "SYS_DRUID_PASSWORD", RandomUtil.randomString(20), "Druid控制台账号密码,已随机生成一个20位密钥,请放心使用"));
|
||||
configInitItems.add(new ConfigInitItem("Linux本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_LINUX", "/opt/gunsFilePath", "本地文件存储的路径,上线请注意别使用/tmp目录,如果没有用本地文件存储,可忽略此配置"));
|
||||
configInitItems.add(new ConfigInitItem("Windows本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_WINDOWS", "D:\\tempFilePath", "本地文件存储的路径,如果没有用本地文件存储,可忽略此配置"));
|
||||
configInitItems.add(new ConfigInitItem("session过期时间", "SYS_SESSION_EXPIRED_SECONDS", "3600", "单位:秒,session的过期时间,这个时间段内不操作会自动踢下线"));
|
||||
configInitItems.add(new ConfigInitItem("账号单端登录限制", "SYS_SINGLE_ACCOUNT_LOGIN_FLAG", "false", "如果开启,则同一个账号只能一个地方登录"));
|
||||
configInitItems.add(new ConfigInitItem("系统默认密码", "SYS_DEFAULT_PASSWORD", "123456", "用在重置密码的默认密码"));
|
||||
configInitItems.add(new ConfigInitItem("系统发布版本", "SYS_RELEASE_VERSION", DateUtil.format(new Date(), "yyyyMMdd"), "系统发布的版本号"));
|
||||
configInitItems.add(new ConfigInitItem("数据库加密AES秘钥", "SYS_ENCRYPT_SECRET_KEY", RandomUtil.randomString(32), "对称加密秘钥,用在数据库数据加密"));
|
||||
configInitItems.add(new ConfigInitItem("SSO服务端加密Token信息秘钥", "SYS_AUTH_SSO_DECRYPT_DATA_SECRET", RandomUtil.randomString(32), "SSO服务端加密Token信息秘钥,用在单点登录认证时候加密生成Token"));
|
||||
|
||||
// 【2024年8月29日新增】设置文件存储的类型,10-本地存储(jar启动路径)
|
||||
configInitItems.add(new ConfigInitItem("文件存储类型", ConfigConstants.SYS_FILE_SAVE_TYPE_CONFIG_CODE, String.valueOf(FileStorageTypeEnum.LOCAL_DEFAULT.getCode()), "文件存储位置类型:10-本地存储(jar包所在位置),11-本地存储(指定位置)"));
|
||||
|
||||
// 【2024年8月29日新增】获取初始化路径地址
|
||||
String localDefaultStoragePath = sysConfigService.initLocalDefaultStoragePath();
|
||||
if(StrUtil.isBlank(localDefaultStoragePath)){
|
||||
configInitItems.add(new ConfigInitItem("Windows本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_WINDOWS", "D:\\tempFilePath", "本地文件存储的路径,如果没有用本地文件存储,可忽略此配置"));
|
||||
configInitItems.add(new ConfigInitItem("Linux本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_LINUX", "/opt/gunsFilePath", "本地文件存储的路径,上线请注意别使用/tmp目录,如果没有用本地文件存储,可忽略此配置"));
|
||||
}else{
|
||||
if(SystemUtil.getOsInfo().isWindows()){
|
||||
configInitItems.add(new ConfigInitItem("Windows本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_WINDOWS", localDefaultStoragePath, "本地文件存储的路径,如果没有用本地文件存储,可忽略此配置"));
|
||||
}else{
|
||||
configInitItems.add(new ConfigInitItem("Linux本地文件保存路径", "SYS_LOCAL_FILE_SAVE_PATH_LINUX", localDefaultStoragePath, "本地文件存储的路径,上线请注意别使用/tmp目录,如果没有用本地文件存储,可忽略此配置"));
|
||||
}
|
||||
}
|
||||
|
||||
return configInitItems;
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
INSERT INTO `sys_config`(`config_id`, `config_name`, `config_code`, `config_value`, `sys_flag`, `remark`, `status_flag`, `group_code`, `del_flag`, `create_time`, `create_user`, `update_time`, `update_user`) VALUES (1829152372339773442, '文件存储类型', 'SYS_FILE_SAVE_TYPE', '10', 'Y', '10-本地,存储到默认路径(jar所在目录)\n11-本地,存储到指定路径下(需要配置linux和windows的路径)\n20-存储到MinIO\n30-存储到阿里云\n40-存储到腾讯云\n50-存储到青云', 1, 'file_config', 'N', '2024-08-29 21:41:24', 1821938198325960706, NULL, NULL);
|
Loading…
Reference in New Issue