mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-09 13:59:05 +00:00
feat 对账差异单和定时任务开发
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
package cn.bootx.platform.daxpay.service.common.typehandler;
|
||||||
|
|
||||||
|
import cn.bootx.platform.common.mybatisplus.handler.JacksonTypeReferenceHandler;
|
||||||
|
import cn.bootx.platform.daxpay.service.core.payment.reconcile.domain.ReconcileDiff;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对账差异内容类型处理器
|
||||||
|
* @author xxm
|
||||||
|
* @since 2024/3/4
|
||||||
|
*/
|
||||||
|
public class ReconcileDiffTypeHandler extends JacksonTypeReferenceHandler<List<ReconcileDiff>> {
|
||||||
|
/**
|
||||||
|
* 返回要反序列化的类型对象
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public TypeReference<List<ReconcileDiff>> getTypeReference() {
|
||||||
|
return new TypeReference<List<ReconcileDiff>>() {};
|
||||||
|
}
|
||||||
|
}
|
@@ -1,23 +0,0 @@
|
|||||||
package cn.bootx.platform.daxpay.service.common.typehandler;
|
|
||||||
|
|
||||||
import cn.bootx.platform.common.mybatisplus.handler.JacksonTypeReferenceHandler;
|
|
||||||
import cn.bootx.platform.daxpay.entity.RefundableInfo;
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 支付订单可退款信息对应的MP字段处理器
|
|
||||||
* @author xxm
|
|
||||||
* @since 2024/1/3
|
|
||||||
*/
|
|
||||||
public class RefundableInfoTypeHandler extends JacksonTypeReferenceHandler<List<RefundableInfo>> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 返回要反序列化的类型对象
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public TypeReference<List<RefundableInfo>> getTypeReference() {
|
|
||||||
return new TypeReference<List<RefundableInfo>>() {};
|
|
||||||
}
|
|
||||||
}
|
|
@@ -49,14 +49,6 @@ public class ReconcileDetail extends MpCreateEntity implements EntityBaseFunctio
|
|||||||
@DbColumn(comment = "本地订单ID")
|
@DbColumn(comment = "本地订单ID")
|
||||||
private String orderId;
|
private String orderId;
|
||||||
|
|
||||||
/** 支付订单ID */
|
|
||||||
@DbColumn(comment = "支付订单ID")
|
|
||||||
private String paymentId;
|
|
||||||
|
|
||||||
/** 本地退款ID */
|
|
||||||
@DbColumn(comment = "本地退款ID")
|
|
||||||
private String refundId;
|
|
||||||
|
|
||||||
/** 网关订单号 - 支付宝/微信的订单号 */
|
/** 网关订单号 - 支付宝/微信的订单号 */
|
||||||
@DbColumn(comment = "网关订单号")
|
@DbColumn(comment = "网关订单号")
|
||||||
private String gatewayOrderNo;
|
private String gatewayOrderNo;
|
||||||
|
@@ -4,17 +4,22 @@ import cn.bootx.platform.common.core.function.EntityBaseFunction;
|
|||||||
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
|
import cn.bootx.platform.common.mybatisplus.base.MpBaseEntity;
|
||||||
import cn.bootx.platform.daxpay.code.ReconcileTradeEnum;
|
import cn.bootx.platform.daxpay.code.ReconcileTradeEnum;
|
||||||
import cn.bootx.platform.daxpay.service.code.ReconcileDiffTypeEnum;
|
import cn.bootx.platform.daxpay.service.code.ReconcileDiffTypeEnum;
|
||||||
|
import cn.bootx.platform.daxpay.service.common.typehandler.ReconcileDiffTypeHandler;
|
||||||
import cn.bootx.platform.daxpay.service.core.order.reconcile.conver.ReconcileConvert;
|
import cn.bootx.platform.daxpay.service.core.order.reconcile.conver.ReconcileConvert;
|
||||||
import cn.bootx.platform.daxpay.service.core.payment.reconcile.domain.ReconcileDiff;
|
import cn.bootx.platform.daxpay.service.core.payment.reconcile.domain.ReconcileDiff;
|
||||||
import cn.bootx.platform.daxpay.service.dto.order.reconcile.ReconcileDiffRecordDto;
|
import cn.bootx.platform.daxpay.service.dto.order.reconcile.ReconcileDiffRecordDto;
|
||||||
import cn.bootx.table.modify.annotation.DbColumn;
|
import cn.bootx.table.modify.annotation.DbColumn;
|
||||||
import cn.bootx.table.modify.annotation.DbTable;
|
import cn.bootx.table.modify.annotation.DbTable;
|
||||||
|
import cn.bootx.table.modify.mysql.annotation.DbMySqlFieldType;
|
||||||
|
import cn.bootx.table.modify.mysql.constants.MySqlFieldTypeEnum;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableField;
|
||||||
import com.baomidou.mybatisplus.annotation.TableName;
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对账差异单
|
* 对账差异单
|
||||||
@@ -25,7 +30,7 @@ import java.time.LocalDateTime;
|
|||||||
@Data
|
@Data
|
||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@DbTable(comment = "对账差异单")
|
@DbTable(comment = "对账差异单")
|
||||||
@TableName("pay_reconcile_diff_record")
|
@TableName(value = "pay_reconcile_diff_record",autoResultMap = true)
|
||||||
public class ReconcileDiffRecord extends MpBaseEntity implements EntityBaseFunction<ReconcileDiffRecordDto> {
|
public class ReconcileDiffRecord extends MpBaseEntity implements EntityBaseFunction<ReconcileDiffRecordDto> {
|
||||||
|
|
||||||
/** 对账单ID */
|
/** 对账单ID */
|
||||||
@@ -45,10 +50,10 @@ public class ReconcileDiffRecord extends MpBaseEntity implements EntityBaseFunct
|
|||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对账订单类型
|
* 订单类型
|
||||||
* @see ReconcileTradeEnum
|
* @see ReconcileTradeEnum
|
||||||
*/
|
*/
|
||||||
@DbColumn(comment = "对账订单类型")
|
@DbColumn(comment = "订单类型")
|
||||||
private String orderType;
|
private String orderType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +69,9 @@ public class ReconcileDiffRecord extends MpBaseEntity implements EntityBaseFunct
|
|||||||
* @see ReconcileDiff
|
* @see ReconcileDiff
|
||||||
*/
|
*/
|
||||||
@DbColumn(comment = "差异内容")
|
@DbColumn(comment = "差异内容")
|
||||||
private String diffContent;
|
@TableField(typeHandler = ReconcileDiffTypeHandler.class)
|
||||||
|
@DbMySqlFieldType(MySqlFieldTypeEnum.LONGTEXT)
|
||||||
|
private List<ReconcileDiff> diffs;
|
||||||
|
|
||||||
/** 网关订单号 */
|
/** 网关订单号 */
|
||||||
@DbColumn(comment = "网关订单号")
|
@DbColumn(comment = "网关订单号")
|
||||||
|
@@ -205,6 +205,7 @@ public class ReconcileService {
|
|||||||
.setOrderType(detail.getType())
|
.setOrderType(detail.getType())
|
||||||
.setGatewayOrderNo(detail.getGatewayOrderNo())
|
.setGatewayOrderNo(detail.getGatewayOrderNo())
|
||||||
.setAmount(detail.getAmount())
|
.setAmount(detail.getAmount())
|
||||||
|
.setDiffs(reconcileDiffs)
|
||||||
.setOrderTime(detail.getOrderTime());
|
.setOrderTime(detail.getOrderTime());
|
||||||
diffRecords.add(diffRecord);
|
diffRecords.add(diffRecord);
|
||||||
}
|
}
|
||||||
@@ -219,7 +220,6 @@ public class ReconcileService {
|
|||||||
.setRecordId(reconcileOrder.getId())
|
.setRecordId(reconcileOrder.getId())
|
||||||
.setDetailId(null)
|
.setDetailId(null)
|
||||||
.setTitle(gateway.getTitle())
|
.setTitle(gateway.getTitle())
|
||||||
.setDiffType(gateway.getType())
|
|
||||||
.setOrderType(gateway.getType())
|
.setOrderType(gateway.getType())
|
||||||
.setGatewayOrderNo(gateway.getGatewayOrderNo())
|
.setGatewayOrderNo(gateway.getGatewayOrderNo())
|
||||||
.setAmount(gateway.getAmount())
|
.setAmount(gateway.getAmount())
|
||||||
@@ -239,8 +239,13 @@ public class ReconcileService {
|
|||||||
List<ReconcileDiff> diffs = new ArrayList<>();
|
List<ReconcileDiff> diffs = new ArrayList<>();
|
||||||
|
|
||||||
// 判断类型是否相同
|
// 判断类型是否相同
|
||||||
if (!(Objects.equals(detail.getType(), ReconcileTradeEnum.PAY.getCode())
|
if (Objects.equals(detail.getType(), ReconcileTradeEnum.PAY.getCode())
|
||||||
&& Objects.equals(record.getType(), AliPayRecordTypeEnum.PAY.getCode()))){
|
&& !Objects.equals(record.getType(), AliPayRecordTypeEnum.PAY.getCode())){
|
||||||
|
log.warn("订单类型不一致: {},{}", detail.getType(), record.getType());
|
||||||
|
diffs.add(new ReconcileDiff().setFieldName("订单类型").setLocalValue(detail.getType()).setGatewayValue(record.getType()));
|
||||||
|
}
|
||||||
|
if (Objects.equals(detail.getType(), ReconcileTradeEnum.REFUND.getCode())
|
||||||
|
&& !Objects.equals(record.getType(), AliPayRecordTypeEnum.REFUND.getCode())){
|
||||||
log.warn("订单类型不一致: {},{}", detail.getType(), record.getType());
|
log.warn("订单类型不一致: {},{}", detail.getType(), record.getType());
|
||||||
diffs.add(new ReconcileDiff().setFieldName("订单类型").setLocalValue(detail.getType()).setGatewayValue(record.getType()));
|
diffs.add(new ReconcileDiff().setFieldName("订单类型").setLocalValue(detail.getType()).setGatewayValue(record.getType()));
|
||||||
}
|
}
|
||||||
|
@@ -35,11 +35,7 @@ public class ReconcileDetailDto extends BaseDto {
|
|||||||
|
|
||||||
/** 本地订单ID */
|
/** 本地订单ID */
|
||||||
@Schema(description = "本地订单ID")
|
@Schema(description = "本地订单ID")
|
||||||
private String paymentId;
|
private String orderId;
|
||||||
|
|
||||||
/** 本地退款ID */
|
|
||||||
@Schema(description = "本地退款ID")
|
|
||||||
private String refundId;
|
|
||||||
|
|
||||||
/** 网关订单号 - 支付宝/微信的订单号 */
|
/** 网关订单号 - 支付宝/微信的订单号 */
|
||||||
@Schema(description = "网关订单号")
|
@Schema(description = "网关订单号")
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
package cn.bootx.platform.daxpay.service.dto.order.reconcile;
|
package cn.bootx.platform.daxpay.service.dto.order.reconcile;
|
||||||
|
|
||||||
import cn.bootx.platform.common.core.rest.dto.BaseDto;
|
import cn.bootx.platform.common.core.rest.dto.BaseDto;
|
||||||
|
import cn.bootx.platform.daxpay.code.ReconcileTradeEnum;
|
||||||
|
import cn.bootx.platform.daxpay.service.code.ReconcileDiffTypeEnum;
|
||||||
|
import cn.bootx.platform.daxpay.service.core.payment.reconcile.domain.ReconcileDiff;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对账差异单
|
* 对账差异单
|
||||||
* @author xxm
|
* @author xxm
|
||||||
@@ -16,4 +22,55 @@ import lombok.experimental.Accessors;
|
|||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@Schema(title = "对账差异单")
|
@Schema(title = "对账差异单")
|
||||||
public class ReconcileDiffRecordDto extends BaseDto {
|
public class ReconcileDiffRecordDto extends BaseDto {
|
||||||
|
|
||||||
|
/** 对账单ID */
|
||||||
|
@Schema(description = "对账单ID")
|
||||||
|
private Long recordId;
|
||||||
|
|
||||||
|
/** 对账单明细ID */
|
||||||
|
@Schema(description = "对账单明细ID")
|
||||||
|
private Long detailId;
|
||||||
|
|
||||||
|
/** 本地订单id */
|
||||||
|
@Schema(description = "本地订单id")
|
||||||
|
private Long orderId;
|
||||||
|
|
||||||
|
/** 订单标题 */
|
||||||
|
@Schema(description = "订单标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对账订单类型
|
||||||
|
* @see ReconcileTradeEnum
|
||||||
|
*/
|
||||||
|
@Schema(description = "对账订单类型")
|
||||||
|
private String orderType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 差异类型
|
||||||
|
* @see ReconcileDiffTypeEnum
|
||||||
|
*/
|
||||||
|
@Schema(description = "差异类型")
|
||||||
|
private String diffType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 差异内容, 存储json字符串, 格式为
|
||||||
|
* {属性: '标题', 本地字段值:'标题1', 网关字段值: '标题2'}
|
||||||
|
* @see ReconcileDiff
|
||||||
|
*/
|
||||||
|
@Schema(description = "差异内容")
|
||||||
|
private List<ReconcileDiff> diffs;
|
||||||
|
|
||||||
|
|
||||||
|
/** 网关订单号 */
|
||||||
|
@Schema(description = "网关订单号")
|
||||||
|
private String gatewayOrderNo;
|
||||||
|
|
||||||
|
/** 交易金额 */
|
||||||
|
@Schema(description = "交易金额")
|
||||||
|
private Integer amount;
|
||||||
|
|
||||||
|
/** 订单时间 */
|
||||||
|
@Schema(description = "订单时间")
|
||||||
|
private LocalDateTime orderTime;
|
||||||
}
|
}
|
||||||
|
@@ -1,11 +1,17 @@
|
|||||||
package cn.bootx.platform.daxpay.service.param.reconcile;
|
package cn.bootx.platform.daxpay.service.param.reconcile;
|
||||||
|
|
||||||
import cn.bootx.platform.common.core.rest.param.QueryOrder;
|
import cn.bootx.platform.common.core.rest.param.QueryOrder;
|
||||||
|
import cn.bootx.platform.daxpay.code.ReconcileTradeEnum;
|
||||||
|
import cn.bootx.platform.daxpay.service.code.ReconcileDiffTypeEnum;
|
||||||
|
import cn.bootx.platform.daxpay.service.core.payment.reconcile.domain.ReconcileDiff;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.experimental.Accessors;
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 对账差异查询参数
|
* 对账差异查询参数
|
||||||
* @author xxm
|
* @author xxm
|
||||||
@@ -16,4 +22,46 @@ import lombok.experimental.Accessors;
|
|||||||
@Accessors(chain = true)
|
@Accessors(chain = true)
|
||||||
@Schema(title = "对账差异查询参数")
|
@Schema(title = "对账差异查询参数")
|
||||||
public class ReconcileDiffQuery extends QueryOrder {
|
public class ReconcileDiffQuery extends QueryOrder {
|
||||||
|
|
||||||
|
/** 对账单ID */
|
||||||
|
@Schema(description = "对账单ID")
|
||||||
|
private Long recordId;
|
||||||
|
|
||||||
|
/** 对账单明细ID */
|
||||||
|
@Schema(description = "对账单明细ID")
|
||||||
|
private Long detailId;
|
||||||
|
|
||||||
|
/** 本地订单id */
|
||||||
|
@Schema(description = "本地订单id")
|
||||||
|
private Long orderId;
|
||||||
|
|
||||||
|
/** 订单标题 */
|
||||||
|
@Schema(description = "订单标题")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对账订单类型
|
||||||
|
* @see ReconcileTradeEnum
|
||||||
|
*/
|
||||||
|
@Schema(description = "对账订单类型")
|
||||||
|
private String orderType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 差异类型
|
||||||
|
* @see ReconcileDiffTypeEnum
|
||||||
|
*/
|
||||||
|
@Schema(description = "差异类型")
|
||||||
|
private String diffType;
|
||||||
|
|
||||||
|
/** 差异内容 */
|
||||||
|
@Schema(description = "差异内容")
|
||||||
|
private List<ReconcileDiff> diffs;
|
||||||
|
|
||||||
|
/** 网关订单号 */
|
||||||
|
@Schema(description = "网关订单号")
|
||||||
|
private String gatewayOrderNo;
|
||||||
|
|
||||||
|
/** 订单时间 */
|
||||||
|
@Schema(description = "订单时间")
|
||||||
|
private LocalDateTime orderTime;
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,9 @@
|
|||||||
package cn.bootx.platform.daxpay.service.task;
|
package cn.bootx.platform.daxpay.service.task;
|
||||||
|
|
||||||
import cn.bootx.platform.daxpay.service.task.service.ReconcileTaskService;
|
import cn.bootx.platform.daxpay.service.task.service.ReconcileTaskService;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import cn.hutool.json.JSONUtil;
|
||||||
|
import lombok.Getter;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
@@ -24,29 +27,46 @@ public class ReconcileTask implements Job {
|
|||||||
private final ReconcileTaskService reconcileTaskService;
|
private final ReconcileTaskService reconcileTaskService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 要同步的通道
|
* 任务参数, 格式
|
||||||
|
* {"channel":"ali_pay","n":1}
|
||||||
*/
|
*/
|
||||||
@Setter
|
@Setter
|
||||||
private String channel;
|
private String parameter;
|
||||||
|
|
||||||
/**
|
|
||||||
* 同步账单规则是 T+N 天, 例如T+1就是同步昨天的账单, T+2就是同步前天的账单
|
|
||||||
*/
|
|
||||||
@Setter
|
|
||||||
private Integer n;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 任务实现
|
* 任务实现
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||||
|
if (StrUtil.isBlank(parameter)){
|
||||||
|
log.warn("传输参数为空");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Parameter bean = JSONUtil.toBean(parameter, Parameter.class);
|
||||||
// 日期, 如果未配置T+N规则, 默认为T+1
|
// 日期, 如果未配置T+N规则, 默认为T+1
|
||||||
LocalDate date = LocalDate.now();
|
LocalDate date = LocalDate.now();
|
||||||
if (Objects.nonNull(n)){
|
if (Objects.nonNull(bean.n)){
|
||||||
date = date.minusDays(n);
|
date = date.minusDays(bean.n);
|
||||||
} else {
|
} else {
|
||||||
date = date.minusDays(1);
|
date = date.minusDays(1);
|
||||||
}
|
}
|
||||||
reconcileTaskService.reconcileTask(date,channel);
|
reconcileTaskService.reconcileTask(date,bean.channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 接收参数
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public static class Parameter {
|
||||||
|
/**
|
||||||
|
* 要同步的通道
|
||||||
|
*/
|
||||||
|
private String channel;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 同步账单规则是 T+N 天, 例如T+1就是同步昨天的账单, T+2就是同步前天的账单
|
||||||
|
*/
|
||||||
|
private Integer n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user