家族等级列表接口新增

This commit is contained in:
tianfeng 2025-12-24 17:43:19 +08:00
parent a6f3a6cf5b
commit 7c16c483fa
5 changed files with 21 additions and 187 deletions

View File

@ -42,14 +42,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 家族服务 前端控制器.
* </p>
*
* @author lisizhe on 2023/9/19
* @eo.api-type http
* @eo.groupName 家族服务
* @eo.path /family
* 家族管理
*/
@RequiredArgsConstructor
@RestController
@ -169,15 +162,10 @@ public class FamilyRestController extends BaseController {
}
/**
* 全部等级配置集合.
*
* @eo.name 全部等级配置集合.
* @eo.url /list/level-config
* @eo.method get
* @eo.request-type formdata
* 家族等级配置
*/
// @GetMapping("/list/level-config")
public List<FamilyLevelParentCacheCO> listLevelConfig(AppExtCommand cmd) {
@GetMapping("/list/level-config")
public List<FamilyLevelCO> listLevelConfig(AppExtCommand cmd) {
return familyService.listLevelConfig(cmd);
}

View File

@ -1,201 +1,47 @@
package com.red.circle.other.app.command.family;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.red.circle.common.business.dto.cmd.AppExtCommand;
import com.red.circle.framework.core.asserts.ResponseAssert;
import com.red.circle.framework.core.response.CommonErrorCode;
import com.red.circle.other.app.dto.clientobject.family.FamilyLevelCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyLevelParentCacheCO;
import com.red.circle.other.infra.database.cache.service.other.FamilyLevelCacheService;
import com.red.circle.other.infra.database.rds.entity.badge.BadgePictureConfig;
import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig;
import com.red.circle.other.infra.database.rds.entity.gift.GiftConfig;
import com.red.circle.other.infra.database.rds.entity.props.PropsSourceRecord;
import com.red.circle.other.infra.database.rds.service.badge.BadgePictureConfigService;
import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService;
import com.red.circle.other.infra.database.rds.service.gift.GiftConfigService;
import com.red.circle.other.infra.database.rds.service.props.PropsSourceRecordService;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.json.JacksonUtils;
import com.red.circle.tool.core.text.StringUtils;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
/**
* <p>
* 全部等级配置集合.
* </p>
*
* @author pengshigang
* @since 2021-07-20
* 家族等级列表.
*/
@Component
@RequiredArgsConstructor
public class FamilyLevelListExe {
private final GiftConfigService giftConfigService;
private final FamilyLevelCacheService familyLevelCacheService;
private final PropsSourceRecordService propsSourceRecordService;
private final FamilyLevelConfigService familyLevelConfigService;
private final BadgePictureConfigService badgePictureConfigService;
private final Map<String, Integer> familyLevelSortMapping = new HashMap<>() {{
put("BLACK_IRON", 0);
put("BRONZE", 1);
put("SILVER", 2);
put("GOLD", 3);
put("PLATINUM", 4);
}};
public List<FamilyLevelParentCacheCO> execute(AppExtCommand cmd) {
String jsonStr = getCacheFamilyLevelParent(cmd);
if (StringUtils.isBlank(jsonStr)) {
List<FamilyLevelParentCacheCO> parents = getLevelCO(getLevelConfigs(cmd), cmd);
familyLevelCache(cmd, parents);
return parents;
}
return Optional
.ofNullable(JacksonUtils
.readValue(jsonStr, new TypeReference<List<FamilyLevelParentCacheCO>>() {
}))
.orElse(Lists.newArrayList());
}
private String getCacheFamilyLevelParent(AppExtCommand cmd) {
return familyLevelCacheService.getFamilyLevelParent(cmd.getReqSysOrigin().getOrigin());
}
private void familyLevelCache(AppExtCommand cmd, List<FamilyLevelParentCacheCO> parents) {
familyLevelCacheService.setFamilyLevelParent(
cmd.getReqSysOrigin().getOrigin(), JacksonUtils.toJson(parents));
}
private List<FamilyLevelParentCacheCO> getLevelCO(List<FamilyLevelConfig> levelConfigs,
AppExtCommand cmd) {
Map<Long, PropsSourceRecord> mapProp = mapProp(levelConfigs);
Map<Long, GiftConfig> mapGift = mapGift(levelConfigs);
Map<Long, BadgePictureConfig> mapBadge = mapBadge(cmd.getReqSysOrigin().getOrigin(),
levelConfigs);
List<FamilyLevelCO> levelList = levelConfigs.stream().map(
familyLevelConfig -> setFamilyLevelCO(mapProp, mapBadge, mapGift, familyLevelConfig,
getBuild(familyLevelConfig))).collect(Collectors.toList());
if (CollectionUtils.isEmpty(levelList)) {
return Lists.newArrayList();
}
List<FamilyLevelParentCacheCO> levelParents = Lists.newArrayList();
getStringListMap(levelList).forEach((k, list) ->
levelParents.add(new FamilyLevelParentCacheCO()
.setLevelType(k)
.setSort(Optional.ofNullable(familyLevelSortMapping.get(k)).orElse(1000))
.setLevel(list)
)
);
return levelParents.stream().sorted(Comparator.comparing(FamilyLevelParentCacheCO::getSort))
.collect(Collectors.toList());
}
private Map<String, List<FamilyLevelCO>> getStringListMap(List<FamilyLevelCO> levelList) {
return levelList.stream().collect(Collectors.groupingBy(FamilyLevelCO::getLevelType));
}
private FamilyLevelCO setFamilyLevelCO(Map<Long, PropsSourceRecord> mapProp,
Map<Long, BadgePictureConfig> mapBadge,
Map<Long, GiftConfig> mapGift,
FamilyLevelConfig familyLevelConfig, FamilyLevelCO levelCO) {
PropsSourceRecord avatarFrame = mapProp.get(familyLevelConfig.getAvatarFrameId());
BadgePictureConfig badge = mapBadge.get(familyLevelConfig.getBadgeId());
GiftConfig gift = mapGift.get(familyLevelConfig.getGiftId());
levelCO.setLevelType(familyLevelConfig.getLevelType());
if (Objects.nonNull(avatarFrame)) {
levelCO.setAvatarFrameCover(avatarFrame.getCover());
levelCO.setAvatarFrameSvg(avatarFrame.getSourceUrl());
}
if (Objects.nonNull(badge)) {
levelCO.setBadgeCover(badge.getSelectUrl());
levelCO.setBadgeSvg(badge.getAnimationUrl());
}
if (Objects.nonNull(gift)) {
levelCO.setGiftCover(gift.getGiftPhoto());
levelCO.setGiftSvg(gift.getGiftSourceUrl());
}
levelCO.setSort(familyLevelConfig.getSort());
return levelCO;
}
private List<FamilyLevelConfig> getLevelConfigs(AppExtCommand cmd) {
public List<FamilyLevelCO> execute(AppExtCommand cmd) {
List<FamilyLevelConfig> levelConfigs = familyLevelConfigService
.listLevelConfig(cmd.getReqSysOrigin().getOrigin());
ResponseAssert.isFalse(CommonErrorCode.NOT_FOUND_RECORD_INFO,
CollectionUtils.isEmpty(levelConfigs));
return levelConfigs;
return levelConfigs.stream()
.map(this::convertToLevelCO)
.sorted(Comparator.comparing(FamilyLevelCO::getSort))
.collect(Collectors.toList());
}
private Map<Long, GiftConfig> mapGift(List<FamilyLevelConfig> levelConfigs) {
if (CollectionUtils.isEmpty(levelConfigs)) {
return Maps.newHashMap();
}
return giftConfigService.mapByIds(getGiftIds(levelConfigs));
}
private Set<Long> getGiftIds(List<FamilyLevelConfig> levelConfigs) {
return levelConfigs.stream().map(FamilyLevelConfig::getGiftId).collect(Collectors.toSet());
}
private Map<Long, PropsSourceRecord> mapProp(List<FamilyLevelConfig> levelConfigs) {
if (CollectionUtils.isEmpty(levelConfigs)) {
return Maps.newHashMap();
}
return propsSourceRecordService
.mapByIds(levelConfigs.stream().map(FamilyLevelConfig::getAvatarFrameId).collect(
Collectors.toSet()));
}
private Map<Long, BadgePictureConfig> mapBadge(String sysOrigin,
List<FamilyLevelConfig> levelConfigs) {
if (CollectionUtils.isEmpty(levelConfigs)) {
return Maps.newHashMap();
}
return badgePictureConfigService
.mapBadge(sysOrigin, levelConfigs.stream().map(FamilyLevelConfig::getBadgeId).collect(
Collectors.toSet()));
}
private FamilyLevelCO getBuild(FamilyLevelConfig familyLevelConfig) {
private FamilyLevelCO convertToLevelCO(FamilyLevelConfig config) {
return new FamilyLevelCO()
.setLevelKey(familyLevelConfig.getLevelKey())
.setLevelExp(familyLevelConfig.getLevelExp())
.setMaxMember(familyLevelConfig.getMaxMember())
.setMaxManager(familyLevelConfig.getMaxManager())
.setLevelBackgroundPicture(familyLevelConfig.getLevelBackgroundPicture());
.setLevelKey(config.getLevelKey())
.setLevelExp(config.getLevelExp())
.setMaxMember(config.getMaxMember())
.setMaxManager(config.getMaxManager())
.setLevelBackgroundPicture(config.getLevelBackgroundPicture())
.setSort(config.getSort());
}
}

View File

@ -34,7 +34,7 @@ import com.red.circle.other.app.command.family.FamilyBoxClaimExe;
import com.red.circle.other.app.dto.clientobject.family.FamilyBaseInfoCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyCreateRulesCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyLeaderboardCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyLevelParentCacheCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyLevelCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyListCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyMemberCO;
import com.red.circle.other.app.dto.clientobject.family.FamilyMsgListCO;
@ -165,7 +165,7 @@ public class FamilyServiceImpl implements FamilyService {
}
@Override
public List<FamilyLevelParentCacheCO> listLevelConfig(AppExtCommand cmd) {
public List<FamilyLevelCO> listLevelConfig(AppExtCommand cmd) {
return familyLevelListExe.execute(cmd);
}

View File

@ -22,7 +22,7 @@ public class FamilyLevelParentCacheCO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 等级类型(BLACK_IRON.黑铁 BRONZE.青铜 SILVER.白银 GOLD.黄金 PLATINUM.铂金).
*
*/
private String levelType;

View File

@ -59,7 +59,7 @@ public interface FamilyService {
/**
* 全部等级配置集合.
*/
List<FamilyLevelParentCacheCO> listLevelConfig(AppExtCommand cmd);
List<FamilyLevelCO> listLevelConfig(AppExtCommand cmd);
/**
* 家族消息处理.