|
@ -2,6 +2,7 @@ package com.example.demo.serviceImpl; |
|
|
|
|
|
|
|
|
import com.example.demo.domain.entity.Role; |
|
|
import com.example.demo.domain.entity.Role; |
|
|
import com.example.demo.domain.vo.ConsumeUser; |
|
|
import com.example.demo.domain.vo.ConsumeUser; |
|
|
|
|
|
import com.example.demo.domain.vo.MenuVo; |
|
|
import com.example.demo.domain.vo.Result; |
|
|
import com.example.demo.domain.vo.Result; |
|
|
import com.example.demo.domain.vo.RoleVo; |
|
|
import com.example.demo.domain.vo.RoleVo; |
|
|
import com.example.demo.mapper.RefundMapper; |
|
|
import com.example.demo.mapper.RefundMapper; |
|
@ -38,29 +39,28 @@ public class RoleServiceImpl implements RoleService { |
|
|
@Transactional |
|
|
@Transactional |
|
|
public Result addRole(RoleVo roleVo) { |
|
|
public Result addRole(RoleVo roleVo) { |
|
|
//校验角色 |
|
|
//校验角色 |
|
|
if(roleVo.getRoleName()==null|| roleVo.getRoleName().isEmpty()){ |
|
|
|
|
|
|
|
|
if (roleVo.getRoleName() == null || roleVo.getRoleName().isEmpty()) { |
|
|
return Result.error("角色名为空"); |
|
|
return Result.error("角色名为空"); |
|
|
} |
|
|
} |
|
|
if(roleMapper.selectByRoleName(roleVo.getRoleName())!=null){ |
|
|
|
|
|
|
|
|
if (roleMapper.selectByRoleName(roleVo.getRoleName()) != null) { |
|
|
return Result.error("角色名重复"); |
|
|
return Result.error("角色名重复"); |
|
|
} |
|
|
} |
|
|
if(roleVo.getPriority()==null){ |
|
|
|
|
|
|
|
|
if (roleVo.getPriority() == null) { |
|
|
return Result.error("优先级为空"); |
|
|
return Result.error("优先级为空"); |
|
|
} |
|
|
} |
|
|
if(roleVo.getMenuIds()==null||roleVo.getMenuIds().isEmpty()){ |
|
|
|
|
|
|
|
|
if (roleVo.getMenuIds() == null || roleVo.getMenuIds().isEmpty()) { |
|
|
return Result.error("权限为空"); |
|
|
return Result.error("权限为空"); |
|
|
} |
|
|
} |
|
|
try { |
|
|
try { |
|
|
roleMapper.addRole(roleVo); |
|
|
roleMapper.addRole(roleVo); |
|
|
Role role = roleMapper.selectByRoleName(roleVo.getRoleName()); |
|
|
Role role = roleMapper.selectByRoleName(roleVo.getRoleName()); |
|
|
if(role==null){ |
|
|
|
|
|
|
|
|
if (role == null) { |
|
|
return Result.error("角色添加失败"); |
|
|
return Result.error("角色添加失败"); |
|
|
}else{ |
|
|
|
|
|
|
|
|
} else { |
|
|
roleVo.setId(role.getId()); |
|
|
roleVo.setId(role.getId()); |
|
|
} |
|
|
} |
|
|
menuService.addPermission(roleVo); |
|
|
menuService.addPermission(roleVo); |
|
|
}catch (Exception e) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
return Result.error("添加失败"); |
|
|
return Result.error("添加失败"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -83,6 +83,13 @@ public class RoleServiceImpl implements RoleService { |
|
|
public PageInfo<RoleVo> selectBy(Integer pageNum, Integer pageSize, RoleVo roleVo) { |
|
|
public PageInfo<RoleVo> selectBy(Integer pageNum, Integer pageSize, RoleVo roleVo) { |
|
|
PageHelper.startPage(pageNum, pageSize); |
|
|
PageHelper.startPage(pageNum, pageSize); |
|
|
List<RoleVo> roleVos = roleMapper.selectBy(roleVo); |
|
|
List<RoleVo> roleVos = roleMapper.selectBy(roleVo); |
|
|
|
|
|
// 遍历 roleVos 列表 |
|
|
|
|
|
for (RoleVo role : roleVos) { |
|
|
|
|
|
// 获取每个角色的权限树 |
|
|
|
|
|
List<MenuVo> permissionTree = menuService.getPermissionTree(role.getId()); |
|
|
|
|
|
// 将权限树设置到角色对象中 |
|
|
|
|
|
role.setTree(permissionTree); |
|
|
|
|
|
} |
|
|
return new PageInfo<>(roleVos); |
|
|
return new PageInfo<>(roleVos); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|