This commit is contained in:
dute7liang
2024-01-20 17:15:09 +08:00
parent 78ea852a34
commit a1fbc045a1
3 changed files with 121 additions and 7 deletions

View File

@@ -1,10 +1,14 @@
package com.ruoyi.cai.controller.app;
import com.fasterxml.jackson.databind.ser.std.CollectionSerializer;
import com.ruoyi.cai.domain.User;
import com.ruoyi.cai.dto.app.vo.rank.RankNodeInvite;
import com.ruoyi.cai.dto.app.vo.rank.RankNodeLove;
import com.ruoyi.cai.enums.GenderEnum;
import com.ruoyi.cai.rank.RankManager;
import com.ruoyi.cai.rank.RankNode;
import com.ruoyi.cai.service.UserService;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.StringUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@@ -13,8 +17,9 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Collections;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api/rank")
@@ -23,6 +28,8 @@ public class RankController {
@Autowired
private RankManager rankManager;
@Autowired
private UserService userService;
@GetMapping("/love")
@Operation(summary = "魅力榜")
@@ -47,7 +54,93 @@ public class RankController {
}else{
rankNodeList = Collections.emptyList();
}
if(rankNodeList.isEmpty()){
return R.ok(Collections.emptyList());
}
List<RankNodeLove> res = new ArrayList<>();
Set<Long> userIds = rankNodeList.stream().map(RankNode::getUserId).collect(Collectors.toSet());
List<User> userList = userService.listByIds(userIds);
Map<Long, User> userMap = userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));
long lastLove = 0;
for (int i = 0; i < rankNodeList.size(); i++) {
RankNode rankNode = rankNodeList.get(i);
User user = userMap.get(rankNode.getUserId());
if(user == null){
continue;
}
RankNodeLove love = new RankNodeLove();
love.setUserId(user.getId());
love.setAvatar(user.getAvatar());
love.setNickname(user.getNickname());
love.setValue(rankNode.getScore());
love.setHide(false);
if(i == 0){
love.setDiffLastValue(0L);
}else{
love.setDiffLastValue(lastLove - rankNode.getScore());
}
lastLove = rankNode.getScore();
res.add(love);
}
return R.ok(res);
}
return R.ok();
@GetMapping("/invite")
@Operation(summary = "邀请榜")
public R<List<RankNodeInvite>> inviteRank(
@Parameter(description = "类型 1-上周 2-昨日 3-日榜 4-周榜 5-月榜 6-总榜") Integer type){
if(type == null){
return R.ok(Collections.emptyList());
}
List<RankNode> rankNodeList;
if(type == 1){
rankNodeList = rankManager.getInviteRankDayLastWeek(10);
}else if(type == 2){
rankNodeList = rankManager.getInviteRankDayLastDay(10);
}else if(type == 3){
rankNodeList = rankManager.getInviteRankDayToday(30);
}else if(type == 4){
rankNodeList = rankManager.getInviteRankDayWeek(30);
}else if(type == 5){
rankNodeList = rankManager.getInviteRankDayMonth(30);
}else if(type == 6){
rankNodeList = rankManager.getInviteRankTotal(30);
}else{
rankNodeList = Collections.emptyList();
}
if(rankNodeList.isEmpty()){
return R.ok(Collections.emptyList());
}
List<RankNodeInvite> res = new ArrayList<>();
Set<Long> userIds = rankNodeList.stream().map(RankNode::getUserId).collect(Collectors.toSet());
List<User> userList = userService.listByIds(userIds);
Map<Long, User> userMap = userList.stream().collect(Collectors.toMap(User::getId, Function.identity()));
long lastLove = 0;
for (int i = 0; i < rankNodeList.size(); i++) {
RankNode rankNode = rankNodeList.get(i);
User user = userMap.get(rankNode.getUserId());
if(user == null){
continue;
}
RankNodeInvite invite = new RankNodeInvite();
invite.setAvatar(GenderEnum.WOMEN.getDefaultAvatar());
invite.setNickname(minNickname(user.getNickname()));
invite.setValue(rankNode.getScore());
if(i == 0){
invite.setDiffLastValue(0L);
}else{
invite.setDiffLastValue(lastLove - rankNode.getScore());
}
lastLove = rankNode.getScore();
res.add(invite);
}
return R.ok(res);
}
private static String minNickname(String nickname){
if(StringUtils.isEmpty(nickname)){
return "*";
}
return "*"+nickname.substring(nickname.length()-1);
}
}

View File

@@ -0,0 +1,19 @@
package com.ruoyi.cai.dto.app.vo.rank;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
@Data
public class RankNodeInvite {
@Schema(description = "头像")
private String avatar;
@Schema(description = "昵称")
private String nickname;
@Schema(description = "数值")
private Long value;
@Schema(description = "距离上一名差距")
private Long diffLastValue;
@Schema(description = "是否已经领取奖励(该字段仅限昨日榜单有用)")
private boolean draw = true;
}

View File

@@ -14,9 +14,11 @@ public class RankNodeLove {
@Schema(description = "昵称")
private String nickname;
@Schema(description = "魅力值")
private Long love;
@Schema(description = "距离上一个魅力值差距")
private Long diffLastLove;
private Long value;
@Schema(description = "距离上一差距")
private Long diffLastValue;
@Schema(description = "是否开启隐身模式")
private boolean hide;
@Schema(description = "是否已经领取奖励(该字段仅限昨日榜单有用)")
private boolean draw = true;
}