提交 b3aabef1 编写于 作者: Tyl666's avatar Tyl666

角色查询父子关系逻辑修改

上级 a28a9c97
......@@ -23,7 +23,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
@Primary
@Service("SysRoleExService")
public class SysRoleExService extends SysRoleServiceImpl {
List<String> result = new ArrayList<>();
List<SysRole> result = new ArrayList<>();
@Override
protected Class currentModelClass() {
......@@ -47,26 +47,24 @@ public class SysRoleExService extends SysRoleServiceImpl {
@Override
@SneakyThrows
public Page<SysRole> searchNoRepeat(SysRoleSearchContext context) {
List<String> newResult = new CopyOnWriteArrayList<>();
List<SysRole> newResult = new CopyOnWriteArrayList<>();
String sysRoleid = (String) context.getParams().get("sys_roleid");
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> pages=baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
List<SysRole> sysRoles = new ArrayList<>();
SysRole currentSysRole = baseMapper.selectById(sysRoleid);
if(!ObjectUtils.isEmpty(currentSysRole)){
sysRoles.add(currentSysRole);
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> pages = baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
if(!ObjectUtils.isEmpty(sysRoleid)){
findSRelation(result,pages.getRecords(),sysRoleid);
newResult.addAll(findPRelation(sysRoleid,new ArrayList<String>()));
newResult.addAll(findPRelation(sysRoleid,new ArrayList<SysRole>()));
newResult.addAll(result);
result.clear();
}
String noRepeat = String.join(";", newResult);
context.setN_sys_roleid_notin(noRepeat);
com.baomidou.mybatisplus.extension.plugins.pagination.Page<SysRole> newPages=baseMapper.searchNoRepeat(context.getPages(),context,context.getSelectCond());
return new PageImpl<SysRole>(newPages.getRecords(), context.getPageable(), newPages.getTotal());
for (int i = 0;i < newResult.size();i++){
for (int j = 0;j < pages.getRecords().size();j++){
if(pages.getRecords().get(j).getRoleid().equals(newResult.get(i).getRoleid())){
pages.getRecords().remove(j);
}
}
}
return new PageImpl<SysRole>(pages.getRecords(), context.getPageable(), pages.getTotal() - newResult.size());
}
/**
......@@ -75,13 +73,13 @@ public class SysRoleExService extends SysRoleServiceImpl {
* @param pList 父id集合
* @return
*/
private List<String> findPRelation(String contextId,List<String> pList){
private List<SysRole> findPRelation(String contextId,List<SysRole> pList){
SysRole currentSysRole = baseMapper.selectById(contextId);
// 查出当前id的所有父级别id
if (!ObjectUtils.isEmpty(currentSysRole)){
String proleId = currentSysRole.getProleid();
if(!StringUtils.isEmpty(proleId)){
pList.add(currentSysRole.getRoleid());
pList.add(currentSysRole);
return findPRelation(proleId,pList);
}else {
return pList;
......@@ -96,12 +94,12 @@ public class SysRoleExService extends SysRoleServiceImpl {
* @param roleList 数据库查询出来的所有角色集合
* @param pId 父id
*/
private void findSRelation(List<String> childRole,List<SysRole> roleList, String pId) {
private void findSRelation(List<SysRole> childRole,List<SysRole> roleList, String pId) {
for (SysRole role : roleList) {
if (!StringUtils.isEmpty(role.getProleid())) {
if (role.getProleid().equals(pId)) {
findSRelation(childRole,roleList, role.getRoleid());
result.add(role.getRoleid());
result.add(role);
}
}
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册