增加集群绑定角色接口.
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user