From 3fe8b20534a259ba7846599f417f07c97f94199d Mon Sep 17 00:00:00 2001 From: stylefeng Date: Sat, 31 Aug 2024 19:11:17 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=908.3.0=E3=80=91=E3=80=90config=E3=80=91?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E9=85=8D=E7=BD=AE=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NewFileConfigController.java | 15 +++++++++++ .../modular/pojo/newconfig/StorageConfig.java | 2 ++ .../modular/service/NewConfigService.java | 8 ++++++ .../service/impl/NewConfigServiceImpl.java | 27 +++++++++++++++++++ 4 files changed, 52 insertions(+) diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/NewFileConfigController.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/NewFileConfigController.java index e5103e637..dc86e431a 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/NewFileConfigController.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/controller/NewFileConfigController.java @@ -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<>(); + } + } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/pojo/newconfig/StorageConfig.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/pojo/newconfig/StorageConfig.java index 86ece673d..5f902a4a9 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/pojo/newconfig/StorageConfig.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/pojo/newconfig/StorageConfig.java @@ -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; /** diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/NewConfigService.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/NewConfigService.java index 2f69a6510..e76d4f5f8 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/NewConfigService.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/NewConfigService.java @@ -42,4 +42,12 @@ public interface NewConfigService { */ StorageConfig getStorageConfig(); + /** + * 更新文件的配置 + * + * @author fengshuonan + * @since 2024/8/31 18:01 + */ + void updateFileConfig(StorageConfig storageConfig); + } diff --git a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/NewConfigServiceImpl.java b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/NewConfigServiceImpl.java index f15eab4ce..1477bc815 100644 --- a/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/NewConfigServiceImpl.java +++ b/kernel-d-config/config-business/src/main/java/cn/stylefeng/roses/kernel/config/modular/service/impl/NewConfigServiceImpl.java @@ -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); + } + } + }