fix(测试跟踪): 首页缺陷数不应该统计已关闭的缺陷

--bug=1015398 --user=李玉号 【测试跟踪】首页缺陷数应该不统计已关闭的缺陷
https://www.tapd.cn/55049933/s/1218089
This commit is contained in:
shiziyuan9527 2022-08-03 10:52:45 +08:00 committed by shiziyuan9527
parent f109a70479
commit 091b03c0ee
9 changed files with 113 additions and 36 deletions

View File

@ -13,4 +13,6 @@ public interface ExtCustomFieldTemplateMapper {
List<CustomFieldTemplateDao> list(@Param("request") CustomFieldTemplate request);
List<CustomFieldDao> lisSimple(@Param("request") CustomFieldTemplate request);
List<String> getSystemCustomField(@Param("templateId") String templateId, @Param("fieldName") String fieldName);
}

View File

@ -31,4 +31,11 @@
where cft.template_id = #{request.templateId}
</if>
</select>
<select id="getSystemCustomField" resultType="java.lang.String">
select cf.id
from custom_field_template cft
join custom_field cf on cft.field_id = cf.id
where cft.template_id = #{templateId}
and cf.name = #{fieldName}
</select>
</mapper>

View File

@ -94,7 +94,7 @@ public interface ExtTestCaseMapper {
List<TrackCountResult> countRelevanceMaintainer(@Param("projectId") String projectId);
int getTestPlanBug(@Param("planId") String planId);
List<String> getTestPlanBug(@Param("planId") String planId);
int getTestPlanCase(@Param("planId") String planId);

View File

@ -859,8 +859,8 @@
and tc.status != 'Trash' and tc.latest = 1 and tc.id in (select distinct test_case_test.test_case_id from test_case_test)
group by tc.maintainer
</select>
<select id="getTestPlanBug" resultType="int">
select count(distinct (tci.issues_id))
<select id="getTestPlanBug" resultType="java.lang.String">
select distinct tci.issues_id
from test_plan_test_case tptc
join test_case_issues tci on tptc.id = tci.resource_id
right join test_case
@ -868,8 +868,6 @@
join issues
on tci.issues_id = issues.id
where tptc.plan_id = #{planId}
and (issues.status != 'closed'
or issues.status is null)
and test_case.status != 'Trash';
</select>
<select id="getTestPlanCase" resultType="int">

View File

@ -0,0 +1,9 @@
package io.metersphere.commons.constants;
/**
* 系统的自定义字段名称
* 名称一般不会被修改
*/
public class SystemCustomField {
public static final String ISSUE_STATUS = "状态";
}

View File

@ -5,12 +5,12 @@ import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.CustomField;
import io.metersphere.base.domain.CustomFieldExample;
import io.metersphere.base.domain.CustomFieldTemplate;
import io.metersphere.base.domain.*;
import io.metersphere.base.domain.ext.CustomFieldResource;
import io.metersphere.base.mapper.CustomFieldIssuesMapper;
import io.metersphere.base.mapper.CustomFieldMapper;
import io.metersphere.base.mapper.CustomFieldTemplateMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.ExtCustomFieldMapper;
import io.metersphere.commons.constants.CustomFieldType;
import io.metersphere.commons.constants.TemplateConstants;
@ -56,7 +56,9 @@ public class CustomFieldService {
@Resource
CustomFieldTemplateService customFieldTemplateService;
@Resource
private CustomFieldTemplateMapper customFieldTemplateMapper;
private ProjectMapper projectMapper;
@Resource
private CustomFieldIssuesMapper customFieldIssuesMapper;
public String add(CustomField customField) {
checkExist(customField);
@ -278,4 +280,29 @@ public class CustomFieldService {
.stream()
.collect(Collectors.toMap(i -> i.getName() + i.getScene(), i -> i));
}
public Map<String, String> getIssueSystemCustomFieldByName(String fieldName, String projectId, List<String> resourceIds) {
if (CollectionUtils.isEmpty(resourceIds)) {
return null;
}
Project project = projectMapper.selectByPrimaryKey(projectId);
if (project == null) {
return null;
}
String templateId = project.getIssueTemplateId();
if (StringUtils.isBlank(templateId)) {
return null;
}
// 模版对于同一个系统字段应该只关联一次
List<String> fieldIds = customFieldTemplateService.getSystemCustomField(templateId, fieldName);
if (CollectionUtils.isEmpty(fieldIds)) {
return null;
}
// 该系统字段的自定义ID
String customFieldId = fieldIds.get(0);
CustomFieldIssuesExample example = new CustomFieldIssuesExample();
example.createCriteria().andFieldIdEqualTo(customFieldId).andResourceIdIn(resourceIds);
List<CustomFieldIssues> customFieldIssues = customFieldIssuesMapper.selectByExample(example);
return customFieldIssues.stream().collect(Collectors.toMap(CustomFieldIssues::getResourceId, CustomFieldIssues::getValue));
}
}

View File

@ -156,4 +156,8 @@ public class CustomFieldTemplateService {
customFieldTemplate.setFieldId(customField.getId());
return customFieldTemplateMapper.updateByExampleSelective(customFieldTemplate, example);
}
public List<String> getSystemCustomField(String templateId, String fieldName) {
return extCustomFieldTemplateMapper.getSystemCustomField(templateId, fieldName);
}
}

View File

@ -6,12 +6,10 @@ import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import io.metersphere.base.domain.*;
import io.metersphere.base.domain.ext.CustomFieldResource;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtIssuesMapper;
import io.metersphere.commons.constants.AttachmentType;
import io.metersphere.commons.constants.IssueRefType;
import io.metersphere.commons.constants.IssuesManagePlatform;
import io.metersphere.commons.constants.IssuesStatus;
import io.metersphere.commons.constants.*;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.*;
import io.metersphere.controller.request.IntegrationRequest;
@ -36,6 +34,7 @@ import io.metersphere.track.request.testcase.IssuesRequest;
import io.metersphere.track.request.testcase.IssuesUpdateRequest;
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -91,9 +90,11 @@ public class IssuesService {
@Resource
IssueFileMapper issueFileMapper;
@Resource
private FileAttachmentMetadataMapper fileAttachmentMetadataMapper;
@Resource
private AttachmentService attachmentService;
@Resource
private CustomFieldService customFieldService;
@Resource
private ProjectMapper projectMapper;
private static final String SYNC_THIRD_PARTY_ISSUES_KEY = "ISSUE:SYNC";
@ -197,7 +198,24 @@ public class IssuesService {
issueRequest.setCaseResourceId(caseResourceId);
ServiceUtils.getDefaultOrder(issueRequest.getOrders());
issueRequest.setRefType(refType);
return disconnectIssue(extIssuesMapper.getIssuesByCaseId(issueRequest));
List<IssuesDao> issues = extIssuesMapper.getIssuesByCaseId(issueRequest);
this.handleCustomFieldStatus(issues);
return disconnectIssue(issues);
}
private void handleCustomFieldStatus(List<IssuesDao> issues) {
if (CollectionUtils.isEmpty(issues)) {
return;
}
List<String> issueIds = issues.stream().map(Issues::getId).collect(Collectors.toList());
String projectId = issues.get(0).getProjectId();
Map<String, String> statusMap = customFieldService.getIssueSystemCustomFieldByName(SystemCustomField.ISSUE_STATUS, projectId, issueIds);
if (MapUtils.isEmpty(statusMap)) {
return;
}
for (IssuesDao issue : issues) {
issue.setStatus(statusMap.getOrDefault(issue.getId(), "").replaceAll("\"", ""));
}
}
public IssuesWithBLOBs getIssue(String id) {
@ -735,23 +753,24 @@ public class IssuesService {
if (StringUtils.isBlank(issuesId) || StringUtils.isBlank(status)) {
return;
}
IssuesWithBLOBs issues = issuesMapper.selectByPrimaryKey(issuesId);
String customFields = issues.getCustomFields();
if (StringUtils.isBlank(customFields)) {
IssuesWithBLOBs issue = issuesMapper.selectByPrimaryKey(issuesId);
Project project = projectMapper.selectByPrimaryKey(issue.getProjectId());
if (project == null) {
return;
}
List<TestCaseBatchRequest.CustomFiledRequest> fields = JSONObject.parseArray(customFields, TestCaseBatchRequest.CustomFiledRequest.class);
for (TestCaseBatchRequest.CustomFiledRequest field : fields) {
if (StringUtils.equals("状态", field.getName())) {
field.setValue(status);
break;
String templateId = project.getIssueTemplateId();
if (StringUtils.isNotBlank(templateId)) {
// 模版对于同一个系统字段应该只关联一次
List<String> fieldIds = customFieldTemplateService.getSystemCustomField(templateId, SystemCustomField.ISSUE_STATUS);
if (CollectionUtils.isNotEmpty(fieldIds)) {
String fieldId = fieldIds.get(0);
CustomFieldResource resource = new CustomFieldResource();
resource.setFieldId(fieldId);
resource.setResourceId(issue.getId());
resource.setValue(JSON.toJSONString(status));
customFieldIssuesService.editFields(issue.getId(), Collections.singletonList(resource));
}
}
issues.setStatus(status);
issues.setCustomFields(JSONObject.toJSONString(fields));
issuesMapper.updateByPrimaryKeySelective(issues);
}
public List<IssuesDao> getCountByStatus(IssuesRequest request) {

View File

@ -5,16 +5,19 @@ import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestPlanTestCaseMapper;
import io.metersphere.commons.constants.SystemCustomField;
import io.metersphere.commons.constants.TestPlanTestCaseStatus;
import io.metersphere.commons.utils.DateUtils;
import io.metersphere.commons.utils.MathUtils;
import io.metersphere.performance.base.ChartsData;
import io.metersphere.service.CustomFieldService;
import io.metersphere.service.ProjectService;
import io.metersphere.track.dto.CountMapDTO;
import io.metersphere.track.dto.TestPlanDTOWithMetric;
import io.metersphere.track.response.BugStatustics;
import io.metersphere.track.response.TestPlanBugCount;
import io.metersphere.track.response.TrackCountResult;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -43,7 +46,7 @@ public class TrackService {
@Resource
private TestPlanLoadCaseService testPlanLoadCaseService;
@Resource
private ProjectService projectService;
private CustomFieldService customFieldService;
public List<TrackCountResult> countPriority(String projectId) {
return extTestCaseMapper.countPriority(projectId);
@ -120,12 +123,14 @@ public class TrackService {
BugStatustics bugStatustics = new BugStatustics();
int index = 1;
int totalCaseSize = 0;
int totalBugSize = 0;
for (TestPlan plan : plans) {
int planBugSize = getPlanBugSize(plan.getId());
int planBugSize = getPlanBugSize(plan.getId(), projectId);
// bug为0不记录
if (planBugSize == 0) {
continue;
}
totalBugSize += planBugSize;
TestPlanBugCount testPlanBug = new TestPlanBugCount();
testPlanBug.setIndex(index++);
@ -144,10 +149,8 @@ public class TrackService {
totalCaseSize += planCaseSize;
}
int totalBugSize = projectService.getProjectBugSize(projectId);
bugStatustics.setList(list);
float rage =totalCaseSize == 0 ? 0 : (float) totalBugSize * 100 / totalCaseSize;
float rage = totalCaseSize == 0 ? 0 : (float) totalBugSize * 100 / totalCaseSize;
DecimalFormat df = new DecimalFormat("0.0");
bugStatustics.setRage(df.format(rage) + "%");
bugStatustics.setBugTotalSize(totalBugSize);
@ -159,8 +162,16 @@ public class TrackService {
}
private int getPlanBugSize(String planId) {
return extTestCaseMapper.getTestPlanBug(planId);
private int getPlanBugSize(String planId, String projectId) {
List<String> issueIds = extTestCaseMapper.getTestPlanBug(planId);
Map<String, String> statusMap = customFieldService.getIssueSystemCustomFieldByName(SystemCustomField.ISSUE_STATUS, projectId, issueIds);
// 缺陷是否有状态
if (MapUtils.isEmpty(statusMap)) {
return issueIds.size();
}
return (int) issueIds.stream()
.filter(id -> !StringUtils.equals(statusMap.getOrDefault(id, "").replaceAll("\"", ""), "closed"))
.count();
}
private double getPlanPassRage(String planId) {