feat(功能用例): 修改用例基本信息触发重新提审状态

This commit is contained in:
WangXu10 2023-12-15 13:51:23 +08:00 committed by 刘瑞斌
parent f2ec50e15b
commit cb826bb6c8
5 changed files with 126 additions and 11 deletions

View File

@ -3,19 +3,20 @@ package io.metersphere.functional.service;
import io.metersphere.functional.constants.CaseEvent;
import io.metersphere.functional.constants.FunctionalCaseReviewStatus;
import io.metersphere.functional.domain.CaseReviewFunctionalCase;
import io.metersphere.functional.domain.CaseReviewFunctionalCaseExample;
import io.metersphere.functional.domain.*;
import io.metersphere.functional.dto.ReviewFunctionalCaseDTO;
import io.metersphere.functional.dto.ReviewsDTO;
import io.metersphere.functional.mapper.CaseReviewFunctionalCaseMapper;
import io.metersphere.functional.mapper.ExtCaseReviewFunctionalCaseMapper;
import io.metersphere.functional.mapper.ExtCaseReviewFunctionalCaseUserMapper;
import io.metersphere.functional.mapper.ExtFunctionalCaseModuleMapper;
import io.metersphere.functional.mapper.*;
import io.metersphere.functional.request.BaseReviewCaseBatchRequest;
import io.metersphere.functional.request.FunctionalCaseEditRequest;
import io.metersphere.functional.request.ReviewFunctionalCasePageRequest;
import io.metersphere.functional.utils.CaseListenerUtils;
import io.metersphere.project.domain.ProjectApplication;
import io.metersphere.project.domain.ProjectApplicationExample;
import io.metersphere.project.domain.ProjectVersion;
import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.system.dto.sdk.BaseTreeNode;
import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource;
@ -24,6 +25,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.stream.Collectors;
@ -49,6 +51,12 @@ public class CaseReviewFunctionalCaseService {
private CaseReviewFunctionalCaseMapper caseReviewFunctionalCaseMapper;
@Resource
private CaseReviewService caseReviewService;
@Resource
private ProjectApplicationMapper projectApplicationMapper;
@Resource
private CaseReviewHistoryMapper caseReviewHistoryMapper;
@Resource
private FunctionalCaseMapper functionalCaseMapper;
/**
* 通过评审id获取关联的用例id集合
@ -157,4 +165,63 @@ public class CaseReviewFunctionalCaseService {
caseReviewFunctionalCaseMapper.insertSelective(reviewFunctionalCase);
}
/**
* 用例更新 更新状态为重新评审
*
* @param request
* @param blob
*/
public void reReviewedCase(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name) {
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria().andProjectIdEqualTo(request.getProjectId()).andTypeEqualTo(ProjectApplicationType.CASE.CASE_RE_REVIEW.name());
List<ProjectApplication> projectApplications = projectApplicationMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(projectApplications) && Boolean.valueOf(projectApplications.get(0).getTypeValue())) {
if (!StringUtils.equals(name, request.getName())
|| !StringUtils.equals(new String(blob.getSteps(), StandardCharsets.UTF_8), request.getSteps())
|| !StringUtils.equals(new String(blob.getTextDescription(), StandardCharsets.UTF_8), request.getTextDescription())
|| !StringUtils.equals(new String(blob.getExpectedResult(), StandardCharsets.UTF_8), request.getExpectedResult())) {
doHandleStatusAndHistory(request, blob, name);
}
}
}
private void doHandleStatusAndHistory(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name) {
CaseReviewFunctionalCaseExample reviewFunctionalCaseExample = new CaseReviewFunctionalCaseExample();
reviewFunctionalCaseExample.createCriteria().andCaseIdEqualTo(blob.getId());
List<CaseReviewFunctionalCase> caseReviewFunctionalCases = caseReviewFunctionalCaseMapper.selectByExample(reviewFunctionalCaseExample);
if (CollectionUtils.isNotEmpty(caseReviewFunctionalCases)) {
caseReviewFunctionalCases.forEach(item -> {
updateReviewCaseAndCaseStatus(item);
insertHistory(item);
});
}
}
private void insertHistory(CaseReviewFunctionalCase item) {
CaseReviewHistory caseReviewHistory = new CaseReviewHistory();
caseReviewHistory.setId(IDGenerator.nextStr());
caseReviewHistory.setCaseId(item.getCaseId());
caseReviewHistory.setReviewId(item.getReviewId());
caseReviewHistory.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.name());
caseReviewHistory.setCreateUser("system");
caseReviewHistory.setCreateTime(System.currentTimeMillis());
caseReviewHistoryMapper.insertSelective(caseReviewHistory);
}
private void updateReviewCaseAndCaseStatus(CaseReviewFunctionalCase item) {
item.setStatus(FunctionalCaseReviewStatus.RE_REVIEWED.name());
item.setUpdateTime(System.currentTimeMillis());
caseReviewFunctionalCaseMapper.updateByPrimaryKeySelective(item);
FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setId(item.getCaseId());
functionalCase.setReviewStatus(FunctionalCaseReviewStatus.RE_REVIEWED.name());
functionalCaseMapper.updateByPrimaryKeySelective(functionalCase);
}
}

View File

@ -273,6 +273,7 @@ public class FunctionalCaseService {
*/
public FunctionalCase updateFunctionalCase(FunctionalCaseEditRequest request, List<MultipartFile> files, String userId) {
FunctionalCase checked = checkFunctionalCase(request.getId());
FunctionalCaseBlob functionalCaseBlob = functionalCaseBlobMapper.selectByPrimaryKey(request.getId());
//对于用例模块的变更同一用例的其他版本用例也需要变更
if (!StringUtils.equals(checked.getModuleId(), request.getModuleId())) {
@ -302,11 +303,18 @@ public class FunctionalCaseService {
functionalCaseAttachmentService.association(request.getRelateFileMetaIds(), request.getId(), userId, UPDATE_FUNCTIONAL_CASE_FILE_LOG_URL, request.getProjectId());
}
//处理评审状态
handleReviewStatus(request, functionalCaseBlob, checked.getName());
return functionalCase;
}
private void handleReviewStatus(FunctionalCaseEditRequest request, FunctionalCaseBlob blob, String name) {
caseReviewFunctionalCaseService.reReviewedCase(request, blob, name);
}
/**
* 多版本所属模块更新处理
@ -326,6 +334,7 @@ public class FunctionalCaseService {
functionalCaseMapper.updateByPrimaryKeySelective(functionalCase);
//更新附属表信息
FunctionalCaseBlob functionalCaseBlob = new FunctionalCaseBlob();
functionalCaseBlob.setId(request.getId());
functionalCaseBlob.setSteps(StringUtils.defaultIfBlank(request.getSteps(), StringUtils.EMPTY).getBytes(StandardCharsets.UTF_8));
functionalCaseBlob.setTextDescription(StringUtils.defaultIfBlank(request.getTextDescription(), StringUtils.EMPTY).getBytes(StandardCharsets.UTF_8));
functionalCaseBlob.setExpectedResult(StringUtils.defaultIfBlank(request.getExpectedResult(), StringUtils.EMPTY).getBytes(StandardCharsets.UTF_8));

View File

@ -194,6 +194,30 @@ public class FunctionalCaseControllerTests extends BaseTest {
ResultHolder updateResultHolder = JSON.parseObject(updateReturnData, ResultHolder.class);
Assertions.assertNotNull(updateResultHolder);
FunctionalCaseEditRequest editRequest = new FunctionalCaseEditRequest();
editRequest.setProjectId("WX_PROJECT_ID");
editRequest.setModuleId("TEST_MODULE_ID");
editRequest.setId("WX_TEST_FUNCTIONAL_CASE_ID");
editRequest.setTemplateId("default_template_id");
editRequest.setName("测试更新评审状态");
editRequest.setCaseEditType("STEP");
paramMap = new LinkedMultiValueMap<>();
paramMap.add("request", JSON.toJSONString(editRequest));
paramMap.add("files", files);
this.requestMultipart(FUNCTIONAL_CASE_UPDATE_URL, paramMap);
editRequest.setSteps("123141243");
paramMap = new LinkedMultiValueMap<>();
paramMap.add("request", JSON.toJSONString(editRequest));
paramMap.add("files", files);
this.requestMultipart(FUNCTIONAL_CASE_UPDATE_URL, paramMap);
editRequest.setTextDescription("adfadsasfdf");
paramMap = new LinkedMultiValueMap<>();
paramMap.add("request", JSON.toJSONString(editRequest));
paramMap.add("files", files);
this.requestMultipart(FUNCTIONAL_CASE_UPDATE_URL, paramMap);
}

View File

@ -50,3 +50,18 @@ INSERT INTO functional_case_attachment(id, case_id, file_id, file_name, size, lo
INSERT INTO functional_case_module(id, project_id, name, parent_id, pos, create_time, update_time, create_user, update_user) VALUES ('TEST_MODULE_ID', '100001100001', '测试所属模块', 'NONE', 0, 1669174143999, 1669174143999, 'admin', 'admin');
INSERT INTO custom_field(id, name, scene, type, remark, internal, scope_type, create_time, update_time, create_user, ref_id, enable_option_key, scope_id) VALUES ('custom_field_id_1', 'functional_priority', 'FUNCTIONAL', 'SELECT', '', b'1', 'ORGANIZATION', 1698983187000, 1698983187000, 'admin', NULL, b'0', '100001');
INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time)
VALUES ('WX_TEST_FUNCTIONAL_CASE_ID', 6, 'TEST_MODULE_ID', 'WX_PROJECT_ID', '100001', '测试重新提审', 'UN_REVIEWED', NULL, 'STEP', 55000, 'v3.0.0', 'TEST_REF_ID_1', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL);
INSERT INTO functional_case_blob(id, steps, text_description, expected_result, prerequisite, description) VALUES ('WX_TEST_FUNCTIONAL_CASE_ID', 'STEP', '1111', '', '', 'TEST');
INSERT INTO project_application(project_id, type, type_value) VALUES ('WX_PROJECT_ID', 'CASE_RE_REVIEW', 'true');
INSERT INTO case_review_functional_case(id, review_id, case_id, status, create_time, update_time, create_user, pos) VALUES ('wx_case_review_id', 'wx_review_id', 'WX_TEST_FUNCTIONAL_CASE_ID', 'PASS', 1700816738199, 1700816738199, 'admin', 0);
INSERT INTO case_review(id, num, name, module_id, project_id, status, review_pass_rule, pos, start_time, end_time, case_count, pass_rate, tags, description, create_time, create_user, update_time, update_user)
VALUES ('wx_review_id',10006,'测试重新提审', 'test_module_one', 'TEST_MODULE_ID', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin');

View File

@ -411,7 +411,7 @@ public class ProjectTemplateService extends BaseTemplateService {
CustomFieldOptions optionDTO = new CustomFieldOptions();
optionDTO.setId(customField.getId());
if (customField.getInternal()) {
customField.setName(baseCustomFieldService.translateInternalField(customField.getName()));
optionDTO.setName(baseCustomFieldService.translateInternalField(customField.getName()));
} else {
optionDTO.setName(customField.getName());
}