Merge branch 'dev_20231101_TXSS' into 'dev_20230829_change'
Dev 20231101 txss See merge request laws-foton-slrs/foton-slrs-system-rest!136
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package com.adc.da.sys.entity;
|
||||
|
||||
import com.adc.da.base.entity.BaseEntity;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
|
||||
/**
|
||||
@@ -9,6 +10,7 @@ import com.adc.da.base.entity.BaseEntity;
|
||||
* <b>日期:</b> 2018-09-03 <br>
|
||||
* <b>版权所有:<b>版权归北京卡达克数据技术中心所有。<br>
|
||||
*/
|
||||
@TableName("TS_USER_ROLE")
|
||||
public class UserRoleEO extends BaseEntity {
|
||||
|
||||
private String roleId;
|
||||
|
||||
@@ -15,8 +15,10 @@ import lombok.experimental.Accessors;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -64,6 +66,10 @@ public class SarMenuStandard extends BaseEntity {
|
||||
@TableField("DISPLAY_SEQ")
|
||||
private Integer displaySeq;
|
||||
|
||||
@ApiModelProperty(value = "排序")
|
||||
@TableField(exist = false)
|
||||
private Integer systemSort;
|
||||
|
||||
@ApiModelProperty(value = "路径")
|
||||
@TableField("HREF")
|
||||
private String href;
|
||||
@@ -107,4 +113,109 @@ public class SarMenuStandard extends BaseEntity {
|
||||
@TableField(exist = false)
|
||||
private String treeType;
|
||||
|
||||
@ApiModelProperty(value = "树层级")
|
||||
@TableField(exist = false)
|
||||
private Integer level;
|
||||
@TableField(exist = false)
|
||||
|
||||
private Integer gbStandCount;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer fbStandCount;
|
||||
|
||||
@TableField(exist = false)
|
||||
private Integer esStandCount;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<String> gbStandIdList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<String> fbStandIdList;
|
||||
|
||||
@TableField(exist = false)
|
||||
private List<String> esStandIdList;
|
||||
|
||||
// 添加用于计算和设置关联关系数量的方法
|
||||
// 添加用于计算和设置关联关系数量的方法
|
||||
public void calculateAndSetCounts(List<StandMenuRelation> gbStandMenu, List<StandMenuRelation> fbStandMenu, List<StandMenuRelation> esStandMenu, Integer curLevel) {
|
||||
this.gbStandIdList = new ArrayList<>();
|
||||
this.fbStandIdList = new ArrayList<>();
|
||||
this.esStandIdList = new ArrayList<>();
|
||||
this.level = curLevel;
|
||||
this.gbStandCount = countMatches(gbStandMenu, this.id, gbStandIdList);
|
||||
this.fbStandCount = countMatches(fbStandMenu, this.id, fbStandIdList);
|
||||
this.esStandCount = countMatches(esStandMenu, this.id, esStandIdList);
|
||||
|
||||
for (SarMenuStandard child : children) {
|
||||
child.calculateAndSetCounts(gbStandMenu, fbStandMenu, esStandMenu, curLevel + 1);
|
||||
this.gbStandCount += child.gbStandCount;
|
||||
this.gbStandIdList.addAll(child.gbStandIdList);
|
||||
this.fbStandCount += child.fbStandCount;
|
||||
this.fbStandIdList.addAll(child.fbStandIdList);
|
||||
this.esStandCount += child.esStandCount;
|
||||
this.esStandIdList.addAll(child.esStandIdList);
|
||||
}
|
||||
}
|
||||
|
||||
private int countMatches(List<StandMenuRelation> standMenuList, String menuId, List<String> standIdList) {
|
||||
int count = 0;
|
||||
// 计算与menuId匹配的项的数量
|
||||
for (StandMenuRelation standMenu : standMenuList) {
|
||||
if (standMenu.getMenuId().equals(menuId)) {
|
||||
count++;
|
||||
standIdList.add(standMenu.getStandId());
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
// 添加用于构建映射的方法
|
||||
public void buildPathMap(Map<String, String> pathMap, String parentPath) {
|
||||
String currentPath = parentPath.isEmpty() ? this.menuName : parentPath + "/" + this.menuName;
|
||||
pathMap.put(this.id, currentPath);
|
||||
for (SarMenuStandard child : children) {
|
||||
child.buildPathMap(pathMap, currentPath);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加用于收集子节点ID的方法
|
||||
public void collectChildIds(List<String> childIds) {
|
||||
childIds.add(this.id);
|
||||
for (SarMenuStandard child : children) {
|
||||
child.collectChildIds(childIds);
|
||||
}
|
||||
}
|
||||
|
||||
public static SarMenuStandard findNodeById(SarMenuStandard node, String menuId) {
|
||||
if (node == null) {
|
||||
return null;
|
||||
}
|
||||
// 检查当前节点的ID是否匹配
|
||||
if (menuId.equals(node.getId())) {
|
||||
return node;
|
||||
}
|
||||
// 在子节点中递归搜索
|
||||
for (SarMenuStandard child : node.getChildren()) {
|
||||
SarMenuStandard found = findNodeById(child, menuId);
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
// 如果在当前节点及其子节点中都没有找到,返回null
|
||||
return null;
|
||||
}
|
||||
|
||||
// 递归方法来设置每个节点的 systemSort
|
||||
public static void setSystemSort(SarMenuStandard node, String parentSort) {
|
||||
// 计算当前节点的 systemSort
|
||||
String currentSort = parentSort.isEmpty() ? String.valueOf(node.getDisplaySeq()) : parentSort + node.getDisplaySeq();
|
||||
|
||||
// 设置当前节点的 systemSort
|
||||
node.setSystemSort(Integer.parseInt(currentSort));
|
||||
|
||||
// 递归设置子节点的 systemSort
|
||||
for (SarMenuStandard child : node.getChildren()) {
|
||||
setSystemSort(child, currentSort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.adc.da.sys.sarMenuStandard.entity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author: Mzaxd
|
||||
* @Date: 2023/11/14 16:31
|
||||
*/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class StandMenuRelation {
|
||||
|
||||
private String standId;
|
||||
|
||||
private String menuId;
|
||||
|
||||
}
|
||||
@@ -3,5 +3,9 @@ package com.adc.da.sys.service;
|
||||
import com.adc.da.sys.entity.UserRoleEO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface IUserRoleEOService extends IService<UserRoleEO> {
|
||||
|
||||
List<String> getRoleIdsByUserId(String userId);
|
||||
}
|
||||
|
||||
@@ -3,11 +3,16 @@ package com.adc.da.sys.service.impl;
|
||||
import com.adc.da.sys.dao.UserRoleEODao;
|
||||
import com.adc.da.sys.entity.UserRoleEO;
|
||||
import com.adc.da.sys.service.IUserRoleEOService;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -21,4 +26,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
@Transactional(value = "transactionManager", readOnly = false, propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
||||
public class UserRoleEOServiceImpl extends ServiceImpl<UserRoleEODao, UserRoleEO> implements IUserRoleEOService {
|
||||
|
||||
@Override
|
||||
public List<String> getRoleIdsByUserId(String userId) {
|
||||
return this.list(new LambdaQueryWrapper<UserRoleEO>()
|
||||
.eq(UserRoleEO::getUserId, userId))
|
||||
.stream().map(UserRoleEO::getRoleId).distinct().collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user