perf 网关同步记录优化

This commit is contained in:
xxm1995
2023-07-17 14:04:13 +08:00
parent ea3443e7fb
commit 9477e8c3c7
11 changed files with 39 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
- 微信V3支付接口
- x 拆分网关同步相关代码
- x 记录网关同步记录
- 重构支付消息通知结构
- 重构支付消息通知结构, 支持多种消息中间件
- x 保存各通道的支付单
- 钱包支持设置开通时的默认金额
- 储值卡多卡支付和退款演示

View File

@@ -8,25 +8,25 @@ package cn.bootx.platform.daxpay.code.pay;
*/
public interface PaySyncStatus {
/** -1 不需要同步 */
/** 不需要同步 */
String NOT_SYNC = "not_sync";
/** 1 远程支付成功 */
/** 远程支付成功 */
String TRADE_SUCCESS = "trade_success";
/** 2 交易创建,等待买家付款 */
/** 交易创建,等待买家付款 */
String WAIT_BUYER_PAY = "wait_buyer_pay";
/** 3 已关闭 */
/** 已关闭 */
String TRADE_CLOSED = "trade_closed";
/** 4 已退款 */
/** 已退款 */
String TRADE_REFUND = "trade_refund";
/** 5 查询不到订单 */
/** 查询不到订单 */
String NOT_FOUND = "not_found";
/** 4 查询失败 */
/** 查询失败 */
String FAIL = "fail";
}

View File

@@ -15,7 +15,7 @@ import org.springframework.web.bind.annotation.RestController;
@Tag(name = "支付同步记录")
@RestController
@RequestMapping("/")
@RequestMapping("/pay/sync")
@RequiredArgsConstructor
public class PaySyncRecordController {
private final PaySyncRecordService syncRecordService;

View File

@@ -66,6 +66,7 @@ public class AlipaySyncService {
}
catch (AlipayApiException e) {
log.error("查询订单失败:", e);
paySyncResult.setMsg(e.getErrMsg());
}
return paySyncResult;
}

View File

@@ -80,6 +80,7 @@ public class WeChatPaySyncService {
}
catch (RuntimeException e) {
log.error("查询订单失败:", e);
paySyncResult.setMsg(e.getMessage());
}
return paySyncResult;
}

View File

@@ -60,6 +60,9 @@ public class PaySyncRecord extends MpCreateEntity implements EntityBaseFunction
@DbComment("同步状态")
private String status;
@DbComment("错误消息")
private String msg;
/** 同步时间 */
@DbComment("同步时间")
private LocalDateTime syncTime;

View File

@@ -13,6 +13,8 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import java.time.LocalDateTime;
@@ -30,6 +32,7 @@ public class PaySyncRecordService {
/**
* 记录同步记录
*/
@Transactional(propagation= Propagation.REQUIRES_NEW)
public void saveRecord(PaySyncResult paySyncResult, Payment payment){
PaySyncRecord paySyncRecord = new PaySyncRecord()
.setPaymentId(payment.getId())
@@ -38,6 +41,7 @@ public class PaySyncRecordService {
.setPayChannel(payment.getAsyncPayChannel())
.setSyncInfo(paySyncResult.getJson())
.setStatus(paySyncResult.getPaySyncStatus())
.setMsg(paySyncResult.getMsg())
.setSyncTime(LocalDateTime.now());
syncRecordManager.save(paySyncRecord);
}

View File

@@ -30,4 +30,7 @@ public class PaySyncResult {
/** 网关返回对象的json字符串 */
private String json;
/** 错误提示 */
private String msg;
}

View File

@@ -77,10 +77,10 @@ public class PaySyncService {
syncPayStrategy.initPayParam(payment);
// 同步
PaySyncResult paySyncResult = syncPayStrategy.doSyncPayStatusHandler();
// 处理
this.resultHandler(paySyncResult,payment);
// 记录
paySyncRecordService.saveRecord(paySyncResult,payment);
// 处理
this.resultHandler(paySyncResult,payment);
}
/**

View File

@@ -24,6 +24,12 @@ public class PayNotifyRecordDto extends BaseDto implements Serializable {
@Schema(description = "支付号")
private Long paymentId;
@Schema(description = "商户编码")
private String mchCode;
@Schema(description = "商户应用编码")
private String mchAppCode;
@Schema(description = "通知消息")
private String notifyInfo;

View File

@@ -1,6 +1,5 @@
package cn.bootx.platform.daxpay.dto.sync;
import cn.bootx.mybatis.table.modify.annotation.DbComment;
import cn.bootx.mybatis.table.modify.mybatis.mysq.annotation.DbMySqlFieldType;
import cn.bootx.mybatis.table.modify.mybatis.mysq.constants.MySqlFieldTypeEnum;
import cn.bootx.platform.common.core.rest.dto.BaseDto;
@@ -25,37 +24,40 @@ import java.time.LocalDateTime;
public class PaySyncRecordDto extends BaseDto {
/** 支付记录id */
@DbComment("支付记录id")
@Schema(description = "支付记录id")
private Long paymentId;
/** 商户编码 */
@DbComment("商户编码")
@Schema(description = "商户编码")
private String mchCode;
/** 商户应用编码 */
@DbComment("商户应用编码")
@Schema(description = "商户应用编码")
private String mchAppCode;
/**
* 支付通道
* @see PayChannelEnum#getCode()
*/
@DbComment("支付通道")
@Schema(description = "支付通道")
private String payChannel;
/** 通知消息 */
@DbMySqlFieldType(MySqlFieldTypeEnum.LONGTEXT)
@DbComment("通知消息")
@Schema(description = "通知消息")
private String syncInfo;
/**
* 同步状态
* @see PaySyncStatus#WAIT_BUYER_PAY
*/
@DbComment("同步状态")
@Schema(description = "同步状态")
private String status;
@Schema(description = "错误消息")
private String msg;
/** 同步时间 */
@DbComment("同步时间")
@Schema(description = "同步时间")
private LocalDateTime syncTime;
}