feat: 体系搜索树接口

This commit is contained in:
2023-11-14 17:10:47 +08:00
parent 9655f55303
commit 5215be2d97
8 changed files with 143 additions and 6 deletions
@@ -107,4 +107,38 @@ public class SarMenuStandard extends BaseEntity {
@TableField(exist = false)
private String treeType;
@TableField(exist = false)
private Integer gbStandCount;
@TableField(exist = false)
private Integer fbStandCount;
@TableField(exist = false)
private Integer esStandCount;
// 添加用于计算和设置关联关系数量的方法
// 添加用于计算和设置关联关系数量的方法
public void calculateAndSetCounts(List<StandMenuRelation> gbStandMenu, List<StandMenuRelation> fbStandMenu, List<StandMenuRelation> esStandMenu) {
this.gbStandCount = countMatches(gbStandMenu, this.id);
this.fbStandCount = countMatches(fbStandMenu, this.id);
this.esStandCount = countMatches(esStandMenu, this.id);
for (SarMenuStandard child : children) {
child.calculateAndSetCounts(gbStandMenu, fbStandMenu, esStandMenu);
this.gbStandCount += child.gbStandCount;
this.fbStandCount += child.fbStandCount;
this.esStandCount += child.esStandCount;
}
}
private int countMatches(List<StandMenuRelation> standMenuList, String menuId) {
int count = 0;
// 计算与menuId匹配的项的数量
for (StandMenuRelation standMenu : standMenuList) {
if (standMenu.getMenuId().equals(menuId)) {
count++;
}
}
return count;
}
}
@@ -0,0 +1,16 @@
package com.adc.da.sys.sarMenuStandard.entity;
import lombok.Data;
/**
* @author: Mzaxd
* @Date: 2023/11/14 16:31
*/
@Data
public class StandMenuRelation {
private String standId;
private String menuId;
}
@@ -0,0 +1,36 @@
package com.adc.da.sys.util;
import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Mzaxd
* @since 2022-11-22 15:36
*/
public class BeanCopyUtils {
private BeanCopyUtils() {
}
public static <V> V copyBean(Object source, Class<V> clazz){
V result = null;
//创建目标对象
try {
result = clazz.newInstance();
//实现属性copy
BeanUtils.copyProperties(source, result);
} catch (Exception e) {
e.printStackTrace();
}
//返回结果
return result;
}
public static <O,V> List<V> copyBeanList(List<O> list, Class<V> clazz) {
return list.stream()
.map(o -> copyBean(o, clazz))
.collect(Collectors.toList());
}
}