diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportShareService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportShareService.java index 84e686d6ca..4aaaf3709b 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportShareService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/ApiReportShareService.java @@ -107,7 +107,10 @@ public class ApiReportShareService { public ShareInfoDTO gen(ApiReportShareRequest shareRequest, String 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(); BeanUtils.copyBean(request, shareRequest); request.setLang(lang); @@ -115,8 +118,8 @@ public class ApiReportShareService { request.setCustomData(shareRequest.getReportId().getBytes()); request.setShareType(ShareInfoType.API_SHARE_REPORT.name()); request.setProjectId(shareRequest.getProjectId()); - ShareInfo shareInfo = createShareInfo(request); - return conversionShareInfoToDTO(shareInfo); + + return conversionShareInfoToDTO(createShareInfo(request)); } public ShareInfo checkResource(String id) { diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportShareService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportShareService.java index 55eed6de79..4c1b6f53fc 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportShareService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanReportShareService.java @@ -27,6 +27,7 @@ import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; import static io.metersphere.sdk.util.ShareUtil.getTimeMills; @@ -79,15 +80,18 @@ public class TestPlanReportShareService { */ public TestPlanShareInfo gen(TestPlanReportShareRequest shareRequest, String 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(); BeanUtils.copyBean(request, shareRequest); request.setLang(lang); request.setCreateUser(currentUser); request.setCustomData(shareRequest.getReportId().getBytes()); request.setShareType(ShareInfoType.TEST_PLAN_SHARE_REPORT.name()); - ShareInfo shareInfo = createShareInfo(request); - return conversionShareInfoToDTO(shareInfo); + + return conversionShareInfoToDTO(createShareInfo(request)); } /**