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

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

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