Explorar el Código

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

tags/V1.3.3
xuziqing hace 1 año
padre
commit
219293af31
Se han modificado 1 ficheros con 35 adiciones y 19 borrados
  1. +35
    -19
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/role/RoleServiceImpl.java

+ 35
- 19
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/role/RoleServiceImpl.java Ver fichero

@@ -7,7 +7,10 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
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.enums.MarkEnum;
import com.tuoheng.admin.enums.code.role.RoleDeleteEnum;
@@ -65,7 +68,6 @@ public class RoleServiceImpl implements IRoleService {


/**
*
* 2023-01-11 此处角色先不区分租户的概念,整个系统就3个角色,后期调整
*
* @param roleQuery
@@ -85,7 +87,7 @@ public class RoleServiceImpl implements IRoleService {
queryWrapper.eq("mark", MarkEnum.VALID.getCode());
//queryWrapper.orderByAsc("sort");
queryWrapper.orderByAsc("create_time");
queryWrapper.ne("id", "1");
//queryWrapper.ne("id", "1");
// 查询分页数据
IPage<Role> pageData = roleMapper.selectPage(page, queryWrapper);
pageData.convert(x -> {
@@ -124,19 +126,19 @@ public class RoleServiceImpl implements IRoleService {
entity.setCreateTime(DateUtils.now());
entity.setTenantId(CurrentUserUtil.getTenantId());
}
if(entity == null){
if (entity == null) {
return JsonResult.error("实体对象不存在");
}
if(entity.getId() !=null && entity.getId()>0){
if (entity.getId() != null && entity.getId() > 0) {
//修改记录
int i = roleMapper.updateById(entity);
if(i<=0){
if (i <= 0) {
return JsonResult.error();
}
}else {
} else {
//新增记录
int count = roleMapper.insert(entity);
if(count<=0){
if (count <= 0) {
return JsonResult.error();
}
}
@@ -146,20 +148,20 @@ public class RoleServiceImpl implements IRoleService {
@Override
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查询是否关联的有用户
for (Integer roleId : roleIds) {
List<User> userList = userMapper.selectList(Wrappers.<User>lambdaQuery()
.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("该角色已经绑定用户,不能删除");
}
Role role = roleMapper.selectById(roleId);
role.setMark(MarkEnum.NOTVALID.getCode());
int result = roleMapper.updateById(role);
if(result<=0){
if (result <= 0) {
return JsonResult.error();
}
}
@@ -208,6 +210,7 @@ public class RoleServiceImpl implements IRoleService {

/**
* 获取菜单列表
*
* @param query
* @return
*/
@@ -220,14 +223,14 @@ public class RoleServiceImpl implements IRoleService {
.eq(Menu::getStatus, 1)
.eq(StringUtils.isNotEmpty(query.getClientId()), Menu::getClientId, query.getClientId())
.orderByAsc(Menu::getSort));
if(!menuList.isEmpty()){
if (!menuList.isEmpty()) {
// 获取角色菜单列表
QueryWrapper<RoleMenu> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("role_id", roleId);
queryWrapper.select("menu_id");
List<RoleMenu> roleMenus = roleMenuMapper.selectList(queryWrapper);
List<Integer> menuIds = roleMenus.stream().map(p -> p.getMenuId()).collect(Collectors.toList());
menuList.forEach(item->{
menuList.forEach(item -> {
if (menuIds.contains(item.getId())) {
item.setChecked(true);
item.setOpen(true);
@@ -246,7 +249,7 @@ public class RoleServiceImpl implements IRoleService {
List<OpPermissions> permissions = opPermissionsMapper.selectList(Wrappers.<OpPermissions>lambdaQuery()
.eq(OpPermissions::getMark, MarkEnum.VALID.getCode())
.eq(StringUtils.isNotEmpty(query.getClientId()), OpPermissions::getClientId, query.getClientId()));
if(!permissions.isEmpty()){
if (!permissions.isEmpty()) {
//获取角色菜单列表
QueryWrapper<OpRolePermission> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("role_id", roleId);
@@ -315,10 +318,10 @@ public class RoleServiceImpl implements IRoleService {
}
}
// 批量插入角色菜单关系数据
roleMenuList.forEach(item->{
roleMenuList.forEach(item -> {
roleMenuMapper.insert(item);
});
permissions.forEach(item->{
permissions.forEach(item -> {
opRolePermissionMapper.insert(item);
});
return JsonResult.success("权限保存成功");
@@ -326,6 +329,7 @@ public class RoleServiceImpl implements IRoleService {

/**
* 初始化租户固定角色
*
* @param ids
* @return
*/
@@ -344,12 +348,24 @@ public class RoleServiceImpl implements IRoleService {
}
return JsonResult.success();
}

@Override
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()
.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);
}


Cargando…
Cancelar
Guardar