refactor(core): 重构用户与购买记录逻辑并添加 UUID 字段
This commit is contained in:
@@ -7,6 +7,7 @@ import com.yolo.keyborad.common.ResultUtils;
|
||||
import com.yolo.keyborad.exception.BusinessException;
|
||||
import com.yolo.keyborad.model.dto.AppleReceiptValidationResult;
|
||||
import com.yolo.keyborad.service.ApplePurchaseService;
|
||||
import com.yolo.keyborad.service.KeyboardUserPurchaseRecordsService;
|
||||
import com.yolo.keyborad.service.AppleReceiptService;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -23,11 +24,14 @@ public class AppleReceiptController {
|
||||
|
||||
private final AppleReceiptService appleReceiptService;
|
||||
private final ApplePurchaseService applePurchaseService;
|
||||
private final KeyboardUserPurchaseRecordsService purchaseRecordsService;
|
||||
|
||||
public AppleReceiptController(AppleReceiptService appleReceiptService,
|
||||
ApplePurchaseService applePurchaseService) {
|
||||
ApplePurchaseService applePurchaseService,
|
||||
KeyboardUserPurchaseRecordsService purchaseRecordsService) {
|
||||
this.appleReceiptService = appleReceiptService;
|
||||
this.applePurchaseService = applePurchaseService;
|
||||
this.purchaseRecordsService = purchaseRecordsService;
|
||||
}
|
||||
|
||||
@PostMapping("/receipt")
|
||||
@@ -85,4 +89,26 @@ public class AppleReceiptController {
|
||||
return ResultUtils.success(Boolean.TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查购买记录是否存在
|
||||
* 根据 transactionId 和 originalTransactionId 查询购买记录
|
||||
*
|
||||
* @param body 请求体,包含 transactionId 和 originalTransactionId
|
||||
* @return 存在返回 true,不存在返回 false
|
||||
*/
|
||||
@PostMapping("/check-purchase")
|
||||
public BaseResponse<Boolean> checkPurchaseExists(@RequestBody Map<String, String> body) {
|
||||
if (body == null) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "body 不能为空");
|
||||
}
|
||||
String transactionId = body.get("transactionId");
|
||||
String originalTransactionId = body.get("originalTransactionId");
|
||||
if ((transactionId == null || transactionId.isBlank())
|
||||
&& (originalTransactionId == null || originalTransactionId.isBlank())) {
|
||||
throw new BusinessException(ErrorCode.PARAMS_ERROR, "transactionId 和 originalTransactionId 不能同时为空");
|
||||
}
|
||||
|
||||
boolean exists = purchaseRecordsService.checkPurchaseExists(transactionId, originalTransactionId);
|
||||
return ResultUtils.success(exists);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -132,4 +132,8 @@ public class KeyboardUser {
|
||||
@TableField(value = "vip_level")
|
||||
@Schema(description = "vip等级")
|
||||
private Integer vipLevel;
|
||||
|
||||
@TableField(value = "uuid")
|
||||
@Schema(description = "uuid")
|
||||
private String uuid;
|
||||
}
|
||||
|
||||
@@ -57,4 +57,6 @@ public class KeyboardUserInfoRespVO {
|
||||
@Schema(description = "vip等级")
|
||||
private Integer vipLevel;
|
||||
|
||||
@Schema(description = "uuid")
|
||||
private String uuid;
|
||||
}
|
||||
@@ -59,4 +59,8 @@ public class KeyboardUserRespVO {
|
||||
@TableField(value = "vip_level")
|
||||
@Schema(description = "vip等级")
|
||||
private Integer vipLevel;
|
||||
|
||||
@TableField(value = "uuid")
|
||||
@Schema(description = "uuid")
|
||||
private String uuid;
|
||||
}
|
||||
@@ -8,4 +8,13 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
*/
|
||||
|
||||
public interface KeyboardUserPurchaseRecordsService extends IService<KeyboardUserPurchaseRecords>{
|
||||
|
||||
/**
|
||||
* 检查购买记录是否存在
|
||||
*
|
||||
* @param transactionId 交易 ID
|
||||
* @param originalTransactionId 原始交易 ID
|
||||
* @return 存在返回 true,不存在返回 false
|
||||
*/
|
||||
boolean checkPurchaseExists(String transactionId, String originalTransactionId);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
package com.yolo.keyborad.service.impl;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yolo.keyborad.mapper.KeyboardUserPurchaseRecordsMapper;
|
||||
import com.yolo.keyborad.model.entity.KeyboardUserPurchaseRecords;
|
||||
@@ -11,8 +10,19 @@ import com.yolo.keyborad.service.KeyboardUserPurchaseRecordsService;
|
||||
* @author: ziin
|
||||
* @date: 2025/12/12 15:16
|
||||
*/
|
||||
|
||||
|
||||
@Service
|
||||
public class KeyboardUserPurchaseRecordsServiceImpl extends ServiceImpl<KeyboardUserPurchaseRecordsMapper, KeyboardUserPurchaseRecords> implements KeyboardUserPurchaseRecordsService{
|
||||
|
||||
@Override
|
||||
public boolean checkPurchaseExists(String transactionId, String originalTransactionId) {
|
||||
LambdaQueryWrapper<KeyboardUserPurchaseRecords> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (transactionId != null && !transactionId.isBlank()) {
|
||||
queryWrapper.eq(KeyboardUserPurchaseRecords::getTransactionId, transactionId);
|
||||
}
|
||||
if (originalTransactionId != null && !originalTransactionId.isBlank()) {
|
||||
queryWrapper.eq(KeyboardUserPurchaseRecords::getOriginalTransactionId, originalTransactionId);
|
||||
}
|
||||
return exists(queryWrapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.yolo.keyborad.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
@@ -203,6 +204,7 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
||||
keyboardUser.setSubjectId(sub);
|
||||
keyboardUser.setUid(IdUtil.getSnowflake().nextId());
|
||||
keyboardUser.setNickName("User_" + RandomUtil.randomString(6));
|
||||
keyboardUser.setUuid(IdUtil.randomUUID());
|
||||
return keyboardUser;
|
||||
}
|
||||
|
||||
|
||||
@@ -118,6 +118,7 @@ public class UserRegistrationHandler {
|
||||
keyboardUser.setEmail(userRegisterDTO.getMailAddress());
|
||||
keyboardUser.setGender(userRegisterDTO.getGender());
|
||||
keyboardUser.setEmailVerified(true);
|
||||
keyboardUser.setUuid(IdUtil.randomUUID());
|
||||
return keyboardUser;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user