refactor(用例管理): 优化用例详情查询代码

This commit is contained in:
guoyuqi 2024-05-23 18:30:11 +08:00 committed by 刘瑞斌
parent 6476aa3a16
commit 6619efe9a3
4 changed files with 17 additions and 11 deletions

View File

@ -173,6 +173,9 @@ ALTER TABLE test_plan DROP INDEX uq_name_project;
CREATE INDEX idx_report_id ON api_scenario_report_step(report_id);
CREATE INDEX idx_source_id ON operation_history(`source_id`);
-- set innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -90,7 +90,7 @@ public class FunctionalCaseController {
@CheckOwner(resourceId = "#id", resourceType = "functional_case")
public FunctionalCaseDetailDTO getFunctionalCaseDetail(@PathVariable String id) {
String userId = SessionUtils.getUserId();
return functionalCaseService.getFunctionalCaseDetail(id, userId);
return functionalCaseService.getFunctionalCaseDetail(id, userId, true);
}

View File

@ -339,7 +339,7 @@ public class FunctionalCaseService {
* @param functionalCaseId functionalCaseId
* @return FunctionalCaseDetailDTO
*/
public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId, String userId) {
public FunctionalCaseDetailDTO getFunctionalCaseDetail(String functionalCaseId, String userId, boolean checkDetailCount) {
FunctionalCase functionalCase = checkFunctionalCase(functionalCaseId);
FunctionalCaseDetailDTO functionalCaseDetailDTO = new FunctionalCaseDetailDTO();
BeanUtils.copyBean(functionalCaseDetailDTO, functionalCase);
@ -369,9 +369,10 @@ public class FunctionalCaseService {
//模块名称
handDTO(functionalCaseDetailDTO);
//处理已关联需求数量/缺陷数量/用例数量
handleCount(functionalCaseDetailDTO);
if (checkDetailCount) {
//处理已关联需求数量/缺陷数量/用例数量
handleCount(functionalCaseDetailDTO);
}
return functionalCaseDetailDTO;
@ -442,8 +443,7 @@ public class FunctionalCaseService {
//获取变更历史数量数量
OperationHistoryExample operationHistoryExample = new OperationHistoryExample();
List<String> types = List.of(OperationLogType.ADD.name(), OperationLogType.IMPORT.name(), OperationLogType.UPDATE.name());
List<String> modules = List.of(OperationLogModule.FUNCTIONAL_CASE);
operationHistoryExample.createCriteria().andSourceIdEqualTo(functionalCaseDetailDTO.getId()).andTypeIn(types).andModuleIn(modules);
operationHistoryExample.createCriteria().andSourceIdEqualTo(functionalCaseDetailDTO.getId()).andModuleEqualTo(OperationLogModule.FUNCTIONAL_CASE).andTypeIn(types);
functionalCaseDetailDTO.setHistoryCount((int) operationHistoryMapper.countByExample(operationHistoryExample));
}
@ -482,12 +482,17 @@ public class FunctionalCaseService {
TemplateDTO templateDTO = projectTemplateService.getTemplateDTOById(functionalCase.getTemplateId(), functionalCase.getProjectId(), TemplateScene.FUNCTIONAL.name());
if (CollectionUtils.isNotEmpty(templateDTO.getCustomFields())) {
List<TemplateCustomFieldDTO> customFields = templateDTO.getCustomFields();
List<String> fieldIds = customFields.stream().map(TemplateCustomFieldDTO::getFieldId).distinct().toList();
FunctionalCaseCustomFieldExample example = new FunctionalCaseCustomFieldExample();
example.createCriteria().andCaseIdEqualTo(functionalCase.getId()).andFieldIdIn(fieldIds);
List<FunctionalCaseCustomField> functionalCaseCustomFields = functionalCaseCustomFieldMapper.selectByExample(example);
Map<String, FunctionalCaseCustomField> customFieldMap = functionalCaseCustomFields.stream().collect(Collectors.toMap(FunctionalCaseCustomField::getFieldId, t -> t));
List<CustomFieldOption> memberCustomOption = getMemberOptions(functionalCase.getProjectId());
customFields.forEach(item -> {
if (StringUtils.equalsAnyIgnoreCase(item.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
item.setOptions(memberCustomOption);
}
FunctionalCaseCustomField caseCustomField = functionalCaseCustomFieldService.getCustomField(item.getFieldId(), functionalCase.getId());
FunctionalCaseCustomField caseCustomField = customFieldMap.get(item.getFieldId());
Optional.ofNullable(caseCustomField).ifPresentOrElse(customField -> {
item.setDefaultValue(customField.getValue());
if (Translator.get("custom_field.functional_priority").equals(item.getFieldName())) {

View File

@ -91,8 +91,6 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
@Resource
private BugRelationCaseMapper bugRelationCaseMapper;
@Resource
private TestPlanModuleService testPlanModuleService;
@Resource
private ExtTestPlanModuleMapper extTestPlanModuleMapper;
@Resource
private FunctionalCaseModuleService functionalCaseModuleService;
@ -553,7 +551,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
public TestPlanCaseDetailResponse getFunctionalCaseDetail(String id, String userId) {
TestPlanFunctionalCase planFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(id);
String caseId = planFunctionalCase.getFunctionalCaseId();
FunctionalCaseDetailDTO functionalCaseDetail = functionalCaseService.getFunctionalCaseDetail(caseId, userId);
FunctionalCaseDetailDTO functionalCaseDetail = functionalCaseService.getFunctionalCaseDetail(caseId, userId, false);
String caseDetailSteps = functionalCaseDetail.getSteps();
List<TestPlanCaseExecuteHistory> testPlanCaseExecuteHistories = extTestPlanCaseExecuteHistoryMapper.selectSteps(id, caseId);
Integer runListCount = 0;