Browse Source

1、修改oidc创建租户接口;2、修改oidc修改租户接口;

tags/v1.2.0^2
wanjing 1 year ago
parent
commit
759900d2cd
2 changed files with 52 additions and 37 deletions
  1. +24
    -21
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/AddOidcTenantService.java
  2. +28
    -16
      tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/EditOidcTenantService.java

+ 24
- 21
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/AddOidcTenantService.java View File

@@ -3,6 +3,8 @@ package com.tuoheng.admin.service.third.oidc;
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.dto.ClientRoleDto;
import com.tuoheng.admin.entity.Role;
import com.tuoheng.admin.entity.Tenant;
import com.tuoheng.admin.entity.User;
@@ -13,14 +15,17 @@ import com.tuoheng.admin.mapper.RoleMapper;
import com.tuoheng.admin.mapper.TenantMapper;
import com.tuoheng.admin.mapper.UserMapper;
import com.tuoheng.admin.request.third.oidc.CreateOidcTenantRequest;
import com.tuoheng.admin.request.user.UserInitRequest;
import com.tuoheng.common.core.utils.CommonUtils;
import com.tuoheng.common.core.utils.DateUtils;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

@Slf4j
@Service
@@ -47,28 +52,28 @@ public class AddOidcTenantService {
return result;
}

Tenant tenant = this.buildTenant(request);
User user = this.buildUser(request);

// 添加oidc
result = addOidcUserService.add(user, request.getPassword(), null);
result = addOidcUserService.add(user, request.getPassword(), tenant);
if (0 != result.getCode()) {
log.info("创建租户业务:添加oidc数据失败:{}", result.getMsg());
return result;
}

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

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

return JsonResult.success();
}

@@ -94,8 +99,8 @@ public class AddOidcTenantService {
return JsonResult.error(400, "租户编号");
}
Integer count = tenantMapper.selectCount(new LambdaQueryWrapper<Tenant>()
.eq(Tenant::getUsername, request.getUsername())
.eq(Tenant::getMark, MarkEnum.VALID.getCode()));
.eq(Tenant::getUsername, request.getUsername())
.eq(Tenant::getMark, MarkEnum.VALID.getCode()));
if (count > 0) {
return JsonResult.error("系统中已经存在该租户名");
}
@@ -114,20 +119,6 @@ public class AddOidcTenantService {
return JsonResult.success();
}

/**
* 添加租户
*/
private JsonResult addTenant(CreateOidcTenantRequest request) {
// 如果是租户先去创建
Tenant tenant = this.buildTenant(request);
Integer count = tenantMapper.insert(tenant);
if (count <= 0) {
log.info("创建租户失败");
JsonResult.error("创建租户失败");
}
return JsonResult.success(tenant);
}

private Tenant buildTenant(CreateOidcTenantRequest request) {
// 创建租户数据
Tenant tenant = new Tenant();
@@ -143,6 +134,18 @@ public class AddOidcTenantService {
return tenant;
}

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

/**
* 构建实体字段数据
*/

+ 28
- 16
tuoheng-service/tuoheng-admin/src/main/java/com/tuoheng/admin/service/third/oidc/EditOidcTenantService.java View File

@@ -50,8 +50,8 @@ public class EditOidcTenantService {
Tenant tenant = (Tenant) result.getData();

User oldUser = userMapper.selectOne(new LambdaQueryWrapper<User>()
.eq(User::getUsername, request.getUsername())
.eq(User::getMark, MarkEnum.VALID.getCode()));
.eq(User::getUsername, request.getUsername())
.eq(User::getMark, MarkEnum.VALID.getCode()));
User user = this.buildUser(request);

if (StringUtils.isNotEmpty(request.getClientId()) && !oldUser.getClientId().equals(user.getClientId())) {
@@ -98,7 +98,6 @@ public class EditOidcTenantService {
*
* @param request
* @param
*
* @return
*/
private JsonResult check(EditOidcTenantRequest request) {
@@ -115,8 +114,8 @@ public class EditOidcTenantService {
return JsonResult.error(400, "租户编号");
}
Tenant tenant = tenantMapper.selectOne(new LambdaQueryWrapper<Tenant>()
.eq(Tenant::getUsername, request.getUsername())
.eq(Tenant::getMark, MarkEnum.VALID.getCode()));
.eq(Tenant::getUsername, request.getUsername())
.eq(Tenant::getMark, MarkEnum.VALID.getCode()));
if (ObjectUtil.isNull(tenant)) {
return JsonResult.error("系统中不存在该租户");
}
@@ -130,7 +129,7 @@ public class EditOidcTenantService {
}

/**
* 修改租户
* 修改租户
*/
private JsonResult updateTenant(Tenant tenant, EditOidcTenantRequest request) {
// 如果是租户先去创建
@@ -141,8 +140,7 @@ public class EditOidcTenantService {
tenant.setDistrictName(request.getDistrictName());
tenant.setCityCode(request.getCityCode());
tenant.setCityName(request.getCityName());

Integer count = tenantMapper.insert(tenant);
Integer count = tenantMapper.updateById(tenant);
if (count <= 0) {
log.info("修改租户失败");
JsonResult.error("修改租户失败");
@@ -156,14 +154,27 @@ public class EditOidcTenantService {
private User buildUser(EditOidcTenantRequest request) {
// 创建用户数据
User user = new User();
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.setClientId(this.getClientId(request.getClientId()));
if (StringUtils.isNotEmpty(request.getPassword())) {
user.setPassword(CommonUtils.password(request.getPassword()));
}
if (StringUtils.isNotEmpty(request.getProvinceCode())) {
user.setProvinceCode(request.getProvinceCode());
}
if (StringUtils.isNotEmpty(request.getCityCode())) {
user.setCityCode(request.getCityCode());
}
if (StringUtils.isNotEmpty(request.getCityName())) {
user.setCityName(request.getCityName());
}
if (StringUtils.isNotEmpty(request.getDistrictCode())) {
user.setDistrictCode(request.getDistrictCode());
}
if (StringUtils.isNotEmpty(request.getClientId())) {
user.setClientId(this.getClientId(request.getClientId()));
}
user.setUpdateTime(DateUtils.now());
return user;
}
@@ -188,17 +199,18 @@ public class EditOidcTenantService {
}

/**
* 修改用户
* 修改用户
*/
private JsonResult editUser(User user) {
User userTmp = userMapper.selectOne(Wrappers.<User>lambdaQuery()
.eq(User::getMark, 1)
.eq(User::getMark, MarkEnum.VALID.getCode())
.eq(User::getStatus, 1)
.eq(User::getUsername, user.getUsername()));
if (ObjectUtil.isNull(userTmp)) {
log.info("修改租户用户,用户不存在,username:{}", user.getUsername());
return JsonResult.error("修改租户用户,不用户存在");
}
user.setId(userTmp.getId());
Integer rowCount = userMapper.updateById(user);
if (rowCount <= 0) {
log.info("修改租户用户失败,username:{}", user.getUsername());

Loading…
Cancel
Save