Răsfoiți Sursa

处理BUG 标题四个统计数值 聊天界面价目表 评论统计数量

lutong 2 luni în urmă
părinte
comite
319684a4f2

+ 22 - 0
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -236,6 +236,28 @@ public class StoreInfoController {
             
             // 如果 store_id 不为空,则使用该 store_id 查询门店详细信息
             if (storeUser.getStoreId() != null && storeUser.getStoreId() > 0) {
+                // 先查询门店信息,检查审核状态和删除标记
+                StoreInfo storeInfo = storeInfoMapper.selectById(storeUser.getStoreId());
+                
+                if (storeInfo == null) {
+                    log.warn("门店不存在: storeId={}, phone={}", storeUser.getStoreId(), phone);
+                    return R.fail("门店不存在");
+                }
+                
+                // 排除被删除的门店
+                if (storeInfo.getDeleteFlag() != null && storeInfo.getDeleteFlag() != 0) {
+                    log.warn("门店已被删除: storeId={}, phone={}, deleteFlag={}", 
+                            storeUser.getStoreId(), phone, storeInfo.getDeleteFlag());
+                    return R.fail("门店已被删除");
+                }
+                
+                // 排除审核状态为2(审核失败)的门店
+                if (storeInfo.getStoreApplicationStatus() != null && storeInfo.getStoreApplicationStatus() == 2) {
+                    log.warn("门店审核失败: storeId={}, phone={}, storeApplicationStatus={}", 
+                            storeUser.getStoreId(), phone, storeInfo.getStoreApplicationStatus());
+                    return R.fail("门店审核失败");
+                }
+                
                 return R.data(storeInfoService.getDetail(storeUser.getStoreId()));
             } else {
                 log.warn("商家用户的 store_id 为空: phone={}, userId={}", phone, storeUser.getId());

+ 105 - 18
alien-store/src/main/java/shop/alien/store/service/LifeStoreService.java

@@ -203,35 +203,80 @@ public class LifeStoreService {
         return mutualAttention;
     }
 
+    /**
+     * 获取首页信息(优化版)
+     * 
+     * @param phoneId 用户标识(格式:user_手机号 或 store_手机号)
+     * @return 首页信息
+     */
     public LifeFansVo getHomePageInfo(String phoneId) {
+        // 参数校验
+        if (StringUtils.isEmpty(phoneId)) {
+            log.warn("getHomePageInfo: phoneId为空");
+            return new LifeFansVo();
+        }
+
+        // 验证 phoneId 格式
+        String[] phoneIdParts = phoneId.split("_");
+        if (phoneIdParts.length < 2) {
+            log.warn("getHomePageInfo: phoneId格式错误,phoneId={}", phoneId);
+            return new LifeFansVo();
+        }
+
         QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
         wrapper.groupBy("foll.phoneId");
 
         // 判断自己的拉黑type
-        String blockerType = "";
-        String blockerId = "";
-        if ("user".equals(phoneId.split("_")[0])) {
-            String myselfUserPhone = phoneId.split("_")[1];
-            blockerType = "2";
-            LifeUser myLifeUser = lifeUserService.getUserByPhone(myselfUserPhone);
-            blockerId = String.valueOf(myLifeUser.getId());
-        } else {
-            String myselfStorePhone = phoneId.split("_")[1];
-            blockerType = "1";
-            StoreUser myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
-            blockerId = String.valueOf(myStoreUser.getId());
+        final String blockerType;
+        final String blockerId;
+        try {
+            if ("user".equals(phoneIdParts[0])) {
+                String myselfUserPhone = phoneIdParts[1];
+                blockerType = "2";
+                LifeUser myLifeUser = lifeUserService.getUserByPhone(myselfUserPhone);
+                if (myLifeUser == null || myLifeUser.getId() == null) {
+                    log.warn("getHomePageInfo: 用户不存在,phoneId={}", phoneId);
+                    return new LifeFansVo();
+                }
+                blockerId = String.valueOf(myLifeUser.getId());
+            } else {
+                String myselfStorePhone = phoneIdParts[1];
+                blockerType = "1";
+                StoreUser myStoreUser = storeUserService.getUserByPhone(myselfStorePhone);
+                if (myStoreUser == null || myStoreUser.getId() == null) {
+                    log.warn("getHomePageInfo: 商户不存在,phoneId={}", phoneId);
+                    return new LifeFansVo();
+                }
+                blockerId = String.valueOf(myStoreUser.getId());
+            }
+        } catch (Exception e) {
+            log.error("getHomePageInfo: 获取用户信息异常,phoneId={}", phoneId, e);
+            return new LifeFansVo();
         }
 
-        IPage<LifeFansVo> myFollowed = lifeFansMapper.getMyFollowed(new Page<>(1, Integer.MAX_VALUE), phoneId, blockerType, blockerId, wrapper);
-        int followedNum = myFollowed.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList()).size();
+        // 优化:使用分页查询统计数量,避免使用 Integer.MAX_VALUE 导致内存溢出
+        // 使用合理的分页大小,如果数据量很大则循环分页统计
+        int pageSize = 1000; // 设置合理的分页大小
+        
+        // 统计关注数量(过滤被拉黑的)
+        int followedNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize, 
+                (page, w) -> lifeFansMapper.getMyFollowed(page, phoneId, blockerType, blockerId, w));
 
-        IPage<LifeFansVo> myFans = lifeFansMapper.getMyFans(new Page<>(1, Integer.MAX_VALUE), phoneId, blockerType, blockerId, wrapper);
-        int fansNum = myFans.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList()).size();
+        // 统计粉丝数量(过滤被拉黑的)
+        int fansNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize,
+                (page, w) -> lifeFansMapper.getMyFans(page, phoneId, blockerType, blockerId, w));
 
