Ver código fonte

Merge remote-tracking branch 'origin/master'

wxd 4 meses atrás
pai
commit
210d0818e2

+ 4 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/StoreInfoVo.java

@@ -12,6 +12,7 @@ import shop.alien.entity.store.StoreInfo;
 import shop.alien.entity.store.StoreStaffConfig;
 
 import java.util.List;
+import java.util.Map;
 
 @EqualsAndHashCode(callSuper = true)
 @Data
@@ -173,5 +174,8 @@ public class StoreInfoVo extends StoreInfo {
     @ApiModelProperty(value = "验证码")
     private String verificationCode;
 
+    private List<Map<String, Object>> quanMapList;
+
+    private String storeClockInCount;
 
 }

+ 12 - 3
alien-entity/src/main/java/shop/alien/mapper/StoreInfoMapper.java

@@ -92,7 +92,16 @@ public interface StoreInfoMapper extends BaseMapper<StoreInfo> {
     @Select("select * from store_info ${ew.customSqlSegment}")
     List<StoreInfo> getList(@Param(Constants.WRAPPER) LambdaQueryWrapper<StoreInfo> queryWrapper);
 
-    @Select("select *," +
-            "            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(store_position, ',', ' '), ')' ))) / 1000, 2) dist from store_info ${ew.customSqlSegment}")
-    IPage<StoreInfo> getPageForDistance(IPage<StoreInfo> page,@Param(Constants.WRAPPER) QueryWrapper<StoreInfo> queryWrapper,  @Param("position") String position);
+    @Select("with menu as (select store_id,GROUP_CONCAT(dish_name) dish_name from store_menu GROUP BY store_id) " +
+            "select a.*," +
+            "            ROUND(ST_Distance_Sphere(ST_GeomFromText(CONCAT('POINT(', REPLACE(#{position}, ',', ' '), ')' )), ST_GeomFromText(CONCAT('POINT(', REPLACE(a.store_position, ',', ' '), ')' ))) / 1000, 2) dist" +
+            ", b.name store_contact, b.phone store_phone, b.password, c.dish_name,  img.img_url entranceImage, d.img_url, dict.dict_detail storeTypeStr, dict2.dict_detail businessStatusStr " +
+            "from store_info a " +
+            "left join store_user b on a.id = b.store_id  AND b.delete_flag = 0 " +
+            "left join menu c on a.id = c.store_id " +
+            "left join store_img img on img.store_id = a.id and img.img_type = 1 and img.delete_flag = 0 " +
+            "left join store_dictionary dict on dict.type_name = 'storeType' and dict.dict_id = a.store_type and dict.delete_flag = 0 " +
+            "left join store_dictionary dict2 on dict2.type_name = 'businessStatus' and a.business_status = dict2.dict_id and dict2.delete_flag = 0 " +
+            "left join store_img d on d.store_id = a.id and d.img_type = 10 and d.delete_flag = 0 ${ew.customSqlSegment}")
+    IPage<StoreInfoVo> getPageForDistance(IPage<StoreInfoVo> page,  @Param("position") String position,@Param(Constants.WRAPPER) QueryWrapper<StoreInfoVo> queryWrapper);
 }

+ 4 - 3
alien-store/src/main/java/shop/alien/store/controller/StoreInfoController.java

