Parcourir la source

/stores/getMyFollowed
/stores/getMyFans
/fans/getFriends
/fans/getFollowStatus
/user/getStoreAndUserByName 完成粉丝连表查询

lutong il y a 2 heures
Parent
commit
7c902428be

+ 46 - 12
alien-entity/src/main/java/shop/alien/mapper/LifeFansMapper.java

@@ -23,7 +23,11 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    with follow as (   " +
             "        select substring_index(followed_id, '_', 1) as flag, substring_index(followed_id, '_', -1) as phone, created_time   " +
             "        from life_fans   " +
-            "        where delete_flag = 0 and fans_id = #{fansId} " +
+            "        where delete_flag = 0 and (fans_id = #{fansId} " +
+            "<if test=\"identityUserType != null and identityRefId != null\">" +
+            "        or (fans_user_type = #{identityUserType} and fans_ref_id = #{identityRefId}) " +
+            "</if>" +
+            ") " +
             "    )   " +
             "    select info.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS NAME," +
             "    user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId ,IFNULL(user.nick_name, user.name) username, user.account_blurb accountBlurb, IF(info.store_application_status = 1, '1', '0') AS isMerchant, foll.created_time " +
@@ -40,19 +44,32 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    where foll.flag = 'user' and user.delete_flag = 0   " +
             "</if>" +
             ") foll   " +
-            "left join life_fans fans on fans.fans_id = foll.phoneId and fans.followed_id = #{relationFansId} and fans.delete_flag = 0 " +
-            "left join life_fans fans_this on fans_this.fans_id = #{relationFansId} and fans_this.followed_id = foll.phoneId and fans_this.delete_flag = 0 " +
+            "left join life_fans fans on fans.fans_id = foll.phoneId and fans.delete_flag = 0 and (fans.followed_id = #{relationFansId} " +
+            "<if test=\"relationIdentityUserType != null and relationIdentityRefId != null\">" +
+            " or (fans.followed_user_type = #{relationIdentityUserType} and fans.followed_ref_id = #{relationIdentityRefId})" +
+            "</if>" +
+            ") " +
+            "left join life_fans fans_this on fans_this.followed_id = foll.phoneId and fans_this.delete_flag = 0 and (fans_this.fans_id = #{relationFansId} " +
+            "<if test=\"relationIdentityUserType != null and relationIdentityRefId != null\">" +
+            " or (fans_this.fans_user_type = #{relationIdentityUserType} and fans_this.fans_ref_id = #{relationIdentityRefId})" +
+            "</if>" +
+            ") " +
             "left join life_blacklist lb on lb.blocked_type = foll.blockedType and lb.blocked_id = foll.blockedId and lb.blocker_type = #{blockerType} and lb.blocker_id = #{blockerId} and lb.delete_flag = 0 " +
             "${ew.customSqlSegment} " +
             "</script>")
