Procházet zdrojové kódy

关注表二次补漏修改

lutong před 7 hodinami
rodič
revize
d09a905c6a
16 změnil soubory, kde provedl 198 přidání a 126 odebrání
  1. 18 18
      alien-entity/src/main/java/shop/alien/mapper/LifeUserExpertMapper.java
  2. 1 1
      alien-entity/src/main/java/shop/alien/mapper/second/SecondRecommendMapper.java
  3. 1 1
      alien-entity/src/main/resources/mapper/PlatformLifeUserMapper.xml
  4. 2 2
      alien-entity/src/main/resources/mapper/second/SecondGoodsInfoMapper.xml
  5. 17 2
      alien-job/src/main/java/shop/alien/job/store/StoreMembershipCardJob.java
  6. 13 7
      alien-second/src/main/java/shop/alien/second/service/impl/SecondRecommendServiceImpl.java
  7. 6 3
      alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StoreBusinessServiceImpl.java
  8. 10 6
      alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java
  9. 36 34
      alien-store/src/main/java/shop/alien/store/service/LifeStoreService.java
  10. 10 2
      alien-store/src/main/java/shop/alien/store/service/LifeUserOrderService.java
  11. 9 5
      alien-store/src/main/java/shop/alien/store/service/impl/CommonCommentServiceImpl.java
  12. 9 6
      alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java
  13. 12 7
      alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java
  14. 12 4
      alien-store/src/main/java/shop/alien/store/service/impl/StoreClockInServiceImpl.java
  15. 25 12
      alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java
  16. 17 16
      alien-store/src/main/java/shop/alien/store/service/impl/TrackEventServiceImpl.java

+ 18 - 18
alien-entity/src/main/java/shop/alien/mapper/LifeUserExpertMapper.java

@@ -25,10 +25,10 @@ import java.util.List;
 public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
 
     @Select("with fans as ( " +
-            "    select followed_id, count(id) num " +
+            "    select followed_user_type, followed_ref_id, count(id) num " +
             "    from life_fans " +
-            "    where delete_flag = 0 " +
-            "    group by followed_id " +
+            "    where delete_flag = 0 and followed_user_type = 1 " +
+            "    group by followed_user_type, followed_ref_id " +
             "), " +
             "works as ( " +
             "    select expert_id, count(id) worksNum, sum(like_count) likeNum, sum(play_count) playNum " +
@@ -46,7 +46,7 @@ public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
             "       ifnull(orders.orderMoney, 0) orderMoney, ifnull(orders.accountMoney, 0) accountMoney, (ifnull(orders.orderMoney, 0) - ifnull(orders.accountMoney, 0)) pendMoney " +
             "from life_user_expert expert " +
             "join life_user user on user.id = expert.user_id " +
-            "left join fans on fans.followed_id = concat('user_', user.user_phone)  " +
+            "left join fans on fans.followed_user_type = 1 and fans.followed_ref_id = user.id  " +
             "left join works on works.expert_id = expert.id " +
             "left join orders on orders.expert_id = expert.id " +
             "${ew.customSqlSegment}")
@@ -112,24 +112,24 @@ public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
 
 
     @Select("with fans as ( " +
-            "    select followed_id, count(id) num " +
+            "    select followed_user_type, followed_ref_id, count(id) num " +
             "    from life_fans " +
-            "    where delete_flag = 0 " +
-            "    group by followed_id " +
+            "    where delete_flag = 0 and followed_user_type = 1 " +
+            "    group by followed_user_type, followed_ref_id " +
             ") " +
             " select expert.id, expert.expert_code, expert.expert_type, user.id AS user_id, user.user_image, user.user_name, user.user_phone, ifnull(fans.num, 0) fansNum " +
             " from life_user_expert expert " +
             " left join life_user user on user.id = expert.user_id " +
-            " left join fans on fans.followed_id = concat('user_', user.user_phone)  " +
+            " left join fans on fans.followed_user_type = 1 and fans.followed_ref_id = user.id  " +
             " where expert.delete_flag = 0 and user.delete_flag = 0 " +
             " ORDER BY fansNum DESC")
     List<LifeUserExpertVo> getRankList();
 
     @Select("with fans as ( " +
-            "    select followed_id, count(id) num " +
+            "    select followed_user_type, followed_ref_id, count(id) num " +
             "    from life_fans " +
-            "    where delete_flag = 0 " +
-            "    group by followed_id " +
+            "    where delete_flag = 0 and followed_user_type = 1 " +
+            "    group by followed_user_type, followed_ref_id " +
             "), " +  // 这里添加逗号分隔不同的 CTE
             "works as ( " +
             "    select expert_id, count(id) worksNum, sum(like_count) likeNum, sum(play_count) playNum " +
@@ -141,7 +141,7 @@ public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
             "ifnull(fans.num, 0) fansNum " +
             " from life_user_expert expert " +
             " left join life_user user on user.id = expert.user_id " +
-            " left join fans on fans.followed_id = concat('user_', user.user_phone)  " +
+            " left join fans on fans.followed_user_type = 1 and fans.followed_ref_id = user.id  " +
             " left join works on works.expert_id = expert.id " + // 添加与 works 表的连接条件
             " where expert.id = #{expertId}")
     List<LifeUserExpertVo> getExpertDetails(Integer expertId);
@@ -149,7 +149,7 @@ public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
     @Select("select expert.id, expert.expert_code, user.user_name, user.province, user.city, user.district, user.user_brithday, user.user_sex " +
             " from life_user_expert expert " +
             " left join life_user user on user.id = expert.user_id " +
-            " left join life_fans fans on fans.followed_id = concat('user_', user.user_phone)  " +
+            " left join life_fans fans on fans.followed_user_type = 1 and fans.followed_ref_id = user.id and fans.delete_flag = 0 " +
             "where expert.delete_flag = 0 and user.delete_flag = 0 and fans.delete_flag = 0" +
             " and expert.id = #{expertId}")
     List<LifeUserExpertVo> getFanPortrait(Integer expertId);
@@ -159,17 +159,17 @@ public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
             "user.user_name, user.province, user.city, user.district, user.user_brithday, user.user_sex " +
             " from life_user_expert expert " +
             " left join life_user user on user.id = expert.user_id " +
