【8.3.0】【config】更新修改文件存储配置的接口

master
stylefeng 2024-08-31 19:11:17 +08:00
parent 72e14614bd
commit 3fe8b20534
4 changed files with 52 additions and 0 deletions

View File

@ -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.rule.pojo.response.SuccessResponseData;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource; 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.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
/** /**
@ -58,6 +61,18 @@ public class NewFileConfigController {
return new SuccessResponseData<>(storageConfig); 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<>();
}
} }

View File

@ -1,6 +1,7 @@
package cn.stylefeng.roses.kernel.config.modular.pojo.newconfig; package cn.stylefeng.roses.kernel.config.modular.pojo.newconfig;
import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription; import cn.stylefeng.roses.kernel.rule.annotation.ChineseDescription;
import jakarta.validation.constraints.NotNull;
import lombok.Data; import lombok.Data;
/** /**
@ -23,6 +24,7 @@ public class StorageConfig {
* 50- * 50-
*/ */
@ChineseDescription("文件存储类型的配置10-本地存储到默认路径jar所在目录11-本地存储到指定路径下需要配置linux和windows的路径20-存储到MinIO30-存储到阿里云40-存储到腾讯云50-存储到青云") @ChineseDescription("文件存储类型的配置10-本地存储到默认路径jar所在目录11-本地存储到指定路径下需要配置linux和windows的路径20-存储到MinIO30-存储到阿里云40-存储到腾讯云50-存储到青云")
@NotNull(message = "文件存储类型的配置不能为空")
private Integer fileSaveType; private Integer fileSaveType;
/** /**

View File

@ -42,4 +42,12 @@ public interface NewConfigService {
*/ */
StorageConfig getStorageConfig(); StorageConfig getStorageConfig();
/**
*
*
* @author fengshuonan
* @since 2024/8/31 18:01
*/
void updateFileConfig(StorageConfig storageConfig);
} }

View File

@ -2,9 +2,11 @@ package cn.stylefeng.roses.kernel.config.modular.service.impl;
import cn.hutool.system.SystemUtil; import cn.hutool.system.SystemUtil;
import cn.stylefeng.roses.kernel.config.api.constants.ConfigConstants; 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.pojo.newconfig.StorageConfig;
import cn.stylefeng.roses.kernel.config.modular.service.NewConfigService; import cn.stylefeng.roses.kernel.config.modular.service.NewConfigService;
import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService; import cn.stylefeng.roses.kernel.config.modular.service.SysConfigService;
import cn.stylefeng.roses.kernel.rule.util.JarPathUtil;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -41,4 +43,29 @@ public class NewConfigServiceImpl implements NewConfigService {
return storageConfig; 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);
}
}
} }