增加集群绑定角色接口.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
package com.xuxd.kafka.console.beans.dos;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 21:35
|
||||
**/
|
||||
@Data
|
||||
@TableName("t_cluster_role_relation")
|
||||
public class ClusterRoleRelationDO {
|
||||
|
||||
@TableId(type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long clusterInfoId;
|
||||
|
||||
private String updateTime;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.xuxd.kafka.console.beans.dto;
|
||||
|
||||
import com.xuxd.kafka.console.beans.dos.ClusterRoleRelationDO;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 21:42
|
||||
**/
|
||||
@Data
|
||||
public class ClusterRoleRelationDTO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long clusterInfoId;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
public ClusterRoleRelationDO toDO() {
|
||||
ClusterRoleRelationDO aDo = new ClusterRoleRelationDO();
|
||||
aDo.setId(id);
|
||||
aDo.setRoleId(roleId);
|
||||
aDo.setClusterInfoId(clusterInfoId);
|
||||
return aDo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.xuxd.kafka.console.beans.vo;
|
||||
|
||||
import com.xuxd.kafka.console.beans.dos.ClusterRoleRelationDO;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 21:45
|
||||
**/
|
||||
@Data
|
||||
public class ClusterRoleRelationVO {
|
||||
|
||||
private Long id;
|
||||
|
||||
private Long roleId;
|
||||
|
||||
private Long clusterInfoId;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
private String roleName;
|
||||
|
||||
private String clusterName;
|
||||
|
||||
public static ClusterRoleRelationVO from(ClusterRoleRelationDO relationDO) {
|
||||
ClusterRoleRelationVO vo = new ClusterRoleRelationVO();
|
||||
vo.setId(relationDO.getId());
|
||||
vo.setRoleId(relationDO.getRoleId());
|
||||
vo.setClusterInfoId(relationDO.getClusterInfoId());
|
||||
vo.setUpdateTime(relationDO.getUpdateTime());
|
||||
return vo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.xuxd.kafka.console.controller;
|
||||
|
||||
import com.xuxd.kafka.console.aspect.annotation.ControllerLog;
|
||||
import com.xuxd.kafka.console.aspect.annotation.Permission;
|
||||
import com.xuxd.kafka.console.beans.dto.ClusterRoleRelationDTO;
|
||||
import com.xuxd.kafka.console.service.ClusterRoleRelationService;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 22:01
|
||||
**/
|
||||
@RestController
|
||||
@RequestMapping("/cluster-role/relation")
|
||||
public class ClusterRoleRelationController {
|
||||
|
||||
private final ClusterRoleRelationService service;
|
||||
|
||||
public ClusterRoleRelationController(ClusterRoleRelationService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Permission("user-manage:cluster-role")
|
||||
@GetMapping
|
||||
public Object select() {
|
||||
return service.select();
|
||||
}
|
||||
|
||||
@ControllerLog("增加集群归属角色信息")
|
||||
@Permission("user-manage:cluster-role:add")
|
||||
@PostMapping
|
||||
public Object add(@RequestBody ClusterRoleRelationDTO dto) {
|
||||
return service.add(dto);
|
||||
}
|
||||
|
||||
@ControllerLog("删除集群归属角色信息")
|
||||
@Permission("user-manage:cluster-role:delete")
|
||||
@DeleteMapping
|
||||
public Object delete(@RequestParam("id") Long id) {
|
||||
return service.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.xuxd.kafka.console.dao;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xuxd.kafka.console.beans.dos.ClusterRoleRelationDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* Cluster info and role relation.
|
||||
*
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 21:40
|
||||
**/
|
||||
@Mapper
|
||||
public interface ClusterRoleRelationMapper extends BaseMapper<ClusterRoleRelationDO> {
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.xuxd.kafka.console.service;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.dto.ClusterRoleRelationDTO;
|
||||
|
||||
/**
|
||||
* Cluster info and role relation.
|
||||
*
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 21:42
|
||||
**/
|
||||
public interface ClusterRoleRelationService {
|
||||
|
||||
ResponseData select();
|
||||
|
||||
ResponseData add(ClusterRoleRelationDTO dto);
|
||||
|
||||
ResponseData delete(Long id);
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package com.xuxd.kafka.console.service.impl;
|
||||
|
||||
import com.xuxd.kafka.console.beans.ResponseData;
|
||||
import com.xuxd.kafka.console.beans.dos.ClusterInfoDO;
|
||||
import com.xuxd.kafka.console.beans.dos.ClusterRoleRelationDO;
|
||||
import com.xuxd.kafka.console.beans.dos.SysRoleDO;
|
||||
import com.xuxd.kafka.console.beans.dto.ClusterRoleRelationDTO;
|
||||
import com.xuxd.kafka.console.beans.vo.ClusterRoleRelationVO;
|
||||
import com.xuxd.kafka.console.dao.ClusterInfoMapper;
|
||||
import com.xuxd.kafka.console.dao.ClusterRoleRelationMapper;
|
||||
import com.xuxd.kafka.console.dao.SysRoleMapper;
|
||||
import com.xuxd.kafka.console.service.ClusterRoleRelationService;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author: xuxd
|
||||
* @since: 2023/8/23 21:50
|
||||
**/
|
||||
@Service
|
||||
public class ClusterRoleRelationServiceImpl implements ClusterRoleRelationService {
|
||||
|
||||
private final ClusterRoleRelationMapper mapper;
|
||||
|
||||
private final SysRoleMapper roleMapper;
|
||||
|
||||
private final ClusterInfoMapper clusterInfoMapper;
|
||||
|
||||
public ClusterRoleRelationServiceImpl(final ClusterRoleRelationMapper mapper,
|
||||
final SysRoleMapper roleMapper,
|
||||
final ClusterInfoMapper clusterInfoMapper) {
|
||||
this.mapper = mapper;
|
||||
this.roleMapper = roleMapper;
|
||||
this.clusterInfoMapper = clusterInfoMapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData select() {
|
||||
List<ClusterRoleRelationDO> dos = mapper.selectList(null);
|
||||
|
||||
Map<Long, SysRoleDO> roleMap = roleMapper.selectList(null).stream().
|
||||
collect(Collectors.toMap(SysRoleDO::getId, Function.identity(), (e1, e2) -> e2));
|
||||
Map<Long, ClusterInfoDO> clusterMap = clusterInfoMapper.selectList(null).stream().
|
||||
collect(Collectors.toMap(ClusterInfoDO::getId, Function.identity(), (e1, e2) -> e2));
|
||||
List<ClusterRoleRelationVO> vos = dos.stream().
|
||||
map(aDo -> {
|
||||
ClusterRoleRelationVO vo = ClusterRoleRelationVO.from(aDo);
|
||||
if (roleMap.containsKey(vo.getRoleId())) {
|
||||
vo.setRoleName(roleMap.get(vo.getRoleId()).getRoleName());
|
||||
}
|
||||
if (clusterMap.containsKey(vo.getClusterInfoId())) {
|
||||
vo.setClusterName(clusterMap.get(vo.getClusterInfoId()).getClusterName());
|
||||
}
|
||||
return vo;
|
||||
}).collect(Collectors.toList());
|
||||
return ResponseData.create().data(vos).success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData add(ClusterRoleRelationDTO dto) {
|
||||
mapper.insert(dto.toDO());
|
||||
return ResponseData.create().success();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResponseData delete(Long id) {
|
||||
mapper.deleteById(id);
|
||||
return ResponseData.create().success();
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,9 @@ insert into t_sys_permission(id, name,type,parent_id,permission) values(147,'保
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(148,'删除',1,146,'user-manage:role:del');
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(149,'权限列表',1,140,'user-manage:permission');
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(150,'个人设置',1,140,'user-manage:setting');
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(151,'集群权限',1,140,'user-manage:cluster-role');
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(152,'新增',1,151,'user-manage:cluster-role:add');
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(153,'删除',1,151,'user-manage:cluster-role:delete');
|
||||
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(160,'运维',0,null,'op');
|
||||
insert into t_sys_permission(id, name,type,parent_id,permission) values(161,'集群切换',1,160,'op:cluster-switch');
|
||||
@@ -98,7 +101,7 @@ insert into t_sys_permission(id, name,type,parent_id,permission) values(171,'取
|
||||
-- t_sys_permission end--
|
||||
|
||||
-- t_sys_role start--
|
||||
insert into t_sys_role(id, role_name, description, permission_ids) VALUES (1,'超级管理员','超级管理员','12,13,14,22,23,24,25,26,27,28,29,30,34,35,31,32,33,42,43,44,45,46,47,48,49,50,62,63,64,65,66,67,81,82,83,84,85,86,87,88,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,141,142,143,144,145,146,147,148,149,150,161,162,163,164,165,166,167,168,169,171,170');
|
||||
insert into t_sys_role(id, role_name, description, permission_ids) VALUES (1,'超级管理员','超级管理员','12,13,14,22,23,24,25,26,27,28,29,30,34,35,31,32,33,42,43,44,45,46,47,48,49,50,62,63,64,65,66,67,81,82,83,84,85,86,87,88,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,141,142,143,144,145,146,147,148,149,150,151,152,153,161,162,163,164,165,166,167,168,169,171,170');
|
||||
insert into t_sys_role(id, role_name, description, permission_ids) VALUES (2,'普通管理员','普通管理员,不能更改用户信息','12,13,14,22,23,24,25,26,27,28,29,30,34,35,31,32,33,42,43,44,45,46,47,48,49,50,62,63,64,65,66,67,81,82,83,84,85,86,87,88,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,141,146,149,150,161,162,163,164,165,166,167,168,169,171,170');
|
||||
-- insert into t_sys_role(id, role_name, description, permission_ids) VALUES (2,'访客','访客','12,13,22,26,29,32,44,45,50,62,63,81,83,85,141,146,149,150,161,163');
|
||||
-- t_sys_role end--
|
||||
|
||||
@@ -65,4 +65,15 @@ CREATE TABLE IF NOT EXISTS t_sys_user
|
||||
role_ids varchar(100) DEFAULT NULL COMMENT '分配角色的ID',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE (username)
|
||||
);
|
||||
|
||||
-- 集群数据权限与角色绑定
|
||||
CREATE TABLE IF NOT EXISTS t_cluster_role_relation
|
||||
(
|
||||
ID IDENTITY NOT NULL COMMENT '主键ID',
|
||||
ROLE_ID bigint(20) NOT NULL COMMENT '角色ID',
|
||||
CLUSTER_INFO_ID bigint(20) NOT NULL COMMENT '集群信息的ID',
|
||||
UPDATE_TIME TIMESTAMP NOT NULL DEFAULT NOW() COMMENT '更新时间',
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE (ROLE_ID, CLUSTER_INFO_ID)
|
||||
);
|
||||
Reference in New Issue
Block a user