feat(invite): 新增H5邀请链接配置与返回
在 AppConfig 中增加 inviteConfig 及 h5Link 字段; 服务层改造 getUserInviteCode 返回 InviteCodeRespVO 并填充 h5Link; Controller 简化调用逻辑,统一走服务层组装 VO。
This commit is contained in:
@@ -17,6 +17,8 @@ public class AppConfig {
|
|||||||
|
|
||||||
private LLmConfig llmConfig = new LLmConfig();
|
private LLmConfig llmConfig = new LLmConfig();
|
||||||
|
|
||||||
|
private inviteConfig inviteConfig = new inviteConfig();
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static class UserRegisterProperties {
|
public static class UserRegisterProperties {
|
||||||
|
|
||||||
@@ -48,4 +50,8 @@ public class AppConfig {
|
|||||||
private Integer maxMessageLength = 1000;
|
private Integer maxMessageLength = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public static class inviteConfig {
|
||||||
|
private String h5Link = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,11 +143,6 @@ public class UserController {
|
|||||||
@Operation(summary = "查询邀请码", description = "查询用户自己的邀请码")
|
@Operation(summary = "查询邀请码", description = "查询用户自己的邀请码")
|
||||||
public BaseResponse<InviteCodeRespVO> getInviteCode() {
|
public BaseResponse<InviteCodeRespVO> getInviteCode() {
|
||||||
long userId = StpUtil.getLoginIdAsLong();
|
long userId = StpUtil.getLoginIdAsLong();
|
||||||
KeyboardUserInviteCodes inviteCode = inviteCodesService.getUserInviteCode(userId);
|
return ResultUtils.success( inviteCodesService.getUserInviteCode(userId));
|
||||||
if (inviteCode == null) {
|
|
||||||
inviteCode = inviteCodesService.createInviteCode(userId);
|
|
||||||
}
|
|
||||||
InviteCodeRespVO respVO = BeanUtil.copyProperties(inviteCode, InviteCodeRespVO.class);
|
|
||||||
return ResultUtils.success(respVO);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -26,4 +26,7 @@ public class InviteCodeRespVO {
|
|||||||
|
|
||||||
@Schema(description = "过期时间")
|
@Schema(description = "过期时间")
|
||||||
private Date expiresAt;
|
private Date expiresAt;
|
||||||
|
|
||||||
|
@Schema(description = "H5链接")
|
||||||
|
private String h5Link;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.yolo.keyborad.service;
|
|||||||
|
|
||||||
import com.yolo.keyborad.model.entity.KeyboardUserInviteCodes;
|
import com.yolo.keyborad.model.entity.KeyboardUserInviteCodes;
|
||||||
import com.baomidou.mybatisplus.extension.service.IService;
|
import com.baomidou.mybatisplus.extension.service.IService;
|
||||||
|
import com.yolo.keyborad.model.vo.user.InviteCodeRespVO;
|
||||||
/*
|
/*
|
||||||
* @author: ziin
|
* @author: ziin
|
||||||
* @date: 2025/12/18 16:26
|
* @date: 2025/12/18 16:26
|
||||||
@@ -21,7 +22,7 @@ public interface KeyboardUserInviteCodesService extends IService<KeyboardUserInv
|
|||||||
* @param userId 用户ID
|
* @param userId 用户ID
|
||||||
* @return 邀请码实体
|
* @return 邀请码实体
|
||||||
*/
|
*/
|
||||||
KeyboardUserInviteCodes getUserInviteCode(Long userId);
|
InviteCodeRespVO getUserInviteCode(Long userId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 为用户创建邀请码
|
* 为用户创建邀请码
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package com.yolo.keyborad.service.impl;
|
package com.yolo.keyborad.service.impl;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
import cn.hutool.core.util.RandomUtil;
|
import cn.hutool.core.util.RandomUtil;
|
||||||
import com.yolo.keyborad.common.ErrorCode;
|
import com.yolo.keyborad.common.ErrorCode;
|
||||||
|
import com.yolo.keyborad.config.AppConfig;
|
||||||
|
import com.yolo.keyborad.config.NacosAppConfigCenter;
|
||||||
import com.yolo.keyborad.exception.BusinessException;
|
import com.yolo.keyborad.exception.BusinessException;
|
||||||
|
import com.yolo.keyborad.model.vo.user.InviteCodeRespVO;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@@ -20,11 +24,25 @@ 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{
|
||||||
|
|
||||||
|
private final NacosAppConfigCenter.DynamicAppConfig cfgHolder;
|
||||||
|
|
||||||
|
public KeyboardUserInviteCodesServiceImpl(NacosAppConfigCenter.DynamicAppConfig cfgHolder) {
|
||||||
|
this.cfgHolder = cfgHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public KeyboardUserInviteCodes getUserInviteCode(Long userId) {
|
public InviteCodeRespVO getUserInviteCode(Long userId) {
|
||||||
QueryWrapper<KeyboardUserInviteCodes> queryWrapper = new QueryWrapper<>();
|
QueryWrapper<KeyboardUserInviteCodes> queryWrapper = new QueryWrapper<>();
|
||||||
queryWrapper.eq("owner_user_id", userId);
|
queryWrapper.eq("owner_user_id", userId);
|
||||||
return this.getOne(queryWrapper);
|
KeyboardUserInviteCodes one = this.getOne(queryWrapper);
|
||||||
|
if (one == null) {
|
||||||
|
one = createInviteCode(userId);
|
||||||
|
}
|
||||||
|
InviteCodeRespVO inviteCodeRespVO = BeanUtil.copyProperties(one, InviteCodeRespVO.class);
|
||||||
|
AppConfig appConfig = cfgHolder.getRef().get();
|
||||||
|
inviteCodeRespVO.setH5Link(appConfig.getInviteConfig().getH5Link());
|
||||||
|
return inviteCodeRespVO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,6 +80,7 @@ public class KeyboardUserInviteCodesServiceImpl extends ServiceImpl<KeyboardUser
|
|||||||
|
|
||||||
// 保存到数据库
|
// 保存到数据库
|
||||||
this.save(inviteCode);
|
this.save(inviteCode);
|
||||||
|
InviteCodeRespVO inviteCodeRespVO = BeanUtil.copyProperties(inviteCode, InviteCodeRespVO.class);
|
||||||
|
|
||||||
return inviteCode;
|
return inviteCode;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user