refactor(constant): 将应用名称和标题常量统一管理

This commit is contained in:
2026-01-13 14:19:30 +08:00
parent 3b3bfff2c5
commit c11fd19351
13 changed files with 27 additions and 45 deletions
@@ -46,4 +46,6 @@ public interface SystemConst {
String SYMBOL_AT = "@"; String SYMBOL_AT = "@";
String PROPERTY_OS_NAME = "os.name"; String PROPERTY_OS_NAME = "os.name";
String OS_NAME_WINDOWS = "Windows"; String OS_NAME_WINDOWS = "Windows";
String CURRENT_APP_NAME = "cutejava";
String CURRENT_APP_TITLE = "CuteJava";
} }
@@ -18,7 +18,6 @@ package cn.odboy.framework.server.core;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.odboy.constant.SystemConst; import cn.odboy.constant.SystemConst;
import cn.odboy.util.KitSystemUtil; import cn.odboy.util.KitSystemUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -36,26 +35,24 @@ public class KitFileLocalUploadHelper {
private static final String PATH_WINDOWS = "C:\\${appName}\\file\\"; private static final String PATH_WINDOWS = "C:\\${appName}\\file\\";
private static final String PATH_MAC = "/Users${username}/${appName}/file/"; private static final String PATH_MAC = "/Users${username}/${appName}/file/";
private static final String PATH_LINUX = "/home/${appName}/file/"; private static final String PATH_LINUX = "/home/${appName}/file/";
@Value("${spring.application.name}")
private String appName;
public String getPath() { public String getPath() {
String os = System.getProperty("os.name"); String os = System.getProperty("os.name");
if (os == null) { if (os == null) {
// 默认使用 Linux 路径作为兜底方案 // 默认使用 Linux 路径作为兜底方案
return PATH_LINUX.replace("${appName}", appName); return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME);
} }
String lowerOs = os.toLowerCase(); String lowerOs = os.toLowerCase();
if (lowerOs.startsWith(SystemConst.WIN)) { if (lowerOs.startsWith(SystemConst.WIN)) {
return PATH_WINDOWS.replace("${appName}", appName); return PATH_WINDOWS.replace("${appName}", SystemConst.CURRENT_APP_NAME);
} else if (lowerOs.startsWith(SystemConst.MAC)) { } else if (lowerOs.startsWith(SystemConst.MAC)) {
String currentUserName = KitSystemUtil.getCurrentUserName(); String currentUserName = KitSystemUtil.getCurrentUserName();
if (StrUtil.isBlank(currentUserName)) { if (StrUtil.isBlank(currentUserName)) {
return PATH_MAC.replace("${appName}", appName).replace("${username}", ""); return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", "");
} }
return PATH_MAC.replace("${appName}", appName).replace("${username}", currentUserName); return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", currentUserName);
} }
return PATH_LINUX.replace("${appName}", appName); return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME);
} }
public int getAvatarMaxSize() { public int getAvatarMaxSize() {
@@ -15,13 +15,13 @@
*/ */
package cn.odboy.system.framework.storage.local; package cn.odboy.system.framework.storage.local;
import cn.odboy.constant.SystemConst;
import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.properties.AppProperties;
import java.io.File;
import jakarta.servlet.MultipartConfigElement; import jakarta.servlet.MultipartConfigElement;
import java.io.File;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory; import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
@@ -31,8 +31,6 @@ import org.springframework.util.unit.DataSize;
@Configuration @Configuration
public class MultipartConfig { public class MultipartConfig {
@Value("${spring.application.name}")
private String name;
@Autowired @Autowired
private AppProperties properties; private AppProperties properties;
@@ -44,7 +42,7 @@ public class MultipartConfig {
MultipartConfigFactory factory = new MultipartConfigFactory(); MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); factory.setMaxFileSize(DataSize.ofMegabytes(properties.getOss().getMaxSize()));
factory.setMaxRequestSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); factory.setMaxRequestSize(DataSize.ofMegabytes(properties.getOss().getMaxSize()));
String location = System.getProperty("user.home") + "/" + name + "/tmp"; String location = System.getProperty("user.home") + "/" + SystemConst.CURRENT_APP_NAME + "/tmp";
File tmpFile = new File(location); File tmpFile = new File(location);
if (!tmpFile.exists()) { if (!tmpFile.exists()) {
if (!tmpFile.mkdirs()) { if (!tmpFile.mkdirs()) {
@@ -19,6 +19,7 @@ import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.mail.Mail; import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailAccount;
import cn.odboy.constant.SystemConst;
import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.properties.AppProperties;
import cn.odboy.framework.redis.KitRedisHelper; import cn.odboy.framework.redis.KitRedisHelper;
@@ -32,7 +33,6 @@ import cn.odboy.util.KitResourceTemplateUtil;
import java.util.Collections; import java.util.Collections;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -46,8 +46,6 @@ public class SystemEmailService {
private KitRedisHelper redisHelper; private KitRedisHelper redisHelper;
@Autowired @Autowired
private AppProperties properties; private AppProperties properties;
@Value("${spring.application.title}")
private String applicationTitle;
/** /**
* 更新邮件配置 * 更新邮件配置
@@ -146,7 +144,7 @@ public class SystemEmailService {
KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode));
} }
SystemSendEmailArgs sendEmailRequest = SystemSendEmailArgs sendEmailRequest =
new SystemSendEmailArgs(Collections.singletonList(email), applicationTitle, content); new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content);
sendEmail(sendEmailRequest); sendEmail(sendEmailRequest);
} }
@@ -9,7 +9,7 @@ spring:
quartz: quartz:
scheduler: scheduler:
# 必需,指定调度器实例的名称 # 必需,指定调度器实例的名称
instanceName: ${spring.application.name} instanceName: cutejava
# 必需,指定调度器实例的 ID # 必需,指定调度器实例的 ID
instanceId: auto instanceId: auto
threadPool: threadPool:
@@ -46,4 +46,6 @@ public interface SystemConst {
String SYMBOL_AT = "@"; String SYMBOL_AT = "@";
String PROPERTY_OS_NAME = "os.name"; String PROPERTY_OS_NAME = "os.name";
String OS_NAME_WINDOWS = "Windows"; String OS_NAME_WINDOWS = "Windows";
String CURRENT_APP_NAME = "cutejava";
String CURRENT_APP_TITLE = "CuteJava";
} }
@@ -18,7 +18,6 @@ package cn.odboy.framework.server.core;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import cn.odboy.constant.SystemConst; import cn.odboy.constant.SystemConst;
import cn.odboy.util.KitSystemUtil; import cn.odboy.util.KitSystemUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
/** /**
@@ -36,26 +35,24 @@ public class KitFileLocalUploadHelper {
private static final String PATH_WINDOWS = "C:\\${appName}\\file\\"; private static final String PATH_WINDOWS = "C:\\${appName}\\file\\";
private static final String PATH_MAC = "/Users${username}/${appName}/file/"; private static final String PATH_MAC = "/Users${username}/${appName}/file/";
private static final String PATH_LINUX = "/home/${appName}/file/"; private static final String PATH_LINUX = "/home/${appName}/file/";
@Value("${spring.application.name}")
private String appName;
public String getPath() { public String getPath() {
String os = System.getProperty("os.name"); String os = System.getProperty("os.name");
if (os == null) { if (os == null) {
// 默认使用 Linux 路径作为兜底方案 // 默认使用 Linux 路径作为兜底方案
return PATH_LINUX.replace("${appName}", appName); return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME);
} }
String lowerOs = os.toLowerCase(); String lowerOs = os.toLowerCase();
if (lowerOs.startsWith(SystemConst.WIN)) { if (lowerOs.startsWith(SystemConst.WIN)) {
return PATH_WINDOWS.replace("${appName}", appName); return PATH_WINDOWS.replace("${appName}", SystemConst.CURRENT_APP_NAME);
} else if (lowerOs.startsWith(SystemConst.MAC)) { } else if (lowerOs.startsWith(SystemConst.MAC)) {
String currentUserName = KitSystemUtil.getCurrentUserName(); String currentUserName = KitSystemUtil.getCurrentUserName();
if (StrUtil.isBlank(currentUserName)) { if (StrUtil.isBlank(currentUserName)) {
return PATH_MAC.replace("${appName}", appName).replace("${username}", ""); return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", "");
} }
return PATH_MAC.replace("${appName}", appName).replace("${username}", "/" + currentUserName); return PATH_MAC.replace("${appName}", SystemConst.CURRENT_APP_NAME).replace("${username}", "/" + currentUserName);
} }
return PATH_LINUX.replace("${appName}", appName); return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME);
} }
public int getAvatarMaxSize() { public int getAvatarMaxSize() {
@@ -43,8 +43,8 @@ public class BizLockAspect {
public Object around(ProceedingJoinPoint joinPoint, BizLock bizLock) throws Throwable { public Object around(ProceedingJoinPoint joinPoint, BizLock bizLock) throws Throwable {
// 解析SpEL表达式生成最终的lockKey // 解析SpEL表达式生成最终的lockKey
String lockKey = parseLockKey(joinPoint, bizLock); String lockKey = parseLockKey(joinPoint, bizLock);
Boolean success = redisHelper.setIfAbsent(lockKey, lockKey, bizLock.leaseTime(), bizLock.timeUnit()); boolean success = redisHelper.setIfAbsent(lockKey, lockKey, bizLock.leaseTime(), bizLock.timeUnit());
if (success == null || !success) { if (!success) {
throw new BadRequestException(bizLock.errorMessage()); throw new BadRequestException(bizLock.errorMessage());
} }
try { try {
@@ -15,6 +15,7 @@
*/ */
package cn.odboy.system.framework.storage.local; package cn.odboy.system.framework.storage.local;
import cn.odboy.constant.SystemConst;
import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.properties.AppProperties;
import java.io.File; import java.io.File;
@@ -30,9 +31,6 @@ import org.springframework.util.unit.DataSize;
@Slf4j @Slf4j
@Configuration @Configuration
public class MultipartConfig { public class MultipartConfig {
@Value("${spring.application.name}")
private String name;
@Autowired @Autowired
private AppProperties properties; private AppProperties properties;
@@ -44,7 +42,7 @@ public class MultipartConfig {
MultipartConfigFactory factory = new MultipartConfigFactory(); MultipartConfigFactory factory = new MultipartConfigFactory();
factory.setMaxFileSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); factory.setMaxFileSize(DataSize.ofMegabytes(properties.getOss().getMaxSize()));
factory.setMaxRequestSize(DataSize.ofMegabytes(properties.getOss().getMaxSize())); factory.setMaxRequestSize(DataSize.ofMegabytes(properties.getOss().getMaxSize()));
String location = System.getProperty("user.home") + "/" + name + "/tmp"; String location = System.getProperty("user.home") + "/" + SystemConst.CURRENT_APP_NAME + "/tmp";
File tmpFile = new File(location); File tmpFile = new File(location);
if (!tmpFile.exists()) { if (!tmpFile.exists()) {
if (!tmpFile.mkdirs()) { if (!tmpFile.mkdirs()) {
@@ -19,6 +19,7 @@ import cn.hutool.core.lang.Dict;
import cn.hutool.core.util.RandomUtil; import cn.hutool.core.util.RandomUtil;
import cn.hutool.extra.mail.Mail; import cn.hutool.extra.mail.Mail;
import cn.hutool.extra.mail.MailAccount; import cn.hutool.extra.mail.MailAccount;
import cn.odboy.constant.SystemConst;
import cn.odboy.framework.exception.BadRequestException; import cn.odboy.framework.exception.BadRequestException;
import cn.odboy.framework.properties.AppProperties; import cn.odboy.framework.properties.AppProperties;
import cn.odboy.framework.redis.KitRedisHelper; import cn.odboy.framework.redis.KitRedisHelper;
@@ -32,7 +33,6 @@ import cn.odboy.util.KitResourceTemplateUtil;
import java.util.Collections; import java.util.Collections;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@@ -46,8 +46,6 @@ public class SystemEmailService {
private KitRedisHelper redisHelper; private KitRedisHelper redisHelper;
@Autowired @Autowired
private AppProperties properties; private AppProperties properties;
@Value("${spring.application.title}")
private String applicationTitle;
/** /**
* 更新邮件配置 * 更新邮件配置
@@ -146,7 +144,7 @@ public class SystemEmailService {
KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode)); KitResourceTemplateUtil.render(null, biEnum.getTemplateName(), Dict.create().set("code", oldCode));
} }
SystemSendEmailArgs sendEmailRequest = SystemSendEmailArgs sendEmailRequest =
new SystemSendEmailArgs(Collections.singletonList(email), applicationTitle, content); new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content);
sendEmail(sendEmailRequest); sendEmail(sendEmailRequest);
} }
@@ -29,10 +29,6 @@ server:
# GRACEFUL (优雅): 当应用程序以"GRACEFUL"模式关闭时,它不会接受新的请求且会尝试完成所有正在进行的请求和处理,然后才会终止。这种方式适用于那些可能需要一些时间来清理资源或完成正在进行的任务的场景。 # GRACEFUL (优雅): 当应用程序以"GRACEFUL"模式关闭时,它不会接受新的请求且会尝试完成所有正在进行的请求和处理,然后才会终止。这种方式适用于那些可能需要一些时间来清理资源或完成正在进行的任务的场景。
# IMMEDIATE(立即): 当应用程序以"IMMEDIATE"模式关闭时,它会立即终止,而不管当前是否有任何活动任务或请求。这种方式适用于那些可以立即停止而不会造成严重问题的情况。 # IMMEDIATE(立即): 当应用程序以"IMMEDIATE"模式关闭时,它会立即终止,而不管当前是否有任何活动任务或请求。这种方式适用于那些可以立即停止而不会造成严重问题的情况。
shutdown: graceful shutdown: graceful
spring:
application:
name: cutejava
title: CuteJava
lifecycle: lifecycle:
# 采用java.time.Duration格式的值,如果在这个时间内,优雅停机没有停掉应用,超过这个时间就会强制停止应用 # 采用java.time.Duration格式的值,如果在这个时间内,优雅停机没有停掉应用,超过这个时间就会强制停止应用
timeout-per-shutdown-phase: 30s timeout-per-shutdown-phase: 30s
@@ -29,10 +29,6 @@ server:
# GRACEFUL (优雅): 当应用程序以"GRACEFUL"模式关闭时,它不会接受新的请求且会尝试完成所有正在进行的请求和处理,然后才会终止。这种方式适用于那些可能需要一些时间来清理资源或完成正在进行的任务的场景。 # GRACEFUL (优雅): 当应用程序以"GRACEFUL"模式关闭时,它不会接受新的请求且会尝试完成所有正在进行的请求和处理,然后才会终止。这种方式适用于那些可能需要一些时间来清理资源或完成正在进行的任务的场景。
# IMMEDIATE(立即): 当应用程序以"IMMEDIATE"模式关闭时,它会立即终止,而不管当前是否有任何活动任务或请求。这种方式适用于那些可以立即停止而不会造成严重问题的情况。 # IMMEDIATE(立即): 当应用程序以"IMMEDIATE"模式关闭时,它会立即终止,而不管当前是否有任何活动任务或请求。这种方式适用于那些可以立即停止而不会造成严重问题的情况。
shutdown: graceful shutdown: graceful
spring:
application:
name: cutejava
title: CuteJava
lifecycle: lifecycle:
# 采用java.time.Duration格式的值,如果在这个时间内,优雅停机没有停掉应用,超过这个时间就会强制停止应用 # 采用java.time.Duration格式的值,如果在这个时间内,优雅停机没有停掉应用,超过这个时间就会强制停止应用
timeout-per-shutdown-phase: 30s timeout-per-shutdown-phase: 30s
@@ -9,7 +9,7 @@ spring:
quartz: quartz:
scheduler: scheduler:
# 必需,指定调度器实例的名称 # 必需,指定调度器实例的名称
instanceName: ${spring.application.name} instanceName: cutejava
# 必需,指定调度器实例的 ID # 必需,指定调度器实例的 ID
instanceId: auto instanceId: auto
threadPool: threadPool: