From 864a3655a0893681b19dc9cd92cf15d83b2d03e1 Mon Sep 17 00:00:00 2001 From: bootx Date: Sat, 20 Jul 2024 18:20:57 +0800 Subject: [PATCH] =?UTF-8?q?ref=20=E4=BA=A4=E6=98=93=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adjust/service/AllocAdjustService.java | 54 ++++++++++++++----- .../adjust/entity/TradeAdjustRecord.java | 9 ++++ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/adjust/service/AllocAdjustService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/adjust/service/AllocAdjustService.java index f292b261..f615ef50 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/adjust/service/AllocAdjustService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/payment/adjust/service/AllocAdjustService.java @@ -4,6 +4,8 @@ import cn.bootx.platform.common.core.exception.RepetitiveOperationException; import cn.daxpay.single.core.code.AllocDetailResultEnum; import cn.daxpay.single.core.code.AllocOrderResultEnum; import cn.daxpay.single.core.code.AllocOrderStatusEnum; +import cn.daxpay.single.core.util.TradeNoGenerateUtil; +import cn.daxpay.single.service.code.TradeTypeEnum; import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderDetailManager; import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderManager; import cn.daxpay.single.service.core.order.allocation.entity.AllocOrder; @@ -11,6 +13,8 @@ import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail; import cn.daxpay.single.service.core.payment.adjust.dto.AllocResultItem; import cn.daxpay.single.service.core.payment.adjust.param.AllocAdjustParam; import cn.daxpay.single.service.core.payment.notice.service.ClientNoticeService; +import cn.daxpay.single.service.core.record.adjust.entity.TradeAdjustRecord; +import cn.daxpay.single.service.core.record.adjust.service.TradeAdjustRecordService; import com.baomidou.lock.LockInfo; import com.baomidou.lock.LockTemplate; import lombok.RequiredArgsConstructor; @@ -20,7 +24,10 @@ import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.function.Function; +import java.util.stream.Collectors; /** * 分账调整 @@ -36,6 +43,7 @@ public class AllocAdjustService { private final AllocOrderDetailManager allocOrderDetailManager; private final AllocOrderManager allocOrderManager; private final ClientNoticeService clientNoticeService; + private final TradeAdjustRecordService tradeAdjustRecordService; /** * 分账订单处理 @@ -49,15 +57,19 @@ public class AllocAdjustService { if (Objects.isNull(lock)){ throw new RepetitiveOperationException("分账调整中,请勿重复操作"); } - - - // 如果是分账结束或失败, 不更新状态 String status = allocOrder.getStatus(); - // 如果是分账结束或失败, 不进行对订单进行处理 List list = Arrays.asList(AllocOrderStatusEnum.FINISH.getCode(), AllocOrderStatusEnum.FINISH_FAILED.getCode()); if (!list.contains(status)){ + Map detailMap = allocAdjustParam.getDetails() + .stream() + .collect(Collectors.toMap(AllocOrderDetail::getId, Function.identity())); + // 更新状态 + for (AllocResultItem resultItem : resultItems) { + + } + // 判断明细状态. 获取成功和失败的 long successCount = details.stream() .map(AllocOrderDetail::getResult) @@ -87,16 +99,34 @@ public class AllocAdjustService { .setResult(AllocOrderResultEnum.PART_SUCCESS.getCode()); } } - } - allocOrderDetailManager.updateAllById(details); - allocOrderManager.updateById(allocOrder); + // 更新 + allocOrderDetailManager.updateAllById(details); + allocOrderManager.updateById(allocOrder); - // 如果状态为完成, 发送通知 - if (Objects.equals(AllocOrderStatusEnum.ALLOCATION_END.getCode(), allocOrder.getStatus())){ - // 发送通知 - clientNoticeService.registerAllocNotice(allocOrder, details); + // 如果状态为完成, 发送通知 + if (Objects.equals(AllocOrderStatusEnum.ALLOCATION_END.getCode(), allocOrder.getStatus())){ + // 发送通知 + clientNoticeService.registerAllocNotice(allocOrder, details); + } + return this.saveRecord(allocAdjustParam).getAdjustNo(); } - return ""; + return null; + } + + /** + * 保存记录 + */ + private TradeAdjustRecord saveRecord(AllocAdjustParam param){ + AllocOrder order = param.getOrder(); + TradeAdjustRecord record = new TradeAdjustRecord() + .setAdjustNo(TradeNoGenerateUtil.adjust()) + .setTradeId(order.getId()) + .setChannel(order.getChannel()) + .setSource(param.getSource().getCode()) + .setTradeNo(order.getOrderNo()) + .setType(TradeTypeEnum.ALLOCATION.getCode()); + tradeAdjustRecordService.saveRecord(record); + return record; } } diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/record/adjust/entity/TradeAdjustRecord.java b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/record/adjust/entity/TradeAdjustRecord.java index 6119c8ed..01f89791 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/record/adjust/entity/TradeAdjustRecord.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/daxpay/single/service/core/record/adjust/entity/TradeAdjustRecord.java @@ -3,7 +3,9 @@ package cn.daxpay.single.service.core.record.adjust.entity; import cn.bootx.platform.common.core.function.EntityBaseFunction; import cn.bootx.platform.common.mybatisplus.base.MpCreateEntity; import cn.bootx.table.modify.annotation.DbColumn; +import cn.bootx.table.modify.mysql.annotation.DbMySqlFieldType; import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex; +import cn.bootx.table.modify.mysql.constants.MySqlFieldTypeEnum; import cn.daxpay.single.core.code.PayStatusEnum; import cn.daxpay.single.service.code.TradeAdjustSourceEnum; import cn.daxpay.single.service.core.record.adjust.convert.TradeAdjustRecordConvert; @@ -77,6 +79,13 @@ public class TradeAdjustRecord extends MpCreateEntity implements EntityBaseFunct @DbColumn(comment = "调整后状态", length = 20, isNull = false) private String afterStatus; + /** + * 扩展信息, json格式 + */ + @DbColumn(comment = "扩展信息") + @DbMySqlFieldType(MySqlFieldTypeEnum.LONGTEXT) + private String ext; + /** * 备注 */