From 1bc820485aac8be2aee1611a99b3c4a6ccf2cddb Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Oct 2024 09:50:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=8F=91=E9=80=81?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../metersphere/api/service/ApiReportShareService.java | 9 ++++++--- .../plan/service/TestPlanReportShareService.java | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) 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)); } /**