Browse Source

优化租户新增逻辑,业务字典支持无限层级复制

test
smallchill 4 years ago
parent
commit
01c2a57398
  1. 43
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

43
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<TenantMapper, Tenant> imp
post.setSort(1);
postService.save(post);
// 新建租户对应的默认业务字典
List<DictBiz> dictBizList = dictBizService.list();
dictBizList.forEach(dictBiz -> {
dictBiz.setId(null);
dictBiz.setTenantId(tenantId);
});
LinkedList<DictBiz> dictBizs = new LinkedList<>();
List<DictBiz> dictBizList = getDictBizs(tenantId, dictBizs);
dictBizService.saveBatch(dictBizList);
// 新建租户对应的默认管理用户
User user = new User();
@ -150,6 +149,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> 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<Boolean> result = userClient.saveUser(user);
@ -209,16 +209,43 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
Menu menu = menuService.getOne(Wrappers.<Menu>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<Menu> menus) {
private void recursionMenu(Long parentId, LinkedList<Menu> menus) {
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));
menuList.forEach(menu -> recursionMenu(menu.getId(), menus));
}
private List<DictBiz> getDictBizs(String tenantId, LinkedList<DictBiz> dictBizs) {
List<DictBiz> dictBizList = dictBizService.list(Wrappers.<DictBiz>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<DictBiz> dictBizs) {
List<DictBiz> dictBizList = dictBizService.list(Wrappers.<DictBiz>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);
});
}
}

Loading…
Cancel
Save