Commit 59e10824 by 林永健

refactor(service): 优化关注人信息填充逻辑

- 增加参数排除当前登录员工,避免关注人列表中显示自己
- 将关注人信息从仅姓名扩展为完整对象以便更多筛选条件
- 过滤空姓名及排除指定UUID的员工
- 改进关注人姓名去重与拼接方式
- 保持原有功能的逻辑完整性及性能稳定
1 parent 739a6e3f
...@@ -218,7 +218,7 @@ public class MerchantBiFollowService { ...@@ -218,7 +218,7 @@ public class MerchantBiFollowService {
long startMs = System.currentTimeMillis(); long startMs = System.currentTimeMillis();
// 0) 关注人信息 & 最近一条策略摘要(最近一个月内) // 0) 关注人信息 & 最近一条策略摘要(最近一个月内)
fillFollowerAndComment(resList); fillFollowerAndComment(resList, req.getLoginUserUuid());
// 1) 门店基础信息:主营品牌、省市等(来自账户中心) // 1) 门店基础信息:主营品牌、省市等(来自账户中心)
merchantBasicInfoService.fillFollowListMerchantInfo(resList); merchantBasicInfoService.fillFollowListMerchantInfo(resList);
...@@ -260,7 +260,7 @@ public class MerchantBiFollowService { ...@@ -260,7 +260,7 @@ public class MerchantBiFollowService {
log.info("关注列表填充完成:关注条数={}, 耗时={}ms", resList.size(), System.currentTimeMillis() - startMs); log.info("关注列表填充完成:关注条数={}, 耗时={}ms", resList.size(), System.currentTimeMillis() - startMs);
} }
private void fillFollowerAndComment(List<MyFollowResponse> resList) { private void fillFollowerAndComment(List<MyFollowResponse> resList, String excludeStaffUuid) {
if (CollectionUtils.isEmpty(resList)) { if (CollectionUtils.isEmpty(resList)) {
return; return;
} }
...@@ -284,16 +284,13 @@ public class MerchantBiFollowService { ...@@ -284,16 +284,13 @@ public class MerchantBiFollowService {
.collect(Collectors.toMap(f -> f.getMerchantId() + "_" + f.getBusinessType(), f -> f, (f1, f2) -> f1)); .collect(Collectors.toMap(f -> f.getMerchantId() + "_" + f.getBusinessType(), f -> f, (f1, f2) -> f1));
List<Integer> followIds = follows.stream().map(MerchantBiFollow::getId).filter(Objects::nonNull).collect(Collectors.toList()); List<Integer> followIds = follows.stream().map(MerchantBiFollow::getId).filter(Objects::nonNull).collect(Collectors.toList());
// 2) 批量查询关注人姓名(按 followId 聚合) // 2) 批量查询关注人信息(按 followId 聚合)
Map<Integer, List<String>> followerNamesMap = new HashMap<>(); Map<Integer, List<MerchantBiFollowDetail>> followersMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(followIds)) { if (CollectionUtils.isNotEmpty(followIds)) {
List<MerchantBiFollowDetail> allDetails = followDetailMapper.findFollowersByFollowIds(followIds); List<MerchantBiFollowDetail> allDetails = followDetailMapper.findFollowersByFollowIds(followIds);
if (CollectionUtils.isNotEmpty(allDetails)) { if (CollectionUtils.isNotEmpty(allDetails)) {
followerNamesMap = allDetails.stream() followersMap = allDetails.stream()
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(MerchantBiFollowDetail::getFollowId));
MerchantBiFollowDetail::getFollowId,
Collectors.mapping(MerchantBiFollowDetail::getStaffName, Collectors.toList())
));
} }
} }
...@@ -331,10 +328,19 @@ public class MerchantBiFollowService { ...@@ -331,10 +328,19 @@ public class MerchantBiFollowService {
String key = res.getStoreId() + "_" + res.getBusinessType(); String key = res.getStoreId() + "_" + res.getBusinessType();
MerchantBiFollow follow = followMap.get(key); MerchantBiFollow follow = followMap.get(key);
if (follow != null) { if (follow != null) {
List<String> names = followerNamesMap.get(follow.getId()); List<MerchantBiFollowDetail> details = followersMap.get(follow.getId());
if (CollectionUtils.isNotEmpty(names)) { if (CollectionUtils.isNotEmpty(details)) {
LinkedHashSet<String> uniqueNames = names.stream() // 过滤掉需要排除的员工(当前登录用户自己),然后获取姓名列表
.filter(StringUtils::isNotBlank) LinkedHashSet<String> uniqueNames = details.stream()
.filter(detail -> StringUtils.isNotBlank(detail.getStaffName()))
.filter(detail -> {
// 如果传入了需要排除的员工 UUID,则过滤掉该员工
if (StringUtils.isNotBlank(excludeStaffUuid)) {
return !excludeStaffUuid.equals(detail.getStaffUuid());
}
return true;
})
.map(MerchantBiFollowDetail::getStaffName)
.collect(Collectors.toCollection(LinkedHashSet::new)); .collect(Collectors.toCollection(LinkedHashSet::new));
res.setFollowerCount(uniqueNames.size()); res.setFollowerCount(uniqueNames.size());
res.setFollowerNames(String.join("/", uniqueNames)); res.setFollowerNames(String.join("/", uniqueNames));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!