58 lines
2.2 KiB
Java
58 lines
2.2 KiB
Java
|
|
package com.engine.salary.remote.cbs8.client;
|
||
|
|
|
||
|
|
import com.engine.salary.exception.SalaryRunTimeException;
|
||
|
|
import com.engine.salary.remote.cbs8.request.GetDtaRequest;
|
||
|
|
import com.engine.salary.remote.cbs8.response.GetDtaResponse;
|
||
|
|
import com.engine.salary.util.JsonUtil;
|
||
|
|
import com.engine.salary.util.SalaryI18nUtil;
|
||
|
|
import lombok.extern.slf4j.Slf4j;
|
||
|
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||
|
|
import org.apache.http.client.methods.HttpPost;
|
||
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||
|
|
import org.apache.http.impl.client.HttpClients;
|
||
|
|
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.nio.charset.StandardCharsets;
|
||
|
|
import java.util.Objects;
|
||
|
|
|
||
|
|
@Slf4j
|
||
|
|
public class BillManagementClient extends CBS8BaseClient {
|
||
|
|
|
||
|
|
public GetDtaResponse dtaQuery(GetDtaRequest requestParam) throws IOException {
|
||
|
|
String url = host + "/openapi/draft/openapi/v1/dta/query";
|
||
|
|
|
||
|
|
CloseableHttpClient client = HttpClients.custom()
|
||
|
|
// 禁止HttpClient自动解压缩
|
||
|
|
.disableContentCompression()
|
||
|
|
.build();
|
||
|
|
|
||
|
|
String requestData = JsonUtil.toJsonString(requestParam);
|
||
|
|
log.info(url + "\n" + requestData);
|
||
|
|
|
||
|
|
HttpPost httpPost = setupRequest(url, requestData);
|
||
|
|
try (CloseableHttpResponse response = client.execute(httpPost)) {
|
||
|
|
byte[] finalResponseData = handleResponse(response);
|
||
|
|
String req = new String(finalResponseData, StandardCharsets.UTF_8);
|
||
|
|
GetDtaResponse getDtaResponse = JsonUtil.parseBean(req, GetDtaResponse.class);
|
||
|
|
log.info(url + "\n" + JsonUtil.toJsonString(getDtaResponse));
|
||
|
|
|
||
|
|
if (Objects.isNull(getDtaResponse)) {
|
||
|
|
throw new SalaryRunTimeException(SalaryI18nUtil.getI18nLabel(156449, "服务异常"));
|
||
|
|
}
|
||
|
|
if (!"0".equals(getDtaResponse.getCode())) {
|
||
|
|
throw new SalaryRunTimeException(getDtaResponse.getMsg());
|
||
|
|
}
|
||
|
|
if (getDtaResponse.getData() == null) {
|
||
|
|
throw new SalaryRunTimeException("未获取数据");
|
||
|
|
}
|
||
|
|
|
||
|
|
return getDtaResponse;
|
||
|
|
} catch (IOException ignored) {
|
||
|
|
throw new SalaryRunTimeException("网络连接失败或超时!");
|
||
|
|
} finally {
|
||
|
|
client.close();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|