|
|
|
|
|
|
|
|
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.tuoheng.admin.dto.*; |
|
|
|
|
|
|
|
|
import com.tuoheng.admin.dto.MenuVo; |
|
|
|
|
|
import com.tuoheng.admin.dto.OpPermissionsVo; |
|
|
|
|
|
import com.tuoheng.admin.dto.RoleMenuDto; |
|
|
|
|
|
import com.tuoheng.admin.dto.RoleMenuPermissionDto; |
|
|
import com.tuoheng.admin.entity.*; |
|
|
import com.tuoheng.admin.entity.*; |
|
|
import com.tuoheng.admin.enums.MarkEnum; |
|
|
import com.tuoheng.admin.enums.MarkEnum; |
|
|
import com.tuoheng.admin.enums.code.role.RoleDeleteEnum; |
|
|
import com.tuoheng.admin.enums.code.role.RoleDeleteEnum; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* |
|
|
|
|
|
* 2023-01-11 此处角色先不区分租户的概念,整个系统就3个角色,后期调整 |
|
|
* 2023-01-11 此处角色先不区分租户的概念,整个系统就3个角色,后期调整 |
|
|
* |
|
|
* |
|
|
* @param roleQuery |
|
|
* @param roleQuery |
|
|
|
|
|
|
|
|
queryWrapper.eq("mark", MarkEnum.VALID.getCode()); |
|
|
queryWrapper.eq("mark", MarkEnum.VALID.getCode()); |
|
|
//queryWrapper.orderByAsc("sort"); |
|
|
//queryWrapper.orderByAsc("sort"); |
|
|
queryWrapper.orderByAsc("create_time"); |
|
|
queryWrapper.orderByAsc("create_time"); |
|
|
queryWrapper.ne("id", "1"); |
|
|
|
|
|
|
|
|
//queryWrapper.ne("id", "1"); |
|
|
// 查询分页数据 |
|
|
// 查询分页数据 |
|
|
IPage<Role> pageData = roleMapper.selectPage(page, queryWrapper); |
|
|
IPage<Role> pageData = roleMapper.selectPage(page, queryWrapper); |
|
|
pageData.convert(x -> { |
|
|
pageData.convert(x -> { |
|
|
|
|
|
|
|
|
entity.setCreateTime(DateUtils.now()); |
|
|
entity.setCreateTime(DateUtils.now()); |
|
|
entity.setTenantId(CurrentUserUtil.getTenantId()); |
|
|
entity.setTenantId(CurrentUserUtil.getTenantId()); |
|
|
} |
|
|
} |
|
|
if(entity == null){ |
|
|
|
|
|
|
|
|
if (entity == null) { |
|
|
return JsonResult.error("实体对象不存在"); |
|
|
return JsonResult.error("实体对象不存在"); |
|
|
} |
|
|
} |
|
|
if(entity.getId() !=null && entity.getId()>0){ |
|
|
|
|
|
|
|
|
if (entity.getId() != null && entity.getId() > 0) { |
|
|
//修改记录 |
|
|
//修改记录 |
|
|
int i = roleMapper.updateById(entity); |
|
|
int i = roleMapper.updateById(entity); |
|
|
if(i<=0){ |
|
|
|
|
|
|
|
|
if (i <= 0) { |
|
|
return JsonResult.error(); |
|
|
return JsonResult.error(); |
|
|
} |
|
|
} |
|
|
}else { |
|
|
|
|
|
|
|
|
} else { |
|
|
//新增记录 |
|
|
//新增记录 |
|
|
int count = roleMapper.insert(entity); |
|
|
int count = roleMapper.insert(entity); |
|
|
if(count<=0){ |
|
|
|
|
|
|
|
|
if (count <= 0) { |
|
|
return JsonResult.error(); |
|
|
return JsonResult.error(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JsonResult deleteByList(Integer[] roleIds) { |
|
|
public JsonResult deleteByList(Integer[] roleIds) { |
|
|
//校验 |
|
|
//校验 |
|
|
if(null == roleIds){ |
|
|
|
|
|
return JsonResult.error(RoleDeleteEnum.ROLE_ID_IS_NULL.getCode(),RoleDeleteEnum.ROLE_ID_IS_NULL.getMsg()); |
|
|
|
|
|
|
|
|
if (null == roleIds) { |
|
|
|
|
|
return JsonResult.error(RoleDeleteEnum.ROLE_ID_IS_NULL.getCode(), RoleDeleteEnum.ROLE_ID_IS_NULL.getMsg()); |
|
|
} |
|
|
} |
|
|
//根据roleId查询是否关联的有用户 |
|
|
//根据roleId查询是否关联的有用户 |
|
|
for (Integer roleId : roleIds) { |
|
|
for (Integer roleId : roleIds) { |
|
|
List<User> userList = userMapper.selectList(Wrappers.<User>lambdaQuery() |
|
|
List<User> userList = userMapper.selectList(Wrappers.<User>lambdaQuery() |
|
|
.eq(User::getMark, MarkEnum.VALID.getCode()).eq(User::getRoleId, roleId)); |
|
|
.eq(User::getMark, MarkEnum.VALID.getCode()).eq(User::getRoleId, roleId)); |
|
|
if(userList.size()>0 && StringUtils.isNotEmpty(userList)){ |
|
|
|
|
|
|
|
|
if (userList.size() > 0 && StringUtils.isNotEmpty(userList)) { |
|
|
return JsonResult.error("该角色已经绑定用户,不能删除"); |
|
|
return JsonResult.error("该角色已经绑定用户,不能删除"); |
|
|
} |
|
|
} |
|
|
Role role = roleMapper.selectById(roleId); |
|
|
Role role = roleMapper.selectById(roleId); |
|
|
role.setMark(MarkEnum.NOTVALID.getCode()); |
|
|
role.setMark(MarkEnum.NOTVALID.getCode()); |
|
|
int result = roleMapper.updateById(role); |
|
|
int result = roleMapper.updateById(role); |
|
|
if(result<=0){ |
|
|
|
|
|
|
|
|
if (result <= 0) { |
|
|
return JsonResult.error(); |
|
|
return JsonResult.error(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 获取菜单列表 |
|
|
* 获取菜单列表 |
|
|
|
|
|
* |
|
|
* @param query |
|
|
* @param query |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
.eq(Menu::getStatus, 1) |
|
|
.eq(Menu::getStatus, 1) |
|
|
.eq(StringUtils.isNotEmpty(query.getClientId()), Menu::getClientId, query.getClientId()) |
|
|
.eq(StringUtils.isNotEmpty(query.getClientId()), Menu::getClientId, query.getClientId()) |
|
|
.orderByAsc(Menu::getSort)); |
|
|
.orderByAsc(Menu::getSort)); |
|
|
if(!menuList.isEmpty()){ |
|
|
|
|
|
|
|
|
if (!menuList.isEmpty()) { |
|
|
// 获取角色菜单列表 |
|
|
// 获取角色菜单列表 |
|
|
QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>(); |
|
|
QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>(); |
|
|
queryWrapper.eq("role_id", roleId); |
|
|
queryWrapper.eq("role_id", roleId); |
|
|
queryWrapper.select("menu_id"); |
|
|
queryWrapper.select("menu_id"); |
|
|
List<RoleMenu> roleMenus = roleMenuMapper.selectList(queryWrapper); |
|
|
List<RoleMenu> roleMenus = roleMenuMapper.selectList(queryWrapper); |
|
|
List<Integer> menuIds = roleMenus.stream().map(p -> p.getMenuId()).collect(Collectors.toList()); |
|
|
List<Integer> menuIds = roleMenus.stream().map(p -> p.getMenuId()).collect(Collectors.toList()); |
|
|
menuList.forEach(item->{ |
|
|
|
|
|
|
|
|
menuList.forEach(item -> { |
|
|
if (menuIds.contains(item.getId())) { |
|
|
if (menuIds.contains(item.getId())) { |
|
|
item.setChecked(true); |
|
|
item.setChecked(true); |
|
|
item.setOpen(true); |
|
|
item.setOpen(true); |
|
|
|
|
|
|
|
|
List<OpPermissions> permissions = opPermissionsMapper.selectList(Wrappers.<OpPermissions>lambdaQuery() |
|
|
List<OpPermissions> permissions = opPermissionsMapper.selectList(Wrappers.<OpPermissions>lambdaQuery() |
|
|
.eq(OpPermissions::getMark, MarkEnum.VALID.getCode()) |
|
|
.eq(OpPermissions::getMark, MarkEnum.VALID.getCode()) |
|
|
.eq(StringUtils.isNotEmpty(query.getClientId()), OpPermissions::getClientId, query.getClientId())); |
|
|
.eq(StringUtils.isNotEmpty(query.getClientId()), OpPermissions::getClientId, query.getClientId())); |
|
|
if(!permissions.isEmpty()){ |
|
|
|
|
|
|
|
|
if (!permissions.isEmpty()) { |
|
|
//获取角色菜单列表 |
|
|
//获取角色菜单列表 |
|
|
QueryWrapper<OpRolePermission> queryWrapper = new QueryWrapper<>(); |
|
|
QueryWrapper<OpRolePermission> queryWrapper = new QueryWrapper<>(); |
|
|
queryWrapper.eq("role_id", roleId); |
|
|
queryWrapper.eq("role_id", roleId); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
// 批量插入角色菜单关系数据 |
|
|
// 批量插入角色菜单关系数据 |
|
|
roleMenuList.forEach(item->{ |
|
|
|
|
|
|
|
|
roleMenuList.forEach(item -> { |
|
|
roleMenuMapper.insert(item); |
|
|
roleMenuMapper.insert(item); |
|
|
}); |
|
|
}); |
|
|
permissions.forEach(item->{ |
|
|
|
|
|
|
|
|
permissions.forEach(item -> { |
|
|
opRolePermissionMapper.insert(item); |
|
|
opRolePermissionMapper.insert(item); |
|
|
}); |
|
|
}); |
|
|
return JsonResult.success("权限保存成功"); |
|
|
return JsonResult.success("权限保存成功"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 初始化租户固定角色 |
|
|
* 初始化租户固定角色 |
|
|
|
|
|
* |
|
|
* @param ids |
|
|
* @param ids |
|
|
* @return |
|
|
* @return |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
return JsonResult.success(); |
|
|
return JsonResult.success(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public JsonResult getRoles() { |
|
|
public JsonResult getRoles() { |
|
|
|
|
|
|
|
|
|
|
|
//超管 |
|
|
|
|
|
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, "superAdmin").eq(User::getMark, 1)); |
|
|
|
|
|
if (StringUtils.isNull(user)) { |
|
|
|
|
|
List<Role> roles = roleMapper.selectList(Wrappers.<Role>lambdaQuery() |
|
|
|
|
|
.eq(Role::getCode, "superAdmin") |
|
|
|
|
|
.eq(Role::getMark, 1) |
|
|
|
|
|
.eq(Role::getStatus, 1)); |
|
|
|
|
|
return JsonResult.success(roles); |
|
|
|
|
|
} |
|
|
|
|
|
//对应的租户角色 |
|
|
List<Role> roles = roleMapper.selectList(Wrappers.<Role>lambdaQuery() |
|
|
List<Role> roles = roleMapper.selectList(Wrappers.<Role>lambdaQuery() |
|
|
.eq(Role::getMark, MarkEnum.VALID.getCode()).eq(Role::getStatus, 1)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.eq(Role::getTenantId, user.getTenantId()) |
|
|
|
|
|
.eq(Role::getMark, 1) |
|
|
|
|
|
.eq(Role::getStatus, 1)); |
|
|
return JsonResult.success(roles); |
|
|
return JsonResult.success(roles); |
|
|
} |
|
|
} |
|
|
|
|
|
|