ソースを参照

更新oidc创建租户相关逻辑

pull/381/head
xiaoying 10ヶ月前
コミット
9e755564c1
3個のファイルの変更87行の追加52行の削除
  1. +4
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Tenant.java
  2. +3
    -0
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/User.java
  3. +80
    -52
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/AddOidcTenantService.java

+ 4
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/Tenant.java ファイルの表示

@@ -1,5 +1,6 @@
package com.tuoheng.admin.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.tuoheng.common.core.common.BaseEntity;
import lombok.Data;
@@ -128,4 +129,7 @@ public class Tenant extends BaseEntity implements Serializable {
*/
private String portraitUrl;

@TableField(exist = false)
private Integer flag;

}

+ 3
- 0
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/entity/User.java ファイルの表示

@@ -231,4 +231,7 @@ public class User implements Serializable {
* 数据权限:1:查看所有部门数据;2:查看本部门及子部门;3:查看本部门数据;
*/
private Integer dataPermission;

@TableField(exist = false)
private Integer flag;
}

+ 80
- 52
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/AddOidcTenantService.java ファイルの表示

@@ -8,8 +8,8 @@ import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.ClientEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.enums.DataPermissionEnum;
import com.tuoheng.admin.enums.MarkEnum;
import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.mapper.UserMapper;
@@ -58,14 +58,14 @@ public class AddOidcTenantService {
// return result;
//}

result = this.addTenant(tenant);
result = this.editTenant(tenant);
if (0 != result.getCode()) {
log.info("创建租户业务:添加租户失败:{}", result.getMsg());
return result;
}

user.setTenantId(tenant.getId());
result = this.addUser(user);
result = this.editUser(user);
if (0 != result.getCode()) {
log.info("创建租户业务:添加用户失败:{}", result.getMsg());
return result;
@@ -115,28 +115,50 @@ public class AddOidcTenantService {
}

private Tenant buildTenant(CreateOidcTenantRequest request) {
// 创建租户数据
Tenant tenant = new Tenant();
tenant.setCode(request.getTenantCode());
tenant.setUsername(request.getUsername());
tenant.setName(request.getTenantName());
Tenant tenant = tenantMapper.selectOne(Wrappers.<Tenant>lambdaQuery().eq(Tenant::getUsername, request.getUsername()));
if (ObjectUtil.isEmpty(tenant)) {
// 创建租户数据
tenant = new Tenant();
tenant.setCode(request.getTenantCode());
tenant.setUsername(request.getUsername());
tenant.setName(request.getTenantName());
tenant.setProvinceCode(request.getProvinceCode());
tenant.setProvinceName(request.getProvinceName());
tenant.setDistrictCode(request.getDistrictCode());
tenant.setDistrictName(request.getDistrictName());
tenant.setCityCode(request.getCityCode());
tenant.setCityName(request.getCityName());
tenant.setFlag(1);
return tenant;
}
tenant.setProvinceCode(request.getProvinceCode());
tenant.setProvinceName(request.getProvinceName());
tenant.setDistrictCode(request.getDistrictCode());
tenant.setDistrictName(request.getDistrictName());
tenant.setCityCode(request.getCityCode());
tenant.setCityName(request.getCityName());
tenant.setFlag(0);
return tenant;
}

/**
* 添加租户
*/
private JsonResult addTenant(Tenant tenant) {
Integer count = tenantMapper.insert(tenant);
if (count <= 0) {
log.info("创建租户失败");
JsonResult.error("创建租户失败");
private JsonResult editTenant(Tenant tenant) {

if (1 == tenant.getFlag()) {
Integer count = tenantMapper.insert(tenant);
if (count <= 0) {
log.info("创建租户失败");
JsonResult.error("创建租户失败");
}
} else if (0 == tenant.getFlag()) {
tenant.setMark(1);
Integer count = tenantMapper.updateById(tenant);
if (count <= 0) {
log.info("更新租户失败");
JsonResult.error("更新租户失败");
}
}
return JsonResult.success(tenant);
}
@@ -145,28 +167,41 @@ public class AddOidcTenantService {
* 构建实体字段数据
*/
private User buildUser(CreateOidcTenantRequest request) {
// 创建用户数据
User user = new User();
user.setCode(request.getTenantCode());
user.setUsername(request.getUsername());
user.setRealname(request.getTenantName());
user.setNickname(request.getTenantName());
user.setPassword(CommonUtils.password(request.getPassword()));
user.setProvinceCode(request.getProvinceCode());
user.setCityCode(request.getCityCode());
user.setCityName(request.getCityName());
user.setDistrictCode(request.getDistrictCode());
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png");
User user = userMapper.selectOne(Wrappers.<User>lambdaQuery().eq(User::getUsername, request.getUsername()));
if (ObjectUtil.isEmpty(user)) {
// 创建用户数据
user = new User();
user.setCode(request.getTenantCode());
user.setUsername(request.getUsername());
user.setRealname(request.getTenantName());
user.setNickname(request.getTenantName());
user.setPassword(CommonUtils.password(request.getPassword()));
user.setProvinceCode(request.getProvinceCode());
user.setCityCode(request.getCityCode());
user.setCityName(request.getCityName());
user.setDistrictCode(request.getDistrictCode());
user.setAvatar("imagedir/n1o1j9ndau_1670488066287.png");
for (ClientRoleDto clientRoleDto : request.getClientRoleDtoList()) {
log.info("请求参数:{}", clientRoleDto);
if (clientRoleDto.getClientId().contains("waterway")) {
user.setRoleId(clientRoleDto.getRoleId());
user.setClientId("1,2");
}
}
user.setDeptId("");
user.setStatus(1);
user.setCreateTime(DateUtils.now());
user.setFlag(1);
return user;
}
for (ClientRoleDto clientRoleDto : request.getClientRoleDtoList()) {
log.info("请求参数:{}", clientRoleDto);
if (clientRoleDto.getClientId().contains("freeway")) {
if (clientRoleDto.getClientId().contains("waterway")) {
user.setRoleId(clientRoleDto.getRoleId());
user.setClientId("1,2");
user.setClientId(clientRoleDto.getClientId());
}
}
user.setDeptId("");
user.setStatus(1);
user.setCreateTime(DateUtils.now());
user.setFlag(0);
return user;
}

@@ -192,28 +227,21 @@ public class AddOidcTenantService {
/**
* 添加用户
*/
private JsonResult 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.isNotNull(userTmp)) {
log.info("创建租户用户,用户已存在,username:{}", user.getUsername());
return JsonResult.error("创建租户用户,用户已存在");
}

// 如果顶级部门存在,将该超级管理员与顶级部门关联
// Dept dept = deptMapper.selectOne(Wrappers.<Dept>lambdaQuery()
// .eq(Dept::getMark, 1)
// .eq(Dept::getTenantId, user.getTenantId())
// .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());
return JsonResult.error("创建租户用户失败");
private JsonResult editUser(User user) {
if (1 == user.getFlag()) {
Integer rowCount = userMapper.insert(user);
if (rowCount <= 0) {
log.info("创建租户用户失败,username:{}", user.getUsername());
return JsonResult.error("创建租户用户失败");
}
} else if (0 == user.getFlag()) {
user.setMark(1);
Integer rowCount = userMapper.updateById(user);
if (rowCount <= 0) {
log.info("更新用户失败,username:{}", user.getUsername());
return JsonResult.error("更新用户失败");
}

}
return JsonResult.success();
}

読み込み中…
キャンセル
保存