From 860ebd5a21006ace05333a973a3805253a7c1419 Mon Sep 17 00:00:00 2001 From: tianfeng <769204422@qq.com> Date: Fri, 26 Sep 2025 11:30:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=A2=E9=98=9F=E8=B4=A6=E5=8D=95=E6=80=BB?= =?UTF-8?q?=E5=92=8C=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adapter/app/team/TeamRestController.java | 17 +--- .../team/query/TeamMemberListQryExe.java | 84 ++++++++++++++++++- .../app/service/team/TeamServiceImpl.java | 17 +--- .../team/TeamMemberCountResultCO.java | 41 +++++++++ .../other/app/service/team/TeamService.java | 17 +--- 5 files changed, 129 insertions(+), 47 deletions(-) create mode 100644 rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/team/TeamMemberCountResultCO.java diff --git a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamRestController.java b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamRestController.java index 5f7d16a8..6d078b66 100644 --- a/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamRestController.java +++ b/rc-service/rc-service-other/other-adapter/src/main/java/com/red/circle/other/adapter/app/team/TeamRestController.java @@ -7,20 +7,7 @@ import com.red.circle.common.business.dto.cmd.app.AppIdStringCmd; import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd; import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; import com.red.circle.framework.web.controller.BaseController; -import com.red.circle.other.app.dto.clientobject.team.AnchorWorkStatisticsCO; -import com.red.circle.other.app.dto.clientobject.team.MemberEntryTeamCO; -import com.red.circle.other.app.dto.clientobject.team.TeamBillCO; -import com.red.circle.other.app.dto.clientobject.team.TeamBillMemberWorkCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberQuitAskCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberTargetSettlementResultCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberWorkCO; -import com.red.circle.other.app.dto.clientobject.team.TeamOwnMemberCO; -import com.red.circle.other.app.dto.clientobject.team.TeamPolicyManagerCO; -import com.red.circle.other.app.dto.clientobject.team.TeamProfileSearchResCO; -import com.red.circle.other.app.dto.clientobject.team.TeamQuitApplyInfoCO; -import com.red.circle.other.app.dto.clientobject.team.TeamUserApplyRecordCO; -import com.red.circle.other.app.dto.clientobject.team.TeamWaitApplyMessageCO; +import com.red.circle.other.app.dto.clientobject.team.*; import com.red.circle.other.app.dto.cmd.team.DateTypeQryCmd; import com.red.circle.other.app.dto.cmd.team.TeamHandleUserApplyCmd; import com.red.circle.other.app.dto.cmd.team.TeamMemberRoleChangeCmd; @@ -108,7 +95,7 @@ public class TeamRestController extends BaseController { * 成员数量 */ @GetMapping("/members/count") - public Integer countTeamMember(@Validated AppIdLongCmd cmd) { + public TeamMemberCountResultCO countTeamMember(@Validated AppIdLongCmd cmd) { return teamService.countTeamMember(cmd); } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberListQryExe.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberListQryExe.java index 0de8556f..187fe39c 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberListQryExe.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/command/team/query/TeamMemberListQryExe.java @@ -4,11 +4,17 @@ import com.google.common.collect.Lists; import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; import com.red.circle.other.app.convertor.user.UserProfileAppConvertor; import com.red.circle.other.app.dto.clientobject.team.TeamMemberCO; +import com.red.circle.other.app.dto.clientobject.team.TeamMemberCountResultCO; import com.red.circle.other.domain.gateway.user.UserProfileGateway; +import com.red.circle.other.infra.database.mongo.dto.team.TeamPolicy; import com.red.circle.other.infra.database.mongo.entity.team.team.TeamMember; 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.service.team.team.TeamMemberService; 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.inner.model.dto.user.UserProfileDTO; import com.red.circle.tool.core.collection.CollectionUtils; import com.red.circle.tool.core.date.ZonedDateTimeAsiaRiyadhUtils; @@ -34,6 +40,8 @@ public class TeamMemberListQryExe { private final UserProfileGateway userProfileGateway; private final UserProfileAppConvertor userProfileAppConvertor; private final TeamMemberTargetService teamMemberTargetService; + private final TeamPolicyManagerService teamPolicyManagerService; + private final TeamProfileService teamProfileService; public List execute(AppIdLongCmd cmd) { @@ -75,10 +83,82 @@ public class TeamMemberListQryExe { return teamMemberCOs; } - public Integer executeCount(AppIdLongCmd cmd) { + public TeamMemberCountResultCO executeCount(AppIdLongCmd cmd) { List teamMembers = teamMemberService.listTeamMember(cmd.getId(), 3000); - return teamMembers.size(); + + if (CollectionUtils.isEmpty(teamMembers)) { + return new TeamMemberCountResultCO() + .setMemberQuantity(0) + .setLevel(null) + .setTargetFormatSum("0") + .setTargetSum(0L); + } + + // 获取团队信息和政策管理器 + TeamProfile teamProfile = teamProfileService.getById(cmd.getId()); + if (teamProfile == null) { + return new TeamMemberCountResultCO() + .setMemberQuantity(teamMembers.size()) + .setLevel(null) + .setTargetFormatSum("0") + .setTargetSum(0L); + } + + TeamPolicyManager teamPolicyManager = teamPolicyManagerService.getReleaseByRegionAndType( + teamProfile.getSysOrigin(), teamProfile.getRegion()); + + if (teamPolicyManager == null || CollectionUtils.isEmpty(teamPolicyManager.getPolicy())) { + return new TeamMemberCountResultCO() + .setMemberQuantity(teamMembers.size()) + .setLevel(null) + .setTargetFormatSum("0") + .setTargetSum(0L); + } + + // 获取团队成员的目标总和 + Set memberUserIds = teamMembers.stream().map(TeamMember::getMemberId) + .collect(Collectors.toSet()); + + Map teamMemberTargetMap = teamMemberTargetService.mapMemberBillTarget( + cmd.getId(), memberUserIds, ZonedDateTimeAsiaRiyadhUtils.nowYearMonthToInt()); + + // 计算目标总和 + Long targetSum = teamMemberTargetMap.values().stream() + .filter(Objects::nonNull) + .mapToLong(target -> Optional.ofNullable(target.sumAcceptGiftValue()).orElse(0L)) + .sum(); + + // 根据团队目标总和匹配对应的TeamPolicy返回对应的挡位 + Integer matchedLevel = findMatchedLevel(teamPolicyManager.getPolicy(), targetSum); + + return new TeamMemberCountResultCO() + .setMemberQuantity(teamMembers.size()) + .setLevel(matchedLevel) + .setTargetFormatSum(NumUtils.formatLong(targetSum)) + .setTargetSum(targetSum); + } + + /** + * 根据目标总和查找匹配的等级. + * 逻辑:从高等级到低等级遍历,找到第一个满足条件的等级 + * + * @param policies 政策列表 + * @param targetSum 目标总和 + * @return 匹配的等级,如果没有匹配则返回null + */ + private Integer findMatchedLevel(List policies, Long targetSum) { + if (CollectionUtils.isEmpty(policies) || targetSum == null) { + return null; + } + + // 按等级降序排列,从高等级到低等级匹配 + return policies.stream() + .sorted((p1, p2) -> Integer.compare(p2.getLevel(), p1.getLevel())) + .filter(policy -> targetSum >= Optional.ofNullable(policy.getTarget()).orElse(0L)) + .findFirst() + .map(TeamPolicy::getLevel) + .orElse(0); } } diff --git a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/team/TeamServiceImpl.java b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/team/TeamServiceImpl.java index 8a93132c..c08885c1 100644 --- a/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/team/TeamServiceImpl.java +++ b/rc-service/rc-service-other/other-application/src/main/java/com/red/circle/other/app/service/team/TeamServiceImpl.java @@ -8,20 +8,7 @@ import com.red.circle.common.business.dto.cmd.app.AppIdStringCmd; import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd; import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; import com.red.circle.other.app.command.team.TeamHandleUserApplyExe; -import com.red.circle.other.app.dto.clientobject.team.AnchorWorkStatisticsCO; -import com.red.circle.other.app.dto.clientobject.team.MemberEntryTeamCO; -import com.red.circle.other.app.dto.clientobject.team.TeamBillCO; -import com.red.circle.other.app.dto.clientobject.team.TeamBillMemberWorkCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberQuitAskCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberTargetSettlementResultCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberWorkCO; -import com.red.circle.other.app.dto.clientobject.team.TeamOwnMemberCO; -import com.red.circle.other.app.dto.clientobject.team.TeamPolicyManagerCO; -import com.red.circle.other.app.dto.clientobject.team.TeamProfileSearchResCO; -import com.red.circle.other.app.dto.clientobject.team.TeamQuitApplyInfoCO; -import com.red.circle.other.app.dto.clientobject.team.TeamUserApplyRecordCO; -import com.red.circle.other.app.dto.clientobject.team.TeamWaitApplyMessageCO; +import com.red.circle.other.app.dto.clientobject.team.*; import com.red.circle.other.app.dto.cmd.team.DateTypeQryCmd; import com.red.circle.other.app.dto.cmd.team.TeamHandleUserApplyCmd; import com.red.circle.other.app.dto.cmd.team.TeamMemberRoleChangeCmd; @@ -129,7 +116,7 @@ public class TeamServiceImpl implements TeamService { } @Override - public Integer countTeamMember(AppIdLongCmd cmd) { + public TeamMemberCountResultCO countTeamMember(AppIdLongCmd cmd) { return teamMemberListQryExe.executeCount(cmd); } diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/team/TeamMemberCountResultCO.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/team/TeamMemberCountResultCO.java new file mode 100644 index 00000000..aa3a79bc --- /dev/null +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/dto/clientobject/team/TeamMemberCountResultCO.java @@ -0,0 +1,41 @@ +package com.red.circle.other.app.dto.clientobject.team; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import com.red.circle.framework.dto.ClientObject; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.experimental.Accessors; + +/** + * 团队成员统计结果. + * + * @author system + */ +@Data +@Accessors(chain = true) +@EqualsAndHashCode(callSuper = false) +public class TeamMemberCountResultCO extends ClientObject { + + /** + * 成员数量. + */ + private Integer memberQuantity; + + /** + * 等级(挡位). + */ + private Integer level; + + /** + * 目标总和格式化. + */ + private String targetFormatSum; + + /** + * 目标总和原始值. + */ + @JsonSerialize(using = ToStringSerializer.class) + private Long targetSum; + +} diff --git a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/team/TeamService.java b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/team/TeamService.java index 8102f9ff..89713057 100644 --- a/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/team/TeamService.java +++ b/rc-service/rc-service-other/other-client/src/main/java/com/red/circle/other/app/service/team/TeamService.java @@ -7,20 +7,7 @@ import com.red.circle.common.business.dto.cmd.app.AppIdLongCmd; import com.red.circle.common.business.dto.cmd.app.AppIdStringCmd; import com.red.circle.common.business.dto.cmd.app.AppRoomIdCmd; import com.red.circle.common.business.dto.cmd.app.AppUserIdCmd; -import com.red.circle.other.app.dto.clientobject.team.AnchorWorkStatisticsCO; -import com.red.circle.other.app.dto.clientobject.team.MemberEntryTeamCO; -import com.red.circle.other.app.dto.clientobject.team.TeamBillCO; -import com.red.circle.other.app.dto.clientobject.team.TeamBillMemberWorkCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberQuitAskCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberTargetSettlementResultCO; -import com.red.circle.other.app.dto.clientobject.team.TeamMemberWorkCO; -import com.red.circle.other.app.dto.clientobject.team.TeamOwnMemberCO; -import com.red.circle.other.app.dto.clientobject.team.TeamPolicyManagerCO; -import com.red.circle.other.app.dto.clientobject.team.TeamProfileSearchResCO; -import com.red.circle.other.app.dto.clientobject.team.TeamQuitApplyInfoCO; -import com.red.circle.other.app.dto.clientobject.team.TeamUserApplyRecordCO; -import com.red.circle.other.app.dto.clientobject.team.TeamWaitApplyMessageCO; +import com.red.circle.other.app.dto.clientobject.team.*; import com.red.circle.other.app.dto.cmd.team.DateTypeQryCmd; import com.red.circle.other.app.dto.cmd.team.TeamHandleUserApplyCmd; import com.red.circle.other.app.dto.cmd.team.TeamMemberRoleChangeCmd; @@ -63,7 +50,7 @@ public interface TeamService { /** * 团队成员数量 */ - Integer countTeamMember(AppIdLongCmd cmd); + TeamMemberCountResultCO countTeamMember(AppIdLongCmd cmd); /** * 获取我的团队成员.