diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/sys/SysBadgeConfigTypeEnum.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/sys/SysBadgeConfigTypeEnum.java index 71abe825..5c714b19 100644 --- a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/sys/SysBadgeConfigTypeEnum.java +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/enums/sys/SysBadgeConfigTypeEnum.java @@ -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; diff --git a/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/material/UseOwnBadgeDTO.java b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/material/UseOwnBadgeDTO.java new file mode 100644 index 00000000..e5611b21 --- /dev/null +++ b/rc-service/rc-inner-api/other-inner/other-inner-model/src/main/java/com/red/circle/other/inner/model/dto/material/UseOwnBadgeDTO.java @@ -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; + +} diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/material/UserBadgeRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/material/UserBadgeRestController.java index 99fc065d..9bcb0c20 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/material/UserBadgeRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/user/material/UserBadgeRestController.java @@ -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 ownedBadge(AppExtCommand cmd, @RequestParam("type") String type) { + return userBadgeService.ownedBadge(cmd, type); + } + + /** * 切换单个徽章佩戴状态. * * @eo.name 切换单个徽章佩戴状态. diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserToggleBadgeCmdExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserToggleBadgeCmdExe.java index 48dfffaa..389f9270 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserToggleBadgeCmdExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/UserToggleBadgeCmdExe.java @@ -49,6 +49,7 @@ public class UserToggleBadgeCmdExe { // 查询当前已佩戴的徽章 LambdaQueryWrapper eq = Wrappers.lambdaQuery(BadgeBackpack.class) .eq(BadgeBackpack::getUserId, userId) + .in(BadgeBackpack::getExpireType) .eq(BadgeBackpack::getUseProps, Boolean.TRUE); List currentWearBadges = badgeBackpackService.list(eq); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UseOwnedBadgeQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UseOwnedBadgeQryExe.java new file mode 100644 index 00000000..7b59a650 --- /dev/null +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/user/query/UseOwnedBadgeQryExe.java @@ -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 execute(AppExtCommand cmd, String type) { + UserProfile userProfile = userProfileGateway.getByUserId(cmd.getReqUserId()); + + // 查询用户所有未过期的徽章 + LambdaQueryWrapper eq = Wrappers.lambdaQuery(BadgeBackpack.class) + .eq(BadgeBackpack::getUserId, userProfile.getId()) + .ge(BadgeBackpack::getExpireTime, TimestampUtils.now()); + List badgeBackpacks = badgeBackpackService.list(eq); + + Set badgeIdSet = badgeBackpacks.stream() + .map(BadgeBackpack::getBadgeId) + .collect(Collectors.toSet()); + + // 构建 badgeId -> useProps 映射 + Map badgeUseMap = badgeBackpacks.stream() + .collect(Collectors.toMap(BadgeBackpack::getBadgeId, BadgeBackpack::getUseProps, (v1, v2) -> v1)); + + List useBadgeDTOS = userBadgeCommon.listUseBadge( + userProfile.getId(), + userProfile.getOriginSys(), + badgeIdSet + ); + + // 转换并赋值 use 字段 + List 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(); + } +} diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeServiceImpl.java index 7b660c7d..b3034692 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeServiceImpl.java @@ -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 ownedBadge(AppExtCommand cmd, String type) { + return useOwnedBadgeQryExe.execute(cmd, type); + } + + @Override public void toggleBadge(UserToggleBadgeCmd cmd) { userToggleBadgeCmdExe.execute(cmd); } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeService.java index 05bdac05..6e18664f 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/user/material/UserBadgeService.java @@ -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 useWearBadge(AppExtCommand cmd); + List ownedBadge(AppExtCommand cmd, String type); + void toggleBadge(UserToggleBadgeCmd cmd); } diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/badge/impl/BadgeBackpackServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/badge/impl/BadgeBackpackServiceImpl.java index 945d292b..92f1179a 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/badge/impl/BadgeBackpackServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/rds/service/badge/impl/BadgeBackpackServiceImpl.java @@ -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()))