|
|
@@ -16,9 +16,7 @@ import com.yc.ship.framework.mybatis.core.util.MyBatisUtils;
|
|
|
import com.yc.ship.module.infra.api.config.ConfigApi;
|
|
|
import com.yc.ship.module.product.dal.dataobject.voyage.VoyageDO;
|
|
|
import com.yc.ship.module.product.service.voyage.VoyageService;
|
|
|
-import com.yc.ship.module.trade.api.insurance.dto.InsuranceApplyReqDTO;
|
|
|
-import com.yc.ship.module.trade.api.insurance.dto.InsuranceOrderInfoDTO;
|
|
|
-import com.yc.ship.module.trade.api.insurance.dto.InsuredDTO;
|
|
|
+import com.yc.ship.module.trade.api.insurance.dto.*;
|
|
|
import com.yc.ship.module.trade.controller.admin.insurance.vo.InsuranceData;
|
|
|
import com.yc.ship.module.trade.controller.admin.insurance.vo.InsurancePageReqVO;
|
|
|
import com.yc.ship.module.trade.controller.admin.insurance.vo.InsuranceRespVO;
|
|
|
@@ -183,7 +181,6 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
// 开始投保
|
|
|
CommonResult commonResult = insuranceUtil.sendInsuranceApply(insuranceApplyReqDTO);
|
|
|
if(!commonResult.isSuccess()) {
|
|
|
- Object checkedData = commonResult.getCheckedData();
|
|
|
throw exception0(commonResult.getCode(),commonResult.getMsg());
|
|
|
}
|
|
|
//保存投保信息
|
|
|
@@ -229,89 +226,45 @@ public class InsuranceServiceImpl implements InsuranceService {
|
|
|
/**
|
|
|
* 退保
|
|
|
*
|
|
|
- * @param orderIdList
|
|
|
+ * @param orderId
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void applyCancelInsurance(List<Long> orderIdList) {
|
|
|
- try {
|
|
|
- List<InsuranceDO> insuranceList = this.getInsuranceByOrder(orderIdList);
|
|
|
- if (CollUtil.isNotEmpty(insuranceList)) {
|
|
|
- for (InsuranceDO insuranceDB : insuranceList) {
|
|
|
-
|
|
|
- JSONObject head = this.getCommonHead(insuranceDB.getRationType(), insuranceDB.getRiskCode(), "SURRENDER");
|
|
|
- JSONObject cancelInsurance = new JSONObject();
|
|
|
- //订单号
|
|
|
- cancelInsurance.set("orderNo", insuranceDB.getInsuranceNo());
|
|
|
- //要进行注销的保单号
|
|
|
- cancelInsurance.set("policyNo", insuranceDB.getPolicyNo());
|
|
|
- //渠道标识
|
|
|
- cancelInsurance.set("sysFlag", configApi.getConfigValueByKey("insurance.sysflag"));
|
|
|
- //交易码
|
|
|
- cancelInsurance.set("taCode", configApi.getConfigValueByKey("insurance.taCode"));
|
|
|
- //保单退保时间
|
|
|
- cancelInsurance.set("surrenderTime", System.currentTimeMillis() + "");
|
|
|
- cancelInsurance.set("centerFlag", "JDX");
|
|
|
- List<JSONObject> writeOffPolicys = new ArrayList<>();
|
|
|
- writeOffPolicys.add(cancelInsurance);
|
|
|
-
|
|
|
- JSONObject request = new JSONObject();
|
|
|
- request.set("head", head);
|
|
|
- request.set("writeOffPolicys", writeOffPolicys);
|
|
|
-
|
|
|
- JSONObject insuranceRequest = new JSONObject();
|
|
|
- insuranceRequest.set("appKey", configApi.getConfigValueByKey("insurance.appKey"));
|
|
|
- insuranceRequest.set("timestamp", System.currentTimeMillis() + "");
|
|
|
- insuranceRequest.set("serviceName", "writeOff");
|
|
|
- insuranceRequest.set("version", configApi.getConfigValueByKey("insurance.version"));
|
|
|
- insuranceRequest.set("encryptType", ENCRYPT_TYPE);
|
|
|
- insuranceRequest.set("bizContent", JSONUtil.toJsonStr(request));
|
|
|
- String publicKey = configApi.getConfigValueByKey("insurance.publicKey");
|
|
|
- String privateKey = configApi.getConfigValueByKey("insurance.privateKey");
|
|
|
- //加密加签
|
|
|
- InsuranceRequestHelper.encryptAndSign(insuranceRequest, publicKey, privateKey);
|
|
|
- String url = configApi.getConfigValueByKey("insurance.url");
|
|
|
-
|
|
|
- RLock lock = redissonClient.getLock(INSURANCE_CANCEL_KEY + insuranceDB.getOrderId());
|
|
|
- try {
|
|
|
- if (lock.tryLock(10, 30, TimeUnit.SECONDS)) {
|
|
|
- log.error("保险开具申请 data=" + JSONUtil.toJsonStr(insuranceRequest));
|
|
|
- String result = HttpUtil.createPost(url + "/writeOff").contentType("application/json").body(JSONUtil.toJsonStr(insuranceRequest)).timeout(15000).execute().body();
|
|
|
- log.error("保险开具申请 result=" + result);
|
|
|
- JSONObject insuranceResponse = JSONUtil.parseObj(result);
|
|
|
- InsuranceRequestHelper.checkSignAndDecrypt(insuranceResponse, publicKey, privateKey);
|
|
|
- // 0:失败 1:成功
|
|
|
- if (insuranceResponse != null && "200".equals(insuranceResponse.get("code"))) {
|
|
|
- String data = insuranceResponse.get("data").toString();
|
|
|
- if (data != null) {
|
|
|
- InsuranceData insuranceData = JSONUtil.toBean(data, InsuranceData.class);
|
|
|
-
|
|
|
- if (insuranceData != null && "SUCCESS".equalsIgnoreCase(insuranceData.getHccResults().get(0).getCode())) {
|
|
|
- insuranceDB.setInsuranceStatus(InsuranceStatusEnum.CANCELLED.getValue());
|
|
|
- insuranceMapper.updateById(insuranceDB);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ public void applyCancelInsurance(Long orderId) {
|
|
|
+ TradeOrderRespVO orderInfo = tradeOrderMapper.getOrderInfo(orderId);
|
|
|
+ VoyageDO voyage = voyageService.getVoyage(orderInfo.getVoyageId());
|
|
|
|
|
|
- } else {
|
|
|
- log.error("保险取消异常:未获取到锁" );
|
|
|
- throw exception(INSURE_CANCEL_FAILED);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- log.error("保险取消异常,:", e);
|
|
|
- throw exception(INSURE_CANCEL_FAILED);
|
|
|
- } finally {
|
|
|
- if (lock.isLocked() && lock.isHeldByCurrentThread()) {
|
|
|
- lock.unlock();
|
|
|
- }
|
|
|
- }
|
|
|
+ //获取投保记录,投保保单号
|
|
|
+ InsuranceDO insuranceDO = insuranceMapper.selectByOrderId(orderId);
|
|
|
|
|
|
- }
|
|
|
- }
|
|
|
+ InsuranceCancelReqDTO insuranceCancelReqDTO = new InsuranceCancelReqDTO();
|
|
|
+ insuranceCancelReqDTO.setService("cancel");
|
|
|
+ insuranceCancelReqDTO.setReplyUrl(notifyUrl);
|
|
|
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- throw exception(INSURE_CANCEL_FAILED);
|
|
|
+ //订单对象, 一个订单下可以有一批被保险人
|
|
|
+ InsuranceOrderInfoCancelDTO insuranceOrderInfoDTO = new InsuranceOrderInfoCancelDTO();
|
|
|
+
|
|
|
+ insuranceOrderInfoDTO.setExternalOrderNo(orderInfo.getOrderNo());
|
|
|
+ insuranceOrderInfoDTO.setBeginDate(DateUtil.format(voyage.getBoardingTime(), "yyyy-MM-dd"));
|
|
|
+ insuranceOrderInfoDTO.setEndDate(DateUtil.format(voyage.getLeaveTime(), "yyyy-MM-dd"));
|
|
|
+ insuranceCancelReqDTO.setOrder(insuranceOrderInfoDTO);
|
|
|
+
|
|
|
+ List<InsuredCancelDTO> insuredList = new ArrayList<>();
|
|
|
+ InsuredCancelDTO insuredDTO = new InsuredCancelDTO();
|
|
|
+ insuredDTO.setExternalPolicyNumber(orderInfo.getId().toString());
|
|
|
+ insuredDTO.setExternalPolicyNumber(insuranceDO.getInsuranceNo());
|
|
|
+ insuredList.add(insuredDTO);
|
|
|
+ insuranceCancelReqDTO.setInsureds(insuredList);
|
|
|
+
|
|
|
+ //验证投保信息
|
|
|
+// CommonResult commonResult = insuranceUtil.validateInsuranceRequest(insuranceApplyReqDTO);
|
|
|
+// if(!commonResult.isSuccess()) {
|
|
|
+// throw exception0(commonResult.getCode(),commonResult.getMsg());
|
|
|
+// }
|
|
|
+ // 开始投保
|
|
|
+ CommonResult commonResult = insuranceUtil.sendInsuranceCancel(insuranceCancelReqDTO);
|
|
|
+ if(!commonResult.isSuccess()) {
|
|
|
+ throw exception0(commonResult.getCode(),commonResult.getMsg());
|
|
|
}
|
|
|
}
|
|
|
|