add 角色树查询接口
This commit is contained in:
+100
@@ -0,0 +1,100 @@
|
||||
package com.jero.common.system.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 角色表 存储树结构数据的实体类
|
||||
*
|
||||
* @author liJiaRao
|
||||
* @date 2021-08-26 16:02
|
||||
*/
|
||||
@Data
|
||||
public class SysRoleTreeModel implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 对应SysRole中的id字段,前端数据树中的key
|
||||
*/
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* 对应SysRole中的id字段,前端数据树中的value
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 对应roleName字段,前端数据树中的title
|
||||
*/
|
||||
private String title;
|
||||
|
||||
private boolean isLeaf;
|
||||
|
||||
// 以下所有字段均与SysRole相同
|
||||
/**
|
||||
* id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 父类id
|
||||
*/
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色编码
|
||||
*/
|
||||
private String roleCode;
|
||||
|
||||
/**
|
||||
* 描述
|
||||
*/
|
||||
private String description;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date createTime;
|
||||
|
||||
/**
|
||||
* 更新人
|
||||
*/
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private Date updateTime;
|
||||
|
||||
private List<SysRoleTreeModel> children = new ArrayList<>();
|
||||
|
||||
public void setChildren(List<SysRoleTreeModel> children) {
|
||||
if (children == null || children.size() == 0) {
|
||||
this.isLeaf = true;
|
||||
}else {
|
||||
this.isLeaf = false;
|
||||
}
|
||||
this.children = children;
|
||||
}
|
||||
}
|
||||
+16
@@ -13,8 +13,11 @@ import java.util.Map;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.jero.common.system.vo.SysDepartTreeModel;
|
||||
import com.jero.common.system.vo.SysRoleTreeModel;
|
||||
import com.jero.modules.system.entity.*;
|
||||
import com.jero.modules.system.service.*;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.authz.annotation.RequiresRoles;
|
||||
import com.jero.common.api.vo.Result;
|
||||
@@ -101,6 +104,19 @@ public class SysRoleController {
|
||||
result.setResult(pageList);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据 查出所有角色,并以树结构数据格式响应给前端
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@ApiOperation(value="树结构查询", notes="查询数据 查出所有角色,并以树结构数据格式响应给前端")
|
||||
@RequiresPermissions("sys:depart:list")
|
||||
@RequestMapping(value = "/treeList", method = RequestMethod.GET)
|
||||
public Result<List<SysRoleTreeModel>> queryTreeList() {
|
||||
List<SysRoleTreeModel> list = sysRoleService.queryTreeList();
|
||||
return Result.OK(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
|
||||
@@ -35,6 +35,11 @@ public class SysRole implements Serializable {
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 父类id
|
||||
*/
|
||||
private String parentId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
|
||||
+9
@@ -2,10 +2,13 @@ package com.jero.modules.system.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.system.vo.SysRoleTreeModel;
|
||||
import com.jero.modules.system.entity.SysRole;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 角色表 服务类
|
||||
@@ -40,4 +43,10 @@ public interface ISysRoleService extends IService<SysRole> {
|
||||
*/
|
||||
public boolean deleteBatchRole(String[] roleids);
|
||||
|
||||
/**
|
||||
* 查询角色树
|
||||
* @return
|
||||
*/
|
||||
List<SysRoleTreeModel> queryTreeList();
|
||||
|
||||
}
|
||||
|
||||
+38
-5
@@ -1,25 +1,23 @@
|
||||
package com.jero.modules.system.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import org.apache.poi.ss.formula.functions.T;
|
||||
import com.jero.common.system.vo.SysRoleTreeModel;
|
||||
import com.jero.common.api.vo.Result;
|
||||
import com.jero.common.constant.CommonConstant;
|
||||
import com.jero.common.util.ImportExcelUtil;
|
||||
import com.jero.common.util.PmsUtil;
|
||||
import com.jero.modules.quartz.service.IQuartzJobService;
|
||||
import com.jero.modules.system.entity.SysRole;
|
||||
import com.jero.modules.system.mapper.SysRoleMapper;
|
||||
import com.jero.modules.system.mapper.SysUserMapper;
|
||||
import com.jero.modules.system.service.ISysRoleService;
|
||||
import org.jeecgframework.poi.excel.ExcelImportUtil;
|
||||
import org.jeecgframework.poi.excel.entity.ImportParams;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -90,4 +88,39 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
||||
this.removeByIds(Arrays.asList(roleIds));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<SysRoleTreeModel> queryTreeList() {
|
||||
//1:获取所有父级
|
||||
List<SysRoleTreeModel> parent = getChildrenByParentId(null);
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据父级id获取所有子集
|
||||
* @param parentId
|
||||
* @return
|
||||
*/
|
||||
private List<SysRoleTreeModel> getChildrenByParentId(String parentId){
|
||||
LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<>();
|
||||
if (parentId==null){
|
||||
wrapper.isNull(SysRole::getParentId);
|
||||
}else {
|
||||
wrapper.eq(SysRole::getParentId,parentId);
|
||||
}
|
||||
List<SysRole> list = sysRoleMapper.selectList(wrapper);
|
||||
List<SysRoleTreeModel> treeModelList = new ArrayList<>();
|
||||
for (SysRole sysRole : list) {
|
||||
SysRoleTreeModel treeModel = new SysRoleTreeModel();
|
||||
BeanUtils.copyProperties(sysRole,treeModel);
|
||||
treeModel.setKey(sysRole.getId());
|
||||
treeModel.setValue(sysRole.getId());
|
||||
treeModel.setTitle(sysRole.getRoleName());
|
||||
List<SysRoleTreeModel> children = getChildrenByParentId(sysRole.getId());
|
||||
treeModel.setChildren(children);
|
||||
treeModelList.add(treeModel);
|
||||
}
|
||||
return treeModelList;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user