fix(用例管理): 修复用例评审周期时间可以早于当前时间问题

--bug=1036045 --user=郭雨琦 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001036045
This commit is contained in:
guoyuqi 2024-03-07 19:27:49 +08:00 committed by 刘瑞斌
parent cad05038c3
commit babf25ea74
2 changed files with 40 additions and 4 deletions

View File

@ -286,8 +286,7 @@ public class CaseReviewService {
caseReview.setTags(request.getTags()); caseReview.setTags(request.getTags());
} }
caseReview.setDescription(request.getDescription()); caseReview.setDescription(request.getDescription());
caseReview.setStartTime(request.getStartTime()); checkAndSetStartAndEndTime(request, caseReview);
caseReview.setEndTime(request.getEndTime());
caseReview.setUpdateTime(System.currentTimeMillis()); caseReview.setUpdateTime(System.currentTimeMillis());
caseReview.setUpdateUser(userId); caseReview.setUpdateUser(userId);
caseReviewMapper.updateByPrimaryKeySelective(caseReview); caseReviewMapper.updateByPrimaryKeySelective(caseReview);
@ -365,8 +364,7 @@ public class CaseReviewService {
caseReview.setCaseCount(caseIds.size()); caseReview.setCaseCount(caseIds.size());
} }
caseReview.setDescription(request.getDescription()); caseReview.setDescription(request.getDescription());
caseReview.setStartTime(request.getStartTime()); checkAndSetStartAndEndTime(request, caseReview);
caseReview.setEndTime(request.getEndTime());
caseReview.setCreateTime(System.currentTimeMillis()); caseReview.setCreateTime(System.currentTimeMillis());
caseReview.setUpdateTime(System.currentTimeMillis()); caseReview.setUpdateTime(System.currentTimeMillis());
caseReview.setCreateUser(userId); caseReview.setCreateUser(userId);
@ -375,6 +373,30 @@ public class CaseReviewService {
return caseReview; 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();
}
/** /**
* 检查用例评审是否存在 * 检查用例评审是否存在
* *

View File

@ -138,6 +138,10 @@ public class CaseReviewControllerTests extends BaseTest {
List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample); List<FunctionalCase> functionalCases = functionalCaseMapper.selectByExample(functionalCaseExample);
Assertions.assertEquals(functionalCases.size(), caseReviewFunctionalCases.size()); Assertions.assertEquals(functionalCases.size(), caseReviewFunctionalCases.size());
caseReviewRequest.setStartTime(1678188043000L);
caseReviewRequest.setEndTime(1678188103000L);
this.requestPost(ADD_CASE_REVIEW, caseReviewRequest).andExpect(status().is5xxServerError());
} }
private List<CaseReview> getCaseReviews(String name) { private List<CaseReview> getCaseReviews(String name) {
@ -224,6 +228,10 @@ public class CaseReviewControllerTests extends BaseTest {
this.requestPost(ADD_CASE_REVIEW, caseReviewRequestNoReviewer).andExpect(status().is4xxClientError()); this.requestPost(ADD_CASE_REVIEW, caseReviewRequestNoReviewer).andExpect(status().is4xxClientError());
CaseReviewRequest caseReviewRequestNoName = getCaseReviewAddRequest(null, CaseReviewPassRule.SINGLE.toString(), null, true, true, null); CaseReviewRequest caseReviewRequestNoName = getCaseReviewAddRequest(null, CaseReviewPassRule.SINGLE.toString(), null, true, true, null);
this.requestPost(ADD_CASE_REVIEW, caseReviewRequestNoName).andExpect(status().is4xxClientError()); 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 @Test
@ -283,6 +291,12 @@ public class CaseReviewControllerTests extends BaseTest {
this.requestPost(EDIT_CASE_REVIEW, caseReviewRequest).andExpect(status().is4xxClientError()); this.requestPost(EDIT_CASE_REVIEW, caseReviewRequest).andExpect(status().is4xxClientError());
caseReviewRequest = getCaseReviewAddRequest("创建评审更新1", CaseReviewPassRule.SINGLE.toString(), null, true, true, "XXX"); caseReviewRequest = getCaseReviewAddRequest("创建评审更新1", CaseReviewPassRule.SINGLE.toString(), null, true, true, "XXX");
this.requestPost(EDIT_CASE_REVIEW, caseReviewRequest).andExpect(status().is5xxServerError()); this.requestPost(EDIT_CASE_REVIEW, caseReviewRequest).andExpect(status().is5xxServerError());
List<CaseReview> 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 @Test