升级处理并优化
This commit is contained in:
parent
79d2132bd4
commit
55d827efd7
@ -1,5 +1,6 @@
|
|||||||
package com.red.circle.other.app.command.family;
|
package com.red.circle.other.app.command.family;
|
||||||
|
|
||||||
|
import cn.hutool.core.collection.CollectionUtil;
|
||||||
import com.red.circle.framework.core.asserts.ResponseAssert;
|
import com.red.circle.framework.core.asserts.ResponseAssert;
|
||||||
import com.red.circle.framework.core.response.CommonErrorCode;
|
import com.red.circle.framework.core.response.CommonErrorCode;
|
||||||
import com.red.circle.other.app.dto.clientobject.family.FamilyBaseInfoCO;
|
import com.red.circle.other.app.dto.clientobject.family.FamilyBaseInfoCO;
|
||||||
@ -21,13 +22,9 @@ import com.red.circle.other.infra.enums.family.FamilyStatusEnum;
|
|||||||
import com.red.circle.other.infra.enums.family.FamilyBoxConfigEnum;
|
import com.red.circle.other.infra.enums.family.FamilyBoxConfigEnum;
|
||||||
import com.red.circle.other.inner.model.dto.famliy.FamilyDetailsDTO;
|
import com.red.circle.other.inner.model.dto.famliy.FamilyDetailsDTO;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
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 java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
|
||||||
@ -108,6 +105,8 @@ public class FamilyBaseInfoExe {
|
|||||||
FamilyBaseInfoCO.FamilyMemberList memberList,
|
FamilyBaseInfoCO.FamilyMemberList memberList,
|
||||||
Boolean joinWaiting) {
|
Boolean joinWaiting) {
|
||||||
|
|
||||||
|
Map<Long, BigDecimal> decimalMap = familyLevelExpService.mapTotalExpCountByFamilyIds(new HashSet<>(Collections.singletonList(baseInfo.getId())));
|
||||||
|
|
||||||
return new FamilyBaseInfoCO()
|
return new FamilyBaseInfoCO()
|
||||||
.setFamilyId(baseInfo.getId())
|
.setFamilyId(baseInfo.getId())
|
||||||
.setFamilyAdmin(adminInfo)
|
.setFamilyAdmin(adminInfo)
|
||||||
@ -116,8 +115,7 @@ public class FamilyBaseInfoExe {
|
|||||||
.setFamilyName(baseInfo.getFamilyName())
|
.setFamilyName(baseInfo.getFamilyName())
|
||||||
.setFamilyNotice(baseInfo.getFamilyNotice())
|
.setFamilyNotice(baseInfo.getFamilyNotice())
|
||||||
.setFamilyIntro(baseInfo.getFamilyIntro())
|
.setFamilyIntro(baseInfo.getFamilyIntro())
|
||||||
.setCurrentExp(
|
.setCurrentExp(decimalMap.get(baseInfo.getId()).longValue())
|
||||||
familyLevelExpService.getExp(baseInfo.getId(), baseInfo.getFamilyLevelId()).longValue())
|
|
||||||
.setCurrentMember(getFamilyMemberCount(baseInfo.getId()))
|
.setCurrentMember(getFamilyMemberCount(baseInfo.getId()))
|
||||||
.setFamilyLevel(Optional.ofNullable(familyLevel.getLevel())
|
.setFamilyLevel(Optional.ofNullable(familyLevel.getLevel())
|
||||||
.orElse(0))
|
.orElse(0))
|
||||||
|
|||||||
@ -47,11 +47,7 @@ import com.red.circle.tool.core.json.JacksonUtils;
|
|||||||
import com.red.circle.tool.core.sequence.IdWorkerUtils;
|
import com.red.circle.tool.core.sequence.IdWorkerUtils;
|
||||||
import com.red.circle.tool.core.text.StringUtils;
|
import com.red.circle.tool.core.text.StringUtils;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.HashSet;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -236,60 +232,57 @@ public class FamilyCommon {
|
|||||||
|
|
||||||
long remainingExp = exp;
|
long remainingExp = exp;
|
||||||
FamilyDetailsDTO levelInfo = currentLevel;
|
FamilyDetailsDTO levelInfo = currentLevel;
|
||||||
|
|
||||||
|
// 先统计一次总经验(只统计一次)
|
||||||
|
expAccumulate(member, exp, regionId);
|
||||||
|
|
||||||
while (remainingExp > 0) {
|
while (remainingExp > 0) {
|
||||||
FamilyLevelConfig nextLevel = getNewLevel(sysOrigin, levelInfo);
|
FamilyLevelConfig nextLevel = getNewLevel(sysOrigin, levelInfo);
|
||||||
|
|
||||||
// 已经是满级,无法继续升级
|
|
||||||
if (Objects.isNull(nextLevel)) {
|
if (Objects.isNull(nextLevel)) {
|
||||||
addExpWithoutLevelUp(member, levelInfo, remainingExp, regionId);
|
// 满级了,剩余经验全部加到当前等级
|
||||||
|
familyLevelExpService.incrExp(member.getFamilyId(),
|
||||||
|
levelInfo.getFamilyLevelId(), BigDecimal.valueOf(remainingExp));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
long currentLevelCompleteExp = levelInfo.getLevelExp(); // 当前等级满级所需总经验
|
long currentLevelCompleteExp = levelInfo.getLevelExp();
|
||||||
long currentFamilyExp = familyLevelExpService.getExp(levelInfo.getFamilyId(),
|
long currentFamilyExp = familyLevelExpService.mapTotalExpCountByFamilyIds(new HashSet<>(Collections.singletonList(levelInfo.getFamilyId())))
|
||||||
levelInfo.getFamilyLevelId()).longValue(); // 当前已有经验
|
.getOrDefault(levelInfo.getFamilyId(), BigDecimal.ZERO).longValue();
|
||||||
long expNeeded = currentLevelCompleteExp - currentFamilyExp; // 还需要多少经验才能升级
|
long expNeeded = currentLevelCompleteExp - currentFamilyExp;
|
||||||
|
|
||||||
// 经验不足以升级,只增加经验不升级
|
|
||||||
if (remainingExp < expNeeded) {
|
if (remainingExp < expNeeded) {
|
||||||
addExpWithoutLevelUp(member, levelInfo, remainingExp, regionId);
|
// 经验不足以升级,全部加到当前等级
|
||||||
|
familyLevelExpService.incrExp(member.getFamilyId(),
|
||||||
|
levelInfo.getFamilyLevelId(), BigDecimal.valueOf(remainingExp));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 经验足够升级:先增加升级所需的经验,然后执行升级
|
// 经验足够升级
|
||||||
addExpWithoutLevelUp(member, levelInfo, expNeeded, regionId);
|
// 1. 把当前等级加满
|
||||||
updateFamily(member, nextLevel);
|
if (expNeeded > 0) {
|
||||||
|
familyLevelExpService.incrExp(member.getFamilyId(),
|
||||||
|
levelInfo.getFamilyLevelId(), BigDecimal.valueOf(expNeeded));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 升级
|
||||||
|
familyLevelUp(member, nextLevel);
|
||||||
|
|
||||||
|
// 3. 剩余经验进入下一轮循环
|
||||||
remainingExp -= expNeeded;
|
remainingExp -= expNeeded;
|
||||||
|
|
||||||
// 重新获取升级后的等级信息
|
// 4. 初始化新等级经验记录(如果有剩余经验,在下一轮循环会加上)
|
||||||
|
if (remainingExp > 0) {
|
||||||
|
familyLevelExpService.incrExp(member.getFamilyId(),
|
||||||
|
nextLevel.getId(), BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 5. 刷新等级信息
|
||||||
levelInfo = getFamilyDetails(sysOrigin, member.getFamilyId());
|
levelInfo = getFamilyDetails(sysOrigin, member.getFamilyId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 增加经验值但不升级
|
|
||||||
*/
|
|
||||||
private void addExpWithoutLevelUp(FamilyMemberInfo member, FamilyDetailsDTO currentLevel, Long exp, String regionId) {
|
|
||||||
addFamilyExpIncreaseRecord(exp, member, currentLevel.getFamilyLevelId());
|
|
||||||
expAccumulate(member, exp, regionId);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 更新家族
|
|
||||||
*
|
|
||||||
* @param member 成员
|
|
||||||
* @param newLevel 新等级
|
|
||||||
*/
|
|
||||||
private void updateFamily(FamilyMemberInfo member, FamilyLevelConfig newLevel) {
|
|
||||||
|
|
||||||
// 家族升级
|
|
||||||
familyLevelUp(member, newLevel);
|
|
||||||
|
|
||||||
// 更新家族等级缓存数据
|
|
||||||
// cacheFamilyLevel(member.getSysOrigin() + member.getFamilyId(), newLevel, member.getFamilyId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 移除家族所有人的头饰与徽章.
|
* 移除家族所有人的头饰与徽章.
|
||||||
@ -429,16 +422,7 @@ public class FamilyCommon {
|
|||||||
return Lists.newArrayList(userIds);
|
return Lists.newArrayList(userIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 家族成员增加经验值记录
|
|
||||||
*
|
|
||||||
* @param exp 经验值
|
|
||||||
* @param member 成员对象
|
|
||||||
* @param levelId 等级ID
|
|
||||||
*/
|
|
||||||
private void addFamilyExpIncreaseRecord(Long exp, FamilyMemberInfo member, Long levelId) {
|
|
||||||
familyLevelExpService.incrExp(member.getFamilyId(), levelId, BigDecimal.valueOf(exp));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 累加经验值(家族成员总榜、家族周榜、家族成员周经验值)
|
* 累加经验值(家族成员总榜、家族周榜、家族成员周经验值)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user