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

移动到自定义代码部分

上级 932968e6
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.uaa.filter.SysRoleSearchContext;
import cn.ibizlab.core.uaa.service.impl.SysRoleServiceImpl;
import liquibase.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.uaa.domain.SysRole;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary;
import org.springframework.util.ObjectUtils;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* 实体[系统角色] 自定义服务对象
......@@ -15,6 +22,7 @@ import java.util.*;
@Primary
@Service("SysRoleExService")
public class SysRoleExService extends SysRoleServiceImpl {
List<SysRole> result = new ArrayList<>();
@Override
protected Class currentModelClass() {
......@@ -31,5 +39,80 @@ public class SysRoleExService extends SysRoleServiceImpl {
public SysRole noRepeat(SysRole et) {
return super.noRepeat(et);
}
/**
* 查询集合 数据查询
*/
@Override
public Page<SysRole> searchNoRepeat(SysRoleSearchContext context) {
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);
selectChild(sysRoles);
// 加入父子级关联对象
newResult.addAll(findPRelation(sysRoleid,new ArrayList<SysRole>()));
newResult.addAll(result);
result.clear();
}
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());
}
/**
*
* @param contextId
* @return
*/
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);
return findPRelation(proleId,pList);
}else {
return pList;
}
}
return null;
}
/**
* 获取某个父节点下面的所有子节点
* @return
*/
public void selectChild(List<SysRole> ids){
//用来存取调用自身递归时的参数
List<SysRole> temp= new ArrayList<SysRole>();
//查询数据库中对应id的实体类
List<SysRole> sysEnterpriseOrgList = new ArrayList<SysRole>();
//遍历传递过来的参数ids
for (SysRole sRole :ids) {
//查询子级架构
sysEnterpriseOrgList= selectByProleid(sRole.getRoleid());
//遍历list获取符合条件的对象的id值,一份存到temp中用作递归的参数,并存到全局变量中用来获取所有符合条件的id
for (SysRole s:sysEnterpriseOrgList) {
temp.add(s);
result.add(s);
}
}
if(temp.size()!=0&&temp!=null){
selectChild(temp);
}
}
}
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册