Преглед изворни кода

更新oidc用户管理中心相关(接入高速,航道等业务平台),修改机场接口对调方式

tags/v2.4.1
xiaoying пре 1 година
родитељ
комит
d7a5aa3f8d
7 измењених фајлова са 122 додато и 107 уклоњено
  1. +6
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/AirportConstant.java
  2. +14
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/FreeWayConstant.java
  3. +2
    -2
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/HhzUrlConstant.java
  4. +15
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/WateWayConstant.java
  5. +1
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java
  6. +2
    -2
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/OidcTenantDto.java
  7. +82
    -102
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java

+ 6
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/AirportConstant.java Прегледај датотеку

@@ -3,12 +3,17 @@ package com.tuoheng.constant;
import lombok.Data;

/**
*机场平台接口常量类
* 机场平台接口常量类
*
* @Author xiaoying
* @Date 2023/1/31 17:45
*/
public class AirportConstant {

public static final String AIRPORT_CLIENT = "tuoheng-airport";

public static final String AIRPORT_NAME = "机场业务平台";

/**
* 创建租户
*/

+ 14
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/FreeWayConstant.java Прегледај датотеку

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

/**
* 高速平台接口常量类
* @Author xiaoying
* @Date 2023/2/23 9:32
*/
public class FreeWayConstant {


public static final String FREEWAY_CLIENT="tuoheng-freeway";

public static final String FREEWAY_NAME="高速业务平台";
}

+ 2
- 2
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/HhzUrlConstant.java Прегледај датотеку

@@ -7,9 +7,9 @@ package com.tuoheng.constant;
*/
public class HhzUrlConstant {

public static String HHZ_CLIENT="tuoheng-hhz";
public static final String HHZ_CLIENT="tuoheng-hhz";

public static String HHZ_NAME="河湖长业务平台";
public static final String HHZ_NAME="河湖长业务平台";

/**
* 创建租户

+ 15
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/constant/WateWayConstant.java Прегледај датотеку

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

/**
* 航道平台接口常量类
*
* @Author xiaoying
* @Date 2023/2/23 9:34
*/
public class WateWayConstant {


public static final String WATEWAY_CLIENT = "tuoheng-wateway";

public static final String WATEWAY_NAME = "航道业务平台";
}

+ 1
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/controller/TenantController.java Прегледај датотеку

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

import com.tuoheng.constant.CommonConstant;
import com.tuoheng.model.dto.LoginUser;
import com.tuoheng.model.dto.OidcTenantDto;
import com.tuoheng.model.param.CreateClientTenantDto;

+ 2
- 2
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/dto/OidcTenantDto.java Прегледај датотеку

@@ -20,7 +20,7 @@ public class OidcTenantDto {
/**
* 租户名称
*/
private String name;
private String tenantName;
/**
* 平台
*/
@@ -32,7 +32,7 @@ public class OidcTenantDto {
/**
* 租户code
*/
private String code;
private String tenantCode;
/**
* 省级编码
*/

+ 82
- 102
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/ClientUserServiceImpl.java Прегледај датотеку

@@ -9,9 +9,7 @@ import com.github.pagehelper.PageHelper;
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.constant.*;
import com.tuoheng.mapper.*;
import com.tuoheng.model.dto.*;
import com.tuoheng.model.param.*;
@@ -239,10 +237,10 @@ public class ClientUserServiceImpl implements ClientUserSevice {
return JsonResult.error("该租户账号已存在!");
}

if (ObjectUtil.isEmpty(dto.getCode())) {
if (ObjectUtil.isEmpty(dto.getTenantCode())) {
return JsonResult.error("租户code不能为空");
}
TTenant tTenant = tenantMapper.getByCode(dto.getCode());
TTenant tTenant = tenantMapper.getByCode(dto.getTenantCode());
if (ObjectUtil.isNotNull(tTenant)) {
return JsonResult.error("该租户code已存在,请重新输入");
}
@@ -253,15 +251,12 @@ public class ClientUserServiceImpl implements ClientUserSevice {
if (result.getCode() != JsonResult.SUCCESS) {
return result;
}
//TODO ->会导致循环终止(后期改进)
return requestAirport(dto, loginUser, CommonConstant.ONE);
}
} else {
JsonResult result = getResult(dto, dto.getClientId(), loginUser);
if (result.getCode() != JsonResult.SUCCESS) {
return result;
}
return requestAirport(dto, loginUser, CommonConstant.ONE);
}
return JsonResult.success();
}
@@ -289,13 +284,31 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
List<BusinessSystemVo> businessSystemVoList = new ArrayList<>();
for (AuthoritiesPo authoritiesPo : poList) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo();
//TODO 后期维护各个业务平台
if (authoritiesPo.getAuthority().contains("hhz")) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo();
businessSystemVo.setClientId(HhzUrlConstant.HHZ_CLIENT);
businessSystemVo.setName(HhzUrlConstant.HHZ_NAME);
businessSystemVoList.add(businessSystemVo);
}
if (authoritiesPo.getAuthority().contains("airport")) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo();
businessSystemVo.setClientId(AirportConstant.AIRPORT_CLIENT);
businessSystemVo.setName(AirportConstant.AIRPORT_NAME);
businessSystemVoList.add(businessSystemVo);
}
if (authoritiesPo.getAuthority().contains("wateway")) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo();
businessSystemVo.setClientId(WateWayConstant.WATEWAY_CLIENT);
businessSystemVo.setName(WateWayConstant.WATEWAY_NAME);
businessSystemVoList.add(businessSystemVo);
}
if (authoritiesPo.getAuthority().contains("freeway")) {
BusinessSystemVo businessSystemVo = new BusinessSystemVo();
businessSystemVo.setClientId(FreeWayConstant.FREEWAY_CLIENT);
businessSystemVo.setName(FreeWayConstant.FREEWAY_NAME);
businessSystemVoList.add(businessSystemVo);
}
}
businessSystemVoList = businessSystemVoList.stream().distinct().collect(Collectors.toList());
vo.setList(businessSystemVoList);
@@ -354,7 +367,7 @@ public class ClientUserServiceImpl implements ClientUserSevice {
@Transactional(rollbackFor = Exception.class)
public JsonResult editTenant(OidcTenantDto dto, LoginUser loginUser) {

if (ObjectUtil.isEmpty(dto.getCode())) {
if (ObjectUtil.isEmpty(dto.getTenantCode())) {
return JsonResult.error("租户code不能为空");
}
if (dto.getClientId().contains(",")) {
@@ -364,21 +377,18 @@ public class ClientUserServiceImpl implements ClientUserSevice {
if (jsonResult.getCode() != JsonResult.SUCCESS) {
return jsonResult;
}
//TODO ->会导致循环终止(后期改进)
requestAirport(dto, loginUser, CommonConstant.TWO);
}
} else {
JsonResult jsonResult = editResult(dto, dto.getClientId(), loginUser);
if (jsonResult.getCode() != JsonResult.SUCCESS) {
return jsonResult;
}
requestAirport(dto, loginUser, CommonConstant.TWO);
}
TTenant tTenant = tenantMapper.getByCode(dto.getCode());
TTenant tTenant = tenantMapper.getByCode(dto.getTenantCode());
dto.setId(tTenant.getId());

TenantPo tenantPo = new TenantPo();
tenantPo.setName(dto.getName())
tenantPo.setName(dto.getTenantName())
.setId(dto.getId())
.setCityCode(dto.getCityCode())
.setCityName(dto.getCityName())
@@ -419,11 +429,27 @@ public class ClientUserServiceImpl implements ClientUserSevice {
HttpEntity httpEntity = new HttpEntity(dto, resultRequestHeader);
//设置地址(hhz平台)
String url = platform.getPlatformUrl();

//根据不同业务平台进行动态匹配
//TODO 后期维护各个业务平台
if (url.contains("hhz")) {
url = url + HhzUrlConstant.CREATE_TENANT;
switch (url){
//河湖长
case HhzUrlConstant.HHZ_CLIENT:
url = url + HhzUrlConstant.CREATE_TENANT;
break;
//机场
case AirportConstant.AIRPORT_CLIENT:
url = url + AirportConstant.CREATE_TENANT;
break;
//case AirportConstant.AIRPORT_CLIENT:
// url = url + AirportConstant.CREATE_TENANT;
// break;
//case AirportConstant.AIRPORT_CLIENT:
// url = url + AirportConstant.CREATE_TENANT;
// break;
default:
break;
}
log.info("请求url:{}",url);
ResponseEntity<JsonResult> response;
try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
@@ -463,14 +489,25 @@ public class ClientUserServiceImpl implements ClientUserSevice {
//设置地址(hhz平台)
String url = platform.getPlatformUrl();
//根据不同业务平台进行动态匹配
if (url.contains("hhz")) {
url = url + HhzUrlConstant.UPDATE_TENANT;
}
//else if (url.contains("lc")) {
// url = url + HhzUrlConstant.UPDATE_TENANT;
//} else if (url.contains("gs")) {
// url = url + HhzUrlConstant.UPDATE_TENANT;
//}
switch (url){
//河湖长
case HhzUrlConstant.HHZ_CLIENT:
url = url + HhzUrlConstant.UPDATE_TENANT;
break;
//机场
case AirportConstant.AIRPORT_CLIENT:
url = url + AirportConstant.EDIT_TENANT;
break;
//case AirportConstant.AIRPORT_CLIENT:
// url = url + AirportConstant.CREATE_TENANT;
// break;
//case AirportConstant.AIRPORT_CLIENT:
// url = url + AirportConstant.CREATE_TENANT;
// break;
default:
break;
}
log.info("请求url:{}",url);
ResponseEntity<JsonResult> response;
try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
@@ -510,14 +547,25 @@ public class ClientUserServiceImpl implements ClientUserSevice {
//设置地址(hhz平台)
String url = platform.getPlatformUrl();
//根据不同业务平台进行动态匹配
if (url.contains("hhz")) {
url = url + HhzUrlConstant.DELETE_TENANT;
}
//else if (url.contains("lc")) {
// url = url + HhzUrlConstant.UPDATE_TENANT;
//} else if (url.contains("gs")) {
// url = url + HhzUrlConstant.UPDATE_TENANT;
//}
switch (url){
//河湖长
case HhzUrlConstant.HHZ_CLIENT:
url = url + HhzUrlConstant.DELETE_TENANT;
break;
//机场
case AirportConstant.AIRPORT_CLIENT:
url = url + AirportConstant.DELETE_TENANT;
break;
//case AirportConstant.AIRPORT_CLIENT:
// url = url + AirportConstant.CREATE_TENANT;
// break;
//case AirportConstant.AIRPORT_CLIENT:
// url = url + AirportConstant.CREATE_TENANT;
// break;
default:
break;
}
log.info("请求url:{}",url);
ResponseEntity<JsonResult> response;
try {
response = restTemplate.exchange(url, HttpMethod.POST, httpEntity, JsonResult.class);
@@ -534,72 +582,4 @@ public class ClientUserServiceImpl implements ClientUserSevice {
}
return JsonResult.success();
}

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

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

//填充请求类
AirportRequest request = new AirportRequest();
request.setPassword(dto.getPassword());
request.setUsername(dto.getUsername());
request.setTenantName(dto.getName());
request.setTenantCode(dto.getCode());

//设置请求头
HttpHeaders resultRequestHeader = new HttpHeaders();
resultRequestHeader.add("Authorization", "Bearer " + loginUser.getThToken());
HttpEntity httpEntity = new HttpEntity(request, resultRequestHeader);
//设置地址(机场平台->配置文件)
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 {
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(), "机场业务发送请求失败");
}
if (null == response || !response.hasBody()) {
log.error("机场业务发送请求失败响应失败");
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "机场业务发送请求失败");
}
if (response.getBody().getCode() != JsonResult.SUCCESS) {
log.error("机场业务发送请求失败响应失败" + response.getBody());
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), response.getBody().getMsg());
}
return JsonResult.success();

}
}

Loading…
Откажи
Сачувај