工资结算增加溢出值处理

This commit is contained in:
tianfeng 2025-11-26 17:05:39 +08:00
parent c94d2e57fa
commit 1bd5c0dc33
3 changed files with 118 additions and 11 deletions

View File

@ -43,6 +43,11 @@ public class TeamMemberTargetIndex implements Serializable {
@JsonSerialize(using = ToStringSerializer.class)
private Long acceptGiftValue;
/**
* 溢出值
*/
private Long overFlowGiftValue;
/**
* 送出等礼物.
*/

View File

@ -226,16 +226,6 @@ public class TeamBillSettleListener implements MessageListener {
return teamMemberTargets;
}
private List<TeamBillMemberTarget> calculatorTarget(List<TeamMemberTarget> teamMemberTargets,
TeamPolicyManager regionPolicyManager) {
//2fun新增钻石政策
if (Objects.isNull(regionPolicyManager.getPolicyType()) || Objects.equals("MONEY", regionPolicyManager.getPolicyType())) {
return TeamBillCycleUtils.calculatorPolicyTarget(teamMemberTargets, regionPolicyManager);
}
return TeamBillCycleUtils.calculatorPolicyDiamondTarget(teamMemberTargets, regionPolicyManager);
}
private Map<String, String> getMetadata(SysRegionConfig regionConfig) {
return Optional.ofNullable(regionConfig)
.map(SysRegionConfig::getMetadata).orElseGet(CollectionUtils::newHashMap);

View File

@ -11,6 +11,7 @@ import com.red.circle.other.infra.database.mongo.entity.team.team.TeamPolicyMana
import com.red.circle.other.infra.database.mongo.entity.user.region.SysRegionConfig;
import com.red.circle.other.infra.database.rds.entity.team.BillDiamondBalance;
import com.red.circle.other.inner.enums.team.TeamMemberTargetIndex;
import com.red.circle.other.inner.enums.team.TeamMemberTargetStatus;
import com.red.circle.tool.core.collection.CollectionUtils;
import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils;
import com.red.circle.tool.core.num.NumUtils;
@ -20,6 +21,7 @@ import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.sql.Timestamp;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
@ -191,7 +193,13 @@ public final class TeamBillCycleUtils {
.collect(Collectors.toList())
: Lists.newArrayList();
return targets.stream().map(target -> {
// 计算上月溢出值并应用到当前月
Map<Long, Long> userOverflowMap = calculateLastMonthOverflow(targets, teamPolicies);
applyOverflowToCurrentMonth(targets, userOverflowMap);
return targets.stream()
.filter(target -> !Boolean.TRUE.equals(target.getHistory()))
.map(target -> {
long targetTimeHours = target.sumAllTargetTime() / 60;
Long acceptGiftValue = target.sumAcceptGiftValue();
Integer effectiveDay = calculateEffectiveDay(target);
@ -238,6 +246,110 @@ public final class TeamBillCycleUtils {
}).filter(Objects::nonNull).collect(Collectors.toList());
}
/**
* 计算上月溢出值.
*/
private static Map<Long, Long> calculateLastMonthOverflow(List<TeamMemberTarget> targets,
List<TeamPolicy> teamPolicies) {
Map<Long, Long> userOverflowMap = new HashMap<>();
// 按用户分组
Map<Long, List<TeamMemberTarget>> userTargetMap = targets.stream()
.collect(Collectors.groupingBy(TeamMemberTarget::getUserId));
userTargetMap.forEach((userId, userTargets) -> {
// 找到所有上月历史已结算数据 (history = true)
List<TeamMemberTarget> historyTargets = userTargets.stream()
.filter(t -> Boolean.TRUE.equals(t.getHistory()))
.collect(Collectors.toList());
if (CollectionUtils.isNotEmpty(historyTargets)) {
// 汇总所有历史记录的 acceptGiftValue
Long totalAcceptGiftValue = historyTargets.stream()
.map(TeamMemberTarget::sumAcceptGiftValue)
.filter(Objects::nonNull)
.reduce(0L, Long::sum);
// 查找该用户达到的最大等级目标值
Long levelTargetValue = findLevelTargetValue(totalAcceptGiftValue, teamPolicies);
// 计算溢出部分
long overflow = totalAcceptGiftValue - levelTargetValue;
if (overflow > 0) {
userOverflowMap.put(userId, overflow);
}
}
});
return userOverflowMap;
}
/**
* 根据总收礼物值查找达到的等级目标值.
*
* @param totalAcceptGiftValue 总收礼物值
* @param teamPolicies 团队政策列表(已按level倒序排序)
* @return 达到的等级目标值
*/
private static Long findLevelTargetValue(Long totalAcceptGiftValue, List<TeamPolicy> teamPolicies) {
if (totalAcceptGiftValue == null || totalAcceptGiftValue <= 0) {
return 0L;
}
for (TeamPolicy teamPolicy : teamPolicies) {
if (totalAcceptGiftValue >= teamPolicy.getTarget()) {
return teamPolicy.getTarget();
}
}
return 0L;
}
/**
* 将上月溢出值应用到当前月数据并持久化.
*
* @param targets 目标数据列表
* @param userOverflowMap 用户溢出值映射
*/
private static void applyOverflowToCurrentMonth(List<TeamMemberTarget> targets,
Map<Long, Long> userOverflowMap) {
if (userOverflowMap.isEmpty()) {
return;
}
targets.stream()
.filter(target -> !Boolean.TRUE.equals(target.getHistory()))
.filter(target -> userOverflowMap.containsKey(target.getUserId()))
.forEach(target -> {
Long overflow = userOverflowMap.get(target.getUserId());
// 获取dailyTargets列表
List<TeamMemberTargetIndex> dailyTargets = target.getDailyTargets();
if (CollectionUtils.isNotEmpty(dailyTargets)) {
// 获取最后一个元素
TeamMemberTargetIndex lastTarget = dailyTargets.get(dailyTargets.size() - 1);
// 设置溢出值
lastTarget.setOverFlowGiftValue(overflow);
lastTarget.setAcceptGiftValue(lastTarget.getAcceptGiftValue() + overflow);
lastTarget.setUpdateTime(new Timestamp(System.currentTimeMillis()));
}
// 添加备注
if (target.getRemarks() == null) {
target.setRemarks(new ArrayList<>());
}
target.getRemarks().add("上半月溢出值: " + overflow);
// 更新修改时间
target.setUpdateTime(new Timestamp(System.currentTimeMillis()));
});
}
/**
* 计算成员工作情况-钻石政策.
*/