113 lines
4.4 KiB
Java
113 lines
4.4 KiB
Java
package com.tenwa.cgbbank.helper;
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
|
import com.fasterxml.jackson.dataformat.xml.ser.XmlSerializerProvider;
|
|
import com.fasterxml.jackson.dataformat.xml.util.XmlRootNameLookup;
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.tenwa.cgb.conf.CGBconfProperties;
|
|
import com.tenwa.cgb.util.CGBLogAssistant;
|
|
import com.tenwa.cgb.util.HttpAssistant;
|
|
import com.tenwa.cgbbank.dto.*;
|
|
import com.tenwa.cgbbank.enums.CGBInterfaceEnum;
|
|
import com.tenwa.cgbbank.xml.CustomNullSerializer;
|
|
import com.tenwa.comm.util.date.DateAssistant;
|
|
import org.apache.commons.logging.Log;
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
/**
|
|
* @program: apzl_leasing
|
|
* @description:
|
|
* @author: 李超杰
|
|
* @create: 2023-06-06 17:39
|
|
*/
|
|
public class CGBBankInterfaceHelper {
|
|
|
|
private static Log log = LogFactory.getLog(CGBBankInterfaceHelper.class);
|
|
|
|
private static CGBBankInterfaceHelper instance = new CGBBankInterfaceHelper();
|
|
|
|
private CGBBankInterfaceHelper() {
|
|
}
|
|
|
|
public static CGBBankInterfaceHelper getInstance() {
|
|
return instance;
|
|
}
|
|
|
|
private static XmlMapper xmlMapper = new XmlMapper();
|
|
|
|
static {
|
|
XmlSerializerProvider provider = new XmlSerializerProvider(new XmlRootNameLookup());
|
|
provider.setNullValueSerializer(new CustomNullSerializer());
|
|
xmlMapper.setSerializerProvider(provider);
|
|
}
|
|
|
|
/**
|
|
* 0032-交易明细查询-分页模式
|
|
*
|
|
* @param reqBody
|
|
* @return
|
|
* @throws Exception
|
|
*/
|
|
public CGBBEDC<CGB0032ResBody> queryTransactionDetails(CGB0032ReqBody reqBody) throws Exception {
|
|
return request(CGBInterfaceEnum.I0032, reqBody, new TypeReference<CGBBEDC<CGB0032ResBody>>() {
|
|
});
|
|
}
|
|
|
|
private <REQ, RES> CGBBEDC<RES> request(CGBInterfaceEnum interfaceEnum, REQ req, TypeReference<CGBBEDC<RES>> resTypeReference) throws Exception {
|
|
String customerBatchNo = "AP" + System.currentTimeMillis();
|
|
String cgbbedcXml = buildReqXml(interfaceEnum, req);
|
|
log.info("CGB [" + customerBatchNo + "] 【" + interfaceEnum.getName() + "】请求参数: " + cgbbedcXml);
|
|
CGBLogAssistant.insertCGBlog(interfaceEnum.getName(), interfaceEnum.getCode(), customerBatchNo, null, cgbbedcXml);
|
|
String retMsg = HttpAssistant.post(CGBconfProperties.CGBURL, ImmutableMap.of("cgb_data", cgbbedcXml));
|
|
|
|
if (retMsg == null) {
|
|
//更新返回日志
|
|
// TODO 记录异常状态
|
|
CGBLogAssistant.updateCGBlog(customerBatchNo, null, retMsg);
|
|
throw new RuntimeException("连接前置机异常,请联系管理员!");
|
|
}
|
|
//更新返回日志
|
|
CGBLogAssistant.updateCGBlog(customerBatchNo, null, retMsg);
|
|
log.info("CGB [" + customerBatchNo + "] 【" + interfaceEnum.getName() + "】返回结果: " + retMsg);
|
|
|
|
CGBBEDC<RES> tcgbbedc = xmlMapper.readValue(retMsg, resTypeReference);
|
|
return tcgbbedc;
|
|
}
|
|
|
|
private <T> String buildReqXml(CGBInterfaceEnum interfaceEnum, T reqBody) throws JsonProcessingException {
|
|
CGBMessageHead messageHead = new CGBMessageHead();
|
|
messageHead.setTranCode(interfaceEnum.getCode());
|
|
messageHead.setCifMaster(CGBconfProperties.CIFMASTER);
|
|
messageHead.setEntSeqNo("CGB" + System.currentTimeMillis());
|
|
messageHead.setTranDate(DateAssistant.getFormatDate("yyyyMMdd"));
|
|
messageHead.setTranTime(DateAssistant.getFormatDate("HHmmss"));
|
|
messageHead.setEntUserId(CGBconfProperties.ENTUSERID);
|
|
messageHead.setPassword(CGBconfProperties.PASSWORD);
|
|
|
|
CGBMessage<T> message = new CGBMessage<>();
|
|
message.setCommHead(messageHead);
|
|
message.setBody(reqBody);
|
|
|
|
CGBBEDC<T> cgbbedc = new CGBBEDC<>();
|
|
cgbbedc.setMessage(message);
|
|
return "<?xml version=\"1.0\" encoding=\"GBK\"?>" + xmlMapper.writeValueAsString(cgbbedc);
|
|
}
|
|
|
|
public static void main(String[] args) throws JsonProcessingException {
|
|
CGB0032ReqBody reqBody = new CGB0032ReqBody();
|
|
reqBody.setAccount("23232326454534767987");
|
|
reqBody.setBeginDate("20230614");
|
|
reqBody.setEndDate("20230614");
|
|
reqBody.setQueryType(0);
|
|
reqBody.setQueryNumber(20);
|
|
|
|
|
|
CGBBankInterfaceHelper instance1 = CGBBankInterfaceHelper.getInstance();
|
|
String xml = instance1.buildReqXml(CGBInterfaceEnum.I0032, reqBody);
|
|
System.out.println(xml);
|
|
|
|
}
|
|
}
|