|
|
@@ -16,6 +16,8 @@ import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.web.client.HttpClientErrorException; |
|
|
|
import org.springframework.web.client.HttpServerErrorException; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
@@ -86,22 +88,37 @@ public class BillBusinessManagerImpl extends AbstractManager implements BillBusi |
|
|
|
} |
|
|
|
|
|
|
|
/** 统一处理请求*/ |
|
|
|
private <T extends AbstractIasRequest<?>, R extends AbstractIasResponse> R processBillRequest(String requestUri, T request, Class<R> responseClass) throws Exception { |
|
|
|
logger.info("请求汇联通开始,请求参数:{}", request); |
|
|
|
private <T extends AbstractIasRequest<?>, R extends AbstractIasResponse> R processBillRequest( |
|
|
|
String requestUri, T request, Class<R> responseClass) throws Exception { |
|
|
|
|
|
|
|
logger.info("请求汇联通开始,请求参数: {}", request); |
|
|
|
|
|
|
|
InterfaceRequest interfaceRequest = new InterfaceRequest(); |
|
|
|
interfaceRequest.setBizContent(request.toJson()); |
|
|
|
InterfaceResponse response = hltService.postHlt(billUrl + requestUri, interfaceRequest); |
|
|
|
logger.info("请求汇联通结束,响应参数:{}", response); |
|
|
|
if (response.getStatusCode() == 200) { |
|
|
|
try { |
|
|
|
return JsonTools.json2Object(response.getBizContent(), responseClass); |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("汇联通响应异常:{}", e.getMessage(), e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("接口错误:汇联通接口返回值格式错误!"); |
|
|
|
|
|
|
|
try { |
|
|
|
InterfaceResponse response = hltService.postHlt(billUrl + requestUri, interfaceRequest); |
|
|
|
logger.info("请求汇联通结束,响应参数: {}", response); |
|
|
|
|
|
|
|
if (response.getStatusCode() == 200) { |
|
|
|
try { |
|
|
|
return JsonTools.json2Object(response.getBizContent(), responseClass); |
|
|
|
} catch (IOException e) { |
|
|
|
logger.error("汇联通响应解析异常: {}", e.getMessage(), e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("接口错误:汇联通接口返回值格式错误!"); |
|
|
|
} |
|
|
|
} else { |
|
|
|
logger.error("汇联通响应异常,状态码: {}, 错误信息: {}", response.getStatusCode(), response.getErrorMsg()); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException( |
|
|
|
String.format("接口错误:汇联通响应异常!状态码:%d,错误信息:%s", response.getStatusCode(), response.getErrorMsg())); |
|
|
|
} |
|
|
|
} else { |
|
|
|
logger.error("汇联通响应异常:{}", response.getErrorMsg()); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("接口错误:汇联通响应异常!" + response.getErrorMsg()); |
|
|
|
} catch (HttpClientErrorException | HttpServerErrorException e) { |
|
|
|
logger.error("HTTP请求异常,状态码: {}, 错误信息: {}", e.getStatusCode(), e.getResponseBodyAsString(), e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException( |
|
|
|
String.format("接口错误:HTTP请求异常!状态码:%d,错误信息:%s", e.getStatusCode(), e.getResponseBodyAsString())); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("请求汇联通异常: {}", e.getMessage(), e); |
|
|
|
throw GlyServiceError.BUSINESS_VALIDATE_ERR.toHandleException("接口错误:请求汇联通异常!"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |