fix: 87974 高级检索-缺少字段
This commit is contained in:
+23
-25
@@ -41,6 +41,7 @@ import com.jero.modules.laws.home.common.LawsHomeSearchCommon;
|
|||||||
import com.jero.modules.laws.home.service.ILawsHomeSearchService;
|
import com.jero.modules.laws.home.service.ILawsHomeSearchService;
|
||||||
import com.jero.modules.laws.standard.entity.*;
|
import com.jero.modules.laws.standard.entity.*;
|
||||||
import com.jero.modules.laws.standard.service.*;
|
import com.jero.modules.laws.standard.service.*;
|
||||||
|
import com.jero.modules.laws.standard.service.impl.PartNameServiceImpl;
|
||||||
import com.jero.modules.oss.entity.OSSFile;
|
import com.jero.modules.oss.entity.OSSFile;
|
||||||
import com.jero.modules.oss.service.IOSSFileService;
|
import com.jero.modules.oss.service.IOSSFileService;
|
||||||
import com.jero.modules.personal.entity.LawsStandardCollection;
|
import com.jero.modules.personal.entity.LawsStandardCollection;
|
||||||
@@ -154,10 +155,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
private ILawsPartNameStandardService partNameStandardService;
|
private ILawsPartNameStandardService partNameStandardService;
|
||||||
@Resource
|
@Resource
|
||||||
private ISysBaseAPI sysBaseAPI;
|
private ISysBaseAPI sysBaseAPI;
|
||||||
@Resource
|
|
||||||
private ILawsEnterpriseStandardService esService;
|
|
||||||
@Resource
|
|
||||||
private ILawsDomesticStandardService fbService;
|
|
||||||
|
|
||||||
public static boolean ENCRYPT_ENABLE;
|
public static boolean ENCRYPT_ENABLE;
|
||||||
public static String DECRYPT_URL;
|
public static String DECRYPT_URL;
|
||||||
@@ -2128,8 +2125,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
// 拼接多表关联查询条件
|
// 拼接多表关联查询条件
|
||||||
Set<String> idSet = new HashSet<>();
|
Set<String> idSet = new HashSet<>();
|
||||||
boolean idSearch = false;
|
boolean idSearch = false;
|
||||||
// 管理员有所有外标的权限
|
|
||||||
adminRoleCodeList.addAll(enterpriseDetailRoleCodeList);
|
|
||||||
// 体系
|
// 体系
|
||||||
String standardSystem = (String) parameterMap.get(FieldCommon.STANDARD_SYSTEM);
|
String standardSystem = (String) parameterMap.get(FieldCommon.STANDARD_SYSTEM);
|
||||||
if (StrUtil.isNotBlank(standardSystem)) {
|
if (StrUtil.isNotBlank(standardSystem)) {
|
||||||
@@ -2176,8 +2171,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
// 零部件名称
|
// 零部件名称
|
||||||
String partName = (String) parameterMap.get(FieldCommon.PART_NAME);
|
String partName = (String) parameterMap.get(FieldCommon.PART_NAME);
|
||||||
if (StrUtil.isNotBlank(partName)) {
|
if (StrUtil.isNotBlank(partName)) {
|
||||||
String sql = getLawsPartNameStandardSql(tableName, partName);
|
idSearch = true;
|
||||||
selectCondition.append(sql);
|
idSet.addAll(getLawsPartNameStandard(partName));
|
||||||
parameterMap.remove(FieldCommon.PART_NAME);
|
parameterMap.remove(FieldCommon.PART_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2247,27 +2242,30 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private String getLawsPartNameStandardSql(String tableName, String partName) {
|
private List<String> getLawsPartNameStandard(String partName) {
|
||||||
LambdaQueryWrapper<PartName> partNameWrapper = new LambdaQueryWrapper<>();
|
PartName targetNode = partNameService.getById(partName);
|
||||||
partNameWrapper.like(PartName::getName, partName);
|
List<PartName> resultNodeList = new ArrayList<>();
|
||||||
List<PartName> list = partNameService.list(partNameWrapper);
|
// 获取整颗零部件树
|
||||||
List<String> codeList = new ArrayList<>();
|
List<PartName> allNodeList = partNameService.list();
|
||||||
list.forEach(p -> codeList.add(p.getCode()));
|
// 获取当前
|
||||||
|
Set<PartName> pathToRoot = PartNameServiceImpl.findPathToRoot(allNodeList, targetNode);
|
||||||
|
Set<PartName> allChildren = PartNameServiceImpl.findAllChildren(allNodeList, targetNode);
|
||||||
|
resultNodeList.addAll(pathToRoot);
|
||||||
|
resultNodeList.addAll(allChildren);
|
||||||
|
|
||||||
if (codeList.isEmpty()) {
|
if (resultNodeList.isEmpty()) {
|
||||||
return ""; // 或者根据实际情况返回一个适当的条件,例如 "1=0" 使得查询结果为空
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuilder sql = new StringBuilder(" AND (");
|
LambdaQueryWrapper<LawsPartNameStandard> pnsWrapper = new LambdaQueryWrapper<>();
|
||||||
for (int i = 0; i < codeList.size(); i++) {
|
pnsWrapper.in(LawsPartNameStandard::getPartNameId, resultNodeList.stream().map(PartName::getCode).collect(Collectors.toList()));
|
||||||
sql.append("FIND_IN_SET('").append(codeList.get(i)).append("', ").append(tableName).append(".part_name)");
|
List<LawsPartNameStandard> partNameStandardList = partNameStandardService.list(pnsWrapper);
|
||||||
if (i < codeList.size() - 1) {
|
|
||||||
sql.append(" OR ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sql.append(")");
|
|
||||||
|
|
||||||
return sql.toString();
|
if (partNameStandardList.isEmpty()) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return partNameStandardList.stream().map(LawsPartNameStandard::getStandardId).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.annotation.IdType;
|
|||||||
import com.baomidou.mybatisplus.annotation.TableField;
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableId;
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import com.jero.modules.laws.standard.service.TreeNode;
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -22,7 +23,7 @@ import java.util.List;
|
|||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@ApiModel(value = "laws_part_name对象", description = "零部件")
|
@ApiModel(value = "laws_part_name对象", description = "零部件")
|
||||||
public class PartName implements Serializable {
|
public class PartName implements Serializable, TreeNode {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主键ID
|
* 主键ID
|
||||||
@@ -112,4 +113,13 @@ public class PartName implements Serializable {
|
|||||||
*/
|
*/
|
||||||
@TableField(exist = false)
|
@TableField(exist = false)
|
||||||
private String levelPath;
|
private String levelPath;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTreeNodeId() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTreeNodeParentId() {
|
||||||
|
return parentCode;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,49 @@
|
|||||||
package com.jero.modules.laws.standard.entity;
|
package com.jero.modules.laws.standard.entity;
|
||||||
|
|
||||||
|
import com.jero.modules.laws.standard.service.TreeNode;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: Mzaxd
|
* @author: Mzaxd
|
||||||
* @Date: 2024/1/19 15:24
|
* @Date: 2024/1/19 15:24
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
public class TreePage<T> {
|
public class TreePage<T extends TreeNode> {
|
||||||
|
|
||||||
private List<T> records;
|
private List<T> records;
|
||||||
private long total;
|
private long total;
|
||||||
private long size;
|
private long size;
|
||||||
private long current;
|
private long current;
|
||||||
|
|
||||||
|
// 查找从节点到根节点的路径
|
||||||
|
public Set<T> findPathToRoot(List<T> allNodes, T node) {
|
||||||
|
Set<T> pathNodes = new HashSet<>();
|
||||||
|
T current = node;
|
||||||
|
while (current != null) {
|
||||||
|
pathNodes.add(current);
|
||||||
|
String parentCode = current.getTreeNodeParentId();
|
||||||
|
current = allNodes.stream()
|
||||||
|
.filter(n -> n.getTreeNodeId().equals(parentCode))
|
||||||
|
.findFirst().orElse(null);
|
||||||
|
}
|
||||||
|
return pathNodes;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 查找所有子节点,包括递归找到的孙节点等
|
||||||
|
public Set<T> findAllChildren(List<T> allNodes, T node) {
|
||||||
|
Set<T> childrenSet = new HashSet<>();
|
||||||
|
List<T> directChildren = allNodes.stream()
|
||||||
|
.filter(n -> n.getTreeNodeParentId().equals(node.getTreeNodeId()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
for (T child : directChildren) {
|
||||||
|
childrenSet.add(child);
|
||||||
|
childrenSet.addAll(findAllChildren(allNodes, child));
|
||||||
|
}
|
||||||
|
return childrenSet;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package com.jero.modules.laws.standard.service;
|
||||||
|
|
||||||
|
public interface TreeNode {
|
||||||
|
String getTreeNodeId(); // 返回节点的唯一标识
|
||||||
|
String getTreeNodeParentId(); // 返回父节点的唯一标识
|
||||||
|
}
|
||||||
+1
-1
@@ -113,7 +113,7 @@ public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
|
|||||||
return pathNodes;
|
return pathNodes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<PartName> findAllChildren(List<PartName> allNodes, PartName node) {
|
public static Set<PartName> findAllChildren(List<PartName> allNodes, PartName node) {
|
||||||
Set<PartName> childrenSet = new HashSet<>();
|
Set<PartName> childrenSet = new HashSet<>();
|
||||||
List<PartName> directChildren = allNodes.stream()
|
List<PartName> directChildren = allNodes.stream()
|
||||||
.filter(n -> n.getParentCode().equals(node.getCode()))
|
.filter(n -> n.getParentCode().equals(node.getCode()))
|
||||||
|
|||||||
Reference in New Issue
Block a user