修改角色新增修改绑定菜单部门关系
This commit is contained in:
@ -106,7 +106,7 @@ public class RoleController {
|
|||||||
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
throw new BadRequestException("A new "+ ENTITY_NAME +" cannot already have an ID");
|
||||||
}
|
}
|
||||||
getLevels(resources.getLevel());
|
getLevels(resources.getLevel());
|
||||||
return new ResponseEntity<>(roleService.save(resources),HttpStatus.CREATED);
|
return new ResponseEntity<>(roleService.create(resources),HttpStatus.CREATED);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Log("修改角色")
|
@Log("修改角色")
|
||||||
@ -116,7 +116,7 @@ public class RoleController {
|
|||||||
public ResponseEntity<Object> update(@Validated @RequestBody Role resources){
|
public ResponseEntity<Object> update(@Validated @RequestBody Role resources){
|
||||||
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
//if(StrUtil.isNotEmpty("22")) throw new BadRequestException("演示环境禁止操作");
|
||||||
getLevels(resources.getLevel());
|
getLevels(resources.getLevel());
|
||||||
roleService.saveOrUpdate(resources);
|
roleService.update(resources);
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +88,19 @@ public interface RoleService extends BaseService<Role>{
|
|||||||
*/
|
*/
|
||||||
void updateMenu(Role resources, RoleDto roleDto);
|
void updateMenu(Role resources, RoleDto roleDto);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建
|
||||||
|
* @param resources /
|
||||||
|
* @return /
|
||||||
|
*/
|
||||||
|
RoleDto create(Role resources);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 编辑
|
||||||
|
* @param resources /
|
||||||
|
*/
|
||||||
|
void update(Role resources);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户权限信息
|
* 获取用户权限信息
|
||||||
* @param user 用户信息
|
* @param user 用户信息
|
||||||
|
@ -8,12 +8,10 @@
|
|||||||
*/
|
*/
|
||||||
package co.yixiang.modules.system.service.impl;
|
package co.yixiang.modules.system.service.impl;
|
||||||
|
|
||||||
import co.yixiang.modules.system.domain.Dept;
|
import co.yixiang.exception.EntityExistException;
|
||||||
import co.yixiang.modules.system.domain.Menu;
|
import co.yixiang.modules.system.domain.*;
|
||||||
import co.yixiang.modules.system.domain.Role;
|
|
||||||
import co.yixiang.common.service.impl.BaseServiceImpl;
|
import co.yixiang.common.service.impl.BaseServiceImpl;
|
||||||
import co.yixiang.modules.system.service.DeptService;
|
import co.yixiang.modules.system.service.*;
|
||||||
import co.yixiang.modules.system.service.MenuService;
|
|
||||||
import co.yixiang.modules.system.service.dto.RoleSmallDto;
|
import co.yixiang.modules.system.service.dto.RoleSmallDto;
|
||||||
import co.yixiang.modules.system.service.dto.UserDto;
|
import co.yixiang.modules.system.service.dto.UserDto;
|
||||||
import co.yixiang.modules.system.service.mapper.DeptMapper;
|
import co.yixiang.modules.system.service.mapper.DeptMapper;
|
||||||
@ -28,7 +26,6 @@ import com.github.pagehelper.PageInfo;
|
|||||||
import co.yixiang.common.utils.QueryHelpPlus;
|
import co.yixiang.common.utils.QueryHelpPlus;
|
||||||
import co.yixiang.utils.ValidationUtil;
|
import co.yixiang.utils.ValidationUtil;
|
||||||
import co.yixiang.utils.FileUtil;
|
import co.yixiang.utils.FileUtil;
|
||||||
import co.yixiang.modules.system.service.RoleService;
|
|
||||||
import co.yixiang.modules.system.service.dto.RoleDto;
|
import co.yixiang.modules.system.service.dto.RoleDto;
|
||||||
import co.yixiang.modules.system.service.dto.RoleQueryCriteria;
|
import co.yixiang.modules.system.service.dto.RoleQueryCriteria;
|
||||||
import co.yixiang.modules.system.service.mapper.RoleMapper;
|
import co.yixiang.modules.system.service.mapper.RoleMapper;
|
||||||
@ -74,6 +71,8 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
|||||||
private final RoleMapper roleMapper;
|
private final RoleMapper roleMapper;
|
||||||
private final MenuMapper menuMapper;
|
private final MenuMapper menuMapper;
|
||||||
private final DeptMapper deptMapper;
|
private final DeptMapper deptMapper;
|
||||||
|
private final RolesMenusService rolesMenusService;
|
||||||
|
private final RolesDeptsService rolesDeptsService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> queryAll(RoleQueryCriteria criteria, Pageable pageable) {
|
public Map<String, Object> queryAll(RoleQueryCriteria criteria, Pageable pageable) {
|
||||||
@ -174,11 +173,70 @@ public class RoleServiceImpl extends BaseServiceImpl<RoleMapper, Role> implement
|
|||||||
@Override
|
@Override
|
||||||
// @CacheEvict(allEntries = true)
|
// @CacheEvict(allEntries = true)
|
||||||
public void updateMenu(Role resources, RoleDto roleDto) {
|
public void updateMenu(Role resources, RoleDto roleDto) {
|
||||||
Role role =generator.convert(roleDto,Role.class);
|
if(resources.getMenus().size()>0){
|
||||||
role.setMenus(resources.getMenus());
|
List<RolesMenus> rolesMenusList = resources.getMenus().stream().map(i ->{
|
||||||
this.save(role);
|
RolesMenus rolesMenus = new RolesMenus();
|
||||||
|
rolesMenus.setRoleId(resources.getId());
|
||||||
|
rolesMenus.setMenuId(i.getId());
|
||||||
|
return rolesMenus;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
rolesMenusService.saveOrUpdateBatch(rolesMenusList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// @CacheEvict(allEntries = true)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public RoleDto create(Role resources) {
|
||||||
|
if(this.getOne(new QueryWrapper<Role>().lambda().eq(Role::getName,resources.getName())) != null){
|
||||||
|
throw new EntityExistException(Role.class,"username",resources.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if(resources.getDepts().size()>0){
|
||||||
|
List<RolesDepts> rolesDeptsList = resources.getDepts().stream().map(i ->{
|
||||||
|
RolesDepts rolesDepts = new RolesDepts();
|
||||||
|
rolesDepts.setRoleId(resources.getId());
|
||||||
|
rolesDepts.setDeptId(i.getId());
|
||||||
|
return rolesDepts;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
rolesDeptsService.saveBatch(rolesDeptsList);
|
||||||
|
}
|
||||||
|
this.save(resources);
|
||||||
|
return generator.convert(resources,RoleDto.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
// @CacheEvict(allEntries = true)
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
public void update(Role resources) {
|
||||||
|
Role role = this.getById(resources.getId());
|
||||||
|
|
||||||
|
Role role1 = this.getOne(new QueryWrapper<Role>().lambda().eq(Role::getName,resources.getName()));
|
||||||
|
|
||||||
|
if(role1 != null && !role1.getId().equals(role.getId())){
|
||||||
|
throw new EntityExistException(Role.class,"username",resources.getName());
|
||||||
|
}
|
||||||
|
role1 = this.getOne(new QueryWrapper<Role>().lambda().eq(Role::getPermission,resources.getPermission()));
|
||||||
|
if(role1 != null && !role1.getId().equals(role.getId())){
|
||||||
|
throw new EntityExistException(Role.class,"permission",resources.getPermission());
|
||||||
|
}
|
||||||
|
role.setName(resources.getName());
|
||||||
|
role.setRemark(resources.getRemark());
|
||||||
|
role.setDataScope(resources.getDataScope());
|
||||||
|
if(resources.getDepts().size()>0){
|
||||||
|
List<RolesDepts> rolesDeptsList = resources.getDepts().stream().map(i ->{
|
||||||
|
RolesDepts rolesDepts = new RolesDepts();
|
||||||
|
rolesDepts.setRoleId(resources.getId());
|
||||||
|
rolesDepts.setDeptId(i.getId());
|
||||||
|
return rolesDepts;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
rolesDeptsService.saveOrUpdateBatch(rolesDeptsList);
|
||||||
|
}
|
||||||
|
role.setLevel(resources.getLevel());
|
||||||
|
role.setPermission(resources.getPermission());
|
||||||
|
this.saveOrUpdate(role);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取用户权限信息
|
* 获取用户权限信息
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user