refactor(constant): 将应用名称和标题常量统一管理
This commit is contained in:
+2
@@ -46,4 +46,6 @@ public interface SystemConst {
|
||||
String SYMBOL_AT = "@";
|
||||
String PROPERTY_OS_NAME = "os.name";
|
||||
String OS_NAME_WINDOWS = "Windows";
|
||||
String CURRENT_APP_NAME = "cutejava";
|
||||
String CURRENT_APP_TITLE = "CuteJava";
|
||||
}
|
||||
|
||||
+5
-8
@@ -18,7 +18,6 @@ package cn.odboy.framework.server.core;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.util.KitSystemUtil;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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_MAC = "/Users${username}/${appName}/file/";
|
||||
private static final String PATH_LINUX = "/home/${appName}/file/";
|
||||
@Value("${spring.application.name}")
|
||||
private String appName;
|
||||
|
||||
public String getPath() {
|
||||
String os = System.getProperty("os.name");
|
||||
if (os == null) {
|
||||
// 默认使用 Linux 路径作为兜底方案
|
||||
return PATH_LINUX.replace("${appName}", appName);
|
||||
return PATH_LINUX.replace("${appName}", SystemConst.CURRENT_APP_NAME);
|
||||
}
|
||||
String lowerOs = os.toLowerCase();
|
||||
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)) {
|
||||
String currentUserName = KitSystemUtil.getCurrentUserName();
|
||||
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() {
|
||||
|
||||
+3
-5
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package cn.odboy.system.framework.storage.local;
|
||||
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
import cn.odboy.framework.properties.AppProperties;
|
||||
import java.io.File;
|
||||
import jakarta.servlet.MultipartConfigElement;
|
||||
import java.io.File;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.servlet.MultipartConfigFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -31,8 +31,6 @@ import org.springframework.util.unit.DataSize;
|
||||
@Configuration
|
||||
public class MultipartConfig {
|
||||
|
||||
@Value("${spring.application.name}")
|
||||
private String name;
|
||||
@Autowired
|
||||
private AppProperties properties;
|
||||
|
||||
@@ -44,7 +42,7 @@ public class MultipartConfig {
|
||||
MultipartConfigFactory factory = new MultipartConfigFactory();
|
||||
factory.setMaxFileSize(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);
|
||||
if (!tmpFile.exists()) {
|
||||
if (!tmpFile.mkdirs()) {
|
||||
|
||||
+2
-4
@@ -19,6 +19,7 @@ import cn.hutool.core.lang.Dict;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.extra.mail.Mail;
|
||||
import cn.hutool.extra.mail.MailAccount;
|
||||
import cn.odboy.constant.SystemConst;
|
||||
import cn.odboy.framework.exception.BadRequestException;
|
||||
import cn.odboy.framework.properties.AppProperties;
|
||||
import cn.odboy.framework.redis.KitRedisHelper;
|
||||
@@ -32,7 +33,6 @@ import cn.odboy.util.KitResourceTemplateUtil;
|
||||
import java.util.Collections;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -46,8 +46,6 @@ public class SystemEmailService {
|
||||
private KitRedisHelper redisHelper;
|
||||
@Autowired
|
||||
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));
|
||||
}
|
||||
SystemSendEmailArgs sendEmailRequest =
|
||||
new SystemSendEmailArgs(Collections.singletonList(email), applicationTitle, content);
|
||||
new SystemSendEmailArgs(Collections.singletonList(email), SystemConst.CURRENT_APP_TITLE, content);
|
||||
sendEmail(sendEmailRequest);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ spring:
|
||||
quartz:
|
||||
scheduler:
|
||||
# 必需,指定调度器实例的名称
|
||||
instanceName: ${spring.application.name}
|
||||
instanceName: cutejava
|
||||
# 必需,指定调度器实例的 ID
|
||||
instanceId: auto
|
||||
threadPool:
|
||||
|
||||
Reference in New Issue
Block a user