Skip to content

Commit

Permalink
chore: 使用属性变量消除配置文件中分散的 ContiNew Admin 品牌元素
Browse files Browse the repository at this point in the history
1.项目配置属性前缀由 continew-admin 改为 project(暂时未发现属性前缀 project 冲突)
2.配置文件中涉及到项目元素信息使用的,统一通过变量引用项目配置属性(如此改动之后,仅需要修改项目配置即可快速调整大量项目配置信息)
  • Loading branch information
Charles7c committed Aug 20, 2023
1 parent cd3ac8a commit 54ea410
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.RandomUtil;

import top.charles7c.cnadmin.common.config.properties.ContiNewAdminProperties;
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;

/**
* 接口文档配置
Expand All @@ -42,17 +42,17 @@
@ConditionalOnProperty(name = "springdoc.swagger-ui.enabled", havingValue = "true", matchIfMissing = true)
public class SwaggerConfiguration {

private final ContiNewAdminProperties continewAdminProperties;
private final ProjectProperties projectProperties;

/**
* 接口文档配置
*/
@Bean
public OpenAPI openApi() {
return new OpenAPI().info(new Info().title(continewAdminProperties.getName() + " 接口文档")
.version(String.format("v%s", continewAdminProperties.getVersion()))
.description(continewAdminProperties.getDescription()).termsOfService(continewAdminProperties.getUrl())
.contact(continewAdminProperties.getAuthor()).license(continewAdminProperties.getLicense()));
return new OpenAPI().info(new Info().title(projectProperties.getName() + " 接口文档")
.version(String.format("v%s", projectProperties.getVersion()))
.description(projectProperties.getDescription()).termsOfService(projectProperties.getUrl())
.contact(projectProperties.getAuthor()).license(projectProperties.getLicense()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
*/
@Data
@Component
@ConfigurationProperties(prefix = "continew-admin")
public class ContiNewAdminProperties {
@ConfigurationProperties(prefix = "project")
public class ProjectProperties {

/**
* 名称
Expand Down Expand Up @@ -87,6 +87,6 @@ public class ContiNewAdminProperties {
public static final boolean IP_ADDR_LOCAL_PARSE_ENABLED;

static {
IP_ADDR_LOCAL_PARSE_ENABLED = Convert.toBool(SpringUtil.getProperty("continew-admin.ipAddrLocalParseEnabled"));
IP_ADDR_LOCAL_PARSE_ENABLED = Convert.toBool(SpringUtil.getProperty("project.ipAddrLocalParseEnabled"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;

import top.charles7c.cnadmin.common.config.properties.ContiNewAdminProperties;
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;

import net.dreamlu.mica.ip2region.core.Ip2regionSearcher;
import net.dreamlu.mica.ip2region.core.IpInfo;
Expand Down Expand Up @@ -55,7 +55,7 @@ public class IpUtils {
* @return 归属地信息
*/
public static String getCityInfo(String ip) {
if (ContiNewAdminProperties.IP_ADDR_LOCAL_PARSE_ENABLED) {
if (ProjectProperties.IP_ADDR_LOCAL_PARSE_ENABLED) {
return getLocalCityInfo(ip);
} else {
return getHttpCityInfo(ip);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import cn.hutool.core.util.URLUtil;
import cn.hutool.extra.spring.SpringUtil;

import top.charles7c.cnadmin.common.config.properties.ContiNewAdminProperties;
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;

/**
* 启动程序
Expand All @@ -54,7 +54,7 @@
@ComponentScan(basePackages = {"top.charles7c.cnadmin", "cn.hutool.extra.spring"})
public class ContiNewAdminApplication implements ApplicationRunner {

private final ContiNewAdminProperties properties;
private final ProjectProperties projectProperties;
private final ServerProperties serverProperties;

public static void main(String[] args) {
Expand All @@ -70,7 +70,7 @@ public static void main(String[] args) {
@SaIgnore
@GetMapping("/")
public String index() {
return String.format("%s backend service started successfully.", properties.getName());
return String.format("%s backend service started successfully.", projectProperties.getName());
}

@Override
Expand All @@ -80,7 +80,7 @@ public void run(ApplicationArguments args) throws Exception {
String contextPath = serverProperties.getServlet().getContextPath();
String baseUrl = URLUtil.normalize(String.format("%s:%s%s", hostAddress, port, contextPath));
log.info("------------------------------------------------------");
log.info("{} backend service started successfully.", properties.getName());
log.info("{} backend service started successfully.", projectProperties.getName());
log.info("后端 API 地址:{}", baseUrl);
Boolean docEnabled = Convert.toBool(SpringUtil.getProperty("springdoc.swagger-ui.enabled"));
if (Boolean.TRUE.equals(docEnabled)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import cn.hutool.core.util.RandomUtil;

import top.charles7c.cnadmin.common.config.properties.CaptchaProperties;
import top.charles7c.cnadmin.common.config.properties.ContiNewAdminProperties;
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
import top.charles7c.cnadmin.common.constant.CacheConsts;
import top.charles7c.cnadmin.common.constant.RegexConsts;
import top.charles7c.cnadmin.common.model.vo.CaptchaVO;
Expand All @@ -65,7 +65,7 @@
public class CaptchaController {

private final CaptchaProperties captchaProperties;
private final ContiNewAdminProperties properties;
private final ProjectProperties projectProperties;

@Operation(summary = "获取图片验证码", description = "获取图片验证码(Base64编码,带图片格式:data:image/gif;base64)")
@GetMapping("/img")
Expand Down Expand Up @@ -101,7 +101,7 @@ public R getMailCaptcha(
Long expirationInMinutes = captchaMail.getExpirationInMinutes();
String content = TemplateUtils.render(captchaMail.getTemplatePath(),
Dict.create().set("captcha", captcha).set("expiration", expirationInMinutes));
MailUtils.sendHtml(email, String.format("【%s】邮箱验证码", properties.getName()), content);
MailUtils.sendHtml(email, String.format("【%s】邮箱验证码", projectProperties.getName()), content);

// 保存验证码
String captchaKey = RedisUtils.formatKey(captchaKeyPrefix, email);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import cn.hutool.core.util.ClassUtil;

import top.charles7c.cnadmin.common.base.BaseEnum;
import top.charles7c.cnadmin.common.config.properties.ContiNewAdminProperties;
import top.charles7c.cnadmin.common.config.properties.ProjectProperties;
import top.charles7c.cnadmin.common.model.query.SortQuery;
import top.charles7c.cnadmin.common.model.vo.LabelValueVO;
import top.charles7c.cnadmin.common.model.vo.R;
Expand Down Expand Up @@ -67,7 +67,7 @@ public class CommonController {
private final DeptService deptService;
private final MenuService menuService;
private final RoleService roleService;
private final ContiNewAdminProperties properties;
private final ProjectProperties projectProperties;

@Operation(summary = "查询部门树", description = "查询树结构的部门列表")
@GetMapping("/tree/dept")
Expand Down Expand Up @@ -95,7 +95,7 @@ public R<List<LabelValueVO<Long>>> listRoleDict(RoleQuery query, SortQuery sortQ
@GetMapping("/dict/enum/{enumTypeName}")
public R<List<LabelValueVO>> listEnumDict(@PathVariable String enumTypeName) {
// 扫描所有 BaseEnum 枚举基类的子类
Set<Class<?>> classSet = ClassUtil.scanPackageBySuper(properties.getBasePackage(), BaseEnum.class);
Set<Class<?>> classSet = ClassUtil.scanPackageBySuper(projectProperties.getBasePackage(), BaseEnum.class);
Optional<Class<?>> first =
classSet.stream().filter(c -> c.getSimpleName().equalsIgnoreCase(enumTypeName)).findFirst();
if (!first.isPresent()) {
Expand Down
4 changes: 2 additions & 2 deletions continew-admin-webapi/src/main/resources/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ local-storage:
avatarMaxSizeInMb: 5
## Windows 系统本地存储配置
windows:
file: C:\continew-admin\data\file\
avatar: C:\continew-admin\data\avatar\
file: C:\${project.appName}\data\file\
avatar: C:\${project.appName}\data\avatar\
## Linux 系统本地存储配置
linux:
file: /data/file/
Expand Down
7 changes: 3 additions & 4 deletions continew-admin-webapi/src/main/resources/application-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ local-storage:
avatarMaxSizeInMb: 5
## Windows 系统本地存储配置
windows:
file: C:\continew-admin\data\file\
avatar: C:\continew-admin\data\avatar\
file: C:\${project.appName}\data\file\
avatar: C:\${project.appName}\data\avatar\
## Linux 系统本地存储配置
linux:
file: /data/file/
Expand All @@ -169,8 +169,7 @@ local-storage:
cors:
# 配置允许跨域的域名
allowedOrigins:
- https://cnadmin.charles7c.top
- https://cnadmin.charles7c.top
- ${project.url}
# 配置允许跨域的请求方式
allowedMethods: '*'
# 配置允许跨域的请求头
Expand Down
24 changes: 12 additions & 12 deletions continew-admin-webapi/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- ### 项目配置
continew-admin:
project:
# 名称
name: ContiNew Admin
# 应用名称
Expand All @@ -9,7 +9,7 @@ continew-admin:
# 描述
description: ContiNew Admin 中后台管理框架/脚手架,Continue New Admin,持续以最新流行技术栈构建,拥抱变化,迭代优化。
# URL
url: https://github.com/Charles7c/continew-admin
url: https://cnadmin.charles7c.top
# 基本包
basePackage: top.charles7c.cnadmin
## 作者信息配置
Expand Down Expand Up @@ -61,27 +61,27 @@ springdoc:
group-configs:
- group: 'all'
paths-to-match: '/**'
packages-to-scan: top.charles7c.cnadmin.webapi.controller
packages-to-scan: ${project.basePackage}.webapi.controller
- group: 'auth'
display-name: '系统认证'
paths-to-match: '/auth/**'
packages-to-scan: top.charles7c.cnadmin.webapi.controller.auth
packages-to-scan: ${project.basePackage}.webapi.controller.auth
- group: 'common'
display-name: '通用接口'
paths-to-match: '/common/**'
packages-to-scan: top.charles7c.cnadmin.webapi.controller.common
packages-to-scan: ${project.basePackage}.webapi.controller.common
- group: 'system'
display-name: '系统管理'
paths-to-match: '/system/**'
packages-to-scan: top.charles7c.cnadmin.webapi.controller.system
packages-to-scan: ${project.basePackage}.webapi.controller.system
- group: 'tool'
display-name: '系统工具'
paths-to-match: '/tool/**'
packages-to-scan: top.charles7c.cnadmin.webapi.controller.tool
packages-to-scan: ${project.basePackage}.webapi.controller.tool
- group: 'monitor'
display-name: '系统监控'
paths-to-match: '/monitor/**'
packages-to-scan: top.charles7c.cnadmin.webapi.controller.monitor
packages-to-scan: ${project.basePackage}.webapi.controller.monitor
## 接口文档增强配置
knife4j:
enable: true
Expand All @@ -93,7 +93,7 @@ knife4j:
# 是否自定义 footer(默认 false 非自定义)
enable-footer-custom: true
# 自定义 footer 内容,支持 Markdown 语法
footer-custom-content: 'Copyright © 2022-present [${continew-admin.author.name}](${continew-admin.author.url})&nbsp;⋅&nbsp;[${continew-admin.name}](${continew-admin.url}) v${continew-admin.version}'
footer-custom-content: 'Copyright © 2022-present [${project.author.name}](${project.author.url})&nbsp;⋅&nbsp;[${project.name}](${project.url}) v${project.version}'

--- ### Sa-Token 配置
sa-token:
Expand Down Expand Up @@ -124,11 +124,11 @@ sa-token:
mybatis-plus:
# Mapper 接口扫描包配置(该配置为自定义配置,非 MP 配置,不支持多包,如有需要可通过注解配置或提升扫描包层级)
# 该配置目前的唯一使用场景为:@MapperScan("${mybatis-plus.mapper-package}")
mapper-package: top.charles7c.**.mapper
mapper-package: ${project.basePackage}.**.mapper
# Mapper XML 文件目录配置
mapper-locations: classpath*:/mapper/**/*Mapper.xml
# 类型别名扫描包配置
type-aliases-package: top.charles7c.**.model
type-aliases-package: ${project.basePackage}.**.model
check-config-location: true
configuration:
# 自动驼峰命名规则(camel case)映射
Expand Down Expand Up @@ -180,7 +180,7 @@ server:
--- ### Spring 配置
spring:
application:
name: ${continew-admin.appName}
name: ${project.appName}
## 环境配置
profiles:
# 启用的环境
Expand Down
2 changes: 1 addition & 1 deletion continew-admin-webapi/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
| |___| (_) || | | || |_ | || |\ || __/ \ V V /|_____|/ ___ \| (_| || | | | | || || | | |
\____|\___/ |_| |_| \__||_||_| \_| \___| \_/\_/ /_/ \_\\__,_||_| |_| |_||_||_| |_|

:: ${continew-admin.name} :: v${continew-admin.version}
:: ${project.name} :: v${project.version}
:: Spring Boot :: v${spring-boot.version}

0 comments on commit 54ea410

Please sign in to comment.