fix(项目管理): 修复发送邮件通知标题语言环境获取问题

This commit is contained in:
guoyuqi 2024-02-05 16:20:35 +08:00 committed by 刘瑞斌
parent e3499e11c2
commit 8778a78db9
1 changed files with 12 additions and 1 deletions

View File

@ -10,6 +10,7 @@ import io.metersphere.system.service.NoticeSendService;
import io.metersphere.system.service.SystemParameterService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;
@ -24,7 +25,7 @@ public class AfterReturningNoticeSendService {
@Async
public void sendNotice(String taskType, String event, List<Map> resources, SessionUser sessionUser, String currentProjectId) {
setLanguage(sessionUser.getLanguage());
// 有批量操作发送多次
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
for (Map resource : resources) {
@ -73,6 +74,16 @@ public class AfterReturningNoticeSendService {
return defaultTemplateTitleMap.get(taskType + "_" + event);
}
private static void setLanguage(String language) {
Locale locale = Locale.SIMPLIFIED_CHINESE;
if (StringUtils.containsIgnoreCase("US",language)) {
locale = Locale.US;
} else if (StringUtils.containsIgnoreCase("TW",language)){
locale = Locale.TAIWAN;
}
LocaleContextHolder.setLocale(locale);
}
/**
* 有些默认的值避免通知里出现 ${key}