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 567ac2d8..faa88aa2 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 @@ -115,7 +115,7 @@ public class TeamBdMemberBillListQryExe { Integer currentBillBelong = TeamBillCycleUtils.getCalcBillBelong(); // 4. 查询当前周期的账单 - Map billCycleMap = teamBillCycleService.mapByTeamIds( + Map billCycleMap = teamBillCycleService.mapByTeamIds2( teamIdSet, currentBillBelong, TeamBillCycleStatus.SETTLED); // 5. 获取团队Profile信息(包含团队人数) diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java index bf05a05e..584edaea 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/BdLeaderSalarySettlementServiceImpl.java @@ -60,7 +60,7 @@ public class BdLeaderSalarySettlementServiceImpl implements BdLeaderSalarySettle log.warn("开始处理所有 BD Leader 工资结算,结算周期:{}", billBelong); // 查询所有 BD Leader - List allBdLeaders = businessDevelopmentBaseInfoService.listBdByLeadUserId(1981629599990001666L); + List allBdLeaders = businessDevelopmentBaseInfoService.listAll(); if (CollectionUtils.isEmpty(allBdLeaders)) { log.warn("没有找到任何 BD Leader 数据"); @@ -140,6 +140,12 @@ public class BdLeaderSalarySettlementServiceImpl implements BdLeaderSalarySettle bdRecord.getSettlementSalary().setScale(2, RoundingMode.DOWN) : BigDecimal.ZERO); detail.setAgencyCount(bdRecord.getAgencyNumber() != null ? bdRecord.getAgencyNumber() : 0); + memberDetails.add(detail); + } else { + BdLeaderTeamMemberDetail detail = new BdLeaderTeamMemberDetail(); + detail.setBdUserId(bdUserId); + detail.setSalary(BigDecimal.ZERO); + detail.setAgencyCount(0); memberDetails.add(detail); } } @@ -150,7 +156,7 @@ public class BdLeaderSalarySettlementServiceImpl implements BdLeaderSalarySettle if (!CollectionUtils.isEmpty(memberDetails)) { Set bdUserIdSet = new HashSet<>(bdUserIds); Map userProfileMap = userProfileGateway.mapByUserIds(bdUserIdSet); - + for (BdLeaderTeamMemberDetail detail : memberDetails) { UserProfile userProfile = userProfileMap.get(detail.getBdUserId()); if (userProfile != null) { @@ -176,7 +182,7 @@ public class BdLeaderSalarySettlementServiceImpl implements BdLeaderSalarySettle if (record.getSettlementSalary() != null && record.getSettlementSalary().compareTo(BigDecimal.ZERO) > 0) { try { // 调用钱包服务发放工资 -// issueSalary(bdLeaderUserId, record); + issueSalary(bdLeaderUserId, record); // 更新状态为成功 bdLeaderSalarySettlementRecordService.updateStatus(record.getId(), BdSettlementStatus.SUCCESS, null); 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 abc6d647..4f5dae23 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 @@ -66,7 +66,7 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService log.warn("开始处理所有 BD 工资结算,结算周期:{}", billBelong); // 查询所有 BD - List allBdTeams = businessDevelopmentTeamService.listByBdUserId(1971066750763978754L); + List allBdTeams = businessDevelopmentTeamService.listAll(); if (CollectionUtils.isEmpty(allBdTeams)) { log.warn("没有找到任何 BD 数据"); @@ -128,11 +128,7 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService if (record.getSettlementSalary() != null && record.getSettlementSalary().compareTo(BigDecimal.ZERO) > 0) { try { // 调用钱包服务发放工资 -// issueSalary(bdUserId, record); - - // 更新状态为成功 - bdSalarySettlementRecordService.updateStatus(record.getId(), BdSettlementStatus.SUCCESS, null); - record.setStatus(BdSettlementStatus.SUCCESS); + issueSalary(bdUserId, record); log.info("BD {} 工资发放成功,金额:{} USD", bdUserId, record.getSettlementSalary()); } catch (Exception e) { @@ -145,6 +141,9 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService } else { log.info("BD {} 本周期未达到结算标准,无工资发放", bdUserId); } + // 更新状态为成功 + bdSalarySettlementRecordService.updateStatus(record.getId(), BdSettlementStatus.SUCCESS, null); + record.setStatus(BdSettlementStatus.SUCCESS); return convertToCO(record); } @@ -324,14 +323,22 @@ public class BdSalarySettlementServiceImpl implements BdSalarySettlementService try { // 计算结算周期的开始和结束时间 - int year = billBelong / 100; - int month = billBelong % 100; - - java.time.LocalDateTime startTime = java.time.LocalDateTime.of(year, month, 1, 0, 0, 0); - java.time.LocalDateTime endTime = startTime.plusMonths(1).minusSeconds(1); + 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); // 调用订单服务批量查询用户充值统计 - com.red.circle.framework.dto.ResultResponse> response = + ResultResponse> response = inAppPurchaseDetailsClientApi.batchUserRechargeStatistics( userIds, SysOriginPlatformEnum.LIKEI.name(), diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamBillCycleService.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamBillCycleService.java index 87f30eff..6e64441f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamBillCycleService.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/TeamBillCycleService.java @@ -22,6 +22,11 @@ public interface TeamBillCycleService { */ Map mapByTeamIds(Set teamIds, Integer billBelong, TeamBillCycleStatus status); + /** + * 获取一组账单信息2. + */ + Map mapByTeamIds2(Set teamIds, Integer billBelong, TeamBillCycleStatus status); + /** * 获取一组账单信息. */ diff --git a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java index 1b1f9937..4a7de53f 100644 --- a/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java +++ b/rc-service/rc-service-other/other-infrastructure/src/main/java/com/red/circle/other/infra/database/mongo/service/team/team/impl/TeamBillCycleServiceImpl.java @@ -102,6 +102,59 @@ public class TeamBillCycleServiceImpl implements TeamBillCycleService { )); } + @Override + public Map mapByTeamIds2(Set teamIds, Integer billBelong, TeamBillCycleStatus status) { + + if (CollectionUtils.isEmpty(teamIds) || Objects.isNull(status)) { + return Maps.newHashMap(); + } + + Criteria criteria = new Criteria().orOperator( + Criteria.where("billBelong").is(billBelong) + ); + + List teamBillCycles = mongoTemplate.find( + Query.query(criteria.and("teamId").in(teamIds).and("status").is(status)), + TeamBillCycle.class); + + if (CollectionUtils.isEmpty(teamBillCycles)) { + return Maps.newHashMap(); + } + + return teamBillCycles.stream() + .collect(Collectors.toMap( + TeamBillCycle::getTeamId, + v -> v, + (v1, v2) -> { + // 当teamId重复时,累加settleResult中的totalSalary + BigDecimal totalSalary1 = BigDecimal.ZERO; + BigDecimal totalSalary2 = BigDecimal.ZERO; + + // 获取v1的totalSalary + if (v1.getSettleResult() != null && v1.getSettleResult().getTotalSalary() != null) { + totalSalary1 = v1.getSettleResult().getTotalSalary(); + } + + // 获取v2的totalSalary + if (v2.getSettleResult() != null && v2.getSettleResult().getTotalSalary() != null) { + totalSalary2 = v2.getSettleResult().getTotalSalary(); + } + + // 累加totalSalary + BigDecimal sumTotalSalary = totalSalary1.add(totalSalary2); + + // 确保v1有settleResult对象 + if (v1.getSettleResult() == null) { + v1.setSettleResult(new TeamBillSettleResult()); + } + + // 设置累加后的totalSalary + v1.getSettleResult().setTotalSalary(sumTotalSalary); + return v1; + } + )); + } + @Override public Map mapByBillIds(Set teamIds, Set billBelongs) { if (CollectionUtils.isEmpty(teamIds) || CollectionUtils.isEmpty(billBelongs)) {