feat:提交角色授权
This commit is contained in:
@@ -4,15 +4,11 @@ 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.*;
|
||||
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.dto.*;
|
||||
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;
|
||||
@@ -31,8 +27,6 @@ import java.util.stream.Collectors;
|
||||
@RequestMapping("/role")
|
||||
public class RoleController {
|
||||
|
||||
@Resource
|
||||
CoreServerService coreServerService;
|
||||
@Resource
|
||||
CoreRoleService coreRoleService;
|
||||
|
||||
@@ -182,7 +176,10 @@ public class RoleController {
|
||||
*/
|
||||
@GetMapping("/server/list")
|
||||
public ApiResp<List<CoreRoleServer>> list() {
|
||||
return ApiResp.respOK(coreServerService.list());
|
||||
return ApiResp.respOK(coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
||||
.eq(CoreRoleServer.IS_DELETED, 0)
|
||||
.eq("is_open", 1)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -194,7 +191,11 @@ public class RoleController {
|
||||
*/
|
||||
@PostMapping("/server/update")
|
||||
public ApiResp<String> update(@RequestBody CoreRoleServer coreService) {
|
||||
coreServerService.saveOrUpdate(coreService);
|
||||
if (StrUtil.isNotEmpty(coreService.getId())) {
|
||||
coreRoleService.getServerMapper().updateById(coreService);
|
||||
} else {
|
||||
coreRoleService.getServerMapper().insert(coreService);
|
||||
}
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
|
||||
@@ -207,14 +208,14 @@ public class RoleController {
|
||||
@GetMapping("/authority/list")
|
||||
public ApiResp<List<ServiceMenuVO>> menuList(@Valid MenuListDTO dto) {
|
||||
|
||||
List<CoreRoleAuthority> list = coreServerService.getAuthorityMapper().selectList(new QueryWrapper<CoreRoleAuthority>()
|
||||
List<CoreRoleAuthority> list = coreRoleService.getAuthorityMapper().selectList(new QueryWrapper<CoreRoleAuthority>()
|
||||
.eq(CoreRoleAuthority.IS_DELETED, 0)
|
||||
.eq("service", dto.getService())
|
||||
.eq(StrUtil.isNotEmpty(dto.getPlatform()), "platform", dto.getPlatform())
|
||||
.orderByAsc("sort")
|
||||
);
|
||||
|
||||
List<ServiceMenuVO> collect = coreServerService.menuWrap(list, null);
|
||||
List<ServiceMenuVO> collect = coreRoleService.menuChildrenWrap(list, null);
|
||||
|
||||
return ApiResp.respOK(collect);
|
||||
}
|
||||
@@ -229,10 +230,10 @@ public class RoleController {
|
||||
public ApiResp<String> menuUpdate(@RequestBody CoreRoleAuthority serviceMenu) {
|
||||
serviceMenu.setParent(StrUtil.emptyToDefault(serviceMenu.getParent(), null));
|
||||
if (StrUtil.isEmpty(serviceMenu.getId())) {
|
||||
coreServerService.getAuthorityMapper().insert(serviceMenu);
|
||||
coreRoleService.getAuthorityMapper().insert(serviceMenu);
|
||||
} else {
|
||||
serviceMenu.setNo(null);
|
||||
coreServerService.getAuthorityMapper().updateById(serviceMenu);
|
||||
coreRoleService.getAuthorityMapper().updateById(serviceMenu);
|
||||
}
|
||||
return ApiResp.respOK("");
|
||||
}
|
||||
@@ -246,10 +247,12 @@ public class RoleController {
|
||||
@GetMapping("/owner/server")
|
||||
public ApiResp<List<CoreRoleServer>> ownerServer() {
|
||||
TokenBean tokenBean = TsTokenConfig.get();
|
||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getAllOwnerMenus(tokenBean.getId(), tokenBean.getRoleId());
|
||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
||||
|
||||
List<CoreRoleServer> roleServerList = coreServerService.list(new QueryWrapper<CoreRoleServer>()
|
||||
List<CoreRoleServer> roleServerList = coreRoleService.getServerMapper().selectList(new QueryWrapper<CoreRoleServer>()
|
||||
.in("id", allOwnerMenus.stream().map(CoreRoleAuthority::getService).collect(Collectors.toList()))
|
||||
.eq(CoreRoleServer.IS_DELETED, 0)
|
||||
.eq("is_open", 1)
|
||||
);
|
||||
|
||||
return ApiResp.respOK(roleServerList);
|
||||
@@ -262,9 +265,12 @@ public class RoleController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/owner/menu")
|
||||
public ApiResp<String> ownerMenu(@Valid ServiceDTO dto) {
|
||||
public ApiResp<List<ServiceMenuVO>> ownerMenu(@Valid OwnerMenuDTO dto) {
|
||||
|
||||
return ApiResp.respOK("");
|
||||
TokenBean tokenBean = TsTokenConfig.get();
|
||||
List<ServiceMenuVO> ownerMenus = coreRoleService.getOwnerMenus(tokenBean.getId(), tokenBean.getRoleId(), dto);
|
||||
|
||||
return ApiResp.respOK(ownerMenus);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -273,10 +279,10 @@ public class RoleController {
|
||||
* @return
|
||||
*/
|
||||
@GetMapping("/owner/point")
|
||||
public ApiResp<List<CoreRoleAuthority>> ownerPoint(@Valid OwerPointDTO dto) {
|
||||
public ApiResp<List<CoreRoleAuthority>> ownerPoint(@Valid OwnerPointDTO dto) {
|
||||
|
||||
TokenBean tokenBean = TsTokenConfig.get();
|
||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getAllOwnerMenus(tokenBean.getId(), tokenBean.getRoleId());
|
||||
List<CoreRoleAuthority> allOwnerMenus = coreRoleService.getOwnerAuthorityLeafList(tokenBean.getId(), tokenBean.getRoleId());
|
||||
|
||||
List<CoreRoleAuthority> collect = allOwnerMenus.stream()
|
||||
.filter(it -> Objects.equals(it.getType(), "point"))
|
||||
|
||||
@@ -29,7 +29,7 @@ public interface CoreRoleUserMapper extends BaseMapper<CoreRoleUser> {
|
||||
* @param userId
|
||||
* @return
|
||||
*/
|
||||
List<CoreRoleAuthority> getAllAuthorityByUserId(@Param("userId") String userId,
|
||||
@Param("roleId") String roleId);
|
||||
List<CoreRoleAuthority> getOwnerAuthorityLeafList(@Param("userId") String userId,
|
||||
@Param("roleId") String roleId);
|
||||
|
||||
}
|
||||
|
||||
@@ -2,9 +2,7 @@ package com.tiesheng.role.pojos.dto;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
public class OwerPointDTO extends ServiceDTO {
|
||||
|
||||
private String parent;
|
||||
public class OwnerMenuDTO extends ServiceDTO {
|
||||
|
||||
@NotEmpty(message = "请选择一个平台")
|
||||
private String platform;
|
||||
@@ -13,19 +11,11 @@ public class OwerPointDTO extends ServiceDTO {
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public String getPlatform() {
|
||||
public @NotEmpty(message = "请选择一个平台") String getPlatform() {
|
||||
return platform;
|
||||
}
|
||||
|
||||
public void setPlatform(String platform) {
|
||||
public void setPlatform(@NotEmpty(message = "请选择一个平台") String platform) {
|
||||
this.platform = platform;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.tiesheng.role.pojos.dto;
|
||||
|
||||
public class OwnerPointDTO extends OwnerMenuDTO {
|
||||
|
||||
private String parent;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// setter\getter
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public String getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +1,24 @@
|
||||
package com.tiesheng.role.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
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.mapper.*;
|
||||
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.role.pojos.dto.MenuListDTO;
|
||||
import com.tiesheng.role.pojos.dto.OwnerMenuDTO;
|
||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||
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;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRoleGroup> {
|
||||
@@ -26,6 +30,19 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
@Resource
|
||||
CoreRoleGroupRxMapper coreRoleGroupRxMapper;
|
||||
|
||||
@Resource
|
||||
CoreRoleAuthorityMapper coreRoleAuthorityMapper;
|
||||
|
||||
@Resource
|
||||
CoreRoleServerMapper coreRoleServerMapper;
|
||||
|
||||
public CoreRoleServerMapper getServerMapper() {
|
||||
return coreRoleServerMapper;
|
||||
}
|
||||
|
||||
public CoreRoleAuthorityMapper getAuthorityMapper() {
|
||||
return coreRoleAuthorityMapper;
|
||||
}
|
||||
|
||||
public CoreRoleUserMapper getUserMapper() {
|
||||
return coreRoleUserMapper;
|
||||
@@ -36,6 +53,32 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 菜单封装
|
||||
*
|
||||
* @param coreServiceMenuList
|
||||
* @param parent
|
||||
* @return
|
||||
*/
|
||||
public List<ServiceMenuVO> menuChildrenWrap(List<CoreRoleAuthority> coreServiceMenuList, String parent) {
|
||||
List<CoreRoleAuthority> distinctList = coreServiceMenuList.stream().distinct().collect(Collectors.toList());
|
||||
|
||||
List<ServiceMenuVO> list = new ArrayList<>();
|
||||
|
||||
for (CoreRoleAuthority coreServiceMenu : distinctList) {
|
||||
if (!StrUtil.equals(parent, coreServiceMenu.getParent())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ServiceMenuVO menuVO = BeanUtil.copyProperties(coreServiceMenu, ServiceMenuVO.class);
|
||||
menuVO.setChildren(menuChildrenWrap(distinctList, coreServiceMenu.getId()));
|
||||
list.add(menuVO);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新角色的权限
|
||||
*
|
||||
@@ -58,16 +101,53 @@ public class CoreRoleService extends TsServiceBase<CoreRoleGroupMapper, CoreRole
|
||||
|
||||
|
||||
/**
|
||||
* 获取所有的菜单
|
||||
* 获取拥有的所有叶子权限
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public List<CoreRoleAuthority> getAllOwnerMenus(String userId, String roleId) {
|
||||
List<CoreRoleAuthority> authority = coreRoleUserMapper.getAllAuthorityByUserId(userId, roleId);
|
||||
|
||||
|
||||
return authority;
|
||||
public List<CoreRoleAuthority> getOwnerAuthorityLeafList(String userId, String roleId) {
|
||||
return coreRoleUserMapper.getOwnerAuthorityLeafList(userId, roleId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取自己拥有的所有菜单
|
||||
*
|
||||
* @param userId
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
public List<ServiceMenuVO> getOwnerMenus(String userId, String roleId, OwnerMenuDTO dto) {
|
||||
List<CoreRoleAuthority> allOwnerMenus = getOwnerAuthorityLeafList(userId, roleId);
|
||||
|
||||
List<CoreRoleAuthority> allRoleAuthorityList = coreRoleAuthorityMapper.selectList(new QueryWrapper<CoreRoleAuthority>()
|
||||
.eq(CoreRoleAuthority.IS_DELETED, 0)
|
||||
.eq("service", dto.getService())
|
||||
.eq("platform", dto.getPlatform())
|
||||
.eq("is_open", 1)
|
||||
);
|
||||
Map<Object, CoreRoleAuthority> allAuthorityMap = CollUtil.fieldValueMap(allRoleAuthorityList, "id");
|
||||
|
||||
|
||||
List<CoreRoleAuthority> ownerAuthorityList = new ArrayList<>();
|
||||
for (CoreRoleAuthority roleAuthority : allOwnerMenus) {
|
||||
ownerAuthorityList.add(roleAuthority);
|
||||
|
||||
String parentId = roleAuthority.getParent();
|
||||
while (StrUtil.isNotEmpty(parentId)) {
|
||||
CoreRoleAuthority parent = allAuthorityMap.get(parentId);
|
||||
if (parent == null) {
|
||||
parentId = "";
|
||||
} else {
|
||||
parentId = parent.getParent();
|
||||
ownerAuthorityList.add(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return menuChildrenWrap(ownerAuthorityList.stream()
|
||||
.filter(it -> Objects.equals(it.getType(), "group") || Objects.equals(it.getType(), "menu"))
|
||||
.collect(Collectors.toList()), null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
package com.tiesheng.role.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.tiesheng.role.mapper.CoreRoleAuthorityMapper;
|
||||
import com.tiesheng.role.mapper.CoreRoleServerMapper;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleAuthority;
|
||||
import com.tiesheng.role.pojos.dao.CoreRoleServer;
|
||||
import com.tiesheng.role.pojos.vo.ServiceMenuVO;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CoreServerService extends ServiceImpl<CoreRoleServerMapper, CoreRoleServer> {
|
||||
|
||||
@Resource
|
||||
CoreRoleAuthorityMapper coreRoleAuthorityMapper;
|
||||
|
||||
public CoreRoleAuthorityMapper getAuthorityMapper() {
|
||||
return coreRoleAuthorityMapper;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 菜单封装
|
||||
*
|
||||
* @param coreServiceMenuList
|
||||
* @param level
|
||||
* @return
|
||||
*/
|
||||
public List<ServiceMenuVO> menuWrap(List<CoreRoleAuthority> coreServiceMenuList, String parent) {
|
||||
List<ServiceMenuVO> list = new ArrayList<>();
|
||||
|
||||
for (CoreRoleAuthority coreServiceMenu : coreServiceMenuList) {
|
||||
if (!StrUtil.equals(parent, coreServiceMenu.getParent())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ServiceMenuVO menuVO = BeanUtil.copyProperties(coreServiceMenu, ServiceMenuVO.class);
|
||||
menuVO.setChildren(menuWrap(coreServiceMenuList, coreServiceMenu.getId()));
|
||||
list.add(menuVO);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user