Commit a1c81687 authored by 5359's avatar 5359

增加异常处理和初始化代码处理

parent c57b51d2
...@@ -25,6 +25,8 @@ import com.hand.hap.system.dto.ResponseData; ...@@ -25,6 +25,8 @@ import com.hand.hap.system.dto.ResponseData;
import com.pingan.openbank.api.sdk.client.ApiClient; import com.pingan.openbank.api.sdk.client.ApiClient;
import com.pingan.openbank.api.sdk.common.http.HttpResult; import com.pingan.openbank.api.sdk.common.http.HttpResult;
import com.pingan.openbank.api.sdk.entity.*; import com.pingan.openbank.api.sdk.entity.*;
import com.pingan.openbank.api.sdk.exception.OpenBankSdkException;
import com.pingan.openbank.api.sdk.exception.OpenBankSdkException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
...@@ -50,7 +52,11 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -50,7 +52,11 @@ public class PingAnServiceImpl implements PingAnService {
private Logger logger = LoggerFactory.getLogger(getClass()); private Logger logger = LoggerFactory.getLogger(getClass());
private static JSONObject baseReqBody = new JSONObject();
private static Properties pro = null; private static Properties pro = null;
private static Calendar cal = null;
private static SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
static { static {
String path = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(1); String path = Thread.currentThread().getContextClassLoader().getResource("").getPath().substring(1);
...@@ -58,7 +64,11 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -58,7 +64,11 @@ public class PingAnServiceImpl implements PingAnService {
if (Objects.isNull(pro)) { if (Objects.isNull(pro)) {
LoggerFactory.getLogger(HclcCmbPolyServiceImpl.class).error("配置文件初始化异常"); LoggerFactory.getLogger(HclcCmbPolyServiceImpl.class).error("配置文件初始化异常");
} }
baseReqBody.put("MrchCode", pro.getProperty("MrchCode"));
baseReqBody.put("MainAccount", pro.getProperty("AcctNo"));
} }
/** /**
* @param interfaceName * @param interfaceName
* @param params * @param params
...@@ -67,72 +77,83 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -67,72 +77,83 @@ public class PingAnServiceImpl implements PingAnService {
@Override @Override
public JSONObject invoke(String interfaceName, JSONObject params) { public JSONObject invoke(String interfaceName, JSONObject params) {
JSONObject responseData = new JSONObject(); JSONObject responseData = new JSONObject();
JSONObject requestBody = ApiUtils.getBaseReqBody(); // JSONObject requestBody = ApiUtils.getBaseReqBody();
JSONObject requestBody = baseReqBody.clone();
cal = Calendar.getInstance();
String today = df.format(cal.getTime());
requestBody.put("CnsmrSeqNo", today + "000");
requestBody.putAll(params); requestBody.putAll(params);
/*插入接口日志表*/ /*插入接口日志表*/
HlsWsRequests hlsWsRequests = new HlsWsRequests(); HlsWsRequests hlsWsRequests = new HlsWsRequests();
hlsWsRequests = createRequestLog(pro.getProperty("baseUrl")+"/V1.0/"+interfaceName, requestBody.toJSONString(), 1L); hlsWsRequests = createRequestLog(pro.getProperty("baseUrl") + "/V1.0/" + interfaceName, requestBody.toJSONString(), 1L);
try {
HttpResult result = ApiUtils.invoke(interfaceName, requestBody); HttpResult result = ApiUtils.invoke(interfaceName, requestBody);
if (Objects.nonNull(result)) { if (Objects.nonNull(result)) {
// 通信成功 // 通信成功
if ("200".equals(result.getCode() + "")) { if ("200".equals(result.getCode() + "")) {
JSONObject res = JSONObject.parseObject(result.getData()); JSONObject res = JSONObject.parseObject(result.getData());
switch (interfaceName) { switch (interfaceName) {
case "bedl/SubAcctMaintenance" : case "bedl/SubAcctMaintenance":
hlsWsRequests.setFunctionName("pingAn_SubAcctMaintenance"); hlsWsRequests.setFunctionName("pingAn_SubAcctMaintenance");
break; break;
case "bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo" : case "bedl/InquiryIntoTheCurrentDetailsOfMainSubaccountAccountTwo":
hlsWsRequests.setFunctionName("pingAn_recentDetailQuery"); hlsWsRequests.setFunctionName("pingAn_recentDetailQuery");
break; break;
case "bedl/DetailReportQueryNew" : case "bedl/DetailReportQueryNew":
hlsWsRequests.setFunctionName("pingAn_DetailReportQueryNew"); hlsWsRequests.setFunctionName("pingAn_DetailReportQueryNew");
break; break;
} }
responseData.put("data",res); responseData.put("data", res);
// 具体业务是否请求成功判定,目前观察成功请求可能没有Code值 // 具体业务是否请求成功判定,目前观察成功请求可能没有Code值
if ("000000".equals(res.getString("Code")) || Objects.isNull(res.getString("Code"))){ if ("000000".equals(res.getString("Code")) || Objects.isNull(res.getString("Code"))) {
if ("bedl/DetailReportQueryNew".equals(interfaceName)){ if ("bedl/DetailReportQueryNew".equals(interfaceName)) {
dowloadDetailFile(res); dowloadDetailFile(res);
} }
hlsWsRequests.setReturnStatus("s"); hlsWsRequests.setReturnStatus("s");
responseData.put(Constants.RESP_CODE, "0000"); responseData.put(Constants.RESP_CODE, "0000");
responseData.put("respMsg", "请求成功"); responseData.put("respMsg", "请求成功");
}else{ } else {
//粗略的报错 如:"Message":"业务处理失败(通讯成功)","Code":"E50000" //粗略的报错 如:"Message":"业务处理失败(通讯成功)","Code":"E50000"
responseData.put(Constants.RESP_CODE ,res.getString("Code")); responseData.put(Constants.RESP_CODE, res.getString("Code"));
responseData.put(Constants.RESP_MSG ,res.getString("Message")); responseData.put(Constants.RESP_MSG, res.getString("Message"));
if (Objects.nonNull(res.getJSONArray("Errors"))){ if (Objects.nonNull(res.getJSONArray("Errors"))) {
//详情报错 如:"ErrorCode":"CE3887","ErrorMessage":":[CE3887]清分台账编码[30206688123456]记录已存在 //详情报错 如:"ErrorCode":"CE3887","ErrorMessage":":[CE3887]清分台账编码[30206688123456]记录已存在
responseData.put(Constants.RESP_CODE ,res.getJSONArray("Errors").getJSONObject(0).getString("ErrorCode")); responseData.put(Constants.RESP_CODE, res.getJSONArray("Errors").getJSONObject(0).getString("ErrorCode"));
responseData.put(Constants.RESP_MSG ,res.getJSONArray("Errors").getJSONObject(0).getString("ErrorMessage")); responseData.put(Constants.RESP_MSG, res.getJSONArray("Errors").getJSONObject(0).getString("ErrorMessage"));
} }
} }
} else { } else {
//请求失败 //请求失败
hlsWsRequests.setReturnStatus("f"); hlsWsRequests.setReturnStatus("f");
JSONObject errRes = JSONObject.parseObject(result.getData()); JSONObject errRes = JSONObject.parseObject(result.getData());
responseData.put(Constants.RESP_CODE,result.getCode()); responseData.put(Constants.RESP_CODE, result.getCode());
responseData.put(Constants.RESP_MSG,"请求失败"); responseData.put(Constants.RESP_MSG, "请求失败");
} }
hlsWsRequests.setResponseJson(result.getData()); hlsWsRequests.setResponseJson(result.getData());
hlsWsRequests.setResponsedDate(new Date()); hlsWsRequests.setResponsedDate(new Date());
} }
} catch (OpenBankSdkException e) {
hlsWsRequests.setReturnStatus("E");
responseData.put(Constants.RESP_CODE, e.getCode());
responseData.put(Constants.RESP_MSG, e.getMessage());
}
//更新日志 //更新日志
hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests); hlsWsRequestsMapper.updateByPrimaryKeySelective(hlsWsRequests);
return responseData; return responseData;
} }
public ResponseData detailNotify(IRequest iRequest, JSONObject data){ public ResponseData detailNotify(IRequest iRequest, JSONObject data) {
ResponseData responseData = new ResponseData(); ResponseData responseData = new ResponseData();
if (Objects.nonNull(data) && data.size() > 0){ if (Objects.nonNull(data) && data.size() > 0) {
// 存表 // 存表
HlsEbankCcbTransaction hlsEbankCcbTransaction = saveTransaction(iRequest,data); HlsEbankCcbTransaction hlsEbankCcbTransaction = saveTransaction(iRequest, data);
// 调用系统的接口服务,推送通知数据 // 调用系统的接口服务,推送通知数据
postNotify(JSONObject.toJSONString(hlsEbankCcbTransaction)); postNotify(JSONObject.toJSONString(hlsEbankCcbTransaction));
responseData.setSuccess(true); responseData.setSuccess(true);
responseData.setMessage("接收成功"); responseData.setMessage("接收成功");
}else{ } else {
responseData.setSuccess(false); responseData.setSuccess(false);
responseData.setMessage("接收失败"); responseData.setMessage("接收失败");
} }
...@@ -186,15 +207,25 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -186,15 +207,25 @@ public class PingAnServiceImpl implements PingAnService {
private HlsEbankCcbTransaction saveTransaction(IRequest iRequest, JSONObject data) { private HlsEbankCcbTransaction saveTransaction(IRequest iRequest, JSONObject data) {
HlsEbankCcbTransaction ccbTransaction = new HlsEbankCcbTransaction(); HlsEbankCcbTransaction ccbTransaction = new HlsEbankCcbTransaction();
ccbTransaction.setStatus("SUCCESS");
ccbTransaction.setNewDate(new Date());
ccbTransaction.setSuccessDate(new Date());
ccbTransaction.setAmount(data.getDouble("STT_VCH_AMT"));
ccbTransaction.setCount(1L);
ccbTransaction.setReturnCode("SUCCESS");
ccbTransaction.setReturnMsg("交易成功");
ccbTransaction.setBankType("PAB");
ccbTransaction.setMerId(ApiUtils.AcctNo); ccbTransaction.setMerId(ApiUtils.AcctNo);
ccbTransaction.setSttVchCardNo(data.getString("STT_VCH_CARD_NO"));
ccbTransaction.setSttAcDate(data.getString("STT_AC_DATE"));
ccbTransaction.setTranDate(data.getString("STT_TR_TIME"));
ccbTransaction.setMerOrderNo(data.getString("STT_CONSUMER_SEQ_NO")); ccbTransaction.setMerOrderNo(data.getString("STT_CONSUMER_SEQ_NO"));
ccbTransaction.setVersion(data.getString("STT_AC_DATE"));
ccbTransaction.setTranDate(data.getString("STT_TR_TIME"));
ccbTransaction.setTranType(data.getString("STT_VCH_SIGN"));
/*订单状态接收成功*/
ccbTransaction.setOrderStatus("R");
ccbTransaction.setCmbOrderId(data.getString("STT_JRN_NO")); ccbTransaction.setCmbOrderId(data.getString("STT_JRN_NO"));
ccbTransaction.setSttVchCardNo(data.getString("STT_VCH_CARD_NO"));
ccbTransaction.setSttAcDate(data.getString("STT_AC_DATE"));
ccbTransaction.setSttVchSeqNo(data.getString("STT_VCH_SEQ_NO")); ccbTransaction.setSttVchSeqNo(data.getString("STT_VCH_SEQ_NO"));
ccbTransaction.setTranType(data.getString("STT_VCH_SIGN"));
ccbTransaction.setAmount(data.getDouble("STT_VCH_AMT"));
ccbTransaction.setSttAmtRmb(data.getDouble("STT_AMT_RMB")); ccbTransaction.setSttAmtRmb(data.getDouble("STT_AMT_RMB"));
ccbTransaction.setSttVchBal(data.getDouble("STT_VCH_BAL")); ccbTransaction.setSttVchBal(data.getDouble("STT_VCH_BAL"));
ccbTransaction.setSttVchRcvAcNo(data.getString("STT_VCH_RCV_AC_NO")); ccbTransaction.setSttVchRcvAcNo(data.getString("STT_VCH_RCV_AC_NO"));
...@@ -208,7 +239,7 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -208,7 +239,7 @@ public class PingAnServiceImpl implements PingAnService {
} }
//下载回单文件 //下载回单文件
private void dowloadDetailFile(JSONObject data){ private void dowloadDetailFile(JSONObject data) {
JSONArray arr = data.getJSONArray("list"); JSONArray arr = data.getJSONArray("list");
//转换成orderFile对象 //转换成orderFile对象
if (Objects.nonNull(arr)) { if (Objects.nonNull(arr)) {
...@@ -226,6 +257,7 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -226,6 +257,7 @@ public class PingAnServiceImpl implements PingAnService {
/** /**
* 近期明细查询 * 近期明细查询
*
* @param interfaceName * @param interfaceName
* @param params * @param params
* @return * @return
...@@ -234,15 +266,15 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -234,15 +266,15 @@ public class PingAnServiceImpl implements PingAnService {
JSONObject responseData = new JSONObject(); JSONObject responseData = new JSONObject();
int pageNo = 0; int pageNo = 0;
String isEnd = "N"; String isEnd = "N";
while("N".equalsIgnoreCase(isEnd)){ while ("N".equalsIgnoreCase(isEnd)) {
params.put("PageNo",++pageNo); params.put("PageNo", ++pageNo);
JSONObject res = invoke(interfaceName, params); JSONObject res = invoke(interfaceName, params);
isEnd = res.getString("isEnd"); isEnd = res.getString("isEnd");
// 对当前查询到的数据进行存表 // 对当前查询到的数据进行存表
JSONObject data = res.getJSONObject("data"); JSONObject data = res.getJSONObject("data");
JSONArray arr = data.getJSONArray("list"); JSONArray arr = data.getJSONArray("list");
if (Objects.nonNull(arr)){ if (Objects.nonNull(arr)) {
batchSaveTransactionByC00602(iRequest,arr); batchSaveTransactionByC00602(iRequest, arr);
} }
} }
responseData.put(Constants.RESP_CODE, "0000"); responseData.put(Constants.RESP_CODE, "0000");
...@@ -257,7 +289,7 @@ public class PingAnServiceImpl implements PingAnService { ...@@ -257,7 +289,7 @@ public class PingAnServiceImpl implements PingAnService {
ccbTransaction.setCmbOrderId(data.getString("JournalNo")); ccbTransaction.setCmbOrderId(data.getString("JournalNo"));
ccbTransaction.setTranType(data.getString("DCFlag")); ccbTransaction.setTranType(data.getString("DCFlag"));
int exist = hlsEbankCcbTransactionMapper.queryByCmbOrderId(ccbTransaction); int exist = hlsEbankCcbTransactionMapper.queryByCmbOrderId(ccbTransaction);
if (exist == 0){ if (exist == 0) {
ccbTransaction.setMerId(ApiUtils.AcctNo); ccbTransaction.setMerId(ApiUtils.AcctNo);
ccbTransaction.setSttVchCardNo(data.getString("SubAccount")); ccbTransaction.setSttVchCardNo(data.getString("SubAccount"));
ccbTransaction.setSttAcDate(data.getString("AccountDate")); ccbTransaction.setSttAcDate(data.getString("AccountDate"));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment