|
@@ -14,6 +14,7 @@ import org.springframework.util.StringUtils;
|
|
|
import shop.alien.entity.store.*;
|
|
|
import shop.alien.entity.store.vo.LifePinglunVo;
|
|
|
import shop.alien.entity.store.vo.LifeUserDynamicsVo;
|
|
|
+import shop.alien.entity.store.vo.StoreCommentVo;
|
|
|
import shop.alien.mapper.*;
|
|
|
|
|
|
import java.util.*;
|
|
@@ -46,6 +47,8 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
|
|
|
private final StoreImgMapper storeImgMapper;
|
|
|
|
|
|
+ private final StoreCommentMapper storeCommentMapper;
|
|
|
+
|
|
|
public int addLiulanCount(String id) {
|
|
|
LambdaUpdateWrapper<LifeUserDynamics> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
lambdaUpdateWrapper.eq(LifeUserDynamics::getId, id);
|
|
@@ -99,44 +102,60 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
return lifePinglunVos.stream().collect(Collectors.groupingBy(LifePinglunVo::getHuifuId));
|
|
|
}
|
|
|
|
|
|
+ //
|
|
|
+ // 生成用户动态信息
|
|
|
+ // 该方法用于获取并处理用户的动态数据,包括过滤、排序和设置相关状态信息
|
|
|
+ //
|
|
|
+ // 参数:
|
|
|
+ // myself - "1"表示查询自己的动态,其他值表示非本人动态
|
|
|
+ // type - 动态类型,为空时返回所有类型
|
|
|
+ // isFollowed - "1"表示查询关注用户的动态
|
|
|
+ // phoneId - 用户标识,用于关联粉丝、点赞和黑名单信息
|
|
|
+ // 返回值:
|
|
|
+ // List<LifeUserDynamicsVo> - 处理后的用户动态列表,包含状态信息如是否关注、是否点赞等
|
|
|
+ //
|
|
|
public List<LifeUserDynamicsVo> getUserDynamics(String myself, String type, String isFollowed, String phoneId) {
|
|
|
- // 查询动态数据
|
|
|
+ // 查询动态数据并按类型过滤
|
|
|
List<LifeUserDynamicsVo> lifeUserDynamicsVoList = lifeUserDynamicsMapper.getLifeUserDynamicsList();
|
|
|
if (!StringUtils.isEmpty(type)) {
|
|
|
lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(item -> type.equals(item.getType())).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- // 查询我的关注
|
|
|
+ // 查询我的关注信息,构建关注者ID列表
|
|
|
LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<>();
|
|
|
lifeFansWrapper.eq(LifeFans::getFansId, phoneId);
|
|
|
List<LifeFans> lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
|
|
|
List<String> followList = lifeFansList.stream().map(LifeFans::getFollowedId).collect(Collectors.toList());
|
|
|
|
|
|
- // 查询我的粉丝
|
|
|
+ // 查询我的粉丝信息,构建粉丝ID列表
|
|
|
lifeFansWrapper = new LambdaQueryWrapper<>();
|
|
|
lifeFansWrapper.eq(LifeFans::getFollowedId, phoneId);
|
|
|
lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
|
|
|
List<String> fansList = lifeFansList.stream().map(LifeFans::getFansId).collect(Collectors.toList());
|
|
|
|
|
|
- // 查询我的点赞
|
|
|
+ // 查询我的点赞记录,构建点赞ID列表
|
|
|
LambdaQueryWrapper<LifeLikeRecord> likeWrapper = new LambdaQueryWrapper<>();
|
|
|
likeWrapper.eq(LifeLikeRecord::getDianzanId, phoneId);
|
|
|
likeWrapper.eq(LifeLikeRecord::getType, "2");
|
|
|
List<LifeLikeRecord> lifeLikeList = lifeLikeRecordMapper.selectList(likeWrapper);
|
|
|
List<String> likeList = lifeLikeList.stream().map(LifeLikeRecord::getHuifuId).collect(Collectors.toList());
|
|
|
|
|
|
- // 我自己的动态
|
|
|
+ // 根据myself参数过滤动态:自己或非本人动态
|
|
|
if ("1".equals(myself)) {
|
|
|
lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(item -> item.getPhoneId().equals(phoneId)).collect(Collectors.toList());
|
|
|
} else {
|
|
|
lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(item -> item.getDraft() == 0).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
- // 我的关注动态
|
|
|
+ // 如果isFollowed为"1",进一步过滤出关注用户的动态
|
|
|
if ("1".equals(isFollowed)) {
|
|
|
lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(item -> followList.contains(item.getPhoneId())).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
+ List<StoreCommentVo> rootCommitCount = storeCommentMapper.getRootCommitCount(2, null);
|
|
|
+ List<StoreCommentVo> sonCommitCount = storeCommentMapper.getSonCommitCount(2, null);
|
|
|
+
|
|
|
+ // 设置动态对象的状态信息:是否关注对方、是否被关注、是否点赞及评论数量
|
|
|
for (LifeUserDynamicsVo vo : lifeUserDynamicsVoList) {
|
|
|
if (followList.contains(vo.getPhoneId())) {
|
|
|
vo.setIsFollowThis("1");
|
|
@@ -153,11 +172,23 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
} else {
|
|
|
vo.setIsLike("0");
|
|
|
}
|
|
|
- vo.setCommentCount(Integer.parseInt(storeCommentService.getCommitCountAndScore(vo.getId(), 2, null).get("commitCount")));
|
|
|
+ List<StoreCommentVo> rootList = rootCommitCount.stream().filter(item -> Objects.equals(item.getBusinessId(), vo.getId())).collect(Collectors.toList());
|
|
|
+ if (rootList.isEmpty()) {
|
|
|
+ vo.setCommentCount(0);
|
|
|
+ } else {
|
|
|
+ Integer count = rootList.size();
|
|
|
+ for (StoreCommentVo storeCommentVo : rootList) {
|
|
|
+ List<StoreCommentVo> sonList = sonCommitCount.stream().filter(item -> Objects.equals(item.getReplyId(), storeCommentVo.getId())).collect(Collectors.toList());
|
|
|
+ if (!sonList.isEmpty()) {
|
|
|
+ count += sonList.get(0).getCommitCount();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ vo.setCommentCount(count);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ // 如果phoneId不为空,处理黑名单逻辑,过滤掉被拉黑用户的动态
|
|
|
if (!StringUtils.isEmpty(phoneId)) {
|
|
|
- // 过滤被拉黑的用户动态
|
|
|
// 通过phoneId查询userId
|
|
|
LifeUser myLifeUser = new LifeUser();
|
|
|
StoreUser myStoreUser = new StoreUser();
|
|
@@ -169,7 +200,7 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
|
|
|
}
|
|
|
|
|
|
- //查询拉黑的对象
|
|
|
+ // 查询拉黑的对象
|
|
|
LambdaQueryWrapper<LifeBlacklist> myLifeBlacklistWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
|
if (null != myLifeUser.getId()) {
|
|
@@ -181,39 +212,29 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
}
|
|
|
List<LifeBlacklist> lifeBlacklists = lifeBlacklistMapper.selectList(myLifeBlacklistWrapper);
|
|
|
|
|
|
-
|
|
|
// 按类型分组的黑名单用户ID映射(1: 商户, 2: 用户)
|
|
|
- Map<String, Set<String>> blockedUserIdsByType = lifeBlacklists.stream()
|
|
|
- .collect(Collectors.groupingBy(
|
|
|
- LifeBlacklist::getBlockedType,
|
|
|
- Collectors.mapping(LifeBlacklist::getBlockedId, Collectors.toSet())
|
|
|
- ));
|
|
|
+ Map<String, Set<String>> blockedUserIdsByType = lifeBlacklists.stream().collect(Collectors.groupingBy(LifeBlacklist::getBlockedType, Collectors.mapping(LifeBlacklist::getBlockedId, Collectors.toSet())));
|
|
|
|
|
|
// 过滤掉发布者在黑名单中的动态
|
|
|
- lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream()
|
|
|
- .filter(dynamics -> {
|
|
|
- String blackPhoneId = dynamics.getPhoneId();
|
|
|
- String userId = dynamics.getStoreOrUserId();
|
|
|
-
|
|
|
- // 确定用户类型(根据phoneId前缀)
|
|
|
- String userType = blackPhoneId.startsWith("store") ? "1" :
|
|
|
- (blackPhoneId.startsWith("user") ? "2" : "0");
|
|
|
-
|
|
|
- // 如果无法识别类型或不在黑名单中,保留该动态
|
|
|
- if ("0".equals(userType) || !blockedUserIdsByType.containsKey(userType)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // 检查用户是否在对应类型的黑名单中
|
|
|
- return !blockedUserIdsByType.get(userType).contains(userId);
|
|
|
- })
|
|
|
- .collect(Collectors.toList());
|
|
|
- }
|
|
|
+ lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(dynamics -> {
|
|
|
+ String blackPhoneId = dynamics.getPhoneId();
|
|
|
+ String userId = dynamics.getStoreOrUserId();
|
|
|
|
|
|
+ // 确定用户类型(根据phoneId前缀)
|
|
|
+ String userType = blackPhoneId.startsWith("store") ? "1" : (blackPhoneId.startsWith("user") ? "2" : "0");
|
|
|
|
|
|
- lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream()
|
|
|
- .sorted(Comparator.comparing(LifeUserDynamicsVo::getCreatedTime).reversed())
|
|
|
- .collect(Collectors.toList());
|
|
|
+ // 如果无法识别类型或不在黑名单中,保留该动态
|
|
|
+ if ("0".equals(userType) || !blockedUserIdsByType.containsKey(userType)) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查用户是否在对应类型的黑名单中
|
|
|
+ return !blockedUserIdsByType.get(userType).contains(userId);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 最后按照创建时间倒序排序
|
|
|
+ lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().sorted(Comparator.comparing(LifeUserDynamicsVo::getCreatedTime).reversed()).collect(Collectors.toList());
|
|
|
|
|
|
return lifeUserDynamicsVoList;
|
|
|
}
|
|
@@ -273,8 +294,7 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
|
|
|
// 判断 targetPhone 是否在 fansList 中 1 已关注 0 未关注
|
|
|
// 处理 fansList
|
|
|
- fansList = lifeFansList.stream()
|
|
|
- .map(LifeFans::getFansId)
|
|
|
+ fansList = lifeFansList.stream().map(LifeFans::getFansId)
|
|
|
// .map(id -> id.split("_")[id.split("_").length - 1])
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
@@ -296,6 +316,15 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
LifeUser lifeUser = new LifeUser();
|
|
|
StoreUser storeUser = new StoreUser();
|
|
|
|
|
|
+ String[] split = myselfPhoneId.split("_");
|
|
|
+// if ("store".equals(split[0])) {
|
|
|
+// // 添加商户用户头像
|
|
|
+// StoreUser storeUserByPhone = storeUserService.getUserByPhone(split[1]);
|
|
|
+// StoreImg storeImg = storeImgMapper.selectOne(new LambdaQueryWrapper<StoreImg>().eq(StoreImg::getStoreId, storeUserByPhone.getId()).eq(StoreImg::getImgType, "10").eq(StoreImg::getDeleteFlag, "0"));
|
|
|
+// if (storeImg != null) {
|
|
|
+// resultMap.put("storeUserImg", storeImg.getImgUrl());
|
|
|
+// }
|
|
|
+// }
|
|
|
if ("user".equals(phoneId.split("_")[0])) {
|
|
|
String userPhone = phoneId.split("_")[1];
|
|
|
lifeUser = lifeUserService.getUserByPhone(userPhone);
|
|
@@ -304,15 +333,9 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
String storePhone = phoneId.split("_")[1];
|
|
|
storeUser = storeUserService.getUserByPhone(storePhone);
|
|
|
resultMap.put("storeUser", storeUser);
|
|
|
- // 添加商户用户头像
|
|
|
- StoreImg storeImg = storeImgMapper.selectOne(new LambdaQueryWrapper<StoreImg>()
|
|
|
- .eq(StoreImg::getStoreId, storeUser.getStoreId())
|
|
|
- .eq(StoreImg::getImgType, "10")
|
|
|
- .eq(StoreImg::getDeleteFlag, "0"));
|
|
|
- if (storeImg != null) {
|
|
|
- resultMap.put("storeUserImg", storeImg.getImgUrl());
|
|
|
- }
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
//查询是否已拉黑
|
|
|
LambdaQueryWrapper<LifeBlacklist> lifeBlacklistWrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
@@ -365,10 +388,7 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
|
|
|
dynamicsVo.setIsLike("0");
|
|
|
}
|
|
|
// 根据store_comment 表 business_id 查询评论数量
|
|
|
- int commentCount = storeCommentService.count(new QueryWrapper<StoreComment>()
|
|
|
- .eq("business_id", dynamicsVo.getId())
|
|
|
- .eq("delete_flag", "0")
|
|
|
- .eq("comment_type", "1"));
|
|
|
+ int commentCount = storeCommentService.count(new QueryWrapper<StoreComment>().eq("business_id", dynamicsVo.getId()).eq("delete_flag", "0").eq("comment_type", "1"));
|
|
|
dynamicsVo.setCommentCount(commentCount);
|
|
|
String phoneId1 = dynamicsVo.getPhoneId();
|
|
|
String storeUserId = "";
|