-        IPage<LifeFansVo> mutualAttention = lifeFansMapper.getMutualAttention(new Page<>(1, Integer.MAX_VALUE), phoneId, blockerType, blockerId, wrapper);
-        int friendNum = mutualAttention.getRecords().stream().filter(x -> null == x.getBlackListid()).collect(Collectors.toList()).size();
+        // 统计好友数量(过滤被拉黑的)
+        int friendNum = countFilteredRecords(phoneId, blockerType, blockerId, wrapper, pageSize,
+                (page, w) -> lifeFansMapper.getMutualAttention(page, phoneId, blockerType, blockerId, w));
 
+        // 获取基础信息(包含dynamicsNum)
         LifeFansVo lifeFansVo = lifeFansMapper.getHomePageInfo(phoneId);
+        if (lifeFansVo == null) {
+            lifeFansVo = new LifeFansVo();
+        }
+        
+        // 设置统计数量
         lifeFansVo.setFollowNum(String.valueOf(followedNum));
         lifeFansVo.setFansNum(String.valueOf(fansNum));
         lifeFansVo.setFriendNum(String.valueOf(friendNum));
@@ -398,6 +443,48 @@ public class LifeStoreService {
     }
 
 
+    /**
+     * 统计过滤后的记录数量(分页查询,避免内存溢出)
+     * 
+     * @param phoneId 用户标识
+     * @param blockerType 拉黑类型
+     * @param blockerId 拉黑者ID
+     * @param wrapper 查询条件
+     * @param pageSize 分页大小
+     * @param queryFunction 查询函数
+     * @return 过滤后的记录数量
+     */
+    private int countFilteredRecords(String phoneId, String blockerType, String blockerId, 
+                                     QueryWrapper<LifeFansVo> wrapper, int pageSize,
+                                     java.util.function.BiFunction<Page<LifeFansVo>, QueryWrapper<LifeFansVo>, IPage<LifeFansVo>> queryFunction) {
+        int totalCount = 0;
+        int currentPage = 1;
+        int maxPages = 100; // 限制最大页数,防止无限循环
+        
+        while (currentPage <= maxPages) {
+            IPage<LifeFansVo> pageResult = queryFunction.apply(new Page<>(currentPage, pageSize), wrapper);
+            
+            if (pageResult == null || CollectionUtils.isEmpty(pageResult.getRecords())) {
+                break;
+            }
+            
+            // 统计当前页过滤后的数量
+            long currentPageCount = pageResult.getRecords().stream()
+                    .filter(x -> null == x.getBlackListid())
+                    .count();
+            totalCount += (int) currentPageCount;
+            
+            // 如果当前页数据少于分页大小,说明已经是最后一页
+            if (pageResult.getRecords().size() < pageSize) {
+                break;
+            }
+            
+            currentPage++;
+        }
+        
+        return totalCount;
+    }
+
     private void filterBlocked(String fansId, IPage<LifeFansVo> myFollowed) {
 
         // 判断自己的拉黑type

+ 7 - 0
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -340,10 +340,17 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         }
 
         // 统计评价数量(common_rating 表,业务类型1=商铺评价)
+        // 排除:1. 被删除的评论(delete_flag != 0)
+        //       2. 审核状态为2(驳回)的评论(audit_status = 2)
+        // 包含:审核状态为0(待审核)、1(通过)或null的评论
         LambdaQueryWrapper<CommonRating> ratingWrapper = new LambdaQueryWrapper<>();
         ratingWrapper.eq(CommonRating::getBusinessType, 1); // 业务类型:1-商铺评价
         ratingWrapper.eq(CommonRating::getBusinessId, id); // 门店ID
         ratingWrapper.eq(CommonRating::getDeleteFlag, 0); // 未删除
+        // 只包含审核状态为0(待审核)、1(通过)或null的评论,排除审核状态为2(驳回)的评论
+        ratingWrapper.and(wrapper -> wrapper.in(CommonRating::getAuditStatus, 0, 1)
+                .or()
+                .isNull(CommonRating::getAuditStatus));
         Integer ratingCountLong = commonRatingMapper.selectCount(ratingWrapper);
         storeMainInfoVo.setRatingCount(ratingCountLong != null ? ratingCountLong.intValue() : 0);