From 506da7d8802847bb54d2326753b3947283f8d36c Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 14 Nov 2025 18:09:25 +0800 Subject: [PATCH] =?UTF-8?q?bd=E5=B7=A5=E8=B5=84=E6=98=BE=E7=A4=BA=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bd/query/TeamBdMemberBillListQryExe.java | 40 ++++++++++++++++--- .../BdLeaderSalarySettlementTask.java | 4 +- .../app/scheduler/BdSalarySettlementTask.java | 4 +- .../BdSalarySettlementServiceImpl.java | 20 +++------- .../service/team/TeamBillCycleUtils.java | 34 ++++++++++++++++ 5 files changed, 79 insertions(+), 23 deletions(-) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java index faa88aa2..36bb7dbb 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/bd/query/TeamBdMemberBillListQryExe.java @@ -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 userProfileMap = userProfileAppConvertor.toMapUserProfileDTO( userProfileGateway.mapByUserIds(agentIdSet)); + Map rechargeMap = getRechargeMap(currentBillBelong, agentIdSet); + // 7. 组装返回结果 List 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 buildBdTeamVO(List teamMembers) { + @NotNull + private Map getRechargeMap(Integer currentBillBelong, Set agentIdSet) { + Map> mapByTeamIds = teamMemberService.mapByTeamIds(agentIdSet); + List memberIds = mapByTeamIds.values().stream() + .flatMap(List::stream) + .map(TeamMember::getMemberId) + .toList(); + + LocalDateTime startTime = TeamBillCycleUtils.getBillBelongStartTime(currentBillBelong); + LocalDateTime endTime = TeamBillCycleUtils.getBillBelongEndTime(currentBillBelong); + ResultResponse> response = + inAppPurchaseDetailsClient.batchUserRechargeStatistics( + memberIds, + SysOriginPlatformEnum.LIKEI.name(), + startTime, + endTime + ); + List body = response.getBody(); + Map rechargeMap = body.stream().collect(Collectors.toMap(BatchUserRechargeStatisticsDTO::getUserId, BatchUserRechargeStatisticsDTO::getTotalAmount, BigDecimal::add)); + return rechargeMap; + } + + private Collection buildBdTeamVO(List teamMembers) { return teamMembers.stream().map(e -> { BusinessDevelopmentTeam businessDevelopmentTeam = new BusinessDevelopmentTeam(); businessDevelopmentTeam.setTeamId(e.getTeamId()); @@ -158,6 +189,7 @@ public class TeamBdMemberBillListQryExe { Map billCycleMap, Map teamProfileMap, Map userProfileMap, + Map 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; } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdLeaderSalarySettlementTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdLeaderSalarySettlementTask.java index 328f611d..20742372 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdLeaderSalarySettlementTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdLeaderSalarySettlementTask.java @@ -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(); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdSalarySettlementTask.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdSalarySettlementTask.java index 0fb8387b..6c251472 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdSalarySettlementTask.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/scheduler/BdSalarySettlementTask.java @@ -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(); diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java index 4f5dae23..06d63c1a 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdSalarySettlementServiceImpl.java @@ -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 allBdTeams = businessDevelopmentTeamService.listAll(); + List 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> response = diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java index d339e75c..727b45e1 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/TeamBillCycleUtils.java @@ -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; + } + }