|
|
|
@ -1,23 +1,20 @@
|
|
|
|
package cn.iocoder.yudao.module.pay.service.transfer;
|
|
|
|
package cn.iocoder.yudao.module.pay.service.transfer;
|
|
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
import cn.hutool.extra.spring.SpringUtil;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.PayClient;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferRespDTO;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.dto.transfer.PayTransferUnifiedReqDTO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.client.exception.PayException;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.channel.PayChannelEnum;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferStatusRespEnum;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferStatusRespEnum;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
|
|
|
import cn.iocoder.yudao.framework.pay.core.enums.transfer.PayTransferTypeEnum;
|
|
|
|
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
|
|
|
import cn.iocoder.yudao.module.pay.api.transfer.dto.PayTransferCreateReqDTO;
|
|
|
|
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitReqVO;
|
|
|
|
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferCreateReqVO;
|
|
|
|
import cn.iocoder.yudao.module.pay.controller.admin.transfer.vo.PayTransferSubmitRespVO;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.app.PayAppDO;
|
|
|
|
import cn.iocoder.yudao.module.pay.convert.transfer.PayTransferConvert;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.channel.PayChannelDO;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferDO;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.dataobject.transfer.PayTransferExtensionDO;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.mysql.transfer.PayTransferExtensionMapper;
|
|
|
|
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.mysql.transfer.PayTransferMapper;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.mysql.transfer.PayTransferMapper;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO;
|
|
|
|
import cn.iocoder.yudao.module.pay.dal.redis.no.PayNoRedisDAO;
|
|
|
|
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum;
|
|
|
|
import cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum;
|
|
|
|
@ -28,8 +25,10 @@ import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import javax.validation.Validator;
|
|
|
|
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
|
|
|
|
|
import static cn.iocoder.yudao.module.pay.convert.transfer.PayTransferConvert.INSTANCE;
|
|
|
|
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
|
|
|
import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.*;
|
|
|
|
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum.*;
|
|
|
|
import static cn.iocoder.yudao.module.pay.enums.transfer.PayTransferStatusEnum.*;
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,61 +46,70 @@ public class PayTransferServiceImpl implements PayTransferService {
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private PayTransferMapper transferMapper;
|
|
|
|
private PayTransferMapper transferMapper;
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private PayTransferExtensionMapper transferExtensionMapper;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private PayAppService appService;
|
|
|
|
private PayAppService appService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private PayChannelService channelService;
|
|
|
|
private PayChannelService channelService;
|
|
|
|
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private PayNoRedisDAO noRedisDAO;
|
|
|
|
private PayNoRedisDAO noRedisDAO;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private Validator validator;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public PayTransferSubmitRespVO submitTransfer(PayTransferSubmitReqVO reqVO, String userIp) {
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public PayTransferDO initiateTransfer(PayTransferCreateReqVO reqVO, String userIp) {
|
|
|
|
|
|
|
|
// 1.1 校验参数
|
|
|
|
|
|
|
|
reqVO.validate(validator);
|
|
|
|
|
|
|
|
// todo 使用 AssertTrue
|
|
|
|
|
|
|
|
validateChannelCodeAndTypeMatch(reqVO.getChannelCode(), reqVO.getType());
|
|
|
|
|
|
|
|
// 1.2 校验转账单是否可以创建
|
|
|
|
|
|
|
|
validateTransferCanCreate(reqVO.getAppId(), reqVO.getMerchantTransferId());
|
|
|
|
|
|
|
|
// 2. 创建转账单,发起转账
|
|
|
|
|
|
|
|
PayTransferCreateReqDTO req = INSTANCE.convert(reqVO).setUserIp(userIp);
|
|
|
|
|
|
|
|
Long transferId = createTransfer(req);
|
|
|
|
|
|
|
|
// 3. 返回转账单
|
|
|
|
|
|
|
|
return getTransfer(transferId);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
|
|
|
public Long createTransfer(PayTransferCreateReqDTO reqDTO) {
|
|
|
|
// 1.1 校验转账单是否可以提交
|
|
|
|
// 1.1 校验转账单是否可以提交
|
|
|
|
PayTransferDO transfer = validateTransferCanSubmit(reqVO.getId());
|
|
|
|
validateTransferExist(reqDTO.getAppId(), reqDTO.getMerchantTransferId());
|
|
|
|
// 1.2 校验转账类型和渠道是否匹配
|
|
|
|
// 1.2 校验 App
|
|
|
|
validateChannelCodeAndTypeMatch(reqVO.getChannelCode(), transfer.getType());
|
|
|
|
PayAppDO appDO = appService.validPayApp(reqDTO.getAppId());
|
|
|
|
// 1.3 校验支付渠道是否有效
|
|
|
|
// 1.3 校验支付渠道是否有效
|
|
|
|
PayChannelDO channel = validateChannelCanSubmit(transfer.getAppId(), reqVO.getChannelCode());
|
|
|
|
PayChannelDO channel = channelService.validPayChannel(reqDTO.getAppId(), reqDTO.getChannelCode());
|
|
|
|
PayClient client = channelService.getPayClient(channel.getId());
|
|
|
|
PayClient client = channelService.getPayClient(channel.getId());
|
|
|
|
|
|
|
|
if (client == null) {
|
|
|
|
// 2. 新增转账拓展单
|
|
|
|
log.error("[createTransfer][渠道编号({}) 找不到对应的支付客户端]", channel.getId());
|
|
|
|
|
|
|
|
throw exception(CHANNEL_NOT_FOUND);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2.创建转账单
|
|
|
|
String no = noRedisDAO.generate(TRANSFER_NO_PREFIX);
|
|
|
|
String no = noRedisDAO.generate(TRANSFER_NO_PREFIX);
|
|
|
|
PayTransferExtensionDO transferExtension = new PayTransferExtensionDO().setNo(no)
|
|
|
|
PayTransferDO transfer = INSTANCE.convert(reqDTO)
|
|
|
|
.setTransferId(transfer.getId()).setChannelId(channel.getId())
|
|
|
|
.setChannelId(channel.getId())
|
|
|
|
.setChannelCode(channel.getCode()).setStatus(WAITING.getStatus());
|
|
|
|
.setNo(no).setStatus(WAITING.getStatus())
|
|
|
|
transferExtensionMapper.insert(transferExtension);
|
|
|
|
.setNotifyUrl(appDO.getRefundNotifyUrl()); // TODO 需要加个transfer Notify url
|
|
|
|
|
|
|
|
transferMapper.insert(transfer);
|
|
|
|
// 3. 调用三方渠道发起转账
|
|
|
|
try {
|
|
|
|
PayTransferUnifiedReqDTO transferUnifiedReq = new PayTransferUnifiedReqDTO()
|
|
|
|
// 3. 调用三方渠道发起转账
|
|
|
|
.setOutTransferNo(transferExtension.getNo()).setPrice(transfer.getPrice())
|
|
|
|
PayTransferUnifiedReqDTO transferUnifiedReq = INSTANCE.convert2(reqDTO)
|
|
|
|
.setType(transfer.getType()).setTitle(transfer.getSubject())
|
|
|
|
.setOutTransferNo(no);
|
|
|
|
.setUserIp(userIp)
|
|
|
|
PayTransferRespDTO unifiedTransferResp = client.unifiedTransfer(transferUnifiedReq);
|
|
|
|
.setChannelExtras(reqVO.getChannelExtras());
|
|
|
|
// 4. 通知转账结果
|
|
|
|
PayTransferRespDTO unifiedTransferResp = client.unifiedTransfer(transferUnifiedReq);
|
|
|
|
getSelf().notifyTransfer(channel, unifiedTransferResp);
|
|
|
|
|
|
|
|
} catch (PayException e) {
|
|
|
|
// 4. 通知转账结果
|
|
|
|
// 这里仅打印异常,不进行抛出。
|
|
|
|
getSelf().notifyTransfer(channel, unifiedTransferResp);
|
|
|
|
// TODO 说明
|
|
|
|
// 如有渠道错误码,则抛出业务异常,提示用户
|
|
|
|
log.error("[createTransfer][转账 id({}) requestDTO({}) 发生异常]", transfer.getId(), reqDTO, e);
|
|
|
|
if (StrUtil.isNotEmpty(unifiedTransferResp.getChannelErrorCode())) {
|
|
|
|
|
|
|
|
throw exception(PAY_TRANSFER_SUBMIT_CHANNEL_ERROR, unifiedTransferResp.getChannelErrorCode(),
|
|
|
|
|
|
|
|
unifiedTransferResp.getChannelErrorMsg());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new PayTransferSubmitRespVO().setStatus(unifiedTransferResp.getStatus());
|
|
|
|
return transfer.getId();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public Long createTransfer(PayTransferCreateReqDTO reqDTO) {
|
|
|
|
public PayTransferDO getTransfer(Long id) {
|
|
|
|
// 校验 App
|
|
|
|
return transferMapper.selectById(id);
|
|
|
|
appService.validPayApp(reqDTO.getAppId());
|
|
|
|
|
|
|
|
// 创建转账单
|
|
|
|
|
|
|
|
PayTransferDO transfer = PayTransferConvert.INSTANCE.convert(reqDTO)
|
|
|
|
|
|
|
|
.setStatus(WAITING.getStatus());
|
|
|
|
|
|
|
|
transferMapper.insert(transfer);
|
|
|
|
|
|
|
|
return transfer.getId();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@ -119,26 +127,38 @@ public class PayTransferServiceImpl implements PayTransferService {
|
|
|
|
// TODO IN_PROGRESS 待处理
|
|
|
|
// TODO IN_PROGRESS 待处理
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void notifyTransferSuccess(PayChannelDO channel, PayTransferRespDTO notify) {
|
|
|
|
private void validateTransferExist(Long appId, String merchantTransferId ) {
|
|
|
|
// 1. 更新 PayTransferExtensionDO 转账成功
|
|
|
|
PayTransferDO transfer = transferMapper.selectByAppIdAndMerchantTransferId(appId, merchantTransferId);
|
|
|
|
PayTransferExtensionDO transferExtension = updateTransferExtensionSuccess(notify);
|
|
|
|
if (transfer != null) { // 是否存在
|
|
|
|
|
|
|
|
throw exception(PAY_TRANSFER_EXISTS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 更新 PayTransferDO 转账成功
|
|
|
|
private void validateTransferCanCreate(Long appId, String merchantTransferId ) {
|
|
|
|
Boolean transferred = updateTransferSuccess(channel,transferExtension, notify);
|
|
|
|
PayTransferDO transfer = transferMapper.selectByAppIdAndMerchantTransferId(appId, merchantTransferId);
|
|
|
|
|
|
|
|
if (transfer != null) { // 是否存在
|
|
|
|
|
|
|
|
throw exception(PAY_MERCHANT_TRANSFER_EXISTS);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void notifyTransferSuccess(PayChannelDO channel, PayTransferRespDTO notify) {
|
|
|
|
|
|
|
|
// 1. 更新 PayTransferDO 转账成功
|
|
|
|
|
|
|
|
Boolean transferred = updateTransferSuccess(channel, notify);
|
|
|
|
if (transferred) {
|
|
|
|
if (transferred) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 3. TODO 插入转账通知记录
|
|
|
|
// 2. TODO 插入转账通知记录
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Boolean updateTransferSuccess(PayChannelDO channel, PayTransferExtensionDO transferExtension,
|
|
|
|
private Boolean updateTransferSuccess(PayChannelDO channel, PayTransferRespDTO notify) {
|
|
|
|
PayTransferRespDTO notify) {
|
|
|
|
|
|
|
|
// 1.校验
|
|
|
|
// 1.校验
|
|
|
|
PayTransferDO transfer = transferMapper.selectById(transferExtension.getTransferId());
|
|
|
|
PayTransferDO transfer = transferMapper.selectByNo(notify.getOutTransferNo());
|
|
|
|
if (transfer == null) {
|
|
|
|
if (transfer == null) {
|
|
|
|
throw exception(PAY_TRANSFER_NOT_FOUND);
|
|
|
|
throw exception(PAY_TRANSFER_NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSuccess(transfer.getStatus())) { // 如果已成功,直接返回,不用重复更新
|
|
|
|
|
|
|
|
return Boolean.TRUE;
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!isPendingStatus(transfer.getStatus())) {
|
|
|
|
if (!isPendingStatus(transfer.getStatus())) {
|
|
|
|
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
|
|
|
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -146,76 +166,52 @@ public class PayTransferServiceImpl implements PayTransferService {
|
|
|
|
int updateCounts = transferMapper.updateByIdAndStatus(transfer.getId(),
|
|
|
|
int updateCounts = transferMapper.updateByIdAndStatus(transfer.getId(),
|
|
|
|
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
|
|
|
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
|
|
|
new PayTransferDO().setStatus(SUCCESS.getStatus()).setSuccessTime(notify.getSuccessTime())
|
|
|
|
new PayTransferDO().setStatus(SUCCESS.getStatus()).setSuccessTime(notify.getSuccessTime())
|
|
|
|
|
|
|
|
.setChannelTransferNo(notify.getChannelTransferNo())
|
|
|
|
.setChannelId(channel.getId()).setChannelCode(channel.getCode())
|
|
|
|
.setChannelId(channel.getId()).setChannelCode(channel.getCode())
|
|
|
|
.setNo(transferExtension.getNo()));
|
|
|
|
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
|
|
|
if (updateCounts == 0) {
|
|
|
|
if (updateCounts == 0) {
|
|
|
|
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
|
|
|
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.info("[updateTransferSuccess][transfer({}) 更新为已转账]", transfer.getId());
|
|
|
|
log.info("[updateTransferSuccess][transfer({}) 更新为已转账]", transfer.getId());
|
|
|
|
return false;
|
|
|
|
return Boolean.FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private PayTransferExtensionDO updateTransferExtensionSuccess(PayTransferRespDTO notify) {
|
|
|
|
private void updateTransferClosed(PayChannelDO channel, PayTransferRespDTO notify) {
|
|
|
|
// 1 校验
|
|
|
|
// 1.校验
|
|
|
|
PayTransferExtensionDO transferExtension = transferExtensionMapper.selectByNo(notify.getOutTransferNo());
|
|
|
|
PayTransferDO transfer = transferMapper.selectByNo(notify.getOutTransferNo());
|
|
|
|
if (transferExtension == null) {
|
|
|
|
if (transfer == null) {
|
|
|
|
throw exception(PAY_TRANSFER_EXTENSION_NOT_FOUND);
|
|
|
|
throw exception(PAY_TRANSFER_NOT_FOUND);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isSuccess(transferExtension.getStatus())) { // 如果已成功,直接返回,不用重复更新
|
|
|
|
if (isClosed(transfer.getStatus())) { // 如果已是关闭状态,直接返回,不用重复更新
|
|
|
|
log.info("[updateTransferExtensionSuccess][transferExtension({}) 已经是成功状态,无需更新]", transferExtension.getId());
|
|
|
|
log.info("[updateTransferClosed][transfer({}) 已经是关闭状态,无需更新]", transfer.getId());
|
|
|
|
return transferExtension;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isPendingStatus(transferExtension.getStatus())) {
|
|
|
|
if (!isPendingStatus(transfer.getStatus())) {
|
|
|
|
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
|
|
|
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 2. 更新 PayTransferExtensionDO
|
|
|
|
// 2.更新
|
|
|
|
int updateCount = transferExtensionMapper.updateByIdAndStatus(transferExtension.getId(),
|
|
|
|
int updateCount = transferMapper.updateByIdAndStatus(transfer.getId(),
|
|
|
|
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
|
|
|
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
|
|
|
new PayTransferExtensionDO().setStatus(SUCCESS.getStatus())
|
|
|
|
new PayTransferDO().setStatus(CLOSED.getStatus()) .setChannelId(channel.getId())
|
|
|
|
|
|
|
|
.setChannelCode(channel.getCode()).setChannelTransferNo(notify.getChannelTransferNo())
|
|
|
|
|
|
|
|
.setChannelErrorCode(notify.getChannelErrorCode()).setChannelErrorMsg(notify.getChannelErrorMsg())
|
|
|
|
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
|
|
|
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
|
|
|
if (updateCount == 0) {
|
|
|
|
if (updateCount == 0) {
|
|
|
|
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
|
|
|
throw exception(PAY_TRANSFER_STATUS_IS_NOT_PENDING);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
log.info("[updateTransferExtensionSuccess][transferExtension({}) 更新为已转账]", transferExtension.getId());
|
|
|
|
log.info("[updateTransferClosed][transfer({}) 更新为关闭状态]", transfer.getId());
|
|
|
|
return transferExtension;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void notifyTransferClosed(PayChannelDO channel, PayTransferRespDTO notify) {
|
|
|
|
private void notifyTransferClosed(PayChannelDO channel, PayTransferRespDTO notify) {
|
|
|
|
// 更新 PayTransferExtensionDO 转账关闭
|
|
|
|
// 更新 PayTransferDO 转账关闭
|
|
|
|
updateTransferExtensionClosed(notify);
|
|
|
|
updateTransferClosed(channel,notify);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void updateTransferExtensionClosed(PayTransferRespDTO notify) {
|
|
|
|
|
|
|
|
// 1 校验
|
|
|
|
|
|
|
|
PayTransferExtensionDO transferExtension = transferExtensionMapper.selectByNo(notify.getOutTransferNo());
|
|
|
|
|
|
|
|
if (transferExtension == null) {
|
|
|
|
|
|
|
|
throw exception(PAY_TRANSFER_EXTENSION_NOT_FOUND);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isClosed(transferExtension.getStatus())) { // 如果已是关闭状态,直接返回,不用重复更新
|
|
|
|
|
|
|
|
log.info("[updateTransferExtensionSuccess][transferExtension({}) 已经是关闭状态,无需更新]", transferExtension.getId());
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isPendingStatus(transferExtension.getStatus())) {
|
|
|
|
|
|
|
|
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 2. 更新 PayTransferExtensionDO
|
|
|
|
|
|
|
|
int updateCount = transferExtensionMapper.updateByIdAndStatus(transferExtension.getId(),
|
|
|
|
|
|
|
|
CollUtil.newArrayList(WAITING.getStatus(), IN_PROGRESS.getStatus()),
|
|
|
|
|
|
|
|
new PayTransferExtensionDO().setStatus(CLOSED.getStatus())
|
|
|
|
|
|
|
|
.setChannelNotifyData(JsonUtils.toJsonString(notify)));
|
|
|
|
|
|
|
|
if (updateCount == 0) {
|
|
|
|
|
|
|
|
throw exception(PAY_TRANSFER_EXTENSION_STATUS_IS_NOT_PENDING);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
log.info("[updateTransferExtensionSuccess][transferExtension({}) 更新为关闭状态]", transferExtension.getId());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void validateChannelCodeAndTypeMatch(String channelCode, Integer type) {
|
|
|
|
private void validateChannelCodeAndTypeMatch(String channelCode, Integer type) {
|
|
|
|
PayTransferTypeEnum transferType = PayTransferTypeEnum.typeOf(type);
|
|
|
|
PayTransferTypeEnum transferType = PayTransferTypeEnum.typeOf(type);
|
|
|
|
PayChannelEnum payChannel = PayChannelEnum.getByCode(channelCode);
|
|
|
|
|
|
|
|
switch (transferType) {
|
|
|
|
switch (transferType) {
|
|
|
|
case ALIPAY_BALANCE: {
|
|
|
|
case ALIPAY_BALANCE: {
|
|
|
|
// TODO @jason:可以抽到 PayChannelEnum 里,isAlipay? 类似这种哈
|
|
|
|
if (!PayChannelEnum.isAlipay(channelCode)) {
|
|
|
|
if (!payChannel.getCode().startsWith("alipay")) {
|
|
|
|
|
|
|
|
throw exception(PAY_TRANSFER_TYPE_AND_CHANNEL_NOT_MATCH);
|
|
|
|
throw exception(PAY_TRANSFER_TYPE_AND_CHANNEL_NOT_MATCH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
@ -241,7 +237,7 @@ public class PayTransferServiceImpl implements PayTransferService {
|
|
|
|
return channel;
|
|
|
|
return channel;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private PayTransferDO validateTransferCanSubmit(Long id) {
|
|
|
|
private PayTransferDO validateTransferExist(Long id) {
|
|
|
|
PayTransferDO transfer = transferMapper.selectById(id);
|
|
|
|
PayTransferDO transfer = transferMapper.selectById(id);
|
|
|
|
if (transfer == null) { // 是否存在
|
|
|
|
if (transfer == null) { // 是否存在
|
|
|
|
throw exception(PAY_TRANSFER_NOT_FOUND);
|
|
|
|
throw exception(PAY_TRANSFER_NOT_FOUND);
|
|
|
|
|