LoanSucceedInfoParam loanSucceedInfoParam = setLoanSucceedInfoParam(orderNumber);
List<RmAttachmentParam> rmAttachmentParamList = new ArrayList<>();
List<Attachment> attachmentList = attachmentService.getListByOrderNumber(orderNumber);
for (Attachment attachment : attachmentList) {
RmAttachmentParam rmAttachmentParam = new RmAttachmentParam();
BeanUtils.copyProperties(attachment,rmAttachmentParam);
rmAttachmentParamList.add(rmAttachmentParam);
}
log.info("附件信息:{}",JacksonUtils.toJson(rmAttachmentParamList));
CloseableHttpClient httpClient = HttpClientPoolUtils.getHttpClient();
HttpPost httpPost = new HttpPost(fundHost + fundSaveSuccessInfo);
log.info("接口提交-传输放款成功数据给贷后系统,地址:[{}]", fundHost + fundSaveSuccessInfo);
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addTextBody("loanSucceedInfoDto",JacksonUtils.toJson(loanSucceedInfoParam), ContentType.APPLICATION_JSON);
builder.addTextBody("rmAttachmentDtoList",JacksonUtils.toJson(rmAttachmentParamList), ContentType.APPLICATION_JSON);
for (Attachment attachment : attachmentList) {
File file = new File(fileuploadPath+attachment.getUrl());
builder.addBinaryBody(file.getName(),file);
}
HttpEntity build = builder.build();
httpPost.setEntity(build);
ThirdpartyRequestRecord thirdpartyRequestRecord = new ThirdpartyRequestRecord();
thirdpartyRequestRecord.setUrl(fundHost + fundSaveSuccessInfo);
Map<String,Object> map = new HashMap<>();
map.put("loanSucceedInfoDto",loanSucceedInfoParam);
map.put("rmAttachmentDtoList",rmAttachmentParamList);
thirdpartyRequestRecord.setRequest(JacksonUtils.toJson(map));
thirdpartyRequestRecord.setType(ThirdpartyTypeEnum.HOME_AFTER_LOAN.getCode());
try (CloseableHttpResponse httpResponse = httpClient.execute(httpPost)) {
int statusCode = httpResponse.getStatusLine().getStatusCode();
thirdpartyRequestRecord.setResponse(JSON.toJSON(httpResponse).toString());
log.info("贷后接口返回状态码:{}",statusCode);
if (statusCode == HttpStatus.SC_OK) {
String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
thirdpartyRequestRecord.setResponse(JSON.toJSON(response).toString());
log.info("订单[{}]推送数据返回结果:[{}]", orderNumber, response);
String code = JSON.parseObject(response).getString("code");
String msg = JSON.parseObject(response).getString("msg");
if (!"10000".equals(code)){
log.error("客户订单号[{}]数据推送至贷后系统异常", orderNumber);
}
}
thirdpartyRequestRecordService.insert(thirdpartyRequestRecord);
}catch (Exception e){
log.error("客户订单号[{}]数据推送至贷后系统异常", orderNumber, e);
}
|