角色管理
This commit is contained in:
parent
8acc07852a
commit
2bafddcaa2
|
|
@ -12,6 +12,9 @@ import lombok.Data;
|
||||||
@Data
|
@Data
|
||||||
public class RoleDto {
|
public class RoleDto {
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "角色ID")
|
||||||
|
private Integer roleId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "角色名称")
|
@ApiModelProperty(value = "角色名称")
|
||||||
private String roleName;
|
private String roleName;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@ package com.securitycontrol.entity.system.vo;
|
||||||
|
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import org.hibernate.validator.constraints.Length;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotBlank;
|
||||||
|
import javax.validation.constraints.Pattern;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:cwchen
|
* @author:cwchen
|
||||||
|
|
@ -16,9 +21,24 @@ public class RoleVo {
|
||||||
private Integer roleId;
|
private Integer roleId;
|
||||||
|
|
||||||
@ApiModelProperty(value = "角色名称")
|
@ApiModelProperty(value = "角色名称")
|
||||||
|
@NotBlank(message = "角色名称不能为空")
|
||||||
|
@Length(max = 30,message = "字符长度不能超过30个字符")
|
||||||
private String roleName;
|
private String roleName;
|
||||||
|
|
||||||
@ApiModelProperty(value = "排序")
|
@ApiModelProperty(value = "排序")
|
||||||
|
@NotBlank(message = "排序不能为空")
|
||||||
|
@Pattern(regexp = "[1-9]\\d{0,2}$|^1000",message = "排序为1-1000")
|
||||||
private String roleSort;
|
private String roleSort;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "创建时间")
|
||||||
|
private String createTime;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "flag")
|
||||||
|
private boolean flag;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "类型")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@ApiModelProperty(value = "菜单ID集合")
|
||||||
|
private List<String> menuIds;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,17 @@
|
||||||
package com.securitycontrol.system.base.controller;
|
package com.securitycontrol.system.base.controller;
|
||||||
|
|
||||||
|
import com.securitycontrol.common.core.web.controller.BaseController;
|
||||||
|
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||||
|
import com.securitycontrol.common.core.web.page.TableDataInfo;
|
||||||
|
import com.securitycontrol.entity.system.dto.RoleDto;
|
||||||
|
import com.securitycontrol.entity.system.vo.RoleVo;
|
||||||
import com.securitycontrol.system.base.service.IRoleService;
|
import com.securitycontrol.system.base.service.IRoleService;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import javax.validation.Valid;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:cwchen
|
* @author:cwchen
|
||||||
|
|
@ -14,8 +21,52 @@ import javax.annotation.Resource;
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/sys/role/")
|
@RequestMapping("/sys/role/")
|
||||||
public class RoleController {
|
public class RoleController extends BaseController {
|
||||||
|
|
||||||
@Resource(name = "IRoleService")
|
@Resource(name = "IRoleService")
|
||||||
private IRoleService service;
|
private IRoleService service;
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取角色列表")
|
||||||
|
@GetMapping("getRoleLists")
|
||||||
|
public TableDataInfo getRoleLists(RoleDto dto) {
|
||||||
|
startPage();
|
||||||
|
List<RoleVo> list = service.getRoleLists(dto);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "新增角色")
|
||||||
|
@PostMapping("addRole")
|
||||||
|
public AjaxResult addRole(@Valid @RequestBody RoleVo vo){
|
||||||
|
return service.addOrUpdateRole(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "修改角色")
|
||||||
|
@PostMapping("editRole")
|
||||||
|
public AjaxResult editRole(@Valid @RequestBody RoleVo vo){
|
||||||
|
return service.addOrUpdateRole(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "角色详情")
|
||||||
|
@GetMapping("getRoleById")
|
||||||
|
public AjaxResult getRoleById(RoleDto dto){
|
||||||
|
return service.getRoleById(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "删除角色")
|
||||||
|
@PostMapping("delRole")
|
||||||
|
public AjaxResult delRole(RoleDto dto){
|
||||||
|
return service.delRole(dto);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "角色授权菜单")
|
||||||
|
@PostMapping("authMenu")
|
||||||
|
public AjaxResult authMenu(@RequestBody RoleVo vo){
|
||||||
|
return service.authMenu(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "获取角色授权的菜单")
|
||||||
|
@GetMapping("getAuthMenus")
|
||||||
|
public AjaxResult getAuthMenu(RoleDto dto){
|
||||||
|
return service.getAuthMenu(dto);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,4 +35,9 @@ public class SelectController extends BaseController {
|
||||||
return service.getRoleLists();
|
return service.getRoleLists();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "菜单树")
|
||||||
|
@PostMapping("getMenuTree")
|
||||||
|
public AjaxResult getMenuTree(){
|
||||||
|
return service.getMenuTree();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
package com.securitycontrol.system.base.mapper;
|
package com.securitycontrol.system.base.mapper;
|
||||||
|
|
||||||
|
import com.securitycontrol.entity.system.dto.RoleDto;
|
||||||
|
import com.securitycontrol.entity.system.vo.RoleVo;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:cwchen
|
* @author:cwchen
|
||||||
* @date:2024-02-23-18:34
|
* @date:2024-02-23-18:34
|
||||||
|
|
@ -10,4 +14,98 @@ import org.springframework.stereotype.Repository;
|
||||||
*/
|
*/
|
||||||
@Repository(value = "IRoleMapper")
|
@Repository(value = "IRoleMapper")
|
||||||
public interface IRoleMapper {
|
public interface IRoleMapper {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色列表
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return List<RoleVo>
|
||||||
|
* @description 角色列表
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 9:34
|
||||||
|
*/
|
||||||
|
List<RoleVo> getRoleLists(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增/修改角色
|
||||||
|
*
|
||||||
|
* @param vo
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:32
|
||||||
|
*/
|
||||||
|
void addOrUpdateRole(RoleVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色是否存在
|
||||||
|
*
|
||||||
|
* @param roleName
|
||||||
|
* @return int
|
||||||
|
* @description 角色是否存在
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:38
|
||||||
|
*/
|
||||||
|
int isRoleName(String roleName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色详情
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return RoleVo
|
||||||
|
* @description 角色详情
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:45
|
||||||
|
*/
|
||||||
|
RoleVo getRoleById(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 是否存在用户使用该角色
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return int
|
||||||
|
* @description 是否存在用户使用该角色
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:50
|
||||||
|
*/
|
||||||
|
int isUserUse(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @description 删除角色
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:51
|
||||||
|
*/
|
||||||
|
void deleteRole(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色已授权的菜单数据
|
||||||
|
*
|
||||||
|
* @param vo
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 14:49
|
||||||
|
*/
|
||||||
|
void delRoleMenu(RoleVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增角色授权的菜单数据
|
||||||
|
*
|
||||||
|
* @param vo
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 14:49
|
||||||
|
*/
|
||||||
|
void addRoleMenu(RoleVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色授权的菜单
|
||||||
|
* @param dto
|
||||||
|
* @return List<String>
|
||||||
|
* @description 获取角色授权的菜单
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 14:55
|
||||||
|
*/
|
||||||
|
List<String> getAuthMenu(RoleDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -27,10 +27,20 @@ public interface ISelectMapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色下拉选
|
* 角色下拉选
|
||||||
|
*
|
||||||
* @return List<SelectVo>
|
* @return List<SelectVo>
|
||||||
* @description 角色下拉选
|
* @description 角色下拉选
|
||||||
* @author cwchen
|
* @author cwchen
|
||||||
* @date 2024/2/22 13:28
|
* @date 2024/2/22 13:28
|
||||||
*/
|
*/
|
||||||
List<SelectVo> getRoleLists();
|
List<SelectVo> getRoleLists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单树
|
||||||
|
* @return List<TreeNode>
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 13:35
|
||||||
|
*/
|
||||||
|
List<TreeNode> getMenuTree();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,11 @@
|
||||||
package com.securitycontrol.system.base.service;
|
package com.securitycontrol.system.base.service;
|
||||||
|
|
||||||
|
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||||
|
import com.securitycontrol.entity.system.dto.RoleDto;
|
||||||
|
import com.securitycontrol.entity.system.vo.RoleVo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:cwchen
|
* @author:cwchen
|
||||||
* @date:2024-02-23-18:32
|
* @date:2024-02-23-18:32
|
||||||
|
|
@ -7,4 +13,69 @@ package com.securitycontrol.system.base.service;
|
||||||
* @description:角色管理-业务层
|
* @description:角色管理-业务层
|
||||||
*/
|
*/
|
||||||
public interface IRoleService {
|
public interface IRoleService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色列表
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return List<RoleVo>
|
||||||
|
* @description 角色列表
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 9:32
|
||||||
|
*/
|
||||||
|
List<RoleVo> getRoleLists(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增/修改角色
|
||||||
|
*
|
||||||
|
* @param vo
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description 新增/修改角色
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:29
|
||||||
|
*/
|
||||||
|
AjaxResult addOrUpdateRole(RoleVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色详情
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:42
|
||||||
|
*/
|
||||||
|
AjaxResult getRoleById(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除角色
|
||||||
|
*
|
||||||
|
* @param dto
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 10:48
|
||||||
|
*/
|
||||||
|
AjaxResult delRole(RoleDto dto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 角色授权菜单
|
||||||
|
*
|
||||||
|
* @param vo
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description 角色授权菜单
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 14:41
|
||||||
|
*/
|
||||||
|
AjaxResult authMenu(RoleVo vo);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取角色授权的菜单
|
||||||
|
* @param dto
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description 获取角色授权的菜单
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 14:54
|
||||||
|
*/
|
||||||
|
AjaxResult getAuthMenu(RoleDto dto);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,10 +22,20 @@ public interface ISelectService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 角色下拉选
|
* 角色下拉选
|
||||||
|
*
|
||||||
* @return AjaxResult
|
* @return AjaxResult
|
||||||
* @description 角色下拉选
|
* @description 角色下拉选
|
||||||
* @author cwchen
|
* @author cwchen
|
||||||
* @date 2024/2/22 13:27
|
* @date 2024/2/22 13:27
|
||||||
*/
|
*/
|
||||||
AjaxResult getRoleLists();
|
AjaxResult getRoleLists();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 菜单树
|
||||||
|
* @return AjaxResult
|
||||||
|
* @description 菜单树
|
||||||
|
* @author cwchen
|
||||||
|
* @date 2024/2/26 13:33
|
||||||
|
*/
|
||||||
|
AjaxResult getMenuTree();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,19 @@
|
||||||
package com.securitycontrol.system.base.service.impl;
|
package com.securitycontrol.system.base.service.impl;
|
||||||
|
|
||||||
|
import com.securitycontrol.common.core.utils.aes.DateTimeHelper;
|
||||||
|
import com.securitycontrol.common.core.web.domain.AjaxResult;
|
||||||
|
import com.securitycontrol.entity.system.dto.RoleDto;
|
||||||
|
import com.securitycontrol.entity.system.vo.RoleVo;
|
||||||
import com.securitycontrol.system.base.mapper.IRoleMapper;
|
import com.securitycontrol.system.base.mapper.IRoleMapper;
|
||||||
import com.securitycontrol.system.base.service.IRoleService;
|
import com.securitycontrol.system.base.service.IRoleService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author:cwchen
|
* @author:cwchen
|
||||||
|
|
@ -13,8 +22,81 @@ import javax.annotation.Resource;
|
||||||
* @description:角色管理-业务逻辑层
|
* @description:角色管理-业务逻辑层
|
||||||
*/
|
*/
|
||||||
@Service(value = "IRoleService")
|
@Service(value = "IRoleService")
|
||||||
|
@Slf4j
|
||||||
public class RoleServiceImpl implements IRoleService {
|
public class RoleServiceImpl implements IRoleService {
|
||||||
|
|
||||||
@Resource(name = "IRoleMapper")
|
@Resource(name = "IRoleMapper")
|
||||||
private IRoleMapper mapper;
|
private IRoleMapper mapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<RoleVo> getRoleLists(RoleDto dto) {
|
||||||
|
List<RoleVo> list = new ArrayList<>();
|
||||||
|
list = mapper.getRoleLists(dto);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult addOrUpdateRole(RoleVo vo) {
|
||||||
|
try {
|
||||||
|
int result = mapper.isRoleName(vo.getRoleName());
|
||||||
|
if (vo.getRoleId() == null) {
|
||||||
|
vo.setType(1);
|
||||||
|
vo.setCreateTime(DateTimeHelper.getNowTime());
|
||||||
|
if(result > 0){
|
||||||
|
return AjaxResult.error("角色已存在");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vo.setType(2);
|
||||||
|
if(vo.isFlag()){
|
||||||
|
if(result > 0){
|
||||||
|
return AjaxResult.error("角色已存在");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mapper.addOrUpdateRole(vo);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("角色",e);
|
||||||
|
//手动回滚异常
|
||||||
|
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||||
|
return AjaxResult.error();
|
||||||
|
}
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult getRoleById(RoleDto dto) {
|
||||||
|
RoleVo vo = new RoleVo();
|
||||||
|
vo = mapper.getRoleById(dto);
|
||||||
|
return AjaxResult.success(vo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult delRole(RoleDto dto) {
|
||||||
|
int result = mapper.isUserUse(dto);
|
||||||
|
if(result > 0){
|
||||||
|
return AjaxResult.error("已有用户绑定该角色,请先删除用户");
|
||||||
|
}
|
||||||
|
mapper.deleteRole(dto);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public AjaxResult authMenu(RoleVo vo) {
|
||||||
|
if(vo.getRoleId() == null || vo.getMenuIds() == null){
|
||||||
|
return AjaxResult.error("参数不完整");
|
||||||
|
}
|
||||||
|
mapper.delRoleMenu(vo);
|
||||||
|
mapper.addRoleMenu(vo);
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult getAuthMenu(RoleDto dto) {
|
||||||
|
List<String> list = new ArrayList<>();
|
||||||
|
list = mapper.getAuthMenu(dto);
|
||||||
|
return AjaxResult.success(list);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
@Service(value = "ISelectService")
|
@Service(value = "ISelectService")
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ISelectServiceImpl implements ISelectService {
|
public class SelectServiceImpl implements ISelectService {
|
||||||
|
|
||||||
@Resource(name = "ISelectMapper")
|
@Resource(name = "ISelectMapper")
|
||||||
private ISelectMapper mapper;
|
private ISelectMapper mapper;
|
||||||
|
|
@ -34,7 +34,7 @@ public class ISelectServiceImpl implements ISelectService {
|
||||||
List<TreeNode> list = mapper.getOrgTree();
|
List<TreeNode> list = mapper.getOrgTree();
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
// 创建树形结构(数据集合作为参数)
|
// 创建树形结构(数据集合作为参数)
|
||||||
groupList= TreeBuild.transTreeList(list);
|
groupList = TreeBuild.transTreeList(list);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("组织机构树-查询失败", e);
|
log.error("组织机构树-查询失败", e);
|
||||||
|
|
@ -49,5 +49,18 @@ public class ISelectServiceImpl implements ISelectService {
|
||||||
return AjaxResult.success(list);
|
return AjaxResult.success(list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public AjaxResult getMenuTree() {
|
||||||
|
List<TreeNode> groupList = new ArrayList<>();
|
||||||
|
try {
|
||||||
|
List<TreeNode> list = mapper.getMenuTree();
|
||||||
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
// 创建树形结构(数据集合作为参数)
|
||||||
|
groupList = TreeBuild.transTreeList(list);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("菜单树-查询失败", e);
|
||||||
|
}
|
||||||
|
return AjaxResult.success(groupList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,80 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||||
<mapper namespace="com.securitycontrol.system.base.mapper.IRoleMapper">
|
<mapper namespace="com.securitycontrol.system.base.mapper.IRoleMapper">
|
||||||
|
<!--新增/修改角色-->
|
||||||
|
<insert id="addOrUpdateRole">
|
||||||
|
<if test="type == 1">
|
||||||
|
INSERT INTO sys_role
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="roleName != null and roleName != ''">role_name,</if>
|
||||||
|
<if test="roleSort != null and roleSort!=''">role_sort,</if>
|
||||||
|
<if test="createTime != null and createTime!=''">create_time,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="roleName != null and roleName != ''">#{roleName},</if>
|
||||||
|
<if test="roleSort != null and roleSort!=''">#{roleSort},</if>
|
||||||
|
<if test="createTime != null and createTime!=''">#{createTime},</if>
|
||||||
|
</trim>
|
||||||
|
</if>
|
||||||
|
<if test="type == 2">
|
||||||
|
UPDATE sys_role
|
||||||
|
<set>
|
||||||
|
<if test="roleName != null and roleName != ''">role_name = #{roleName},</if>
|
||||||
|
<if test="roleSort != null and roleSort != ''">role_sort = #{roleSort},</if>
|
||||||
|
</set>
|
||||||
|
WHERE role_id = #{roleId}
|
||||||
|
</if>
|
||||||
|
</insert>
|
||||||
|
<!--新增角色授权的菜单数据-->
|
||||||
|
<insert id="addRoleMenu">
|
||||||
|
INSERT INTO sys_role_menu(role_id,menu_id) VALUES
|
||||||
|
<foreach collection="menuIds" separator="," item="item">
|
||||||
|
(
|
||||||
|
#{roleId},#{item}
|
||||||
|
)
|
||||||
|
</foreach>
|
||||||
|
</insert>
|
||||||
|
<!--删除角色-->
|
||||||
|
<update id="deleteRole">
|
||||||
|
UPDATE sys_role SET del_flag = 1 WHERE role_id = #{roleId}
|
||||||
|
</update>
|
||||||
|
<!--删除角色已授权的菜单数据-->
|
||||||
|
<delete id="delRoleMenu">
|
||||||
|
DELETE FROM sys_role_menu WHERE role_id = #{roleId}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<!--角色列表-->
|
||||||
|
<select id="getRoleLists" resultType="com.securitycontrol.entity.system.vo.RoleVo">
|
||||||
|
SELECT role_id AS roleId,
|
||||||
|
role_name AS roleName,
|
||||||
|
role_sort AS roleSort,
|
||||||
|
create_time AS createTime
|
||||||
|
FROM sys_role
|
||||||
|
<where>
|
||||||
|
<if test="roleName!=null and roleName!=''">
|
||||||
|
INSTR(role_name,#{roleName}) > 0
|
||||||
|
</if>
|
||||||
|
AND del_flag = 0
|
||||||
|
</where>
|
||||||
|
ORDER BY role_sort, create_time
|
||||||
|
</select>
|
||||||
|
<!--角色是否存在-->
|
||||||
|
<select id="isRoleName" resultType="java.lang.Integer">
|
||||||
|
SELECT COUNT(*) FROM sys_role WHERE role_name = #{roleName} AND del_flag = 0
|
||||||
|
</select>
|
||||||
|
<!--角色详情-->
|
||||||
|
<select id="getRoleById" resultType="com.securitycontrol.entity.system.vo.RoleVo">
|
||||||
|
SELECT role_id AS roleId,
|
||||||
|
role_name AS roleName,
|
||||||
|
role_sort AS roleSort
|
||||||
|
FROM sys_role WHERE role_id = #{roleId} AND del_flag = 0
|
||||||
|
</select>
|
||||||
|
<!--是否存在用户使用该角色-->
|
||||||
|
<select id="isUserUse" resultType="java.lang.Integer">
|
||||||
|
SELECT COUNT(*) FROM sys_user WHERE role_id = #{roleId} AND del_flag = 0
|
||||||
|
</select>
|
||||||
|
<!--获取角色授权的菜单-->
|
||||||
|
<select id="getAuthMenu" resultType="java.lang.String">
|
||||||
|
SELECT menu_id FROM sys_role_menu WHERE role_id = #{roleId}
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
@ -18,4 +18,13 @@
|
||||||
WHERE del_flag = 0
|
WHERE del_flag = 0
|
||||||
ORDER BY role_sort
|
ORDER BY role_sort
|
||||||
</select>
|
</select>
|
||||||
|
<!--菜单树-->
|
||||||
|
<select id="getMenuTree" resultType="com.securitycontrol.entity.system.vo.TreeNode">
|
||||||
|
SELECT menu_id AS id,
|
||||||
|
p_id AS parentId,
|
||||||
|
menu_name AS label,
|
||||||
|
menu_url AS level
|
||||||
|
FROM sys_menu
|
||||||
|
WHERE del_flag = 0
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
Loading…
Reference in New Issue