@@ -487,7 +487,7 @@ public class StoreInfoController {
      */
     @ApiOperation("新八大类用户端筛选")
     @PostMapping(value = "getScreeningNew")
-    public R<IPage<StoreInfo>> getScreeningNew(@RequestBody ScreeningOfEightMajorCategoriesVO screeningOfEightMajorCategoriesVO) {
+    public R<IPage<StoreInfoVo>> getScreeningNew(@RequestBody ScreeningOfEightMajorCategoriesVO screeningOfEightMajorCategoriesVO) {
         // 参数校验
         if (screeningOfEightMajorCategoriesVO == null) {
             return R.fail("筛选参数不能为空");
@@ -505,7 +505,7 @@ public class StoreInfoController {
 
         try {
             // 调用服务层获取筛选结果
-            IPage<StoreInfo> result = storeInfoService.getScreeningNew(screeningOfEightMajorCategoriesVO);
+            IPage<StoreInfoVo> result = storeInfoService.getScreeningNew(screeningOfEightMajorCategoriesVO);
 
             // 记录响应日志
             log.info("新八大类用户端筛选响应 - 总记录数: {}, 当前页: {}, 页大小: {}",
@@ -517,7 +517,8 @@ public class StoreInfoController {
             return R.fail(e.getMessage());
         } catch (Exception e) {
             log.error("新八大类用户端筛选异常", e);
-            return R.fail("筛选失败,请稍后重试");
+            return R.data(null);
+            //return R.fail("筛选失败,请稍后重试");
         }
     }
 

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/LifeUserStoreService.java

@@ -74,7 +74,7 @@ public class LifeUserStoreService {
             // 过滤已删除的门店
             wrapper.eq("a.delete_flag", 0);
             // 过滤非营业中的门店
-            wrapper.in(null != storeType && !"".equals(storeType), "a.business_section", Arrays.asList(storeType.split(",")));
+            wrapper.in(null != storeType && !"".equals(storeType), "a.store_type", Arrays.asList(storeType.split(",")));
             // 过滤掉永久关门的店铺
             wrapper.ne("a.business_status", 99);
             // 根据构建的条件查询门店信息

+ 1 - 1
alien-store/src/main/java/shop/alien/store/service/StoreInfoService.java

@@ -189,7 +189,7 @@ public interface StoreInfoService extends IService<StoreInfo> {
      * 八大类用户端筛选
      */
     IPage<StoreInfo> getScreening(ScreeningOfEightMajorCategoriesVO screeningOfEightMajorCategoriesVO);
-    IPage<StoreInfo> getScreeningNew(ScreeningOfEightMajorCategoriesVO screeningOfEightMajorCategoriesVO);
+    IPage<StoreInfoVo> getScreeningNew(ScreeningOfEightMajorCategoriesVO screeningOfEightMajorCategoriesVO);
 
     List<StoreInfo> getBusinessTypesName(String businessTypesNames);
 

+ 112 - 8
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -35,6 +35,7 @@ import shop.alien.mapper.*;
 import shop.alien.store.config.BaseRedisService;
 import shop.alien.store.config.GaoDeMapUtil;
 import shop.alien.store.service.NearMeService;
+import shop.alien.store.service.StoreClockInService;
 import shop.alien.store.service.StoreInfoService;
 import shop.alien.store.util.FileUploadUtil;
 import shop.alien.store.util.GroupConstant;
@@ -111,6 +112,8 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
 
     private final LifeGroupBuyMainMapper lifeGroupBuyMainMapper;
 
+    private final StoreClockInService storeClockInService;
+
     @Value("${spring.web.resources.excel-path}")
     private String excelPath;
 
@@ -1388,7 +1391,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
     }
 
     @Override
-    public IPage<StoreInfo> getScreeningNew(ScreeningOfEightMajorCategoriesVO vo) {
+    public IPage<StoreInfoVo> getScreeningNew(ScreeningOfEightMajorCategoriesVO vo) {
         // 参数校验
         if (vo == null) {
             throw new IllegalArgumentException("筛选参数不能为空");
@@ -1409,7 +1412,7 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
             throw new IllegalArgumentException("经纬度参数不能为空");
         }
         // 创建分页对象
-        IPage<StoreInfo> page = new Page<>(vo.getPageNum(), vo.getPageSize());
+        IPage<StoreInfoVo> page = new Page<>(vo.getPageNum(), vo.getPageSize());
 
         String storeId = "";
 
@@ -1429,8 +1432,8 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         }
 
         // 通过商家id获取商家信息
-        IPage<StoreInfo> storeInfoIPage = new Page<>();
-        QueryWrapper<StoreInfo> queryWrapper = new QueryWrapper<>();
+        IPage<StoreInfoVo> storeInfoIPage = new Page<>();
+        QueryWrapper<StoreInfoVo> queryWrapper = new QueryWrapper<>();
         if (StringUtils.isNotEmpty(storeId)) {
             List<String> storeIds = Arrays.asList(storeId.split(","));
             if (StringUtils.isNotEmpty(startTime) && StringUtils.isNotEmpty(endTime)) {
@@ -1473,12 +1476,13 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
                         .collect(Collectors.toList());
             }
             if (!CollectionUtils.isEmpty(storeIds)) {
-                queryWrapper.in("id", storeIds);
+                queryWrapper.in("a.id", storeIds);
             }
         }
 
-        queryWrapper.like(StringUtils.isNotEmpty(vo.getFoodType()), "business_types_name", vo.getFoodType());
-        queryWrapper.like(StringUtils.isNotEmpty(vo.getStoreName()), "store_name", vo.getStoreName());
+        queryWrapper.eq("a.delete_flag",0);
+        queryWrapper.like(StringUtils.isNotEmpty(vo.getFoodType()), "a.business_types_name", vo.getFoodType());
+        queryWrapper.like(StringUtils.isNotEmpty(vo.getStoreName()), "a.store_name", vo.getStoreName());
 
         if (ObjectUtils.isNotEmpty(vo.getRqyx())) {
             if (vo.getRqyx() == 1) {
@@ -1486,7 +1490,107 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
             }
         }
         queryWrapper.orderByAsc("dist");
-        storeInfoIPage = storeInfoMapper.getPageForDistance(page, queryWrapper, lon + "," + lat);
+        storeInfoIPage = storeInfoMapper.getPageForDistance(page,lon + "," + lat, queryWrapper);
+        List<StoreInfoVo> storeInfoVoList = storeInfoIPage.getRecords();
+
+        // 提取所有符合条件的门店ID
+        List<Integer> storeIds = storeInfoVoList.stream().map(StoreInfoVo::getId).collect(Collectors.toList());
+        // 构建查询优惠券的条件对象
+        LambdaUpdateWrapper<LifeCoupon> quanWrapper = new LambdaUpdateWrapper<>();
+        // 添加门店ID筛选条件
+        quanWrapper.in(LifeCoupon::getStoreId, storeIds)
+                // 添加优惠券状态筛选条件
+                .eq(LifeCoupon::getStatus, 1)
+                // 按照创建时间降序排序
+                .orderByDesc(LifeCoupon::getCreatedTime);
+        // 查询符合条件的优惠券列表
+        List<LifeCoupon> quanList = lifeCouponMapper.selectList(quanWrapper);
+        // 获取全部店铺的评分与平均花销
+        Map<Object, List<Map<String, Object>>> avgScoreMap = storeEvaluationMapper.allStoreAvgScore().stream().collect(Collectors.groupingBy(o -> o.get("store_id")));
+        // 获取用户订单信息,用于计算平均消费
+        Map<Object, List<Map<String, Object>>> avgPriceMap = lifeUserOrderMapper.allStoreAvgPrice().stream().collect(Collectors.groupingBy(o -> o.get("store_id")));
+        // 获取所有店铺的打卡次数
+        List<Map<Integer, Integer>> storeClockInCountList = storeClockInService.getStoreClockInCount();
+        // 遍历所有门店信息,构造返回结果
+        for (StoreInfoVo store : storeInfoVoList) {
+            Map<String, Object> storeMap = new HashMap<>();
+            storeMap.put("dist",store.getDist());
+            // 添加门店的业务状态及其描述
+            storeMap.put("businessStatus", store.getBusinessStatus());
+            storeMap.put("businessStatusStr", store.getBusinessStatusStr());
+            // 添加门店ID
+            storeMap.put("storeId", store.getId());
+            // 如果存在评分数据,则添加评分、平均消费及评价总数
+            if (avgScoreMap.containsKey(String.valueOf(store.getId()))) {
+                store.setAvgScore(avgScoreMap.get(String.valueOf(store.getId())).get(0).get("avg_score").toString());
+                store.setAvgPrice(avgPriceMap.get(String.valueOf(store.getId())).get(0).get("avg_price").toString());
+                store.setTotalNum(avgScoreMap.get(String.valueOf(store.getId())).get(0).get("total_num").toString());
+                /*storeMap.put("avgScore", avgScoreMap.get(String.valueOf(store.getId())).get(0).get("avg_score"));
+                storeMap.put("avgPrice", avgPriceMap.get(String.valueOf(store.getId())).get(0).get("avg_price"));
+                // 条数
+                storeMap.put("totalNum", avgScoreMap.get(String.valueOf(store.getId())).get(0).get("total_num"));*/
+            } else {
+                // 否则,设置默认值
+                /*storeMap.put("avgScore", 0);
+                storeMap.put("avgPrice", 0);
+                storeMap.put("totalNum", 0);*/
+                store.setAvgScore("0");
+                store.setAvgPrice("0");
+                store.setTotalNum("0");
+            }
+            // 添加门店名称
+            storeMap.put("storeName", store.getStoreName());
+            // 添加门店地址
+            storeMap.put("storeAddress", store.getStoreAddress());
+            // 添加门店类型
+            storeMap.put("storeType", store.getStoreType());
+            // 添加门店入口图片
+            storeMap.put("entranceImage", store.getEntranceImage());
+            // 添加门店图片
+            storeMap.put("storeImage", store.getImgUrl());
+            // 解析并添加门店经纬度
+            String[] position = store.getStorePosition().split(",");
+            storeMap.put("longitude", position.length == 2 ? position[0] : "");
+            storeMap.put("latitude", position.length == 2 ? position[1] : "");
+            // 构造该门店的优惠券列表
+            List<Map<String, Object>> quanMapList = new ArrayList<>();
+            if (!quanList.isEmpty()) {
+                for (LifeCoupon quan : quanList) {
+                    // 如果优惠券的门店ID与当前门店ID匹配,则添加到优惠券列表中
+                    if (store.getId().toString().equals(quan.getStoreId())) {
+                        Map<String, Object> quanMap = new HashMap<>();
+                        quanMap.put("quanType", quan.getType());
+                        quanMap.put("name", quan.getName());
+                        quanMap.put("price", quan.getPrice());
+                        // 折扣价
+                        quanMap.put("offprice", quan.getOffprice());
+                        quanMap.put("quanId", quan.getId());
+                        quanMapList.add(quanMap);
+                    }
+                }
+                // 将优惠券列表添加到门店信息中
+                storeMap.put("quanList", quanMapList);
+                store.setQuanList(quanMapList);
+            }
+            // 添加门店类型的描述
+            storeMap.put("storeTypeStr", store.getStoreTypeStr());
+            // 遍历打卡次数列表,找到当前门店的打卡次数并添加到门店信息中
+            storeClockInCountList.forEach(b -> {
+                Integer stId = b.get("storeId");
+                if (Objects.equals(stId, store.getId())) {
+                    storeMap.put("storeClockInCount", b.get("count"));
+                    store.setStoreClockInCount(String.valueOf(b.get("count")));
+                }
+            });
+            // 如果未找到打卡次数,则设置为0
+            if (null == storeMap.get("storeClockInCount")) {
+                storeMap.put("storeClockInCount", 0);
+                store.setStoreClockInCount("0");
+            }
+            // 将当前门店的信息添加到返回结果列表中
+            //returnMaps.add(storeMap);
+        }
+
         return storeInfoIPage;
     }