mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-03 02:56:20 +00:00
ref 交易调整功能重构
This commit is contained in:
@@ -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<String> list = Arrays.asList(AllocOrderStatusEnum.FINISH.getCode(), AllocOrderStatusEnum.FINISH_FAILED.getCode());
|
||||
if (!list.contains(status)){
|
||||
Map<Long, AllocOrderDetail> 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;
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
|
Reference in New Issue
Block a user