فهرست منبع

Merge branch 'release_lutong_bug' into sit

lutong 2 ماه پیش
والد
کامیت
13df7a9e01
1فایلهای تغییر یافته به همراه128 افزوده شده و 0 حذف شده
  1. 128 0
      alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

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

@@ -1,9 +1,14 @@
 package shop.alien.store.controller;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.annotation.JsonInclude;
 import io.swagger.annotations.*;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.collections4.CollectionUtils;
@@ -62,6 +67,9 @@ public class StoreInfoController {
     private final StoreCommentMapper storeCommentMapper;
     private final StoreClockInMapper storeClockInMapper;
     private final LifeUserMapper lifeUserMapper;
+    private final StoreInfoMapper storeInfoMapper;
+    private final LifeBlacklistMapper lifeBlacklistMapper;
+    private final StoreUserMapper storeUserMapper;
 
     @ApiOperation("获取所有门店")
     @ApiOperationSupport(order = 1)
@@ -1455,5 +1463,125 @@ public class StoreInfoController {
         }
     }
 
+    @ApiOperation("分页随机查询店铺(排除已删除和已拉黑的店铺)")
+    @ApiOperationSupport(order = 100)
+    @ApiImplicitParams({
+            @ApiImplicitParam(
+                    name = "page",
+                    value = "页数(默认1)",
+                    dataType = "int",
+                    paramType = "query"
+            ),
+            @ApiImplicitParam(
+                    name = "size",
+                    value = "页容(默认10)",
+                    dataType = "int",
+                    paramType = "query"
+            )
+    })
+    @GetMapping("/getRandomPage")
+    public R<IPage<StoreInfoWithHeadImg>> getRandomPage(
+            @RequestParam(defaultValue = "1") int page,
+            @RequestParam(defaultValue = "10") int size) {
+        log.info("StoreInfoController.getRandomPage - page={}, size={}", page, size);
+        try {
+            // 参数校验
+            int pageNum = page > 0 ? page : 1;
+            int pageSize = size > 0 ? size : 10;
+            
+            // 查询所有被拉黑的店铺ID
+            LambdaQueryWrapper<LifeBlacklist> blacklistWrapper = new LambdaQueryWrapper<>();
+            blacklistWrapper.eq(LifeBlacklist::getBlockedType, "1") // 1表示商户
+                           .eq(LifeBlacklist::getDeleteFlag, 0);
+            List<LifeBlacklist> blacklist = lifeBlacklistMapper.selectList(blacklistWrapper);
+            List<Integer> blacklistedStoreIds = new ArrayList<>();
+            if (!CollectionUtils.isEmpty(blacklist)) {
+                for (LifeBlacklist item : blacklist) {
+                    try {
+                        if (item.getBlockedId() != null && !item.getBlockedId().trim().isEmpty()) {
+                            blacklistedStoreIds.add(Integer.parseInt(item.getBlockedId()));
+                        }
+                    } catch (NumberFormatException e) {
+                        log.warn("拉黑记录中的店铺ID格式错误: {}", item.getBlockedId());
+                    }
+                }
+            }
+            
+            // 构建查询条件
+            LambdaQueryWrapper<StoreInfo> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(StoreInfo::getDeleteFlag, 0); // 未删除
+            
+            // 排除被拉黑的店铺
+            if (!blacklistedStoreIds.isEmpty()) {
+                queryWrapper.notIn(StoreInfo::getId, blacklistedStoreIds);
+            }
+            
+            // 随机排序
+            queryWrapper.last("ORDER BY RAND()");
+            
+            // 构建分页对象
+            IPage<StoreInfo> pageObj = new Page<>(pageNum, pageSize);
+            
+            // 执行分页查询
+            IPage<StoreInfo> result = storeInfoMapper.selectPage(pageObj, queryWrapper);
+            
+            // 批量查询商户头像
+            List<Integer> storeIds = new ArrayList<>();
+            for (StoreInfo store : result.getRecords()) {
+                if (store.getId() != null) {
+                    storeIds.add(store.getId());
+                }
+            }
+            
+            Map<Integer, String> headImgMap = new HashMap<>();
+            if (!storeIds.isEmpty()) {
+                LambdaQueryWrapper<StoreUser> userWrapper = new LambdaQueryWrapper<>();
+                userWrapper.in(StoreUser::getStoreId, storeIds)
+                          .eq(StoreUser::getDeleteFlag, 0);
+                List<StoreUser> storeUsers = storeUserMapper.selectList(userWrapper);
+                for (StoreUser user : storeUsers) {
+                    if (user.getStoreId() != null && user.getHeadImg() != null) {
+                        // 如果同一个店铺有多个用户,取第一个(通常是主账号)
+                        headImgMap.putIfAbsent(user.getStoreId(), user.getHeadImg());
+                    }
+                }
+            }
+            
+            // 转换为包含头像的VO对象
+            List<StoreInfoWithHeadImg> voList = new ArrayList<>();
+            for (StoreInfo store : result.getRecords()) {
+                StoreInfoWithHeadImg vo = new StoreInfoWithHeadImg();
+                BeanUtils.copyProperties(store, vo);
+                // 获取商户头像,如果没有头像则设置为null
+                String headImg = headImgMap.get(store.getId());
+                vo.setHeadImg(headImg != null && !headImg.trim().isEmpty() ? headImg : null);
+                voList.add(vo);
+            }
+            
+            // 构建返回结果
+            IPage<StoreInfoWithHeadImg> voPage = new Page<>(pageNum, pageSize, result.getTotal());
+            voPage.setRecords(voList);
+            
+            log.info("分页随机查询店铺成功 - 共{}条记录,当前页{}条", voPage.getTotal(), voList.size());
+            return R.data(voPage);
+        } catch (Exception e) {
+            log.error("分页随机查询店铺失败 - page={}, size={}, error={}", page, size, e.getMessage(), e);
+            return R.fail("查询失败: " + e.getMessage());
+        }
+    }
+    
+    /**
+     * 店铺信息(包含商户头像)
+     */
+    @Data
+    @EqualsAndHashCode(callSuper = true)
+    @JsonInclude(JsonInclude.Include.NON_NULL)
+    @ApiModel(value = "StoreInfoWithHeadImg对象", description = "店铺信息(包含商户头像)")
+    public static class StoreInfoWithHeadImg extends StoreInfo {
+        @ApiModelProperty(value = "商户头像(来自store_user表的head_img字段)")
+        @TableField(exist = false)
+        private String headImg;
+    }
+
 
 }