-            " left join life_fans fans on fans.followed_id = concat('user_', user.user_phone)  " +
+            " left join life_fans fans on fans.followed_user_type = 1 and fans.followed_ref_id = user.id and fans.delete_flag = 0 " +
             "where expert.delete_flag = 0 and user.delete_flag = 0" +
             " and user.id = #{userId}")
     List<LifeUserExpertVo> ifExpert(String userId);
 
 
     @Select("with fans as ( " +
-            "    select followed_id, count(id) num " +
+            "    select followed_user_type, followed_ref_id, count(id) num " +
             "    from life_fans " +
-            "    where delete_flag = 0 " +
-            "    group by followed_id " +
+            "    where delete_flag = 0 and followed_user_type = 1 " +
+            "    group by followed_user_type, followed_ref_id " +
             "), " +  // 这里添加逗号分隔不同的 CTE
             "works as ( " +
             "    select expert_id, count(id) worksNum, sum(like_count) likeNum, sum(play_count) playNum " +
@@ -182,7 +182,7 @@ public interface LifeUserExpertMapper extends BaseMapper<LifeUserExpert> {
             "ifnull(fans.num, 0) fansNum " +
             " from life_user_expert expert " +
             " left join life_user user on user.id = expert.user_id " +
-            " left join fans on fans.followed_id = concat('user_', user.user_phone)  " +
+            " left join fans on fans.followed_user_type = 1 and fans.followed_ref_id = user.id  " +
             " left join works on works.expert_id = expert.id " + // 添加与 works 表的连接条件
             " where expert.id = #{expertId}")
     LifeUserExpertVo getTalentIdentityInformation(Integer expertId);

+ 1 - 1
alien-entity/src/main/java/shop/alien/mapper/second/SecondRecommendMapper.java

@@ -19,7 +19,7 @@ public interface SecondRecommendMapper extends BaseMapper<SecondGoodsRecommendVo
      */
     IPage<SecondGoodsRecommendVo> getSecondRecommendByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("position") String position, @Param("typeId") Integer typeId, @Param("phoneId") String phoneId, @Param("radiusKm") String radiusKm);
 
-    IPage<SecondGoodsRecommendVo> querySecondConcernByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("phoneId") String phoneId, @Param("position") String position, @Param("collectUserType") Integer collectUserType, @Param("collectRefId") Integer collectRefId);
+    IPage<SecondGoodsRecommendVo> querySecondConcernByPage(IPage<SecondGoodsRecommendVo> page, @Param("userId") Integer userId, @Param("phoneId") String phoneId, @Param("position") String position, @Param("collectUserType") Integer collectUserType, @Param("collectRefId") Integer collectRefId, @Param("fansUserType") Integer fansUserType, @Param("fansRefId") Integer fansRefId);
 
     IPage<SecondGoodsRecommendVo> querySecondNewGoodsByPage(IPage<SecondGoodsRecommendVo> page,@Param("userId") String userId, @Param("phoneId") String phoneId, @Param("position") String position, @Param("radiusKm") String radiusKm, @Param("timeRange") Integer timeRange, @Param("collectUserType") Integer collectUserType, @Param("collectRefId") Integer collectRefId);
 

+ 1 - 1
alien-entity/src/main/resources/mapper/PlatformLifeUserMapper.xml

@@ -40,7 +40,7 @@
         FROM life_user user
         LEFT JOIN orders ON orders.user_id = user.id
         LEFT JOIN comment ON comment.user_id = user.id
-        LEFT JOIN life_fans lf ON lf.followed_id = CONCAT('user_', user.user_phone) and lf.delete_flag = 0
+        LEFT JOIN life_fans lf ON lf.followed_user_type = 1 AND lf.followed_ref_id = user.id AND lf.delete_flag = 0
         LEFT JOIN life_user_expert lue ON lue.user_id = user.id and lue.delete_flag = 0
         LEFT JOIN second_user_credit suc ON suc.user_id = user.id and suc.delete_flag = 0
         <!-- 动态 SQL 片段,用于拼接查询条件 -->

+ 2 - 2
alien-entity/src/main/resources/mapper/second/SecondGoodsInfoMapper.xml

@@ -126,7 +126,7 @@
 <!--            (SELECT count(1) FROM store_comment c where c.business_id = g.id and c.business_type = 7 and c.delete_flag = 0 ) as commentCount-->
         from
             life_fans f inner join life_user u on
-                f.followed_id = CONCAT('user_', u.user_phone) and u.delete_flag = 0
+                f.followed_user_type = 1 and f.followed_ref_id = u.id and u.delete_flag = 0
             inner join second_goods g on
                 u.id = g.user_id
                 and g.goods_status = 3
@@ -134,7 +134,7 @@
             left join life_like_record llr on llr.dianzan_user_type = 1 and llr.dianzan_ref_id = (select id from life_user where concat('user_', user_phone) = #{phoneId} and delete_flag = 0 limit 1) and llr.huifu_id = g.id and llr.type = 6 and llr.delete_flag = 0
             left join life_collect lc on lc.business_id = g.id and lc.user_id_user_type = #{collectUserType} and lc.user_id_ref_id = #{collectRefId} and lc.delete_flag = 0 and lc.business_type = 1
         where
-            f.fans_id = #{phoneId} and f.delete_flag = 0
+            f.fans_user_type = #{fansUserType} and f.fans_ref_id = #{fansRefId} and f.delete_flag = 0
             and not exists (select 1 from shieldUser s where s.id = g.id)
             and not exists (select 1 from second_shield s where s.user_id = #{userId} and s.shield_type = 1 and s.shield_id = g.id and s.delete_flag = 0)
             and g.position != '' and g.position is not null

+ 17 - 2
alien-job/src/main/java/shop/alien/job/store/StoreMembershipCardJob.java

@@ -201,8 +201,13 @@ public class StoreMembershipCardJob {
                             try {
                                 if (storeUser.getPhone() != null) {
                                     LambdaQueryWrapper<LifeFans> queryWrapper = new LambdaQueryWrapper<LifeFans>()
-                                            .eq(LifeFans::getFollowedId, "store_" + storeUser.getPhone())
-                                            .or().eq(LifeFans::getFansId, "store_" + storeUser.getPhone());
+                                            .eq(LifeFans::getDeleteFlag, 0)
+                                            .and(w -> w
+                                                    .nested(n -> n.eq(LifeFans::getFollowedUserType, 2)
+                                                            .eq(LifeFans::getFollowedRefId, storeUser.getId()))
+                                                    .or()
+                                                    .nested(n -> n.eq(LifeFans::getFansUserType, 2)
+                                                            .eq(LifeFans::getFansRefId, storeUser.getId())));
                                     int deleted = lifeFansMapper.delete(queryWrapper);
                                     deletedFans += deleted;
                                 }
@@ -250,6 +255,16 @@ public class StoreMembershipCardJob {
                     if (date.compareTo(sevenDay) >= 0) {
                         // 删除已过注销时间的用户
                         lifeUserMapper.deleteById(lifeUser.getId());
+                        // 清理粉丝
+                        LambdaQueryWrapper<LifeFans> queryWrapper = new LambdaQueryWrapper<LifeFans>()
+                                .eq(LifeFans::getDeleteFlag, 0)
+                                .and(w -> w
+                                        .nested(n -> n.eq(LifeFans::getFollowedUserType, 1)
+                                                .eq(LifeFans::getFollowedRefId, lifeUser.getId()))
+                                        .or()
+                                        .nested(n -> n.eq(LifeFans::getFansUserType, 1)
+                                                .eq(LifeFans::getFansRefId, lifeUser.getId())));
+                        lifeFansMapper.delete(queryWrapper);
                         successCount++;
                     }
                 }

+ 13 - 7
alien-second/src/main/java/shop/alien/second/service/impl/SecondRecommendServiceImpl.java

@@ -2,6 +2,7 @@ package shop.alien.second.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
 import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -20,6 +21,7 @@ import shop.alien.mapper.second.SecondRecommendMapper;
 import shop.alien.second.service.SecondRecommendService;
 import shop.alien.util.common.JwtUtil;
 import shop.alien.util.type.LifeCollectIdentityQuery;
+import shop.alien.util.type.LifeFansIdentityQuery;
 import shop.alien.util.type.TypeUtil;
 
 import java.math.BigDecimal;
@@ -100,7 +102,10 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
                 return null;
             }
             LifeCollectIdentityQuery.Scope collectScope = resolveCollectScope(phoneId, userId);
-            IPage<SecondGoodsRecommendVo> list = mapper.querySecondConcernByPage(page, userId, "user_" + phoneId, position, collectScope.getUserType(), collectScope.getRefId());
+            LifeFansIdentityQuery.Scope fansScope = LifeFansIdentityQuery.resolve("user_" + phoneId, typeUtil);
+            IPage<SecondGoodsRecommendVo> list = mapper.querySecondConcernByPage(page, userId, "user_" + phoneId, position,
+                    collectScope.getUserType(), collectScope.getRefId(),
+                    fansScope.getUserType(), fansScope.getRefId());
             List<Integer> idList = list.getRecords().stream() // 创建流
                     .map(obj -> obj.getId())   // 提取每个元素的 ID
                     .collect(Collectors.toList());
@@ -277,12 +282,13 @@ public class SecondRecommendServiceImpl extends ServiceImpl<SecondRecommendMappe
             item.setImgList(imgArr);
         }
 
-        QueryWrapper<LifeFans> query1 = new QueryWrapper<>();
-        query1.lambda()
-                .eq(LifeFans::getFollowedId, item.getUserPhone())
-                .eq(LifeFans::getDeleteFlag, 0)
-                .eq(LifeFans::getFansId, toLifeCollectUserId(phoneId));
-        List<LifeFans> lifeFans = lifeFansMapper.selectList(query1);
+        LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve(toLifeCollectUserId(phoneId), typeUtil);
+        LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(item.getUserPhone(), typeUtil);
+        LambdaQueryWrapper<LifeFans> fansQuery = new LambdaQueryWrapper<>();
+        fansQuery.eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyFansSide(fansQuery, fanScope);
+        LifeFansIdentityQuery.applyFollowedSide(fansQuery, followedScope);
+        List<LifeFans> lifeFans = lifeFansMapper.selectList(fansQuery);
         if (lifeFans.size() > 0) {
             item.setFansStatus(1);
         }

+ 6 - 3
alien-store-platform/src/main/java/shop/alien/storeplatform/service/impl/StoreBusinessServiceImpl.java

@@ -45,6 +45,7 @@ import shop.alien.util.common.constant.CouponStatusEnum;
 import shop.alien.util.common.constant.CouponTypeEnum;
 import shop.alien.util.common.constant.OrderStatusEnum;
 import shop.alien.util.type.LifeCollectIdentityQuery;
+import shop.alien.util.type.LifeFansIdentityQuery;
 import shop.alien.util.type.LifeNoticeUtil;
 import shop.alien.util.type.TypeUtil;
 
@@ -1273,16 +1274,18 @@ public class StoreBusinessServiceImpl extends ServiceImpl<StoreInfoMapper, Store
             LifeUser lifeUser = lifeUserMapper.selectById(userId);
             if (lifeUser != null && StringUtils.isNotEmpty(lifeUser.getUserPhone())) {
                 // 查询我的关注信息,构建关注者ID列表
+                LifeFansIdentityQuery.Scope storeViewerScope = LifeFansIdentityQuery.resolve("user_" + result.getStorePhone(), typeUtil);
                 LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<>();
-                lifeFansWrapper.eq(LifeFans::getFansId, "user_" + result.getStorePhone());
+                lifeFansWrapper.eq(LifeFans::getDeleteFlag, 0);
+                LifeFansIdentityQuery.applyFansSide(lifeFansWrapper, storeViewerScope);
                 List<LifeFans> lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
                 if (!CollectionUtils.isEmpty(lifeFansList)) {
                     followList = lifeFansList.stream().map(LifeFans::getFollowedId).collect(Collectors.toList());
                 }
 
-                // 查询我的粉丝信息,构建粉丝ID列表
                 lifeFansWrapper = new LambdaQueryWrapper<>();
-                lifeFansWrapper.eq(LifeFans::getFollowedId, "user_" + result.getStorePhone());
+                lifeFansWrapper.eq(LifeFans::getDeleteFlag, 0);
+                LifeFansIdentityQuery.applyFollowedSide(lifeFansWrapper, storeViewerScope);
                 lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
                 if (!CollectionUtils.isEmpty(lifeFansList)) {
                     fansList = lifeFansList.stream().map(LifeFans::getFansId).collect(Collectors.toList());

+ 10 - 6
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -32,6 +32,8 @@ import shop.alien.entity.store.StorePrice;
 import shop.alien.entity.store.UserLoginInfo;
 import shop.alien.store.util.StoreClockInIdentityHelper;
 import shop.alien.util.common.TokenInfo;
+import shop.alien.util.type.LifeFansIdentityQuery;
+import shop.alien.util.type.TypeUtil;
 import springfox.documentation.annotations.ApiIgnore;
 
 import java.io.IOException;
@@ -76,6 +78,7 @@ public class StoreInfoController {
     private final LifeBlacklistMapper lifeBlacklistMapper;
     private final StoreUserMapper storeUserMapper;
     private final LifeFansMapper lifeFansMapper;
+    private final TypeUtil typeUtil;
 
     private final StoreClockInIdentityHelper clockInIdentityHelper;
 
@@ -1626,10 +1629,11 @@ public class StoreInfoController {
                         String fansId = "user_" + lifeUser.getUserPhone();
                         
                         // 查询该用户关注的所有门店(followed_id 以 "store_" 开头)
+                        LifeFansIdentityQuery.Scope userScope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
                         LambdaQueryWrapper<LifeFans> fansWrapper = new LambdaQueryWrapper<>();
-                        fansWrapper.eq(LifeFans::getFansId, fansId)
-                                   .likeRight(LifeFans::getFollowedId, "store_")
-                                   .eq(LifeFans::getDeleteFlag, 0);
+                        fansWrapper.eq(LifeFans::getDeleteFlag, 0);
+                        LifeFansIdentityQuery.applyFansSide(fansWrapper, userScope);
+                        fansWrapper.eq(LifeFans::getFollowedUserType, 2);
                         List<LifeFans> lifeFansList = lifeFansMapper.selectList(fansWrapper);
                         
                         if (!CollectionUtils.isEmpty(lifeFansList)) {
@@ -1778,10 +1782,10 @@ public class StoreInfoController {
                             String fansId = "user_" + lifeUser.getUserPhone();
 
                             // 查询关注关系
+                            LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
+                            LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(followedId, typeUtil);
                             LambdaQueryWrapper<LifeFans> fansWrapper = new LambdaQueryWrapper<>();
-                            fansWrapper.eq(LifeFans::getFollowedId, followedId)
-                                    .eq(LifeFans::getFansId, fansId)
-                                    .eq(LifeFans::getDeleteFlag, 0);
+                            LifeFansIdentityQuery.applyPairWithDeleteFlag(fansWrapper, fanScope, followedScope);
                             LifeFans lifeFans = lifeFansMapper.selectOne(fansWrapper);
 
                             if (lifeFans != null) {

+ 36 - 34
alien-store/src/main/java/shop/alien/store/service/LifeStoreService.java

@@ -27,6 +27,7 @@ import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
 import java.util.Optional;
 import java.util.stream.Collectors;
 
@@ -330,31 +331,30 @@ public class LifeStoreService {
      */
     public IPage<LifeUserVo> getUserFans(String storeId, String name, int page, int size) {
         List<LifeUser> mapList = null;
-        LambdaUpdateWrapper<LifeFans> wrapperFans = new LambdaUpdateWrapper<>();
-        wrapperFans.eq(LifeFans::getFollowedId, storeId);
-        wrapperFans.eq(LifeFans::getFansType, "1");
+        LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(storeId, typeUtil);
+        LambdaQueryWrapper<LifeFans> wrapperFans = new LambdaQueryWrapper<>();
+        wrapperFans.eq(LifeFans::getDeleteFlag, 0).eq(LifeFans::getFansType, "1");
+        LifeFansIdentityQuery.applyFollowedSide(wrapperFans, followedScope);
+        wrapperFans.eq(LifeFans::getFansUserType, 1);
         List<LifeFans> userfans = lifeFansMapper.selectList(wrapperFans);
         if (!CollectionUtils.isEmpty(userfans)) {
-            List<String> userIds = userfans.stream().map(LifeFans::getFansId).collect(Collectors.toList());
-            LambdaUpdateWrapper<LifeUser> wrapperUser = new LambdaUpdateWrapper<>();
-            wrapperUser.like(StringUtils.isNotEmpty(name), LifeUser::getUserName, name);
-            wrapperUser.in(LifeUser::getId, userIds);
-            mapList = lifeUserMapper.selectList(wrapperUser);
+            List<Integer> userIds = userfans.stream().map(LifeFans::getFansRefId).filter(Objects::nonNull).collect(Collectors.toList());
+            if (!CollectionUtils.isEmpty(userIds)) {
+                LambdaQueryWrapper<LifeUser> wrapperUser = new LambdaQueryWrapper<>();
+                wrapperUser.like(StringUtils.isNotEmpty(name), LifeUser::getUserName, name);
+                wrapperUser.in(LifeUser::getId, userIds);
+                mapList = lifeUserMapper.selectList(wrapperUser);
+            }
         }
-        LambdaUpdateWrapper<LifeFans> wrapper = new LambdaUpdateWrapper<>();
-        wrapper.eq(LifeFans::getFollowedId, storeId);
         List<LifeUserVo> mapListVo = new ArrayList<>();
         if (!CollectionUtils.isEmpty(mapList)) {
-            for (LifeUser store : mapList) {
-                wrapper.eq(LifeFans::getFansId, store.getId());
-                List<LifeFans> lifeFans = lifeFansMapper.selectList(wrapper);
+            for (LifeUser user : mapList) {
+                LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve("user_" + user.getUserPhone(), typeUtil);
+                LambdaQueryWrapper<LifeFans> checkWrapper = new LambdaQueryWrapper<>();
+                LifeFansIdentityQuery.applyPairWithDeleteFlag(checkWrapper, fanScope, followedScope);
                 LifeUserVo vo = new LifeUserVo();
-                BeanUtils.copyProperties(store, vo);
-                if (CollectionUtils.isEmpty(lifeFans)) {
-                    vo.setIsGuanzhu("0");
-                } else {
-                    vo.setIsGuanzhu("1");
-                }
+                BeanUtils.copyProperties(user, vo);
+                vo.setIsGuanzhu(lifeFansMapper.selectCount(checkWrapper) > 0 ? "1" : "0");
                 mapListVo.add(vo);
             }
         }
@@ -420,30 +420,32 @@ public class LifeStoreService {
      * @return
      */
     public IPage<LifeStoreVo> getStoreFans(String storeId, String storeContact, int page, int size) {
-        LambdaUpdateWrapper<LifeFans> wrapperFans = new LambdaUpdateWrapper<>();
-        wrapperFans.eq(LifeFans::getFollowedId, storeId);
-        wrapperFans.eq(LifeFans::getFansType, "2");
+        LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(storeId, typeUtil);
+        LambdaQueryWrapper<LifeFans> wrapperFans = new LambdaQueryWrapper<>();
+        wrapperFans.eq(LifeFans::getDeleteFlag, 0).eq(LifeFans::getFansType, "2");
+        LifeFansIdentityQuery.applyFollowedSide(wrapperFans, followedScope);
+        wrapperFans.eq(LifeFans::getFansUserType, 2);
         List<LifeFans> userFans = lifeFansMapper.selectList(wrapperFans);
         if (!CollectionUtils.isEmpty(userFans)) {
-            List<String> storeIds = userFans.stream().map(LifeFans::getFansId).collect(Collectors.toList());
+            List<Integer> storeUserIds = userFans.stream().map(LifeFans::getFansRefId).filter(Objects::nonNull).collect(Collectors.toList());
+            List<StoreUser> fanStoreUsers = storeUserService.listByIds(storeUserIds);
+            List<Integer> storeInfoIds = fanStoreUsers.stream().map(StoreUser::getStoreId).filter(Objects::nonNull).collect(Collectors.toList());
+            if (CollectionUtils.isEmpty(storeInfoIds)) {
+                return null;
+            }
             QueryWrapper<StoreInfoVo> queryWrapper = new QueryWrapper<>();
-            queryWrapper.in("a.id", storeIds).eq("a.delete_flag", 0).eq("b.name", storeContact);
+            queryWrapper.in("a.id", storeInfoIds).eq("a.delete_flag", 0).eq("b.name", storeContact);
             List<StoreInfoVo> storeInfoVoList = storeInfoMapper.getStoreInfoVoList(queryWrapper);
             List<LifeStoreVo> mapListVo = new ArrayList<>();
             if (!CollectionUtils.isEmpty(storeInfoVoList)) {
                 for (StoreInfoVo store : storeInfoVoList) {
-                    LambdaUpdateWrapper<LifeFans> wrapper = new LambdaUpdateWrapper<>();
-                    wrapper.eq(LifeFans::getFollowedId, store.getId());
-                    wrapper.eq(LifeFans::getFansId, storeId);
-                    wrapper.eq(LifeFans::getFollowedId, store.getId());
-                    List<LifeFans> lifeFans = lifeFansMapper.selectList(wrapper);
+                    LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve(storeId, typeUtil);
+                    LifeFansIdentityQuery.Scope backScope = LifeFansIdentityQuery.resolve("store_" + store.getStoreTel(), typeUtil);
+                    LambdaQueryWrapper<LifeFans> checkWrapper = new LambdaQueryWrapper<>();
+                    LifeFansIdentityQuery.applyPairWithDeleteFlag(checkWrapper, fanScope, backScope);
                     LifeStoreVo vo = new LifeStoreVo();
                     BeanUtils.copyProperties(store, vo);
-                    if (CollectionUtils.isEmpty(lifeFans)) {
-                        vo.setIsGuanzhu("0");
-                    } else {
-                        vo.setIsGuanzhu("1");
-                    }
+                    vo.setIsGuanzhu(lifeFansMapper.selectCount(checkWrapper) > 0 ? "1" : "0");
                     mapListVo.add(vo);
                 }
             }

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

@@ -31,7 +31,9 @@ import shop.alien.store.util.ali.AliApi;
 import shop.alien.util.ali.AliOSSUtil;
 import shop.alien.util.common.UniqueRandomNumGenerator;
 import shop.alien.util.common.constant.*;
+import shop.alien.util.type.LifeFansIdentityQuery;
 import shop.alien.util.type.LifeNoticeUtil;
+import shop.alien.util.type.TypeUtil;
 
 import java.io.File;
 import java.io.IOException;
@@ -64,6 +66,7 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
     private final GaoDeMapUtil gaoDeMapUtil;
 
     private final LifeFansMapper lifeFansMapper;
+    private final TypeUtil typeUtil;
 
     private final StoreCommentService storeCommentService;
 
@@ -340,14 +343,19 @@ public class LifeUserOrderService extends ServiceImpl<LifeUserOrderMapper, LifeU
 
         String receiverId = "store_" + store.getStorePhone();
 
+        LifeFansIdentityQuery.Scope userScope = LifeFansIdentityQuery.resolve(s, typeUtil);
+        LifeFansIdentityQuery.Scope storeScope = LifeFansIdentityQuery.resolve(receiverId, typeUtil);
+
         //关注我的
         LambdaQueryWrapper<LifeFans> wrapperOne = new LambdaQueryWrapper<>();
-        wrapperOne.eq(LifeFans::getFollowedId, s).eq(LifeFans::getFansId, receiverId);
+        wrapperOne.eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyPair(wrapperOne, storeScope, userScope);
         List<LifeFans> isFollowMeList = lifeFansMapper.selectList(wrapperOne);
 
         //我关注的
         LambdaQueryWrapper<LifeFans> wrapperTwo = new LambdaQueryWrapper<>();
-        wrapperTwo.eq(LifeFans::getFollowedId, receiverId).eq(LifeFans::getFansId, s);
+        wrapperTwo.eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyPair(wrapperTwo, userScope, storeScope);
         List<LifeFans> isFollowThisList = lifeFansMapper.selectList(wrapperTwo);
 
         Map<String, Object> storeMap = new HashMap<>();

+ 9 - 5
alien-store/src/main/java/shop/alien/store/service/impl/CommonCommentServiceImpl.java

@@ -21,7 +21,8 @@ import shop.alien.store.util.LifeDynamicsIdentityHelper;
 import shop.alien.store.util.StoreLikeRecordIdentityHelper;
 import shop.alien.store.util.StoreLikeRecordIdentityHelper.StoreLikerScope;
 import shop.alien.store.util.ai.AiContentModerationUtil;
-import shop.alien.util.common.constant.CommentSourceTypeEnum;
+import shop.alien.util.type.LifeFansIdentityQuery;
+import shop.alien.util.type.TypeUtil;
 import shop.alien.util.common.safe.TextModerationUtil;
 
 import java.util.*;
@@ -52,6 +53,7 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
     private final StoreUserMapper storeUserMapper;
     private final LifeUserViolationMapper lifeUserViolationMapper;
     private final LifeUserMapper lifeUserMapper;
+    private final TypeUtil typeUtil;
     @Autowired
     private LifeFansMapper lifeFansMapper;
     private final AiContentModerationUtil aiContentModerationUtil;
@@ -334,10 +336,12 @@ public class CommonCommentServiceImpl extends ServiceImpl<CommonCommentMapper, C
             // 4.查询当前登录人是否关注了动态发布者
 
             String publisherPhoneId = dynamicsIdentityHelper.resolveComparablePhoneId(lifeUserDynamics);
-            LifeFans lifeFans = lifeFansMapper.selectOne(new QueryWrapper<LifeFans>().eq("followed_id", publisherPhoneId)
-                    .eq("fans_id", fansId)
-                    .eq("fans_type", fansType)
-                    .last("limit 1"));
+            LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
+            LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(publisherPhoneId, typeUtil);
+            LambdaQueryWrapper<LifeFans> fansQuery = new LambdaQueryWrapper<>();
+            fansQuery.eq(LifeFans::getDeleteFlag, 0).eq(LifeFans::getFansType, fansType);
+            LifeFansIdentityQuery.applyPair(fansQuery, fanScope, followedScope);
+            LifeFans lifeFans = lifeFansMapper.selectOne(fansQuery.last("limit 1"));
             if(null != lifeFans){
                 map.put("isFans",1);
             } else {

+ 9 - 6
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -42,7 +42,8 @@ import shop.alien.store.util.ai.ReceiptAuditUtil;
 import shop.alien.util.common.DateUtils;
 import shop.alien.util.common.constant.CommentSourceTypeEnum;
 import shop.alien.util.common.constant.RatingBusinessTypeEnum;
-import shop.alien.util.common.safe.TextModerationUtil;
+import shop.alien.util.type.LifeFansIdentityQuery;
+import shop.alien.util.type.TypeUtil;
 import shop.alien.util.common.safe.TextReviewServiceEnum;
 import shop.alien.util.type.LifeCollectIdentityQuery;
 import shop.alien.util.type.LifeNoticeUtil;
@@ -86,6 +87,7 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
     private final StoreLikeRecordIdentityHelper lifeLikeIdentityHelper;
     private final LifeCollectMapper lifeCollectMapper;
     private final LifeFansMapper lifeFansMapper;
+    private final TypeUtil typeUtil;
     private final TagsSynonymMapper tagsSynonymMapper;
     private final CommonCommentService commonCommentService;
     private final StoreCommentAppealMapper storeCommentAppealMapper;
@@ -856,11 +858,12 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             throw new IllegalArgumentException("登录用户不存在");
         }
         // 查询当前用户关注列表
-        List<LifeFans> lifeFans = lifeFansMapper.selectList(new QueryWrapper<LifeFans>().lambda()
-                .eq(LifeFans::getFollowedId, "user_".concat(ratingUser.getUserPhone()))
-                .eq(LifeFans::getFansId, "user_".concat(loginUser.getUserPhone()))
-                .eq(LifeFans::getFansType, "1")
-                .eq(LifeFans::getDeleteFlag, 0));
+        LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve("user_".concat(ratingUser.getUserPhone()), typeUtil);
+        LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve("user_".concat(loginUser.getUserPhone()), typeUtil);
+        LambdaQueryWrapper<LifeFans> fansQuery = new LambdaQueryWrapper<>();
+        fansQuery.eq(LifeFans::getDeleteFlag, 0).eq(LifeFans::getFansType, "1");
+        LifeFansIdentityQuery.applyPair(fansQuery, fanScope, followedScope);
+        List<LifeFans> lifeFans = lifeFansMapper.selectList(fansQuery);
         // 设置是否关注
         commonRatingVo.setIsFollow(lifeFans.size() > 0 ? 1 : 0);
         // 根据业务类型处理

+ 12 - 7
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponStoreFriendServiceImpl.java

@@ -24,7 +24,9 @@ import shop.alien.store.service.LifeDiscountCouponStoreFriendService;
 import shop.alien.util.common.constant.DiscountCouponEnum;
 import shop.alien.util.coupon.DiscountCouponExpirationUtil;
 import shop.alien.util.coupon.LifeDiscountCouponStock;
+import shop.alien.util.type.LifeFansIdentityQuery;
 import shop.alien.util.type.LifeNoticeUtil;
+import shop.alien.util.type.TypeUtil;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -61,6 +63,7 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
     private final StoreUserMapper storeUserMapper;
 
     private final LifeFansMapper lifeFansMapper;
+    private final TypeUtil typeUtil;
 
     private final LifeDiscountCouponMapper lifeDiscountCouponMapper;
 
@@ -100,18 +103,20 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
         //查询该店铺登录人 fans 表互相关注的列表
         String fansUserPhone = STORE_PREFIX + phoneNumber;
         //查看自己关注的店铺
-        LambdaQueryWrapper<LifeFans> queryWrapper = new LambdaQueryWrapper();
-        //查看自己关注的id(我作为粉丝)
-        queryWrapper.eq(LifeFans::getFansId, fansUserPhone);
-        //并且是商户id的相关数据
-        queryWrapper.likeRight(LifeFans::getFollowedId, STORE_PREFIX);
+        LifeFansIdentityQuery.Scope fansScope = LifeFansIdentityQuery.resolve(fansUserPhone, typeUtil);
+        LambdaQueryWrapper<LifeFans> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyFansSide(queryWrapper, fansScope);
+        queryWrapper.eq(LifeFans::getFollowedUserType, 2);
         List<LifeFans> lifeFans = lifeFansMapper.selectList(queryWrapper);
         //循环本人关注列表查看也关注我的列表
         for (LifeFans lifeFan : lifeFans) {
             //关注人id
             String followedId = lifeFan.getFollowedId();
-            //查询也关注我的信息(他作为粉丝,关注我)
-            LifeFans alsoFansMe = lifeFansMapper.selectOne(new LambdaQueryWrapper<LifeFans>().eq(LifeFans::getFansId, followedId).eq(LifeFans::getFollowedId, fansUserPhone));
+            LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(followedId, typeUtil);
+            LambdaQueryWrapper<LifeFans> mutualWrapper = new LambdaQueryWrapper<>();
+            LifeFansIdentityQuery.applyPairWithDeleteFlag(mutualWrapper, followedScope, fansScope);
+            LifeFans alsoFansMe = lifeFansMapper.selectOne(mutualWrapper);
             //如果有值说明我俩互为朋友
             if (alsoFansMe != null) {
                 LifeDiscountCouponStoreFriendVo addLifeDiscountCouponStoreFriendVo = new LifeDiscountCouponStoreFriendVo();

+ 12 - 4
alien-store/src/main/java/shop/alien/store/service/impl/StoreClockInServiceImpl.java

@@ -28,6 +28,7 @@ import shop.alien.store.service.StoreCommentService;
 import shop.alien.util.type.LifeNoticeUtil;
 import shop.alien.store.util.ai.AiContentModerationUtil;
 import shop.alien.util.common.constant.CommentSourceTypeEnum;
+import shop.alien.util.type.LifeFansIdentityQuery;
 import shop.alien.util.type.PhoneTypeIdResult;
 import shop.alien.util.type.LifeCollectIdentityQuery;
 import shop.alien.util.type.TypeUtil;
@@ -234,8 +235,10 @@ public class StoreClockInServiceImpl extends ServiceImpl<StoreClockInMapper, Sto
 
         // 优化:批量查询所有需要的数据
         // 查询我的关注 - 使用Set提高查找效率
+        LifeFansIdentityQuery.Scope viewerScope = LifeFansIdentityQuery.resolve(phoneId, typeUtil);
         LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<>();
-        lifeFansWrapper.eq(LifeFans::getFansId, phoneId);
+        lifeFansWrapper.eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyFansSide(lifeFansWrapper, viewerScope);
         List<LifeFans> lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
         Set<String> followSet = lifeFansList.stream()
                 .map(LifeFans::getFollowedId)
@@ -243,7 +246,8 @@ public class StoreClockInServiceImpl extends ServiceImpl<StoreClockInMapper, Sto
 
         // 查询我的粉丝 - 使用Set提高查找效率
         lifeFansWrapper = new LambdaQueryWrapper<>();
-        lifeFansWrapper.eq(LifeFans::getFollowedId, phoneId);
+        lifeFansWrapper.eq(LifeFans::getDeleteFlag, 0);
+        LifeFansIdentityQuery.applyFollowedSide(lifeFansWrapper, viewerScope);
         lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
         Set<String> fansSet = lifeFansList.stream()
                 .map(LifeFans::getFansId)
@@ -562,12 +566,16 @@ public class StoreClockInServiceImpl extends ServiceImpl<StoreClockInMapper, Sto
                     : null;
             String authorPhoneId = storeClockInVo.getPhoneId();
             if (viewerPhoneId != null && StringUtils.isNotBlank(authorPhoneId)) {
+                LifeFansIdentityQuery.Scope viewerScope = LifeFansIdentityQuery.resolve(viewerPhoneId, typeUtil);
+                LifeFansIdentityQuery.Scope authorScope = LifeFansIdentityQuery.resolve(authorPhoneId, typeUtil);
                 LambdaQueryWrapper<LifeFans> iFollowAuthor = new LambdaQueryWrapper<>();
-                iFollowAuthor.eq(LifeFans::getFansId, viewerPhoneId).eq(LifeFans::getFollowedId, authorPhoneId);
+                iFollowAuthor.eq(LifeFans::getDeleteFlag, 0);
+                LifeFansIdentityQuery.applyPair(iFollowAuthor, viewerScope, authorScope);
                 storeClockInVo.setIsFollowThis(lifeFansMapper.selectCount(iFollowAuthor) > 0 ? "1" : "0");
 
                 LambdaQueryWrapper<LifeFans> authorFollowsMe = new LambdaQueryWrapper<>();
-                authorFollowsMe.eq(LifeFans::getFansId, authorPhoneId).eq(LifeFans::getFollowedId, viewerPhoneId);
+                authorFollowsMe.eq(LifeFans::getDeleteFlag, 0);
+                LifeFansIdentityQuery.applyPair(authorFollowsMe, authorScope, viewerScope);
                 storeClockInVo.setIsFollowMe(lifeFansMapper.selectCount(authorFollowsMe) > 0 ? "1" : "0");
             }
         }

+ 25 - 12
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -54,7 +54,7 @@ import shop.alien.util.common.constant.CouponStatusEnum;
 import shop.alien.util.common.constant.CouponTypeEnum;
 import shop.alien.util.common.constant.OcrTypeEnum;
 import shop.alien.util.common.constant.OrderStatusEnum;
-import shop.alien.util.type.LifeCollectIdentityQuery;
+import shop.alien.util.type.LifeFansIdentityQuery;
 import shop.alien.util.type.LifeNoticeUtil;
 import shop.alien.util.type.TypeUtil;
 
@@ -2110,8 +2110,10 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
             LifeUser lifeUser = lifeUserMapper.selectById(userId);
             if (lifeUser != null && StringUtils.isNotEmpty(lifeUser.getUserPhone())) {
                 // 查询我的关注信息,构建关注者ID列表
+                LifeFansIdentityQuery.Scope storeViewerScope = LifeFansIdentityQuery.resolve("user_" + result.getStorePhone(), typeUtil);
                 LambdaQueryWrapper<LifeFans> lifeFansWrapper = new LambdaQueryWrapper<>();
-                lifeFansWrapper.eq(LifeFans::getFansId, "user_" + result.getStorePhone());
+                lifeFansWrapper.eq(LifeFans::getDeleteFlag, 0);
+                LifeFansIdentityQuery.applyFansSide(lifeFansWrapper, storeViewerScope);
                 List<LifeFans> lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
                 if (!CollectionUtils.isEmpty(lifeFansList)) {
                     followList = lifeFansList.stream().map(LifeFans::getFollowedId).collect(Collectors.toList());
@@ -2119,7 +2121,8 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
 
                 // 查询我的粉丝信息,构建粉丝ID列表
                 lifeFansWrapper = new LambdaQueryWrapper<>();
-                lifeFansWrapper.eq(LifeFans::getFollowedId, "user_" + result.getStorePhone());
+                lifeFansWrapper.eq(LifeFans::getDeleteFlag, 0);
+                LifeFansIdentityQuery.applyFollowedSide(lifeFansWrapper, storeViewerScope);
                 lifeFansList = lifeFansMapper.selectList(lifeFansWrapper);
                 if (!CollectionUtils.isEmpty(lifeFansList)) {
                     fansList = lifeFansList.stream().map(LifeFans::getFansId).collect(Collectors.toList());
@@ -5126,10 +5129,11 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                         String myFansId = "user_" + currentUser.getUserPhone();
 
                         // 我关注的店铺
+                        LifeFansIdentityQuery.Scope myScope = LifeFansIdentityQuery.resolve(myFansId, typeUtil);
                         LambdaQueryWrapper<LifeFans> myFollowWrapper = new LambdaQueryWrapper<>();
-                        myFollowWrapper.eq(LifeFans::getFansId, myFansId)
-                                .likeRight(LifeFans::getFollowedId, "store_")
-                                .eq(LifeFans::getDeleteFlag, 0);
+                        myFollowWrapper.eq(LifeFans::getDeleteFlag, 0);
+                        LifeFansIdentityQuery.applyFansSide(myFollowWrapper, myScope);
+                        myFollowWrapper.eq(LifeFans::getFollowedUserType, 2);
                         List<LifeFans> myFollows = lifeFansMapper.selectList(myFollowWrapper);
 
                         // 过滤出互相关注(店铺也关注我)的店铺phoneId:store_xxx
@@ -5141,11 +5145,19 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                                     .collect(Collectors.toList());
 
                             if (!followedStoreIds.isEmpty()) {
+                                List<Integer> fanStoreRefIds = followedStoreIds.stream()
+                                        .map(id -> LifeFansIdentityQuery.resolve(id, typeUtil))
+                                        .filter(LifeFansIdentityQuery.Scope::hasTypeRef)
+                                        .filter(scope -> Integer.valueOf(2).equals(scope.getUserType()))
+                                        .map(LifeFansIdentityQuery.Scope::getRefId)
+                                        .collect(Collectors.toList());
+                                if (!fanStoreRefIds.isEmpty()) {
                                 // 查询这些店铺是否关注我
                                 LambdaQueryWrapper<LifeFans> reciprocalWrapper = new LambdaQueryWrapper<>();
-                                reciprocalWrapper.in(LifeFans::getFansId, followedStoreIds)
-                                        .eq(LifeFans::getFollowedId, myFansId)
-                                        .eq(LifeFans::getDeleteFlag, 0);
+                                reciprocalWrapper.eq(LifeFans::getDeleteFlag, 0);
+                                LifeFansIdentityQuery.applyFollowedSide(reciprocalWrapper, myScope);
+                                reciprocalWrapper.eq(LifeFans::getFansUserType, 2)
+                                        .in(LifeFans::getFansRefId, fanStoreRefIds);
                                 List<LifeFans> reciprocals = lifeFansMapper.selectList(reciprocalWrapper);
                                 Set<String> reciprocalFansIds = reciprocals.stream()
                                         .map(LifeFans::getFansId)
@@ -5158,6 +5170,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                                         mutualStorePhones.add(followedId);
                                     }
                                 }
+                                }
                             }
                         }
 
@@ -6087,10 +6100,10 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                     String fansId = "user_" + lifeUser.getUserPhone();
 
                     // 查询关注关系
+                    LifeFansIdentityQuery.Scope fanScope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
+                    LifeFansIdentityQuery.Scope followedScope = LifeFansIdentityQuery.resolve(followedId, typeUtil);
                     LambdaQueryWrapper<LifeFans> fansWrapper = new LambdaQueryWrapper<>();
-                    fansWrapper.eq(LifeFans::getFollowedId, followedId)
-                            .eq(LifeFans::getFansId, fansId)
-                            .eq(LifeFans::getDeleteFlag, 0);
+                    LifeFansIdentityQuery.applyPairWithDeleteFlag(fansWrapper, fanScope, followedScope);
                     LifeFans lifeFans = lifeFansMapper.selectOne(fansWrapper.last("LIMIT 1"));
 
                     if (lifeFans != null) {

+ 17 - 16
alien-store/src/main/java/shop/alien/store/service/impl/TrackEventServiceImpl.java

@@ -13,7 +13,8 @@ import shop.alien.entity.store.StoreTrackStatistics;
 import shop.alien.mapper.*;
 import shop.alien.store.config.BaseRedisService;
 import shop.alien.store.service.TrackEventService;
-import shop.alien.store.util.LifeDynamicsIdentityHelper;
+import shop.alien.util.type.LifeFansIdentityQuery;
+import shop.alien.util.type.TypeUtil;
 
 import java.math.BigDecimal;
 import java.math.RoundingMode;
@@ -39,6 +40,7 @@ public class TrackEventServiceImpl extends ServiceImpl<StoreTrackEventMapper, St
     // 新增依赖:用于查询其他表数据
     private final StoreUserMapper storeUserMapper;
     private final LifeFansMapper lifeFansMapper;
+    private final TypeUtil typeUtil;
     private final LifeUserDynamicsMapper lifeUserDynamicsMapper;
 
     private final LifeDynamicsIdentityHelper dynamicsIdentityHelper;
@@ -365,10 +367,10 @@ public class TrackEventServiceImpl extends ServiceImpl<StoreTrackEventMapper, St
             Set<String> blockedUserIds = getBlockedUserIds(blockerType, blockerId);
             
             // 查询店铺关注的所有用户(截止到统计日期)
+            LifeFansIdentityQuery.Scope storeScope = LifeFansIdentityQuery.resolve(storePhoneId, typeUtil);
             LambdaQueryWrapper<LifeFans> followWrapper = new LambdaQueryWrapper<>();
-            followWrapper.eq(LifeFans::getFansId, storePhoneId)
-                    .lt(LifeFans::getCreatedTime, endDate)
-                    .eq(LifeFans::getDeleteFlag, 0);
+            followWrapper.lt(LifeFans::getCreatedTime, endDate).eq(LifeFans::getDeleteFlag, 0);
+            LifeFansIdentityQuery.applyFansSide(followWrapper, storeScope);
             Set<String> followedIds = lifeFansMapper.selectList(followWrapper).stream()
                     .map(LifeFans::getFollowedId)
                     .filter(id -> isUserValid(id) && !isBlocked(id, blockedUserIds))
@@ -380,9 +382,8 @@ public class TrackEventServiceImpl extends ServiceImpl<StoreTrackEventMapper, St
             
             // 查询关注店铺的所有用户(截止到统计日期)
             LambdaQueryWrapper<LifeFans> fansWrapper = new LambdaQueryWrapper<>();
-            fansWrapper.eq(LifeFans::getFollowedId, storePhoneId)
-                    .lt(LifeFans::getCreatedTime, endDate)
-                    .eq(LifeFans::getDeleteFlag, 0);
+            fansWrapper.lt(LifeFans::getCreatedTime, endDate).eq(LifeFans::getDeleteFlag, 0);
+            LifeFansIdentityQuery.applyFollowedSide(fansWrapper, storeScope);
             Set<String> fansIds = lifeFansMapper.selectList(fansWrapper).stream()
                     .map(LifeFans::getFansId)
                     .filter(id -> isUserValid(id) && !isBlocked(id, blockedUserIds))
@@ -416,25 +417,25 @@ public class TrackEventServiceImpl extends ServiceImpl<StoreTrackEventMapper, St
             Set<String> blockedUserIds = getBlockedUserIds(blockerType, blockerId);
             
             // 查询店铺关注的所有用户(截止到统计日期),并过滤被拉黑的用户
+            LifeFansIdentityQuery.Scope storeScope = LifeFansIdentityQuery.resolve(storePhoneId, typeUtil);
             LambdaQueryWrapper<LifeFans> wrapper = new LambdaQueryWrapper<>();
-            wrapper.eq(LifeFans::getFansId, storePhoneId)
-                    .lt(LifeFans::getCreatedTime, endDate)
-                    .eq(LifeFans::getDeleteFlag, 0);
+            wrapper.lt(LifeFans::getCreatedTime, endDate).eq(LifeFans::getDeleteFlag, 0);
+            LifeFansIdentityQuery.applyFansSide(wrapper, storeScope);
             List<LifeFans> fansList = lifeFansMapper.selectList(wrapper);
-            
+
             // 过滤被拉黑的用户和已删除的用户
             long count = fansList.stream()
                     .map(LifeFans::getFollowedId)
                     .filter(id -> isUserValid(id) && !isBlocked(id, blockedUserIds))
                     .count();
-            
+
             return count;
         } catch (Exception e) {
             log.error("计算关注数量失败: storePhoneId={}", storePhoneId, e);
             return 0L;
         }
     }
-    
+
     /**
      * 计算粉丝数量(关注店铺用户的人数)
      * 注意:粉丝数量是累计数据,统计截止到endDate的所有粉丝关系
@@ -454,10 +455,10 @@ public class TrackEventServiceImpl extends ServiceImpl<StoreTrackEventMapper, St
             Set<String> blockedUserIds = getBlockedUserIds(blockerType, blockerId);
             
             // 查询关注店铺的所有用户(截止到统计日期),并过滤被拉黑的用户
+            LifeFansIdentityQuery.Scope storeScope = LifeFansIdentityQuery.resolve(storePhoneId, typeUtil);
             LambdaQueryWrapper<LifeFans> wrapper = new LambdaQueryWrapper<>();
-            wrapper.eq(LifeFans::getFollowedId, storePhoneId)
-                    .lt(LifeFans::getCreatedTime, endDate)
-                    .eq(LifeFans::getDeleteFlag, 0);
+            wrapper.lt(LifeFans::getCreatedTime, endDate).eq(LifeFans::getDeleteFlag, 0);
+            LifeFansIdentityQuery.applyFollowedSide(wrapper, storeScope);
             List<LifeFans> fansList = lifeFansMapper.selectList(wrapper);
             
             // 过滤被拉黑的用户和已删除的用户