Merge branch 'dev-role' into dev
This commit is contained in:
commit
f4ce15986c
@ -48,7 +48,7 @@ public class SysRoleController {
|
|||||||
* 根据角色编号获取详细信息
|
* 根据角色编号获取详细信息
|
||||||
*/
|
*/
|
||||||
@GetMapping(value = "/{roleId}")
|
@GetMapping(value = "/{roleId}")
|
||||||
public R<RoleVO> getInfo(@PathVariable @NotNull Long roleId) {
|
public R<RoleVO> getInfo(@PathVariable("roleId") @NotNull Long roleId) {
|
||||||
RoleVO roleInfo = sysRoleService.getRoleInfo(roleId);
|
RoleVO roleInfo = sysRoleService.getRoleInfo(roleId);
|
||||||
return R.ok(roleInfo);
|
return R.ok(roleInfo);
|
||||||
}
|
}
|
||||||
@ -65,7 +65,7 @@ public class SysRoleController {
|
|||||||
/**
|
/**
|
||||||
* 移除角色
|
* 移除角色
|
||||||
*/
|
*/
|
||||||
@PostMapping(value = "/{roleId}")
|
@PostMapping(value = "/del/{roleId}")
|
||||||
public R<Void> remove(@PathVariable("roleId") List<Long> roleIds) {
|
public R<Void> remove(@PathVariable("roleId") List<Long> roleIds) {
|
||||||
sysRoleService.deleteRole(roleIds);
|
sysRoleService.deleteRole(roleIds);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@ -74,7 +74,7 @@ public class SysRoleController {
|
|||||||
/**
|
/**
|
||||||
* 修改保存角色
|
* 修改保存角色
|
||||||
*/
|
*/
|
||||||
@PostMapping
|
@PostMapping("/update")
|
||||||
public R<Void> edit(@Validated @RequestBody UpdateRoleDTO updateDTO) {
|
public R<Void> edit(@Validated @RequestBody UpdateRoleDTO updateDTO) {
|
||||||
sysRoleService.updateRole(updateDTO);
|
sysRoleService.updateRole(updateDTO);
|
||||||
return R.ok();
|
return R.ok();
|
||||||
@ -94,7 +94,7 @@ public class SysRoleController {
|
|||||||
/**
|
/**
|
||||||
* 角色状态修改
|
* 角色状态修改
|
||||||
*/
|
*/
|
||||||
@PostMapping("/{roleId}/status")
|
@PostMapping("/status/{roleId}")
|
||||||
public R<Void> changeStatus(@PathVariable("roleId") Long roleId,
|
public R<Void> changeStatus(@PathVariable("roleId") Long roleId,
|
||||||
@RequestBody UpdateStatusDTO updateDTO) {
|
@RequestBody UpdateStatusDTO updateDTO) {
|
||||||
updateDTO.setRoleId(roleId);
|
updateDTO.setRoleId(roleId);
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
package com.agileboot.system.role.mapper;
|
package com.agileboot.system.role.mapper;
|
||||||
|
|
||||||
|
import com.agileboot.common.mybatis.mapper.BaseMapperDelete;
|
||||||
import com.agileboot.system.role.entity.SysRole;
|
import com.agileboot.system.role.entity.SysRole;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
import org.apache.ibatis.annotations.Select;
|
import org.apache.ibatis.annotations.Select;
|
||||||
|
|
||||||
public interface SysRoleMapper extends BaseMapper<SysRole> {
|
public interface SysRoleMapper extends BaseMapperDelete<SysRole> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 判断菜单是否被角色分配
|
* 判断菜单是否被角色分配
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
package com.agileboot.system.role.mapper;
|
package com.agileboot.system.role.mapper;
|
||||||
|
|
||||||
|
import com.agileboot.common.mybatis.mapper.BaseMapperDelete;
|
||||||
import com.agileboot.system.role.entity.SysRoleMenu;
|
import com.agileboot.system.role.entity.SysRoleMenu;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|
||||||
|
|
||||||
public interface SysRoleMenuMapper extends BaseMapper<SysRoleMenu> {
|
public interface SysRoleMenuMapper extends BaseMapperDelete<SysRoleMenu> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRo
|
|||||||
@Override
|
@Override
|
||||||
public boolean saveMenus(Long roleId, List<Long> menuIds) {
|
public boolean saveMenus(Long roleId, List<Long> menuIds) {
|
||||||
List<SysRoleMenu> list = new ArrayList<>();
|
List<SysRoleMenu> list = new ArrayList<>();
|
||||||
if (menuIds != null) {
|
if (menuIds != null && !menuIds.isEmpty()) {
|
||||||
for (Long menuId : menuIds) {
|
for (Long menuId : menuIds) {
|
||||||
SysRoleMenu rm = new SysRoleMenu();
|
SysRoleMenu rm = new SysRoleMenu();
|
||||||
rm.setRoleId(roleId);
|
rm.setRoleId(roleId);
|
||||||
@ -40,7 +40,6 @@ public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRo
|
|||||||
if (roleIds == null || roleIds.isEmpty()) {
|
if (roleIds == null || roleIds.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LambdaQueryWrapper<SysRoleMenu> queryWrapper = Wrappers.lambdaQuery(SysRoleMenu.class).in(SysRoleMenu::getRoleId, roleIds);
|
this.baseMapper.deleteAbsoluteByIds(roleIds);
|
||||||
super.remove(queryWrapper);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,20 +18,20 @@ import com.agileboot.system.user.dto.UserInfo;
|
|||||||
import com.agileboot.system.user.entity.SysUser;
|
import com.agileboot.system.user.entity.SysUser;
|
||||||
import com.agileboot.system.user.service.ISysUserService;
|
import com.agileboot.system.user.service.ISysUserService;
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.google.common.base.Preconditions;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.CollectionUtils;
|
import org.springframework.util.CollectionUtils;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -65,12 +65,9 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
public void addRole(AddRoleDTO addDTO) {
|
public void addRole(AddRoleDTO addDTO) {
|
||||||
SysRole entity = new SysRole();
|
SysRole entity = new SysRole();
|
||||||
BeanUtil.copyProperties(addDTO, entity);
|
BeanUtil.copyProperties(addDTO, entity);
|
||||||
if (this.isRoleNameDuplicated(null, addDTO.getRoleName())) {
|
this.checkRoleNameUnique(null, addDTO.getRoleName());
|
||||||
throw new BizException(ErrorCode.Business.ROLE_NAME_IS_NOT_UNIQUE, addDTO.getRoleName());
|
this.checkRoleKeyUnique(null, addDTO.getRoleKey());
|
||||||
}
|
|
||||||
if (this.isRoleKeyDuplicated(null, addDTO.getRoleKey())) {
|
|
||||||
throw new BizException(ErrorCode.Business.ROLE_KEY_IS_NOT_UNIQUE, addDTO.getRoleKey());
|
|
||||||
}
|
|
||||||
super.save(entity);
|
super.save(entity);
|
||||||
roleMenuService.saveMenus(entity.getRoleId(), addDTO.getMenuIds());
|
roleMenuService.saveMenus(entity.getRoleId(), addDTO.getMenuIds());
|
||||||
}
|
}
|
||||||
@ -94,30 +91,55 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
|
|
||||||
// 清空之前的角色菜单关联
|
// 清空之前的角色菜单关联
|
||||||
roleMenuService.cleanOldMenus(collect);
|
roleMenuService.cleanOldMenus(collect);
|
||||||
super.removeBatchByIds(collect);
|
super.baseMapper.deleteAbsoluteByIds(collect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Override
|
||||||
|
// @Transactional(rollbackFor = Exception.class)
|
||||||
|
// public void updateRole(UpdateRoleDTO updateDTO) {
|
||||||
|
// LambdaQueryWrapper<SysRole> roleLqw = new LambdaQueryWrapper<>();
|
||||||
|
// roleLqw.eq(SysRole::getRoleId, updateDTO.getRoleId());
|
||||||
|
// roleLqw.eq(SysRole::getStatus, StatusEnum.ENABLE.getValue());
|
||||||
|
// SysRole sysRole = getOne(roleLqw);
|
||||||
|
// Preconditions.checkArgument(Objects.nonNull(sysRole), "角色不存在");
|
||||||
|
// LambdaQueryWrapper<SysRoleMenu> roleMenuLqw = new LambdaQueryWrapper<>();
|
||||||
|
// roleMenuLqw.eq(SysRoleMenu::getRoleId, updateDTO.getRoleId());
|
||||||
|
// //角色对应的菜单
|
||||||
|
// LambdaUpdateWrapper<SysRoleMenu> roleMenuLuw = new LambdaUpdateWrapper<>();
|
||||||
|
// roleMenuLuw.eq(SysRoleMenu::getRoleId, updateDTO.getRoleId());
|
||||||
|
// roleMenuService.cleanOldMenus(List.of(updateDTO.getRoleId()));//清空之前的角色菜单关联
|
||||||
|
// List<Long> menuIds = updateDTO.getMenuIds();//新的菜单列表
|
||||||
|
// if (!CollectionUtils.isEmpty(menuIds)) {
|
||||||
|
// roleMenuService.saveMenus(updateDTO.getRoleId(), menuIds);
|
||||||
|
// }
|
||||||
|
// BeanUtils.copyProperties(updateDTO, sysRole, "roleId");
|
||||||
|
// updateById(sysRole);
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public void updateRole(UpdateRoleDTO updateDTO) {
|
public void updateRole(UpdateRoleDTO updateDTO) {
|
||||||
SysRole byId = super.getById(updateDTO.getRoleId());
|
SysRole byId = super.getById(updateDTO.getRoleId());
|
||||||
if (byId == null) {
|
if (byId == null) {
|
||||||
throw new BizException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, updateDTO.getRoleId(), "角色");
|
throw new BizException(ErrorCode.Business.COMMON_OBJECT_NOT_FOUND, updateDTO.getRoleId(), "角色");
|
||||||
}
|
}
|
||||||
List<SysRoleMenu> roleMenus = roleMenuService.listById(updateDTO.getRoleId());
|
// List<SysRoleMenu> roleMenus = roleMenuService.listById(updateDTO.getRoleId());
|
||||||
List<Long> menuIds = roleMenus.stream().map(SysRoleMenu::getMenuId).toList();
|
List<Long> menuIds = updateDTO.getMenuIds();
|
||||||
|
// List<Long> menuIds = roleMenus.stream().map(SysRoleMenu::getMenuId).toList();
|
||||||
|
|
||||||
// List<Long> deptIds = StrUtil.split(byId.getDeptIdSet(), ",").stream().map(Convert::toLong).toList();
|
// List<Long> deptIds = StrUtil.split(byId.getDeptIdSet(), ",").stream().map(Convert::toLong).toList();
|
||||||
|
|
||||||
SysRole entity = new SysRole();
|
BeanUtils.copyProperties(updateDTO, byId, "roleId");
|
||||||
BeanUtil.copyProperties(byId, entity);
|
this.checkRoleKeyUnique(byId.getRoleId(), byId.getRoleKey());
|
||||||
if (this.isRoleKeyDuplicated(entity.getRoleId(), entity.getRoleKey())) {
|
this.checkRoleNameUnique(byId.getRoleId(), byId.getRoleName());
|
||||||
throw new BizException(ErrorCode.Business.ROLE_KEY_IS_NOT_UNIQUE, entity.getRoleKey());
|
// 清空之前的角色菜单关联
|
||||||
|
roleMenuService.cleanOldMenus(List.of(byId.getRoleId()));
|
||||||
|
boolean b = roleMenuService.saveMenus(byId.getRoleId(), menuIds);
|
||||||
|
if (!b) {
|
||||||
|
throw new BizException("修改角色失败");
|
||||||
}
|
}
|
||||||
if (this.isRoleNameDuplicated(entity.getRoleId(), entity.getRoleName())) {
|
super.updateById(byId);
|
||||||
throw new BizException(ErrorCode.Business.ROLE_NAME_IS_NOT_UNIQUE, entity.getRoleName());
|
|
||||||
}
|
|
||||||
roleMenuService.cleanOldMenus(List.of(entity.getRoleId()));
|
|
||||||
roleMenuService.saveMenus(entity.getRoleId(), menuIds);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -183,18 +205,22 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
|
|||||||
|
|
||||||
|
|
||||||
//------------------------------
|
//------------------------------
|
||||||
private boolean isRoleNameDuplicated(Long roleId, String roleName) {
|
private void checkRoleNameUnique(Long roleId, String roleName) {
|
||||||
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery(SysRole.class)
|
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery(SysRole.class)
|
||||||
.ne(roleId != null, SysRole::getRoleId, roleId)
|
.ne(roleId != null, SysRole::getRoleId, roleId)
|
||||||
.eq(SysRole::getRoleName, roleName);
|
.eq(SysRole::getRoleName, roleName);
|
||||||
return this.baseMapper.exists(queryWrapper);
|
if (super.exists(queryWrapper)) {
|
||||||
|
throw new BizException(ErrorCode.Business.ROLE_NAME_IS_NOT_UNIQUE, roleName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isRoleKeyDuplicated(Long roleId, String roleKey) {
|
private void checkRoleKeyUnique(Long roleId, String roleKey) {
|
||||||
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery(SysRole.class)
|
LambdaQueryWrapper<SysRole> queryWrapper = Wrappers.lambdaQuery(SysRole.class)
|
||||||
.ne(roleId != null, SysRole::getRoleId, roleId)
|
.ne(roleId != null, SysRole::getRoleId, roleId)
|
||||||
.eq(SysRole::getRoleKey, roleKey);
|
.eq(SysRole::getRoleKey, roleKey);
|
||||||
return this.baseMapper.exists(queryWrapper);
|
if (super.exists(queryWrapper)) {
|
||||||
|
throw new BizException(ErrorCode.Business.ROLE_KEY_IS_NOT_UNIQUE, roleKey);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String generateDeptIdSet(List<Long> deptIds) {
|
private String generateDeptIdSet(List<Long> deptIds) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user