Merge remote-tracking branch 'origin/main'

This commit is contained in:
attiya 2025-10-23 09:22:39 +08:00
commit d802bd0625
10 changed files with 160 additions and 231 deletions

View File

@ -1,33 +0,0 @@
package com.cdzy.payment.enums;
/**
* @author: yanglei
* @since: 2025-10-17 15:10
*/
public interface DetailType {
/**
* 骑行时长费
*/
int RIDE_DURATION_FEE = 1;
/**
* 运营区调度费用
*/
int OPERATION_AREA_DISPATCH_FEE = 2;
/**
* 停车区调度费用
*/
int PARKING_AREA_DISPATCH_FEE = 3;
/**
* 高峰时段出行费用
*/
int PEAK_HOUR_FEE = 4;
/**
* 高峰日出行费用
*/
int PEAK_DAY_FEE = 5;
/**
* 起步费用
*/
int START_FEE = 6;
}

View File

@ -1,26 +0,0 @@
package com.cdzy.payment.enums;
/**
* 故障处理状态枚举
*
* @author: yanglei
* @since: 2025-10-17 15:12
*/
public interface HandleStatus {
/**
* 待处理
*/
int PENDING = 0;
/**
* 处理中
*/
int PROCESSING = 1;
/**
* 处理完
*/
int COMPLETED = 2;
}

View File

@ -1,56 +0,0 @@
package com.cdzy.payment.enums;
/**
* 订单状态枚举
*
* @author: yanglei
* @since: 2025-10-17 15:09
*/
public interface OrderStatus {
/**
* 进行中
*/
int IN_PROGRESS = 0;
/**
* 已取消
*/
int CANCELED = 1;
/**
* 待支付
*/
int PENDING_PAYMENT = 2;
/**
* 已支付
*/
int PAID = 3;
/**
* 退款中
*/
int REFUNDING = 4;
/**
* 已退款
*/
int REFUNDED = 5;
/**
* 退款申请中
*/
int REFUND_APPLYING = 6;
/**
* 退款驳回
*/
int REFUND_REJECTED = 7;
/**
* 退款失败
*/
int REFUND_FAILED = 8;
}

View File

@ -1,20 +0,0 @@
package com.cdzy.payment.enums;
/**
* 订单类型枚举
*
* @author: yanglei
* @since: 2025-10-17 15:09
*/
public interface OrderType {
/** 单次骑行 */
int SINGLE_RIDE = 1;
/** 骑行卡购买 */
int RIDE_CARD_PURCHASE = 2;
/** 会员卡续费 */
int MEMBER_CARD_RENEW = 3;
}

View File

@ -1,28 +0,0 @@
package com.cdzy.payment.enums;
/**
* 审核状态枚举
*
* @author: yanglei
* @since: 2025-10-17 15:11
*/
public interface ProcessStatus {
/**
* 申请中
*/
int APPLYING = 0;
/**
* 处理中
*/
int PROCESSING = 1;
/**
* 已处理
*/
int PROCESSED = 2;
/**
* 已关闭
*/
int CLOSED = 3;
}

View File

@ -1,26 +0,0 @@
package com.cdzy.payment.enums;
/**
* 退款方式枚举
*
* @author: yanglei
* @since: 2025-10-17 15:11
*/
public interface RefundMethod {
/**
* 原路返回
*/
int ORIGINAL = 0;
/**
* 余额
*/
int BALANCE = 1;
/**
* 线下退款
*/
int OFFLINE = 2;
}

View File

@ -1,42 +0,0 @@
package com.cdzy.payment.enums;
/**
* @author: yanglei
* @since: 2025-10-17 15:10
*/
public interface TradeStatus {
/**
* 支付成功
*/
int SUCCESS = 0;
/**
* 退款
*/
int REFUNDED = 1;
/**
* 未支付
*/
int UNPAID = 2;
/**
* 关闭
*/
int CLOSED = 3;
/**
* 取消
*/
int CANCELED = 4;
/**
* 支付中
*/
int PAYING = 5;
/**
* 支付错误
*/
int ERROR = 6;
/**
* 接受
*/
int ACCEPTED = 7;
}

View File

@ -0,0 +1,58 @@
package com.cdzy.payment.task;
import com.cdzy.payment.config.WxPayConfig;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
import org.springframework.scheduling.support.CronTrigger;
import org.springframework.stereotype.Component;
/**
* 微信支付定时作业调度器
*
* @author: yanglei
* @since: 2025-10-22 16:11
*/
@Slf4j
@Component
public class WxPayScheduledManager {
@Resource
private WxPayConfig wxPayConfig;
@Resource
private ThreadPoolTaskScheduler threadPoolTaskScheduler;
@Resource
private WxPayTask wxPayTask;
@PostConstruct
public void init() {
String payCron = wxPayConfig.getPaySchedule();
String refundCron = wxPayConfig.getRefundSchedule();
// 注册支付状态检查任务
scheduleTask("CheckOrderStatus", wxPayTask::checkOrderStatus, payCron);
// 注册退款状态检查任务
scheduleTask("CheckRefundStatus", wxPayTask::checkRefundStatus, refundCron);
}
private void scheduleTask(String taskName, Runnable task, String cronExpression) {
if (cronExpression == null || cronExpression.trim().isEmpty()) {
log.warn("定时任务 [{}] 未配置Cron表达式跳过注册", taskName);
return;
}
threadPoolTaskScheduler.schedule(() -> {
try {
log.debug("执行定时任务: {}", taskName);
task.run();
} catch (Exception e) {
log.error("定时任务执行异常: {}", taskName, e);
}
}, new CronTrigger(cronExpression));
log.info("已注册定时任务: {}, Cron表达式: {}", taskName, cronExpression);
}
}

View File

@ -0,0 +1,100 @@
package com.cdzy.payment.task;
import com.cdzy.payment.config.WxPayConfig;
import com.cdzy.payment.model.entity.EbikePayment;
import com.cdzy.payment.model.entity.EbikeRefund;
import com.cdzy.payment.service.EbikePaymentService;
import com.cdzy.payment.service.EbikeRefundService;
import com.cdzy.payment.service.WxPayService;
import com.wechat.pay.java.service.payments.model.Transaction;
import com.wechat.pay.java.service.refund.model.Refund;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 用户订单支付任务检测支付状态更新订单状态
*
* @author: yanglei
* @since: 2025-10-22 16:09
*/
@Slf4j
@Service
public class WxPayTask {
@Resource
private WxPayConfig wxPayConfig;
@Resource
private WxPayService wxPayService;
@Resource
private EbikePaymentService ebikePaymentService;
@Resource
private EbikeRefundService ebikeRefundService;
/**
* 查询创建未超过24小时并且未支付的订单
*/
public void checkOrderStatus() {
log.info("checkOrderStatus 执行......");
// 1. 查询未支付的订单
List<EbikePayment> ebikePaymentList = ebikePaymentService.getNoPayOrderByDuration(wxPayConfig.getExpireMinute());
// 2. 遍历订单查询支付状态
for (EbikePayment ebikePayment : ebikePaymentList) {
log.warn("未支付的订单号 ===> {}", ebikePayment.getOrderId());
// 调用微信支付查询接口查询支付状态
Transaction transaction = wxPayService.queryOrderByOutTradeNo(ebikePayment.getTradeId());
// 3. 更新订单状态
if (transaction != null) {
ebikePaymentService.updatePaymentStatus(transaction);
}
}
}
/**
* 查询创建超过24小时并且未支付的订单
*/
public void closeOrder() {
log.info("closeOrder 执行......");
// 1. 查询未支付的超时订单
List<EbikePayment> ebikePaymentList = ebikePaymentService.getExpireOrderByDuration(wxPayConfig.getExpireMinute());
// 2. 遍历订单关闭订单
for (EbikePayment ebikePayment : ebikePaymentList) {
log.warn("超时未支付的订单号 ===> {}", ebikePayment.getOrderId());
// 调用微信支付关闭接口关闭订单
boolean close = wxPayService.closeOrder(ebikePayment.getTradeId());
if (close) {
// 3. 更新订单状态
Transaction transaction = new Transaction();
transaction.setTradeState(Transaction.TradeStateEnum.CLOSED);
transaction.setTradeStateDesc("订单关闭");
ebikePaymentService.updatePaymentStatus(transaction);
}
}
}
/**
* 查询创建未超过24小时并且未成功的退款单
*/
public void checkRefundStatus() {
log.info("checkRefundStatus 执行......");
// 1. 查询未成功的退款单
List<EbikeRefund> ebikeRefundList = ebikeRefundService.getNoSuccessRefundOrderByDuration(wxPayConfig.getExpireMinute());
// 2. 遍历退款单查询退款状态
for (EbikeRefund ebikeRefund : ebikeRefundList) {
log.warn("超时未退款的退款单号 ===> {}", ebikeRefund.getRefundId());
// 调用微信退款查询接口查询退款状态
Refund refund = wxPayService.queryRefundByOutTradeNo(ebikeRefund.getRefundOrder());
if (refund != null) {
// 3. 更新退款单状态
ebikeRefundService.updateRefundStatus(refund);
}
}
}
}

View File

@ -1,6 +1,8 @@
package com.cdzy.user.enums;
/**
* 实名认证的状态
*
* @author: yanglei
* @since: 2025-10-16 11:10
*/