瀏覽代碼

Merge branch 'develop' of gitadmin/tuoheng_oidc into release

tags/v2.4.0
xuziqing 1 年之前
父節點
當前提交
5e02b7481d
共有 3 個檔案被更改,包括 91 行新增11 行删除
  1. +9
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/AirportConstant.java
  2. +27
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/CommonConstant.java
  3. +55
    -11
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java

+ 9
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/AirportConstant.java 查看文件

@@ -13,4 +13,13 @@ public class AirportConstant {
* 创建租户
*/
public static String CREATE_TENANT = "/api/airportInterface/addTenant";
/**
* 修改租户
*/
public static String EDIT_TENANT = "/api/airportInterface/editTenant";
/**
* 删除租户
*/
public static String DELETE_TENANT = "/api/airportInterface/delTenant";

}

+ 27
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/CommonConstant.java 查看文件

@@ -0,0 +1,27 @@
package com.tuoheng.constant;

/**
* 通用常量类
*
* @Author xiaoying
* @Date 2023/2/2 14:08
*/
public final class CommonConstant {
/**
* 构造器私有化
*/
private CommonConstant() {
// 可抛出异常,防止通过反射实例化对象
}

/**
* 常用数值
*/
public static final Integer ONE = 1;
public static final Integer TWO = 2;
public static final Integer THREE = 3;
public static final Integer FOUR = 4;
public static final Integer FIVE = 5;


}

+ 55
- 11
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java 查看文件

@@ -10,6 +10,7 @@ import com.github.pagehelper.PageInfo;
import com.tuoheng.common.CommonConfig;
import com.tuoheng.common.ServiceException;
import com.tuoheng.constant.AirportConstant;
import com.tuoheng.constant.CommonConstant;
import com.tuoheng.constant.HhzUrlConstant;
import com.tuoheng.mapper.*;
import com.tuoheng.model.dto.*;
@@ -228,7 +229,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
public JsonResult addTenant(OidcTenantDto dto, LoginUser loginUser) {

if (clientUserMapper.judgeCreateByUserName(dto.getUsername()) > 0) {
return JsonResult.error("该用户名称已存在!");
return JsonResult.error("该租户账号已存在!");
}

if (ObjectUtil.isEmpty(dto.getCode())) {
@@ -245,14 +246,15 @@ public class ClientUserServiceImpl implements ClientUserSevice {
if (!"操作成功".equals(result.getMsg())) {
return result;
}
return requestAirport(dto, loginUser);
//TODO ->会导致循环终止(后期改进)
return requestAirport(dto, loginUser, CommonConstant.ONE);
}
} else {
JsonResult result = getResult(dto, dto.getClientId(), loginUser);
if (!"操作成功".equals(result.getMsg())) {
return result;
}
return requestAirport(dto, loginUser);
return requestAirport(dto, loginUser, CommonConstant.ONE);
}
return JsonResult.success();
}
@@ -317,10 +319,19 @@ public class ClientUserServiceImpl implements ClientUserSevice {
if (dto.getClientId().contains(",")) {
String[] codes = dto.getClientId().split(",");
for (String code : codes) {
return deleteResult(dto, code, loginUser);
JsonResult jsonResult = deleteResult(dto, code, loginUser);
if (!"操作成功".equals(jsonResult.getMsg())) {
return jsonResult;
}
//TODO ->会导致循环终止(后期改进)
return requestAirport(dto, loginUser, CommonConstant.THREE);
}
} else {
return deleteResult(dto, dto.getClientId(), loginUser);
JsonResult jsonResult = deleteResult(dto, dto.getClientId(), loginUser);
if (!"操作成功".equals(jsonResult.getMsg())) {
return jsonResult;
}
return requestAirport(dto, loginUser, CommonConstant.THREE);
}
return JsonResult.success();
}
@@ -346,12 +357,15 @@ public class ClientUserServiceImpl implements ClientUserSevice {
if (!"操作成功".equals(jsonResult.getMsg())) {
return jsonResult;
}
//TODO ->会导致循环终止(后期改进)
return requestAirport(dto, loginUser, CommonConstant.TWO);
}
} else {
JsonResult jsonResult = editResult(dto, dto.getClientId(), loginUser);
if (!"操作成功".equals(jsonResult.getMsg())) {
return jsonResult;
}
return requestAirport(dto, loginUser, CommonConstant.TWO);
}
TTenant tTenant = tenantMapper.getByCode(dto.getCode());
dto.setId(tTenant.getId());
@@ -509,12 +523,16 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}

/**
* 向机场发送请求
* 向机场发送请求-创建租户
*
* @param dto
* @param loginUser
* @return
*/
private JsonResult requestAirport(OidcTenantDto dto,LoginUser loginUser) {
private JsonResult requestAirport(OidcTenantDto dto, LoginUser loginUser, Integer type) {

//type 1 创建 2 修改 3 删除

//填充请求类
AirportRequest request = new AirportRequest();
request.setPassword(dto.getPassword());
@@ -527,10 +545,36 @@ public class ClientUserServiceImpl implements ClientUserSevice {
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken());
HttpEntity httpEntity = new HttpEntity(request, resultRequestHeader);
//设置地址(机场平台->配置文件)
String url = CommonConfig.airportURL+ AirportConstant.CREATE_TENANT;
ResponseEntity<JsonResult> response;
String url="";
switch (type) {
case 1:
url = CommonConfig.airportURL + AirportConstant.CREATE_TENANT;
break;
case 2:
url = CommonConfig.airportURL + AirportConstant.EDIT_TENANT;
break;
case 3:
url = CommonConfig.airportURL + AirportConstant.DELETE_TENANT+"/"+request.getTenantCode();
break;
default:
break;
}

ResponseEntity<JsonResult> response = null;
try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
switch (type) {
case 1:
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
break;
case 2:
response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity, JsonResult.class);
break;
case 3:
response = restTemplate.exchange(url, HttpMethod.DELETE, httpEntity, JsonResult.class);
break;
default:
break;
}
} catch (Exception e) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "机场平台创建租户失败");
}
@@ -540,7 +584,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
if (response.getBody().getCode() != JsonResult.SUCCESS) {
log.error("机场平台创建租户响应失败" + response.getBody());
return JsonResult.error(response.getBody().getMsg());
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg());
}
return JsonResult.success();


Loading…
取消
儲存