mirror of https://gitee.com/stylefeng/roses
【8.3.0】【config】更新修改文件存储配置的接口
parent
72e14614bd
commit
3fe8b20534
|
@ -30,7 +30,10 @@ import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
|
|||
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
|
||||
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
|
@ -58,6 +61,18 @@ public class NewFileConfigController {
|
|||
return new SuccessResponseData<>(storageConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新文件配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/31 18:00
|
||||
*/
|
||||
@PostResource(name = "更新文件配置", path = "/new/sysConfig/updateFileConfig")
|
||||
public ResponseData<?> updateFileConfig(@RequestBody @Validated StorageConfig storageConfig) {
|
||||
newConfigService.updateFileConfig(storageConfig);
|
||||
return new SuccessResponseData<>();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package cn.stylefeng.roses.kernel.config.modular.pojo.newconfig;
|
||||
|
||||
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
|
@ -23,6 +24,7 @@ public class StorageConfig {
|
|||
* 50-存储到青云
|
||||
*/
|
||||
@ChineseDescription("文件存储类型的配置:10-本地,存储到默认路径(jar所在目录),11-本地,存储到指定路径下(需要配置linux和windows的路径),20-存储到MinIO,30-存储到阿里云,40-存储到腾讯云,50-存储到青云")
|
||||
@NotNull(message = "文件存储类型的配置不能为空")
|
||||
private Integer fileSaveType;
|
||||
|
||||
/**
|
||||
|
|
|
@ -42,4 +42,12 @@ public interface NewConfigService {
|
|||
*/
|
||||
StorageConfig getStorageConfig();
|
||||
|
||||
/**
|
||||
* 更新文件的配置
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @since 2024/8/31 18:01
|
||||
*/
|
||||
void updateFileConfig(StorageConfig storageConfig);
|
||||
|
||||
}
|
||||
|
|
|
@ -2,9 +2,11 @@ package cn.stylefeng.roses.kernel.config.modular.service.impl;
|
|||
|
||||
import cn.hutool.system.SystemUtil;
|
||||
import cn.stylefeng.roses.kernel.config.api.constants.ConfigConstants;
|
||||
import cn.stylefeng.roses.kernel.config.api.enums.FileStorageTypeEnum;
|
||||
import cn.stylefeng.roses.kernel.config.modular.pojo.newconfig.StorageConfig;
|
||||
import cn.stylefeng.roses.kernel.config.modular.service.NewConfigService;
|
||||
import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService;
|
||||
import cn.stylefeng.roses.kernel.rule.util.JarPathUtil;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -41,4 +43,29 @@ public class NewConfigServiceImpl implements NewConfigService {
|
|||
return storageConfig;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFileConfig(StorageConfig storageConfig) {
|
||||
String jarPath = null;
|
||||
|
||||
// 1. 如果修改为程序默认路径的存储,获取当前jar路径
|
||||
if (FileStorageTypeEnum.LOCAL_DEFAULT.getCode().equals(storageConfig.getFileSaveType())) {
|
||||
jarPath = JarPathUtil.getJarPath();
|
||||
}
|
||||
|
||||
// 2. 如果修改为指定路径
|
||||
else if (FileStorageTypeEnum.LOCAL.getCode().equals(storageConfig.getFileSaveType())) {
|
||||
jarPath = storageConfig.getLocalFileSavePath();
|
||||
}
|
||||
|
||||
// 修改类型
|
||||
sysConfigService.updateConfigByCode(ConfigConstants.SYS_FILE_SAVE_TYPE_CONFIG_CODE, String.valueOf(storageConfig.getFileSaveType()));
|
||||
|
||||
// 修改路径配置
|
||||
if (SystemUtil.getOsInfo().isWindows()) {
|
||||
sysConfigService.updateConfigByCode(ConfigConstants.SYS_LOCAL_FILE_SAVE_PATH_WINDOWS, jarPath);
|
||||
} else {
|
||||
sysConfigService.updateConfigByCode(ConfigConstants.SYS_LOCAL_FILE_SAVE_PATH_LINUX, jarPath);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue