Commit 5fe3ea44 by wubh

包活干V1.9.0-修改:长城欧拉返回状态码问题

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@27034 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent 5d0c150f
......@@ -6,7 +6,7 @@ import com.glsx.ordercenter.controller.BaseController;
import com.glsx.ordercenter.dto.req.OraInsuranceRefundReq;
import com.glsx.ordercenter.dto.req.OraInsuranceUpdateReq;
import com.glsx.ordercenter.dto.resp.OraResultObject;
import com.glsx.ordercenter.exception.SysException;
import com.glsx.ordercenter.exception.BusinessException;
import com.glsx.ordercenter.service.api.OraInsuranceService;
import com.glsx.ordercenter.utils.OraSignUtil;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -48,7 +48,7 @@ public class OraInsuranceController extends BaseController {
OraSignUtil.verifyRequest(appKey, appSecret, saveData);
super.checkRequestParam(bindingResult);
resultObject = insuranceService.save(saveData);
} catch (SysException e) {
} catch (BusinessException e) {
super.logError("长城欧拉分派保单-异常", e);
ResultObject result = e.getResultEntity();
resultObject = new OraResultObject(result.getCode(), result.getMessage());
......@@ -69,7 +69,7 @@ public class OraInsuranceController extends BaseController {
OraSignUtil.verifyRequest(appKey, appSecret, updateReq);
super.checkRequestParam(bindingResult);
resultObject = insuranceService.update(updateReq);
} catch (SysException e) {
} catch (BusinessException e) {
super.logError("长城欧拉修改保单-异常", e);
ResultObject result = e.getResultEntity();
resultObject = new OraResultObject(result.getCode(), result.getMessage());
......@@ -91,7 +91,7 @@ public class OraInsuranceController extends BaseController {
OraSignUtil.verifyRequest(appKey, appSecret, refundReq);
super.checkRequestParam(bindingResult);
resultObject = insuranceService.refund(refundReq);
} catch (SysException e) {
} catch (BusinessException e) {
super.logError("长城欧拉退保-异常", e);
ResultObject result = e.getResultEntity();
resultObject = new OraResultObject(result.getCode(), result.getMessage());
......
package com.glsx.ordercenter.service.api.impl;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Semaphore;
import com.alibaba.fastjson.JSONObject;
import com.glsx.common.utils.DateUtil;
import com.glsx.ordercenter.config.ThreadPoolConfig;
import com.glsx.ordercenter.constants.insurance.*;
import com.glsx.ordercenter.constants.insurance.InsuranceCardType;
import com.glsx.ordercenter.constants.insurance.InsuranceCustomerType;
import com.glsx.ordercenter.constants.insurance.InsuranceSource;
import com.glsx.ordercenter.constants.insurance.InsuranceStatus;
import com.glsx.ordercenter.constants.insurance.OraResultCode;
import com.glsx.ordercenter.dto.req.OraInsuranceRefundReq;
import com.glsx.ordercenter.dto.req.OraInsuranceUpdateReq;
import com.glsx.ordercenter.dto.resp.OraResultObject;
......@@ -23,11 +31,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.concurrent.Semaphore;
/**
* <p>Description:
*
......@@ -182,11 +185,11 @@ public class OraInsuranceServiceImpl extends BaseOrderService implements OraInsu
* 生成保单更新邮件内容
*
* @param updateReq 请求体
* @param insurancePolicy 保单数据
* @param policy 保单数据
* @return 保单更新邮件内容
*/
private String buildUpdateMailContent(OraInsuranceUpdateReq updateReq,
SysInsurancePolicy insurancePolicy) {
SysInsurancePolicy policy) {
String content = "<table>" +
"<tr>" +
" <td>" + "客户类型" + "</td>" +
......@@ -234,11 +237,11 @@ public class OraInsuranceServiceImpl extends BaseOrderService implements OraInsu
"</tr>" +
"<tr>" +
" <td>" + "安装日期" + "</td>" +
" <td>" + updateReq.getInstallationTime() + "</td>" +
" <td>" + DateUtil.formatDate(updateReq.getInstallationTime()) + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "生效日期" + "</td>" +
" <td>" + insurancePolicy.getExpectedEffectiveTime() + "</td>" +
" <td>" + DateUtil.formatDate(policy.getExpectedEffectiveTime()) + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "车身颜色" + "</td>" +
......@@ -258,7 +261,7 @@ public class OraInsuranceServiceImpl extends BaseOrderService implements OraInsu
"</tr>" +
"<tr>" +
" <td>" + "保单PDF地址" + "</td>" +
" <td>" + insurancePolicy.getInsurancePdf() + "</td>" +
" <td>" + policy.getInsurancePdf() + "</td>" +
"</tr>" +
"</table>";
super.logInfo("长城欧拉修改保单-邮件内容", content);
......@@ -307,11 +310,11 @@ public class OraInsuranceServiceImpl extends BaseOrderService implements OraInsu
"</tr>" +
"<tr>" +
" <td>" + "提交日期" + "</td>" +
" <td>" + policy.getCreateTime() + "</td>" +
" <td>" + DateUtil.formatDate(policy.getCreateTime()) + "</td>" +
"</tr>" +
"<tr>" +
" <td>" + "生效日期" + "</td>" +
" <td>" + policy.getExpectedEffectiveTime() + "</td>" +
" <td>" + DateUtil.formatDate(policy.getExpectedEffectiveTime()) + "</td>" +
"</tr>" +
"</table>";
super.logInfo("长城欧拉退保-邮件内容", content);
......
......@@ -364,7 +364,7 @@ public class InsuranceServiceImpl extends BaseOrderService implements InsuranceS
// 如果7天内退保则自动调用TSP接口
result = this.hasOutdated(insurancePolicy)
? this.refundManually(insurancePolicy)
: this.refundAutomatically(insurancePolicy, API_INVOKE_RETRIES);
: this.refundAutomatically(insurancePolicy);
return result;
}
......@@ -419,7 +419,7 @@ public class InsuranceServiceImpl extends BaseOrderService implements InsuranceS
* @return 是否超过7天
*/
private boolean hasOutdated(SysInsurancePolicy insurancePolicy) {
Date createTime = insurancePolicy.getCreateTime();
Date createTime = insurancePolicy.getExpectedEffectiveTime();
Date currentDate = new Date();
return ((currentDate.getTime() - createTime.getTime()) > MILLISECONDS_PER_WEEK);
......@@ -429,10 +429,9 @@ public class InsuranceServiceImpl extends BaseOrderService implements InsuranceS
* 调用TSP退保
*
* @param insurancePolicy 保单数据
* @param retries 重试次数
* @return 退保结果
*/
private InsuranceResp refundAutomatically(SysInsurancePolicy insurancePolicy, int retries) {
private InsuranceResp refundAutomatically(SysInsurancePolicy insurancePolicy) {
InsuranceResp insuranceResp = new InsuranceResp();
TspRefundReq tspRefundReq = new TspRefundReq();
......@@ -441,33 +440,28 @@ public class InsuranceServiceImpl extends BaseOrderService implements InsuranceS
tspRefundReq.setSeqNo(insurancePolicy.getInsuranceSeqNo());
this.taskExecutor.defaultThreadPool().execute(() -> {
boolean invokeSuccess;
int retries = API_INVOKE_RETRIES;
try {
TspResp tspResp = this.tspApiInvoker.with(this.appKey, this.secret)
.refund(tspRefundReq);
super.logInfo("TSP接口调用结果", tspResp);
// 判断是否调用成功
invokeSuccess = TspResultCode.SUCCESS.getCode().equals(tspResp.getCode())
&& (tspResp.getData() != null)
&& tspResp.getData().getCallResult();
} catch (RuntimeException e) {
super.logError("TSP接口调用异常", e);
invokeSuccess = false;
}
if (invokeSuccess) {
// 成功,更新字段状态
this.refundManually(insurancePolicy);
}
if (!invokeSuccess && retries > 1) {
// 如果失败并且需要重试则重新退保
while (retries-- > 0) {
try {
Thread.sleep(API_INVOKE_RETRY_DELAY);
this.refundAutomatically(insurancePolicy, retries - 1);
} catch (InterruptedException e) {
super.logError("TSP重试调用错误", e);
TspResp tspResp = this.tspApiInvoker
.with(this.appKey, this.secret)
.refund(tspRefundReq);
super.logInfo("TSP接口调用结果", tspResp);
// 判断是否调用成功
boolean invokeSuccess = TspResultCode.SUCCESS.getCode().equals(
tspResp.getCode());
if (invokeSuccess) {
// 成功,更新字段状态
this.refundManually(insurancePolicy);
break;
} else {
super.logInfo("TSP退保接口返回失败,等待重试", tspResp);
Thread.sleep(API_INVOKE_RETRY_DELAY);
}
} catch (Exception e) {
super.logError("TSP接口调用异常", e);
}
}
});
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!