|
|
@@ -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; |
|
|
|
} |
|
|
|
|