diff --git a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java index c187b7c4..858ed3ce 100644 --- a/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java +++ b/blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java @@ -17,6 +17,7 @@ package org.springblade.system.service.impl; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.Wrappers; import lombok.AllArgsConstructor; import org.springblade.core.cache.utils.CacheUtil; @@ -35,6 +36,7 @@ import org.springblade.system.entity.*; import org.springblade.system.mapper.TenantMapper; import org.springblade.system.service.*; import org.springblade.system.user.entity.User; +import org.springblade.system.user.enums.UserEnum; import org.springblade.system.user.feign.IUserClient; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -130,11 +132,8 @@ public class TenantServiceImpl extends BaseServiceImpl imp post.setSort(1); postService.save(post); // 新建租户对应的默认业务字典 - List dictBizList = dictBizService.list(); - dictBizList.forEach(dictBiz -> { - dictBiz.setId(null); - dictBiz.setTenantId(tenantId); - }); + LinkedList dictBizs = new LinkedList<>(); + List dictBizList = getDictBizs(tenantId, dictBizs); dictBizService.saveBatch(dictBizList); // 新建租户对应的默认管理用户 User user = new User(); @@ -150,6 +149,7 @@ public class TenantServiceImpl extends BaseServiceImpl imp user.setPostId(String.valueOf(post.getId())); user.setBirthday(new Date()); user.setSex(1); + user.setUserType(UserEnum.WEB.getCategory()); user.setIsDeleted(BladeConstant.DB_NOT_DELETED); boolean temp = super.saveOrUpdate(tenant); R result = userClient.saveUser(user); @@ -209,16 +209,43 @@ public class TenantServiceImpl extends BaseServiceImpl imp Menu menu = menuService.getOne(Wrappers.query().lambda().eq(Menu::getCode, code).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED)); if (menu != null) { menus.add(menu); - recursion(menu.getId(), menus); + recursionMenu(menu.getId(), menus); } }); return menus; } - private void recursion(Long parentId, LinkedList menus) { + private void recursionMenu(Long parentId, LinkedList menus) { List menuList = menuService.list(Wrappers.query().lambda().eq(Menu::getParentId, parentId).eq(Menu::getIsDeleted, BladeConstant.DB_NOT_DELETED)); menus.addAll(menuList); - menuList.forEach(menu -> recursion(menu.getId(), menus)); + menuList.forEach(menu -> recursionMenu(menu.getId(), menus)); + } + + private List getDictBizs(String tenantId, LinkedList dictBizs) { + List dictBizList = dictBizService.list(Wrappers.query().lambda().eq(DictBiz::getParentId, BladeConstant.TOP_PARENT_ID).eq(DictBiz::getIsDeleted, BladeConstant.DB_NOT_DELETED)); + dictBizList.forEach(dictBiz -> { + Long oldParentId = dictBiz.getId(); + Long newParentId = IdWorker.getId(); + dictBiz.setId(newParentId); + dictBiz.setTenantId(tenantId); + dictBizs.add(dictBiz); + recursionDictBiz(tenantId, oldParentId, newParentId, dictBizs); + }); + return dictBizs; } + private void recursionDictBiz(String tenantId, Long oldParentId, Long newParentId, LinkedList dictBizs) { + List dictBizList = dictBizService.list(Wrappers.query().lambda().eq(DictBiz::getParentId, oldParentId).eq(DictBiz::getIsDeleted, BladeConstant.DB_NOT_DELETED)); + dictBizList.forEach(dictBiz -> { + Long oldSubParentId = dictBiz.getId(); + Long newSubParentId = IdWorker.getId(); + dictBiz.setId(newSubParentId); + dictBiz.setTenantId(tenantId); + dictBiz.setParentId(newParentId); + dictBizs.add(dictBiz); + recursionDictBiz(tenantId, oldSubParentId, newSubParentId, dictBizs); + }); + } + + }