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

Loading…
Cancel
Save