bd工资显示显示处理

This commit is contained in:
tianfeng 2025-11-14 18:09:25 +08:00
parent e4d525eaac
commit 506da7d880
5 changed files with 79 additions and 23 deletions

View File

@ -1,5 +1,9 @@
package com.red.circle.other.app.command.bd.query;
import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.order.inner.endpoint.InAppPurchaseDetailsClient;
import com.red.circle.order.inner.model.dto.inapp.BatchUserRechargeStatisticsDTO;
import com.red.circle.other.app.convertor.user.UserProfileAppConvertor;
import com.red.circle.other.app.dto.clientobject.TeamBdMemberBillCO;
import com.red.circle.other.app.dto.clientobject.TeamBdMemberCO;
@ -24,10 +28,12 @@ import com.red.circle.other.inner.model.dto.user.UserProfileDTO;
import com.red.circle.tool.core.collection.CollectionUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Component;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -52,6 +58,7 @@ public class TeamBdMemberBillListQryExe {
private final BdTeamLeaderClient bdTeamLeaderClient;
private final TeamMemberService teamMemberService;
private final BusinessDevelopmentBaseInfoService businessDevelopmentBaseInfoService;
private final InAppPurchaseDetailsClient inAppPurchaseDetailsClient;
/**
* 执行查询.
@ -128,9 +135,11 @@ public class TeamBdMemberBillListQryExe {
Map<Long, UserProfileDTO> userProfileMap = userProfileAppConvertor.toMapUserProfileDTO(
userProfileGateway.mapByUserIds(agentIdSet));
Map<Long, BigDecimal> rechargeMap = getRechargeMap(currentBillBelong, agentIdSet);
// 7. 组装返回结果
List<TeamBdMemberBillCO> collect = bdTeamList.stream()
.map(bdTeam -> buildMemberBillCO(bdTeam, billCycleMap, teamProfileMap, userProfileMap, currentBillBelong))
.map(bdTeam -> buildMemberBillCO(bdTeam, billCycleMap, teamProfileMap, userProfileMap,rechargeMap, currentBillBelong))
.collect(Collectors.toList());
TeamBdMemberCO teamBdMemberCO = new TeamBdMemberCO();
@ -141,7 +150,29 @@ public class TeamBdMemberBillListQryExe {
return teamBdMemberCO;
}
private Collection<? extends BusinessDevelopmentTeam> buildBdTeamVO(List<TeamMember> teamMembers) {
@NotNull
private Map<Long, BigDecimal> getRechargeMap(Integer currentBillBelong, Set<Long> agentIdSet) {
Map<Long, List<TeamMember>> mapByTeamIds = teamMemberService.mapByTeamIds(agentIdSet);
List<Long> memberIds = mapByTeamIds.values().stream()
.flatMap(List::stream)
.map(TeamMember::getMemberId)
.toList();
LocalDateTime startTime = TeamBillCycleUtils.getBillBelongStartTime(currentBillBelong);
LocalDateTime endTime = TeamBillCycleUtils.getBillBelongEndTime(currentBillBelong);
ResultResponse<List<BatchUserRechargeStatisticsDTO>> response =
inAppPurchaseDetailsClient.batchUserRechargeStatistics(
memberIds,
SysOriginPlatformEnum.LIKEI.name(),
startTime,
endTime
);
List<BatchUserRechargeStatisticsDTO> body = response.getBody();
Map<Long, BigDecimal> rechargeMap = body.stream().collect(Collectors.toMap(BatchUserRechargeStatisticsDTO::getUserId, BatchUserRechargeStatisticsDTO::getTotalAmount, BigDecimal::add));
return rechargeMap;
}
private Collection<? extends BusinessDevelopmentTeam> buildBdTeamVO(List<TeamMember> teamMembers) {
return teamMembers.stream().map(e -> {
BusinessDevelopmentTeam businessDevelopmentTeam = new BusinessDevelopmentTeam();
businessDevelopmentTeam.setTeamId(e.getTeamId());
@ -158,6 +189,7 @@ public class TeamBdMemberBillListQryExe {
Map<Long, TeamBillCycle> billCycleMap,
Map<Long, TeamProfile> teamProfileMap,
Map<Long, UserProfileDTO> userProfileMap,
Map<Long, BigDecimal> rechargeMap,
Integer billBelong) {
TeamBdMemberBillCO co = new TeamBdMemberBillCO();
@ -196,13 +228,11 @@ public class TeamBdMemberBillListQryExe {
// 团队薪资和充值
co.setTeamSalaryAmount(settleResult.getTotalSalary());
co.setTeamRechargeAmount(BigDecimal.ZERO);
} else {
// 如果没有账单周期设置默认值
co.setTeamSalaryAmount(BigDecimal.ZERO);
co.setTeamRechargeAmount(BigDecimal.ZERO);
}
co.setTeamRechargeAmount(Optional.ofNullable(rechargeMap.get(bdTeam.getAgentId())).orElse(BigDecimal.ZERO));
return co;
}

View File

@ -27,9 +27,9 @@ public class BdLeaderSalarySettlementTask {
private final BdLeaderSalarySettlementService bdLeaderSalarySettlementService;
/**
* 每月1号和16号 0点执行半月结算.
* 每月1号和16号 1点半执行半月结算.
*/
// @Scheduled(cron = "0 0 2 1,16 * ?", zone = "Asia/Riyadh")
@Scheduled(cron = "0 30 1 1,16 * ?", zone = "Asia/Riyadh")
@TaskCacheLock(key = "BD_LEADER_SALARY_SETTLEMENT", expireSecond = 86400)
public void processBdLeaderSalarySettlement() {
long startTime = System.currentTimeMillis();

View File

@ -27,9 +27,9 @@ public class BdSalarySettlementTask {
private final BdSalarySettlementService bdSalarySettlementService;
/**
* 每月1号和16号 0点执行半月结算.
* 每月1号和16号 1点执行半月结算.
*/
// @Scheduled(cron = "0 0 1 1,16 * ?", zone = "Asia/Riyadh")
@Scheduled(cron = "0 0 1 1,16 * ?", zone = "Asia/Riyadh")
@TaskCacheLock(key = "BD_SALARY_SETTLEMENT", expireSecond = 86400)
public void processBdSalarySettlement() {
long startTime = System.currentTimeMillis();

View File

@ -5,10 +5,12 @@ import com.red.circle.common.business.core.enums.SysOriginPlatformEnum;
import com.red.circle.framework.dto.ResultResponse;
import com.red.circle.other.app.dto.clientobject.BdSalarySettlementCO;
import com.red.circle.other.app.dto.clientobject.BdTeamStatisticsCO;
import com.red.circle.other.app.util.DateTimeAsiaRiyadhUtils;
import com.red.circle.other.domain.gateway.user.UserProfileGateway;
import com.red.circle.other.domain.model.user.UserProfile;
import com.red.circle.other.infra.database.mongo.entity.bd.detail.BdTeamMemberDetail;
import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMemberTarget;
import com.red.circle.other.infra.database.mongo.service.team.TeamBillCycleUtils;
import com.red.circle.other.infra.enums.BdPolicyType;
import com.red.circle.other.infra.enums.BdSettlementStatus;
import com.red.circle.other.infra.database.mongo.entity.bd.BdSalaryPolicy;
@ -31,6 +33,7 @@ import com.red.circle.wallet.inner.model.dto.UserBankRunningWaterDTO;
import com.red.circle.wallet.inner.model.enums.UserBankWaterEvent;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -66,7 +69,7 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService
log.warn("开始处理所有 BD 工资结算,结算周期:{}", billBelong);
// 查询所有 BD
List<BusinessDevelopmentTeam> allBdTeams = businessDevelopmentTeamService.listAll();
List<BusinessDevelopmentTeam> allBdTeams = businessDevelopmentTeamService.listByUserId(1963790037740466178L);
if (CollectionUtils.isEmpty(allBdTeams)) {
log.warn("没有找到任何 BD 数据");
@ -323,19 +326,8 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService
try {
// 计算结算周期的开始和结束时间
int year, month;
if (billBelong > 999999) {
// 8位格式20251016
year = billBelong / 10000;
month = (billBelong / 100) % 100;
} else {
// 6位格式202510
year = billBelong / 100;
month = billBelong % 100;
}
LocalDateTime startTime = java.time.LocalDateTime.of(year, month, 1, 0, 0, 0);
LocalDateTime endTime = startTime.plusMonths(1).minusSeconds(1);
LocalDateTime startTime = TeamBillCycleUtils.getBillBelongStartTime(billBelong);
LocalDateTime endTime = TeamBillCycleUtils.getBillBelongEndTime(billBelong);
// 调用订单服务批量查询用户充值统计
ResultResponse<List<BatchUserRechargeStatisticsDTO>> response =

View File

@ -21,6 +21,7 @@ import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.Comparator;
@ -619,4 +620,37 @@ public final class TeamBillCycleUtils {
return String.format("%d年%d月%s", year, month, batchDesc);
}
public static LocalDateTime getBillBelongStartTime(Integer billBelong) {
int year, month;
if (billBelong > 999999) {
// 8位格式20251016
year = billBelong / 10000;
month = (billBelong / 100) % 100;
} else {
// 6位格式202510
year = billBelong / 100;
month = billBelong % 100;
}
LocalDateTime startTime = LocalDateTime.of(year, month, 1, 0, 0, 0);
return startTime;
}
public static LocalDateTime getBillBelongEndTime(Integer billBelong) {
int year, month;
if (billBelong > 999999) {
// 8位格式20251016
year = billBelong / 10000;
month = (billBelong / 100) % 100;
} else {
// 6位格式202510
year = billBelong / 100;
month = billBelong % 100;
}
LocalDateTime startTime = LocalDateTime.of(year, month, 1, 0, 0, 0);
LocalDateTime endTime = startTime.plusMonths(1).minusSeconds(1);
return endTime;
}
}