mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-03 11:06:46 +00:00
fix 分账订单创建不全问题\调试
This commit is contained in:
@@ -15,6 +15,7 @@ import cn.daxpay.single.service.core.payment.allocation.service.AllocationServic
|
||||
import cn.daxpay.single.service.core.payment.allocation.service.AllocationSyncService;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDto;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderExtraDto;
|
||||
import cn.daxpay.single.service.param.order.AllocationOrderQuery;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
@@ -69,7 +70,7 @@ public class AllocationOrderController {
|
||||
|
||||
@Operation(summary = "查询扩展信息")
|
||||
@GetMapping("/extra/findById")
|
||||
public ResResult<AllocationOrderDto> findExtraById(Long id){
|
||||
public ResResult<AllocationOrderExtraDto> findExtraById(Long id){
|
||||
return Res.ok(allocationOrderService.findExtraById(id));
|
||||
}
|
||||
|
||||
|
@@ -4,8 +4,10 @@ import cn.daxpay.single.result.order.AllocOrderDetailResult;
|
||||
import cn.daxpay.single.result.order.AllocOrderResult;
|
||||
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.order.allocation.entity.AllocationOrderExtra;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDto;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderExtraDto;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@@ -21,6 +23,8 @@ public interface AllocationConvert {
|
||||
|
||||
AllocationOrderDto convert(AllocationOrder in);
|
||||
|
||||
AllocationOrderExtraDto convert(AllocationOrderExtra in);
|
||||
|
||||
AllocOrderResult toResult(AllocationOrder in);
|
||||
|
||||
AllocOrderDetailResult toResult(AllocationOrderDetail in);
|
||||
|
@@ -1,11 +1,11 @@
|
||||
package cn.daxpay.single.service.core.order.allocation.entity;
|
||||
|
||||
import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
||||
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
|
||||
import cn.bootx.table.modify.annotation.DbColumn;
|
||||
import cn.bootx.table.modify.annotation.DbTable;
|
||||
import cn.daxpay.single.param.channel.AliPayParam;
|
||||
import cn.daxpay.single.param.channel.WalletPayParam;
|
||||
import cn.daxpay.single.param.channel.WeChatPayParam;
|
||||
import cn.daxpay.single.service.core.order.allocation.convert.AllocationConvert;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderExtraDto;
|
||||
import com.baomidou.mybatisplus.annotation.FieldStrategy;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
@@ -25,7 +25,7 @@ import java.time.LocalDateTime;
|
||||
@Accessors(chain = true)
|
||||
@DbTable(comment = "分账订单扩展")
|
||||
@TableName("pay_allocation_order_extra")
|
||||
public class AllocationOrderExtra extends MpBaseEntity {
|
||||
public class AllocationOrderExtra extends MpBaseEntity implements EntityBaseFunction<AllocationOrderExtraDto> {
|
||||
|
||||
/** 异步通知地址 */
|
||||
@DbColumn(comment = "异步通知地址")
|
||||
@@ -36,16 +36,6 @@ public class AllocationOrderExtra extends MpBaseEntity {
|
||||
@DbColumn(comment = "商户扩展参数")
|
||||
private String attach;
|
||||
|
||||
/**
|
||||
* 附加参数 以最后一次为准
|
||||
* @see AliPayParam
|
||||
* @see WeChatPayParam
|
||||
* @see WalletPayParam
|
||||
*/
|
||||
@DbColumn(comment = "附加参数")
|
||||
@TableField(updateStrategy = FieldStrategy.ALWAYS)
|
||||
private String extraParam;
|
||||
|
||||
/** 请求时间,时间戳转时间 */
|
||||
@DbColumn(comment = "请求时间,传输时间戳")
|
||||
private LocalDateTime reqTime;
|
||||
@@ -53,4 +43,9 @@ public class AllocationOrderExtra extends MpBaseEntity {
|
||||
/** 终端ip */
|
||||
@DbColumn(comment = "支付终端ip")
|
||||
private String clientIp;
|
||||
|
||||
@Override
|
||||
public AllocationOrderExtraDto toDto() {
|
||||
return AllocationConvert.CONVERT.convert(this);
|
||||
}
|
||||
}
|
||||
|
@@ -29,6 +29,7 @@ import cn.daxpay.single.service.core.payment.allocation.entity.AllocationReceive
|
||||
import cn.daxpay.single.service.dto.allocation.AllocationGroupReceiverResult;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDto;
|
||||
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderExtraDto;
|
||||
import cn.daxpay.single.service.param.order.AllocationOrderQuery;
|
||||
import cn.daxpay.single.util.OrderNoGenerateUtil;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
@@ -109,8 +110,6 @@ public class AllocationOrderService {
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public OrderAndDetail createAndUpdate(AllocationParam param, PayOrder payOrder, List<AllocationGroupReceiverResult> receiversByGroups){
|
||||
long orderId = IdUtil.getSnowflakeNextId();
|
||||
|
||||
// 订单明细
|
||||
List<AllocationOrderDetail> details = receiversByGroups.stream()
|
||||
.map(o -> {
|
||||
@@ -118,8 +117,7 @@ public class AllocationOrderService {
|
||||
Integer rate = o.getRate();
|
||||
Integer amount = payOrder.getAmount() * rate / 10000;
|
||||
AllocationOrderDetail detail = new AllocationOrderDetail();
|
||||
detail.setAllocationId(orderId)
|
||||
.setReceiverNo(o.getReceiverNo())
|
||||
detail.setReceiverNo(o.getReceiverNo())
|
||||
.setReceiverId(o.getId())
|
||||
.setAmount(amount)
|
||||
.setResult(AllocDetailResultEnum.PENDING.getCode())
|
||||
@@ -130,35 +128,13 @@ public class AllocationOrderService {
|
||||
return detail;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
// 求分账的总额
|
||||
Integer sumAmount = details.stream()
|
||||
.map(AllocationOrderDetail::getAmount)
|
||||
.reduce(0, Integer::sum);
|
||||
// 分账订单
|
||||
AllocationOrder allocationOrder = new AllocationOrder()
|
||||
.setOrderId(payOrder.getId())
|
||||
.setOrderNo(payOrder.getOrderNo())
|
||||
.setBizOrderNo(payOrder.getBizOrderNo())
|
||||
.setOutOrderNo(payOrder.getOutOrderNo())
|
||||
.setTitle(payOrder.getTitle())
|
||||
.setAllocationNo(OrderNoGenerateUtil.allocation())
|
||||
.setBizAllocationNo(param.getBizAllocationNo())
|
||||
.setChannel(payOrder.getChannel())
|
||||
.setDescription(param.getDescription())
|
||||
.setStatus(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())
|
||||
.setAmount(sumAmount);
|
||||
allocationOrder.setId(orderId);
|
||||
// 更新支付订单分账状态
|
||||
payOrder.setAllocationStatus(PayOrderAllocStatusEnum.ALLOCATION.getCode());
|
||||
payOrderManager.updateById(payOrder);
|
||||
allocationOrderDetailManager.saveAll(details);
|
||||
allocationOrderManager.save(allocationOrder);
|
||||
return new OrderAndDetail().setOrder(allocationOrder).setDetails(details);
|
||||
return this.saveAllocOrder(param, payOrder, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成分账订单, 通过传入的分账方创建
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public OrderAndDetail createAndUpdate(AllocationParam param, PayOrder payOrder) {
|
||||
List<String> receiverNos = param.getReceivers()
|
||||
.stream()
|
||||
@@ -200,6 +176,17 @@ public class AllocationOrderService {
|
||||
return detail;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return this.saveAllocOrder(param, payOrder, details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存分账相关订单信息
|
||||
*/
|
||||
private OrderAndDetail saveAllocOrder(AllocationParam param, PayOrder payOrder, List<AllocationOrderDetail> details ) {
|
||||
long allocId = IdUtil.getSnowflakeNextId();
|
||||
// 分账明细设置ID
|
||||
details.forEach(o -> o.setAllocationId(allocId));
|
||||
|
||||
// 求分账的总额
|
||||
Integer sumAmount = details.stream()
|
||||
.map(AllocationOrderDetail::getAmount)
|
||||
@@ -233,5 +220,13 @@ public class AllocationOrderService {
|
||||
allocationOrderManager.save(allocationOrder);
|
||||
return new OrderAndDetail().setOrder(allocationOrder).setDetails(details);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询扩展订单信息
|
||||
*/
|
||||
public AllocationOrderExtraDto findExtraById(Long id) {
|
||||
return allocationOrderExtraManager.findById(id).map(AllocationOrderExtra::toDto)
|
||||
.orElseThrow(() -> new DataNotExistException("未找到"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -6,12 +6,30 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 分账订单扩展
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "")
|
||||
@Schema(title = "分账订单扩展")
|
||||
public class AllocationOrderExtraDto extends BaseDto {
|
||||
|
||||
/** 异步通知地址 */
|
||||
@Schema(description = "异步通知地址")
|
||||
private String notifyUrl;
|
||||
|
||||
/** 商户扩展参数,回调时会原样返回, 以最后一次为准 */
|
||||
@Schema(description = "商户扩展参数")
|
||||
private String attach;
|
||||
|
||||
/** 请求时间,时间戳转时间 */
|
||||
@Schema(description = "请求时间,传输时间戳")
|
||||
private LocalDateTime reqTime;
|
||||
|
||||
/** 终端ip */
|
||||
@Schema(description = "支付终端ip")
|
||||
private String clientIp;
|
||||
}
|
||||
|
Reference in New Issue
Block a user