BD Center 列表数据实时显示问题处理
This commit is contained in:
parent
de418ea444
commit
289da0f2b8
@ -15,19 +15,16 @@ import com.red.circle.other.app.dto.clientobject.team.BdHistoryCO;
|
||||
import com.red.circle.other.app.dto.cmd.TeamBdMemberBillCmd;
|
||||
import com.red.circle.other.app.service.BdSalarySettlementServiceImpl;
|
||||
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillMemberTarget;
|
||||
import com.red.circle.other.infra.database.mongo.entity.bd.BdSalaryPolicy;
|
||||
import com.red.circle.other.infra.database.mongo.entity.bd.BdSalarySettlementRecord;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.*;
|
||||
import com.red.circle.other.infra.database.mongo.service.bd.BdSalaryPolicyService;
|
||||
import com.red.circle.other.infra.database.mongo.service.team.team.*;
|
||||
import com.red.circle.other.infra.enums.BdPolicyType;
|
||||
import com.red.circle.other.infra.enums.BdSettlementStatus;
|
||||
import com.red.circle.other.infra.database.mongo.dto.team.TeamBillSettleResult;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamBillCycle;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember;
|
||||
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamProfile;
|
||||
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.TeamMemberService;
|
||||
import com.red.circle.other.infra.database.mongo.service.team.team.TeamProfileService;
|
||||
import com.red.circle.other.infra.database.rds.entity.team.BusinessDevelopmentBaseInfo;
|
||||
import com.red.circle.other.infra.database.rds.entity.team.BusinessDevelopmentTeam;
|
||||
import com.red.circle.other.infra.database.rds.service.team.BusinessDevelopmentBaseInfoService;
|
||||
@ -66,6 +63,8 @@ public class TeamBdMemberBillListQryExe {
|
||||
private final BusinessDevelopmentTeamService businessDevelopmentTeamService;
|
||||
private final TeamBillCycleService teamBillCycleService;
|
||||
private final TeamProfileService teamProfileService;
|
||||
private final TeamPolicyManagerService teamPolicyManagerService;
|
||||
private final TeamMemberTargetService teamMemberTargetService;
|
||||
private final UserProfileGateway userProfileGateway;
|
||||
private final UserProfileAppConvertor userProfileAppConvertor;
|
||||
private final TeamMemberService teamMemberService;
|
||||
@ -120,10 +119,16 @@ public class TeamBdMemberBillListQryExe {
|
||||
Set<Long> teamIdSet = bdTeamList.stream()
|
||||
.map(BusinessDevelopmentTeam::getTeamId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
// 4. 查询当前周期的账单
|
||||
|
||||
// 获取所有区域的政策配置
|
||||
Map<Long, TeamBillCycle> billCycleMap = teamBillCycleService.mapByTeamIds2(
|
||||
teamIdSet, currentBillBelong, TeamBillCycleStatus.UNPAID);
|
||||
Map<String, TeamPolicyManager> regionPolicyMap = teamPolicyManagerService.mapRegionRelease(
|
||||
billCycleMap.values().stream().map(TeamBillCycle::getRegion).collect(Collectors.toSet()));
|
||||
|
||||
// 4. 查询当前周期的账单
|
||||
Map<Long, List<TeamMemberTarget>> memberBillTarget =
|
||||
teamMemberTargetService.mapMemberBillTarget(teamIdSet, currentBillBelong);
|
||||
|
||||
// 5. 获取团队Profile信息
|
||||
Map<Long, TeamProfile> teamProfileMap = teamProfileService.mapProfileByIds(teamIdSet);
|
||||
@ -140,7 +145,7 @@ public class TeamBdMemberBillListQryExe {
|
||||
|
||||
// 8. 组装成员账单列表(每个 Agent 团队一条)
|
||||
List<TeamBdMemberBillCO> memberBillList = bdTeamList.stream()
|
||||
.map(bdTeam -> buildMemberBillCO(bdTeam, billCycleMap, teamProfileMap,
|
||||
.map(bdTeam -> buildMemberBillCO(bdTeam, billCycleMap, memberBillTarget,regionPolicyMap, teamProfileMap,
|
||||
userProfileMap, rechargeMap, currentBillBelong))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@ -272,17 +277,18 @@ public class TeamBdMemberBillListQryExe {
|
||||
// 6. 查询账单数据
|
||||
Map<Long, TeamBillCycle> billCycleMap = teamBillCycleService.mapByTeamIds2(
|
||||
teamIdSet, currentBillBelong, TeamBillCycleStatus.UNPAID);
|
||||
|
||||
// 7. 汇总所有团队的工资
|
||||
|
||||
Map<String, TeamPolicyManager> regionPolicyMap = teamPolicyManagerService.mapRegionRelease(
|
||||
billCycleMap.values().stream().map(TeamBillCycle::getRegion).collect(Collectors.toSet()));
|
||||
|
||||
// 4. 查询当前周期的账单
|
||||
Map<Long, List<TeamMemberTarget>> memberBillTarget =
|
||||
teamMemberTargetService.mapMemberBillTarget(teamIdSet, currentBillBelong);
|
||||
|
||||
BigDecimal totalSalary = BigDecimal.ZERO;
|
||||
for (BusinessDevelopmentTeam bdTeam : bdTeamList) {
|
||||
TeamBillCycle billCycle = billCycleMap.get(bdTeam.getTeamId());
|
||||
if (billCycle != null && billCycle.getSettleResult() != null) {
|
||||
BigDecimal teamSalary = billCycle.getSettleResult().getTotalSalary();
|
||||
if (teamSalary != null) {
|
||||
totalSalary = totalSalary.add(teamSalary);
|
||||
}
|
||||
}
|
||||
Long teamId = bdTeam.getTeamId();
|
||||
totalSalary = totalSalary.add(getTeamTotalSalary(billCycleMap, memberBillTarget, regionPolicyMap, teamId));
|
||||
}
|
||||
co.setTeamSalaryAmount(totalSalary);
|
||||
|
||||
@ -357,6 +363,8 @@ public class TeamBdMemberBillListQryExe {
|
||||
private TeamBdMemberBillCO buildMemberBillCO(
|
||||
BusinessDevelopmentTeam bdTeam,
|
||||
Map<Long, TeamBillCycle> billCycleMap,
|
||||
Map<Long, List<TeamMemberTarget>> teamMemberTargetMap,
|
||||
Map<String, TeamPolicyManager> policyManagerMap,
|
||||
Map<Long, TeamProfile> teamProfileMap,
|
||||
Map<Long, UserProfileDTO> userProfileMap,
|
||||
Map<Long, BigDecimal> rechargeMap,
|
||||
@ -392,21 +400,32 @@ public class TeamBdMemberBillListQryExe {
|
||||
co.setEndDate(dates[1]);
|
||||
|
||||
// 账单周期信息
|
||||
TeamBillCycle billCycle = billCycleMap.get(bdTeam.getTeamId());
|
||||
if (billCycle != null && billCycle.getSettleResult() != null) {
|
||||
TeamBillSettleResult settleResult = billCycle.getSettleResult();
|
||||
|
||||
// 团队薪资和充值
|
||||
co.setTeamSalaryAmount(settleResult.getTotalSalary());
|
||||
} else {
|
||||
// 如果没有账单周期,设置默认值
|
||||
co.setTeamSalaryAmount(BigDecimal.ZERO);
|
||||
}
|
||||
Long teamId = bdTeam.getTeamId();
|
||||
BigDecimal totalSalary = getTeamTotalSalary(billCycleMap, teamMemberTargetMap, policyManagerMap, teamId);
|
||||
co.setTeamSalaryAmount(totalSalary);
|
||||
co.setTeamRechargeAmount(Optional.ofNullable(rechargeMap.get(bdTeam.getAgentId())).orElse(BigDecimal.ZERO));
|
||||
|
||||
return co;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private BigDecimal getTeamTotalSalary(Map<Long, TeamBillCycle> billCycleMap, Map<Long, List<TeamMemberTarget>> teamMemberTargetMap, Map<String, TeamPolicyManager> policyManagerMap, Long teamId) {
|
||||
TeamBillCycle billCycle = billCycleMap.get(teamId);
|
||||
if (billCycle == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
List<TeamMemberTarget> targetList = teamMemberTargetMap.get(teamId);
|
||||
List<TeamBillMemberTarget> memberTargets = TeamBillCycleUtils.calculatorPolicyTarget(targetList, policyManagerMap.get(billCycle.getRegion()));
|
||||
return ownTotalSalary(memberTargets);
|
||||
}
|
||||
|
||||
private BigDecimal ownTotalSalary(List<TeamBillMemberTarget> teamBillMemberTargets) {
|
||||
return teamBillMemberTargets.stream().map(TeamBillMemberTarget::getTotalSalary)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
.setScale(2, RoundingMode.DOWN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算当前未结算的 BD 账单信息.
|
||||
*
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user