fix: 87974 高级检索-缺少字段

This commit is contained in:
2024-08-02 15:30:37 +08:00
parent 56cad570a5
commit 2f6f8945a0
5 changed files with 72 additions and 29 deletions
@@ -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.standard.entity.*;
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.service.IOSSFileService;
import com.jero.modules.personal.entity.LawsStandardCollection;
@@ -154,10 +155,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
private ILawsPartNameStandardService partNameStandardService;
@Resource
private ISysBaseAPI sysBaseAPI;
@Resource
private ILawsEnterpriseStandardService esService;
@Resource
private ILawsDomesticStandardService fbService;
public static boolean ENCRYPT_ENABLE;
public static String DECRYPT_URL;
@@ -2128,8 +2125,6 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 拼接多表关联查询条件
Set<String> idSet = new HashSet<>();
boolean idSearch = false;
// 管理员有所有外标的权限
adminRoleCodeList.addAll(enterpriseDetailRoleCodeList);
// 体系
String standardSystem = (String) parameterMap.get(FieldCommon.STANDARD_SYSTEM);
if (StrUtil.isNotBlank(standardSystem)) {
@@ -2176,8 +2171,8 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
// 零部件名称
String partName = (String) parameterMap.get(FieldCommon.PART_NAME);
if (StrUtil.isNotBlank(partName)) {
String sql = getLawsPartNameStandardSql(tableName, partName);
selectCondition.append(sql);
idSearch = true;
idSet.addAll(getLawsPartNameStandard(partName));
parameterMap.remove(FieldCommon.PART_NAME);
}
@@ -2247,27 +2242,30 @@ public class LawsCommonServiceImpl implements ILawsCommonService {
}
@NotNull
private String getLawsPartNameStandardSql(String tableName, String partName) {
LambdaQueryWrapper<PartName> partNameWrapper = new LambdaQueryWrapper<>();
partNameWrapper.like(PartName::getName, partName);
List<PartName> list = partNameService.list(partNameWrapper);
List<String> codeList = new ArrayList<>();
list.forEach(p -> codeList.add(p.getCode()));
private List<String> getLawsPartNameStandard(String partName) {
PartName targetNode = partNameService.getById(partName);
List<PartName> resultNodeList = new ArrayList<>();
// 获取整颗零部件树
List<PartName> allNodeList = partNameService.list();
// 获取当前
Set<PartName> pathToRoot = PartNameServiceImpl.findPathToRoot(allNodeList, targetNode);
Set<PartName> allChildren = PartNameServiceImpl.findAllChildren(allNodeList, targetNode);
resultNodeList.addAll(pathToRoot);
resultNodeList.addAll(allChildren);
if (codeList.isEmpty()) {
return ""; // 或者根据实际情况返回一个适当的条件,例如 "1=0" 使得查询结果为空
if (resultNodeList.isEmpty()) {
return new ArrayList<>();
}
StringBuilder sql = new StringBuilder(" AND (");
for (int i = 0; i < codeList.size(); i++) {
sql.append("FIND_IN_SET('").append(codeList.get(i)).append("', ").append(tableName).append(".part_name)");
if (i < codeList.size() - 1) {
sql.append(" OR ");
}
}
sql.append(")");
LambdaQueryWrapper<LawsPartNameStandard> pnsWrapper = new LambdaQueryWrapper<>();
pnsWrapper.in(LawsPartNameStandard::getPartNameId, resultNodeList.stream().map(PartName::getCode).collect(Collectors.toList()));
List<LawsPartNameStandard> partNameStandardList = partNameStandardService.list(pnsWrapper);
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.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jero.modules.laws.standard.service.TreeNode;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -22,7 +23,7 @@ import java.util.List;
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
@ApiModel(value = "laws_part_name对象", description = "零部件")
public class PartName implements Serializable {
public class PartName implements Serializable, TreeNode {
/**
* 主键ID
@@ -112,4 +113,13 @@ public class PartName implements Serializable {
*/
@TableField(exist = false)
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;
import com.jero.modules.laws.standard.service.TreeNode;
import lombok.Data;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author: Mzaxd
* @Date: 2024/1/19 15:24
*/
@Data
public class TreePage<T> {
public class TreePage<T extends TreeNode> {
private List<T> records;
private long total;
private long size;
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(); // 返回父节点的唯一标识
}
@@ -113,7 +113,7 @@ public class PartNameServiceImpl extends ServiceImpl<PartNameMapper, PartName>
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<>();
List<PartName> directChildren = allNodes.stream()
.filter(n -> n.getParentCode().equals(node.getCode()))