diff --git a/ReadMe.md b/ReadMe.md index 0727598..432f611 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -12,6 +12,16 @@ Pure-admin文档:https://pure-admin.github.io/pure-admin-doc 正式线上预览地址:http://bunny-web.site/#/welcome +> 如果发现网站打开白屏很有可能是因为更新造成的,因为需要维护删除不需要的功能可能会导致这个情况,但基本不会遇到。 +> +> 谷歌方式如下: +> +> ![image-20250108225817891](http://116.196.101.14:9000/docs/image-20250108225817891.png) +> +> Edge方式如下: +> +> ![image-20250108225915189](http://116.196.101.14:9000/docs/image-20250108225915189.png) + **打包视频** https://www.bilibili.com/video/BV1AYm8YSEKY/ @@ -1200,6 +1210,8 @@ mvn clean package -Pprod -DskipTests mvn clean package -Ptest -DskipTests ``` +**:star: 如果不需要内置文件操作什么的这一步可以忽略** + ![image-20241108153705104](http://116.196.101.14:9000/docs/auth/image-20241108153705104.png) 这个文件夹是必须的 diff --git a/dao/src/main/java/cn/bunny/dao/constant/RedisUserConstant.java b/dao/src/main/java/cn/bunny/dao/constant/RedisUserConstant.java index a0f8e4d..6cc314e 100644 --- a/dao/src/main/java/cn/bunny/dao/constant/RedisUserConstant.java +++ b/dao/src/main/java/cn/bunny/dao/constant/RedisUserConstant.java @@ -10,6 +10,7 @@ public class RedisUserConstant { // 过期时间 public static final Long REDIS_EXPIRATION_TIME = 7L;// 7 天/分钟 Redis过期 public static final Integer Cookie_EXPIRATION_TIME = 5 * 60 * 60;// cookies 过期时间 5 分钟 + public static final String WEB_CONFIG_KEY = "webConfig::platformConfig";// web配置 private static final String ADMIN_LOGIN_INFO_PREFIX = "admin::login_info::"; private static final String ADMIN_EMAIL_CODE_PREFIX = "admin::email_code::"; diff --git a/dao/src/main/java/cn/bunny/dao/vo/configuration/WebConfigurationVo.java b/dao/src/main/java/cn/bunny/dao/vo/configuration/WebConfigurationVo.java deleted file mode 100644 index 287c131..0000000 --- a/dao/src/main/java/cn/bunny/dao/vo/configuration/WebConfigurationVo.java +++ /dev/null @@ -1,121 +0,0 @@ -package cn.bunny.dao.vo.configuration; - -import com.alibaba.fastjson2.annotation.JSONField; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Builder -@Schema(name = "WebConfigurationVo对象", title = "前端配置获取返回结果", description = "前端配置获取返回结果") -public class WebConfigurationVo { - - @Schema(name = "Version", description = "应用程序的版本") - @JSONField(name = "Version") - private String version; - - @Schema(name = "Title", description = "应用程序的标题") - @JSONField(name = "Title") - private String title; - - @Schema(name = "Copyright", description = "版权信息") - @JSONField(name = "Copyright") - private String copyright; - - @Schema(name = "FixedHeader", description = "头部是否固定") - @JSONField(name = "FixedHeader") - private boolean fixedHeader; - - @Schema(name = "HiddenSideBar", description = "侧边栏是否隐藏") - @JSONField(name = "HiddenSideBar") - private boolean hiddenSideBar; - - @Schema(name = "MultiTagsCache", description = "是否缓存多个标签") - @JSONField(name = "MultiTagsCache") - private boolean multiTagsCache; - - @Schema(name = "KeepAlive", description = "是否持久化") - @JSONField(name = "KeepAlive") - private boolean keepAlive; - - @Schema(name = "Locale", description = "语言类型") - @JSONField(name = "Locale") - private String locale; - - @Schema(name = "Layout", description = "应用程序的布局") - @JSONField(name = "Layout") - private String layout; - - @Schema(name = "Theme", description = "应用程序的主题") - @JSONField(name = "Theme") - private String theme; - - @Schema(name = "DarkMode", description = "是否启用深色模式") - @JSONField(name = "DarkMode") - private boolean darkMode; - - @Schema(name = "OverallStyle", description = "应用程序的整体样式") - @JSONField(name = "OverallStyle") - private String overallStyle; - - @Schema(name = "Grey", description = "是否启用灰色模式") - @JSONField(name = "Grey") - private boolean grey; - - @Schema(name = "Weak", description = "色弱模式") - @JSONField(name = "Weak") - private boolean weak; - - @Schema(name = "HideTabs", description = "是否隐藏选项卡") - @JSONField(name = "HideTabs") - private boolean hideTabs; - - @Schema(name = "HideFooter", description = "是否隐藏页脚") - @JSONField(name = "HideFooter") - private boolean hideFooter; - - @Schema(name = "Stretch", description = "是否拉伸显示") - @JSONField(name = "Stretch") - private boolean stretch; - - @Schema(name = "SidebarStatus", description = "侧边栏的状态") - @JSONField(name = "SidebarStatus") - private boolean sidebarStatus; - - @Schema(name = "EpThemeColor", description = "主题颜色") - @JSONField(name = "EpThemeColor") - private String epThemeColor; - - @Schema(name = "ShowLogo", description = "是否显示logo") - @JSONField(name = "ShowLogo") - private boolean showLogo; - - @Schema(name = "ShowModel", description = "要显示的模型") - @JSONField(name = "ShowModel") - private String showModel; - - @Schema(name = "MenuArrowIconNoTransition", description = "菜单箭头图标是否没有过渡效果") - @JSONField(name = "MenuArrowIconNoTransition") - private boolean menuArrowIconNoTransition; - - @Schema(name = "CachingAsyncRoutes", description = "是否缓存异步路由") - @JSONField(name = "CachingAsyncRoutes") - private boolean cachingAsyncRoutes; - - @Schema(name = "TooltipEffect", description = "工具提示的效果") - @JSONField(name = "TooltipEffect") - private String tooltipEffect; - - @Schema(name = "ResponsiveStorageNameSpace", description = "响应式存储的命名空间") - @JSONField(name = "ResponsiveStorageNameSpace") - private String responsiveStorageNameSpace; - - @Schema(name = "MenuSearchHistory", description = "菜单搜索历史") - @JSONField(name = "MenuSearchHistory") - private int menuSearchHistory; - -} \ No newline at end of file diff --git a/service/src/main/java/cn/bunny/services/controller/ConfigurationController.java b/service/src/main/java/cn/bunny/services/controller/ConfigurationController.java index c9d080b..478ad3c 100644 --- a/service/src/main/java/cn/bunny/services/controller/ConfigurationController.java +++ b/service/src/main/java/cn/bunny/services/controller/ConfigurationController.java @@ -2,14 +2,12 @@ package cn.bunny.services.controller; import cn.bunny.dao.dto.system.configuration.WebConfigurationDto; import cn.bunny.dao.entity.configuration.WebConfiguration; -import cn.bunny.dao.vo.configuration.WebConfigurationVo; import cn.bunny.dao.vo.result.Result; import cn.bunny.dao.vo.result.ResultCodeEnum; import cn.bunny.services.service.ConfigurationService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; -import lombok.SneakyThrows; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import reactor.core.publisher.Mono; @@ -22,19 +20,17 @@ public class ConfigurationController { @Autowired private ConfigurationService configurationService; - @SneakyThrows @Operation(summary = "读取web配置文件", description = "读取web配置文件") @GetMapping("noAuth/webConfig") public WebConfiguration webConfig() { return configurationService.webConfig(); } - @SneakyThrows @Operation(summary = "获取修改web配置文件", description = "获取修改web配置文件") @GetMapping("getWebConfig") - public Mono> getWebConfig() { - WebConfigurationVo webConfiguration = configurationService.getWebConfig(); - return Mono.just(Result.success(webConfiguration)); + public Result getWebConfig() { + WebConfiguration webConfiguration = configurationService.webConfig(); + return Result.success(webConfiguration); } @Operation(summary = "更新web配置文件", description = "更新web配置文件") diff --git a/service/src/main/java/cn/bunny/services/service/ConfigurationService.java b/service/src/main/java/cn/bunny/services/service/ConfigurationService.java index 2aa1cb5..38d3162 100644 --- a/service/src/main/java/cn/bunny/services/service/ConfigurationService.java +++ b/service/src/main/java/cn/bunny/services/service/ConfigurationService.java @@ -2,7 +2,6 @@ package cn.bunny.services.service; import cn.bunny.dao.dto.system.configuration.WebConfigurationDto; import cn.bunny.dao.entity.configuration.WebConfiguration; -import cn.bunny.dao.vo.configuration.WebConfigurationVo; public interface ConfigurationService { @@ -20,10 +19,4 @@ public interface ConfigurationService { */ WebConfiguration webConfig(); - /** - * 获取修改web配置文件 - * - * @return 要修改前端配置文件 - */ - WebConfigurationVo getWebConfig(); } \ No newline at end of file diff --git a/service/src/main/java/cn/bunny/services/service/impl/ConfigurationServiceImpl.java b/service/src/main/java/cn/bunny/services/service/impl/ConfigurationServiceImpl.java index 9a2cbda..1f44ef3 100644 --- a/service/src/main/java/cn/bunny/services/service/impl/ConfigurationServiceImpl.java +++ b/service/src/main/java/cn/bunny/services/service/impl/ConfigurationServiceImpl.java @@ -1,41 +1,27 @@ package cn.bunny.services.service.impl; import cn.bunny.common.service.exception.AuthCustomerException; +import cn.bunny.dao.constant.RedisUserConstant; import cn.bunny.dao.dto.system.configuration.WebConfigurationDto; import cn.bunny.dao.entity.configuration.WebConfiguration; -import cn.bunny.dao.vo.configuration.WebConfigurationVo; import cn.bunny.dao.vo.result.ResultCodeEnum; import cn.bunny.services.service.ConfigurationService; import com.alibaba.fastjson2.JSON; -import org.jetbrains.annotations.NotNull; import org.springframework.beans.BeanUtils; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.cache.annotation.CacheEvict; -import org.springframework.cache.annotation.Cacheable; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; @Service +@Transactional public class ConfigurationServiceImpl implements ConfigurationService { - @Value("${bunny.bashPath}") - private String bashPath; - - private static @NotNull String getWebConfigString(InputStream inputStream, Path templatePath) throws IOException { - if (inputStream == null) throw new AuthCustomerException(ResultCodeEnum.MISSING_TEMPLATE_FILES); - - // 判断web模板文件是否存在,不存在进行复制 - boolean exists = Files.exists(templatePath); - if (!exists) Files.copy(inputStream, templatePath); - - // 将读取文件返回 - byte[] bytes = Files.readAllBytes(templatePath); - return new String(bytes); - } + @Autowired + private RedisTemplate redisTemplate; /** * * 更新web配置 @@ -43,26 +29,14 @@ public class ConfigurationServiceImpl implements ConfigurationService { * @param dto 前端配置选项 */ @Override - @CacheEvict(cacheNames = "webConfig", key = "'platformConfig'", beforeInvocation = true, cacheManager = "cacheManagerWithMouth") public void updateWebConfiguration(WebConfigurationDto dto) { - try { - // 系统模板文件位置 - Path templatePath = Path.of(bashPath + "/platform-config.json"); + redisTemplate.delete(RedisUserConstant.WEB_CONFIG_KEY); - // 提交表单转换 - WebConfiguration webConfiguration = new WebConfiguration(); - BeanUtils.copyProperties(dto, webConfiguration); + // 提交表单转换 + WebConfiguration webConfiguration = new WebConfiguration(); + BeanUtils.copyProperties(dto, webConfiguration); - // 将表单转成存储的类型 - WebConfigurationVo webConfigurationVo = new WebConfigurationVo(); - BeanUtils.copyProperties(webConfiguration, webConfigurationVo); - - // 将文件写入 - String jsonString = JSON.toJSONString(webConfigurationVo); - Files.writeString(templatePath, jsonString); - } catch (IOException e) { - throw new RuntimeException(e); - } + redisTemplate.opsForValue().set(RedisUserConstant.WEB_CONFIG_KEY, webConfiguration); } /** @@ -71,32 +45,24 @@ public class ConfigurationServiceImpl implements ConfigurationService { * @return 前端配置文件 */ @Override - @Cacheable(cacheNames = "webConfig", key = "'platformConfig'", cacheManager = "cacheManagerWithMouth") public WebConfiguration webConfig() { - // 系统模板文件位置 - Path templatePath = Path.of(bashPath + "/platform-config.json"); - - try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/platform-config.json")) { - String string = getWebConfigString(inputStream, templatePath); - return JSON.parseObject(string, WebConfiguration.class); - } catch (IOException exception) { - throw new AuthCustomerException(exception.getMessage()); + // 判断Redis中是否存在 + Object object = redisTemplate.opsForValue().get(RedisUserConstant.WEB_CONFIG_KEY); + if (object != null) { + String jsonString = JSON.toJSONString(object); + return JSON.parseObject(jsonString, WebConfiguration.class); } - } - - /** - * 获取修改web配置文件 - * - * @return 要修改前端配置文件 - */ - @Override - public WebConfigurationVo getWebConfig() { - // 系统模板文件位置 - Path templatePath = Path.of(bashPath + "/platform-config.json"); + // 不存在从文件中获取 try (InputStream inputStream = getClass().getClassLoader().getResourceAsStream("static/platform-config.json")) { - String string = getWebConfigString(inputStream, templatePath); - return JSON.parseObject(string, WebConfigurationVo.class); + if (inputStream == null) throw new AuthCustomerException(ResultCodeEnum.MISSING_TEMPLATE_FILES); + + // 读取文件返回并存入Redis + byte[] bytes = inputStream.readAllBytes(); + WebConfiguration webConfiguration = JSON.parseObject(new String(bytes), WebConfiguration.class); + redisTemplate.opsForValue().set(RedisUserConstant.WEB_CONFIG_KEY, webConfiguration); + + return webConfiguration; } catch (IOException exception) { throw new AuthCustomerException(exception.getMessage()); } diff --git a/service/src/main/resources/application-dev.yml b/service/src/main/resources/application-dev.yml index ae932e7..d2ccd9d 100644 --- a/service/src/main/resources/application-dev.yml +++ b/service/src/main/resources/application-dev.yml @@ -39,4 +39,3 @@ bunny: bucket-name: auth-admin backPath: "D:\\MyData\\backup" - bashPath: "D:\\MyData\\auth"