Browse Source

🎉 优化租户逻辑

test
smallchill 5 years ago
parent
commit
73745a1745
  1. 20
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

20
blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

@ -26,12 +26,8 @@ import org.springblade.core.tool.api.R;
import org.springblade.core.tool.constant.BladeConstant;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.entity.*;
import org.springblade.system.mapper.DeptMapper;
import org.springblade.system.mapper.MenuMapper;
import org.springblade.system.mapper.RoleMapper;
import org.springblade.system.mapper.TenantMapper;
import org.springblade.system.service.IRoleMenuService;
import org.springblade.system.service.ITenantService;
import org.springblade.system.service.*;
import org.springblade.system.user.entity.User;
import org.springblade.system.user.feign.IUserClient;
import org.springframework.stereotype.Service;
@ -50,9 +46,9 @@ import java.util.stream.Collectors;
public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> implements ITenantService {
private final TenantId tenantId;
private final RoleMapper roleMapper;
private final MenuMapper menuMapper;
private final DeptMapper deptMapper;
private final IRoleService roleService;
private final IMenuService menuService;
private final IDeptService deptService;
private final IRoleMenuService roleMenuService;
private final IUserClient userClient;
@ -90,7 +86,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
role.setRoleAlias("admin");
role.setSort(2);
role.setIsDeleted(0);
roleMapper.insert(role);
roleService.save(role);
// 新建租户对应的角色菜单权限
LinkedList<Menu> userMenus = new LinkedList<>();
List<Menu> menus = getMenus(menuCodes, userMenus);
@ -112,7 +108,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
dept.setDeptCategory(1);
dept.setSort(2);
dept.setIsDeleted(0);
deptMapper.insert(dept);
deptService.save(dept);
// 新建租户对应的默认管理用户
User user = new User();
user.setTenantId(tenantId);
@ -143,7 +139,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
private List<Menu> getMenus(List<String> codes, LinkedList<Menu> menus) {
codes.forEach(code -> {
Menu menu = menuMapper.selectOne(Wrappers.<Menu>query().lambda().eq(Menu::getCode, code).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
Menu menu = menuService.getOne(Wrappers.<Menu>query().lambda().eq(Menu::getCode, code).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
menus.add(menu);
recursion(menu.getId(), menus);
});
@ -151,7 +147,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
}
private void recursion(Long parentId, LinkedList<Menu> menus) {
List<Menu> menuList = menuMapper.selectList(Wrappers.<Menu>query().lambda().eq(Menu::getParentId, parentId).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
List<Menu> menuList = menuService.list(Wrappers.<Menu>query().lambda().eq(Menu::getParentId, parentId).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED));
menus.addAll(menuList);
menuList.forEach(menu -> recursion(menu.getId(), menus));
}

Loading…
Cancel
Save