mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-03 11:06:46 +00:00
ref 分账字段统一为Alloc, 不包括接口名称, 支付订单拆分退款状态为单独的字段, 策略工厂修改为通用策略工厂
This commit is contained in:
@@ -88,9 +88,9 @@ public class AllocationOrderController {
|
||||
@InitPaymentContext(PaymentApiCode.SYNC_ALLOCATION)
|
||||
@Operation(summary = "同步分账结果")
|
||||
@PostMapping("/sync")
|
||||
public ResResult<Void> sync(String allocationNo){
|
||||
public ResResult<Void> sync(String allocNo){
|
||||
AllocSyncParam param = new AllocSyncParam();
|
||||
param.setAllocationNo(allocationNo);
|
||||
param.setAllocNo(allocNo);
|
||||
allocationSyncService.sync(param);
|
||||
return Res.ok();
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class AllocationOrderController {
|
||||
@PostMapping("/finish")
|
||||
public ResResult<Void> finish(String allocationNo){
|
||||
AllocFinishParam param = new AllocFinishParam();
|
||||
param.setAllocationNo(allocationNo);
|
||||
param.setAllocNo(allocationNo);
|
||||
allocationService.finish(param);
|
||||
return Res.ok();
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ import lombok.EqualsAndHashCode;
|
||||
public class AllocFinishParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
|
||||
@Schema(description = "分账单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ import lombok.EqualsAndHashCode;
|
||||
public class AllocSyncParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "分账号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
@Schema(description = "商户分账号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
}
|
||||
|
@@ -16,8 +16,8 @@ import lombok.EqualsAndHashCode;
|
||||
public class QueryAllocOrderParam extends PaymentCommonParam {
|
||||
|
||||
@Schema(description = "分账单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
@Schema(description = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
}
|
||||
|
@@ -20,11 +20,11 @@ public class AllocationResult extends PaymentCommonResult {
|
||||
|
||||
/** 分账订单号 */
|
||||
@Schema(description = "分账订单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
/** 商户分账订单号 */
|
||||
@Schema(description = "商户分账订单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
|
@@ -25,15 +25,15 @@ public class AllocOrderResult extends PaymentCommonResult {
|
||||
|
||||
/** 分账单号 */
|
||||
@Schema(description = "分账单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
/** 商户分账单号 */
|
||||
@Schema(description = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
|
||||
/** 通道分账号 */
|
||||
@Schema(description = "通道分账号")
|
||||
private String outAllocationNo;
|
||||
private String outAllocNo;
|
||||
|
||||
/**
|
||||
* 支付订单号
|
||||
|
@@ -2,6 +2,7 @@ package cn.daxpay.single.result.order;
|
||||
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
|
||||
import cn.daxpay.single.code.PayOrderRefundStatusEnum;
|
||||
import cn.daxpay.single.code.PayStatusEnum;
|
||||
import cn.daxpay.single.result.PaymentCommonResult;
|
||||
import cn.daxpay.single.serializer.LocalDateTimeToTimestampSerializer;
|
||||
@@ -79,12 +80,19 @@ public class PayOrderResult extends PaymentCommonResult {
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
* @see PayOrderRefundStatusEnum
|
||||
*/
|
||||
@Schema(description = "退款状态")
|
||||
private String refundStatus;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
* @see PayOrderAllocStatusEnum
|
||||
*/
|
||||
@Schema(description = "分账状态")
|
||||
private String allocationStatus;
|
||||
private String allocStatus;
|
||||
|
||||
/** 支付时间 */
|
||||
@Schema(description = "支付时间")
|
||||
|
@@ -49,7 +49,7 @@ public class AliPayAllocationService {
|
||||
public void allocation(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails){
|
||||
// 分账主体参数
|
||||
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
|
||||
model.setOutRequestNo(allocationOrder.getAllocationNo());
|
||||
model.setOutRequestNo(allocationOrder.getAllocNo());
|
||||
model.setTradeNo(allocationOrder.getOutOrderNo());
|
||||
model.setRoyaltyMode(AliPayCode.ALLOC_ASYNC);
|
||||
|
||||
@@ -79,7 +79,7 @@ public class AliPayAllocationService {
|
||||
public void finish(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails ){
|
||||
// 分账主体参数
|
||||
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
|
||||
model.setOutRequestNo(String.valueOf(allocationOrder.getAllocationNo()));
|
||||
model.setOutRequestNo(String.valueOf(allocationOrder.getAllocNo()));
|
||||
model.setTradeNo(allocationOrder.getOutOrderNo());
|
||||
model.setRoyaltyMode(AliPayCode.ALLOC_ASYNC);
|
||||
// 分账完结参数
|
||||
@@ -109,7 +109,7 @@ public class AliPayAllocationService {
|
||||
public AllocRemoteSyncResult sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails){
|
||||
AlipayTradeOrderSettleQueryModel model = new AlipayTradeOrderSettleQueryModel();
|
||||
model.setTradeNo(allocationOrder.getOutOrderNo());
|
||||
model.setOutRequestNo(allocationOrder.getAllocationNo());
|
||||
model.setOutRequestNo(allocationOrder.getAllocNo());
|
||||
AlipayTradeOrderSettleQueryRequest request = new AlipayTradeOrderSettleQueryRequest();
|
||||
request.setBizModel(model);
|
||||
AlipayTradeOrderSettleQueryResponse response = AliPayApi.execute(request);
|
||||
|
@@ -239,10 +239,9 @@ public class AliPayReconcileService {
|
||||
*/
|
||||
private void saveOriginalFile(ReconcileOrder reconcileOrder, byte[] bytes) {
|
||||
// 将原始文件进行保存
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(reconcileOrder.getChannel());
|
||||
String date = LocalDateTimeUtil.format(reconcileOrder.getDate(), DatePattern.PURE_DATE_PATTERN);
|
||||
// 将原始文件进行保存 通道-日期
|
||||
String fileName = StrUtil.format("交易对账单-{}-{}.csv", channelEnum.getName(),date);
|
||||
String fileName = StrUtil.format("交易对账单-支付宝-{}.csv",date);
|
||||
UploadPretreatment uploadPretreatment = fileStorageService.of(bytes);
|
||||
if (StrUtil.isNotBlank(fileName)) {
|
||||
uploadPretreatment.setOriginalFilename(fileName);
|
||||
|
@@ -210,10 +210,9 @@ public class UnionPayReconcileService {
|
||||
* 保存下载的原始对账文件
|
||||
*/
|
||||
private void saveOriginalFile(ReconcileOrder reconcileOrder, byte[] bytes) {
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(reconcileOrder.getChannel());
|
||||
String date = LocalDateTimeUtil.format(reconcileOrder.getDate(), DatePattern.PURE_DATE_PATTERN);
|
||||
// 将原始文件进行保存 通道-日期
|
||||
String fileName = StrUtil.format("交易对账单-{}-{}.txt", channelEnum.getName(),date);
|
||||
String fileName = StrUtil.format("交易对账单-云闪付-{}.txt",date);
|
||||
UploadPretreatment uploadPretreatment = fileStorageService.of(bytes);
|
||||
if (StrUtil.isNotBlank(fileName)) {
|
||||
uploadPretreatment.setOriginalFilename(fileName);
|
||||
|
@@ -75,7 +75,7 @@ public class WeChatPayAllocationService {
|
||||
.appid(config.getWxAppId())
|
||||
.nonce_str(WxPayKit.generateStr())
|
||||
.transaction_id(allocationOrder.getOutOrderNo())
|
||||
.out_order_no(allocationOrder.getAllocationNo())
|
||||
.out_order_no(allocationOrder.getAllocNo())
|
||||
.receivers(JSON.toJSONString(list))
|
||||
.build()
|
||||
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
|
||||
@@ -97,7 +97,7 @@ public class WeChatPayAllocationService {
|
||||
.nonce_str(WxPayKit.generateStr())
|
||||
.transaction_id(allocationOrder.getOutOrderNo())
|
||||
// 分账要使用单独的的流水号, 不能与分账号相同
|
||||
.out_order_no(allocationOrder.getAllocationNo()+'F')
|
||||
.out_order_no(allocationOrder.getAllocNo()+'F')
|
||||
.description("分账已完成")
|
||||
.build()
|
||||
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
|
||||
@@ -118,7 +118,7 @@ public class WeChatPayAllocationService {
|
||||
.mch_id(config.getWxMchId())
|
||||
.nonce_str(WxPayKit.generateStr())
|
||||
.transaction_id(allocationOrder.getOutOrderNo())
|
||||
.out_order_no(allocationOrder.getAllocationNo())
|
||||
.out_order_no(allocationOrder.getAllocNo())
|
||||
.build()
|
||||
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
|
||||
String xmlResult = WxPayApi.profitSharingQuery(params);
|
||||
|
@@ -320,10 +320,9 @@ public class WechatPayReconcileService{
|
||||
*/
|
||||
private void saveOriginalFile(ReconcileOrder reconcileOrder, String text) {
|
||||
// 微信接收结果转换为 byte[]
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(reconcileOrder.getChannel());
|
||||
String date = LocalDateTimeUtil.format(reconcileOrder.getDate(), DatePattern.PURE_DATE_PATTERN);
|
||||
// 将原始文件进行保存 通道-日期
|
||||
String fileName = StrUtil.format("交易对账单-{}-{}.txt", channelEnum.getName(),date);
|
||||
String fileName = StrUtil.format("交易对账单-微信-{}.txt",date);
|
||||
byte[] bytes = StrUtil.bytes(text, CharsetUtil.CHARSET_UTF_8);
|
||||
UploadPretreatment uploadPretreatment = fileStorageService.of(bytes);
|
||||
if (StrUtil.isNotBlank(fileName)) {
|
||||
|
@@ -31,14 +31,14 @@ public class AllocationOrderManager extends BaseManager<AllocationOrderMapper, A
|
||||
* 根据分账单号查询
|
||||
*/
|
||||
public Optional<AllocationOrder> findByAllocationNo(String allocationNo){
|
||||
return findByField(AllocationOrder::getAllocationNo, allocationNo);
|
||||
return findByField(AllocationOrder::getAllocNo, allocationNo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据商户分账号查询
|
||||
*/
|
||||
public Optional<AllocationOrder> findByBizAllocationNo(String bizAllocationNo){
|
||||
return findByField(AllocationOrder::getBizAllocationNo, bizAllocationNo);
|
||||
return findByField(AllocationOrder::getBizAllocNo, bizAllocationNo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -34,19 +34,19 @@ public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction<
|
||||
* 分账单号
|
||||
*/
|
||||
@DbColumn(comment = "分账单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
/**
|
||||
* 商户分账单号
|
||||
*/
|
||||
@DbColumn(comment = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
|
||||
/**
|
||||
* 通道分账号
|
||||
*/
|
||||
@DbColumn(comment = "通道分账号")
|
||||
private String outAllocationNo;
|
||||
private String outAllocNo;
|
||||
|
||||
/** 支付订单ID */
|
||||
@DbColumn(comment = "支付订单ID")
|
||||
|
@@ -164,8 +164,8 @@ public class AllocationOrderService {
|
||||
.setBizOrderNo(payOrder.getBizOrderNo())
|
||||
.setOutOrderNo(payOrder.getOutOrderNo())
|
||||
.setTitle(payOrder.getTitle())
|
||||
.setAllocationNo(OrderNoGenerateUtil.allocation())
|
||||
.setBizAllocationNo(param.getBizAllocationNo())
|
||||
.setAllocNo(OrderNoGenerateUtil.allocation())
|
||||
.setBizAllocNo(param.getBizAllocationNo())
|
||||
.setChannel(payOrder.getChannel())
|
||||
.setDescription(param.getDescription())
|
||||
.setStatus(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())
|
||||
@@ -187,7 +187,7 @@ public class AllocationOrderService {
|
||||
extend.setId(allocId);
|
||||
|
||||
// 更新支付订单分账状态
|
||||
payOrder.setAllocationStatus(PayOrderAllocStatusEnum.ALLOCATION.getCode());
|
||||
payOrder.setAllocStatus(PayOrderAllocStatusEnum.ALLOCATION.getCode());
|
||||
payOrderManager.updateById(payOrder);
|
||||
allocationOrderDetailManager.saveAll(details);
|
||||
allocationOrderExtraManager.save(extend);
|
||||
|
@@ -48,7 +48,7 @@ public class PayBuilder {
|
||||
.setRefundableBalance(payParam.getAmount());
|
||||
// 如果支持分账, 设置分账状态为代分账
|
||||
if (payOrder.getAllocation()) {
|
||||
payOrder.setAllocationStatus(PayOrderAllocStatusEnum.WAITING.getCode());
|
||||
payOrder.setAllocStatus(PayOrderAllocStatusEnum.WAITING.getCode());
|
||||
}
|
||||
return payOrder;
|
||||
}
|
||||
|
@@ -71,7 +71,7 @@ public class PayOrderManager extends BaseManager<PayOrderMapper, PayOrder> {
|
||||
return this.lambdaQuery()
|
||||
.eq(PayOrder::getAllocation, true)
|
||||
.eq(PayOrder::getAutoAllocation, true)
|
||||
.eq(PayOrder::getAllocationStatus, PayOrderAllocStatusEnum.WAITING.getCode())
|
||||
.eq(PayOrder::getAllocStatus, PayOrderAllocStatusEnum.WAITING.getCode())
|
||||
.eq(PayOrder::getStatus, PayStatusEnum.SUCCESS.getCode())
|
||||
.list();
|
||||
}
|
||||
|
@@ -106,7 +106,7 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
|
||||
* @see PayOrderAllocStatusEnum
|
||||
*/
|
||||
@DbColumn(comment = "分账状态")
|
||||
private String allocationStatus;
|
||||
private String allocStatus;
|
||||
|
||||
/** 支付时间 */
|
||||
@DbColumn(comment = "支付时间")
|
||||
|
@@ -1,39 +0,0 @@
|
||||
package cn.daxpay.single.service.core.payment.allocation.factory;
|
||||
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.exception.pay.PayUnsupportedMethodException;
|
||||
import cn.daxpay.single.service.core.payment.allocation.strategy.allocation.AliPayAllocationStrategy;
|
||||
import cn.daxpay.single.service.core.payment.allocation.strategy.allocation.WeChatPayAllocationStrategy;
|
||||
import cn.daxpay.single.service.func.AbsAllocationStrategy;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* 分账策略工厂
|
||||
* @author xxm
|
||||
* @since 2024/4/7
|
||||
*/
|
||||
@UtilityClass
|
||||
public class AllocationFactory {
|
||||
|
||||
/**
|
||||
* 根据传入的支付通道创建策略
|
||||
* @return 支付策略
|
||||
*/
|
||||
public static AbsAllocationStrategy create(String channel) {
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(channel);
|
||||
|
||||
AbsAllocationStrategy strategy;
|
||||
switch (channelEnum) {
|
||||
case ALI:
|
||||
strategy = SpringUtil.getBean(AliPayAllocationStrategy.class);
|
||||
break;
|
||||
case WECHAT:
|
||||
strategy = SpringUtil.getBean(WeChatPayAllocationStrategy.class);
|
||||
break;
|
||||
default:
|
||||
throw new PayUnsupportedMethodException();
|
||||
}
|
||||
return strategy;
|
||||
}
|
||||
}
|
@@ -1,38 +0,0 @@
|
||||
package cn.daxpay.single.service.core.payment.allocation.factory;
|
||||
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.exception.pay.PayUnsupportedMethodException;
|
||||
import cn.daxpay.single.service.core.payment.allocation.strategy.receiver.AliPayAllocationReceiverStrategy;
|
||||
import cn.daxpay.single.service.core.payment.allocation.strategy.receiver.WeChatPayAllocationReceiverStrategy;
|
||||
import cn.daxpay.single.service.func.AbsAllocationReceiverStrategy;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* 分账接收方策略工厂
|
||||
* @author xxm
|
||||
* @since 2024/4/1
|
||||
*/
|
||||
@UtilityClass
|
||||
public class AllocationReceiverFactory {
|
||||
|
||||
/**
|
||||
* 根据传入的支付通道创建策略
|
||||
* @return 支付策略
|
||||
*/
|
||||
public static AbsAllocationReceiverStrategy create(PayChannelEnum channelEnum) {
|
||||
|
||||
AbsAllocationReceiverStrategy strategy;
|
||||
switch (channelEnum) {
|
||||
case ALI:
|
||||
strategy = SpringUtil.getBean(AliPayAllocationReceiverStrategy.class);
|
||||
break;
|
||||
case WECHAT:
|
||||
strategy = SpringUtil.getBean(WeChatPayAllocationReceiverStrategy.class);
|
||||
break;
|
||||
default:
|
||||
throw new PayUnsupportedMethodException();
|
||||
}
|
||||
return strategy;
|
||||
}
|
||||
}
|
@@ -18,7 +18,7 @@ public class AllocationCallbackService {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void callback(String allocationNo){
|
||||
public void callback(String allocNo){
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -94,7 +94,6 @@ public class AllocationGroupService {
|
||||
* 创建分账组
|
||||
*/
|
||||
public void create(AllocationGroupParam param){
|
||||
PayChannelEnum.findByCode(param.getChannel());
|
||||
AllocationGroup group = AllocationGroupConvert.CONVERT.convert(param);
|
||||
group.setTotalRate(0);
|
||||
groupManager.save(group);
|
||||
|
@@ -20,10 +20,10 @@ import cn.daxpay.single.service.core.payment.allocation.convert.AllocationReceiv
|
||||
import cn.daxpay.single.service.core.payment.allocation.dao.AllocationGroupReceiverManager;
|
||||
import cn.daxpay.single.service.core.payment.allocation.dao.AllocationReceiverManager;
|
||||
import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceiver;
|
||||
import cn.daxpay.single.service.core.payment.allocation.factory.AllocationReceiverFactory;
|
||||
import cn.daxpay.single.service.dto.allocation.AllocationReceiverDto;
|
||||
import cn.daxpay.single.service.func.AbsAllocationReceiverStrategy;
|
||||
import cn.daxpay.single.service.param.allocation.receiver.AllocationReceiverQuery;
|
||||
import cn.daxpay.single.service.util.PayStrategyFactory;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.baomidou.lock.LockInfo;
|
||||
import com.baomidou.lock.LockTemplate;
|
||||
@@ -120,8 +120,7 @@ public class AllocationReceiverService {
|
||||
}
|
||||
AllocationReceiver receiver = AllocationReceiverConvert.CONVERT.convert(param);
|
||||
// 获取策略
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(param.getChannel());
|
||||
AbsAllocationReceiverStrategy receiverStrategy = AllocationReceiverFactory.create(channelEnum);
|
||||
AbsAllocationReceiverStrategy receiverStrategy = PayStrategyFactory.create(param.getChannel(), AbsAllocationReceiverStrategy.class);
|
||||
// 校验
|
||||
receiverStrategy.setAllocationReceiver(receiver);
|
||||
if (!receiverStrategy.validation()){
|
||||
@@ -148,8 +147,7 @@ public class AllocationReceiverService {
|
||||
throw new PayFailureException("该接收方已被使用,无法被删除");
|
||||
}
|
||||
// 获取策略
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(receiver.getChannel());
|
||||
AbsAllocationReceiverStrategy receiverStrategy = AllocationReceiverFactory.create(channelEnum);
|
||||
AbsAllocationReceiverStrategy receiverStrategy = PayStrategyFactory.create(receiver.getChannel(), AbsAllocationReceiverStrategy.class);
|
||||
LockInfo lock = lockTemplate.lock("payment:receiver:" + param.getReceiverNo(),10000,200);
|
||||
if (Objects.isNull(lock)){
|
||||
throw new PayFailureException("分账方处理中,请勿重复操作");
|
||||
|
@@ -11,9 +11,9 @@ import cn.daxpay.single.exception.pay.PayFailureException;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocFinishParam;
|
||||
import cn.daxpay.single.param.payment.allocation.AllocationParam;
|
||||
import cn.daxpay.single.param.payment.allocation.QueryAllocOrderParam;
|
||||
import cn.daxpay.single.result.allocation.AllocationResult;
|
||||
import cn.daxpay.single.result.order.AllocOrderDetailResult;
|
||||
import cn.daxpay.single.result.order.AllocOrderResult;
|
||||
import cn.daxpay.single.result.allocation.AllocationResult;
|
||||
import cn.daxpay.single.service.common.local.PaymentContextLocal;
|
||||
import cn.daxpay.single.service.core.order.allocation.convert.AllocationConvert;
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
|
||||
@@ -28,9 +28,9 @@ import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
|
||||
import cn.daxpay.single.service.core.order.pay.service.PayOrderQueryService;
|
||||
import cn.daxpay.single.service.core.payment.allocation.dao.AllocationGroupManager;
|
||||
import cn.daxpay.single.service.core.payment.allocation.entity.AllocationGroup;
|
||||
import cn.daxpay.single.service.core.payment.allocation.factory.AllocationFactory;
|
||||
import cn.daxpay.single.service.dto.allocation.AllocationGroupReceiverResult;
|
||||
import cn.daxpay.single.service.func.AbsAllocationStrategy;
|
||||
import cn.daxpay.single.service.util.PayStrategyFactory;
|
||||
import com.baomidou.lock.LockInfo;
|
||||
import com.baomidou.lock.LockTemplate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -111,13 +111,13 @@ public class AllocationService {
|
||||
// 无需进行分账,
|
||||
if (Objects.equals(order.getStatus(),AllocOrderStatusEnum.IGNORE.getCode())){
|
||||
return new AllocationResult()
|
||||
.setAllocationNo(order.getAllocationNo())
|
||||
.setBizAllocationNo(order.getBizAllocationNo())
|
||||
.setAllocNo(order.getAllocNo())
|
||||
.setBizAllocNo(order.getBizAllocNo())
|
||||
.setStatus(order.getStatus());
|
||||
}
|
||||
|
||||
// 创建分账策略并初始化
|
||||
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(payOrder.getChannel());
|
||||
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(payOrder.getChannel(),AbsAllocationStrategy.class);
|
||||
allocationStrategy.initParam(order, details);
|
||||
try {
|
||||
// 分账预处理
|
||||
@@ -139,11 +139,11 @@ public class AllocationService {
|
||||
String outAllocationNo = PaymentContextLocal.get()
|
||||
.getAllocationInfo()
|
||||
.getOutAllocationNo();
|
||||
order.setOutAllocationNo(outAllocationNo);
|
||||
order.setOutAllocNo(outAllocationNo);
|
||||
allocationOrderManager.updateById(order);
|
||||
return new AllocationResult()
|
||||
.setAllocationNo(order.getAllocationNo())
|
||||
.setBizAllocationNo(order.getBizAllocationNo())
|
||||
.setAllocNo(order.getAllocNo())
|
||||
.setBizAllocNo(order.getBizAllocNo())
|
||||
.setStatus(order.getStatus());
|
||||
} finally {
|
||||
lockTemplate.releaseLock(lock);
|
||||
@@ -168,7 +168,7 @@ public class AllocationService {
|
||||
}
|
||||
List<AllocationOrderDetail> details = this.getDetails(order.getId());
|
||||
// 创建分账策略并初始化
|
||||
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(order.getChannel());
|
||||
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(order.getChannel(),AbsAllocationStrategy.class);
|
||||
allocationStrategy.initParam(order, details);
|
||||
// 分账预处理
|
||||
allocationStrategy.doBeforeHandler();
|
||||
@@ -191,8 +191,8 @@ public class AllocationService {
|
||||
}
|
||||
allocationOrderManager.updateById(order);
|
||||
return new AllocationResult()
|
||||
.setAllocationNo(order.getAllocationNo())
|
||||
.setBizAllocationNo(order.getBizAllocationNo())
|
||||
.setAllocNo(order.getAllocNo())
|
||||
.setBizAllocNo(order.getBizAllocNo())
|
||||
.setStatus(order.getStatus());
|
||||
} finally {
|
||||
lockTemplate.releaseLock(lock);
|
||||
@@ -204,11 +204,11 @@ public class AllocationService {
|
||||
*/
|
||||
public AllocationResult finish(AllocFinishParam param) {
|
||||
AllocationOrder allocationOrder;
|
||||
if (Objects.nonNull(param.getAllocationNo())){
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo())
|
||||
if (Objects.nonNull(param.getAllocNo())){
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocNo())
|
||||
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
|
||||
} else {
|
||||
allocationOrder = allocationOrderManager.findByBizAllocationNo(param.getBizAllocationNo())
|
||||
allocationOrder = allocationOrderManager.findByBizAllocationNo(param.getBizAllocNo())
|
||||
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
|
||||
}
|
||||
return this.finish(allocationOrder);
|
||||
@@ -225,7 +225,7 @@ public class AllocationService {
|
||||
List<AllocationOrderDetail> details = this.getDetails(allocationOrder.getId());
|
||||
|
||||
// 创建分账策略并初始化
|
||||
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(allocationOrder.getChannel());
|
||||
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(allocationOrder.getChannel(),AbsAllocationStrategy.class);
|
||||
allocationStrategy.initParam(allocationOrder, details);
|
||||
|
||||
// 分账完结预处理
|
||||
@@ -245,8 +245,8 @@ public class AllocationService {
|
||||
}
|
||||
allocationOrderManager.updateById(allocationOrder);
|
||||
return new AllocationResult()
|
||||
.setAllocationNo(allocationOrder.getAllocationNo())
|
||||
.setBizAllocationNo(allocationOrder.getBizAllocationNo())
|
||||
.setAllocNo(allocationOrder.getAllocNo())
|
||||
.setBizAllocNo(allocationOrder.getBizAllocNo())
|
||||
.setStatus(allocationOrder.getStatus());
|
||||
}
|
||||
|
||||
@@ -262,7 +262,7 @@ public class AllocationService {
|
||||
throw new PayFailureException("该订单不允许分账");
|
||||
}
|
||||
// 判断分账状态
|
||||
if (Objects.equals(PayOrderAllocStatusEnum.ALLOCATION.getCode(), payOrder.getAllocationStatus())){
|
||||
if (Objects.equals(PayOrderAllocStatusEnum.ALLOCATION.getCode(), payOrder.getAllocStatus())){
|
||||
throw new PayFailureException("该订单已分账完成");
|
||||
}
|
||||
return payOrder;
|
||||
@@ -273,7 +273,7 @@ public class AllocationService {
|
||||
*/
|
||||
public AllocOrderResult queryAllocationOrder(QueryAllocOrderParam param) {
|
||||
// 查询分账单
|
||||
AllocationOrder allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo())
|
||||
AllocationOrder allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocNo())
|
||||
.orElseThrow(() -> new PayFailureException("分账单不存在"));
|
||||
AllocOrderResult result = AllocationConvert.CONVERT.toResult(allocationOrder);
|
||||
// 查询分账单明细
|
||||
|
@@ -13,12 +13,12 @@ import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailM
|
||||
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderManager;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
|
||||
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
|
||||
import cn.daxpay.single.service.core.payment.allocation.factory.AllocationFactory;
|
||||
import cn.daxpay.single.service.core.payment.notice.service.ClientNoticeService;
|
||||
import cn.daxpay.single.service.core.payment.sync.result.AllocRemoteSyncResult;
|
||||
import cn.daxpay.single.service.core.record.sync.entity.PaySyncRecord;
|
||||
import cn.daxpay.single.service.core.record.sync.service.PaySyncRecordService;
|
||||
import cn.daxpay.single.service.func.AbsAllocationStrategy;
|
||||
import cn.daxpay.single.service.util.PayStrategyFactory;
|
||||
import com.baomidou.lock.LockInfo;
|
||||
import com.baomidou.lock.LockTemplate;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -58,12 +58,12 @@ public class AllocationSyncService {
|
||||
public AllocSyncResult sync(AllocSyncParam param) {
|
||||
// 获取分账订单
|
||||
AllocationOrder allocationOrder = null;
|
||||
if (Objects.nonNull(param.getAllocationNo())){
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocationNo())
|
||||
if (Objects.nonNull(param.getAllocNo())){
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocNo())
|
||||
.orElseThrow(() -> new DataNotExistException("分账单不存在"));
|
||||
}
|
||||
if (Objects.isNull(allocationOrder)){
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getBizAllocationNo())
|
||||
allocationOrder = allocationOrderManager.findByAllocationNo(param.getBizAllocNo())
|
||||
.orElseThrow(() -> new DataNotExistException("分账单不存在"));
|
||||
}
|
||||
// 如果类型为忽略, 不进行同步处理
|
||||
@@ -87,7 +87,7 @@ public class AllocationSyncService {
|
||||
try {
|
||||
List<AllocationOrderDetail> detailList = allocationOrderDetailManager.findAllByOrderId(allocationOrder.getId());
|
||||
// 获取分账策略
|
||||
AbsAllocationStrategy allocationStrategy = AllocationFactory.create(allocationOrder.getChannel());
|
||||
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(allocationOrder.getChannel(),AbsAllocationStrategy.class);
|
||||
allocationStrategy.initParam(allocationOrder, detailList);
|
||||
// 分账完结预处理
|
||||
allocationStrategy.doBeforeHandler();
|
||||
@@ -159,9 +159,9 @@ public class AllocationSyncService {
|
||||
*/
|
||||
private void saveRecord(AllocationOrder order, AllocRemoteSyncResult syncResult, String errorCode, String errorMsg){
|
||||
PaySyncRecord paySyncRecord = new PaySyncRecord()
|
||||
.setBizTradeNo(order.getBizAllocationNo())
|
||||
.setTradeNo(order.getAllocationNo())
|
||||
.setOutTradeNo(order.getOutAllocationNo())
|
||||
.setBizTradeNo(order.getBizAllocNo())
|
||||
.setTradeNo(order.getAllocNo())
|
||||
.setOutTradeNo(order.getOutAllocNo())
|
||||
.setSyncType(PaymentTypeEnum.ALLOCATION.getCode())
|
||||
.setChannel(order.getChannel())
|
||||
.setSyncInfo(syncResult.getSyncInfo())
|
||||
|
@@ -28,19 +28,19 @@ public class AllocNoticeResult extends PaymentCommonResult {
|
||||
* 分账单号
|
||||
*/
|
||||
@Schema(description = "分账单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
/**
|
||||
* 商户分账单号
|
||||
*/
|
||||
@Schema(description = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
|
||||
/**
|
||||
* 通道分账号
|
||||
*/
|
||||
@Schema(description = "通道分账号")
|
||||
private String outAllocationNo;
|
||||
private String outAllocNo;
|
||||
|
||||
/**
|
||||
* 支付订单号
|
||||
|
@@ -2,6 +2,7 @@ package cn.daxpay.single.service.core.payment.notice.result;
|
||||
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
|
||||
import cn.daxpay.single.code.PayOrderRefundStatusEnum;
|
||||
import cn.daxpay.single.code.PayStatusEnum;
|
||||
import cn.daxpay.single.result.PaymentCommonResult;
|
||||
import cn.daxpay.single.serializer.LocalDateTimeToTimestampSerializer;
|
||||
@@ -75,12 +76,19 @@ public class PayNoticeResult extends PaymentCommonResult {
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
* @see PayOrderRefundStatusEnum
|
||||
*/
|
||||
@Schema(description = "退款状态")
|
||||
private String refundStatus;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
* @see PayOrderAllocStatusEnum
|
||||
*/
|
||||
@Schema(description = "分账状态")
|
||||
private String allocationStatus;
|
||||
private String allocStatus;
|
||||
|
||||
/** 支付时间 */
|
||||
@Schema(description = "支付时间")
|
||||
|
@@ -97,7 +97,7 @@ public class ClientNoticeAssistService {
|
||||
.setNoticeType(ClientNoticeTypeEnum.ALLOCATION.getType())
|
||||
.setSendCount(0)
|
||||
.setTradeId(order.getId())
|
||||
.setTradeNo(order.getAllocationNo())
|
||||
.setTradeNo(order.getAllocNo())
|
||||
.setTradeStatus(order.getStatus());
|
||||
}
|
||||
|
||||
|
@@ -157,7 +157,7 @@ public class PayAssistService {
|
||||
.setChannel(payParam.getChannel())
|
||||
.setMethod(payParam.getMethod());
|
||||
if (!order.getAllocation()) {
|
||||
order.setAllocationStatus(null);
|
||||
order.setAllocStatus(null);
|
||||
}
|
||||
|
||||
// 扩展信息
|
||||
|
@@ -257,7 +257,7 @@ public class ReconcileService {
|
||||
// 设置header信息
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
// TODO 后续使用数据库中数据
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(reconcileOrder.getChannel());
|
||||
String date = LocalDateTimeUtil.format(reconcileOrder.getDate(), DatePattern.PURE_DATE_PATTERN);
|
||||
// 将原始文件进行保存 通道-日期
|
||||
@@ -284,7 +284,7 @@ public class ReconcileService {
|
||||
byte[] bytes = byteArrayOutputStream.toByteArray();// 设置header信息
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
// TODO 后续使用数据库中数据
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(reconcileOrder.getChannel());
|
||||
String date = LocalDateTimeUtil.format(reconcileOrder.getDate(), DatePattern.PURE_DATE_PATTERN);
|
||||
// 将原始文件进行保存 通道-日期
|
||||
@@ -316,6 +316,7 @@ public class ReconcileService {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
||||
|
||||
// TODO 后续使用数据库中数据
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(reconcileOrder.getChannel());
|
||||
String date = LocalDateTimeUtil.format(reconcileOrder.getDate(), DatePattern.PURE_DATE_PATTERN);
|
||||
// 将原始文件进行保存 通道-日期
|
||||
|
@@ -1,35 +0,0 @@
|
||||
package cn.daxpay.single.service.core.payment.transfer.factory;
|
||||
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.exception.pay.PayUnsupportedMethodException;
|
||||
import cn.daxpay.single.service.core.payment.transfer.strategy.AliPayTransferStrategy;
|
||||
import cn.daxpay.single.service.func.AbsTransferStrategy;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
/**
|
||||
* 转账工具类
|
||||
* @author xxm
|
||||
* @since 2024/3/21
|
||||
*/
|
||||
@UtilityClass
|
||||
public class TransferFactory {
|
||||
|
||||
/**
|
||||
* 获取转账策略
|
||||
* @param channelCode 支付通道编码
|
||||
* @return 支付同步策略类
|
||||
*/
|
||||
public AbsTransferStrategy create(String channelCode) {
|
||||
AbsTransferStrategy strategy;
|
||||
PayChannelEnum channelEnum = PayChannelEnum.findByCode(channelCode);
|
||||
switch (channelEnum) {
|
||||
case ALI:
|
||||
strategy = SpringUtil.getBean(AliPayTransferStrategy.class);
|
||||
break;
|
||||
default:
|
||||
throw new PayUnsupportedMethodException();
|
||||
}
|
||||
return strategy;
|
||||
}
|
||||
}
|
@@ -1,13 +1,12 @@
|
||||
package cn.daxpay.single.service.core.payment.transfer.service;
|
||||
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.code.RefundStatusEnum;
|
||||
import cn.daxpay.single.param.payment.transfer.TransferParam;
|
||||
import cn.daxpay.single.result.transfer.TransferResult;
|
||||
import cn.daxpay.single.service.common.local.PaymentContextLocal;
|
||||
import cn.daxpay.single.service.core.order.transfer.entity.TransferOrder;
|
||||
import cn.daxpay.single.service.core.payment.transfer.factory.TransferFactory;
|
||||
import cn.daxpay.single.service.func.AbsTransferStrategy;
|
||||
import cn.daxpay.single.service.util.PayStrategyFactory;
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -31,7 +30,7 @@ public class TransferService {
|
||||
public TransferResult transfer(TransferParam transferParam){
|
||||
|
||||
// 获取策略
|
||||
AbsTransferStrategy transferStrategy = TransferFactory.create(PayChannelEnum.ALI.getCode());
|
||||
AbsTransferStrategy transferStrategy = PayStrategyFactory.create(transferParam.getChannel(),AbsTransferStrategy.class);
|
||||
// 检查转账参数
|
||||
transferStrategy.doValidateParam(transferParam);
|
||||
// 创建转账订单并设置
|
||||
|
@@ -23,18 +23,18 @@ public class AllocationOrderDto extends BaseDto {
|
||||
* 分账订单号
|
||||
*/
|
||||
@Schema(description = "分账订单号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
/**
|
||||
* 商户分账单号
|
||||
*/
|
||||
@Schema(description = "商户分账单号")
|
||||
private String bizAllocationNo;
|
||||
private String bizAllocNo;
|
||||
/**
|
||||
* 通道分账单号
|
||||
*/
|
||||
@Schema(description = "通道分账单号")
|
||||
private String outAllocationNo;
|
||||
private String outAllocNo;
|
||||
|
||||
/**
|
||||
* 支付订单ID
|
||||
|
@@ -3,6 +3,7 @@ package cn.daxpay.single.service.dto.order.pay;
|
||||
import cn.bootx.platform.common.core.rest.dto.BaseDto;
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
|
||||
import cn.daxpay.single.code.PayOrderRefundStatusEnum;
|
||||
import cn.daxpay.single.code.PayStatusEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -78,12 +79,19 @@ public class PayOrderDto extends BaseDto {
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
* @see PayOrderRefundStatusEnum
|
||||
*/
|
||||
@Schema(description = "退款状态")
|
||||
private String refundStatus;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
* @see PayOrderAllocStatusEnum
|
||||
*/
|
||||
@Schema(description = "分账状态")
|
||||
private String allocationStatus;
|
||||
private String allocStatus;
|
||||
|
||||
/** 支付时间 */
|
||||
@Schema(description = "支付时间")
|
||||
|
@@ -8,6 +8,7 @@ import com.alibaba.excel.metadata.property.ExcelContentProperty;
|
||||
|
||||
/**
|
||||
* 支付通道转换
|
||||
* TODO 改为读取数据库
|
||||
* @author xxm
|
||||
* @since 2024/5/6
|
||||
*/
|
||||
|
@@ -24,7 +24,7 @@ public class AllocationOrderQuery {
|
||||
private String title;
|
||||
|
||||
@Schema(description = "分账业务号")
|
||||
private String allocationNo;
|
||||
private String allocNo;
|
||||
|
||||
@Schema(description = "分账通道")
|
||||
private String channel;
|
||||
|
@@ -4,6 +4,7 @@ import cn.bootx.platform.common.core.annotation.QueryParam;
|
||||
import cn.bootx.platform.common.core.rest.param.QueryOrder;
|
||||
import cn.daxpay.single.code.PayChannelEnum;
|
||||
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
|
||||
import cn.daxpay.single.code.PayOrderRefundStatusEnum;
|
||||
import cn.daxpay.single.code.PayStatusEnum;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
@@ -71,12 +72,19 @@ public class PayOrderQuery extends QueryOrder {
|
||||
@Schema(description = "支付状态")
|
||||
private String status;
|
||||
|
||||
/**
|
||||
* 退款状态
|
||||
* @see PayOrderRefundStatusEnum
|
||||
*/
|
||||
@Schema(description = "退款状态")
|
||||
private String refundStatus;
|
||||
|
||||
/**
|
||||
* 分账状态
|
||||
* @see PayOrderAllocStatusEnum
|
||||
*/
|
||||
@Schema(description = "分账状态")
|
||||
private String allocationStatus;
|
||||
private String allocStatus;
|
||||
|
||||
/** 错误码 */
|
||||
@Schema(description = "错误码")
|
||||
|
@@ -43,7 +43,7 @@ public class AllocationSyncTask implements Job {
|
||||
allocationService.finish(allocationOrder);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("分账同步或完结失败, 分账号:{}", allocationOrder.getAllocationNo());
|
||||
log.warn("分账同步或完结失败, 分账号:{}", allocationOrder.getAllocNo());
|
||||
log.warn("分账同步或完结失败", e);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user