Browse Source

优化新增租户逻辑,新增时同步超管配置的默认业务字典集

test
smallchill 5 years ago
parent
commit
d73bcf75d3
  1. 2
      blade-service/blade-system/src/main/java/org/springblade/system/controller/TenantController.java
  2. 2
      blade-service/blade-system/src/main/java/org/springblade/system/service/ITenantService.java
  3. 16
      blade-service/blade-system/src/main/java/org/springblade/system/service/impl/TenantServiceImpl.java

2
blade-service/blade-system/src/main/java/org/springblade/system/controller/TenantController.java

@ -123,7 +123,7 @@ public class TenantController extends BladeController {
@PreAuth(RoleConstant.HAS_ROLE_ADMINISTRATOR)
public R submit(@Valid @RequestBody Tenant tenant) {
CacheUtil.clear(SYS_CACHE);
return R.status(tenantService.saveTenant(tenant));
return R.status(tenantService.submitTenant(tenant));
}

2
blade-service/blade-system/src/main/java/org/springblade/system/service/ITenantService.java

@ -52,7 +52,7 @@ public interface ITenantService extends BaseService<Tenant> {
* @param tenant
* @return
*/
boolean saveTenant(Tenant tenant);
boolean submitTenant(Tenant tenant);
/**
* 删除

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

@ -58,6 +58,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
private final IDeptService deptService;
private final IPostService postService;
private final IRoleMenuService roleMenuService;
private final IDictBizService dictBizService;
private final IUserClient userClient;
@Override
@ -72,7 +73,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
@Override
@Transactional(rollbackFor = Exception.class)
public boolean saveTenant(Tenant tenant) {
public boolean submitTenant(Tenant tenant) {
if (Func.isEmpty(tenant.getId())) {
List<Tenant> tenants = baseMapper.selectList(Wrappers.<Tenant>query().lambda().eq(Tenant::getIsDeleted, BladeConstant.DB_NOT_DELETED));
List<String> codes = tenants.stream().map(Tenant::getTenantId).collect(Collectors.toList());
@ -88,7 +89,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
role.setRoleName("管理员");
role.setRoleAlias("admin");
role.setSort(2);
role.setIsDeleted(0);
role.setIsDeleted(BladeConstant.DB_NOT_DELETED);
roleService.save(role);
// 新建租户对应的角色菜单权限
LinkedList<Menu> userMenus = new LinkedList<>();
@ -112,7 +113,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
dept.setFullName(tenant.getTenantName());
dept.setDeptCategory(1);
dept.setSort(2);
dept.setIsDeleted(0);
dept.setIsDeleted(BladeConstant.DB_NOT_DELETED);
deptService.save(dept);
// 新建租户对应的默认岗位
Post post = new Post();
@ -122,6 +123,13 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
post.setPostName("首席执行官");
post.setSort(1);
postService.save(post);
// 新建租户对应的默认业务字典
List<DictBiz> dictBizList = dictBizService.list();
dictBizList.forEach(dictBiz -> {
dictBiz.setId(null);
dictBiz.setTenantId(tenantId);
});
dictBizService.saveBatch(dictBizList);
// 新建租户对应的默认管理用户
User user = new User();
user.setTenantId(tenantId);
@ -136,7 +144,7 @@ public class TenantServiceImpl extends BaseServiceImpl<TenantMapper, Tenant> imp
user.setPostId(String.valueOf(post.getId()));
user.setBirthday(new Date());
user.setSex(1);
user.setIsDeleted(0);
user.setIsDeleted(BladeConstant.DB_NOT_DELETED);
boolean temp = super.saveOrUpdate(tenant);
R<Boolean> result = userClient.saveUser(user);
if (!result.isSuccess()) {

Loading…
Cancel
Save