fix(测试跟踪): 测试评审不显示用例

--bug=1014951 --user=陈建星 【测试跟踪】用例评审详情里不显示用例了 https://www.tapd.cn/55049933/s/1203680
This commit is contained in:
chenjianxing 2022-07-18 18:26:22 +08:00 committed by f2c-ci-robot[bot]
parent fa0d4e25b8
commit 682f6bf3c3
10 changed files with 86 additions and 70 deletions

View File

@ -31,14 +31,6 @@ public interface ExtTestPlanTestCaseMapper {
int updateTestCaseStates(@Param("ids") List<String> ids, @Param("reportStatus") String reportStatus);
/**
* 根据项目 ids 查询 TestPlanCaseDTO 列表
*
* @param ids project id list
* @return List<TestPlanCaseDTO>
*/
List<TestPlanCaseDTO> listTestCaseByProjectIds(@Param("ids") List<String> ids);
TestPlanCaseDTO get(String testPlanTestCaseId);
void deleteByTestCaseID(String id);

View File

@ -278,15 +278,6 @@
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<select id="listTestCaseByProjectIds" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
select distinct * from test_plan_test_case, test_case
where test_plan_test_case.case_id = test_case.id
and test_case.project_id in
<foreach collection="ids" item="id" index="index" open="(" close=")" separator=",">
#{id}
</foreach>
</select>
<select id="listByNode" resultType="io.metersphere.track.dto.TestPlanCaseDTO">
select test_plan_test_case.*, test_case.*
from test_plan_test_case

View File

@ -99,18 +99,14 @@
select test_case_review_test_case.id as id, test_case_review_test_case.reviewer,
test_case_review_test_case.update_time, test_case_review_test_case.review_id as reviewId,
test_case.id as caseId, test_case.name, test_case.priority, test_case.test_id as testId,
test_case.type, test_case.node_path, test_case.method, if(pa.type_value = 'false', cast(test_case.num as char),
test_case.custom_num) as customNum, test_case_review_test_case.status reviewStatus,
test_case.type, test_case.node_path, test_case.method, test_case.num,
test_case.custom_num, test_case_review_test_case.status reviewStatus,
test_case.remark as remark, test_case.maintainer, test_case.steps as steps, test_case.node_id as nodeId,
test_case_node.name as model,
project.name as projectName,
project_version.name as versionName,project_version.id as versionId
test_case.project_id,
test_case_node.name as model, test_case.version_id
from test_case_review_test_case
inner join test_case on test_case_review_test_case.case_id = test_case.id
left join test_case_node on test_case_node.id=test_case.node_id
inner join project on project.id = test_case.project_id
inner join project_application pa on project.id = pa.project_id and pa.type = 'CASE_CUSTOM_NUM'
left join project_version on project_version.project_id = project.id and test_case.version_id = project_version.id
<include refid="queryWhereCondition"/>
<if test="request.orders != null and request.orders.size() > 0">
order by

View File

@ -8,6 +8,7 @@ import io.metersphere.commons.exception.MSException;
import io.metersphere.controller.request.BaseQueryRequest;
import io.metersphere.controller.request.OrderRequest;
import io.metersphere.controller.request.ResetOrderRequest;
import io.metersphere.service.ProjectApplicationService;
import io.metersphere.service.ProjectService;
import io.metersphere.service.ProjectVersionService;
import io.metersphere.service.UserService;
@ -329,19 +330,7 @@ public class ServiceUtils {
return;
}
List<String> versionIds = list.stream()
.map(i -> {
Class<?> clazz = i.getClass();
try {
Method getVersionId = clazz.getMethod("getVersionId");
return getVersionId.invoke(i).toString();
} catch (Exception e) {
LogUtil.error(e);
return i.toString();
}
})
.distinct()
.collect(Collectors.toList());
List<String> versionIds = getFieldListByMethod(list, "getVersionId");
Map<String, String> versionNameMap = projectVersionService.getProjectVersionByIds(versionIds).
stream()
@ -359,4 +348,59 @@ public class ServiceUtils {
}
});
}
public static void buildProjectInfo(List<? extends Object> list) {
List<String> projectIds = getFieldListByMethod(list, "getProjectId");
Map<String, String> projectNameMap = getProjectNameMap(projectIds);
list.forEach(i -> {
Class<?> clazz = i.getClass();
try {
Method setProjectName = clazz.getMethod("setProjectName", String.class);
Method getProjectId = clazz.getMethod("getProjectId");
Object projectId = getProjectId.invoke(i);
setProjectName.invoke(i, projectNameMap.get(projectId));
} catch (Exception e) {
LogUtil.error(e);
}
});
}
public static void buildCustomNumInfo(List<? extends Object> list) {
List<String> projectIds = getFieldListByMethod(list, "getProjectId");
ProjectApplicationService projectApplicationService = CommonBeanFactory.getBean(ProjectApplicationService.class);
Map<String, String> customNumMap = projectApplicationService.getCustomNumMapByProjectIds(projectIds);
list.forEach(i -> {
Class<?> clazz = i.getClass();
try {
Method setIsCustomNum = clazz.getMethod("setCustomNum", String.class);
Method getNum = clazz.getMethod("getNum");
Method getProjectId = clazz.getMethod("getProjectId");
Object projectId = getProjectId.invoke(i);
String isCustomNum = customNumMap.get(projectId);
if (isCustomNum == null) {
setIsCustomNum.invoke(i, String.valueOf(getNum.invoke(i)));
}
} catch (Exception e) {
LogUtil.error(e);
}
});
}
private static List<String> getFieldListByMethod(List<?> list, String field) {
return list.stream()
.map(i -> {
Class<?> clazz = i.getClass();
try {
Method getField = clazz.getMethod(field);
return getField.invoke(i).toString();
} catch (Exception e) {
LogUtil.error(e);
return i.toString();
}
})
.distinct()
.collect(Collectors.toList());
}
}

