修改条款零部件多选联查父子集数据
This commit is contained in:
+80
-5
@@ -1,18 +1,21 @@
|
||||
package com.jero.modules.laws.documenttool.handler.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.jero.modules.laws.common.constant.FieldCommon;
|
||||
import com.jero.modules.laws.documenttool.common.DocumentSplitCommon;
|
||||
import com.jero.modules.laws.documenttool.factory.ConditionMapFactory;
|
||||
import com.jero.modules.laws.documenttool.handler.AbstractConditionBase;
|
||||
import com.jero.modules.laws.standard.entity.PartName;
|
||||
import com.jero.modules.laws.standard.service.ILawsPartNameService;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.Resource;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -34,10 +37,7 @@ public class InConditionImpl extends AbstractConditionBase {
|
||||
List<String> list = Arrays.asList(value.split(","));
|
||||
// 涉及系统/部件 特殊处理
|
||||
if (FieldCommon.PART_NAME.equals(fieldName)){
|
||||
List<PartName> partNameList = lawsPartNameService.listByIds(list);
|
||||
if (!Objects.isNull(partNameList)){
|
||||
list = partNameList.stream().map(PartName::getCode).collect(Collectors.toList());
|
||||
}
|
||||
list = getStrings(list);
|
||||
}
|
||||
for (String s : list) {
|
||||
in.append(DocumentSplitCommon.INSTR_BEGIN).append(fieldName).append(",").append("'").append(s).append("'").append(")");
|
||||
@@ -55,6 +55,81 @@ public class InConditionImpl extends AbstractConditionBase {
|
||||
return in.toString();
|
||||
}
|
||||
|
||||
private List<String> getStrings(List<String> list) {
|
||||
LambdaQueryWrapper<PartName> queryPartName = new LambdaQueryWrapper<>();
|
||||
queryPartName.select(PartName::getId,PartName::getCode,PartName::getParentCode);
|
||||
List<PartName> listPartName = lawsPartNameService.list(queryPartName);
|
||||
if(CollectionUtils.isEmpty(listPartName)) {
|
||||
return list;
|
||||
}
|
||||
List<String> finalList = list;
|
||||
List<PartName> partNameList = listPartName.stream().filter(o-> finalList.contains(o.getId())).collect(Collectors.toList());
|
||||
if(CollectionUtils.isEmpty(partNameList)){
|
||||
return list;
|
||||
}
|
||||
Set<PartName> setAll = new HashSet<>(new HashSet<>(partNameList));
|
||||
Set<String> setCode = partNameList.stream().map(PartName::getCode).collect(Collectors.toSet());
|
||||
Set<String> setParentCode = partNameList.stream().map(PartName::getParentCode).collect(Collectors.toSet());
|
||||
if(!CollectionUtils.isEmpty(listPartName)){
|
||||
if(!CollectionUtils.isEmpty(setParentCode)){
|
||||
// 查询父级
|
||||
Set<PartName> setP = getParent(setParentCode, listPartName);
|
||||
if(!CollectionUtils.isEmpty(setP)){
|
||||
setAll.addAll(setP);
|
||||
}
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(setCode)){
|
||||
// 查询子级
|
||||
Set<PartName> setP = getSub(setCode, listPartName);
|
||||
if(!CollectionUtils.isEmpty(setP)){
|
||||
setAll.addAll(setP);
|
||||
}
|
||||
}
|
||||
}
|
||||
if(!CollectionUtils.isEmpty(setAll)){
|
||||
list = setAll.stream().map(PartName::getCode).collect(Collectors.toList());
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private Set<PartName> getParent(Set<String> setCode, List<PartName> listPartName) {
|
||||
Set<PartName> set = new HashSet<>();
|
||||
if(!CollectionUtils.isEmpty(setCode)){
|
||||
Set<PartName> listPartNameParent = listPartName.stream().filter(o->
|
||||
setCode.contains(o.getCode())).collect(Collectors.toSet());
|
||||
if(!CollectionUtils.isEmpty(listPartNameParent)){
|
||||
set.addAll(listPartNameParent);
|
||||
Set<String> listParent = listPartNameParent.stream().map(PartName::getParentCode).collect(Collectors.toSet());
|
||||
if(!CollectionUtils.isEmpty(listParent)){
|
||||
Set<PartName> set2 = getParent(listParent, listPartName);
|
||||
if(!CollectionUtils.isEmpty(set2)){
|
||||
set.addAll(set2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
private Set<PartName> getSub(Set<String> setCode, List<PartName> listPartName) {
|
||||
Set<PartName> set = new HashSet<>();
|
||||
if(!CollectionUtils.isEmpty(setCode)){
|
||||
Set<PartName> listPartNameSub = listPartName.stream().filter(o->
|
||||
setCode.contains(o.getParentCode())).collect(Collectors.toSet());
|
||||
if(!CollectionUtils.isEmpty(listPartNameSub)){
|
||||
set.addAll(listPartNameSub);
|
||||
Set<String> listSub = listPartNameSub.stream().map(PartName::getCode).collect(Collectors.toSet());
|
||||
if(!CollectionUtils.isEmpty(listSub)){
|
||||
Set<PartName> set2 = getParent(listSub, listPartName);
|
||||
if(!CollectionUtils.isEmpty(set2)){
|
||||
set.addAll(set2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化注册到工厂
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user