feat 一些常量名称更改, 查询字段添加

This commit is contained in:
bootx
2024-02-01 22:18:05 +08:00
parent e05af18c2b
commit dd1d70dcfb
20 changed files with 94 additions and 68 deletions

View File

@@ -14,7 +14,8 @@ public enum PayRepairSourceEnum{
SYNC("sync","同步"),
CALLBACK("callback","回调"),
RECONCILE("reconcile","对账"),;
TASK("task","定时任务"),
RECONCILE("reconcile","对账");
private final String code;
private final String name;

View File

@@ -12,11 +12,11 @@ import lombok.Getter;
@AllArgsConstructor
public enum PayRepairWayEnum {
SUCCESS("success","支付成功"),
CLOSE_LOCAL("close_local","关闭本地支付"),
WAIT_PAY("wait_pay","支付"),
SUCCESS("pay_success","支付成功"),
CLOSE_LOCAL("pay_close_local","关闭本地支付"),
PROGRESS("pay_progress","切换到支付"),
/** 同时也会关闭本地支付 */
CLOSE_GATEWAY("close_gateway","关闭网关支付");
CLOSE_GATEWAY("pay_close_gateway","关闭网关支付");
private final String code;
private final String name;

View File

@@ -12,8 +12,8 @@ import lombok.Getter;
@AllArgsConstructor
public enum RefundRepairWayEnum {
SUCCESS("success","退款成功"),
FAIL("fail","退款失败");
SUCCESS("refund_success","退款成功"),
FAIL("refund_fail","退款失败");
private final String code;
private final String name;

View File

@@ -4,8 +4,6 @@ import cn.bootx.platform.common.core.util.LocalDateTimeUtil;
import cn.bootx.platform.daxpay.code.PayRefundSyncStatusEnum;
import cn.bootx.platform.daxpay.code.PaySyncStatusEnum;
import cn.bootx.platform.daxpay.service.code.AliPayCode;
import cn.bootx.platform.daxpay.service.common.context.PaySyncLocal;
import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal;
import cn.bootx.platform.daxpay.service.core.order.pay.entity.PayOrder;
import cn.bootx.platform.daxpay.service.core.order.refund.entity.PayRefundOrder;
import cn.bootx.platform.daxpay.service.core.payment.sync.result.PayGatewaySyncResult;
@@ -46,34 +44,25 @@ public class AliPaySyncService {
* 5 查询失败
*/
public PayGatewaySyncResult syncPayStatus(PayOrder payOrder) {
PaySyncLocal paySyncLocal = PaymentContextLocal.get().getPaySyncInfo();
PayGatewaySyncResult syncResult = new PayGatewaySyncResult().setSyncStatus(PaySyncStatusEnum.FAIL);
// 查询
try {
AlipayTradeQueryModel queryModel = new AlipayTradeQueryModel();
queryModel.setOutTradeNo(String.valueOf(payOrder.getId()));
// queryModel.setQueryOptions(Collections.singletonList("trade_settle_info"));
AlipayTradeQueryResponse response = AliPayApi.tradeQueryToResponse(queryModel);
String tradeStatus = response.getTradeStatus();
syncResult.setSyncInfo(JSONUtil.toJsonStr(response));
// 失败
if (!Objects.equals(AliPayCode.SUCCESS, response.getCode())) {
syncResult.setSyncStatus(PaySyncStatusEnum.FAIL);
syncResult.setErrorCode(response.getSubCode());
syncResult.setErrorMsg(response.getSubMsg());
return syncResult;
}
// 设置网关订单号
syncResult.setGatewayOrderNo(response.getTradeNo());
// 支付完成 TODO 部分退款也在这个地方, 但无法进行区分, 需要借助对账进行处理
if (Objects.equals(tradeStatus, AliPayCode.NOTIFY_TRADE_SUCCESS) || Objects.equals(tradeStatus, AliPayCode.NOTIFY_TRADE_FINISHED)) {
// 支付完成时间
LocalDateTime payTime = LocalDateTimeUtil.of(response.getSendPayDate());
return syncResult.setSyncStatus(PaySyncStatusEnum.PAY_SUCCESS).setPayTime(payTime);
return syncResult.setSyncStatus(PaySyncStatusEnum.SUCCESS).setPayTime(payTime);
}
// 待支付
if (Objects.equals(tradeStatus, AliPayCode.NOTIFY_WAIT_BUYER_PAY)) {
return syncResult.setSyncStatus(PaySyncStatusEnum.PAY_WAIT);
return syncResult.setSyncStatus(PaySyncStatusEnum.PROGRESS);
}
// 已关闭或支付完成后全额退款
if (Objects.equals(tradeStatus, AliPayCode.NOTIFY_TRADE_CLOSED)) {
@@ -88,6 +77,13 @@ public class AliPaySyncService {
if (Objects.equals(response.getSubCode(), AliPayCode.ACQ_TRADE_NOT_EXIST)) {
return syncResult.setSyncStatus(PaySyncStatusEnum.NOT_FOUND_UNKNOWN);
}
// 查询失败
if (!Objects.equals(AliPayCode.SUCCESS, response.getCode())) {
syncResult.setSyncStatus(PaySyncStatusEnum.FAIL);
syncResult.setErrorCode(response.getSubCode());
syncResult.setErrorMsg(response.getSubMsg());
return syncResult;
}
}
catch (AlipayApiException e) {
log.error("支付订单同步失败:", e);

View File

@@ -39,7 +39,7 @@ import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import static cn.bootx.platform.daxpay.code.PaySyncStatusEnum.PAY_WAIT;
import static cn.bootx.platform.daxpay.code.PaySyncStatusEnum.PROGRESS;
import static com.ijpay.wxpay.model.UnifiedOrderModel.UnifiedOrderModelBuilder;
import static com.ijpay.wxpay.model.UnifiedOrderModel.builder;
@@ -270,7 +270,7 @@ public class WeChatPayService {
public void rotationSync(PayOrder payOrder) {
SyncResult syncResult = paySyncService.syncPayOrder(payOrder);
// 不为支付中状态后, 调用系统同步更新状态, 支付状态则继续重试
if (Objects.equals(PAY_WAIT.getCode(), syncResult.getGatewayStatus())) {
if (Objects.equals(PROGRESS.getCode(), syncResult.getGatewayStatus())) {
throw new RetryableException();
}
}

View File

@@ -73,12 +73,12 @@ public class WeChatPaySyncService {
if (Objects.equals(tradeStatus, WeChatPayCode.PAY_SUCCESS) || Objects.equals(tradeStatus, WeChatPayCode.PAY_ACCEPT)) {
String timeEnd = result.get(WeChatPayCode.TIME_END);
LocalDateTime time = LocalDateTimeUtil.parse(timeEnd, DatePattern.PURE_DATETIME_PATTERN);
return syncResult.setPayTime(time).setSyncStatus(PaySyncStatusEnum.PAY_SUCCESS);
return syncResult.setPayTime(time).setSyncStatus(PaySyncStatusEnum.SUCCESS);
}
// 待支付
if (Objects.equals(tradeStatus, WeChatPayCode.PAY_NOTPAY)
|| Objects.equals(tradeStatus, WeChatPayCode.PAY_USERPAYING)) {
return syncResult.setSyncStatus(PaySyncStatusEnum.PAY_WAIT);
return syncResult.setSyncStatus(PaySyncStatusEnum.PROGRESS);
}
// 已退款/退款中
@@ -130,12 +130,12 @@ public class WeChatPaySyncService {
}
// 退款中
if (Objects.equals(tradeStatus, WeChatPayCode.REFUND_PROCESSING)) {
return syncResult.setSyncStatus(PayRefundSyncStatusEnum.REFUNDING);
return syncResult.setSyncStatus(PayRefundSyncStatusEnum.PROGRESS);
}
return syncResult.setSyncStatus(PayRefundSyncStatusEnum.FAIL);
} catch (Exception e) {
log.error("查询退款订单失败:", e);
syncResult.setSyncStatus(PayRefundSyncStatusEnum.REFUNDING).setErrorMsg(e.getMessage());
syncResult.setSyncStatus(PayRefundSyncStatusEnum.PROGRESS).setErrorMsg(e.getMessage());
}
return syncResult;

View File

@@ -213,7 +213,7 @@ public class PayService {
payStrategyList.forEach(AbsPayStrategy::doSuccessHandler);
// 6. 更新支付订单和扩展参数
// payOrderService.updateById(payOrder);
payOrderService.updateById(payOrder);
payAssistService.updatePayOrderExtra(payParam,payOrder.getId());
// 7. 组装返回参数

View File

@@ -87,6 +87,7 @@ public class AliPayStrategy extends AbsPayStrategy {
@Override
public void doSuccessHandler() {
channelOrderService.switchAsyncPayChannel(this.getOrder(), this.getPayChannelParam());
this.getOrder().setAsyncChannel(this.getChannel().getCode());
}
/**

View File

@@ -92,6 +92,7 @@ public class WeChatPayStrategy extends AbsPayStrategy {
@Override
public void doSuccessHandler() {
channelOrderService.switchAsyncPayChannel(this.getOrder(), this.getPayChannelParam());
this.getOrder().setAsyncChannel(this.getChannel().getCode());
}
/**

View File

@@ -75,7 +75,7 @@ public class PayRepairService {
this.closeLocal(order, repairStrategies);
repairResult.setAfterPayStatus(PayStatusEnum.CLOSE);
break;
case WAIT_PAY:
case PROGRESS:
this.waitPay(order, repairStrategies);
repairResult.setAfterPayStatus(PayStatusEnum.PROGRESS);
break;

View File

@@ -6,7 +6,7 @@ import lombok.experimental.Accessors;
import java.time.LocalDateTime;
import static cn.bootx.platform.daxpay.code.PayRefundSyncStatusEnum.REFUNDING;
import static cn.bootx.platform.daxpay.code.PayRefundSyncStatusEnum.PROGRESS;
/**
* 支付退款同步结果
@@ -21,7 +21,7 @@ public class RefundGatewaySyncResult {
* 支付网关订单状态, 默认为退款中
* @see PayRefundSyncStatusEnum
*/
private PayRefundSyncStatusEnum syncStatus = REFUNDING;
private PayRefundSyncStatusEnum syncStatus = PROGRESS;
/** 同步时网关返回的对象, 序列化为json字符串 */
private String syncInfo;

View File

@@ -98,7 +98,7 @@ public class PayRefundSyncService {
return new SyncResult().setErrorMsg(syncResult.getErrorMsg());
}
// 支付订单的网关订单号是否一致, 不一致进行更新
if (!Objects.equals(syncResult.getGatewayOrderNo(), refundOrder.getGatewayOrderNo())){
if (Objects.nonNull(syncResult.getGatewayOrderNo()) && !Objects.equals(syncResult.getGatewayOrderNo(), refundOrder.getGatewayOrderNo())){
refundOrder.setGatewayOrderNo(syncResult.getGatewayOrderNo());
refundOrderManager.updateById(refundOrder);
}
@@ -155,7 +155,7 @@ public class PayRefundSyncService {
return true;
}
// 退款中
if (Objects.equals(syncStatus, PayRefundSyncStatusEnum.REFUNDING)&&
if (Objects.equals(syncStatus, PayRefundSyncStatusEnum.PROGRESS)&&
Objects.equals(orderStatus, PayRefundStatusEnum.PROGRESS.getCode())) {
return true;
}
@@ -174,7 +174,7 @@ public class PayRefundSyncService {
case SUCCESS:
repair = repairService.repair(order, RefundRepairWayEnum.SUCCESS);
break;
case REFUNDING:
case PROGRESS:
// 不进行处理 TODO 添加重试
log.warn("退款状态同步接口调用出错");
break;

View File

@@ -106,7 +106,7 @@ public class PaySyncService {
return new SyncResult().setErrorMsg(syncResult.getErrorMsg());
}
// 支付订单的网关订单号是否一致, 不一致进行更新
if (!Objects.equals(syncResult.getGatewayOrderNo(), payOrder.getGatewayOrderNo())){
if (Objects.nonNull(syncResult.getGatewayOrderNo()) && !Objects.equals(syncResult.getGatewayOrderNo(), payOrder.getGatewayOrderNo())){
payOrder.setGatewayOrderNo(syncResult.getGatewayOrderNo());
payOrderService.updateById(payOrder);
}
@@ -151,7 +151,7 @@ public class PaySyncService {
PaySyncStatusEnum syncStatus = syncResult.getSyncStatus();
String orderStatus = order.getStatus();
// 本地支付成功/网关支付成功
if (orderStatus.equals(PayStatusEnum.SUCCESS.getCode()) && syncStatus.equals(PAY_SUCCESS)){
if (orderStatus.equals(PayStatusEnum.SUCCESS.getCode()) && syncStatus.equals(SUCCESS)){
return true;
}
@@ -159,7 +159,7 @@ public class PaySyncService {
本地支付中/网关支付中或者订单未找到(未知) 支付宝特殊情况,未找到订单可能是发起支付用户未操作、支付已关闭、交易未找到三种情况
所以需要根据本地订单不同的状态进行特殊处理
*/
List<PaySyncStatusEnum> syncWaitEnums = Arrays.asList(PAY_WAIT, NOT_FOUND_UNKNOWN);
List<PaySyncStatusEnum> syncWaitEnums = Arrays.asList(PROGRESS, NOT_FOUND_UNKNOWN);
if (orderStatus.equals(PayStatusEnum.PROGRESS.getCode()) && syncWaitEnums.contains(syncStatus)){
// 判断支付单是否支付超时, 如果待支付状态下触发超时
if (LocalDateTimeUtil.le(order.getExpiredTime(), LocalDateTime.now())){
@@ -196,13 +196,13 @@ public class PaySyncService {
// 对支付网关同步的结果进行处理
switch (syncStatusEnum) {
// 支付成功 支付宝退款时也是支付成功状态, 除非支付完成
case PAY_SUCCESS: {
case SUCCESS: {
repair = repairService.repair(payOrder, PayRepairWayEnum.SUCCESS);
break;
}
// 待支付, 将订单状态重新设置为待支付
case PAY_WAIT: {
repair = repairService.repair(payOrder, PayRepairWayEnum.WAIT_PAY);
case PROGRESS: {
repair = repairService.repair(payOrder, PayRepairWayEnum.PROGRESS);
break;
}
case REFUND:

View File

@@ -1,6 +1,8 @@
package cn.bootx.platform.daxpay.service.core.timeout.task;
import cn.bootx.platform.daxpay.param.pay.PaySyncParam;
import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum;
import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal;
import cn.bootx.platform.daxpay.service.core.payment.sync.service.PaySyncService;
import cn.bootx.platform.daxpay.service.core.timeout.dao.PayExpiredTimeRepository;
import com.baomidou.lock.LockInfo;
@@ -44,6 +46,8 @@ public class PayExpiredTimeTask {
continue;
}
try {
// 设置补偿来源为定时任务
PaymentContextLocal.get().getRepairInfo().setSource(PayRepairSourceEnum.TASK);
// 执行同步操作, 网关同步时会对支付的进行状态的处理
Long paymentId = Long.parseLong(expiredKey);
PaySyncParam paySyncParam = new PaySyncParam();

View File

@@ -21,9 +21,9 @@ import lombok.experimental.Accessors;
@Schema(title = "支付回调信息记录")
public class PayCallbackRecordQuery extends QueryOrder {
/** 支付记录id */
@Schema(description = "支付记录id")
private Long paymentId;
/** 本地订单ID */
@Schema(description = "本地订单ID")
private Long orderId;
/**
* 支付通道
@@ -36,6 +36,7 @@ public class PayCallbackRecordQuery extends QueryOrder {
/**
* 回调处理状态
* @see PayCallbackStatusEnum
* @see RefundCallbackStatusEnum
*/
@Schema(description = "回调处理状态")
private String status;

View File

@@ -4,6 +4,7 @@ import cn.bootx.platform.common.core.annotation.QueryParam;
import cn.bootx.platform.daxpay.code.PayStatusEnum;
import cn.bootx.platform.daxpay.service.code.PayRepairSourceEnum;
import cn.bootx.platform.daxpay.service.code.PayRepairWayEnum;
import cn.bootx.platform.daxpay.service.code.PaymentTypeEnum;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.experimental.Accessors;
@@ -19,14 +20,23 @@ import lombok.experimental.Accessors;
@Schema(title = "支付修复记录查询参数")
public class PayRepairRecordQuery {
/** 支付ID */
@Schema(description = "支付ID")
private Long paymentId;
/** 本地订单ID */
@Schema(description = "本地订单ID")
private Long orderId;
/** 业务号 */
@Schema(description = "业务")
private String businessNo;
/** 本地订单号 */
@Schema(description = "本地订单")
private String orderNo;
@Schema(description = "修复单号")
private String repairNo;
/**
* 修复类型
* @see PaymentTypeEnum
*/
@Schema(description = "修复类型")
private String repairType;
/**
* 修复来源
* @see PayRepairSourceEnum
@@ -35,11 +45,11 @@ public class PayRepairRecordQuery {
private String repairSource;
/**
* 修复类型
* 修复方式
* @see PayRepairWayEnum
*/
@Schema(description = "修复类型")
private String repairType;
@Schema(description = "修复方式")
private String repairWay;
/** 修复的异步通道 */
@Schema(description = "修复的异步通道")

View File

@@ -19,9 +19,20 @@ import lombok.experimental.Accessors;
@Schema(title = "支付同步记录查询参数")
public class PaySyncRecordQuery {
/** 支付记录id */
@Schema(description = "支付记录id")
private Long paymentId;
/** 本地订单id */
@Schema(description = "本地订单id")
private Long orderId;
@Schema(description = "本地订单号")
private String orderNo;
/** 网关订单号 */
@Schema(description = "网关订单号")
private String gatewayOrderNo;
/** 同步类型 */
@Schema(description = "同步类型")
private String syncType;
/**
* 支付通道