新增荣誉徽章类型

This commit is contained in:
tianfeng 2025-11-19 19:21:34 +08:00
parent 0e668d8dfc
commit 69eae095fb
8 changed files with 208 additions and 10 deletions

View File

@ -25,6 +25,16 @@ public enum SysBadgeConfigTypeEnum {
*/
ACTIVITY("ACTIVITY", "用户-活动"),
/**
* 荣誉活动.
*/
HONOR_ACTIVITY("HONOR_ACTIVITY", "荣誉-活动"),
/**
* 荣誉成就.
*/
HONOR_ACHIEVEMENT("HONOR_ACHIEVEMENT", "荣誉-成就"),
/**
* 家族-徽章.
*/
@ -35,6 +45,10 @@ public enum SysBadgeConfigTypeEnum {
*/
ROOM_ACHIEVEMENT("ROOM_ACHIEVEMENT", "房间-成就");
public static boolean isHonorType(String name) {
return name != null && name.startsWith("HONOR");
}
private final String desc;
private final String name;

View File

@ -0,0 +1,83 @@
package com.red.circle.other.inner.model.dto.material;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import lombok.Data;
import java.io.Serial;
import java.io.Serializable;
/**
* 用户的徽章.
*/
@Data
public class UseOwnBadgeDTO implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键标识.
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long id;
/**
* 用户id.
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long userId;
/**
* 徽章等级.
*/
private Integer badgeLevel;
/**
* 徽章可领取里程碑.
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long milestone;
/**
* 徽章名称.
*/
private String badgeName;
/**
* 徽章类型.
*/
private String type;
/**
* 徽章key.
*/
private String badgeKey;
/**
* 选中url.
*/
private String selectUrl;
/**
* 没有选中的url.
*/
private String notSelectUrl;
/**
* 动画链接.
*/
private String animationUrl;
/**
* 过期时间.
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long expireTime;
/**
* 是否佩戴
*/
private Boolean use;
}

View File

@ -7,14 +7,13 @@ import com.red.circle.other.app.dto.cmd.user.material.UserToggleBadgeCmd;
import com.red.circle.other.app.service.user.material.UserBadgeService;
import com.red.circle.other.inner.model.dto.material.BadgeConfigDetailsDTO;
import java.util.List;
import com.red.circle.other.inner.model.dto.material.UseBadgeDTO;
import com.red.circle.other.inner.model.dto.material.UseOwnBadgeDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
* 用户徽章.
@ -57,7 +56,16 @@ public class UserBadgeRestController extends BaseController {
return userBadgeService.useWearBadge(cmd);
}
/**
/**
* 拥有的徽章徽章.
*
*/
@GetMapping("/own/list")
public List<UseOwnBadgeDTO> ownedBadge(AppExtCommand cmd, @RequestParam("type") String type) {
return userBadgeService.ownedBadge(cmd, type);
}
/**
* 切换单个徽章佩戴状态.
*
* @eo.name 切换单个徽章佩戴状态.

View File

@ -49,6 +49,7 @@ public class UserToggleBadgeCmdExe {
// 查询当前已佩戴的徽章
LambdaQueryWrapper<BadgeBackpack> eq = Wrappers.lambdaQuery(BadgeBackpack.class)
.eq(BadgeBackpack::getUserId, userId)
.in(BadgeBackpack::getExpireType)
.eq(BadgeBackpack::getUseProps, Boolean.TRUE);
List<BadgeBackpack> currentWearBadges = badgeBackpackService.list(eq);

View File

@ -0,0 +1,81 @@
package com.red.circle.other.app.command.user.query;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.common.collect.Lists;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.infra.common.props.UserBadgeCommon;
import com.red.circle.other.infra.database.rds.entity.badge.BadgeBackpack;
import com.red.circle.other.infra.database.rds.service.badge.BadgeBackpackService;
import com.red.circle.other.infra.database.rds.service.badge.BadgeConfigService;
import com.red.circle.other.inner.enums.sys.SysBadgeConfigTypeEnum;
import com.red.circle.other.inner.model.dto.material.BadgeConfigDetailsDTO;
import com.red.circle.other.inner.model.dto.material.UseBadgeDTO;
import com.red.circle.other.inner.model.dto.material.UseOwnBadgeDTO;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.date.TimestampUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import java.util.*;
import java.util.stream.Collectors;
/**
* 用户拥有的勋章.
*/
@Service
@RequiredArgsConstructor
public class UseOwnedBadgeQryExe {
private final UserProfileGateway userProfileGateway;
private final UserBadgeCommon userBadgeCommon;
private final BadgeBackpackService badgeBackpackService;
public List<UseOwnBadgeDTO> execute(AppExtCommand cmd, String type) {
UserProfile userProfile = userProfileGateway.getByUserId(cmd.getReqUserId());
// 查询用户所有未过期的徽章
LambdaQueryWrapper<BadgeBackpack> eq = Wrappers.lambdaQuery(BadgeBackpack.class)
.eq(BadgeBackpack::getUserId, userProfile.getId())
.ge(BadgeBackpack::getExpireTime, TimestampUtils.now());
List<BadgeBackpack> badgeBackpacks = badgeBackpackService.list(eq);
Set<Long> badgeIdSet = badgeBackpacks.stream()
.map(BadgeBackpack::getBadgeId)
.collect(Collectors.toSet());
// 构建 badgeId -> useProps 映射
Map<Long, Boolean> badgeUseMap = badgeBackpacks.stream()
.collect(Collectors.toMap(BadgeBackpack::getBadgeId, BadgeBackpack::getUseProps, (v1, v2) -> v1));
List<UseBadgeDTO> useBadgeDTOS = userBadgeCommon.listUseBadge(
userProfile.getId(),
userProfile.getOriginSys(),
badgeIdSet
);
// 转换并赋值 use 字段
List<UseOwnBadgeDTO> useOwnBadgeDTOS = useBadgeDTOS.stream()
.map(useBadgeDTO -> {
UseOwnBadgeDTO useOwnBadgeDTO = new UseOwnBadgeDTO();
BeanUtils.copyProperties(useBadgeDTO, useOwnBadgeDTO);
useOwnBadgeDTO.setUse(badgeUseMap.getOrDefault(useBadgeDTO.getId(), Boolean.FALSE));
return useOwnBadgeDTO;
})
.toList();
if ("HONOR".equals(type)) {
return useOwnBadgeDTOS.stream()
.filter(e -> SysBadgeConfigTypeEnum.isHonorType(e.getType()))
.toList();
}
return useOwnBadgeDTOS.stream()
.filter(e -> !SysBadgeConfigTypeEnum.isHonorType(e.getType()))
.toList();
}
}

View File

@ -1,6 +1,7 @@
package com.red.circle.other.app.service.user.material;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.command.user.query.UseOwnedBadgeQryExe;
import com.red.circle.other.inner.model.dto.material.BadgeConfigDetailsDTO;
import com.red.circle.other.app.command.user.UserSwitchBadgeCmdExe;
import com.red.circle.other.app.command.user.UserToggleBadgeCmdExe;
@ -8,6 +9,8 @@ import com.red.circle.other.app.command.user.query.UseWearBadgeQryExe;
import com.red.circle.other.app.dto.cmd.user.material.UserSwitchBadgeCmd;
import com.red.circle.other.app.dto.cmd.user.material.UserToggleBadgeCmd;
import java.util.List;
import com.red.circle.other.inner.model.dto.material.UseOwnBadgeDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
@ -23,6 +26,7 @@ public class UserBadgeServiceImpl implements UserBadgeService {
private final UseWearBadgeQryExe useWearBadgeQryExe;
private final UserSwitchBadgeCmdExe userSwitchBadgeCmdExe;
private final UserToggleBadgeCmdExe userToggleBadgeCmdExe;
private final UseOwnedBadgeQryExe useOwnedBadgeQryExe;
@Override
public void switchBadge(UserSwitchBadgeCmd cmd) {
@ -34,7 +38,12 @@ public class UserBadgeServiceImpl implements UserBadgeService {
return useWearBadgeQryExe.execute(cmd);
}
@Override
@Override
public List<UseOwnBadgeDTO> ownedBadge(AppExtCommand cmd, String type) {
return useOwnedBadgeQryExe.execute(cmd, type);
}
@Override
public void toggleBadge(UserToggleBadgeCmd cmd) {
userToggleBadgeCmdExe.execute(cmd);
}

View File

@ -4,6 +4,8 @@ import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.other.app.dto.cmd.user.material.UserSwitchBadgeCmd;
import com.red.circle.other.app.dto.cmd.user.material.UserToggleBadgeCmd;
import com.red.circle.other.inner.model.dto.material.BadgeConfigDetailsDTO;
import com.red.circle.other.inner.model.dto.material.UseOwnBadgeDTO;
import java.util.List;
/**
@ -17,6 +19,8 @@ public interface UserBadgeService {
List<BadgeConfigDetailsDTO> useWearBadge(AppExtCommand cmd);
List<UseOwnBadgeDTO> ownedBadge(AppExtCommand cmd, String type);
void toggleBadge(UserToggleBadgeCmd cmd);
}

View File

@ -148,9 +148,7 @@ public class BadgeBackpackServiceImpl extends
}
return Optional.ofNullable(query()
.eq(BadgeBackpack::getUserId, userId)
.in(badgeIds.size() > 1, BadgeBackpack::getBadgeId, badgeIds)
.eq(Objects.equals(badgeIds.size(), 1), BadgeBackpack::getBadgeId,
badgeIds.iterator().next())
.in(BadgeBackpack::getBadgeId, badgeIds)
.list())
.map(badgeBackpacks -> badgeBackpacks.stream().filter(this::filterAvailable)
.collect(Collectors.toList()))