-    IPage<LifeFansVo> getMyFollowed(IPage<LifeFansVo> iPage, @Param("fansId") String fansId, @Param("relationFansId") String relationFansId, @Param("blockerType") String blockerType, @Param("blockerId") String blockerId, @Param("onlyStoreFollowed") boolean onlyStoreFollowed, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> wrapper);
+    IPage<LifeFansVo> getMyFollowed(IPage<LifeFansVo> iPage, @Param("fansId") String fansId, @Param("identityUserType") Integer identityUserType, @Param("identityRefId") Integer identityRefId, @Param("relationFansId") String relationFansId, @Param("relationIdentityUserType") Integer relationIdentityUserType, @Param("relationIdentityRefId") Integer relationIdentityRefId, @Param("blockerType") String blockerType, @Param("blockerId") String blockerId, @Param("onlyStoreFollowed") boolean onlyStoreFollowed, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> wrapper);
 
 
-    @Select("select foll.*, if(isnull(fans.id), 0, 1) isFollowMe, 1 as isFollowThis from ( " +
+    @Select("<script>" +
+            "select foll.*, if(isnull(fans.id), 0, 1) isFollowMe, 1 as isFollowThis from ( " +
             "    with follow as (   " +
             "        select substring_index(followed_id, '_', 1) as flag, substring_index(followed_id, '_', -1) as phone   " +
             "        from life_fans   " +
-            "        where delete_flag = 0 and fans_id = #{fansId} " +
+            "        where delete_flag = 0 and (fans_id = #{fansId} " +
+            "<if test=\"identityUserType != null and identityRefId != null\">" +
+            "        or (fans_user_type = #{identityUserType} and fans_ref_id = #{identityRefId}) " +
+            "</if>" +
+            ") " +
             "    )   " +
             "    select info.id, info.store_name name, img.img_url image, concat('store_', user.phone) phoneId " +
             "    from follow foll " +
@@ -66,8 +83,13 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    join life_user user on foll.phone = user.user_phone   " +
             "    where foll.flag = 'user' and user.delete_flag = 0   " +
             ") foll " +
-            "left join life_fans fans on fans.fans_id = foll.phoneId and fans.followed_id = #{fansId} and fans.delete_flag = 0 ")
-    List<LifeFansVo> getMyFollowedAll(@Param("fansId") String fansId);
+            "left join life_fans fans on fans.fans_id = foll.phoneId and fans.delete_flag = 0 and (fans.followed_id = #{fansId} " +
+            "<if test=\"identityUserType != null and identityRefId != null\">" +
+            " or (fans.followed_user_type = #{identityUserType} and fans.followed_ref_id = #{identityRefId})" +
+            "</if>" +
+            ") " +
+            "</script>")
+    List<LifeFansVo> getMyFollowedAll(@Param("fansId") String fansId, @Param("identityUserType") Integer identityUserType, @Param("identityRefId") Integer identityRefId);
 
     @Select("<script>" +
             "select MAX(foll.id) id, MAX(foll.name) name, MAX(foll.image) image, foll.phoneId, MAX(foll.blurb) blurb, MAX(foll.blockedType) blockedType, MAX(foll.blockedId) blockedId, MAX(foll.isMerchant) isMerchant, MAX(foll.created_time) created_time, " +
@@ -78,7 +100,11 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    with follow as ( " +
             "        select substring_index(fans_id, '_', 1) as flag, substring_index(fans_id, '_', -1) as phone, created_time " +
             "        from life_fans " +
-            "        where delete_flag = 0 and followed_id = #{fansId} " +
+            "        where delete_flag = 0 and (followed_id = #{fansId} " +
+            "<if test=\"identityUserType != null and identityRefId != null\">" +
+            "        or (followed_user_type = #{identityUserType} and followed_ref_id = #{identityRefId}) " +
+            "</if>" +
+            ") " +
             "    ) " +
             "    select user.id, IF(info.store_application_status = 0, user.nick_name, info.store_name) AS name, user.head_img image, concat('store_', user.phone) phoneId, IF(info.store_application_status = 0, user.account_blurb, info.store_blurb) AS blurb, 1 blockedType,user.id blockedId, IF(info.store_application_status = 1, '1', '0') AS isMerchant, foll.created_time " +
             "    from follow foll " +
@@ -94,12 +120,20 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    where foll.flag = 'user' and user.delete_flag = 0 " +
             "</if>" +
             ") foll " +
-            "left join life_fans fans on fans.followed_id = foll.phoneId and fans.fans_id = #{relationFansId} and fans.delete_flag = 0 " +
-            "left join life_fans fans_me on fans_me.fans_id = foll.phoneId and fans_me.followed_id = #{relationFansId} and fans_me.delete_flag = 0 " +
+            "left join life_fans fans on fans.followed_id = foll.phoneId and fans.delete_flag = 0 and (fans.fans_id = #{relationFansId} " +
+            "<if test=\"relationIdentityUserType != null and relationIdentityRefId != null\">" +
+            " or (fans.fans_user_type = #{relationIdentityUserType} and fans.fans_ref_id = #{relationIdentityRefId})" +
+            "</if>" +
+            ") " +
+            "left join life_fans fans_me on fans_me.fans_id = foll.phoneId and fans_me.delete_flag = 0 and (fans_me.followed_id = #{relationFansId} " +
+            "<if test=\"relationIdentityUserType != null and relationIdentityRefId != null\">" +
+            " or (fans_me.followed_user_type = #{relationIdentityUserType} and fans_me.followed_ref_id = #{relationIdentityRefId})" +
+            "</if>" +
+            ") " +
             "left join life_blacklist lb on lb.blocked_type = foll.blockedType and lb.blocked_id = foll.blockedId and lb.blocker_type = #{blockerType} and lb.blocker_id = #{blockerId} and lb.delete_flag = 0 " +
             "${ew.customSqlSegment} " +
             "</script>")
-    IPage<LifeFansVo> getMyFans(IPage<LifeFansVo> iPage, @Param("fansId") String fansId, @Param("relationFansId") String relationFansId, @Param("blockerType") String blockerType, @Param("blockerId") String blockerId, @Param("onlyStoreFans") boolean onlyStoreFans, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> wrapper);
+    IPage<LifeFansVo> getMyFans(IPage<LifeFansVo> iPage, @Param("fansId") String fansId, @Param("identityUserType") Integer identityUserType, @Param("identityRefId") Integer identityRefId, @Param("relationFansId") String relationFansId, @Param("relationIdentityUserType") Integer relationIdentityUserType, @Param("relationIdentityRefId") Integer relationIdentityRefId, @Param("blockerType") String blockerType, @Param("blockerId") String blockerId, @Param("onlyStoreFans") boolean onlyStoreFans, @Param(Constants.WRAPPER) QueryWrapper<LifeFansVo> wrapper);
 
 //    @Select("select foll.*, if(isnull(fans.id), 0, 1) isFollowThis, 1 as isFollowMe, count(fans2.id) fansNum, count(fans3.id) followNum from ( " +
 //            "    with follow as ( " +

+ 31 - 6
alien-store/src/main/java/shop/alien/store/service/LifeStoreService.java

@@ -18,7 +18,9 @@ import shop.alien.entity.store.vo.LifeUserVo;
 import shop.alien.entity.store.vo.StoreInfoVo;
 import shop.alien.mapper.*;
 import shop.alien.store.config.BaseRedisService;
+import shop.alien.store.util.LifeFansIdentityQuery;
 import shop.alien.util.common.ListToPage;
+import shop.alien.util.type.TypeUtil;
 
 import java.time.LocalDateTime;
 import java.util.ArrayList;
@@ -58,6 +60,8 @@ public class LifeStoreService {
 
     private final BaseRedisService baseRedisService;
 
+    private final TypeUtil typeUtil;
+
     public LifeUser loginByPhone(String phone) {
         LambdaUpdateWrapper<LifeUser> wrapperFans = new LambdaUpdateWrapper<>();
         wrapperFans.eq(LifeUser::getUserPhone, phone);
@@ -98,7 +102,7 @@ public class LifeStoreService {
             blockerId = String.valueOf(myStoreUser.getId());
         }
         boolean onlyStoreFollowed = (type != null && type == 1) && fansId != null && fansId.startsWith("store_");
-        IPage<LifeFansVo> myFollowed = lifeFansMapper.getMyFollowed(new Page<>(page, size), fansId, relationFansId, blockerType, blockerId, onlyStoreFollowed, wrapper);
+        IPage<LifeFansVo> myFollowed = queryMyFollowed(new Page<>(page, size), fansId, relationFansId, blockerType, blockerId, onlyStoreFollowed, wrapper);
         // 过滤掉我拉黑的
         List<LifeFansVo> collect = myFollowed.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList());
         myFollowed.setRecords(collect);
@@ -110,7 +114,8 @@ public class LifeStoreService {
      * 我的关注所有
      */
     public List<LifeFansVo> getMyFollowedAll(String fansId) {
-        return lifeFansMapper.getMyFollowedAll(fansId);
+        LifeFansIdentityQuery.Scope scope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
+        return lifeFansMapper.getMyFollowedAll(fansId, scope.getUserType(), scope.getRefId());
     }
 
     /**
@@ -141,7 +146,7 @@ public class LifeStoreService {
             blockerId = String.valueOf(myStoreUser.getId());
         }
         boolean onlyStoreFans = (type != null && type == 1) && fansId != null && fansId.startsWith("store_");
-        IPage<LifeFansVo> myFans = lifeFansMapper.getMyFans(new Page<>(page, size), fansId, relationFansId, blockerType, blockerId, onlyStoreFans, wrapper);
+        IPage<LifeFansVo> myFans = queryMyFans(new Page<>(page, size), fansId, relationFansId, blockerType, blockerId, onlyStoreFans, wrapper);
         List<LifeFansVo> collect = myFans.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList());
         myFans.setRecords(collect);
         myFans.setTotal(collect.size());
@@ -277,12 +282,12 @@ public class LifeStoreService {
         int pageSize = 1000; // 设置合理的分页大小
         
         // 统计关注数量(过滤被拉黑的)
-        int followedNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize, 
-                (page, w) -> lifeFansMapper.getMyFollowed(page, phoneId, phoneId, blockerType, blockerId, false, w));
+        int followedNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize,
+                (page, w) -> queryMyFollowed(page, phoneId, phoneId, blockerType, blockerId, false, w));
 
         // 统计粉丝数量(过滤被拉黑的)
         int fansNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize,
-                (page, w) -> lifeFansMapper.getMyFans(page, phoneId, phoneId, blockerType, blockerId, false, w));
+                (page, w) -> queryMyFans(page, phoneId, phoneId, blockerType, blockerId, false, w));
 
         // 统计好友数量(过滤被拉黑的)
         int friendNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize,
@@ -503,6 +508,26 @@ public class LifeStoreService {
         return totalCount;
     }
 
+    private IPage<LifeFansVo> queryMyFollowed(Page<LifeFansVo> page, String fansId, String relationFansId,
+                                              String blockerType, String blockerId, boolean onlyStoreFollowed,
+                                              QueryWrapper<LifeFansVo> wrapper) {
+        LifeFansIdentityQuery.Scope scope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
+        LifeFansIdentityQuery.Scope relationScope = LifeFansIdentityQuery.resolve(relationFansId, typeUtil);
+        return lifeFansMapper.getMyFollowed(page, fansId, scope.getUserType(), scope.getRefId(),
+                relationFansId, relationScope.getUserType(), relationScope.getRefId(),
+                blockerType, blockerId, onlyStoreFollowed, wrapper);
+    }
+
+    private IPage<LifeFansVo> queryMyFans(Page<LifeFansVo> page, String fansId, String relationFansId,
+                                          String blockerType, String blockerId, boolean onlyStoreFans,
+                                          QueryWrapper<LifeFansVo> wrapper) {
+        LifeFansIdentityQuery.Scope scope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
+        LifeFansIdentityQuery.Scope relationScope = LifeFansIdentityQuery.resolve(relationFansId, typeUtil);
+        return lifeFansMapper.getMyFans(page, fansId, scope.getUserType(), scope.getRefId(),
+                relationFansId, relationScope.getUserType(), relationScope.getRefId(),
+                blockerType, blockerId, onlyStoreFans, wrapper);
+    }
+
     private void filterBlocked(String fansId, IPage<LifeFansVo> myFollowed) {
 
         // 判断自己的拉黑type

+ 2 - 2
alien-store/src/main/java/shop/alien/store/service/LifeUserService.java

@@ -39,6 +39,7 @@ import shop.alien.store.feign.SecondServiceFeign;
 import shop.alien.store.service.clockin.ClockInRecommendCacheService;
 import shop.alien.store.service.dynamics.DynamicsRecommendCacheService;
 import shop.alien.store.util.FunctionMagic;
+import shop.alien.store.util.LifeFansIdentityQuery;
 import shop.alien.util.type.PhoneTypeIdResult;
 import shop.alien.util.type.TypeUtil;
 
@@ -458,9 +459,8 @@ public class LifeUserService extends ServiceImpl<LifeUserMapper, LifeUser> {
         }
         IPage<LifeUserVo> voList = lifeUserMapper.getStoreAndUserByName(new Page<>(vo.getPage(), vo.getSize()), queryWrapper);
 
-        // 查询我的关注
         LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<>();
-        lifeFansWrapper.eq(LifeFans::getFansId, vo.getPhoneId());
+        LifeFansIdentityQuery.applyFansSide(lifeFansWrapper, LifeFansIdentityQuery.resolve(vo.getPhoneId(), typeUtil));
         List<LifeFans> lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
         List<String> followList = lifeFansList.stream().map(LifeFans::getFollowedId).collect(Collectors.toList());
 

+ 13 - 18
alien-store/src/main/java/shop/alien/store/service/impl/LifeFansServiceImpl.java

@@ -11,6 +11,8 @@ import shop.alien.mapper.LifeFansMapper;
 import shop.alien.mapper.LifeUserMapper;
 import shop.alien.mapper.StoreUserMapper;
 import shop.alien.store.service.LifeFansService;
+import shop.alien.store.util.LifeFansIdentityQuery;
+import shop.alien.util.type.TypeUtil;
 
 import java.util.*;
 import java.util.stream.Collectors;
@@ -31,22 +33,23 @@ public class LifeFansServiceImpl extends ServiceImpl<LifeFansMapper, LifeFans> i
     private final LifeUserMapper lifeUserMapper;
 
     private final StoreUserMapper storeUserMapper;
+
     private final LifeFansMapper lifeFansMapper;
 
+    private final TypeUtil typeUtil;
+
     @Override
     public List<Map<String, Object>> getFriends(String phone) {
-        // 查询我关注的人
         LambdaQueryWrapper<LifeFans> myFollowWrapper = new LambdaQueryWrapper<>();
-        myFollowWrapper.eq(LifeFans::getFansId, phone)
-                .eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyFansSide(myFollowWrapper, LifeFansIdentityQuery.resolve(phone, typeUtil));
+        myFollowWrapper.eq(LifeFans::getDeleteFlag, 0);
         List<LifeFans> myFollows = this.list(myFollowWrapper);
 
-
         List<String> phones = new ArrayList<>();
         for (LifeFans myFollow : myFollows) {
-            // 查询是否关注我
             LambdaQueryWrapper<LifeFans> fansQueryWrapper = new LambdaQueryWrapper<>();
-            myFollowWrapper.eq(LifeFans::getFansId, myFollow.getFollowedId());
+            LifeFansIdentityQuery.applyFansSide(fansQueryWrapper,
+                    LifeFansIdentityQuery.resolve(myFollow.getFollowedId(), typeUtil));
             List<LifeFans> fansList = this.list(fansQueryWrapper);
             List<String> myFollowIds = fansList.stream()
                     .map(LifeFans::getFollowedId)
@@ -57,7 +60,6 @@ public class LifeFansServiceImpl extends ServiceImpl<LifeFansMapper, LifeFans> i
             }
         }
 
-        // 查询好友用户信息
         if (phones.isEmpty()) {
             return Collections.emptyList();
         }
@@ -81,7 +83,6 @@ public class LifeFansServiceImpl extends ServiceImpl<LifeFansMapper, LifeFans> i
                 .collect(Collectors.toList());
         List<Map<String, Object>> userList = new ArrayList<>();
 
-        // 获取互相关注的用户
         if (!userPhone.isEmpty()) {
             LambdaQueryWrapper<LifeUser> userWrapper = new LambdaQueryWrapper<>();
             userWrapper.in(LifeUser::getUserPhone, userPhone)
@@ -97,7 +98,6 @@ public class LifeFansServiceImpl extends ServiceImpl<LifeFansMapper, LifeFans> i
             }
         }
 
-        // 获取互相关注的商家
         if (!storePhone.isEmpty()) {
             String userPhones = "'" + String.join("','", storePhone) + "'";
             List<Map<String, Object>> storeUsers = storeUserMapper.selectStore(userPhones);
@@ -113,13 +113,6 @@ public class LifeFansServiceImpl extends ServiceImpl<LifeFansMapper, LifeFans> i
         return userList;
     }
 
-    /**
-     * 查询是否关注
-     *
-     * @param userId         用户id
-     * @param followedUserId 关注人id
-     * @return boolean
-     */
     @Override
     public boolean getFollowStatus(Integer userId, Integer followedUserId) {
         LifeUser lifeUser1 = lifeUserMapper.selectOne(new LambdaQueryWrapper<LifeUser>().eq(LifeUser::getId, userId));
@@ -133,8 +126,10 @@ public class LifeFansServiceImpl extends ServiceImpl<LifeFansMapper, LifeFans> i
             return false;
         }
         LambdaQueryWrapper<LifeFans> wrapper = new LambdaQueryWrapper<>();
-        wrapper.eq(LifeFans::getFansId, "user_" + lifeUser1.getUserPhone())
-                .eq(LifeFans::getFollowedId, "user_" + lifeUser2.getUserPhone());
+        LifeFansIdentityQuery.applyFansSide(wrapper,
+                LifeFansIdentityQuery.resolve("user_" + lifeUser1.getUserPhone(), typeUtil));
+        LifeFansIdentityQuery.applyFollowedSide(wrapper,
+                LifeFansIdentityQuery.resolve("user_" + lifeUser2.getUserPhone(), typeUtil));
         return !lifeFansMapper.selectList(wrapper).isEmpty();
     }
 }

+ 85 - 0
alien-store/src/main/java/shop/alien/store/util/LifeFansIdentityQuery.java

@@ -0,0 +1,85 @@
+package shop.alien.store.util;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import shop.alien.entity.store.LifeFans;
+import shop.alien.util.type.PhoneTypeIdResult;
+import shop.alien.util.type.TypeUtil;
+
+/**
+ * life_fans 查询条件:在原有 fans_id / followed_id 字符串匹配基础上,增加 type + refId 匹配。
+ */
+public final class LifeFansIdentityQuery {
+
+    private LifeFansIdentityQuery() {
+    }
+
+    public static final class Scope {
+        private final String legacyPhoneId;
+        private final Integer userType;
+        private final Integer refId;
+
+        public Scope(String legacyPhoneId, Integer userType, Integer refId) {
+            this.legacyPhoneId = legacyPhoneId;
+            this.userType = userType;
+            this.refId = refId;
+        }
+
+        public String getLegacyPhoneId() {
+            return legacyPhoneId;
+        }
+
+        public Integer getUserType() {
+            return userType;
+        }
+
+        public Integer getRefId() {
+            return refId;
+        }
+
+        public boolean hasTypeRef() {
+            return userType != null && refId != null;
+        }
+    }
+
+    public static Scope resolve(String phoneId, TypeUtil typeUtil) {
+        if (phoneId == null) {
+            return new Scope(null, null, null);
+        }
+        Integer userType = null;
+        Integer refId = null;
+        if (typeUtil != null && typeUtil.containsUnderscore(phoneId)) {
+            PhoneTypeIdResult resolved = typeUtil.resolveTypeAndId(phoneId);
+            if (resolved != null) {
+                userType = resolved.getType();
+                refId = resolved.getId();
+            }
+        }
+        return new Scope(phoneId, userType, refId);
+    }
+
+    public static void applyFansSide(LambdaQueryWrapper<LifeFans> wrapper, Scope scope) {
+        if (scope == null || scope.getLegacyPhoneId() == null) {
+            return;
+        }
+        wrapper.and(q -> {
+            q.eq(LifeFans::getFansId, scope.getLegacyPhoneId());
+            if (scope.hasTypeRef()) {
+                q.or(sub -> sub.eq(LifeFans::getFansUserType, scope.getUserType())
+                        .eq(LifeFans::getFansRefId, scope.getRefId()));
+            }
+        });
+    }
+
+    public static void applyFollowedSide(LambdaQueryWrapper<LifeFans> wrapper, Scope scope) {
+        if (scope == null || scope.getLegacyPhoneId() == null) {
+            return;
+        }
+        wrapper.and(q -> {
+            q.eq(LifeFans::getFollowedId, scope.getLegacyPhoneId());
+            if (scope.hasTypeRef()) {
+                q.or(sub -> sub.eq(LifeFans::getFollowedUserType, scope.getUserType())
+                        .eq(LifeFans::getFollowedRefId, scope.getRefId()));
+            }
+        });
+    }
+}