添加邀请统计接口

This commit is contained in:
zk
2026-05-15 16:47:17 +08:00
parent 5156dd3b2f
commit fc22b49d5a
3 changed files with 51 additions and 2 deletions
@@ -1,6 +1,7 @@
package org.jiayunet.controller;
import lombok.AllArgsConstructor;
import org.jiayunet.pojo.dto.user.InviteStatsDto;
import org.jiayunet.pojo.dto.user.UserInfoDto;
import org.jiayunet.pojo.param.user.UserInfoParam;
import org.jiayunet.service.UserManageService;
@@ -42,4 +43,12 @@ public class UserManageController {
public void cancelAccount() {
userManageService.cancelAccount();
}
/**
* 邀请统计(累计邀请人数、累计获得会员天数)
*/
@GetMapping("/inviteStats")
public InviteStatsDto getInviteStats() {
return userManageService.getInviteStats();
}
}
@@ -0,0 +1,16 @@
package org.jiayunet.pojo.dto.user;
import lombok.Data;
/**
* 用户邀请统计DTO
*
* @author zk
*/
@Data
public class InviteStatsDto {
/** 累计邀请人数 */
private Long inviteCount;
/** 累计获得会员天数 */
private Integer rewardDays;
}
@@ -1,12 +1,16 @@
package org.jiayunet.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jiayunet.constant.PreRedisKeyName;
import org.jiayunet.mapper.UserInviteMapper;
import org.jiayunet.mapper.UserMapper;
import org.jiayunet.pojo.dto.user.InviteStatsDto;
import org.jiayunet.pojo.dto.user.UserInfoDto;
import org.jiayunet.pojo.param.user.UserInfoParam;
import org.jiayunet.pojo.po.User;
import org.jiayunet.pojo.po.UserInvite;
import org.jiayunet.tool.UserSecurityTool;
import org.jiayunet.tool.server.RedisServerTool;
import org.springframework.beans.BeanUtils;
@@ -15,10 +19,12 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.List;
/**
* 用户账号管理服务
* <p>主要功能:查看个人信息、修改个人信息、注销账号</p>
* <p>使用表:bg_user(查询/更新/逻辑删除)</p>
* <p>主要功能:查看个人信息、修改个人信息、注销账号、邀请统计</p>
* <p>使用表:bg_user(查询/更新/逻辑删除)、bg_user_invite(邀请统计)</p>
* <p>使用Redislogin:token:{userId}(注销时清理登录态)</p>
*
* @author zk
@@ -30,6 +36,9 @@ public class UserManageService {
@Autowired
private UserMapper userMapper;
@Autowired
private UserInviteMapper userInviteMapper;
@Autowired
private RedisServerTool redisServerTool;
@@ -80,4 +89,19 @@ public class UserManageService {
log.info("用户注销账号 userId:{}", userId);
}
/**
* 邀请统计
* <p>查询当前用户的累计邀请人数和累计获得会员天数</p>
*/
public InviteStatsDto getInviteStats() {
Long userId = UserSecurityTool.getUserId();
List<UserInvite> invites = userInviteMapper.selectList(new LambdaQueryWrapper<UserInvite>().eq(UserInvite::getInviterId, userId));
InviteStatsDto dto = new InviteStatsDto();
dto.setInviteCount((long) invites.size());
dto.setRewardDays(invites.stream().mapToInt(i -> i.getRewardDays() == null ? 0 : i.getRewardDays()).sum());
return dto;
}
}