diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLevelListExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLevelListExe.java index c55478c5..8afaecfc 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLevelListExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/family/FamilyLevelListExe.java @@ -4,8 +4,12 @@ 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.infra.database.rds.entity.family.FamilyBaseInfo; import com.red.circle.other.infra.database.rds.entity.family.FamilyLevelConfig; +import com.red.circle.other.infra.database.rds.entity.family.FamilyMemberInfo; +import com.red.circle.other.infra.database.rds.service.family.FamilyBaseInfoService; import com.red.circle.other.infra.database.rds.service.family.FamilyLevelConfigService; +import com.red.circle.other.infra.database.rds.service.family.FamilyMemberInfoService; import com.red.circle.tool.core.collection.CollectionUtils; import java.util.Comparator; import java.util.List; @@ -21,6 +25,8 @@ import org.springframework.stereotype.Component; public class FamilyLevelListExe { private final FamilyLevelConfigService familyLevelConfigService; + private final FamilyMemberInfoService familyMemberInfoService; + private final FamilyBaseInfoService familyBaseInfoService; public List execute(AppExtCommand cmd) { List levelConfigs = familyLevelConfigService @@ -29,16 +35,45 @@ public class FamilyLevelListExe { ResponseAssert.isFalse(CommonErrorCode.NOT_FOUND_RECORD_INFO, CollectionUtils.isEmpty(levelConfigs)); + // 获取用户当前家族等级 + Long currentFamilyLevelId = getCurrentFamilyLevelId(cmd.getReqUserId()); + return levelConfigs.stream() - .map(this::convertToLevelCO) + .map(config -> convertToLevelCO(config, currentFamilyLevelId)) .sorted(Comparator.comparing(FamilyLevelCO::getSort)) .collect(Collectors.toList()); } - private FamilyLevelCO convertToLevelCO(FamilyLevelConfig config) { + /** + * 获取用户当前家族等级id + */ + private Long getCurrentFamilyLevelId(Long userId) { + FamilyMemberInfo familyMemberInfo = familyMemberInfoService.getFamilyMemberByUserId(userId); + if (familyMemberInfo == null) { + return null; + } + + FamilyBaseInfo familyBaseInfo = familyBaseInfoService.getBaseInfoById(familyMemberInfo.getFamilyId()); + if (familyBaseInfo == null) { + return 1L; + } + + return familyBaseInfo.getFamilyLevelId(); + } + + /** + * 转换为LevelCO,如果等级大于当前家族等级Id,则levelExp设置为null + */ + private FamilyLevelCO convertToLevelCO(FamilyLevelConfig config, Long currentFamilyLevelId) { + // 如果用户有家族,且配置等级大于当前家族等级,则levelExp设置为null + Integer levelExp = config.getLevelExp(); + if (currentFamilyLevelId != null && config.getId() > currentFamilyLevelId) { + levelExp = null; + } + return new FamilyLevelCO() .setLevel(config.getLevelKey().substring(6)) - .setLevelExp(config.getLevelExp()) + .setLevelExp(levelExp) .setMaxMember(config.getMaxMember()) .setMaxManager(config.getMaxManager()) .setLevelBackgroundPicture(config.getLevelBackgroundPicture())