U7: @Idempotent 落地 payment:pay 场景(防重复支付)
@Idempotent 注解和 IdempotentAspect 此前已建未用(Redis+DB 双保障幂等机制)。 lazy 决策:落地 1 个最典型场景比清理(涉及迁移脚本风险)更省。 在 PaymentController.pay 端点添加 @Idempotent(operation = "payment:pay", expireHours = 24): - 客户端通过 Idempotency-Key 请求头传入幂等键 - 首次请求正常处理,响应缓存到 Redis + DB - 重复请求(相同键)返回首次缓存结果 - 业务失败时删除 Redis 占位符允许重试 - 不传键则跳过幂等校验(向后兼容) 编译通过:./gradlew :pms-charge:compileJava
This commit is contained in:
parent
84b9cb8a3e
commit
e39da23976
|
|
@ -5,6 +5,7 @@ import com.pms.charge.dto.PaymentDTO;
|
|||
import com.pms.charge.dto.PaymentRequest;
|
||||
import com.pms.charge.service.PaymentService;
|
||||
import com.pms.common.annotation.AuditLog;
|
||||
import com.pms.common.annotation.Idempotent;
|
||||
import com.pms.common.response.PageResult;
|
||||
import com.pms.common.response.Result;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
|
@ -38,6 +39,7 @@ public class PaymentController {
|
|||
@PostMapping("/pay")
|
||||
@PreAuthorize("hasAuthority('charge:payment:manage')")
|
||||
@AuditLog(module = "charge", type = "CREATE", description = "发起支付", recordParams = false)
|
||||
@Idempotent(operation = "payment:pay", expireHours = 24)
|
||||
public Result<Map<String, Object>> pay(@Valid @RequestBody PaymentRequest request) {
|
||||
return Result.success(paymentService.pay(request));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue