refactor(缺陷管理): 去重缺陷列表表头字段
This commit is contained in:
parent
2ee6833b96
commit
2c86f9d06a
|
@ -75,6 +75,9 @@ import java.io.IOException;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@ -1388,10 +1391,12 @@ public class BugService {
|
||||||
* @return 自定义字段集合
|
* @return 自定义字段集合
|
||||||
*/
|
*/
|
||||||
public List<TemplateCustomFieldDTO> getHeaderCustomFields(String projectId) {
|
public List<TemplateCustomFieldDTO> getHeaderCustomFields(String projectId) {
|
||||||
List<TemplateCustomFieldDTO> headerCustomFields = new ArrayList<>();
|
List<TemplateCustomFieldDTO> allCustomFields = new ArrayList<>();
|
||||||
// 本地模板
|
// 本地模板
|
||||||
List<Template> templates = projectTemplateService.getTemplates(projectId, TemplateScene.BUG.name());
|
List<Template> templates = projectTemplateService.getTemplates(projectId, TemplateScene.BUG.name());
|
||||||
templates.forEach(template -> headerCustomFields.addAll(baseTemplateService.getTemplateDTO(template).getCustomFields()));
|
templates.forEach(template -> allCustomFields.addAll(baseTemplateService.getTemplateDTO(template).getCustomFields()));
|
||||||
|
// 本地模板自定义字段去重
|
||||||
|
List<TemplateCustomFieldDTO> headerCustomFields = allCustomFields.stream().filter(distinctByKey(TemplateCustomFieldDTO::getFieldId)).collect(Collectors.toList());
|
||||||
// 填充自定义字段成员类型的选项值
|
// 填充自定义字段成员类型的选项值
|
||||||
List<SelectOption> memberOption = bugCommonService.getHeaderHandlerOption(projectId);
|
List<SelectOption> memberOption = bugCommonService.getHeaderHandlerOption(projectId);
|
||||||
List<CustomFieldOption> memberCustomOption = memberOption.stream().map(option -> {
|
List<CustomFieldOption> memberCustomOption = memberOption.stream().map(option -> {
|
||||||
|
@ -1401,7 +1406,7 @@ public class BugService {
|
||||||
return customFieldOption;
|
return customFieldOption;
|
||||||
}).toList();
|
}).toList();
|
||||||
headerCustomFields.forEach(field -> {
|
headerCustomFields.forEach(field -> {
|
||||||
if (StringUtils.equalsAny(field.getType(), CustomFieldType.MEMBER.getType(), CustomFieldType.MULTIPLE_MEMBER.getType())) {
|
if (StringUtils.equalsAny(field.getType(), CustomFieldType.MEMBER.name(), CustomFieldType.MULTIPLE_MEMBER.name())) {
|
||||||
field.setOptions(memberCustomOption);
|
field.setOptions(memberCustomOption);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1410,8 +1415,7 @@ public class BugService {
|
||||||
if (pluginDefaultTemplate != null) {
|
if (pluginDefaultTemplate != null) {
|
||||||
headerCustomFields.addAll(pluginDefaultTemplate.getCustomFields());
|
headerCustomFields.addAll(pluginDefaultTemplate.getCustomFields());
|
||||||
}
|
}
|
||||||
// 重复的自定义字段去重
|
return headerCustomFields;
|
||||||
return headerCustomFields.stream().distinct().toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1467,4 +1471,14 @@ public class BugService {
|
||||||
Long pos = extBugMapper.getMaxPos(projectId);
|
Long pos = extBugMapper.getMaxPos(projectId);
|
||||||
return (pos == null ? 0 : pos) + INTERVAL_POS;
|
return (pos == null ? 0 : pos) + INTERVAL_POS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* distinct by key
|
||||||
|
* @param function distinct function
|
||||||
|
* @return predicate
|
||||||
|
*/
|
||||||
|
private static <T> Predicate<T> distinctByKey(Function<? super T, ?> function) {
|
||||||
|
Set<Object> keySet = ConcurrentHashMap.newKeySet();
|
||||||
|
return t -> keySet.add(function.apply(t));
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue