ref 订单相关字段设置长度, 索引配置, 分账订单名称简化

This commit is contained in:
DaxPay
2024-06-12 19:24:57 +08:00
parent 27e21470c1
commit 73919fea4d
40 changed files with 423 additions and 397 deletions

View File

@@ -6,8 +6,8 @@ import cn.daxpay.single.code.AllocDetailResultEnum;
import cn.daxpay.single.exception.pay.PayFailureException;
import cn.daxpay.single.service.code.AliPayCode;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
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.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.payment.sync.result.AllocRemoteSyncResult;
import cn.daxpay.single.util.PayUtil;
import cn.hutool.core.date.LocalDateTimeUtil;
@@ -46,11 +46,11 @@ public class AliPayAllocationService {
* 发起分账
*/
@SneakyThrows
public void allocation(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails){
public void allocation(AllocOrder allocOrder, List<AllocOrderDetail> orderDetails){
// 分账主体参数
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
model.setOutRequestNo(allocationOrder.getAllocNo());
model.setTradeNo(allocationOrder.getOutOrderNo());
model.setOutRequestNo(allocOrder.getAllocNo());
model.setTradeNo(allocOrder.getOutOrderNo());
model.setRoyaltyMode(AliPayCode.ALLOC_ASYNC);
// 分账子参数 根据Id排序
@@ -76,11 +76,11 @@ public class AliPayAllocationService {
* 分账完结
*/
@SneakyThrows
public void finish(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails ){
public void finish(AllocOrder allocOrder, List<AllocOrderDetail> orderDetails ){
// 分账主体参数
AlipayTradeOrderSettleModel model = new AlipayTradeOrderSettleModel();
model.setOutRequestNo(String.valueOf(allocationOrder.getAllocNo()));
model.setTradeNo(allocationOrder.getOutOrderNo());
model.setOutRequestNo(String.valueOf(allocOrder.getAllocNo()));
model.setTradeNo(allocOrder.getOutOrderNo());
model.setRoyaltyMode(AliPayCode.ALLOC_ASYNC);
// 分账完结参数
SettleExtendParams extendParams = new SettleExtendParams();
@@ -106,21 +106,21 @@ public class AliPayAllocationService {
* 分账状态同步
*/
@SneakyThrows
public AllocRemoteSyncResult sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails){
public AllocRemoteSyncResult sync(AllocOrder allocOrder, List<AllocOrderDetail> allocOrderDetails){
AlipayTradeOrderSettleQueryModel model = new AlipayTradeOrderSettleQueryModel();
model.setTradeNo(allocationOrder.getOutOrderNo());
model.setOutRequestNo(allocationOrder.getAllocNo());
model.setTradeNo(allocOrder.getOutOrderNo());
model.setOutRequestNo(allocOrder.getAllocNo());
AlipayTradeOrderSettleQueryRequest request = new AlipayTradeOrderSettleQueryRequest();
request.setBizModel(model);
AlipayTradeOrderSettleQueryResponse response = AliPayApi.execute(request);
// 验证
this.verifyErrorMsg(response);
Map<String, AllocationOrderDetail> detailMap = allocationOrderDetails.stream()
.collect(Collectors.toMap(AllocationOrderDetail::getReceiverAccount, Function.identity(), CollectorsFunction::retainLatest));
Map<String, AllocOrderDetail> detailMap = allocOrderDetails.stream()
.collect(Collectors.toMap(AllocOrderDetail::getReceiverAccount, Function.identity(), CollectorsFunction::retainLatest));
List<RoyaltyDetail> royaltyDetailList = response.getRoyaltyDetailList();
// 转换成通用的明细详情
for (RoyaltyDetail receiver : royaltyDetailList) {
AllocationOrderDetail detail = detailMap.get(receiver.getTransIn());
AllocOrderDetail detail = detailMap.get(receiver.getTransIn());
if (Objects.nonNull(detail)) {
detail.setResult(this.getDetailResultEnum(receiver.getState()).getCode());
detail.setErrorCode(receiver.getErrorCode());

View File

@@ -7,8 +7,8 @@ import cn.daxpay.single.code.AllocReceiverTypeEnum;
import cn.daxpay.single.exception.pay.PayFailureException;
import cn.daxpay.single.service.code.WeChatPayCode;
import cn.daxpay.single.service.core.channel.wechat.entity.WeChatPayConfig;
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.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.payment.sync.result.AllocRemoteSyncResult;
import cn.daxpay.single.service.dto.channel.wechat.WeChatPayAllocationReceiver;
import cn.hutool.core.codec.Base64;
@@ -51,8 +51,8 @@ public class WeChatPayAllocationService {
* 发起分账
*/
@SneakyThrows
public void allocation(AllocationOrder allocationOrder, List<AllocationOrderDetail> orderDetails, WeChatPayConfig config){
String description = allocationOrder.getDescription();
public void allocation(AllocOrder allocOrder, List<AllocOrderDetail> orderDetails, WeChatPayConfig config){
String description = allocOrder.getDescription();
if (StrUtil.isBlank(description)){
description = "分账";
}
@@ -74,8 +74,8 @@ public class WeChatPayAllocationService {
.mch_id(config.getWxMchId())
.appid(config.getWxAppId())
.nonce_str(WxPayKit.generateStr())
.transaction_id(allocationOrder.getOutOrderNo())
.out_order_no(allocationOrder.getAllocNo())
.transaction_id(allocOrder.getOutOrderNo())
.out_order_no(allocOrder.getAllocNo())
.receivers(JSON.toJSONString(list))
.build()
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
@@ -90,14 +90,14 @@ public class WeChatPayAllocationService {
/**
* 完成分账
*/
public void finish(AllocationOrder allocationOrder, WeChatPayConfig config){
public void finish(AllocOrder allocOrder, WeChatPayConfig config){
Map<String, String> params = ProfitSharingModel.builder()
.mch_id(config.getWxMchId())
.appid(config.getWxAppId())
.nonce_str(WxPayKit.generateStr())
.transaction_id(allocationOrder.getOutOrderNo())
.transaction_id(allocOrder.getOutOrderNo())
// 分账要使用单独的的流水号, 不能与分账号相同
.out_order_no(allocationOrder.getAllocNo()+'F')
.out_order_no(allocOrder.getAllocNo()+'F')
.description("分账已完成")
.build()
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
@@ -112,13 +112,13 @@ public class WeChatPayAllocationService {
/**
* 同步分账状态
*/
public AllocRemoteSyncResult sync(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails, WeChatPayConfig config){
public AllocRemoteSyncResult sync(AllocOrder allocOrder, List<AllocOrderDetail> allocOrderDetails, WeChatPayConfig config){
// 不要传输AppId参数, 否则会失败
Map<String, String> params = ProfitSharingModel.builder()
.mch_id(config.getWxMchId())
.nonce_str(WxPayKit.generateStr())
.transaction_id(allocationOrder.getOutOrderNo())
.out_order_no(allocationOrder.getAllocNo())
.transaction_id(allocOrder.getOutOrderNo())
.out_order_no(allocOrder.getAllocNo())
.build()
.createSign(config.getApiKeyV2(), SignType.HMACSHA256);
String xmlResult = WxPayApi.profitSharingQuery(params);
@@ -126,11 +126,11 @@ public class WeChatPayAllocationService {
this.verifyErrorMsg(result);
String json = result.get(WeChatPayCode.ALLOC_RECEIVERS);
List<WeChatPayAllocationReceiver> receivers = JSONUtil.toBean(json, new TypeReference<List<WeChatPayAllocationReceiver>>() {}, false);
Map<String, AllocationOrderDetail> detailMap = allocationOrderDetails.stream()
.collect(Collectors.toMap(AllocationOrderDetail::getReceiverAccount, Function.identity(), CollectorsFunction::retainLatest));
Map<String, AllocOrderDetail> detailMap = allocOrderDetails.stream()
.collect(Collectors.toMap(AllocOrderDetail::getReceiverAccount, Function.identity(), CollectorsFunction::retainLatest));
// 根据明细更新订单明细内容
for (WeChatPayAllocationReceiver receiver : receivers) {
AllocationOrderDetail detail = detailMap.get(receiver.getAccount());
AllocOrderDetail detail = detailMap.get(receiver.getAccount());
if (Objects.nonNull(detail)){
detail.setResult(this.getDetailResultEnum(receiver.getResult()).getCode());
detail.setErrorMsg(receiver.getFailReason());

View File

@@ -2,12 +2,12 @@ package cn.daxpay.single.service.core.order.allocation.convert;
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.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.payment.notice.result.AllocDetailNoticeResult;
import cn.daxpay.single.service.core.payment.notice.result.AllocNoticeResult;
import cn.daxpay.single.service.dto.order.allocation.AllocOrderDto;
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDto;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
@@ -17,19 +17,19 @@ import org.mapstruct.factory.Mappers;
* @since 2024/4/7
*/
@Mapper
public interface AllocationConvert {
AllocationConvert CONVERT = Mappers.getMapper(AllocationConvert.class);
public interface AllocOrderConvert {
AllocOrderConvert CONVERT = Mappers.getMapper(AllocOrderConvert.class);
AllocationOrderDto convert(AllocationOrder in);
AllocOrderDto convert(AllocOrder in);
AllocOrderResult toResult(AllocationOrder in);
AllocOrderResult toResult(AllocOrder in);
AllocOrderDetailResult toResult(AllocationOrderDetail in);
AllocOrderDetailResult toResult(AllocOrderDetail in);
AllocationOrderDetailDto convert(AllocationOrderDetail in);
AllocationOrderDetailDto convert(AllocOrderDetail in);
AllocNoticeResult toNotice(AllocationOrder in);
AllocNoticeResult toNotice(AllocOrder in);
AllocDetailNoticeResult toNotice(AllocationOrderDetail in);
AllocDetailNoticeResult toNotice(AllocOrderDetail in);
}

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.service.core.order.allocation.dao;
import cn.bootx.platform.common.mybatisplus.impl.BaseManager;
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
@@ -16,12 +16,12 @@ import java.util.List;
@Slf4j
@Repository
@RequiredArgsConstructor
public class AllocationOrderDetailManager extends BaseManager<AllocationOrderDetailMapper, AllocationOrderDetail> {
public class AllocOrderDetailManager extends BaseManager<AllocOrderDetailMapper, AllocOrderDetail> {
/**
* 根据订单ID查询
*/
public List<AllocationOrderDetail> findAllByOrderId(Long orderId) {
return findAllByField(AllocationOrderDetail::getAllocationId, orderId);
public List<AllocOrderDetail> findAllByOrderId(Long orderId) {
return findAllByField(AllocOrderDetail::getAllocationId, orderId);
}
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.service.core.order.allocation.dao;
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrderDetail;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@@ -10,5 +10,5 @@ import org.apache.ibatis.annotations.Mapper;
* @since 2024/4/7
*/
@Mapper
public interface AllocationOrderDetailMapper extends BaseMapper<AllocationOrderDetail> {
public interface AllocOrderDetailMapper extends BaseMapper<AllocOrderDetail> {
}

View File

@@ -1,6 +1,6 @@
package cn.daxpay.single.service.core.order.allocation.dao;
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@@ -10,5 +10,5 @@ import org.apache.ibatis.annotations.Mapper;
* @since 2024/4/7
*/
@Mapper
public interface AllocationOrderMapper extends BaseMapper<AllocationOrder> {
public interface AllocOrderMapper extends BaseMapper<AllocOrder> {
}

View File

@@ -5,8 +5,8 @@ import cn.bootx.platform.common.mybatisplus.impl.BaseManager;
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
import cn.bootx.platform.common.query.generator.QueryGenerator;
import cn.daxpay.single.code.AllocOrderStatusEnum;
import cn.daxpay.single.service.core.order.allocation.entity.AllocationOrder;
import cn.daxpay.single.service.param.order.AllocationOrderQuery;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrder;
import cn.daxpay.single.service.param.order.AllocOrderQuery;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
@@ -25,38 +25,38 @@ import java.util.Optional;
@Slf4j
@Repository
@RequiredArgsConstructor
public class AllocationOrderManager extends BaseManager<AllocationOrderMapper, AllocationOrder> {
public class AllocationOrderManager extends BaseManager<AllocOrderMapper, AllocOrder> {
/**
* 根据分账单号查询
*/
public Optional<AllocationOrder> findByAllocationNo(String allocationNo){
return findByField(AllocationOrder::getAllocNo, allocationNo);
public Optional<AllocOrder> findByAllocNo(String allocNo){
return findByField(AllocOrder::getAllocNo, allocNo);
}
/**
* 根据商户分账号查询
*/
public Optional<AllocationOrder> findByBizAllocationNo(String bizAllocationNo){
return findByField(AllocationOrder::getBizAllocNo, bizAllocationNo);
public Optional<AllocOrder> findByBizAllocNo(String bizAllocNo){
return findByField(AllocOrder::getBizAllocNo, bizAllocNo);
}
/**
* 分页
*/
public Page<AllocationOrder> page(PageParam pageParam, AllocationOrderQuery param){
Page<AllocationOrder> mpPage = MpUtil.getMpPage(pageParam, AllocationOrder.class);
QueryWrapper<AllocationOrder> generator = QueryGenerator.generator(param);
public Page<AllocOrder> page(PageParam pageParam, AllocOrderQuery param){
Page<AllocOrder> mpPage = MpUtil.getMpPage(pageParam, AllocOrder.class);
QueryWrapper<AllocOrder> generator = QueryGenerator.generator(param);
return this.page(mpPage, generator);
}
/**
* 查询待同步的分账单
*/
public List<AllocationOrder> findSyncOrder(){
public List<AllocOrder> findSyncOrder(){
List<String> statusList = Arrays.asList(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode(), AllocOrderStatusEnum.ALLOCATION_END.getCode());
return lambdaQuery()
.in(AllocationOrder::getStatus, statusList)
.in(AllocOrder::getStatus, statusList)
.list();
}
}

View File

@@ -4,11 +4,12 @@ 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.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.AllocOrderResultEnum;
import cn.daxpay.single.code.AllocOrderStatusEnum;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.service.core.order.allocation.convert.AllocationConvert;
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDto;
import cn.daxpay.single.service.core.order.allocation.convert.AllocOrderConvert;
import cn.daxpay.single.service.dto.order.allocation.AllocOrderDto;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -27,86 +28,85 @@ import java.time.LocalDateTime;
@Data
@Accessors(chain = true)
@DbTable(comment = "分账订单")
@TableName("pay_allocation_order")
public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction<AllocationOrderDto> {
@TableName("pay_alloc_order")
public class AllocOrder extends MpBaseEntity implements EntityBaseFunction<AllocOrderDto> {
/**
* 分账单号
*/
@DbColumn(comment = "分账单号")
@DbMySqlIndex(comment = "分账单号索引")
@DbColumn(comment = "分账单号", length = 32, isNull = false)
private String allocNo;
/**
* 商户分账单号
*/
@DbColumn(comment = "商户分账单号")
@DbMySqlIndex(comment = "商户分账单号索引")
@DbColumn(comment = "商户分账单号", length = 100, isNull = false)
private String bizAllocNo;
/**
* 通道分账号
*/
@DbColumn(comment = "通道分账号")
@DbMySqlIndex(comment = "通道分账号索引")
@DbColumn(comment = "通道分账号", length = 150, isNull = false)
private String outAllocNo;
/** 支付订单ID */
@DbColumn(comment = "支付订单ID")
@DbMySqlIndex(comment = "支付订单ID索引")
@DbColumn(comment = "支付订单ID", isNull = false)
private Long orderId;
/**
* 支付订单号
*/
@DbColumn(comment = "支付订单号")
/** 支付订单号 */
@DbMySqlIndex(comment = "支付订单号索引")
@DbColumn(comment = "支付订单号", length = 32, isNull = false)
private String orderNo;
/**
* 商户支付订单号
*/
@DbColumn(comment = "商户支付订单号")
/** 商户支付订单号 */
@DbMySqlIndex(comment = "商户支付订单号索引")
@DbColumn(comment = "商户支付订单号", length = 100, isNull = false)
private String bizOrderNo;
/**
* 通道系统支付订单号
*/
@DbColumn(comment = "通道支付订单号")
/** 通道支付订单号 */
@DbMySqlIndex(comment = "通道支付订单号索引")
@DbColumn(comment = "通道支付订单号", length = 150, isNull = false)
private String outOrderNo;
/**
* 支付订单标题
*/
@DbColumn(comment = "支付订单标题")
/** 支付标题 */
@DbColumn(comment = "支付标题", length = 100, isNull = false)
private String title;
/**
* 所属通道
* @see PayChannelEnum
*/
@DbColumn(comment = "所属通道")
@DbColumn(comment = "所属通道", length = 20, isNull = false)
private String channel;
/**
* 总分账金额
*/
@DbColumn(comment = "总分账金额")
@DbColumn(comment = "总分账金额", length = 15, isNull = false)
private Integer amount;
/**
* 分账描述
*/
@DbColumn(comment = "分账描述")
@DbColumn(comment = "分账描述", length = 150)
private String description;
/**
* 状态
* @see AllocOrderStatusEnum
*/
@DbColumn(comment = "状态")
@DbColumn(comment = "状态", length = 20, isNull = false)
private String status;
/**
* 处理结果
* @see AllocOrderResultEnum
*/
@DbColumn(comment = "处理结果")
@DbColumn(comment = "处理结果", length = 20, isNull = false)
private String result;
/** 分账完成时间 */
@@ -114,12 +114,12 @@ public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction<
private LocalDateTime finishTime;
/** 异步通知地址 */
@DbColumn(comment = "异步通知地址")
@DbColumn(comment = "异步通知地址", length = 200)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String notifyUrl;
/** 商户扩展参数,回调时会原样返回, 以最后一次为准 */
@DbColumn(comment = "商户扩展参数")
@DbColumn(comment = "商户扩展参数", length = 500)
private String attach;
/** 请求时间,时间戳转时间 */
@@ -127,28 +127,22 @@ public class AllocationOrder extends MpBaseEntity implements EntityBaseFunction<
private LocalDateTime reqTime;
/** 终端ip */
@DbColumn(comment = "支付终端ip")
@DbColumn(comment = "支付终端ip", length = 64)
private String clientIp;
/**
* 错误码
*/
@DbColumn(comment = "错误码")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
/** 错误码 */
@DbColumn(comment = "错误码", length = 10)
private String errorCode;
/**
* 错误信息
*/
@DbColumn(comment = "错误原因")
@TableField(updateStrategy = FieldStrategy.ALWAYS)
/** 错误信息 */
@DbColumn(comment = "错误信息", length = 150)
private String errorMsg;
/**
* 转换
*/
@Override
public AllocationOrderDto toDto() {
return AllocationConvert.CONVERT.convert(this);
public AllocOrderDto toDto() {
return AllocOrderConvert.CONVERT.convert(this);
}
}

View File

@@ -4,10 +4,11 @@ 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.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.AllocDetailResultEnum;
import cn.daxpay.single.code.AllocReceiverTypeEnum;
import cn.daxpay.single.service.common.typehandler.DecryptTypeHandler;
import cn.daxpay.single.service.core.order.allocation.convert.AllocationConvert;
import cn.daxpay.single.service.core.order.allocation.convert.AllocOrderConvert;
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -26,58 +27,59 @@ import java.time.LocalDateTime;
@Data
@Accessors(chain = true)
@DbTable(comment = "分账订单明细")
@TableName(value = "pay_allocation_order_detail",autoResultMap = true)
public class AllocationOrderDetail extends MpBaseEntity implements EntityBaseFunction<AllocationOrderDetailDto> {
@TableName(value = "pay_alloc_order_detail",autoResultMap = true)
public class AllocOrderDetail extends MpBaseEntity implements EntityBaseFunction<AllocationOrderDetailDto> {
/** 分账订单ID */
@DbColumn(comment = "分账订单ID")
@DbMySqlIndex(comment = "分账订单ID索引")
@DbColumn(comment = "分账订单ID", isNull = false)
private Long allocationId;
/** 接收者ID */
@DbColumn(comment = "接收者ID")
@DbColumn(comment = "接收者ID", isNull = false)
private Long receiverId;
/** 分账接收方编号 */
@DbColumn(comment = "分账接收方编号")
@DbColumn(comment = "分账接收方编号", length = 20, isNull = false)
private String receiverNo;
/** 分账比例 */
@DbColumn(comment = "分账比例(万分之多少)")
@DbColumn(comment = "分账比例(万分之多少)", length = 5, isNull = false)
private Integer rate;
/** 分账金额 */
@DbColumn(comment = "分账金额")
@DbColumn(comment = "分账金额", length = 15, isNull = false)
private Integer amount;
/**
* 分账接收方类型
* @see AllocReceiverTypeEnum
*/
@DbColumn(comment = "分账接收方类型")
@DbColumn(comment = "分账接收方类型", length = 20, isNull = false)
private String receiverType;
/** 接收方账号 */
@DbColumn(comment = "接收方账号")
@DbColumn(comment = "接收方账号", length = 150, isNull = false)
@TableField(typeHandler = DecryptTypeHandler.class)
private String receiverAccount;
/** 接收方姓名 */
@DbColumn(comment = "接收方姓名")
@DbColumn(comment = "接收方姓名", length = 150)
private String receiverName;
/**
* 分账结果
* @see AllocDetailResultEnum
*/
@DbColumn(comment = "分账结果")
@DbColumn(comment = "分账结果", length = 20, isNull = false)
private String result;
/** 错误代码 */
@DbColumn(comment = "错误代码")
@DbColumn(comment = "错误代码", length = 10)
private String errorCode;
/** 错误原因 */
@DbColumn(comment = "错误原因")
@DbColumn(comment = "错误原因", length = 150)
private String errorMsg;
/** 分账完成时间 */
@@ -89,6 +91,6 @@ public class AllocationOrderDetail extends MpBaseEntity implements EntityBaseFun
*/
@Override
public AllocationOrderDetailDto toDto() {
return AllocationConvert.CONVERT.convert(this);
return AllocOrderConvert.CONVERT.convert(this);
}
}

View File

@@ -15,7 +15,7 @@ import java.util.List;
public class OrderAndDetail {
/** 分账订单 */
private AllocationOrder order;
private AllocOrder order;
/** 分账订单明细 */
private List<AllocationOrderDetail> details;
private List<AllocOrderDetail> details;
}

View File

@@ -7,13 +7,13 @@ import cn.bootx.platform.common.core.rest.param.PageParam;
import cn.bootx.platform.common.core.util.ResultConvertUtil;
import cn.bootx.platform.common.mybatisplus.util.MpUtil;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderDetailManager;
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.order.allocation.entity.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.dto.order.allocation.AllocOrderDto;
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDetailDto;
import cn.daxpay.single.service.dto.order.allocation.AllocationOrderDto;
import cn.daxpay.single.service.param.order.AllocationOrderQuery;
import cn.daxpay.single.service.param.order.AllocOrderQuery;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -29,9 +29,9 @@ import java.util.List;
@Slf4j
@Service
@RequiredArgsConstructor
public class AllocationOrderQueryService {
public class AllocOrderQueryService {
private final AllocationOrderDetailManager allocationOrderDetailManager;
private final AllocOrderDetailManager allocOrderDetailManager;
private final AllocationOrderManager allocationOrderManager;
@@ -48,36 +48,36 @@ public class AllocationOrderQueryService {
/**
* 分页查询
*/
public PageResult<AllocationOrderDto> page(PageParam pageParam, AllocationOrderQuery param){
public PageResult<AllocOrderDto> page(PageParam pageParam, AllocOrderQuery param){
return MpUtil.convert2DtoPageResult(allocationOrderManager.page(pageParam, param));
}
/**
* 查询详情
*/
public AllocationOrderDto findById(Long id) {
return allocationOrderManager.findById(id).map(AllocationOrder::toDto).orElseThrow(() -> new DataNotExistException("分账订单不存在"));
public AllocOrderDto findById(Long id) {
return allocationOrderManager.findById(id).map(AllocOrder::toDto).orElseThrow(() -> new DataNotExistException("分账订单不存在"));
}
/**
* 查询详情
*/
public AllocationOrderDto findByAllocNo(String allocNo) {
return allocationOrderManager.findByAllocationNo(allocNo).map(AllocationOrder::toDto).orElseThrow(() -> new DataNotExistException("分账订单不存在"));
public AllocOrderDto findByAllocNo(String allocNo) {
return allocationOrderManager.findByAllocNo(allocNo).map(AllocOrder::toDto).orElseThrow(() -> new DataNotExistException("分账订单不存在"));
}
/**
* 查询订单明细列表
*/
public List<AllocationOrderDetailDto> findDetailsByOrderId(Long orderId){
return ResultConvertUtil.dtoListConvert(allocationOrderDetailManager.findAllByOrderId(orderId));
return ResultConvertUtil.dtoListConvert(allocOrderDetailManager.findAllByOrderId(orderId));
}
/**
* 查询订单明细详情
*/
public AllocationOrderDetailDto findDetailById(Long id){
return allocationOrderDetailManager.findById(id).map(AllocationOrderDetail::toDto).orElseThrow(() -> new DataNotExistException("分账订单明细不存在"));
return allocOrderDetailManager.findById(id).map(AllocOrderDetail::toDto).orElseThrow(() -> new DataNotExistException("分账订单明细不存在"));
}
}

View File

@@ -6,10 +6,10 @@ import cn.daxpay.single.code.PayOrderAllocStatusEnum;
import cn.daxpay.single.exception.pay.PayFailureException;
import cn.daxpay.single.param.payment.allocation.AllocReceiverParam;
import cn.daxpay.single.param.payment.allocation.AllocationParam;
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderDetailManager;
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.order.allocation.entity.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.order.allocation.entity.OrderAndDetail;
import cn.daxpay.single.service.core.order.pay.dao.PayOrderManager;
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
@@ -39,12 +39,12 @@ import java.util.stream.Collectors;
@Slf4j
@Service
@RequiredArgsConstructor
public class AllocationOrderService {
public class AllocOrderService {
private final AllocationReceiverManager receiverManager;
private final AllocationOrderManager allocationOrderManager;
private final AllocationOrderDetailManager allocationOrderDetailManager;
private final AllocOrderDetailManager allocOrderDetailManager;
private final PayOrderManager payOrderManager;
@@ -55,7 +55,7 @@ public class AllocationOrderService {
@Transactional(rollbackFor = Exception.class)
public OrderAndDetail createAndUpdate(AllocationParam param, PayOrder payOrder, List<AllocationGroupReceiverResult> receiversByGroups){
// 订单明细
List<AllocationOrderDetail> details = receiversByGroups.stream()
List<AllocOrderDetail> details = receiversByGroups.stream()
.map(o -> {
// 计算分账金额, 小数部分直接舍弃, 防止分账金额超过上限
Integer rate = o.getRate();
@@ -64,7 +64,7 @@ public class AllocationOrderService {
.multiply(BigDecimal.valueOf(rate))
.divide(BigDecimal.valueOf(10000), 0, RoundingMode.DOWN).intValue();
AllocationOrderDetail detail = new AllocationOrderDetail()
AllocOrderDetail detail = new AllocOrderDetail()
.setReceiverNo(o.getReceiverNo())
.setReceiverId(o.getId())
.setAmount(amount)
@@ -117,14 +117,14 @@ public class AllocationOrderService {
long allocId = IdUtil.getSnowflakeNextId();
// 订单明细
List<AllocationOrderDetail> details = receivers.stream()
List<AllocOrderDetail> details = receivers.stream()
.map(o -> {
// 计算分账比例, 不是很精确
Integer amount = receiverNoMap.get(o.getReceiverNo());
Integer rate = BigDecimal.valueOf(amount)
.divide(BigDecimal.valueOf(payOrder.getAmount()), 4, RoundingMode.DOWN)
.multiply(BigDecimal.valueOf(10000)).intValue();
AllocationOrderDetail detail = new AllocationOrderDetail();
AllocOrderDetail detail = new AllocOrderDetail();
detail.setAllocationId(allocId)
.setReceiverId(o.getId())
.setReceiverNo(o.getReceiverNo())
@@ -143,16 +143,16 @@ public class AllocationOrderService {
/**
* 保存分账相关订单信息
*/
private OrderAndDetail saveAllocOrder(AllocationParam param, PayOrder payOrder, List<AllocationOrderDetail> details ) {
private OrderAndDetail saveAllocOrder(AllocationParam param, PayOrder payOrder, List<AllocOrderDetail> details ) {
long allocId = IdUtil.getSnowflakeNextId();
// 分账明细设置ID
details.forEach(o -> o.setAllocationId(allocId));
// 求分账的总额
Integer sumAmount = details.stream()
.map(AllocationOrderDetail::getAmount)
.map(AllocOrderDetail::getAmount)
.reduce(0, Integer::sum);
// 分账订单
AllocationOrder allocationOrder = new AllocationOrder()
AllocOrder allocOrder = new AllocOrder()
.setOrderId(payOrder.getId())
.setOrderNo(payOrder.getOrderNo())
.setBizOrderNo(payOrder.getBizOrderNo())
@@ -169,19 +169,19 @@ public class AllocationOrderService {
.setClientIp(param.getClientIp());
// 如果分账订单金额为0, 设置为忽略状态
if (sumAmount == 0){
allocationOrder.setStatus(AllocOrderStatusEnum.IGNORE.getCode())
allocOrder.setStatus(AllocOrderStatusEnum.IGNORE.getCode())
.setFinishTime(LocalDateTime.now())
.setResult(AllocOrderStatusEnum.ALLOCATION_FAILED.getCode())
.setErrorMsg("分账比例有误或金额太小, 无法进行分账");
}
allocationOrder.setId(allocId);
allocOrder.setId(allocId);
// 更新支付订单分账状态
payOrder.setAllocStatus(PayOrderAllocStatusEnum.ALLOCATION.getCode());
payOrderManager.updateById(payOrder);
allocationOrderDetailManager.saveAll(details);
allocationOrderManager.save(allocationOrder);
return new OrderAndDetail().setOrder(allocationOrder).setDetails(details);
allocOrderDetailManager.saveAll(details);
allocationOrderManager.save(allocOrder);
return new OrderAndDetail().setOrder(allocOrder).setDetails(details);
}
}

View File

@@ -2,20 +2,15 @@ package cn.daxpay.single.service.core.order.pay.entity;
import cn.bootx.platform.common.core.function.EntityBaseFunction;
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.daxpay.single.code.PayMethodEnum;
import cn.daxpay.single.code.PayOrderAllocStatusEnum;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.code.PayOrderRefundStatusEnum;
import cn.daxpay.single.code.PayStatusEnum;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.*;
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.pay.convert.PayOrderConvert;
import cn.daxpay.single.service.dto.order.pay.PayOrderDto;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.bootx.table.modify.mysql.constants.MySqlIndexType;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -39,25 +34,27 @@ import java.util.Objects;
public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrderDto> {
/** 商户订单号 */
@DbMySqlIndex(comment = "商户订单号索引",type = MySqlIndexType.UNIQUE)
@DbColumn(comment = "商户订单号")
@DbMySqlIndex(comment = "商户订单号索引")
@DbColumn(comment = "商户订单号", length = 100, isNull = false)
private String bizOrderNo;
@DbColumn(comment = "支付订单号")
@DbMySqlIndex(comment = "支付订单号索引")
@DbColumn(comment = "支付订单号", length = 32, isNull = false)
private String orderNo;
/**
* 通道系统交易号
*/
@DbColumn(comment = "通道支付订单")
@DbMySqlIndex(comment = "通道支付订单索引")
@DbColumn(comment = "通道支付订单号", length = 150)
private String outOrderNo;
/** 标题 */
@DbColumn(comment = "标题")
@DbColumn(comment = "标题", length = 100, isNull = false)
private String title;
/** 描述 */
@DbColumn(comment = "描述")
@DbColumn(comment = "描述",length = 500)
private String description;
/** 是否支持分账 */
@@ -71,36 +68,36 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
* 支付通道
* @see PayChannelEnum
*/
@DbColumn(comment = "异步支付通道")
@DbColumn(comment = "异步支付通道", length = 20, isNull = false)
private String channel;
/**
* 支付方式
* @see PayMethodEnum
*/
@DbColumn(comment = "支付方式")
@DbColumn(comment = "支付方式", length = 20, isNull = false)
private String method;
/** 金额 */
@DbColumn(comment = "金额")
@DbColumn(comment = "金额", length = 15, isNull = false)
private Integer amount;
/** 可退款余额 */
@DbColumn(comment = "可退款余额")
@DbColumn(comment = "可退款余额", length = 15, isNull = false)
private Integer refundableBalance;
/**
* 支付状态
* @see PayStatusEnum
*/
@DbColumn(comment = "支付状态")
@DbColumn(comment = "支付状态", length = 20, isNull = false)
private String status;
/**
* 退款状态
* @see PayOrderRefundStatusEnum
*/
@DbColumn(comment = "退款状态")
@DbColumn(comment = "退款状态", length = 20, isNull = false)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String refundStatus;
@@ -108,7 +105,7 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
* 分账状态
* @see PayOrderAllocStatusEnum
*/
@DbColumn(comment = "分账状态")
@DbColumn(comment = "分账状态", length = 20)
private String allocStatus;
/** 支付时间 */
@@ -126,22 +123,22 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
private LocalDateTime expiredTime;
/** 错误码 */
@DbColumn(comment = "错误码")
@DbColumn(comment = "错误码", length = 10)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String errorCode;
/** 错误信息 */
@DbColumn(comment = "错误信息")
@DbColumn(comment = "错误信息", length = 150)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String errorMsg;
/** 同步跳转地址, 以最后一次为准 */
@DbColumn(comment = "同步跳转地址")
@DbColumn(comment = "同步跳转地址", length = 200)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String returnUrl;
/** 异步通知地址,以最后一次为准 */
@DbColumn(comment = "异步通知地址")
@DbColumn(comment = "异步通知地址", length = 200)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String notifyUrl;
@@ -151,25 +148,22 @@ public class PayOrder extends MpBaseEntity implements EntityBaseFunction<PayOrde
* @see WeChatPayParam
* @see WalletPayParam
*/
@DbColumn(comment = "附加参数")
@DbColumn(comment = "附加参数", length = 2048)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String extraParam;
/** 商户扩展参数,回调时会原样返回, 以最后一次为准 */
@DbColumn(comment = "商户扩展参数")
@DbColumn(comment = "商户扩展参数", length = 500)
private String attach;
/** 请求时间,时间戳转时间, 以最后一次为准 */
@DbColumn(comment = "请求时间,传输时间戳,以最后一次为准")
@DbColumn(comment = "请求时间")
private LocalDateTime reqTime;
/** 支付终端ip 以最后一次为准 */
@DbColumn(comment = "支付终端ip")
@DbColumn(comment = "支付终端ip", length = 64)
private String clientIp;
/**
* 如果
*/
public Boolean getAllocation() {
return Objects.equals(this.allocation, true);
}

View File

@@ -1,13 +1,14 @@
package cn.daxpay.single.service.core.order.reconcile.entity;
import cn.bootx.platform.common.core.function.EntityBaseFunction;
import cn.bootx.platform.common.mybatisplus.base.MpCreateEntity;
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.service.code.ReconcileResultEnum;
import cn.daxpay.single.service.core.order.reconcile.conver.ReconcileConvert;
import cn.daxpay.single.service.dto.order.reconcile.ReconcileOrderDto;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -27,45 +28,46 @@ import java.time.LocalDate;
@Accessors(chain = true)
@DbTable(comment = "支付对账单订单")
@TableName(value = "pay_reconcile_order")
public class ReconcileOrder extends MpCreateEntity implements EntityBaseFunction<ReconcileOrderDto> {
public class ReconcileOrder extends MpBaseEntity implements EntityBaseFunction<ReconcileOrderDto> {
/** 对账号 */
@DbColumn(comment = "对账号")
@DbMySqlIndex(comment = "对账号索引")
@DbColumn(comment = "对账号", length = 32, isNull = false)
private String reconcileNo;
/** 日期 */
@DbColumn(comment = "日期")
@DbColumn(comment = "日期", isNull = false)
private LocalDate date;
/**
* 通道
* @see PayChannelEnum
*/
@DbColumn(comment = "通道")
@DbColumn(comment = "通道", length = 20, isNull = false)
private String channel;
/** 交易对账文件是否下载成功 */
@DbColumn(comment = "明细对账单下载")
@DbColumn(comment = "明细对账单下载", isNull = false)
private boolean downOrUpload;
/** 交易对账文件是否比对完成 */
@DbColumn(comment = "明细对账单比对")
@DbColumn(comment = "明细对账单比对", isNull = false)
private boolean compare;
/**
* 交易对账结果
* @see ReconcileResultEnum
*/
@DbColumn(comment = "对账结果")
@DbColumn(comment = "对账结果", length = 20)
private String result;
/** 错误码 */
@DbColumn(comment = "错误码")
@DbColumn(comment = "错误码", length = 10)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String errorCode;
/** 错误信息 */
@DbColumn(comment = "错误信息")
@DbColumn(comment = "错误信息", length = 150)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String errorMsg;

View File

@@ -2,6 +2,9 @@ package cn.daxpay.single.service.core.order.refund.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.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.code.RefundStatusEnum;
import cn.daxpay.single.param.channel.AliPayParam;
@@ -9,8 +12,6 @@ import cn.daxpay.single.param.channel.WalletPayParam;
import cn.daxpay.single.param.channel.WeChatPayParam;
import cn.daxpay.single.service.core.order.refund.convert.RefundOrderConvert;
import cn.daxpay.single.service.dto.order.refund.RefundOrderDto;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
@@ -33,54 +34,61 @@ import java.time.LocalDateTime;
public class RefundOrder extends MpBaseEntity implements EntityBaseFunction<RefundOrderDto> {
/** 支付订单ID */
@DbColumn(comment = "支付订单ID")
@DbMySqlIndex(comment = "支付订单ID索引")
@DbColumn(comment = "支付订单ID", isNull = false)
private Long orderId;
/** 支付订单号 */
@DbColumn(comment = "支付订单号")
@DbMySqlIndex(comment = "支付订单号索引")
@DbColumn(comment = "支付订单号", length = 32, isNull = false)
private String orderNo;
/** 商户支付订单号 */
@DbColumn(comment = "商户支付订单号")
@DbMySqlIndex(comment = "商户支付订单号索引")
@DbColumn(comment = "商户支付订单号", length = 100, isNull = false)
private String bizOrderNo;
/** 通道支付订单号 */
@DbColumn(comment = "通道支付订单号")
@DbMySqlIndex(comment = "通道支付订单号索引")
@DbColumn(comment = "通道支付订单号", length = 150, isNull = false)
private String outOrderNo;
/** 支付标题 */
@DbColumn(comment = "支付标题")
@DbColumn(comment = "支付标题", length = 100, isNull = false)
private String title;
/** 退款号 */
@DbColumn(comment = "退款号")
@DbMySqlIndex(comment = "退款号索引")
@DbColumn(comment = "退款号", length = 32, isNull = false)
private String refundNo;
/** 商户退款号 */
@DbColumn(comment = "商户退款号")
@DbMySqlIndex(comment = "商户退款号索引")
@DbColumn(comment = "商户退款号", length = 100, isNull = false)
private String bizRefundNo;
/** 通道退款交易号 */
@DbColumn(comment = "通道退款交易号")
@DbMySqlIndex(comment = "通道退款交易号索引")
@DbColumn(comment = "通道退款交易号", length = 150)
private String outRefundNo;
/**
* 退款通道
* @see PayChannelEnum
*/
@DbColumn(comment = "支付通道")
@DbColumn(comment = "支付通道", length = 20, isNull = false)
private String channel;
/** 订单金额 */
@DbColumn(comment = "订单金额")
@DbColumn(comment = "订单金额", length = 15, isNull = false)
private Integer orderAmount;
/** 退款金额 */
@DbColumn(comment = "退款金额")
@DbColumn(comment = "退款金额", length = 15, isNull = false)
private Integer amount;
/** 退款原因 */
@DbColumn(comment = "退款原因")
@DbColumn(comment = "退款原因", length = 150)
private String reason;
/** 退款完成时间 */
@@ -91,16 +99,16 @@ public class RefundOrder extends MpBaseEntity implements EntityBaseFunction<Refu
* 退款状态
* @see RefundStatusEnum
*/
@DbColumn(comment = "退款状态")
@DbColumn(comment = "退款状态", length = 20, isNull = false)
private String status;
/** 异步通知地址 */
@DbColumn(comment = "异步通知地址")
@DbColumn(comment = "异步通知地址", length = 200)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String notifyUrl;
/** 商户扩展参数,回调时会原样返回, 以最后一次为准 */
@DbColumn(comment = "商户扩展参数")
@DbColumn(comment = "商户扩展参数", length = 500)
private String attach;
/**
@@ -109,7 +117,7 @@ public class RefundOrder extends MpBaseEntity implements EntityBaseFunction<Refu
* @see WeChatPayParam
* @see WalletPayParam
*/
@DbColumn(comment = "附加参数")
@DbColumn(comment = "附加参数", length = 2048)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String extraParam;
@@ -118,15 +126,15 @@ public class RefundOrder extends MpBaseEntity implements EntityBaseFunction<Refu
private LocalDateTime reqTime;
/** 终端ip */
@DbColumn(comment = "支付终端ip")
@DbColumn(comment = "支付终端ip", length = 64)
private String clientIp;
/** 错误码 */
@DbColumn(comment = "错误码")
@DbColumn(comment = "错误码", length = 10)
private String errorCode;
/** 错误信息 */
@DbColumn(comment = "错误信息")
@DbColumn(comment = "错误信息", length = 150)
private String errorMsg;
@Override

View File

@@ -3,6 +3,7 @@ package cn.daxpay.single.service.core.order.transfer.entity;
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
import cn.bootx.table.modify.annotation.DbColumn;
import cn.bootx.table.modify.annotation.DbTable;
import cn.bootx.table.modify.mysql.annotation.DbMySqlIndex;
import cn.daxpay.single.code.PayChannelEnum;
import cn.daxpay.single.code.TransferPayeeTypeEnum;
import cn.daxpay.single.code.TransferTypeEnum;
@@ -28,71 +29,74 @@ import java.time.LocalDateTime;
public class TransferOrder extends MpBaseEntity {
/** 商户转账号 */
@DbColumn(comment = "商户转账号")
@DbMySqlIndex(comment = "商户转账号索引")
@DbColumn(comment = "商户转账号", length = 100, isNull = false)
private String bizTransferNo;
/** 转账号 */
@DbColumn(comment = "转账号")
@DbMySqlIndex(comment = "转账号索引")
@DbColumn(comment = "转账号", length = 150, isNull = false)
private String transferNo;
/** 通道转账号 */
@DbColumn(comment = "通道转账号")
@DbMySqlIndex(comment = "通道转账号索引")
@DbColumn(comment = "通道转账号", length = 150)
private String outTransferNo;
/**
* 支付通道
* @see PayChannelEnum
*/
@DbColumn(comment = "支付通道")
@DbColumn(comment = "支付通道", length = 20, isNull = false)
private String channel;
/** 转账金额 */
@DbColumn(comment = "转账金额")
@DbColumn(comment = "转账金额", length = 15, isNull = false)
private Integer amount;
/** 标题 */
@DbColumn(comment = "标题")
@DbColumn(comment = "标题", length = 100)
private String title;
/** 转账原因/备注 */
@DbColumn(comment = "转账原因/备注")
@DbColumn(comment = "转账原因/备注", length = 150)
private String reason;
/**
* 转账类型, 微信使用
* @see TransferTypeEnum
*/
@DbColumn(comment = "转账类型, 微信使用")
@DbColumn(comment = "转账类型, 微信使用", length = 20)
private String transferType;
/** 付款方 */
@DbColumn(comment = "付款方")
@DbColumn(comment = "付款方", length = 100)
private String payer;
/** 付款方显示名称 */
@DbColumn(comment = "付款方显示名称")
@DbColumn(comment = "付款方显示名称", length = 50)
private String payerShowName;
/**
* 收款人类型
* @see TransferPayeeTypeEnum
*/
@DbColumn(comment = "收款人类型")
@DbColumn(comment = "收款人类型", length = 20)
private String payeeType;
/** 收款人账号 */
@DbColumn(comment = "收款人账号")
@DbColumn(comment = "收款人账号", length = 100)
private String payeeAccount;
/** 收款人姓名 */
@DbColumn(comment = "收款人姓名")
@DbColumn(comment = "收款人姓名", length = 50)
private String payeeName;
/**
* 状态
* @see cn.daxpay.single.code.TransferStatusEnum
*/
@DbColumn(comment = "状态")
@DbColumn(comment = "状态", length = 20, isNull = false)
private String status;
/** 成功时间 */
@@ -101,12 +105,12 @@ public class TransferOrder extends MpBaseEntity {
/** 异步通知地址 */
@DbColumn(comment = "异步通知地址")
@DbColumn(comment = "异步通知地址", length = 200)
@TableField(updateStrategy = FieldStrategy.ALWAYS)
private String notifyUrl;
/** 商户扩展参数,回调时会原样返回, 以最后一次为准 */
@DbColumn(comment = "商户扩展参数")
@DbColumn(comment = "商户扩展参数", length = 500)
private String attach;
/** 请求时间,时间戳转时间 */
@@ -114,15 +118,15 @@ public class TransferOrder extends MpBaseEntity {
private LocalDateTime reqTime;
/** 终端ip */
@DbColumn(comment = "支付终端ip")
@DbColumn(comment = "支付终端ip", length = 64)
private String clientIp;
/** 错误提示码 */
@DbColumn(comment = "错误提示")
/** 错误码 */
@DbColumn(comment = "错误码", length = 10)
private String errorCode;
/** 错误提示 */
@DbColumn(comment = "错误提示")
/** 错误信息 */
@DbColumn(comment = "错误信息", length = 150)
private String errorMsg;
}

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.core.payment.allocation.service;
import cn.daxpay.single.param.payment.allocation.AllocationParam;
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.AllocOrder;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -25,7 +25,7 @@ public class AllocationAssistService {
* 根据新传入的分账订单更新订单和扩展信息
*/
@Transactional(rollbackFor = Exception.class)
public void updateOrder(AllocationParam allocationParam, AllocationOrder orderExtra) {
public void updateOrder(AllocationParam allocationParam, AllocOrder orderExtra) {
// 扩展信息
orderExtra.setClientIp(allocationParam.getClientIp())
.setNotifyUrl(allocationParam.getNotifyUrl())

View File

@@ -15,13 +15,13 @@ 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.service.common.local.PaymentContextLocal;
import cn.daxpay.single.service.core.order.allocation.convert.AllocationConvert;
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
import cn.daxpay.single.service.core.order.allocation.convert.AllocOrderConvert;
import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderDetailManager;
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.order.allocation.entity.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.order.allocation.entity.OrderAndDetail;
import cn.daxpay.single.service.core.order.allocation.service.AllocationOrderService;
import cn.daxpay.single.service.core.order.allocation.service.AllocOrderService;
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;
@@ -60,9 +60,9 @@ public class AllocationService {
private final AllocationGroupService allocationGroupService;
private final AllocationOrderService allocationOrderService;
private final AllocOrderService allocOrderService;
private final AllocationOrderDetailManager allocationOrderDetailManager;
private final AllocOrderDetailManager allocOrderDetailManager;
private final AllocationAssistService allocationAssistService;
@@ -76,11 +76,11 @@ public class AllocationService {
*/
public AllocationResult allocation(AllocationParam param) {
// 判断是否已经有分账订单
AllocationOrder allocationOrder = allocationOrderManager.findByBizAllocationNo(param.getBizAllocationNo())
AllocOrder allocOrder = allocationOrderManager.findByBizAllocNo(param.getBizAllocationNo())
.orElse(null);
if (Objects.nonNull(allocationOrder)){
if (Objects.nonNull(allocOrder)){
// 重复分账
return this.retryAllocation(param, allocationOrder);
return this.retryAllocation(param, allocOrder);
} else {
// 首次分账
PayOrder payOrder = this.getAndCheckPayOrder(param);
@@ -100,8 +100,8 @@ public class AllocationService {
// 构建分账订单相关信息
OrderAndDetail orderAndDetail = this.checkAndCreateAlloc(param, payOrder);
// 检查是否需要进行分账
AllocationOrder order = orderAndDetail.getOrder();
List<AllocationOrderDetail> details = orderAndDetail.getDetails();
AllocOrder order = orderAndDetail.getOrder();
List<AllocOrderDetail> details = orderAndDetail.getDetails();
// 无需进行分账,
if (Objects.equals(order.getStatus(),AllocOrderStatusEnum.IGNORE.getCode())){
return new AllocationResult()
@@ -147,7 +147,7 @@ public class AllocationService {
/**
* 重新分账
*/
private AllocationResult retryAllocation(AllocationParam param, AllocationOrder order){
private AllocationResult retryAllocation(AllocationParam param, AllocOrder order){
LockInfo lock = lockTemplate.lock("payment:allocation:" + order.getOrderId(),10000,200);
if (Objects.isNull(lock)){
throw new RepetitiveOperationException("分账发起处理中,请勿重复操作");
@@ -160,7 +160,7 @@ public class AllocationService {
if (!list.contains(order.getStatus())){
throw new PayFailureException("分账单状态错误,无法重试");
}
List<AllocationOrderDetail> details = this.getDetails(order.getId());
List<AllocOrderDetail> details = this.getDetails(order.getId());
// 创建分账策略并初始化
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(order.getChannel(),AbsAllocationStrategy.class);
allocationStrategy.initParam(order, details);
@@ -194,30 +194,30 @@ public class AllocationService {
* 分账完结
*/
public AllocationResult finish(AllocFinishParam param) {
AllocationOrder allocationOrder;
AllocOrder allocOrder;
if (Objects.nonNull(param.getAllocNo())){
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocNo())
allocOrder = allocationOrderManager.findByAllocNo(param.getAllocNo())
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
} else {
allocationOrder = allocationOrderManager.findByBizAllocationNo(param.getBizAllocNo())
allocOrder = allocationOrderManager.findByBizAllocNo(param.getBizAllocNo())
.orElseThrow(() -> new DataNotExistException("未查询到分账单信息"));
}
return this.finish(allocationOrder);
return this.finish(allocOrder);
}
/**
* 分账完结
*/
public AllocationResult finish(AllocationOrder allocationOrder) {
public AllocationResult finish(AllocOrder allocOrder) {
// 只有分账结束后才可以完结
if (!Arrays.asList(ALLOCATION_END.getCode(),FINISH_FAILED.getCode()).contains(allocationOrder.getStatus())) {
if (!Arrays.asList(ALLOCATION_END.getCode(),FINISH_FAILED.getCode()).contains(allocOrder.getStatus())) {
throw new PayFailureException("分账单状态错误");
}
List<AllocationOrderDetail> details = this.getDetails(allocationOrder.getId());
List<AllocOrderDetail> details = this.getDetails(allocOrder.getId());
// 创建分账策略并初始化
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(allocationOrder.getChannel(),AbsAllocationStrategy.class);
allocationStrategy.initParam(allocationOrder, details);
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(allocOrder.getChannel(),AbsAllocationStrategy.class);
allocationStrategy.initParam(allocOrder, details);
// 分账完结预处理
allocationStrategy.doBeforeHandler();
@@ -225,20 +225,20 @@ public class AllocationService {
// 完结处理
allocationStrategy.finish();
// 完结状态
allocationOrder.setStatus(AllocOrderStatusEnum.FINISH.getCode())
allocOrder.setStatus(AllocOrderStatusEnum.FINISH.getCode())
.setFinishTime(LocalDateTime.now())
.setErrorMsg(null);
} catch (Exception e) {
log.error("分账完结错误:", e);
// 失败
allocationOrder.setStatus(FINISH_FAILED.getCode())
allocOrder.setStatus(FINISH_FAILED.getCode())
.setErrorMsg(e.getMessage());
}
allocationOrderManager.updateById(allocationOrder);
allocationOrderManager.updateById(allocOrder);
return new AllocationResult()
.setAllocNo(allocationOrder.getAllocNo())
.setBizAllocNo(allocationOrder.getBizAllocNo())
.setStatus(allocationOrder.getStatus());
.setAllocNo(allocOrder.getAllocNo())
.setBizAllocNo(allocOrder.getBizAllocNo())
.setStatus(allocOrder.getStatus());
}
/**
@@ -264,12 +264,12 @@ public class AllocationService {
*/
public AllocOrderResult queryAllocationOrder(QueryAllocOrderParam param) {
// 查询分账单
AllocationOrder allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocNo())
AllocOrder allocOrder = allocationOrderManager.findByAllocNo(param.getAllocNo())
.orElseThrow(() -> new PayFailureException("分账单不存在"));
AllocOrderResult result = AllocationConvert.CONVERT.toResult(allocationOrder);
AllocOrderResult result = AllocOrderConvert.CONVERT.toResult(allocOrder);
// 查询分账单明细
List<AllocOrderDetailResult> details = allocationOrderDetailManager.findAllByOrderId(allocationOrder.getId()).stream()
.map(AllocationConvert.CONVERT::toResult)
List<AllocOrderDetailResult> details = allocOrderDetailManager.findAllByOrderId(allocOrder.getId()).stream()
.map(AllocOrderConvert.CONVERT::toResult)
.collect(Collectors.toList());
result.setDetails(details);
return result;
@@ -283,7 +283,7 @@ public class AllocationService {
OrderAndDetail orderAndDetail;
// 判断是否传输了分账接收方列表
if (CollUtil.isNotEmpty(param.getReceivers())) {
orderAndDetail = allocationOrderService.createAndUpdate(param, payOrder);
orderAndDetail = allocOrderService.createAndUpdate(param, payOrder);
} else {
AllocationGroup allocationGroup;
if (Objects.nonNull(param.getGroupNo())){
@@ -299,7 +299,7 @@ public class AllocationService {
}
List<AllocationGroupReceiverResult> receiversByGroups = allocationGroupService.findReceiversByGroups(allocationGroup.getId());
orderAndDetail = allocationOrderService.createAndUpdate(param ,payOrder, receiversByGroups);
orderAndDetail = allocOrderService.createAndUpdate(param ,payOrder, receiversByGroups);
}
return orderAndDetail;
}
@@ -307,8 +307,8 @@ public class AllocationService {
/**
* 获取发起分账或完结的明细
*/
private List<AllocationOrderDetail> getDetails(Long allocOrderId){
List<AllocationOrderDetail> details = allocationOrderDetailManager.findAllByOrderId(allocOrderId);
private List<AllocOrderDetail> getDetails(Long allocOrderId){
List<AllocOrderDetail> details = allocOrderDetailManager.findAllByOrderId(allocOrderId);
// 过滤掉忽略的条目
return details.stream()
.filter(detail -> !Objects.equals(detail.getResult(), AllocDetailResultEnum.IGNORE.getCode()))

View File

@@ -9,10 +9,10 @@ import cn.daxpay.single.param.payment.allocation.AllocSyncParam;
import cn.daxpay.single.result.sync.AllocSyncResult;
import cn.daxpay.single.service.code.PaymentTypeEnum;
import cn.daxpay.single.service.common.local.PaymentContextLocal;
import cn.daxpay.single.service.core.order.allocation.dao.AllocationOrderDetailManager;
import cn.daxpay.single.service.core.order.allocation.dao.AllocOrderDetailManager;
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.order.allocation.entity.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
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;
@@ -45,7 +45,7 @@ public class AllocationSyncService {
private final AllocationOrderManager allocationOrderManager;
private final AllocationOrderDetailManager allocationOrderDetailManager;
private final AllocOrderDetailManager allocOrderDetailManager;
private final PaySyncRecordService paySyncRecordService;
@@ -57,46 +57,46 @@ public class AllocationSyncService {
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public AllocSyncResult sync(AllocSyncParam param) {
// 获取分账订单
AllocationOrder allocationOrder = null;
AllocOrder allocOrder = null;
if (Objects.nonNull(param.getAllocNo())){
allocationOrder = allocationOrderManager.findByAllocationNo(param.getAllocNo())
allocOrder = allocationOrderManager.findByAllocNo(param.getAllocNo())
.orElseThrow(() -> new DataNotExistException("分账单不存在"));
}
if (Objects.isNull(allocationOrder)){
allocationOrder = allocationOrderManager.findByAllocationNo(param.getBizAllocNo())
if (Objects.isNull(allocOrder)){
allocOrder = allocationOrderManager.findByAllocNo(param.getBizAllocNo())
.orElseThrow(() -> new DataNotExistException("分账单不存在"));
}
// 如果类型为忽略, 不进行同步处理
if (Objects.equals(allocationOrder.getStatus(), AllocOrderStatusEnum.IGNORE.getCode())){
if (Objects.equals(allocOrder.getStatus(), AllocOrderStatusEnum.IGNORE.getCode())){
return new AllocSyncResult();
}
// 调用同步逻辑
this.sync(allocationOrder);
this.sync(allocOrder);
return new AllocSyncResult();
}
/**
* 分账同步
*/
public void sync(AllocationOrder allocationOrder){
LockInfo lock = lockTemplate.lock("payment:allocation:" + allocationOrder.getOrderId(),10000,200);
public void sync(AllocOrder allocOrder){
LockInfo lock = lockTemplate.lock("payment:allocation:" + allocOrder.getOrderId(),10000,200);
if (Objects.isNull(lock)){
throw new RepetitiveOperationException("分账同步中,请勿重复操作");
}
try {
List<AllocationOrderDetail> detailList = allocationOrderDetailManager.findAllByOrderId(allocationOrder.getId());
List<AllocOrderDetail> detailList = allocOrderDetailManager.findAllByOrderId(allocOrder.getId());
// 获取分账策略
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(allocationOrder.getChannel(),AbsAllocationStrategy.class);
allocationStrategy.initParam(allocationOrder, detailList);
AbsAllocationStrategy allocationStrategy = PayStrategyFactory.create(allocOrder.getChannel(),AbsAllocationStrategy.class);
allocationStrategy.initParam(allocOrder, detailList);
// 分账完结预处理
allocationStrategy.doBeforeHandler();
// 执行同步操作, 分账明细的状态变更会在这个里面
AllocRemoteSyncResult allocRemoteSyncResult = allocationStrategy.doSync();
// 保存分账同步记录
this.saveRecord(allocationOrder, allocRemoteSyncResult,null,null);
this.saveRecord(allocOrder, allocRemoteSyncResult,null,null);
// 根据订单明细更新订单的状态和处理结果
this.updateOrderStatus(allocationOrder, detailList);
this.updateOrderStatus(allocOrder, detailList);
} finally {
lockTemplate.releaseLock(lock);
}
@@ -106,50 +106,50 @@ public class AllocationSyncService {
* 根据订单明细更新订单的状态和处理结果, 如果订单是分账结束或失败, 不更新状态
* TODO 是否多次同步会产生多次变动, 注意处理多次推送通知的问题, 目前是
*/
private void updateOrderStatus(AllocationOrder allocationOrder, List<AllocationOrderDetail> details){
private void updateOrderStatus(AllocOrder allocOrder, List<AllocOrderDetail> details){
// 如果是分账结束或失败, 不更新状态
String status = allocationOrder.getStatus();
String status = allocOrder.getStatus();
// 如果是分账结束或失败, 不进行对订单进行处理
List<String> list = Arrays.asList(AllocOrderStatusEnum.FINISH.getCode(), AllocOrderStatusEnum.FINISH_FAILED.getCode());
if (!list.contains(status)){
// 判断明细状态. 获取成功和失败的
long successCount = details.stream()
.map(AllocationOrderDetail::getResult)
.map(AllocOrderDetail::getResult)
.filter(AllocDetailResultEnum.SUCCESS.getCode()::equals)
.count();
long failCount = details.stream()
.map(AllocationOrderDetail::getResult)
.map(AllocOrderDetail::getResult)
.filter(AllocDetailResultEnum.FAIL.getCode()::equals)
.count();
// 成功和失败都为0 表示进行中
if (successCount == 0 && failCount == 0){
allocationOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())
allocOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())
.setResult(AllocOrderResultEnum.ALL_PENDING.getCode());
} else {
if (failCount == details.size()){
// 全部失败
allocationOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_END.getCode())
allocOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_END.getCode())
.setResult(AllocOrderResultEnum.ALL_FAILED.getCode());
} else if (successCount == details.size()){
// 全部成功
allocationOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_END.getCode())
allocOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_END.getCode())
.setResult(AllocOrderResultEnum.ALL_SUCCESS.getCode());
} else {
// 部分成功
allocationOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_END.getCode())
allocOrder.setStatus(AllocOrderStatusEnum.ALLOCATION_END.getCode())
.setResult(AllocOrderResultEnum.PART_SUCCESS.getCode());
}
}
}
allocationOrderDetailManager.updateAllById(details);
allocationOrderManager.updateById(allocationOrder);
allocOrderDetailManager.updateAllById(details);
allocationOrderManager.updateById(allocOrder);
// 如果状态为完成, 发送通知
if (Objects.equals(AllocOrderStatusEnum.ALLOCATION_END.getCode(), allocationOrder.getStatus())){
if (Objects.equals(AllocOrderStatusEnum.ALLOCATION_END.getCode(), allocOrder.getStatus())){
// 发送通知
clientNoticeService.registerAllocNotice(allocationOrder, details);
clientNoticeService.registerAllocNotice(allocOrder, details);
}
}
@@ -157,7 +157,7 @@ public class AllocationSyncService {
/**
* 保存同步记录
*/
private void saveRecord(AllocationOrder order, AllocRemoteSyncResult syncResult, String errorCode, String errorMsg){
private void saveRecord(AllocOrder order, AllocRemoteSyncResult syncResult, String errorCode, String errorMsg){
PaySyncRecord paySyncRecord = new PaySyncRecord()
.setBizTradeNo(order.getBizAllocNo())
.setTradeNo(order.getAllocNo())

View File

@@ -60,7 +60,7 @@ public class AliPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void allocation() {
aliPayAllocationService.allocation(this.getAllocationOrder(), this.getAllocationOrderDetails());
aliPayAllocationService.allocation(this.getAllocOrder(), this.getAllocOrderDetails());
}
/**
@@ -68,7 +68,7 @@ public class AliPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void finish() {
aliPayAllocationService.finish(this.getAllocationOrder(), this.getAllocationOrderDetails());
aliPayAllocationService.finish(this.getAllocOrder(), this.getAllocOrderDetails());
}
/**
@@ -76,7 +76,7 @@ public class AliPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public AllocRemoteSyncResult doSync() {
return aliPayAllocationService.sync(this.getAllocationOrder(), this.getAllocationOrderDetails());
return aliPayAllocationService.sync(this.getAllocOrder(), this.getAllocOrderDetails());
}
}

View File

@@ -52,7 +52,7 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
throw new PayFailureException("微信支付配置不支持分账");
}
// 如果分账金额为0, 不发起分账
if (getAllocationOrder().getAmount() == 0){
if (getAllocOrder().getAmount() == 0){
throw new PayFailureException("微信订单的分账比例不正确或订单金额太小, 无法进行分账");
}
}
@@ -62,7 +62,7 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void allocation() {
weChatPayAllocationService.allocation(getAllocationOrder(), this.getAllocationOrderDetails(), weChatPayConfig);
weChatPayAllocationService.allocation(getAllocOrder(), this.getAllocOrderDetails(), weChatPayConfig);
}
/**
@@ -70,7 +70,7 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public void finish() {
weChatPayAllocationService.finish(getAllocationOrder(), weChatPayConfig);
weChatPayAllocationService.finish(getAllocOrder(), weChatPayConfig);
}
/**
@@ -78,7 +78,7 @@ public class WeChatPayAllocationStrategy extends AbsAllocationStrategy {
*/
@Override
public AllocRemoteSyncResult doSync() {
return weChatPayAllocationService.sync(this.getAllocationOrder(),this.getAllocationOrderDetails(),weChatPayConfig);
return weChatPayAllocationService.sync(this.getAllocOrder(),this.getAllocOrderDetails(),weChatPayConfig);
}
}

View File

@@ -56,7 +56,7 @@ public class PayNoticeResult extends PaymentCommonResult {
* 支付通道
* @see PayChannelEnum
*/
@Schema(description = "异步支付通道")
@Schema(description = "支付通道")
private String channel;
/**

View File

@@ -3,9 +3,9 @@ package cn.daxpay.single.service.core.payment.notice.service;
import cn.bootx.platform.common.jackson.util.JacksonUtil;
import cn.daxpay.single.service.code.ClientNoticeTypeEnum;
import cn.daxpay.single.service.core.notice.entity.ClientNoticeTask;
import cn.daxpay.single.service.core.order.allocation.convert.AllocationConvert;
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.convert.AllocOrderConvert;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.order.pay.convert.PayOrderConvert;
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
import cn.daxpay.single.service.core.order.refund.convert.RefundOrderConvert;
@@ -75,12 +75,12 @@ public class ClientNoticeAssistService {
/**
* 构建分账通知
*/
public ClientNoticeTask buildAllocTask(AllocationOrder order, List<AllocationOrderDetail> list){
public ClientNoticeTask buildAllocTask(AllocOrder order, List<AllocOrderDetail> list){
// 分账
AllocNoticeResult allocOrderResult = AllocationConvert.CONVERT.toNotice(order);
AllocNoticeResult allocOrderResult = AllocOrderConvert.CONVERT.toNotice(order);
// 分账详情
List<AllocDetailNoticeResult> details = list.stream()
.map(AllocationConvert.CONVERT::toNotice)
.map(AllocOrderConvert.CONVERT::toNotice)
.collect(Collectors.toList());
// 分账扩展和明细
allocOrderResult.setAttach(order.getAttach())

View File

@@ -8,8 +8,8 @@ import cn.daxpay.single.service.core.notice.dao.ClientNoticeTaskManager;
import cn.daxpay.single.service.core.notice.entity.ClientNoticeRecord;
import cn.daxpay.single.service.core.notice.entity.ClientNoticeTask;
import cn.daxpay.single.service.core.notice.service.ClientNoticeRecordService;
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.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.order.pay.entity.PayOrder;
import cn.daxpay.single.service.core.order.refund.entity.RefundOrder;
import cn.hutool.core.util.StrUtil;
@@ -128,7 +128,7 @@ public class ClientNoticeService {
* 注册分账消息通知任务
*/
@Async("bigExecutor")
public void registerAllocNotice(AllocationOrder order, List<AllocationOrderDetail> list) {
public void registerAllocNotice(AllocOrder order, List<AllocOrderDetail> list) {
// 判断是否需要进行通知
if (StrUtil.isBlank(order.getNotifyUrl())){
log.info("分账订单无需通知订单ID{}",order.getId());

View File

@@ -53,8 +53,6 @@ public class PayService {
public PayResult pay(PayParam payParam){
// 创建返回类
PayResult payResult = new PayResult();
// 支付参数检查
PayUtil.validation(payParam);
// 校验支付限额
payAssistService.validationLimitAmount(payParam);
// 获取商户订单号

View File

@@ -1,7 +1,6 @@
package cn.daxpay.single.service.core.payment.refund.service;
import cn.bootx.platform.common.core.exception.DataNotExistException;
import cn.bootx.platform.common.core.util.CollUtil;
import cn.bootx.platform.common.core.util.ValidationUtil;
import cn.daxpay.single.code.PayOrderRefundStatusEnum;
import cn.daxpay.single.code.RefundStatusEnum;
@@ -20,7 +19,6 @@ import cn.daxpay.single.service.core.record.flow.service.TradeFlowRecordService;
import cn.daxpay.single.service.func.AbsRefundStrategy;
import cn.daxpay.single.service.util.PayStrategyFactory;
import cn.hutool.extra.spring.SpringUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.lock.LockInfo;
import com.baomidou.lock.LockTemplate;
import lombok.RequiredArgsConstructor;
@@ -182,10 +180,8 @@ public class RefundService {
order.setAttach(param.getAttach())
.setClientIp(param.getClientIp())
.setNotifyUrl(param.getNotifyUrl())
.setReqTime(param.getReqTime());
if (CollUtil.isNotEmpty(param.getExtraParam())){
order.setExtraParam(JSONUtil.toJsonStr(param.getExtraParam()));
}
.setReqTime(param.getReqTime())
.setExtraParam(param.getExtraParam());
refundOrderManager.updateById(order);
}

View File

@@ -19,7 +19,7 @@ import java.time.LocalDateTime;
@Data
@Accessors(chain = true)
@Schema(title = "分账订单")
public class AllocationOrderDto extends BaseDto {
public class AllocOrderDto extends BaseDto {
/**
* 分账订单号

View File

@@ -1,7 +1,7 @@
package cn.daxpay.single.service.func;
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.AllocOrder;
import cn.daxpay.single.service.core.order.allocation.entity.AllocOrderDetail;
import cn.daxpay.single.service.core.payment.sync.result.AllocRemoteSyncResult;
import lombok.Getter;
import lombok.Setter;
@@ -19,16 +19,16 @@ import java.util.List;
@Setter
public abstract class AbsAllocationStrategy implements PayStrategy{
private AllocationOrder allocationOrder;
private AllocOrder allocOrder;
private List<AllocationOrderDetail> allocationOrderDetails;
private List<AllocOrderDetail> allocOrderDetails;
/**
* 初始化参数
*/
public void initParam(AllocationOrder allocationOrder, List<AllocationOrderDetail> allocationOrderDetails) {
this.allocationOrder = allocationOrder;
this.allocationOrderDetails = allocationOrderDetails;
public void initParam(AllocOrder allocOrder, List<AllocOrderDetail> allocOrderDetails) {
this.allocOrder = allocOrder;
this.allocOrderDetails = allocOrderDetails;
}
/**

View File

@@ -12,7 +12,7 @@ import lombok.experimental.Accessors;
@Data
@Accessors(chain = true)
@Schema(title = "分账订单查询参数")
public class AllocationOrderQuery {
public class AllocOrderQuery {
@Schema(description = "分账订单号")
private String orderNo;

View File

@@ -2,7 +2,7 @@ package cn.daxpay.single.service.task;
import cn.daxpay.single.code.AllocOrderStatusEnum;
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.AllocOrder;
import cn.daxpay.single.service.core.payment.allocation.service.AllocationService;
import cn.daxpay.single.service.core.payment.allocation.service.AllocationSyncService;
import lombok.RequiredArgsConstructor;
@@ -32,18 +32,18 @@ public class AllocationSyncTask implements Job {
*/
@Override
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
for (AllocationOrder allocationOrder : allocationOrderManager.findSyncOrder()) {
for (AllocOrder allocOrder : allocationOrderManager.findSyncOrder()) {
try {
// 分账中走同步逻辑
if (allocationOrder.getStatus().equals(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())) {
allocationSyncService.sync(allocationOrder);
if (allocOrder.getStatus().equals(AllocOrderStatusEnum.ALLOCATION_PROCESSING.getCode())) {
allocationSyncService.sync(allocOrder);
}
// 如果分账结束, 调用自动完结逻辑
if (allocationOrder.getStatus().equals(AllocOrderStatusEnum.ALLOCATION_END.getCode())) {
allocationService.finish(allocationOrder);
if (allocOrder.getStatus().equals(AllocOrderStatusEnum.ALLOCATION_END.getCode())) {
allocationService.finish(allocOrder);
}
} catch (Exception e) {
log.warn("分账同步或完结失败, 分账号:{}", allocationOrder.getAllocNo());
log.warn("分账同步或完结失败, 分账号:{}", allocOrder.getAllocNo());
log.warn("分账同步或完结失败", e);
}
}