feat;增加角色模块
This commit is contained in:
@@ -3,20 +3,22 @@ package com.tiesheng.role.controller;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleServer;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleUser;
|
||||
import com.tiesheng.role.pojos.dao.*;
|
||||
import com.tiesheng.role.pojos.dto.GroupRxUpdateDTO;
|
||||
import com.tiesheng.role.pojos.dto.MenuListDTO;
|
||||
import com.tiesheng.role.pojos.dto.OwerPointDTO;
|
||||
import com.tiesheng.role.pojos.dto.ServiceDTO;
|
||||
import com.tiesheng.role.pojos.vo.GroupTypeDTO;
|
||||
import com.tiesheng.role.pojos.vo.RoleUserPageVO;
|
||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||
import com.tiesheng.role.service.CoreRoleService;
|
||||
import com.tiesheng.role.service.CoreServerService;
|
||||
import com.tiesheng.util.config.TsTokenConfig;
|
||||
import com.tiesheng.util.exception.ApiException;
|
||||
import com.tiesheng.util.pojos.ApiResp;
|
||||
import com.tiesheng.util.pojos.IdDTO;
|
||||
import com.tiesheng.util.pojos.PageDTO;
|
||||
import com.tiesheng.util.pojos.TokenBean;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@@ -94,6 +96,33 @@ public class RoleController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取角色的权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/group/rx/list")
|
||||
public ApiResp<List<CoreRoleGroupRx>> groupRxList(@Valid IdDTO dto) {
|
||||
List<CoreRoleGroupRx> list = coreRoleService.getGroupRxMapper().selectList(new QueryWrapper<CoreRoleGroupRx>()
|
||||
.eq(CoreRoleGroupRx.IS_DELETED, 0)
|
||||
.eq("group_id", dto.getId())
|
||||
);
|
||||
return ApiResp.respOK(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 橘色的权限编辑
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/group/rx/update")
|
||||
public ApiResp<String> groupRxUpdate(@RequestBody @Valid GroupRxUpdateDTO dto) {
|
||||
coreRoleService.updateGroupRx(dto);
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 授权列表
|
||||
*
|
||||
@@ -175,11 +204,12 @@ public class RoleController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/authority/list")
|
||||
public ApiResp<List<ServiceMenuVO>> menuList(@Valid ServiceDTO dto) {
|
||||
public ApiResp<List<ServiceMenuVO>> menuList(@Valid MenuListDTO dto) {
|
||||
|
||||
List<CoreRoleAuthority> list = coreServerService.getAuthorityMapper().selectList(new QueryWrapper<CoreRoleAuthority>()
|
||||
.eq(CoreRoleAuthority.IS_DELETED, 0)
|
||||
.eq("service", dto.getService())
|
||||
.eq(StrUtil.isNotEmpty(dto.getPlatform()), "platform", dto.getPlatform())
|
||||
.orderByAsc("sort")
|
||||
);
|
||||
|
||||
@@ -196,6 +226,7 @@ public class RoleController {
|
||||
*/
|
||||
@PostMapping("/authority/update")
|
||||
public ApiResp<String> menuUpdate(@RequestBody CoreRoleAuthority serviceMenu) {
|
||||
serviceMenu.setParent(StrUtil.emptyToDefault(serviceMenu.getParent(), null));
|
||||
if (StrUtil.isEmpty(serviceMenu.getId())) {
|
||||
coreServerService.getAuthorityMapper().insert(serviceMenu);
|
||||
} else {
|
||||
@@ -206,4 +237,41 @@ public class RoleController {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取自己拥有的服务
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/owner/server")
|
||||
public ApiResp<List<CoreRoleAuthority>> ownerServer() {
|
||||
TokenBean tokenBean = TsTokenConfig.get();
|
||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getAllOwnerMenus(tokenBean.getId(), tokenBean.getRoleId());
|
||||
return ApiResp.respOK(allOwnerMenus);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取自己拥有的菜单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/owner/menu")
|
||||
public ApiResp<String> ownerMenu(@Valid ServiceDTO dto) {
|
||||
|
||||
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取自己拥有的功能点
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/owner/point")
|
||||
public ApiResp<String> ownerPoint(@Valid OwerPointDTO dto) {
|
||||
|
||||
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.tiesheng.role.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleGroupRx;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CoreRoleGroupRxMapper extends BaseMapper<CoreRoleGroupRx> {
|
||||
/**
|
||||
* 批量插入数据
|
||||
*
|
||||
* @param coreRoleGroupRxs
|
||||
* @return
|
||||
*/
|
||||
int batchInsert(@Param("list") List<CoreRoleGroupRx> coreRoleGroupRxs);
|
||||
}
|
||||
@@ -3,10 +3,13 @@ package com.tiesheng.role.mapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleUser;
|
||||
import com.tiesheng.role.pojos.vo.RoleUserPageVO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CoreRoleUserMapper extends BaseMapper<CoreRoleUser> {
|
||||
|
||||
|
||||
@@ -19,4 +22,14 @@ public interface CoreRoleUserMapper extends BaseMapper<CoreRoleUser> {
|
||||
*/
|
||||
Page<RoleUserPageVO> page(Page<RoleUserPageVO> page, @Param("ew") QueryWrapper<CoreRoleUser> wrapper);
|
||||
|
||||
|
||||
/**
|
||||
* 获取用户所有的权限
|
||||
*
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CoreRoleAuthority> getAllAuthorityByUserId(@Param("userId") String userId,
|
||||
@Param("roleId") String roleId);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.tiesheng.role.pojos.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import com.tiesheng.util.pojos.DaoBase;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 角色-分组-关系
|
||||
*/
|
||||
@TableName(value = "core_role_group_rx")
|
||||
public class CoreRoleGroupRx extends DaoBase {
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@TableField(value = "group_id")
|
||||
private String groupId;
|
||||
|
||||
/**
|
||||
* 菜单id
|
||||
*/
|
||||
@TableField(value = "menu_id")
|
||||
private String menuId;
|
||||
|
||||
/**
|
||||
* 获取角色id
|
||||
*
|
||||
* @return group_id - 角色id
|
||||
*/
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置角色id
|
||||
*
|
||||
* @param groupId 角色id
|
||||
*/
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取菜单id
|
||||
*
|
||||
* @return menu_id - 菜单id
|
||||
*/
|
||||
public String getMenuId() {
|
||||
return menuId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置菜单id
|
||||
*
|
||||
* @param menuId 菜单id
|
||||
*/
|
||||
public void setMenuId(String menuId) {
|
||||
this.menuId = menuId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
import com.tiesheng.util.pojos.IdDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupRxUpdateDTO extends IdDTO {
|
||||
|
||||
private List<String> menuIds;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public List<String> getMenuIds() {
|
||||
return menuIds;
|
||||
}
|
||||
|
||||
public void setMenuIds(List<String> menuIds) {
|
||||
this.menuIds = menuIds;
|
||||
}
|
||||
}
|
||||
@@ -2,26 +2,17 @@ package com.tiesheng.role.pojos.dto;
|
||||
|
||||
public class MenuListDTO extends ServiceDTO {
|
||||
|
||||
private String parent;
|
||||
private Integer childSize = 0;
|
||||
private String platform;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
public String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public Integer getChildSize() {
|
||||
return childSize;
|
||||
}
|
||||
|
||||
public void setChildSize(Integer childSize) {
|
||||
this.childSize = childSize;
|
||||
public void setPlatform(String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
public class OwerPointDTO extends ServiceDTO {
|
||||
|
||||
private String parent;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,20 @@
|
||||
package com.tiesheng.role.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.tiesheng.role.mapper.CoreRoleGroupMapper;
|
||||
import com.tiesheng.role.mapper.CoreRoleGroupRxMapper;
|
||||
import com.tiesheng.role.mapper.CoreRoleUserMapper;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleGroup;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleGroupRx;
|
||||
import com.tiesheng.role.pojos.dto.GroupRxUpdateDTO;
|
||||
import com.tiesheng.util.service.TsServiceBase;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRoleGroup> {
|
||||
@@ -15,7 +23,53 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
@Resource
|
||||
CoreRoleUserMapper coreRoleUserMapper;
|
||||
|
||||
@Resource
|
||||
CoreRoleGroupRxMapper coreRoleGroupRxMapper;
|
||||
|
||||
|
||||
public CoreRoleUserMapper getUserMapper() {
|
||||
return coreRoleUserMapper;
|
||||
}
|
||||
|
||||
public CoreRoleGroupRxMapper getGroupRxMapper() {
|
||||
return coreRoleGroupRxMapper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新角色的权限
|
||||
*
|
||||
* @param dto
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateGroupRx(GroupRxUpdateDTO dto) {
|
||||
coreRoleGroupRxMapper.delete(new QueryWrapper<CoreRoleGroupRx>()
|
||||
.eq("group_id", dto.getId())
|
||||
);
|
||||
List<CoreRoleGroupRx> list = new ArrayList<>();
|
||||
for (String menuId : dto.getMenuIds()) {
|
||||
CoreRoleGroupRx coreRoleGroupRx = new CoreRoleGroupRx();
|
||||
coreRoleGroupRx.setGroupId(dto.getId());
|
||||
coreRoleGroupRx.setMenuId(menuId);
|
||||
list.add(coreRoleGroupRx);
|
||||
}
|
||||
coreRoleGroupRxMapper.batchInsert(list);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有的菜单
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<CoreRoleAuthority> getAllOwnerMenus(String userId,String roleId) {
|
||||
List<CoreRoleAuthority> authority = coreRoleUserMapper.getAllAuthorityByUserId(userId, "");
|
||||
|
||||
|
||||
|
||||
|
||||
return authority;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user