View File

@ -30,10 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.*;
import java.util.stream.Collectors;
@Service
@Transactional(rollbackFor = Exception.class)
@ -363,4 +361,16 @@ public class ProjectApplicationService {
}
}
}
public Map<String, String> getCustomNumMapByProjectIds(List<String> projectIds) {
ProjectApplicationExample example = new ProjectApplicationExample();
example.createCriteria()
.andProjectIdIn(projectIds)
.andTypeEqualTo(ProjectApplicationType.CASE_CUSTOM_NUM.name())
.andTypeValueEqualTo("true");
List<ProjectApplication> projectApplications = projectApplicationMapper.selectByExample(example);
return projectApplications.stream()
.collect(Collectors.toMap(ProjectApplication::getProjectId, ProjectApplication::getType));
}
}

View File

@ -30,7 +30,6 @@ public class TestPlanTestCaseController {
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<TestPlanCaseDTO>> getTestPlanCases(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanCaseRequest request) {
testPlanTestCaseService.wrapQueryTestPlanCaseRequest(request);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);
return PageUtils.setPageInfo(page, testPlanTestCaseService.list(request));
}
@ -96,7 +95,6 @@ public class TestPlanTestCaseController {
@PostMapping("/list/all")
public List<TestPlanCaseDTO> getTestPlanCases(@RequestBody QueryTestPlanCaseRequest request) {
testPlanTestCaseService.wrapQueryTestPlanCaseRequest(request);
return testPlanTestCaseService.list(request);
}

View File

@ -35,8 +35,6 @@ public class QueryTestPlanCaseRequest extends BaseQueryRequest {
private String id;
private Boolean isCustomNum = false;
private String projectName;
private Map<String, Object> combine;

View File

@ -718,17 +718,9 @@ public class TestPlanService {
QueryTestPlanCaseRequest request = new QueryTestPlanCaseRequest();
request.setPlanId(planId);
request.setProjectId(testPlanMapper.selectByPrimaryKey(planId).getProjectId());
testPlanTestCaseService.wrapQueryTestPlanCaseRequest(request);
return testPlanTestCaseService.list(request);
}
private List<TestPlanCaseDTO> listTestCaseByProjectIds(List<String> projectIds) {
if (CollectionUtils.isEmpty(projectIds)) {
return new ArrayList<>();
}
return extTestPlanTestCaseMapper.listTestCaseByProjectIds(projectIds);
}
public TestCaseReportMetricDTO getMetric(String planId) {
QueryTestPlanRequest queryTestPlanRequest = new QueryTestPlanRequest();
queryTestPlanRequest.setId(planId);
@ -1751,7 +1743,6 @@ public class TestPlanService {
/**
* @param testPlanReport 测试计划报告
* @param testPlanReportContentWithBLOBs 测试计划报告内容
* @param isReportContenChanged 测试计划报告是否已经修改过
* @return
*/
public TestPlanReportBuildResultDTO buildPlanReport(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs testPlanReportContentWithBLOBs) {

View File

@ -92,27 +92,16 @@ public class TestPlanTestCaseService {
public List<TestPlanCaseDTO> list(QueryTestPlanCaseRequest request) {
List<OrderRequest> orders = ServiceUtils.getDefaultSortOrder(request.getOrders());
orders = ServiceUtils.replaceCustomNumOrder(request.getIsCustomNum(), orders);
request.setOrders(orders);
List<TestPlanCaseDTO> list = extTestPlanTestCaseMapper.list(request);
if (CollectionUtils.isNotEmpty(list)) {
Map<String, String> projectMap = ServiceUtils.getProjectNameMap(list.stream().map(TestPlanCaseDTO::getProjectId)
.distinct()
.collect(Collectors.toList()));
list.forEach(item -> {
// 设置项目名称
item.setProjectName(projectMap.get(item.getProjectId()));
if (!request.getIsCustomNum()) {
// 如果配置是不启用自定义字段则设置为 num
item.setCustomNum(item.getNum().toString());
}
});
// 设置版本信息
ServiceUtils.buildVersionInfo(list);
ServiceUtils.buildProjectInfo(list);
ServiceUtils.buildCustomNumInfo(list);
QueryMemberRequest queryMemberRequest = new QueryMemberRequest();
queryMemberRequest.setProjectId(request.getProjectId());
Map<String, String> userMap = userService.getProjectMemberList(queryMemberRequest)
@ -127,7 +116,6 @@ public class TestPlanTestCaseService {
public QueryTestPlanCaseRequest wrapQueryTestPlanCaseRequest(QueryTestPlanCaseRequest request) {
ProjectApplication projectApplication = projectApplicationService.getProjectApplication(request.getProjectId(), ProjectApplicationType.CASE_CUSTOM_NUM.name());
request.setIsCustomNum(StringUtils.equals(projectApplication.getTypeValue(), "false") ? false : true);
return request;
}

View File

@ -66,6 +66,14 @@ public class TestReviewTestCaseService {
public List<TestReviewCaseDTO> list(QueryCaseReviewRequest request) {
request.setOrders(ServiceUtils.getDefaultSortOrder(request.getOrders()));
List<TestReviewCaseDTO> list = extTestReviewCaseMapper.list(request);
if (CollectionUtils.isEmpty(list)) {
return list;
}
ServiceUtils.buildVersionInfo(list);
ServiceUtils.buildProjectInfo(list);
ServiceUtils.buildCustomNumInfo(list);
QueryMemberRequest queryMemberRequest = new QueryMemberRequest();
queryMemberRequest.setWorkspaceId(SessionUtils.getCurrentProjectId());
Map<String, String> userMap = userService.getMemberList(queryMemberRequest)