protected <T> T newDoPost(java.lang.String cmd, Object reqBody, Class<T > tClass) {
String url = outerConfig.getIdoutecUrl().get(cmd);
if(StringUtils.isEmpty(url)){
return getErrorBean(tClass, "未得到地址:"+cmd);
}
ResponseEntity<T> tResponseEntity = restTemplate.postForEntity(url,reqBody, tClass);
HttpStatus statusCode = tResponseEntity.getStatusCode();
if(statusCode.value()==HttpStatus.OK.value() && (null!=tResponseEntity&&tResponseEntity.hasBody())){
T returnBody = tResponseEntity.getBody();
returnBody.success();
return returnBody;
}else{
logger.error("与xx系统进行交互时报错,命令:{},请求参数:{}",cmd,JSON.toJSONString(reqBody));
return getErrorBean(tClass, "与xx系统进行交互时报错:"+cmd);
}
}
private <T extends BaseResponse> T getErrorBean(Class<T> tClass, String errorMsg) {
T returnBody = null;
try {
returnBody = tClass.newInstance();
returnBody.fail();
returnBody.setRtnMsg(errorMsg);
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return returnBody;
}