Просмотр исходного кода

好友关注 被关注者注销了 username显示已注销

qinxuyang 9 часов назад
Родитель
Сommit
f4249fcfdb

+ 6 - 4
alien-entity/src/main/java/shop/alien/mapper/LifeFansMapper.java

@@ -19,7 +19,7 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "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.username) username, MAX(foll.accountBlurb) accountBlurb, MAX(foll.isMerchant) isMerchant, MAX(foll.created_time) created_time, " +
             "  MAX(lb.id) blackListid, MAX(if(isnull(fans.id), 0, 1)) isFollowMe, MAX(if(isnull(fans_this.id), 0, 1)) isFollowThis, MAX(if(isnull(lb.id), '0', '1')) isBlocked,  " +
             "  (select count(1) from life_fans lf_cnt where lf_cnt.fans_user_type = foll.followedUserType and lf_cnt.fans_ref_id = foll.followedRefId and lf_cnt.delete_flag = 0) followNum, " +
-            "  (select count(1) from life_fans lf_cnt2 where lf_cnt2.followed_user_type = foll.followedUserType and lf_cnt2.followed_ref_id = foll.followedRefId and lf_cnt2.delete_flag = 0) fansNum, foll.username from ( " +
+            "  (select count(1) from life_fans lf_cnt2 where lf_cnt2.followed_user_type = foll.followedUserType and lf_cnt2.followed_ref_id = foll.followedRefId and lf_cnt2.delete_flag = 0) fansNum from ( " +
             "    with follow as (   " +
             "        select followed_user_type as followedUserType, followed_ref_id as followedRefId, created_time   " +
             "        from life_fans   " +
@@ -28,8 +28,9 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "        and 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,user.name username 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, 2 as followedUserType, user.id as followedRefId " +
+            "    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, 2 as followedUserType, user.id as followedRefId " +
             "    from follow foll " +
             "    join store_user user on foll.followedUserType = 2 and user.id = foll.followedRefId " +
             "    join store_info info on info.id = user.store_id " +
