Browse Source

更新创建租户相关

tags/v2.5.2
xiaoying 1 year ago
parent
commit
013d12ce30
4 changed files with 26 additions and 57 deletions
  1. +2
    -1
      tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/ClientRoleDto.java
  2. +1
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java
  3. +3
    -0
      tuoheng_oidc_admin/src/main/java/com/tuoheng/third/request/ModelInfoDao.java
  4. +20
    -56
      tuoheng_oidc_admin/src/main/java/com/tuoheng/third/service/impl/ThirdServiceImpl.java

+ 2
- 1
tuoheng_oidc_admin/src/main/java/com/tuoheng/model/param/ClientRoleDto.java View File

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

import com.tuoheng.third.request.ModelInfoDao;
import com.tuoheng.third.vo.ModelInfoVo;
import lombok.Data;

@@ -37,6 +38,6 @@ public class ClientRoleDto {
/**
* 模型集合及其对应检测目标集合
*/
private List<ModelInfoVo> modelInfoVoList;
private List<ModelInfoDao> modelInfoDaos;

}

+ 1
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/service/impl/TenantServiceImpl.java View File

@@ -193,6 +193,7 @@ public class TenantServiceImpl implements TenantService {
clientUserRoleMapper.batchInsert(clientUserRolePoArrayList);
//todo:调用业务系统完成租户创建
List<ClientRoleDto> list = createClientTenantDto.getClientRoleDtoList();

list = thirdService.getModelList(list);
createClientTenantDto.setClientRoleDtoList(list);
for (ClientRoleDto clientRoleDto : list) {

+ 3
- 0
tuoheng_oidc_admin/src/main/java/com/tuoheng/third/request/ModelInfoDao.java View File

@@ -18,4 +18,7 @@ public class ModelInfoDao {
private String detectTargetsName;

private String detectTargetsCode;

private String serviceName;

}

+ 20
- 56
tuoheng_oidc_admin/src/main/java/com/tuoheng/third/service/impl/ThirdServiceImpl.java View File

@@ -27,6 +27,7 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.client.RestTemplate;

import java.util.*;
@@ -91,68 +92,31 @@ public class ThirdServiceImpl implements ThirdService {
@Override
public List<ClientRoleDto> getModelList(List<ClientRoleDto> list) {

String param = list.stream().map(ClientRoleDto::getServiceId).collect(Collectors.toList()).toString().replace("[", "").replace("]", "");

String url = CommonConfig.dspURL + DspConstant.FIND_MODELIST + "?serviceIds=" + param;
for (ClientRoleDto clientRoleDto : list) {
if (ObjectUtil.isNotEmpty(clientRoleDto.getServiceId())) {

ParameterizedTypeReference<JsonResult<List<ModelInfoDao>>> parameterizedTypeReference =
new ParameterizedTypeReference<JsonResult<List<ModelInfoDao>>>() {
};
ResponseEntity<JsonResult<List<ModelInfoDao>>> response;
try {
log.info("url:{}", url);
response = restTemplate.exchange(url, HttpMethod.GET, null, parameterizedTypeReference);
} catch (Exception e) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "请求发送内部出现异常!");
}
if (response == null || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "dsp获取服务实例异常");
}
List<String> collect = Arrays.stream(clientRoleDto.getServiceId().split(",")).collect(Collectors.toList());
String param = collect.toString().replace("[", "").replace("]", "");
String url = CommonConfig.dspURL + DspConstant.FIND_MODELIST + "?serviceIds=" + param;

List<ModelInfoDao> modelInfoDaos = response.getBody().getData();

Map<String, Map<String, ModelInfoVo>> modelMap = new HashMap<>();
for (ModelInfoDao m : modelInfoDaos) {
Map<String, ModelInfoVo> map = modelMap.getOrDefault(m.getServiceInstId(), new HashMap<>());
if (CollectionUtils.isEmpty(map)) {
ModelInfoVo modelInfoVo = new ModelInfoVo();
modelInfoVo.setModelId(m.getModelId());
modelInfoVo.setModelName(m.getModelName());
List<DetectTargetsVo> detectTargetsList = new ArrayList<>();
DetectTargetsVo detectTargetsVo = new DetectTargetsVo();
detectTargetsVo.setDetectTargetsId(m.getDetectTargetsId());
detectTargetsVo.setDetectTargetsName(m.getDetectTargetsName());
detectTargetsVo.setDetectTargetsCode(m.getDetectTargetsCode());
detectTargetsList.add(detectTargetsVo);
modelInfoVo.setDetectTargetsVoList(detectTargetsList);
map.put(m.getModelId(), modelInfoVo);
modelMap.put(m.getServiceInstId(), map);

} else {
ModelInfoVo modelInfoVo = map.getOrDefault(m.getModelId(), null);
if (modelInfoVo == null) {
modelInfoVo = new ModelInfoVo();
modelInfoVo.setModelId(m.getModelId());
modelInfoVo.setModelName(m.getModelName());
List<DetectTargetsVo> detectTargetsList = new ArrayList<>();
DetectTargetsVo detectTargetsVo = new DetectTargetsVo();
detectTargetsVo.setDetectTargetsId(m.getDetectTargetsId());
detectTargetsVo.setDetectTargetsName(m.getDetectTargetsName());
detectTargetsVo.setDetectTargetsCode(m.getDetectTargetsCode());
detectTargetsList.add(detectTargetsVo);
modelInfoVo.setDetectTargetsVoList(detectTargetsList);
map.put(m.getModelId(), modelInfoVo);
} else {
List<DetectTargetsVo> detectTargetsList = modelInfoVo.getDetectTargetsVoList();
DetectTargetsVo detectTargetsVo = new DetectTargetsVo();
detectTargetsVo.setDetectTargetsId(m.getDetectTargetsId());
detectTargetsVo.setDetectTargetsName(m.getDetectTargetsName());
detectTargetsVo.setDetectTargetsCode(m.getDetectTargetsCode());
detectTargetsList.add(detectTargetsVo);
ParameterizedTypeReference<JsonResult<List<ModelInfoDao>>> parameterizedTypeReference =
new ParameterizedTypeReference<JsonResult<List<ModelInfoDao>>>() {
};
ResponseEntity<JsonResult<List<ModelInfoDao>>> response;
try {
log.info("url:{}", url);
response = restTemplate.exchange(url, HttpMethod.GET, null, parameterizedTypeReference);
} catch (Exception e) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "请求发送内部出现异常!");
}
if (null == response || !response.hasBody() || response.getBody().getCode() != JsonResult.SUCCESS) {
throw new ServiceException(HttpStatus.BAD_REQUEST.value(), "dsp获取服务实例异常");
}
List<ModelInfoDao> modelInfoDaos = response.getBody().getData();
clientRoleDto.setModelInfoDaos(modelInfoDaos);
}
}
list.forEach(t -> t.setModelInfoVoList(new ArrayList<>(modelMap.getOrDefault(t.getServiceId(), new HashMap<>()).values())));
return list;
}


Loading…
Cancel
Save