Browse Source

Merge branch 'develop' of gitadmin/tuoheng_freeway into release

tags/v1.0.0^2
wanjing 1 year ago
parent
commit
06f5f9ccc0
1 changed files with 58 additions and 26 deletions
  1. +58
    -26
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/init/SystemUserInitService.java

+ 58
- 26
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/user/init/SystemUserInitService.java View File

@@ -3,9 +3,12 @@ package com.tuoheng.admin.service.user.init;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.admin.constant.SystemConstant;
import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.mapper.DeptMapper;
import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.mapper.UserMapper;
@@ -36,6 +39,9 @@ public class SystemUserInitService {
@Autowired
private RoleMapper roleMapper;

@Autowired
private DeptMapper deptMapper;

@Autowired
private TenantMapper tenantMapper;

@@ -60,7 +66,7 @@ public class SystemUserInitService {
}
User user = this.buildUser(request);
// 添加oidc
result = oidcService.addUser(user, request.getPassword(), tenant);
// result = oidcService.addUser(user, request.getPassword(), tenant);
if (0 != result.getCode()) {
log.info("初始化系统租户用户业务接口:添加oidc数据失败:{}", result.getMsg());
return result;
@@ -76,33 +82,11 @@ public class SystemUserInitService {
log.info("租户不存在,tenantCode:{}", request.getTenantCode());
}
}
Integer rowCount = userMapper.insert(user);
if (rowCount <= 0) {
return JsonResult.error(400, "初始化系统租户用户失败");
}
return JsonResult.success();
}

/**
* 添加租户
*/
private Tenant addTenant(UserInitRequest request) {
// 如果是租户先去创建
Tenant tenant = new Tenant();
tenant.setName(request.getName());
tenant.setUsername(request.getName());
tenant.setCode(request.getTenantCode());
tenant.setAirportUrl(request.getAirportUrl());
user.setTenantId(tenant.getId());
this.addUser(user);

Tenant tenantTmp = tenantMapper.selectOne(Wrappers.<Tenant>lambdaQuery()
.eq(Tenant::getMark, 1)
.eq(Tenant::getStatus, 1)
.eq(Tenant::getName, request.getName())
.eq(Tenant::getCode, request.getTenantCode()));
if (ObjectUtil.isNull(tenantTmp)) {
tenantMapper.insert(tenant);
}
return tenant;
return JsonResult.success();
}

/**
@@ -157,5 +141,53 @@ public class SystemUserInitService {
}
return JsonResult.success();
}
/**
* 添加租户
*/
private Tenant addTenant(UserInitRequest request) {
// 如果是租户先去创建
Tenant tenant = new Tenant();
tenant.setName(request.getName());
tenant.setUsername(request.getName());
tenant.setCode(request.getTenantCode());
tenant.setAirportUrl(request.getAirportUrl());

Tenant tenantTmp = tenantMapper.selectOne(Wrappers.<Tenant>lambdaQuery()
.eq(Tenant::getMark, 1)
.eq(Tenant::getStatus, 1)
.eq(Tenant::getName, request.getName())
.eq(Tenant::getCode, request.getTenantCode()));
if (ObjectUtil.isNull(tenantTmp)) {
tenantMapper.insert(tenant);
return tenant;
} else {
return tenantTmp;
}
}

/**
* 添加用户
*/
private void addUser(User user) {
User userTmp = userMapper.selectOne(Wrappers.<User>lambdaQuery()
.eq(User::getMark, 1)
.eq(User::getStatus, 1)
.eq(User::getUsername, user.getUsername()));
if (ObjectUtil.isNull(userTmp)) {
log.info("初始化系统租户用户,用户已存在,username:{}", user.getUsername());
}

// 如果顶级部门存在,将该超级管理员与顶级部门关联
Dept dept = deptMapper.selectOne(Wrappers.<Dept>lambdaQuery()
.eq(Dept::getMark, 1)
.eq(Dept::getPid, SystemConstant.ROOT_DEPT_PID));
if (ObjectUtil.isNotNull(dept)) {
user.setDeptId(dept.getId());
}
Integer rowCount = userMapper.insert(user);
if (rowCount <= 0) {
log.info("初始化系统租户用户失败,username:{}", user.getUsername());
}
}

}

Loading…
Cancel
Save