From a773c520d19097e08f2db684a5ab0d8b229da313 Mon Sep 17 00:00:00 2001 From: DaxPay Date: Tue, 28 May 2024 20:58:03 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E5=88=86=E8=B4=A6=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA=E4=B8=8D=E5=85=A8=E9=97=AE=E9=A2=98\?= =?UTF-8?q?=E8=B0=83=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../single/demo/service/CashierService.java | 2 + .../src/main/resources/application-dev.yml | 2 +- .../allocation/AllocationOrderController.java | 3 +- .../allocation/convert/AllocationConvert.java | 4 ++ .../entity/AllocationOrderExtra.java | 23 ++++----- .../service/AllocationOrderService.java | 51 +++++++++---------- .../allocation/AllocationOrderExtraDto.java | 20 +++++++- 7 files changed, 60 insertions(+), 45 deletions(-) diff --git a/daxpay-single-demo/src/main/java/cn/daxpay/single/demo/service/CashierService.java b/daxpay-single-demo/src/main/java/cn/daxpay/single/demo/service/CashierService.java index 241b709db..3d7aa9edb 100644 --- a/daxpay-single-demo/src/main/java/cn/daxpay/single/demo/service/CashierService.java +++ b/daxpay-single-demo/src/main/java/cn/daxpay/single/demo/service/CashierService.java @@ -53,6 +53,8 @@ public class CashierService { PayParam payParam = new PayParam(); payParam.setBizOrderNo(param.getBizOrderNo()); payParam.setAllocation(param.getAllocation()); + // 如果为分账, 则设置为默认分账 + payParam.setAutoAllocation(param.getAllocation()); int amount = param.getAmount() .multiply(BigDecimal.valueOf(100)) .intValue(); diff --git a/daxpay-single-start/src/main/resources/application-dev.yml b/daxpay-single-start/src/main/resources/application-dev.yml index b229a1ae1..4bde957f7 100644 --- a/daxpay-single-start/src/main/resources/application-dev.yml +++ b/daxpay-single-start/src/main/resources/application-dev.yml @@ -60,7 +60,7 @@ springdoc: # 开发时显示debug日志 logging: level: - cn.bootx.**: debug + cn.daxpay.**: debug org.springframework.jdbc.core: debug # 项目配置 bootx: diff --git a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java index c9ca8bcbd..5759ba197 100644 --- a/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java +++ b/daxpay-single/daxpay-single-admin/src/main/java/cn/daxpay/single/admin/controller/allocation/AllocationOrderController.java @@ -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 findExtraById(Long id){ + public ResResult findExtraById(Long id){ return Res.ok(allocationOrderService.findExtraById(id)); } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/convert/AllocationConvert.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/convert/AllocationConvert.java index 015235bc4..636d2dfca 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/convert/AllocationConvert.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/convert/AllocationConvert.java @@ -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); diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/entity/AllocationOrderExtra.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/entity/AllocationOrderExtra.java index 35d50bf2d..63ea17fa2 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/entity/AllocationOrderExtra.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/entity/AllocationOrderExtra.java @@ -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 { /** 异步通知地址 */ @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); + } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java index 861fd6354..661f09b55 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/order/allocation/service/AllocationOrderService.java @@ -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 receiversByGroups){ - long orderId = IdUtil.getSnowflakeNextId(); - // 订单明细 List 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 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 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("未找到")); + } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/dto/order/allocation/AllocationOrderExtraDto.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/dto/order/allocation/AllocationOrderExtraDto.java index bf9aa413a..36471ce8b 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/dto/order/allocation/AllocationOrderExtraDto.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/dto/order/allocation/AllocationOrderExtraDto.java @@ -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; }