refactor(invite): 移除用户主动生成邀请码功能
- 删除 InviteCodeRespVO.java VO 类 - 移除 KeyboardUserInviteCodesService 及其实现中的 createInviteCode/getUserInviteCode 方法 - 删除 UserController 中 /inviteCode 查询接口 - 注册流程不再自动为用户创建邀请码,仅保留绑定逻辑
This commit is contained in:
@@ -8,12 +8,9 @@ import com.yolo.keyborad.model.dto.AppleLoginReq;
|
|||||||
import com.yolo.keyborad.model.dto.user.*;
|
import com.yolo.keyborad.model.dto.user.*;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardFeedback;
|
import com.yolo.keyborad.model.entity.KeyboardFeedback;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardUser;
|
import com.yolo.keyborad.model.entity.KeyboardUser;
|
||||||
import com.yolo.keyborad.model.entity.KeyboardUserInviteCodes;
|
|
||||||
import com.yolo.keyborad.model.vo.user.InviteCodeRespVO;
|
|
||||||
import com.yolo.keyborad.model.vo.user.KeyboardUserInfoRespVO;
|
import com.yolo.keyborad.model.vo.user.KeyboardUserInfoRespVO;
|
||||||
import com.yolo.keyborad.model.vo.user.KeyboardUserRespVO;
|
import com.yolo.keyborad.model.vo.user.KeyboardUserRespVO;
|
||||||
import com.yolo.keyborad.service.IAppleService;
|
import com.yolo.keyborad.service.IAppleService;
|
||||||
import com.yolo.keyborad.service.KeyboardUserInviteCodesService;
|
|
||||||
import com.yolo.keyborad.service.UserService;
|
import com.yolo.keyborad.service.UserService;
|
||||||
import io.swagger.v3.oas.annotations.Operation;
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
import io.swagger.v3.oas.annotations.Parameter;
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
@@ -46,9 +43,6 @@ public class UserController {
|
|||||||
@Resource
|
@Resource
|
||||||
private com.yolo.keyborad.service.KeyboardFeedbackService feedbackService;
|
private com.yolo.keyborad.service.KeyboardFeedbackService feedbackService;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private KeyboardUserInviteCodesService inviteCodesService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 苹果登录
|
* 苹果登录
|
||||||
*
|
*
|
||||||
@@ -133,15 +127,6 @@ public class UserController {
|
|||||||
return ResultUtils.success(feedbackService.save(feedback));
|
return ResultUtils.success(feedbackService.save(feedback));
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/inviteCode")
|
|
||||||
@Operation(summary = "查询邀请码", description = "查询用户自己的邀请码")
|
|
||||||
public BaseResponse<InviteCodeRespVO> getInviteCode() {
|
|
||||||
long userId = StpUtil.getLoginIdAsLong();
|
|
||||||
KeyboardUserInviteCodes inviteCode = inviteCodesService.getUserInviteCode(userId);
|
|
||||||
InviteCodeRespVO respVO = BeanUtil.copyProperties(inviteCode, InviteCodeRespVO.class);
|
|
||||||
return ResultUtils.success(respVO);
|
|
||||||
}
|
|
||||||
|
|
||||||
@PostMapping("/bindInviteCode")
|
@PostMapping("/bindInviteCode")
|
||||||
@Operation(summary = "绑定邀请码", description = "用户填写邀请码进行绑定")
|
@Operation(summary = "绑定邀请码", description = "用户填写邀请码进行绑定")
|
||||||
public BaseResponse<Boolean> bindInviteCode(@RequestBody BindInviteCodeDTO bindInviteCodeDTO) {
|
public BaseResponse<Boolean> bindInviteCode(@RequestBody BindInviteCodeDTO bindInviteCodeDTO) {
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package com.yolo.keyborad.model.vo.user;
|
|
||||||
|
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
|
||||||
import lombok.Data;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 邀请码响应VO
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Schema(description = "邀请码信息")
|
|
||||||
public class InviteCodeRespVO {
|
|
||||||
|
|
||||||
@Schema(description = "邀请码")
|
|
||||||
private String code;
|
|
||||||
|
|
||||||
@Schema(description = "邀请码状态:1=启用,0=停用")
|
|
||||||
private Short status;
|
|
||||||
|
|
||||||
@Schema(description = "已使用次数")
|
|
||||||
private Integer usedCount;
|
|
||||||
|
|
||||||
@Schema(description = "最大可使用次数")
|
|
||||||
private Integer maxUses;
|
|
||||||
|
|
||||||
@Schema(description = "过期时间")
|
|
||||||
private Date expiresAt;
|
|
||||||
}
|
|
||||||
@@ -8,21 +8,6 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public interface KeyboardUserInviteCodesService extends IService<KeyboardUserInviteCodes>{
|
public interface KeyboardUserInviteCodesService extends IService<KeyboardUserInviteCodes>{
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取用户的邀请码
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @return 邀请码实体
|
|
||||||
*/
|
|
||||||
KeyboardUserInviteCodes getUserInviteCode(Long userId);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 为用户创建邀请码
|
|
||||||
* @param userId 用户ID
|
|
||||||
* @return 创建的邀请码实体
|
|
||||||
*/
|
|
||||||
KeyboardUserInviteCodes createInviteCode(Long userId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证邀请码是否有效
|
* 验证邀请码是否有效
|
||||||
* @param code 邀请码
|
* @param code 邀请码
|
||||||
|
|||||||
@@ -20,52 +20,6 @@ import com.yolo.keyborad.service.KeyboardUserInviteCodesService;
|
|||||||
@Service
|
@Service
|
||||||
public class KeyboardUserInviteCodesServiceImpl extends ServiceImpl<KeyboardUserInviteCodesMapper, KeyboardUserInviteCodes> implements KeyboardUserInviteCodesService{
|
public class KeyboardUserInviteCodesServiceImpl extends ServiceImpl<KeyboardUserInviteCodesMapper, KeyboardUserInviteCodes> implements KeyboardUserInviteCodesService{
|
||||||
|
|
||||||
@Override
|
|
||||||
public KeyboardUserInviteCodes getUserInviteCode(Long userId) {
|
|
||||||
QueryWrapper<KeyboardUserInviteCodes> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("owner_user_id", userId);
|
|
||||||
return this.getOne(queryWrapper);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public KeyboardUserInviteCodes createInviteCode(Long userId) {
|
|
||||||
// 生成唯一的邀请码
|
|
||||||
String code;
|
|
||||||
int maxRetries = 10;
|
|
||||||
int retryCount = 0;
|
|
||||||
|
|
||||||
do {
|
|
||||||
// 生成8位字母数字组合的邀请码
|
|
||||||
code = RandomUtil.randomString(8).toUpperCase();
|
|
||||||
|
|
||||||
// 检查邀请码是否已存在
|
|
||||||
QueryWrapper<KeyboardUserInviteCodes> queryWrapper = new QueryWrapper<>();
|
|
||||||
queryWrapper.eq("code", code);
|
|
||||||
KeyboardUserInviteCodes existingCode = this.getOne(queryWrapper);
|
|
||||||
|
|
||||||
if (existingCode == null) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
retryCount++;
|
|
||||||
} while (retryCount < maxRetries);
|
|
||||||
|
|
||||||
// 创建邀请码实体
|
|
||||||
KeyboardUserInviteCodes inviteCode = new KeyboardUserInviteCodes();
|
|
||||||
inviteCode.setCode(code);
|
|
||||||
inviteCode.setOwnerUserId(userId);
|
|
||||||
inviteCode.setStatus((short) 1); // 启用状态
|
|
||||||
inviteCode.setCreatedAt(new Date());
|
|
||||||
inviteCode.setExpiresAt(null); // 永久有效
|
|
||||||
inviteCode.setMaxUses(null); // 不限次数
|
|
||||||
inviteCode.setUsedCount(0); // 初始使用次数为0
|
|
||||||
|
|
||||||
// 保存到数据库
|
|
||||||
this.save(inviteCode);
|
|
||||||
|
|
||||||
return inviteCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeyboardUserInviteCodes validateInviteCode(String code) {
|
public KeyboardUserInviteCodes validateInviteCode(String code) {
|
||||||
// 查询邀请码
|
// 查询邀请码
|
||||||
|
|||||||
@@ -114,9 +114,6 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
|||||||
quotaTotal.setUpdatedAt(new Date());
|
quotaTotal.setUpdatedAt(new Date());
|
||||||
quotaTotalService.save(quotaTotal);
|
quotaTotalService.save(quotaTotal);
|
||||||
|
|
||||||
// 初始化用户邀请码
|
|
||||||
inviteCodesService.createInviteCode(keyboardUser.getId());
|
|
||||||
|
|
||||||
log.info("User registered with Apple Sign-In, userId={}, freeQuota={}",
|
log.info("User registered with Apple Sign-In, userId={}, freeQuota={}",
|
||||||
keyboardUser.getId(), appConfig.getUserRegisterProperties().getFreeTrialQuota());
|
keyboardUser.getId(), appConfig.getUserRegisterProperties().getFreeTrialQuota());
|
||||||
|
|
||||||
@@ -256,9 +253,6 @@ public class UserServiceImpl extends ServiceImpl<KeyboardUserMapper, KeyboardUse
|
|||||||
quotaTotal.setUpdatedAt(new Date());
|
quotaTotal.setUpdatedAt(new Date());
|
||||||
quotaTotalService.save(quotaTotal);
|
quotaTotalService.save(quotaTotal);
|
||||||
|
|
||||||
// 初始化用户邀请码
|
|
||||||
inviteCodesService.createInviteCode(keyboardUser.getId());
|
|
||||||
|
|
||||||
// 处理邀请码绑定
|
// 处理邀请码绑定
|
||||||
if (userRegisterDTO.getInviteCode() != null && !userRegisterDTO.getInviteCode().trim().isEmpty()) {
|
if (userRegisterDTO.getInviteCode() != null && !userRegisterDTO.getInviteCode().trim().isEmpty()) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user