fix: 修复发送通知错误问题

This commit is contained in:
fit2-zhao 2024-10-24 09:50:25 +08:00 committed by Craftsman
parent 6f0fb0a1cb
commit 1bc820485a
2 changed files with 13 additions and 6 deletions

View File

@ -107,7 +107,10 @@ public class ApiReportShareService {
public ShareInfoDTO gen(ApiReportShareRequest shareRequest, String userId) { public ShareInfoDTO gen(ApiReportShareRequest shareRequest, String userId) {
UserDTO userDTO = baseUserMapper.selectById(userId); UserDTO userDTO = baseUserMapper.selectById(userId);
String lang = userDTO.getLanguage() == null ? LocaleContextHolder.getLocale().toString().split("_#")[0] : userDTO.getLanguage(); String lang = (userDTO != null && userDTO.getLanguage() != null)
? userDTO.getLanguage()
: LocaleContextHolder.getLocale().toString().split("_#")[0];
ShareInfo request = new ShareInfo(); ShareInfo request = new ShareInfo();
BeanUtils.copyBean(request, shareRequest); BeanUtils.copyBean(request, shareRequest);
request.setLang(lang); request.setLang(lang);
@ -115,8 +118,8 @@ public class ApiReportShareService {
request.setCustomData(shareRequest.getReportId().getBytes()); request.setCustomData(shareRequest.getReportId().getBytes());
request.setShareType(ShareInfoType.API_SHARE_REPORT.name()); request.setShareType(ShareInfoType.API_SHARE_REPORT.name());
request.setProjectId(shareRequest.getProjectId()); request.setProjectId(shareRequest.getProjectId());
ShareInfo shareInfo = createShareInfo(request);
return conversionShareInfoToDTO(shareInfo); return conversionShareInfoToDTO(createShareInfo(request));
} }
public ShareInfo checkResource(String id) { public ShareInfo checkResource(String id) {

View File

@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.List; import java.util.List;
import java.util.Optional;
import static io.metersphere.sdk.util.ShareUtil.getTimeMills; import static io.metersphere.sdk.util.ShareUtil.getTimeMills;
@ -79,15 +80,18 @@ public class TestPlanReportShareService {
*/ */
public TestPlanShareInfo gen(TestPlanReportShareRequest shareRequest, String currentUser) { public TestPlanShareInfo gen(TestPlanReportShareRequest shareRequest, String currentUser) {
UserDTO userDTO = baseUserMapper.selectById(currentUser); UserDTO userDTO = baseUserMapper.selectById(currentUser);
String lang = userDTO.getLanguage() == null ? LocaleContextHolder.getLocale().toString().split("_#")[0] : userDTO.getLanguage(); String lang = Optional.ofNullable(userDTO)
.map(UserDTO::getLanguage)
.orElse(LocaleContextHolder.getLocale().toString().split("_#")[0]);
ShareInfo request = new ShareInfo(); ShareInfo request = new ShareInfo();
BeanUtils.copyBean(request, shareRequest); BeanUtils.copyBean(request, shareRequest);
request.setLang(lang); request.setLang(lang);
request.setCreateUser(currentUser); request.setCreateUser(currentUser);
request.setCustomData(shareRequest.getReportId().getBytes()); request.setCustomData(shareRequest.getReportId().getBytes());
request.setShareType(ShareInfoType.TEST_PLAN_SHARE_REPORT.name()); request.setShareType(ShareInfoType.TEST_PLAN_SHARE_REPORT.name());
ShareInfo shareInfo = createShareInfo(request);
return conversionShareInfoToDTO(shareInfo); return conversionShareInfoToDTO(createShareInfo(request));
} }
/** /**