From babf25ea74dd29eaeec5721bdd00cfeb1ca35b7b Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Thu, 7 Mar 2024 19:27:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E7=94=A8=E4=BE=8B=E7=AE=A1=E7=90=86):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=94=A8=E4=BE=8B=E8=AF=84=E5=AE=A1=E5=91=A8?= =?UTF-8?q?=E6=9C=9F=E6=97=B6=E9=97=B4=E5=8F=AF=E4=BB=A5=E6=97=A9=E4=BA=8E?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B4=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1036045 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036045 --- .../functional/service/CaseReviewService.java | 30 ++++++++++++++++--- .../controller/CaseReviewControllerTests.java | 14 +++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java index f8207adfab..4b936b6178 100644 --- a/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java +++ b/backend/services/case-management/src/main/java/io/metersphere/functional/service/CaseReviewService.java @@ -286,8 +286,7 @@ public class CaseReviewService { caseReview.setTags(request.getTags()); } caseReview.setDescription(request.getDescription()); - caseReview.setStartTime(request.getStartTime()); - caseReview.setEndTime(request.getEndTime()); + checkAndSetStartAndEndTime(request, caseReview); caseReview.setUpdateTime(System.currentTimeMillis()); caseReview.setUpdateUser(userId); caseReviewMapper.updateByPrimaryKeySelective(caseReview); @@ -365,8 +364,7 @@ public class CaseReviewService { caseReview.setCaseCount(caseIds.size()); } caseReview.setDescription(request.getDescription()); - caseReview.setStartTime(request.getStartTime()); - caseReview.setEndTime(request.getEndTime()); + checkAndSetStartAndEndTime(request, caseReview); caseReview.setCreateTime(System.currentTimeMillis()); caseReview.setUpdateTime(System.currentTimeMillis()); caseReview.setCreateUser(userId); @@ -375,6 +373,30 @@ public class CaseReviewService { return caseReview; } + private void checkAndSetStartAndEndTime(CaseReviewRequest request, CaseReview caseReview) { + long currentZeroTime = getCurrentZeroTime(); + if (request.getStartTime() != null && request.getStartTime() < currentZeroTime) { + throw new MSException("评审周期开始时间不得早于当前时间"); + } else { + caseReview.setStartTime(request.getStartTime()); + } + if (request.getEndTime() != null && request.getEndTime() < currentZeroTime) { + throw new MSException("评审周期结束时间不得早于当前时间"); + } else { + caseReview.setEndTime(request.getEndTime()); + } + } + + public long getCurrentZeroTime() { + Calendar calendar = Calendar.getInstance(); + calendar.set(Calendar.SECOND, 0); + calendar.set(Calendar.MINUTE, 0); + calendar.set(Calendar.HOUR_OF_DAY, 0); + calendar.set(Calendar.MILLISECOND, 0); + return calendar.getTimeInMillis(); + } + + /** * 检查用例评审是否存在 * diff --git a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java index 2ab88a94e3..7bdf92afa5 100644 --- a/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java +++ b/backend/services/case-management/src/test/java/io/metersphere/functional/controller/CaseReviewControllerTests.java @@ -138,6 +138,10 @@ public class CaseReviewControllerTests extends BaseTest { List functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); Assertions.assertEquals(functionalCases.size(), caseReviewFunctionalCases.size()); + caseReviewRequest.setStartTime(1678188043000L); + caseReviewRequest.setEndTime(1678188103000L); + this.requestPost(ADD_CASE_REVIEW, caseReviewRequest).andExpect(status().is5xxServerError()); + } private List getCaseReviews(String name) { @@ -224,6 +228,10 @@ public class CaseReviewControllerTests extends BaseTest { this.requestPost(ADD_CASE_REVIEW, caseReviewRequestNoReviewer).andExpect(status().is4xxClientError()); CaseReviewRequest caseReviewRequestNoName = getCaseReviewAddRequest(null, CaseReviewPassRule.SINGLE.toString(), null, true, true, null); this.requestPost(ADD_CASE_REVIEW, caseReviewRequestNoName).andExpect(status().is4xxClientError()); + CaseReviewRequest caseReviewRequestWidthStartTime = getCaseReviewAddRequest("创建评审5", CaseReviewPassRule.SINGLE.toString(), null, true, true, null); + caseReviewRequestWidthStartTime.setStartTime(1678188043000L); + caseReviewRequestWidthStartTime.setEndTime(1678188103000L); + this.requestPost(ADD_CASE_REVIEW, caseReviewRequestWidthStartTime).andExpect(status().is5xxServerError()); } @Test @@ -283,6 +291,12 @@ public class CaseReviewControllerTests extends BaseTest { this.requestPost(EDIT_CASE_REVIEW, caseReviewRequest).andExpect(status().is4xxClientError()); caseReviewRequest = getCaseReviewAddRequest("创建评审更新1", CaseReviewPassRule.SINGLE.toString(), null, true, true, "XXX"); this.requestPost(EDIT_CASE_REVIEW, caseReviewRequest).andExpect(status().is5xxServerError()); + List caseReviews = getCaseReviews("创建评审1"); + CaseReview caseReview = caseReviews.get(0); + CaseReviewRequest caseReviewRequestWidthStartTime = getCaseReviewAddRequest("创建评审更新1", CaseReviewPassRule.SINGLE.toString(), caseReview.getId(), true, true, null); + caseReviewRequestWidthStartTime.setStartTime(1678188043000L); + caseReviewRequestWidthStartTime.setEndTime(1678188103000L); + this.requestPost(ADD_CASE_REVIEW, caseReviewRequestWidthStartTime).andExpect(status().is5xxServerError()); } @Test