@@ -37,7 +38,8 @@ public interface LifeFansMapper extends BaseMapper<LifeFans> {
             "    where user.delete_flag = 0 and info.delete_flag = 0 " +
             "<if test=\"onlyStoreFollowed == false\">" +
             "    union " +
-            "    select user.id, user.user_name name,user.user_name username, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType,user.id blockedId,'' username, '' accountBlurb, '0' AS isMerchant, foll.created_time, 1 as followedUserType, user.id as followedRefId " +
+            "    select user.id, user.user_name name, user.user_image image, concat('user_', user.user_phone) phoneId, user.jianjie blurb, 2 blockedType, user.id blockedId, " +
+            "    user.user_name username, '' accountBlurb, '0' AS isMerchant, foll.created_time, 1 as followedUserType, user.id as followedRefId " +
             "    from follow foll " +
             "    join life_user user on foll.followedUserType = 1 and user.id = foll.followedRefId   " +
             "    where user.delete_flag = 0   " +

+ 87 - 0
alien-store/src/main/java/shop/alien/store/service/LifeStoreService.java

@@ -40,6 +40,8 @@ import java.util.stream.Collectors;
 @RequiredArgsConstructor
 public class LifeStoreService {
 
+    private static final String LOGOUT_DISPLAY_NAME = "已注销";
+
     private final LifeCollectMapper lifeCollectMapper;
 
     private final LifeUserMapper lifeUserMapper;
@@ -105,6 +107,7 @@ public class LifeStoreService {
         }
         boolean onlyStoreFollowed = (type != null && type == 1) && fansId != null && fansId.startsWith("store_");
         IPage<LifeFansVo> myFollowed = queryMyFollowed(new Page<>(page, size), fansId, relationFansId, blockerType, blockerId, onlyStoreFollowed, wrapper);
+        applyLoggedOutUsername(myFollowed.getRecords());
         // 过滤掉我拉黑的
         List<LifeFansVo> collect = myFollowed.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList());
         myFollowed.setRecords(collect);
@@ -112,6 +115,88 @@ public class LifeStoreService {
         return myFollowed;
     }
 
+    /** 关注/互关等列表回显:被关注方 logout_flag=1 时 username 展示为「已注销」 */
+    private void applyLoggedOutUsername(List<LifeFansVo> records) {
+        if (CollectionUtils.isEmpty(records)) {
+            return;
+        }
+        for (LifeFansVo vo : records) {
+            if (isFollowedAccountLoggedOut(vo)) {
+                vo.setUsername(LOGOUT_DISPLAY_NAME);
+            }
+        }
+    }
+
+    private boolean isFollowedAccountLoggedOut(LifeFansVo vo) {
+        if (vo == null) {
+            return false;
+        }
+        // 互关/关注列表:商户 id 为 store_info.id,按 store_id 查 store_user.logout_flag
+        if (isStoreFansVo(vo) && StringUtils.isNotEmpty(vo.getId())) {
+            try {
+                if (storeUserService.count(new LambdaQueryWrapper<StoreUser>()
+                        .eq(StoreUser::getStoreId, Integer.valueOf(vo.getId()))
+                        .eq(StoreUser::getDeleteFlag, 0)
+                        .eq(StoreUser::getLogoutFlag, StoreUser.LOGOUT_FLAG_DONE)) > 0) {
+                    return true;
+                }
+            } catch (NumberFormatException ignored) {
+                // ignore
+            }
+        }
+        // C 端用户:列表 id 为 life_user.id
+        if (isLifeUserFansVo(vo) && StringUtils.isNotEmpty(vo.getId())) {
+            try {
+                LifeUser user = lifeUserMapper.selectById(Integer.valueOf(vo.getId()));
+                if (user != null && (user.getDeleteFlag() == null || user.getDeleteFlag() == 0)
+                        && user.getLogoutFlag() != null
+                        && LifeUser.LOGOUT_FLAG_DONE == user.getLogoutFlag()) {
+                    return true;
+                }
+            } catch (NumberFormatException ignored) {
+                // ignore
+            }
+        }
+        if (StringUtils.isEmpty(vo.getPhoneId())) {
+            return false;
+        }
+        String[] parts = vo.getPhoneId().split("_", 2);
+        if (parts.length < 2 || StringUtils.isEmpty(parts[1])) {
+            return false;
+        }
+        if ("user".equals(parts[0])) {
+            LifeUser user = lifeUserMapper.selectOne(new LambdaQueryWrapper<LifeUser>()
+                    .eq(LifeUser::getUserPhone, parts[1])
+                    .eq(LifeUser::getDeleteFlag, 0)
+                    .orderByDesc(LifeUser::getCreatedTime)
+                    .orderByDesc(LifeUser::getId)
+                    .last("LIMIT 1"));
+            return user != null && user.getLogoutFlag() != null
+                    && LifeUser.LOGOUT_FLAG_DONE == user.getLogoutFlag();
+        }
+        if ("store".equals(parts[0])) {
+            StoreUser user = storeUserService.getOne(new LambdaQueryWrapper<StoreUser>()
+                    .eq(StoreUser::getPhone, parts[1])
+                    .eq(StoreUser::getDeleteFlag, 0)
+                    .orderByDesc(StoreUser::getCreatedTime)
+                    .orderByDesc(StoreUser::getId)
+                    .last("LIMIT 1"));
+            return user != null && user.getLogoutFlag() != null
+                    && StoreUser.LOGOUT_FLAG_DONE == user.getLogoutFlag();
+        }
+        return false;
+    }
+
+    private static boolean isStoreFansVo(LifeFansVo vo) {
+        return "1".equals(vo.getIsMerchant())
+                || (vo.getPhoneId() != null && vo.getPhoneId().startsWith("store_"));
+    }
+
+    private static boolean isLifeUserFansVo(LifeFansVo vo) {
+        return !"1".equals(vo.getIsMerchant())
+                && (vo.getPhoneId() == null || vo.getPhoneId().startsWith("user_"));
+    }
+
     /**
      * 我的关注所有
      */
@@ -213,6 +298,7 @@ public class LifeStoreService {
         LifeFansIdentityQuery.Scope scope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
         IPage<LifeFansVo> mutualAttention = lifeFansMapper.getMutualAttention(new Page<>(page, size), fansId,
                 scope.getUserType(), scope.getRefId(), blockerType, blockerId, wrapper);
+        applyLoggedOutUsername(mutualAttention.getRecords());
         List<LifeFansVo> collect = mutualAttention.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList());
         mutualAttention.setRecords(collect);
         mutualAttention.setTotal(collect.size());
@@ -229,6 +315,7 @@ public class LifeStoreService {
         LifeFansIdentityQuery.Scope scope = LifeFansIdentityQuery.resolve(fansId, typeUtil);
         IPage<LifeFansVo> mutualAttention = lifeFansMapper.getMutualAttentionUser(new Page<>(page, size), fansId,
                 scope.getUserType(), scope.getRefId(), wrapper);
+        applyLoggedOutUsername(mutualAttention.getRecords());
         filterBlocked(fansId, mutualAttention);
         List<LifeFansVo> collect = mutualAttention.getRecords().stream().filter(x -> x.getIsBlocked().equals("0")).collect(Collectors.toList());
         mutualAttention.setRecords(collect);