|
|
@@ -1,11 +1,34 @@ |
|
|
|
package com.tuoheng.admin.service.role; |
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.convert.Convert; |
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
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.UserRoleDto; |
|
|
|
import com.tuoheng.admin.entity.OpRolePermission; |
|
|
|
import com.tuoheng.admin.entity.Role; |
|
|
|
import com.tuoheng.admin.entity.RoleMenu; |
|
|
|
import com.tuoheng.admin.mapper.OpRolePermissionMapper; |
|
|
|
import com.tuoheng.admin.mapper.RoleMapper; |
|
|
|
import com.tuoheng.admin.mapper.RoleMenuMapper; |
|
|
|
import com.tuoheng.admin.mapper.UserRoleMapper; |
|
|
|
import com.tuoheng.admin.query.RoleClientQuery; |
|
|
|
import com.tuoheng.admin.query.RoleQuery; |
|
|
|
import com.tuoheng.admin.utils.CurrentUserUtil; |
|
|
|
import com.tuoheng.admin.vo.RoleListVo; |
|
|
|
import com.tuoheng.common.core.common.BaseServiceImpl; |
|
|
|
import com.tuoheng.common.core.utils.DateUtils; |
|
|
|
import com.tuoheng.common.core.utils.JsonResult; |
|
|
|
import com.tuoheng.common.core.utils.StringUtils; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.stream.Collectors; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* @Author ChengWang |
|
|
@@ -14,4 +37,157 @@ import org.springframework.stereotype.Service; |
|
|
|
@Service |
|
|
|
public class RoleServiceImpl implements IRoleService { |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RoleMapper roleMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private RoleMenuMapper roleMenuMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private OpRolePermissionMapper opRolePermissionMapper; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private UserRoleMapper userRoleMapper; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult getRoleList(RoleQuery roleQuery) { |
|
|
|
IPage<Role> page = new Page<>(roleQuery.getPage(), roleQuery.getLimit()); |
|
|
|
// 查询条件 |
|
|
|
QueryWrapper<Role> queryWrapper = new QueryWrapper<>(); |
|
|
|
// 租户ID |
|
|
|
queryWrapper.eq("tenant_id", CurrentUserUtil.getTenantId()); |
|
|
|
// 角色名称 |
|
|
|
if (!StringUtils.isEmpty(roleQuery.getRoleName())) { |
|
|
|
queryWrapper.like("role_name", roleQuery.getRoleName()); |
|
|
|
} |
|
|
|
queryWrapper.eq("mark", 1); |
|
|
|
//queryWrapper.orderByAsc("sort"); |
|
|
|
queryWrapper.orderByAsc("create_time"); |
|
|
|
queryWrapper.ne("code", "super"); |
|
|
|
// 查询分页数据 |
|
|
|
IPage<Role> pageData = roleMapper.selectPage(page, queryWrapper); |
|
|
|
pageData.convert(x -> { |
|
|
|
RoleListVo roleListVo = Convert.convert(RoleListVo.class, x); |
|
|
|
// TODO... |
|
|
|
return roleListVo; |
|
|
|
}); |
|
|
|
return JsonResult.success(pageData); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult editRole(Role entity) { |
|
|
|
if (StringUtils.isNotNull(entity.getId()) && entity.getId() > 0) { |
|
|
|
// 更新 |
|
|
|
Integer count = roleMapper.selectCount(new LambdaQueryWrapper<Role>() |
|
|
|
.ne(Role::getId, entity.getId()) |
|
|
|
.eq(Role::getTenantId, CurrentUserUtil.getTenantId()) |
|
|
|
.eq(Role::getCode, entity.getCode()) |
|
|
|
.eq(Role::getMark, 1)); |
|
|
|
//当前用户 |
|
|
|
entity.setUpdateUser(CurrentUserUtil.getUserId()); |
|
|
|
entity.setUpdateTime(DateUtils.now()); |
|
|
|
if (count > 0) { |
|
|
|
return JsonResult.error("系统中已存在相同的角色编码"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
// 添加 |
|
|
|
Integer count = roleMapper.selectCount(new LambdaQueryWrapper<Role>() |
|
|
|
.eq(Role::getTenantId, CurrentUserUtil.getTenantId()) |
|
|
|
.eq(Role::getCode, entity.getCode()) |
|
|
|
.eq(Role::getMark, 1)); |
|
|
|
if (count > 0) { |
|
|
|
return JsonResult.error("系统中已存在相同的角色编码"); |
|
|
|
} |
|
|
|
entity.setCreateUser(CurrentUserUtil.getUserId()); |
|
|
|
entity.setCreateTime(DateUtils.now()); |
|
|
|
entity.setTenantId(CurrentUserUtil.getTenantId()); |
|
|
|
} |
|
|
|
if(entity == null){ |
|
|
|
return JsonResult.error("实体对象不存在"); |
|
|
|
} |
|
|
|
if(entity.getId() !=null && entity.getId()>0){ |
|
|
|
//修改记录 |
|
|
|
int i = roleMapper.updateById(entity); |
|
|
|
if(i<=0){ |
|
|
|
return JsonResult.error(); |
|
|
|
} |
|
|
|
}else { |
|
|
|
//新增记录 |
|
|
|
int count = roleMapper.insert(entity); |
|
|
|
if(count<=0){ |
|
|
|
return JsonResult.error(); |
|
|
|
} |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult deleteByList(Integer[] roleIds) { |
|
|
|
List<Role> roles = roleMapper.selectList(Wrappers.<Role>lambdaQuery().eq(Role::getStatus, 1).eq(Role::getMark, 1).eq(Role::getTenantId, CurrentUserUtil.getTenantId())); |
|
|
|
// |
|
|
|
List<Integer> collect = roles.stream().filter(t -> !t.getCode().equals("001")) |
|
|
|
.filter(t -> t.getCode().equals("002")) |
|
|
|
.filter(t -> t.getCode().equals("003")).map(t -> t.getId()).collect(Collectors.toList()); |
|
|
|
if (collect.contains(roleIds)) { |
|
|
|
return JsonResult.error("初始化配置角色不能删除"); |
|
|
|
} |
|
|
|
for (Integer roleId : roleIds) { |
|
|
|
List<RoleMenu> roleMenus = roleMenuMapper.selectList(Wrappers.<RoleMenu>lambdaQuery().eq(RoleMenu::getRoleId, roleId).eq(RoleMenu::getMark, 1)); |
|
|
|
if (roleMenus.size() > 0 && StringUtils.isNotEmpty(roleMenus)) { |
|
|
|
return JsonResult.error("该角色已配置菜单不能删除!"); |
|
|
|
} |
|
|
|
List<OpRolePermission> opRolePermissionList = opRolePermissionMapper.selectList(Wrappers.<OpRolePermission>lambdaQuery().eq(OpRolePermission::getRoleId,roleId).eq(OpRolePermission::getMark, 1)); |
|
|
|
if (opRolePermissionList.size() > 0 && StringUtils.isNotEmpty(opRolePermissionList)) { |
|
|
|
return JsonResult.error("该角色已配置权限不能删除!"); |
|
|
|
} |
|
|
|
List<UserRoleDto> userRoles = userRoleMapper.getListByRoleId(roleId, CurrentUserUtil.getTenantId()); |
|
|
|
if (userRoles.size() > 0 && StringUtils.isNotEmpty(userRoles)) { |
|
|
|
return JsonResult.error("该角色已经分配用户不能删除!"); |
|
|
|
} |
|
|
|
Role role = roleMapper.selectById(roleId); |
|
|
|
role.setMark(0); |
|
|
|
roleMapper.updateById(role); |
|
|
|
} |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult getRoleLists() { |
|
|
|
QueryWrapper<Role> queryWrapper = new QueryWrapper<>(); |
|
|
|
// 租户ID |
|
|
|
//不展示超管 |
|
|
|
queryWrapper.ne("code", "001"); |
|
|
|
queryWrapper.eq("tenant_id", CurrentUserUtil.getTenantId()); |
|
|
|
queryWrapper.eq("status", 1); |
|
|
|
queryWrapper.eq("mark", 1); |
|
|
|
queryWrapper.orderByAsc("create_time"); |
|
|
|
List<Role> rolesLists = roleMapper.selectList(queryWrapper); |
|
|
|
|
|
|
|
return JsonResult.success(rolesLists); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取菜单列表 |
|
|
|
* @param query |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public JsonResult getMenuList(RoleClientQuery query) { |
|
|
|
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public JsonResult updateStatus(Role entity) { |
|
|
|
Role role = roleMapper.selectById(entity.getId()); |
|
|
|
if (null == role) { |
|
|
|
return JsonResult.error("该角色不存在"); |
|
|
|
} |
|
|
|
role.setStatus(entity.getStatus()); |
|
|
|
roleMapper.updateById(role); |
|
|
|
return JsonResult.success(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |