feat:
1. notice module
This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
package org.springblade.modules.common.eums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum OrderStatus {
|
||||||
|
|
||||||
|
PENDING_PAYMENT(0, "📌 订单 %s 尚未支付!请尽快完成付款,以免订单自动取消。"),
|
||||||
|
PAID(1, "✅ 订单 %s 已支付成功!商家正在准备发货(或待您使用),请耐心等待。"),
|
||||||
|
CANCELLED(2, "🗑️ 订单 %s 已取消。如有疑问,可联系客服了解详情。"),
|
||||||
|
SHIPPED(3, "🚚 订单 %s 已发货!(或🎫 电子票已出票)请留意物流信息(或按时使用服务)。"),
|
||||||
|
COMPLETED(4, "🎉 订单 %s 已完成!感谢您的信任,期待再次为您服务~"),
|
||||||
|
CLOSED_TIMEOUT(5, "⏰ 订单 %s 因超时未支付已自动关闭。如需购买,请重新下单。"),
|
||||||
|
REFUNDING(6, "🔄 订单 %s 的退款申请已受理,款项将在1-7个工作日内原路退回,请耐心等待。"),
|
||||||
|
REFUNDED(7, "💸 订单 %s 的退款已成功!金额已退至您的原支付账户,请注意查收。");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String userMessageTemplate;
|
||||||
|
|
||||||
|
OrderStatus(int code, String userMessageTemplate) {
|
||||||
|
this.code = code;
|
||||||
|
this.userMessageTemplate = userMessageTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据订单号生成面向用户的消息
|
||||||
|
*/
|
||||||
|
public String formatUserMessage(String orderId) {
|
||||||
|
return userMessageTemplate.formatted(orderId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 静态工具方法 ==========
|
||||||
|
|
||||||
|
private static final Map<Integer, OrderStatus> BY_CODE = Stream.of(values())
|
||||||
|
.collect(Collectors.toUnmodifiableMap(OrderStatus::getCode, Function.identity()));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据状态码(int)获取对应的 OrderStatus 枚举
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException 如果状态码无效
|
||||||
|
*/
|
||||||
|
public static OrderStatus fromCode(int code) {
|
||||||
|
OrderStatus status = BY_CODE.get(code);
|
||||||
|
if (status == null) {
|
||||||
|
throw new IllegalArgumentException("无效的订单状态码: " + code);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全版本:根据状态码获取枚举,若无效则返回 null(适用于非严格场景)
|
||||||
|
*/
|
||||||
|
public static OrderStatus fromCodeOrNull(int code) {
|
||||||
|
return BY_CODE.get(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package org.springblade.modules.common.eums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum PaymentStatus {
|
||||||
|
UNPAID(0, "未支付"),
|
||||||
|
PAID(1, "已支付"),
|
||||||
|
FAILED(2, "支付失败"),
|
||||||
|
PROCESSING(3, "支付中(如跳转网银)");
|
||||||
|
|
||||||
|
private final int code;
|
||||||
|
private final String description;
|
||||||
|
|
||||||
|
PaymentStatus(int code, String description) {
|
||||||
|
this.code = code;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== 静态映射:code -> enum ==========
|
||||||
|
|
||||||
|
private static final Map<Integer, PaymentStatus> BY_CODE = Stream.of(values())
|
||||||
|
.collect(Collectors.toUnmodifiableMap(PaymentStatus::getCode, Function.identity()));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 根据整型状态码获取对应的枚举(严格模式)
|
||||||
|
*
|
||||||
|
* @throws IllegalArgumentException 如果状态码无效
|
||||||
|
*/
|
||||||
|
public static PaymentStatus fromCode(int code) {
|
||||||
|
PaymentStatus status = BY_CODE.get(code);
|
||||||
|
if (status == null) {
|
||||||
|
throw new IllegalArgumentException("无效的支付状态码: " + code);
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 安全版本:无效状态码返回 null
|
||||||
|
*/
|
||||||
|
public static PaymentStatus fromCodeOrNull(int code) {
|
||||||
|
return BY_CODE.get(code);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,12 +25,10 @@
|
|||||||
*/
|
*/
|
||||||
package org.springblade.modules.common.service.impl;
|
package org.springblade.modules.common.service.impl;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
||||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||||
import io.jsonwebtoken.lang.Assert;
|
import io.jsonwebtoken.lang.Assert;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.RandomUtils;
|
|
||||||
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.secure.utils.AuthUtil;
|
||||||
import org.springblade.modules.api.request.CreateOrderRequest;
|
import org.springblade.modules.api.request.CreateOrderRequest;
|
||||||
import org.springblade.modules.api.request.PaymentRequest;
|
import org.springblade.modules.api.request.PaymentRequest;
|
||||||
@@ -38,6 +36,8 @@ import org.springblade.modules.api.response.CreateOrderResponse;
|
|||||||
import org.springblade.modules.api.response.PaymentResponse;
|
import org.springblade.modules.api.response.PaymentResponse;
|
||||||
import org.springblade.modules.api.vo.CommonUserOrderApiVO;
|
import org.springblade.modules.api.vo.CommonUserOrderApiVO;
|
||||||
import org.springblade.modules.common.convert.AppCommonConvert;
|
import org.springblade.modules.common.convert.AppCommonConvert;
|
||||||
|
import org.springblade.modules.common.eums.OrderStatus;
|
||||||
|
import org.springblade.modules.common.eums.PaymentStatus;
|
||||||
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
|
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
|
||||||
import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
|
import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
|
||||||
import org.springblade.modules.common.excel.CommonUserOrderExcel;
|
import org.springblade.modules.common.excel.CommonUserOrderExcel;
|
||||||
@@ -135,8 +135,8 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
|
|||||||
@Override
|
@Override
|
||||||
public boolean confirmPayment(CommonUserOrderEntity order) {
|
public boolean confirmPayment(CommonUserOrderEntity order) {
|
||||||
return update(Wrappers.<CommonUserOrderEntity>lambdaUpdate()
|
return update(Wrappers.<CommonUserOrderEntity>lambdaUpdate()
|
||||||
.set(CommonUserOrderEntity::getOrderStatus, 1)
|
.set(CommonUserOrderEntity::getOrderStatus, OrderStatus.PAID.getCode())
|
||||||
.set(CommonUserOrderEntity::getPaymentStatus, 1)
|
.set(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.PAID.getCode())
|
||||||
.set(CommonUserOrderEntity::getPaymentTime, new Date())
|
.set(CommonUserOrderEntity::getPaymentTime, new Date())
|
||||||
.eq(CommonUserOrderEntity::getId, order.getId())
|
.eq(CommonUserOrderEntity::getId, order.getId())
|
||||||
.eq(CommonUserOrderEntity::getPaymentType, 99)
|
.eq(CommonUserOrderEntity::getPaymentType, 99)
|
||||||
|
|||||||
Reference in New Issue
Block a user