结算修复

This commit is contained in:
tianfeng 2025-10-31 21:41:41 +08:00
parent d197793839
commit 877131dae8
2 changed files with 111 additions and 195 deletions

View File

@ -1,5 +1,7 @@
package com.red.circle.other.infra.database.mongo.service.team;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Lists;
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillMemberTarget;
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillPolicyType;
@ -23,6 +25,7 @@ import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
@ -153,7 +156,9 @@ public final class TeamBillCycleUtils {
return targets.stream().map(target -> {
long targetTimeHours = target.sumAllTargetTime() / 60;
Long acceptGiftValue = target.sumAcceptGiftValue();
Integer effectiveDay = target.sumEffectiveDay();
// 计算有效天数统计每日在线时长 >= 60分钟的天数
Integer effectiveDay = calculateEffectiveDay(target);
TeamBillMemberTarget resultTarget = new TeamBillMemberTarget()
.setTargetId(target.getTimeId())
@ -172,18 +177,22 @@ public final class TeamBillCycleUtils {
Long policyOnlineTimeHours = NumUtils.isNullDefaultZero(teamPolicy.getOnlineTime());
Long policyGiftValue = NumUtils.isNullDefaultZero(teamPolicy.getTarget());
// 南亚区域特殊处理
if ("SA".equals(regionConfig.getRegionCode())) {
if (acceptGiftValue < policyGiftValue) {
continue;
}
if (!Boolean.TRUE.equals(target.getIsOwn())) {
Integer policyEffectiveDay = NumUtils.isNullDefaultZero(teamPolicy.getEffectiveDay());
if (targetTimeHours >= policyOnlineTimeHours && effectiveDay >= policyEffectiveDay) {
resultTarget.setMemberSalary(teamPolicy.getMemberSalary());
resultTarget.setOwnSalary(teamPolicy.getOwnSalary());
resultTarget.setTotalSalary(teamPolicy.getTotalSalary());
} else if (acceptGiftValue >= policyGiftValue && !Boolean.TRUE.equals(target.getIsOwn())){
resultTarget.setMemberSalary(teamPolicy.getMemberSalary().multiply(new BigDecimal("0.9")).setScale(2, RoundingMode.DOWN));
resultTarget.setTotalSalary(teamPolicy.getMemberSalary().multiply(new BigDecimal("0.9")).setScale(2, RoundingMode.DOWN));
} else {
resultTarget.setMemberSalary(teamPolicy.getMemberSalary());
resultTarget.setOwnSalary(teamPolicy.getOwnSalary());
resultTarget.setTotalSalary(teamPolicy.getTotalSalary());
}
resultTarget.setLevel(teamPolicy.getLevel());
resultTarget.setSatisfyLevel(Boolean.TRUE);
@ -193,6 +202,8 @@ public final class TeamBillCycleUtils {
// 20240918 政策新增有效天字段大于1小时60分钟即可获取当天有效天
Integer policyEffectiveDay = NumUtils.isNullDefaultZero(teamPolicy.getEffectiveDay());
// 完全满足条件在线时长礼物价值有效天数都达标
if (targetTimeHours >= policyOnlineTimeHours && acceptGiftValue >= policyGiftValue && effectiveDay >= policyEffectiveDay) {
resultTarget.setMemberSalary(teamPolicy.getMemberSalary());
resultTarget.setOwnSalary(teamPolicy.getOwnSalary());
@ -201,7 +212,9 @@ public final class TeamBillCycleUtils {
resultTarget.setSatisfyLevel(Boolean.TRUE);
resultTarget.setPropsRewards(teamPolicy.getPropsRewards());
return resultTarget;
} else if (acceptGiftValue >= policyGiftValue && !Boolean.TRUE.equals(target.getIsOwn())) {
}
// 部分满足条件礼物价值达标但不是主播本人
else if (acceptGiftValue >= policyGiftValue && !Boolean.TRUE.equals(target.getIsOwn())) {
resultTarget.setMemberSalary(teamPolicy.getMemberSalary().multiply(new BigDecimal("0.9")).setScale(2, RoundingMode.DOWN));
resultTarget.setTotalSalary(teamPolicy.getMemberSalary().multiply(new BigDecimal("0.9")).setScale(2, RoundingMode.DOWN));
resultTarget.setLevel(teamPolicy.getLevel());
@ -209,13 +222,52 @@ public final class TeamBillCycleUtils {
resultTarget.setPropsRewards(teamPolicy.getPropsRewards());
return resultTarget;
}
}
}
return resultTarget;
}).filter(Objects::nonNull).collect(Collectors.toList());
}
/**
* 计算有效天数
* 规则每日在线时长 >= 60分钟算作有效一天
*
* @param target 成员目标数据
* @return 有效天数
*/
private static Integer calculateEffectiveDay(TeamMemberTarget target) {
if (target == null || target.getDailyTargets() == null) {
return 0;
}
// 统计每日在线时长 >= 60分钟的天数
int effectiveDayCount = 0;
for (Object dailyData : target.getDailyTargets()) {
// 假设dailyData是包含ownOnlineTime和otherOnlineTime的对象
Long dailyOnlineTime = getDailyTotalOnlineTime(dailyData);
if (dailyOnlineTime != null && dailyOnlineTime >= 60) {
effectiveDayCount++;
}
}
return effectiveDayCount;
}
/**
* 获取每日总在线时长
* 根据您的MongoDB数据结构需要累加ownOnlineTime和otherOnlineTime
*/
private static Long getDailyTotalOnlineTime(Object dailyData) {
try {
JSONObject jsonObject = (JSONObject) JSON.toJSON(dailyData);
Long ownOnlineTime = NumUtils.isNullDefaultZero(jsonObject.getLong("ownOnlineTime"));
Long otherOnlineTime = NumUtils.isNullDefaultZero(jsonObject.getLong("otherOnlineTime"));
return ownOnlineTime + otherOnlineTime;
} catch (Exception e) {
return 0L;
}
}
/**
* 计算成员工作情况.
*/

View File

@ -5,6 +5,18 @@ import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.other.app.listener.team.TeamBillSettleListener;
import com.red.circle.other.app.manager.activity.award.WeeklyRewardsSentManager;
import com.red.circle.other.app.scheduler.TeamBillTask;
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillMemberTarget;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamBillCycle;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMemberTarget;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamPolicyManager;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile;
import com.red.circle.other.infra.database.mongo.entity.user.region.SysRegionConfig;
import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamBillCycleService;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamMemberTargetService;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamPolicyManagerService;
import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
import com.red.circle.other.infra.database.mongo.service.user.region.SysRegionConfigService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@ -13,6 +25,7 @@ import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import javax.annotation.Resource;
import java.util.List;
@SpringBootTest(classes = OtherServiceApplication.class)
@RunWith(SpringRunner.class)
@ -24,6 +37,16 @@ public class TeamMonthBillTest {
private TeamBillSettleListener teamBillSettleListener;
@Autowired
private WeeklyRewardsSentManager weeklyRewardsSentManager;
@Autowired
private TeamBillCycleService teamBillCycleService;
@Autowired
private TeamPolicyManagerService teamPolicyManagerService;
@Autowired
private SysRegionConfigService sysRegionConfigService;
@Autowired
private TeamProfileService teamProfileService;
@Autowired
private TeamMemberTargetService teamMemberTargetService;
/**
* 更新账单 然很发布消息
@ -38,193 +61,34 @@ public class TeamMonthBillTest {
*/
@Test
public void testListener() {
String json = "[\"1972121664590573570\",\n" +
"\"1972145409317269506\",\n" +
"\"1940312568494260225\",\n" +
"\"1947932808143228929\",\n" +
"\"1954059793963393025\",\n" +
"\"1940312568494260225\",\n" +
"\"1960648963499921410\",\n" +
"\"1943236733952118786\",\n" +
"\"1934955663112970241\",\n" +
"\"1934594294344105986\",\n" +
"\"1927993836921233409\",\n" +
"\"1964984476343652354\",\n" +
"\"1954059793963393025\",\n" +
"\"1934954337746460674\",\n" +
"\"1927688171883532290\",\n" +
"\"1934955663112970241\",\n" +
"\"1934954337746460674\",\n" +
"\"1934594294344105986\",\n" +
"\"1927688171883532290\",\n" +
"\"1930095641158983681\",\n" +
"\"1928027505396359170\",\n" +
"\"1970839746512867329\",\n" +
"\"1970239228578291714\",\n" +
"\"1970238525914931202\",\n" +
"\"1970237660088950786\",\n" +
"\"1970041049628270594\",\n" +
"\"1928027505396359170\",\n" +
"\"1965241868967084033\",\n" +
"\"1965241670379372546\",\n" +
"\"1966343406124924929\",\n" +
"\"1970553931623206914\",\n" +
"\"1970240726255198210\",\n" +
"\"1970090975087288322\",\n" +
"\"1969985144628113410\",\n" +
"\"1972262152727556098\",\n" +
"\"1972307251536719874\",\n" +
"\"1972327008868626433\",\n" +
"\"1972482248846733314\",\n" +
"\"1972562275459846146\",\n" +
"\"1972554883678523394\",\n" +
"\"1972591139447820290\",\n" +
"\"1965377272632741889\",\n" +
"\"1972681486747893762\",\n" +
"\"1972682144213434369\",\n" +
"\"1972731507686047746\",\n" +
"\"1972349403469836289\",\n" +
"\"1972907488023478273\",\n" +
"\"1972907397208408066\",\n" +
"\"1972912907135549441\",\n" +
"\"1972977801876799489\",\n" +
"\"1972977652035289089\",\n" +
"\"1972978013382967297\",\n" +
"\"1972977685359034370\",\n" +
"\"1972977733950046209\",\n" +
"\"1973009710040285186\",\n" +
"\"1973009626665910273\",\n" +
"\"1972988900453974018\",\n" +
"\"1972978425821462529\",\n" +
"\"1972978278588809217\",\n" +
"\"1970084633211559938\",\n" +
"\"1969441508127473665\",\n" +
"\"1968582050277437442\",\n" +
"\"1965697878976794625\",\n" +
"\"1965670605449113602\",\n" +
"\"1960648963499921410\",\n" +
"\"1943236733952118786\",\n" +
"\"1972349473577627649\",\n" +
"\"1972349324952465409\",\n" +
"\"1971231353175326722\",\n" +
"\"1970839810392117249\",\n" +
"\"1970241741360652289\",\n" +
"\"1970241001481232386\",\n" +
"\"1970240500932993025\",\n" +
"\"1970240149588729858\",\n" +
"\"1970239738387554305\",\n" +
"\"1970239373046898689\",\n" +
"\"1970041153391157250\",\n" +
"\"1970047885051944961\",\n" +
"\"1971502931662389249\",\n" +
"\"1971119532736958466\",\n" +
"\"1970672013117132802\",\n" +
"\"1971398904870125570\",\n" +
"\"1971398839711612930\",\n" +
"\"1970671768509517826\",\n" +
"\"1970248923946868738\",\n" +
"\"1970241328838270977\",\n" +
"\"1970241165533044737\",\n" +
"\"1970240870782525441\",\n" +
"\"1970240311325286401\",\n" +
"\"1970091061435424769\",\n" +
"\"1970059597205463041\",\n" +
"\"1969985281152708610\",\n" +
"\"1971143512139837441\",\n" +
"\"1971035111505711105\",\n" +
"\"1971034990600704001\",\n" +
"\"1970329468156436481\",\n" +
"\"1947932808143228929\",\n" +
"\"1927993836921233409\",\n" +
"\"1968616688228184065\",\n" +
"\"1968561226841407490\",\n" +
"\"1968573544702881794\",\n" +
"\"1968238092672479234\",\n" +
"\"1968246725334446081\",\n" +
"\"1968205632966406146\",\n" +
"\"1965724731682754561\",\n" +
"\"1965717967356727297\",\n" +
"\"1965702919053807618\",\n" +
"\"1965344339153850370\",\n" +
"\"1965343456902975489\",\n" +
"\"1965342993398829057\",\n" +
"\"1965341926967676929\",\n" +
"\"1965339775214227458\",\n" +
"\"1930095641158983681\",\n" +
"\"1970672134152163329\",\n" +
"\"1970672079907229697\",\n" +
"\"1970671939247050753\",\n" +
"\"1970671845219143682\",\n" +
"\"1970096695274889218\",\n" +
"\"1970084553494618113\",\n" +
"\"1969985850600779777\",\n" +
"\"1966098751514025985\",\n" +
"\"1970035825907851265\",\n" +
"\"1971455753556377602\",\n" +
"\"1971123684477841409\",\n" +
"\"1970772560712749058\",\n" +
"\"1970436903638462466\",\n" +
"\"1970084759590133762\",\n" +
"\"1970069435985682433\",\n" +
"\"1970068771016531970\",\n" +
"\"1970073471430418433\",\n" +
"\"1970075846048210945\",\n" +
"\"1970080430351179778\",\n" +
"\"1970080585141968898\",\n" +
"\"1970080221135101954\",\n" +
"\"1970075181422993409\",\n" +
"\"1970089627893620738\",\n" +
"\"1970038103905656833\",\n" +
"\"1970385020353835010\",\n" +
"\"1969975991420100610\",\n" +
"\"1969451850308059137\",\n" +
"\"1970442731334463489\",\n" +
"\"1971506063222030338\",\n" +
"\"1971119641667227650\",\n" +
"\"1970850172302708738\",\n" +
"\"1970839352965517313\",\n" +
"\"1970482354323886082\",\n" +
"\"1970453333624811522\",\n" +
"\"1970452378665676802\",\n" +
"\"1970452824843153410\",\n" +
"\"1970451795703558146\",\n" +
"\"1970086999805648897\",\n" +
"\"1970670927341850625\",\n" +
"\"1970671684883484673\",\n" +
"\"1970671644618166274\",\n" +
"\"1970802597927243778\",\n" +
"\"1970802187380379649\",\n" +
"\"1970096749712760834\",\n" +
"\"1970913548764631042\",\n" +
"\"1970913104457814018\",\n" +
"\"1970912960966479874\",\n" +
"\"1970385065883004929\",\n" +
"\"1965973353994915841\",\n" +
"\"1971037465688854530\",\n" +
"\"1971536719738093570\",\n" +
"\"1971521576442576897\",\n" +
"\"1971217424445390849\",\n" +
"\"1970087088099942401\",\n" +
"\"1964987386611814402\",\n" +
"\"1965602648182272002\",\n" +
"\"1971133558871896065\",\n" +
"\"1970098518413008897\",\n" +
"\"1971891423947386881\",\n" +
"\"1969980420420575233\",\n" +
"\"1970239073175134210\",\n" +
"\"1970088781013311489\",\n" +
"\"1971984869315964929\",\n" +
"\"1971922350274637826\",\n" +
"\"1971922546337378306\",\n" +
"\"1971945279959986177\",\n" +
"\"1969980558530617345\",\n" +
"\"1971989713510592513\",\n" +
"\"1971984929332260865\"]";
JSONArray teamIdArray = JSONArray.parseArray(json);
for (int i = 0; i < teamIdArray.size(); i++) {
Long teamId = teamIdArray.getLong(i);
teamBillSettleListener.processBillTest(teamId);
}
Long teamId = 1978293732420083713L;
// 获取团队信息
TeamProfile teamProfile = teamProfileService.getById(teamId);
TeamBillCycle teamBillCycle = new TeamBillCycle();
teamBillCycle.setSysOrigin("LIKEI");
teamBillCycle.setRegion(teamProfile.getRegion());
teamBillCycle.setBillBelong(20251016);
teamBillCycle.setTeamId(teamId);
// 获取团队区域政策
TeamPolicyManager regionPolicyManager = teamPolicyManagerService.getReleaseByRegionAndType(
teamBillCycle.getSysOrigin(),
teamBillCycle.getRegion()
);
SysRegionConfig regionConfig = sysRegionConfigService.getById(teamProfile.getRegion());
List<TeamMemberTarget> teamMemberTargets = teamMemberTargetService.listByBillBelong(
teamBillCycle.getTeamId(),
teamBillCycle.getBillBelong());
List<TeamBillMemberTarget> teamBillMemberTargets =
TeamBillCycleUtils.calculatorPolicyTargetNew(teamMemberTargets, regionPolicyManager, regionConfig);
System.out.println(teamBillMemberTargets);
// teamBillSettleListener.processBillTest(1984239048869130242L);
}
@Test