去除 common_pay_order
This commit is contained in:
@@ -8,11 +8,11 @@ import lombok.extern.slf4j.Slf4j;
|
||||
import org.springblade.common.utils.date.DateUtil;
|
||||
import org.springblade.modules.api.constant.AppAliPayConstant;
|
||||
import org.springblade.modules.api.service.PaymentFacade;
|
||||
import org.springblade.modules.common.eums.BusinessModule;
|
||||
import org.springblade.modules.common.eums.OrderStatus;
|
||||
import org.springblade.modules.common.eums.PaymentStatus;
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.eums.PaymentType;
|
||||
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
|
||||
import org.springblade.modules.common.service.ICommonPayOrderService;
|
||||
import org.springblade.modules.common.service.ICommonUserOrderService;
|
||||
import org.springblade.plugin.pay.service.IOrderService;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -35,7 +35,6 @@ public class AliUserOrderCloseProcessor implements BasicProcessor {
|
||||
|
||||
|
||||
|
||||
private final ICommonPayOrderService commonPayOrderService;
|
||||
private final ICommonUserOrderService commonUserOrderService;
|
||||
private final PaymentFacade paymentFacade;
|
||||
private final IOrderService orderService;
|
||||
@@ -54,12 +53,12 @@ public class AliUserOrderCloseProcessor implements BasicProcessor {
|
||||
while (true) {
|
||||
// 2. 分批查询数据库
|
||||
// 【优化点1】增加 orderByAsc 保证按时间顺序处理,增加 last("LIMIT") 限制数量
|
||||
List<CommonPayOrderEntity> payOrderList = commonPayOrderService.list(
|
||||
Wrappers.lambdaQuery(CommonPayOrderEntity.class)
|
||||
.eq(CommonPayOrderEntity::getPaymentStatus, PaymentStatus.UNPAID.getCode()) // 确保传的是 code 值,如果是枚举对象需调整
|
||||
.eq(CommonPayOrderEntity::getOrderStatus, OrderStatus.PENDING_PAYMENT.getCode())
|
||||
.le(CommonPayOrderEntity::getCreateTime, expireTime)
|
||||
.orderByAsc(CommonPayOrderEntity::getCreateTime)
|
||||
List<CommonUserOrderEntity> payOrderList = commonUserOrderService.list(
|
||||
Wrappers.lambdaQuery(CommonUserOrderEntity.class)
|
||||
.eq(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.UNPAID.getCode()) // 确保传的是 code 值,如果是枚举对象需调整
|
||||
.eq(CommonUserOrderEntity::getOrderStatus, OrderStatus.PENDING_PAYMENT.getCode())
|
||||
.le(CommonUserOrderEntity::getCreateTime, expireTime)
|
||||
.orderByAsc(CommonUserOrderEntity::getCreateTime)
|
||||
.last("LIMIT " + batchSize)
|
||||
);
|
||||
|
||||
@@ -67,11 +66,11 @@ public class AliUserOrderCloseProcessor implements BasicProcessor {
|
||||
break; // 没有数据了,退出循环
|
||||
}
|
||||
|
||||
for (CommonPayOrderEntity payOrder : payOrderList) {
|
||||
for (CommonUserOrderEntity payOrder : payOrderList) {
|
||||
try {
|
||||
processSingleOrder(payOrder);
|
||||
} catch (Exception e) {
|
||||
log.error("处理超时订单异常,订单号: {}", payOrder.getOrderNo(), e);
|
||||
log.error("处理超时订单异常,订单号: {}", payOrder.getId(), e);
|
||||
// 单个失败不影响整体流程
|
||||
}
|
||||
}
|
||||
@@ -90,29 +89,22 @@ public class AliUserOrderCloseProcessor implements BasicProcessor {
|
||||
* 处理单个订单逻辑
|
||||
* 核心原则:先远程交互,成功后再开短事务更新本地
|
||||
*/
|
||||
private void processSingleOrder(CommonPayOrderEntity payOrder) {
|
||||
String orderNo = payOrder.getOrderNo();
|
||||
Long orderId = payOrder.getOrderId();
|
||||
|
||||
CommonPayOrderEntity currentPayOrder = commonPayOrderService.getById(payOrder.getId());
|
||||
if (currentPayOrder == null ||
|
||||
currentPayOrder.getPaymentStatus() != PaymentStatus.UNPAID.getCode()) {
|
||||
log.debug("订单 {} 状态已变更,跳过", orderNo);
|
||||
return;
|
||||
}
|
||||
|
||||
CommonUserOrderEntity userOrder = commonUserOrderService.getById(orderId);
|
||||
if (userOrder == null) {
|
||||
private void processSingleOrder(CommonUserOrderEntity payOrder) {
|
||||
Long orderId = payOrder.getId();
|
||||
String orderNo = PaymentType.fromCodeOrNull(payOrder.getPaymentType()).getAbbr() + BusinessModule.fromCodeIgnoreCaseOrNull(payOrder.getOrderType()).getAbbr() + payOrder.getId();
|
||||
log.info("处理超时订单,订单号: {}", orderNo);
|
||||
if (payOrder == null) {
|
||||
log.error("关联用户订单不存在,orderId: {}", orderId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
AlipayTradeQueryResponse response = paymentFacade.aliQuery(orderNo);
|
||||
log.info("查询结果: {}", response);
|
||||
|
||||
|
||||
if (response == null) {
|
||||
updateOrderToClosed(payOrder, userOrder);
|
||||
updateOrderToClosed(payOrder);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,7 +119,7 @@ public class AliUserOrderCloseProcessor implements BasicProcessor {
|
||||
}
|
||||
|
||||
|
||||
updateOrderToClosed(payOrder, userOrder);
|
||||
updateOrderToClosed(payOrder);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -139,35 +131,13 @@ public class AliUserOrderCloseProcessor implements BasicProcessor {
|
||||
* 使用 update(entity, wrapper) 方式实现乐观锁检查
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateOrderToClosed(CommonPayOrderEntity payOrder, CommonUserOrderEntity userOrder) {
|
||||
// 构造更新条件:必须当前还是未支付状态才能更新,否则说明被并发修改了
|
||||
LambdaQueryWrapper<CommonPayOrderEntity> updateWrapper = Wrappers.lambdaQuery(CommonPayOrderEntity.class)
|
||||
.eq(CommonPayOrderEntity::getId, payOrder.getId())
|
||||
.eq(CommonPayOrderEntity::getPaymentStatus, PaymentStatus.UNPAID.getCode());
|
||||
public void updateOrderToClosed( CommonUserOrderEntity userOrder) {
|
||||
// 支付单更新成功,再更新用户订单
|
||||
userOrder.setOrderStatus(OrderStatus.CLOSED_TIMEOUT.getCode());
|
||||
userOrder.setPaymentStatus(PaymentStatus.FAILED.getCode());
|
||||
// userOrder.setUpdateTime(new Date());
|
||||
commonUserOrderService.updateById(userOrder);
|
||||
|
||||
// 准备更新的数据
|
||||
CommonPayOrderEntity updatePayOrder = new CommonPayOrderEntity();
|
||||
updatePayOrder.setOrderStatus(OrderStatus.CLOSED_TIMEOUT.getCode());
|
||||
updatePayOrder.setPaymentStatus(PaymentStatus.FAILED.getCode());
|
||||
// updatePayOrder.setUpdateTime(new Date());
|
||||
|
||||
boolean updated = commonPayOrderService.update(updatePayOrder, updateWrapper);
|
||||
|
||||
if (updated) {
|
||||
// 支付单更新成功,再更新用户订单
|
||||
userOrder.setOrderStatus(OrderStatus.CLOSED_TIMEOUT.getCode());
|
||||
userOrder.setPaymentStatus(PaymentStatus.FAILED.getCode());
|
||||
// userOrder.setUpdateTime(new Date());
|
||||
commonUserOrderService.updateById(userOrder);
|
||||
|
||||
log.info("订单 {} 已成功关闭", payOrder.getOrderNo());
|
||||
} else {
|
||||
// 更新失败,说明在此期间状态变了(比如用户刚支付成功回调到了)
|
||||
log.warn("订单 {} 关闭更新失败,状态可能已变更,放弃本次关闭本地状态", payOrder.getOrderNo());
|
||||
// 这里可以选择抛出异常回滚,或者仅仅记录日志。
|
||||
// 既然支付宝侧已经 close 成功了,本地不一致可以通过后续的“对账任务”来修复,或者抛异常让事务回滚(但支付宝侧已关无法回滚,所以最好记录日志告警)
|
||||
throw new RuntimeException("并发冲突:订单状态已变更,关闭失败");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package org.springblade.modules.api.constant;
|
||||
|
||||
public interface AppAliPayConstant {
|
||||
|
||||
Long ALI_APP_ID = 2088380917299813L;
|
||||
Long ALI_MACH_ID = 2021006137661681L;
|
||||
Long ALI_APP_ID = 2021006137661681L;
|
||||
Long ALI_MACH_ID = 2088380917299813L;
|
||||
String APP_ALI_AES_KEY = "yichuyilu.app.ali.aes.key";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
package org.springblade.modules.common.controller;
|
||||
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
|
||||
import lombok.AllArgsConstructor;
|
||||
import jakarta.validation.Valid;
|
||||
|
||||
|
||||
import org.springblade.core.mp.support.Condition;
|
||||
import org.springblade.core.mp.support.Query;
|
||||
import org.springblade.core.tool.api.R;
|
||||
import org.springblade.core.tool.utils.Func;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.pojo.vo.CommonPayOrderVO;
|
||||
import org.springblade.modules.common.wrapper.CommonPayOrderWrapper;
|
||||
import org.springblade.modules.common.service.ICommonPayOrderService;
|
||||
import org.springblade.core.boot.ctrl.BladeController;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 控制器
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
@RestController
|
||||
@AllArgsConstructor
|
||||
@RequestMapping("common/pay-order")
|
||||
@Tag(name = "系统内部订单关联支付记录", description = "系统内部订单关联支付记录接口")
|
||||
public class CommonPayOrderController extends BladeController {
|
||||
|
||||
private final ICommonPayOrderService commonPayOrderService;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 详情
|
||||
*/
|
||||
@GetMapping("/detail")
|
||||
@ApiOperationSupport(order = 1)
|
||||
@Operation(summary = "详情", description = "传入commonPayOrder")
|
||||
public R<CommonPayOrderVO> detail(CommonPayOrderEntity commonPayOrder) {
|
||||
CommonPayOrderEntity detail = commonPayOrderService.getOne(Condition.getQueryWrapper(commonPayOrder));
|
||||
return R.data(CommonPayOrderWrapper.build().entityVO(detail));
|
||||
}
|
||||
/**
|
||||
* 系统内部订单关联支付记录 分页
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
@ApiOperationSupport(order = 2)
|
||||
@Operation(summary = "分页", description = "传入commonPayOrder")
|
||||
public R<IPage<CommonPayOrderVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> commonPayOrder, Query query) {
|
||||
IPage<CommonPayOrderEntity> pages = commonPayOrderService.page(Condition.getPage(query), Condition.getQueryWrapper(commonPayOrder, CommonPayOrderEntity.class));
|
||||
return R.data(CommonPayOrderWrapper.build().pageVO(pages));
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 自定义分页
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@ApiOperationSupport(order = 3)
|
||||
@Operation(summary = "分页", description = "传入commonPayOrder")
|
||||
public R<IPage<CommonPayOrderVO>> page(CommonPayOrderVO commonPayOrder, Query query) {
|
||||
IPage<CommonPayOrderVO> pages = commonPayOrderService.selectCommonPayOrderPage(Condition.getPage(query), commonPayOrder);
|
||||
return R.data(pages);
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 新增
|
||||
*/
|
||||
@PostMapping("/save")
|
||||
@ApiOperationSupport(order = 4)
|
||||
@Operation(summary = "新增", description = "传入commonPayOrder")
|
||||
public R save(@Valid @RequestBody CommonPayOrderEntity commonPayOrder) {
|
||||
return R.status(commonPayOrderService.save(commonPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 修改
|
||||
*/
|
||||
@PostMapping("/update")
|
||||
@ApiOperationSupport(order = 5)
|
||||
@Operation(summary = "修改", description = "传入commonPayOrder")
|
||||
public R update(@Valid @RequestBody CommonPayOrderEntity commonPayOrder) {
|
||||
return R.status(commonPayOrderService.updateById(commonPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 新增或修改
|
||||
*/
|
||||
@PostMapping("/submit")
|
||||
@ApiOperationSupport(order = 6)
|
||||
@Operation(summary = "新增或修改", description = "传入commonPayOrder")
|
||||
public R submit(@Valid @RequestBody CommonPayOrderEntity commonPayOrder) {
|
||||
return R.status(commonPayOrderService.saveOrUpdate(commonPayOrder));
|
||||
}
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 删除
|
||||
*/
|
||||
@PostMapping("/remove")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@Operation(summary = "逻辑删除", description = "传入ids")
|
||||
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
|
||||
return R.status(commonPayOrderService.deleteLogic(Func.toLongList(ids)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package org.springblade.modules.common.event;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springblade.modules.common.eums.PaymentType;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
@@ -12,6 +13,7 @@ public class PaymentCallbackEvent implements Serializable {
|
||||
|
||||
private Long id;
|
||||
private Date payTime;
|
||||
private PaymentType paymentType;
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -8,9 +8,7 @@ import org.springblade.modules.common.eums.PaymentStatus;
|
||||
import org.springblade.modules.common.event.PaymentCallbackEvent;
|
||||
import org.springblade.modules.common.event.PaymentSuccessEvent;
|
||||
import org.springblade.modules.common.event.StatsCommissionAccountEvent;
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
|
||||
import org.springblade.modules.common.service.ICommonPayOrderService;
|
||||
import org.springblade.modules.common.service.ICommonUserOrderService;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.event.EventListener;
|
||||
@@ -23,7 +21,6 @@ import org.springframework.stereotype.Component;
|
||||
@AllArgsConstructor
|
||||
public class PaymentListener {
|
||||
|
||||
private final ICommonPayOrderService commonPayOrderService;
|
||||
private final ICommonUserOrderService commonUserOrderService;
|
||||
private final ApplicationEventPublisher publisher;
|
||||
|
||||
@@ -32,43 +29,27 @@ public class PaymentListener {
|
||||
public void callbackSuccessPayment(PaymentCallbackEvent event) {
|
||||
log.info("支付回调监听 : {}" , event);
|
||||
|
||||
CommonPayOrderEntity payOrder = commonPayOrderService.getById(event.getId());
|
||||
if (payOrder == null){
|
||||
log.error("支付回调监听 : 订单不存在 , 订单id : {}" , event.getId());
|
||||
return;
|
||||
}
|
||||
if (payOrder.getOrderStatus() == 1){
|
||||
log.error("支付回调监听 : 订单已支付 , 订单id : {}" , event.getId());
|
||||
return;
|
||||
}
|
||||
if (payOrder.getPaymentStatus() == 1){
|
||||
log.error("支付回调监听 : 订单已支付 , 订单id : {}" , event.getId());
|
||||
return;
|
||||
}
|
||||
CommonUserOrderEntity userOrder = commonUserOrderService.getById(payOrder.getOrderId());
|
||||
|
||||
CommonUserOrderEntity userOrder = commonUserOrderService.getById(event.getId());
|
||||
if (userOrder == null){
|
||||
log.error("支付回调监听 : 订单不存在 , 订单id : {}" , payOrder.getOrderId());
|
||||
log.error("支付回调监听 : 订单不存在 , 订单id : {}" , userOrder.getId());
|
||||
return;
|
||||
}
|
||||
if (userOrder.getOrderStatus() == 1){
|
||||
log.error("支付回调监听 : 订单已支付 , 订单id : {}" , payOrder.getOrderId());
|
||||
log.error("支付回调监听 : 订单已支付 , 订单id : {}" , userOrder.getId());
|
||||
return;
|
||||
}
|
||||
|
||||
payOrder.setOrderStatus(OrderStatus.PAID.getCode());
|
||||
payOrder.setPaymentStatus(PaymentStatus.PAID.getCode());
|
||||
|
||||
userOrder.setOrderStatus(OrderStatus.PAID.getCode());
|
||||
userOrder.setPaymentStatus(PaymentStatus.PAID.getCode());
|
||||
userOrder.setPaymentType(payOrder.getPaymentType());
|
||||
userOrder.setPaymentTime(event.getPayTime());
|
||||
if (!commonPayOrderService.updateById(payOrder) || !commonUserOrderService.updateById(userOrder)){
|
||||
log.error("支付回调监听 : 订单支付失败 , 订单id : {}" , payOrder.getOrderId());
|
||||
if ( !commonUserOrderService.updateById(userOrder)){
|
||||
log.error("支付回调监听 : 订单支付失败 , 订单id : {}" , userOrder.getId());
|
||||
return;
|
||||
}
|
||||
log.info("支付回调监听 : 订单支付成功 , 订单id : {}" , payOrder.getOrderId());
|
||||
log.info("支付回调监听 : 订单支付成功 , 订单id : {}" , userOrder.getId());
|
||||
publisher.publishEvent(new StatsCommissionAccountEvent().setId(userOrder.getId()));
|
||||
publisher.publishEvent(new PaymentSuccessEvent(payOrder.getOrderId(), userOrder.getUserId(), BusinessModule.fromCodeIgnoreCase(userOrder.getOrderType())));
|
||||
publisher.publishEvent(new PaymentSuccessEvent(userOrder.getId(), userOrder.getUserId(), BusinessModule.fromCodeIgnoreCase(userOrder.getOrderType())));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
package org.springblade.modules.common.mapper;
|
||||
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.pojo.vo.CommonPayOrderVO;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 Mapper 接口
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
public interface CommonPayOrderMapper extends BaseMapper<CommonPayOrderEntity> {
|
||||
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param commonPayOrder 查询参数
|
||||
* @return List<CommonPayOrderVO>
|
||||
*/
|
||||
List<CommonPayOrderVO> selectCommonPayOrderPage(IPage page, CommonPayOrderVO commonPayOrder);
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="org.springblade.modules.common.mapper.CommonPayOrderMapper">
|
||||
|
||||
<!-- 通用查询映射结果 -->
|
||||
<resultMap id="commonPayOrderResultMap" type="org.springblade.modules.common.pojo.entity.CommonPayOrderEntity">
|
||||
<result column="id" property="id"/>
|
||||
<result column="order_id" property="orderId"/>
|
||||
<result column="order_status" property="orderStatus"/>
|
||||
<result column="payment_status" property="paymentStatus"/>
|
||||
<result column="create_user" property="createUser"/>
|
||||
<result column="create_dept" property="createDept"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_user" property="updateUser"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
<result column="is_deleted" property="isDeleted"/>
|
||||
<result column="remark" property="remark"/>
|
||||
</resultMap>
|
||||
|
||||
|
||||
<select id="selectCommonPayOrderPage" resultMap="commonPayOrderResultMap">
|
||||
select * from common_pay_order where is_deleted = 0
|
||||
</select>
|
||||
|
||||
|
||||
|
||||
</mapper>
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.modules.common.pojo.dto;
|
||||
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 数据传输对象实体类
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommonPayOrderDTO extends CommonPayOrderEntity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.modules.common.pojo.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import java.util.Date;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.springblade.core.mp.base.BaseEntity;
|
||||
import org.springblade.core.tenant.mp.TenantEntity;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 实体类
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
@Data
|
||||
@TableName("common_pay_order")
|
||||
@Schema(description = "CommonPayOrder对象")
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Accessors(chain = true)
|
||||
public class CommonPayOrderEntity extends BaseEntity {
|
||||
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 系统内部订单id
|
||||
*/
|
||||
@Schema(description = "系统内部订单id")
|
||||
private Long orderId;
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
@Schema(description = "订单状态")
|
||||
private Integer orderStatus;
|
||||
/**
|
||||
* 支付状态
|
||||
*/
|
||||
@Schema(description = "支付状态")
|
||||
private Integer paymentStatus;
|
||||
|
||||
/**
|
||||
* 支付类型
|
||||
*/
|
||||
@Schema(description = "支付类型")
|
||||
private Integer paymentType;
|
||||
|
||||
/**
|
||||
* 支付插件orderNo
|
||||
*/
|
||||
@Schema(description = "支付插件orderNo")
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Schema(description = "备注")
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.modules.common.pojo.vo;
|
||||
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import java.io.Serial;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 视图实体类
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class CommonPayOrderVO extends CommonPayOrderEntity {
|
||||
@Serial
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
package org.springblade.modules.common.service;
|
||||
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.pojo.vo.CommonPayOrderVO;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseService;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 服务类
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
public interface ICommonPayOrderService extends BaseService<CommonPayOrderEntity> {
|
||||
/**
|
||||
* 自定义分页
|
||||
*
|
||||
* @param page 分页参数
|
||||
* @param commonPayOrder 查询参数
|
||||
* @return IPage<CommonPayOrderVO>
|
||||
*/
|
||||
IPage<CommonPayOrderVO> selectCommonPayOrderPage(IPage<CommonPayOrderVO> page, CommonPayOrderVO commonPayOrder);
|
||||
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package org.springblade.modules.common.service.impl;
|
||||
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.pojo.vo.CommonPayOrderVO;
|
||||
import org.springblade.modules.common.mapper.CommonPayOrderMapper;
|
||||
import org.springblade.modules.common.service.ICommonPayOrderService;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springblade.core.mp.base.BaseServiceImpl;
|
||||
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 服务实现类
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
@Service
|
||||
public class CommonPayOrderServiceImpl extends BaseServiceImpl<CommonPayOrderMapper, CommonPayOrderEntity> implements ICommonPayOrderService {
|
||||
|
||||
@Override
|
||||
public IPage<CommonPayOrderVO> selectCommonPayOrderPage(IPage<CommonPayOrderVO> page, CommonPayOrderVO commonPayOrder) {
|
||||
return page.setRecords(baseMapper.selectCommonPayOrderPage(page, commonPayOrder));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
/**
|
||||
* BladeX Commercial License Agreement
|
||||
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
|
||||
* <p>
|
||||
* Use of this software is governed by the Commercial License Agreement
|
||||
* obtained after purchasing a license from BladeX.
|
||||
* <p>
|
||||
* 1. This software is for development use only under a valid license
|
||||
* from BladeX.
|
||||
* <p>
|
||||
* 2. Redistribution of this software's source code to any third party
|
||||
* without a commercial license is strictly prohibited.
|
||||
* <p>
|
||||
* 3. Licensees may copyright their own code but cannot use segments
|
||||
* from this software for such purposes. Copyright of this software
|
||||
* remains with BladeX.
|
||||
* <p>
|
||||
* Using this software signifies agreement to this License, and the software
|
||||
* must not be used for illegal purposes.
|
||||
* <p>
|
||||
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
|
||||
* not liable for any claims arising from secondary or illegal development.
|
||||
* <p>
|
||||
* Author: Chill Zhuang (bladejava@qq.com)
|
||||
*/
|
||||
package org.springblade.modules.common.wrapper;
|
||||
|
||||
import org.springblade.core.mp.support.BaseEntityWrapper;
|
||||
import org.springblade.core.tool.utils.BeanUtil;
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.pojo.vo.CommonPayOrderVO;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 系统内部订单关联支付记录 包装类,返回视图层所需的字段
|
||||
*
|
||||
* @author BladeX
|
||||
* @since 2026-03-24
|
||||
*/
|
||||
public class CommonPayOrderWrapper extends BaseEntityWrapper<CommonPayOrderEntity, CommonPayOrderVO> {
|
||||
|
||||
public static CommonPayOrderWrapper build() {
|
||||
return new CommonPayOrderWrapper();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonPayOrderVO entityVO(CommonPayOrderEntity commonPayOrder) {
|
||||
CommonPayOrderVO commonPayOrderVO = Objects.requireNonNull(BeanUtil.copyProperties(commonPayOrder, CommonPayOrderVO.class));
|
||||
|
||||
//User createUser = UserCache.getUser(commonPayOrder.getCreateUser());
|
||||
//User updateUser = UserCache.getUser(commonPayOrder.getUpdateUser());
|
||||
//commonPayOrderVO.setCreateUserName(createUser.getName());
|
||||
//commonPayOrderVO.setUpdateUserName(updateUser.getName());
|
||||
|
||||
return commonPayOrderVO;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public interface IOrderService extends BaseService<Order> {
|
||||
* @param notifyUrl
|
||||
* @return
|
||||
*/
|
||||
public Order save(String appId, String mchId, String payName, String body, String money, String chanel, String payType, String notifyUrl , String orderPrefix);
|
||||
public Order save(String appId, String mchId, String payName, String body, String money, String chanel, String payType, String notifyUrl , String orderNo);
|
||||
|
||||
/**
|
||||
* 根据订单号、商户号查询支付订单
|
||||
|
||||
@@ -17,11 +17,6 @@ import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.oss.model.BladeFile;
|
||||
import org.springblade.core.tool.utils.PathUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.modules.common.eums.OrderStatus;
|
||||
import org.springblade.modules.common.eums.PaymentStatus;
|
||||
import org.springblade.modules.common.eums.PaymentType;
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.service.ICommonPayOrderService;
|
||||
import org.springblade.modules.resource.builder.OssBuilder;
|
||||
import org.springblade.plugin.pay.api.alipay.IAliPayApiService;
|
||||
import org.springblade.plugin.pay.common.AliPayException;
|
||||
@@ -64,14 +59,13 @@ public class AliPayServiceImpl implements IAliPayService {
|
||||
private final IAliPayAccountConfigService aliPayAccountConfigService;
|
||||
private final OssBuilder ossBuilder;
|
||||
private final IRefundService refundService;
|
||||
private final ICommonPayOrderService commonPayOrderService;
|
||||
|
||||
/**
|
||||
* 订单前置验证
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private AliPayCheckBiz beforeCheck(String appId, String mchId, String body, String money, String notifyUrl, String payType , String orderPrefix) {
|
||||
private AliPayCheckBiz beforeCheck(String appId, String mchId, String body, String money, String notifyUrl, String payType , String orderNo) {
|
||||
AliPayAccountConfig aliPayAccountConfig = aliPayAccountConfigService.getInfoByMchIdAndAppId(mchId, appId);
|
||||
if (aliPayAccountConfig == null) {
|
||||
throw new ServiceException("该商户号尚未接入");
|
||||
@@ -82,7 +76,7 @@ public class AliPayServiceImpl implements IAliPayService {
|
||||
if (StringUtil.isBlank(notifyUrl)) {
|
||||
notifyUrl = aliPayAccountConfig.getNotifyUrl();
|
||||
}
|
||||
Order order = orderService.save(appId, mchId, aliPayAccountConfig.getPayName(), body, money, PayConstant.ALIPAY, payType, notifyUrl , orderPrefix);
|
||||
Order order = orderService.save(appId, mchId, aliPayAccountConfig.getPayName(), body, money, PayConstant.ALIPAY, payType, notifyUrl , orderNo);
|
||||
if (order == null) {
|
||||
throw new ServiceException("下单失败,请稍候再试");
|
||||
}
|
||||
@@ -326,17 +320,9 @@ public class AliPayServiceImpl implements IAliPayService {
|
||||
public String appPay(String appId, String mchId, String body, String money, String notifyUrl, String attach ,String orderPrefix , Long orderId) {
|
||||
String appPayStr = null;
|
||||
try {
|
||||
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.APPPAY , orderPrefix);
|
||||
AliPayCheckBiz aliPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.APPPAY , orderPrefix + orderId);
|
||||
Order order = aliPayCheckBiz.getOrder();
|
||||
CommonPayOrderEntity commonPayOrderEntity = new CommonPayOrderEntity();
|
||||
commonPayOrderEntity.setId(order.getId());
|
||||
commonPayOrderEntity.setOrderId(orderId);
|
||||
commonPayOrderEntity.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
|
||||
commonPayOrderEntity.setPaymentStatus(PaymentStatus.UNPAID.getCode());
|
||||
commonPayOrderEntity.setOrderNo(order.getOrderNo());
|
||||
commonPayOrderEntity.setPaymentType(PaymentType.ALI.getCode());
|
||||
commonPayOrderEntity.setCreateTime(new Date());
|
||||
commonPayOrderService.save(commonPayOrderEntity);
|
||||
|
||||
AliPayAccountConfig aliPayAccountConfig = aliPayCheckBiz.getAliPayAccountConfig();
|
||||
Integer apiType = aliPayAccountConfig.getApiType();
|
||||
switch (apiType) {
|
||||
|
||||
@@ -53,11 +53,11 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order save(String appId, String mchId, String payName, String body, String money, String chanel, String payType, String notifyUrl ,String orderPrefix) {
|
||||
public Order save(String appId, String mchId, String payName, String body, String money, String chanel, String payType, String notifyUrl ,String orderNo) {
|
||||
Order order = null;
|
||||
try {
|
||||
order = new Order();
|
||||
order.setOrderNo(OrderUtil.createOrderNo(orderPrefix));
|
||||
order.setOrderNo(orderNo);
|
||||
order.setBody(body);
|
||||
order.setMoney(money);
|
||||
order.setMchId(mchId);
|
||||
@@ -131,7 +131,7 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
|
||||
.eq(Order::getMchId, mchId));
|
||||
|
||||
if (update){
|
||||
publisher.publishEvent(new PaymentCallbackEvent().setId(order.getId()).setPayTime(DateUtil.convertFromString(payTime , "yyyy-MM-dd hh:mm:ss")));
|
||||
publisher.publishEvent(new PaymentCallbackEvent().setId(parsePrefixString(orderNo)).setPayTime(DateUtil.convertFromString(payTime , "yyyy-MM-dd hh:mm:ss")));
|
||||
}
|
||||
return update;
|
||||
}
|
||||
@@ -172,4 +172,22 @@ public class OrderServiceImpl extends BaseServiceImpl<OrderMapper, Order> implem
|
||||
return update;
|
||||
}
|
||||
|
||||
private long parsePrefixString(String input) {
|
||||
if (input == null || input.isEmpty()) {
|
||||
throw new IllegalArgumentException("订单号为空");
|
||||
}
|
||||
|
||||
String numberPart = input.replaceAll("^[A-Za-z]+", "");
|
||||
|
||||
if (numberPart.isEmpty()) {
|
||||
throw new IllegalArgumentException("去除前缀后未找到数字部分");
|
||||
}
|
||||
|
||||
try {
|
||||
return Long.parseLong(numberPart);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new IllegalArgumentException("数字部分格式错误或超出 long 范围: " + numberPart, e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,11 +15,6 @@ import org.springblade.core.log.exception.ServiceException;
|
||||
import org.springblade.core.oss.model.BladeFile;
|
||||
import org.springblade.core.tool.utils.PathUtil;
|
||||
import org.springblade.core.tool.utils.StringUtil;
|
||||
import org.springblade.modules.common.eums.OrderStatus;
|
||||
import org.springblade.modules.common.eums.PaymentStatus;
|
||||
import org.springblade.modules.common.eums.PaymentType;
|
||||
import org.springblade.modules.common.pojo.entity.CommonPayOrderEntity;
|
||||
import org.springblade.modules.common.service.ICommonPayOrderService;
|
||||
import org.springblade.modules.resource.builder.OssBuilder;
|
||||
import org.springblade.plugin.pay.api.wxpay.IWxPayApiService;
|
||||
import org.springblade.plugin.pay.common.WxPayException;
|
||||
@@ -61,7 +56,6 @@ public class WxPayServiceImpl implements IWxPayService {
|
||||
private final OssBuilder ossBuilder;
|
||||
private final WxPayV3ParamsUtil wxPayV3ParamsUtil;
|
||||
private final IRefundService refundService;
|
||||
private final ICommonPayOrderService commonPayOrderService;
|
||||
|
||||
|
||||
/**
|
||||
@@ -233,17 +227,8 @@ public class WxPayServiceImpl implements IWxPayService {
|
||||
public Map<String, String> appPay(String appId, String mchId, String body, String money, String notifyUrl, String attach, String orderPrefix, Long orderId) {
|
||||
Map<String, String> appPayParams = null;
|
||||
try {
|
||||
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.APPPAY , orderPrefix);
|
||||
WxPayCheckBiz wxPayCheckBiz = beforeCheck(appId, mchId, body, money, notifyUrl,PayConstant.APPPAY , orderPrefix + orderId);
|
||||
Order order = wxPayCheckBiz.getOrder();
|
||||
CommonPayOrderEntity commonPayOrderEntity = new CommonPayOrderEntity();
|
||||
commonPayOrderEntity.setId(order.getId());
|
||||
commonPayOrderEntity.setOrderId(orderId);
|
||||
commonPayOrderEntity.setStatus(OrderStatus.PENDING_PAYMENT.getCode());
|
||||
commonPayOrderEntity.setPaymentStatus(PaymentStatus.UNPAID.getCode());
|
||||
commonPayOrderEntity.setOrderNo(order.getOrderNo());
|
||||
commonPayOrderEntity.setPaymentType(PaymentType.WECHAT.getCode());
|
||||
commonPayOrderEntity.setCreateTime(new Date());
|
||||
commonPayOrderService.save(commonPayOrderEntity);
|
||||
|
||||
WxPayAccountConfig wxPayAccountConfig = wxPayCheckBiz.getWxPayAccountConfig();
|
||||
Integer apiType = wxPayAccountConfig.getApiType();
|
||||
|
||||
Reference in New Issue
Block a user