fix(测试跟踪): 首页遗留缺陷统计总数和占比有统计错误

--bug=1017609 --user=李玉号 【测试跟踪】首页遗留缺陷统计总数和占比有统计错误
https://www.tapd.cn/55049933/s/1292665
This commit is contained in:
shiziyuan9527 2022-11-08 17:53:03 +08:00 committed by lyh
parent 0c79482e5c
commit 23afe75805
1 changed files with 37 additions and 3 deletions

View File

@ -1,8 +1,9 @@
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.base.domain.CustomField; import io.metersphere.base.domain.*;
import io.metersphere.base.domain.CustomFieldExample;
import io.metersphere.base.mapper.CustomFieldMapper; import io.metersphere.base.mapper.CustomFieldMapper;
import io.metersphere.base.mapper.CustomFieldTemplateMapper;
import io.metersphere.base.mapper.ProjectMapper;
import io.metersphere.base.mapper.ext.BaseCustomFieldMapper; import io.metersphere.base.mapper.ext.BaseCustomFieldMapper;
import io.metersphere.commons.constants.CustomFieldType; import io.metersphere.commons.constants.CustomFieldType;
import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.JSON;
@ -29,6 +30,11 @@ public class BaseCustomFieldService {
@Resource @Resource
CustomFieldMapper customFieldMapper; CustomFieldMapper customFieldMapper;
@Resource
private ProjectMapper projectMapper;
@Resource
private CustomFieldTemplateMapper customFieldTemplateMapper;
public CustomField get(String id) { public CustomField get(String id) {
return customFieldMapper.selectByPrimaryKey(id); return customFieldMapper.selectByPrimaryKey(id);
} }
@ -102,13 +108,41 @@ public class BaseCustomFieldService {
} }
public CustomField getCustomFieldByName(String projectId, String fieldName) { public CustomField getCustomFieldByName(String projectId, String fieldName) {
Project project = projectMapper.selectByPrimaryKey(projectId);
if (project == null) {
return null;
}
String issueTemplateId = project.getIssueTemplateId();
if (StringUtils.isBlank(issueTemplateId)) {
return null;
}
CustomFieldTemplateExample customFieldTemplateExample = new CustomFieldTemplateExample();
customFieldTemplateExample.createCriteria().andTemplateIdEqualTo(issueTemplateId);
List<CustomFieldTemplate> customFieldTemplates = customFieldTemplateMapper.selectByExample(customFieldTemplateExample);
if (CollectionUtils.isEmpty(customFieldTemplates)) {
return null;
}
List<String> templateFieldIds = customFieldTemplates
.stream()
.map(CustomFieldTemplate::getFieldId)
.collect(Collectors.toList());
CustomFieldExample example = new CustomFieldExample(); CustomFieldExample example = new CustomFieldExample();
example.createCriteria() example.createCriteria()
.andProjectIdEqualTo(projectId) .andProjectIdEqualTo(projectId)
.andNameEqualTo(fieldName); .andNameEqualTo(fieldName);
List<CustomField> customFields = customFieldMapper.selectByExample(example); List<CustomField> customFields = customFieldMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(customFields)) { if (CollectionUtils.isNotEmpty(customFields)) {
return customFields.get(0); for (CustomField customField : customFields) {
if (templateFieldIds.contains(customField.getId())) {
return customField;
}
}
return null;
} else { } else {
example.clear(); example.clear();
example.createCriteria() example.createCriteria()