From c0183887da1d5e12fd4b205565253d7dfafe084b Mon Sep 17 00:00:00 2001 From: khalil <842328916@qq.com> Date: Thu, 14 Aug 2025 19:29:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=90=8E=E5=8F=B0=E7=BB=9F=E8=AE=A1-=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1-=E5=85=AC=E4=BC=9A-=E5=85=AC=E4=BC=9A=E9=95=BF?= =?UTF-8?q?=E5=9B=BD=E5=AE=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../business/dto/WeekActiveGuildStat.java | 8 +- .../service/WeekGuildStatService.java | 260 +++++++----------- 2 files changed, 111 insertions(+), 157 deletions(-) diff --git a/accompany-business/accompany-business-sdk/src/main/java/com/accompany/business/dto/WeekActiveGuildStat.java b/accompany-business/accompany-business-sdk/src/main/java/com/accompany/business/dto/WeekActiveGuildStat.java index 000d06773..de0acc04f 100644 --- a/accompany-business/accompany-business-sdk/src/main/java/com/accompany/business/dto/WeekActiveGuildStat.java +++ b/accompany-business/accompany-business-sdk/src/main/java/com/accompany/business/dto/WeekActiveGuildStat.java @@ -14,8 +14,14 @@ public class WeekActiveGuildStat { private Integer partitionId; private Integer guildId; + private Long ownerUid; @TableField(exist = false) - private Long ownErbanNo; + private Long ownerErbanNo; + @TableField(exist = false) + private Integer ownerRegionId; + @TableField(exist = false) + private String ownerRegionName; + @TableField(exist = false) private String groupByKey; diff --git a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/WeekGuildStatService.java b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/WeekGuildStatService.java index 2ef2b23b5..b37477ff4 100644 --- a/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/WeekGuildStatService.java +++ b/accompany-business/accompany-business-service/src/main/java/com/accompany/business/service/WeekGuildStatService.java @@ -1,20 +1,22 @@ package com.accompany.business.service; import com.accompany.business.dto.WeekActiveGuildStat; +import com.accompany.business.model.Hall; import com.accompany.business.model.WeekGuildStat; import com.accompany.business.model.family.Family; +import com.accompany.business.model.guild.Guild; import com.accompany.business.mybatismapper.WeekGuildStatMapper; import com.accompany.business.mybatismapper.WeekActiveGuildStatMapper; import com.accompany.business.service.family.FamilyService; import com.accompany.business.service.guild.GuildService; import com.accompany.business.service.hall.HallService; -import com.accompany.business.vo.family.SimpleFamilyMemberVo; -import com.accompany.business.vo.guild.AgencyOwnerVo; -import com.accompany.business.vo.hall.HallVo; +import com.accompany.business.service.user.UsersService; +import com.accompany.common.constant.Constant; import com.accompany.common.model.PageReq; import com.accompany.common.utils.DateTimeUtil; -import com.accompany.common.utils.StringUtils; import com.accompany.core.enumeration.PartitionEnum; +import com.accompany.core.model.Users; +import com.accompany.core.service.region.RegionInfoService; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -47,6 +49,10 @@ public class WeekGuildStatService { private FamilyService familyService; @Autowired private HallService hallService; + @Autowired + private RegionInfoService regionInfoService; + @Autowired + private UsersService usersService; public void stat(String monday) { stat(monday, true); @@ -165,36 +171,106 @@ public class WeekGuildStatService { Map> activeGuildPartitionMap = activeGuildStatList.stream().collect(Collectors.groupingBy(WeekActiveGuildStat::getPartitionId)); - List enActiveGuildList = activeGuildPartitionMap.getOrDefault(PartitionEnum.ENGLISH.getId(), Collections.emptyList()) - .stream().sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()).collect(Collectors.toList()); + List enActiveGuildList = buildActiveCountDetail(activeGuildPartitionMap, PartitionEnum.ENGLISH.getId()); stat.setEnActiveCount(enActiveGuildList.size()); stat.setEnActiveCountDetail(JSON.toJSONString(enActiveGuildList)); - List arActiveGuildList = activeGuildPartitionMap.getOrDefault(PartitionEnum.ARAB.getId(), Collections.emptyList()) - .stream().sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()).collect(Collectors.toList());; + List arActiveGuildList = buildActiveCountDetail(activeGuildPartitionMap, PartitionEnum.ARAB.getId()); stat.setArActiveCount(arActiveGuildList.size()); stat.setArActiveCountDetail(JSON.toJSONString(arActiveGuildList)); - List zhActiveGuildList = activeGuildPartitionMap.getOrDefault(PartitionEnum.CHINESE.getId(), Collections.emptyList()) - .stream().sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()).collect(Collectors.toList());; + List zhActiveGuildList = buildActiveCountDetail(activeGuildPartitionMap, PartitionEnum.CHINESE.getId()); stat.setZhActiveCount(zhActiveGuildList.size()); stat.setZhActiveCountDetail(JSON.toJSONString(zhActiveGuildList)); - List trActiveGuildList = activeGuildPartitionMap.getOrDefault(PartitionEnum.TURKEY.getId(), Collections.emptyList()) - .stream().sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()).collect(Collectors.toList());; + List trActiveGuildList = buildActiveCountDetail(activeGuildPartitionMap, PartitionEnum.TURKEY.getId()); stat.setTrActiveCount(trActiveGuildList.size()); stat.setTrActiveCountDetail(JSON.toJSONString(trActiveGuildList)); - List en2ActiveGuildList = activeGuildPartitionMap.getOrDefault(PartitionEnum.ENGLISH2.getId(), Collections.emptyList()) - .stream().sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()).collect(Collectors.toList());; + List en2ActiveGuildList = buildActiveCountDetail(activeGuildPartitionMap, PartitionEnum.ENGLISH2.getId()); stat.setEn2ActiveCount(en2ActiveGuildList.size()); stat.setEn2ActiveCountDetail(JSON.toJSONString(en2ActiveGuildList)); guildWeekPlatformStatMapper.insertOrUpdate(stat); } + private List buildActiveCountDetail(Map> activeGuildPartitionMap, Integer partitionId) { + if (!activeGuildPartitionMap.containsKey(partitionId)){ + return Collections.emptyList(); + } + + List detailList = activeGuildPartitionMap.get(partitionId); + + Map ownerUidMap = new HashMap<>(); + + List guildIdList = detailList.stream().map(WeekActiveGuildStat::getGuildId).distinct().toList(); + if (!CollectionUtils.isEmpty(guildIdList)){ + PartitionEnum partitionEnum = PartitionEnum.getByPartitionId(partitionId); + if (Constant.ClanMode.CLAN_HALL.equals(partitionEnum.getClanMode())){ + List hallList = hallService.listHallByIds(guildIdList.stream().map(Integer::longValue).toList()); + hallList.forEach(hall->{ + ownerUidMap.put(hall.getId().intValue(), hall.getOwnerUid()); + }); + } else if (Constant.ClanMode.FAMILY.equals(partitionEnum.getClanMode())) { + List familyList = familyService.listByIds(guildIdList); + familyList.forEach(family->{ + ownerUidMap.put(family.getId(), family.getOwnerUid()); + }); + } else if (Constant.ClanMode.GUILD.equals(partitionEnum.getClanMode()) || Constant.ClanMode.GUILD_POLICY2.equals(partitionEnum.getClanMode())) { + List guildList = guildService.listByIds(guildIdList); + guildList.forEach(guild->{ + ownerUidMap.put(guild.getId(), guild.getOwnerUid()); + }); + } + } + + Map ownerUserMap = usersService.getUsersMapByUids(ownerUidMap.values().stream().toList()); + + Map regionNameMap = regionInfoService.getRegionName(); + + return detailList.stream().peek(item->{ + Long ownerUid = ownerUidMap.get(item.getGuildId()); + if (null != ownerUid){ + Users ownerUser = ownerUserMap.get(ownerUid); + if (ownerUser != null){ + item.setOwnerRegionId(ownerUser.getRegionId()); + item.setOwnerRegionName(regionNameMap.get(ownerUser.getRegionId())); + item.setOwnerUid(ownerUser.getUid()); + item.setOwnerErbanNo(ownerUser.getErbanNo()); + } + } + }).sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()).collect(Collectors.toList()); + } + private List buildNewCountDetail(Map> newGuildCountMap, Map activeGuildStatMap, Integer partitionId, String monday, String sunday){ + Map ownerUidMap = new HashMap<>(); + + List guildIdList = newGuildCountMap.containsKey(partitionId)? newGuildCountMap.get(partitionId).stream().map(key->Long.parseLong(key.split("_")[1])).distinct().toList():Collections.emptyList(); + if (!CollectionUtils.isEmpty(guildIdList)){ + PartitionEnum partitionEnum = PartitionEnum.getByPartitionId(partitionId); + if (Constant.ClanMode.CLAN_HALL.equals(partitionEnum.getClanMode())){ + List hallList = hallService.listHallByIds(guildIdList); + hallList.forEach(hall->{ + ownerUidMap.put(hall.getId().intValue(), hall.getOwnerUid()); + }); + } else if (Constant.ClanMode.FAMILY.equals(partitionEnum.getClanMode())) { + List familyList = familyService.listByIds(guildIdList); + familyList.forEach(family->{ + ownerUidMap.put(family.getId(), family.getOwnerUid()); + }); + } else if (Constant.ClanMode.GUILD.equals(partitionEnum.getClanMode()) || Constant.ClanMode.GUILD_POLICY2.equals(partitionEnum.getClanMode())) { + List guildList = guildService.listByIds(guildIdList); + guildList.forEach(guild->{ + ownerUidMap.put(guild.getId(), guild.getOwnerUid()); + }); + } + } + + Map ownerUserMap = usersService.getUsersMapByUids(ownerUidMap.values().stream().toList()); + + Map regionNameMap = regionInfoService.getRegionName(); + return newGuildCountMap.containsKey(partitionId)? newGuildCountMap.get(partitionId).stream().map(key->{ WeekActiveGuildStat item = activeGuildStatMap.get(key); @@ -210,8 +286,20 @@ public class WeekGuildStatService { item.setGuildGoldFlow(BigDecimal.ZERO); return item; } + return item; - }).sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()) + }).peek(item->{ + Long ownerUid = ownerUidMap.get(item.getGuildId()); + if (null != ownerUid){ + Users ownerUser = ownerUserMap.get(ownerUid); + if (null != ownerUser){ + item.setOwnerErbanNo(ownerUser.getErbanNo()); + item.setOwnerRegionId(ownerUser.getRegionId()); + item.setOwnerRegionName(regionNameMap.get(ownerUser.getRegionId())); + } + } + + }).sorted(Comparator.comparing(WeekActiveGuildStat::getGuildDiamondFlow).reversed()) .collect(Collectors.toList()): Collections.emptyList(); } @@ -224,147 +312,7 @@ public class WeekGuildStatService { Page page = new Page<>(pageReq.getPage(), pageReq.getPageSize()); QueryWrapper queryWrapper = new QueryWrapper<>(); queryWrapper.lambda().orderByDesc(WeekGuildStat::getDate); - Page weekGuildStatPage = guildWeekPlatformStatMapper.selectPage(page, queryWrapper); - List records = weekGuildStatPage.getRecords(); - if (CollectionUtils.isEmpty(records)) { - return weekGuildStatPage; - } - Map guildMap = guildService.getAgencyOwnerMapByHallIds(null); - Map familyMap = familyService.getOwnerUserMap(null); - Map hallMap = hallService.mapHallByIds(null); - for (WeekGuildStat record : records) { - try { - String enNewCountDetail = record.getEnNewCountDetail(); - if (StringUtils.isNotEmpty(enNewCountDetail)) { - List enNewCountDetailList = JSON.parseArray(enNewCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : enNewCountDetailList) { - SimpleFamilyMemberVo memberVo = familyMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setEnNewCountDetail(JSON.toJSONString(enNewCountDetailList)); - } - - String arNewCountDetail = record.getArNewCountDetail(); - if (StringUtils.isNotEmpty(arNewCountDetail)) { - List arNewCountDetailList = JSON.parseArray(arNewCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : arNewCountDetailList) { - AgencyOwnerVo memberVo = guildMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setArNewCountDetail(JSON.toJSONString(arNewCountDetailList)); - } - - String zhNewCountDetail = record.getZhNewCountDetail(); - if (StringUtils.isNotEmpty(zhNewCountDetail)) { - List zhNewCountDetailList = JSON.parseArray(zhNewCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : zhNewCountDetailList) { - HallVo memberVo = hallMap.get(weekActiveGuildStat.getGuildId().longValue()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getOwnerErbanNo()); - } - } - record.setZhNewCountDetail(JSON.toJSONString(zhNewCountDetailList)); - } - - String trNewCountDetail = record.getTrNewCountDetail(); - if (StringUtils.isNotEmpty(trNewCountDetail)) { - List trNewCountDetailList = JSON.parseArray(trNewCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : trNewCountDetailList) { - AgencyOwnerVo memberVo = guildMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setTrNewCountDetail(JSON.toJSONString(trNewCountDetailList)); - } - - String en2NewCountDetail = record.getEn2NewCountDetail(); - if (StringUtils.isNotEmpty(en2NewCountDetail)) { - List en2NewCountDetailList = JSON.parseArray(en2NewCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : en2NewCountDetailList) { - if (weekActiveGuildStat.getGuildId() == null) { - continue; - } - AgencyOwnerVo memberVo = guildMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setEn2NewCountDetail(JSON.toJSONString(en2NewCountDetailList)); - } -//----------------------- - String enActiveCountDetail = record.getEnActiveCountDetail(); - if (StringUtils.isNotEmpty(enActiveCountDetail)) { - List enActiveGuildList = JSON.parseArray(enActiveCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : enActiveGuildList) { - SimpleFamilyMemberVo memberVo = familyMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setEnActiveCountDetail(JSON.toJSONString(enActiveGuildList)); - } - - String arActiveCountDetail = record.getArActiveCountDetail(); - if (StringUtils.isNotEmpty(arActiveCountDetail)) { - List arActiveGuildList = JSON.parseArray(arActiveCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : arActiveGuildList) { - AgencyOwnerVo memberVo = guildMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setArActiveCountDetail(JSON.toJSONString(arActiveGuildList)); - } - - String zhActiveCountDetail = record.getZhActiveCountDetail(); - if (StringUtils.isNotEmpty(zhActiveCountDetail)) { - List zhActiveGuildList = JSON.parseArray(zhActiveCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : zhActiveGuildList) { - HallVo memberVo = hallMap.get(weekActiveGuildStat.getGuildId().longValue()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getOwnerErbanNo()); - } - } - record.setZhActiveCountDetail(JSON.toJSONString(zhActiveGuildList)); - } - - - String trActiveCountDetail = record.getTrActiveCountDetail(); - if (StringUtils.isNotEmpty(trActiveCountDetail)) { - List trActiveGuildList = JSON.parseArray(trActiveCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : trActiveGuildList) { - AgencyOwnerVo memberVo = guildMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setTrActiveCountDetail(JSON.toJSONString(trActiveGuildList)); - } - - String en2ActiveCountDetail = record.getEn2ActiveCountDetail(); - if (StringUtils.isNotEmpty(en2ActiveCountDetail)) { - List en2ActiveGuildList = JSON.parseArray(en2ActiveCountDetail, WeekActiveGuildStat.class); - for (WeekActiveGuildStat weekActiveGuildStat : en2ActiveGuildList) { - if (weekActiveGuildStat.getGuildId() == null) { - continue; - } - AgencyOwnerVo memberVo = guildMap.get(weekActiveGuildStat.getGuildId()); - if (memberVo != null) { - weekActiveGuildStat.setOwnErbanNo(memberVo.getErbanNo()); - } - } - record.setEn2ActiveCountDetail(JSON.toJSONString(en2ActiveGuildList)); - } - } catch (Exception e) { - log.error("WeekGuildStatService.pageWeekGuildStat,e:{}", e.getMessage(), e); - } - } - return weekGuildStatPage; + return guildWeekPlatformStatMapper.selectPage(page, queryWrapper); } }