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