Browse Source

推荐列表修改

zhangchen 2 weeks ago
parent
commit
fc4a468d57

+ 54 - 59
alien-store/src/main/java/shop/alien/store/service/impl/StoreInfoServiceImpl.java

@@ -2500,76 +2500,71 @@ public class StoreInfoServiceImpl extends ServiceImpl<StoreInfoMapper, StoreInfo
         if (CollectionUtils.isEmpty(storeInfoVoList)) {
             return Collections.emptyList();
         }
-        if (!storeInfoVoList.isEmpty()) {
-            // 提前查询所有需要的字典数据
-            List<StoreInfoVo> collect = storeInfoVoList.stream().filter(record -> StringUtils.isNotEmpty(record.getStoreType())).collect(Collectors.toList());
-            Set<String> allTypes = collect.stream().map(StoreInfoVo::getStoreType).flatMap(type -> Arrays.stream(type.split(","))).collect(Collectors.toSet());
+        // 提前查询所有需要的字典数据
+        List<StoreInfoVo> collect = storeInfoVoList.stream().filter(record -> StringUtils.isNotEmpty(record.getStoreType())).collect(Collectors.toList());
+        Set<String> allTypes = collect.stream().map(StoreInfoVo::getStoreType).flatMap(type -> Arrays.stream(type.split(","))).collect(Collectors.toSet());
 
-            List<StoreDictionary> storeDictionaries = storeDictionaryMapper.selectList(new LambdaQueryWrapper<StoreDictionary>().eq(StoreDictionary::getTypeName, "storeType").isNull(StoreDictionary::getParentId).in(!allTypes.isEmpty(), StoreDictionary::getDictId, allTypes));
-            Map<String, String> typeMap = storeDictionaries.stream().collect(Collectors.toMap(StoreDictionary::getDictId, StoreDictionary::getDictDetail));
+        List<StoreDictionary> storeDictionaries = storeDictionaryMapper.selectList(new LambdaQueryWrapper<StoreDictionary>().eq(StoreDictionary::getTypeName, "storeType").isNull(StoreDictionary::getParentId).in(!allTypes.isEmpty(), StoreDictionary::getDictId, allTypes));
+        Map<String, String> typeMap = storeDictionaries.stream().collect(Collectors.toMap(StoreDictionary::getDictId, StoreDictionary::getDictDetail));
 
-            Map<Object, List<Map<String, Object>>> avgScoreMap = new HashMap<>();
-            Map<Integer, List<StoreComment>> commentMap = new HashMap<>();
 
-            // 如果获取美食列表进行以下前置操作
-            List<Integer> storeIds = storeInfoVoList.stream().map(StoreInfoVo::getId).collect(Collectors.toList());
-            LambdaUpdateWrapper<LifeCoupon> quanWrapper = new LambdaUpdateWrapper<>();
-            quanWrapper.in(LifeCoupon::getStoreId, storeIds).eq(LifeCoupon::getStatus, 1).orderByDesc(LifeCoupon::getCreatedTime);
+        // 计算平均分和评价
+        Map<Object, List<Map<String, Object>>> avgScoreMap = new HashMap<>();
+        Map<Integer, List<StoreComment>> commentMap = new HashMap<>();
 
-            avgScoreMap = storeEvaluationMapper.allStoreAvgScore().stream().collect(Collectors.groupingBy(o -> o.get("store_id")));
-            commentMap = storeCommentMapper.selectList(new QueryWrapper<StoreComment>().eq("business_type", "5").eq("delete_flag", 0)).stream().collect(Collectors.groupingBy(StoreComment::getStoreId));
+        avgScoreMap = storeEvaluationMapper.allStoreAvgScore().stream().collect(Collectors.groupingBy(o -> o.get("store_id")));
+        commentMap = storeCommentMapper.selectList(new QueryWrapper<StoreComment>().eq("business_type", "5").eq("delete_flag", 0)).stream().collect(Collectors.groupingBy(StoreComment::getStoreId));
 
 
-            for (StoreInfoVo record : storeInfoVoList) {
-                //处理类型
-                if (StringUtils.isNotEmpty(record.getStoreType())) {
-                    String[] types = record.getStoreType().split(",");
-                    List<String> typeDetails = Arrays.stream(types).map(typeMap::get).filter(Objects::nonNull).collect(Collectors.toList());
-                    record.setStoreTypeStr(String.join(",", typeDetails));
-                    record.setStoreTypeList(Arrays.asList(types));
-                }
-                //写经纬度
-                String[] split = record.getStorePosition().split(",");
-                record.setStorePositionLongitude(split[0]);
-                record.setStorePositionLatitude(split[1]);
-                //处理一下到期状态
-                Date expirationTime = record.getExpirationTime();
-                if (expirationTime != null) {
-                    // 获取当前时间
-                    Calendar now = Calendar.getInstance();
-                    Date nowCurrentDate = now.getTime();
-                    // 计算 30 天后的时间
-                    now.add(Calendar.DAY_OF_YEAR, 30);
-                    Date thirtyDaysLater = now.getTime();
-                    // 比较两个日期
-                    if (expirationTime.after(currentDate)) {
-                        record.setExpiredState("0");
-                        if ((expirationTime.after(nowCurrentDate) || expirationTime.equals(nowCurrentDate)) && expirationTime.before(thirtyDaysLater)) {
-                            record.setExpiredState("1");
-                        }
-                    } else {
-                        record.setExpiredState("2");
+        for (StoreInfoVo record : storeInfoVoList) {
+            //处理类型
+            if (StringUtils.isNotEmpty(record.getStoreType())) {
+                String[] types = record.getStoreType().split(",");
+                List<String> typeDetails = Arrays.stream(types).map(typeMap::get).filter(Objects::nonNull).collect(Collectors.toList());
+                record.setStoreTypeStr(String.join(",", typeDetails));
+                record.setStoreTypeList(Arrays.asList(types));
+            }
+            //写经纬度
+            String[] split = record.getStorePosition().split(",");
+            record.setStorePositionLongitude(split[0]);
+            record.setStorePositionLatitude(split[1]);
+            //处理一下到期状态
+            Date expirationTime = record.getExpirationTime();
+            if (expirationTime != null) {
+                // 获取当前时间
+                Calendar now = Calendar.getInstance();
+                Date nowCurrentDate = now.getTime();
+                // 计算 30 天后的时间
+                now.add(Calendar.DAY_OF_YEAR, 30);
+                Date thirtyDaysLater = now.getTime();
+                // 比较两个日期
+                if (expirationTime.after(currentDate)) {
+                    record.setExpiredState("0");
+                    if ((expirationTime.after(nowCurrentDate) || expirationTime.equals(nowCurrentDate)) && expirationTime.before(thirtyDaysLater)) {
+                        record.setExpiredState("1");
                     }
-
-                    // 获取当前时间
-                    LocalDate nowLocal = LocalDate.now();
-                    // 将 expirationTime 转换为 LocalDate
-                    LocalDate expDate = expirationTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
-                    // 计算距离到期的天数
-                    long daysToExpire = ChronoUnit.DAYS.between(nowLocal, expDate);
-                    record.setDaysToExpire(daysToExpire);
+                } else {
+                    record.setExpiredState("2");
                 }
 
-                // 设置店铺得分,设置店铺人均消费,设置总评论数
-                if (avgScoreMap.containsKey(String.valueOf(record.getId()))) {
-                    record.setAvgScore(String.valueOf(avgScoreMap.get(String.valueOf(record.getId())).get(0).get("avg_score")));
-                }
-                // 设置店铺得分,设置店铺人均消费,设置总评论
-                if (commentMap.containsKey(record.getId())) {
-                    record.setTotalNum(String.valueOf(commentMap.get(record.getId()).size()));
-                }
+                // 获取当前时间
+                LocalDate nowLocal = LocalDate.now();
+                // 将 expirationTime 转换为 LocalDate
+                LocalDate expDate = expirationTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+                // 计算距离到期的天
+                long daysToExpire = ChronoUnit.DAYS.between(nowLocal, expDate);
+                record.setDaysToExpire(daysToExpire);
+            }
 
+            // 设置店铺得分,设置店铺人均消费,设置总评论数
+            if (avgScoreMap.containsKey(String.valueOf(record.getId()))) {
+                record.setAvgScore(String.valueOf(avgScoreMap.get(String.valueOf(record.getId())).get(0).get("avg_score")));
+            }
+            // 设置店铺得分,设置店铺人均消费,设置总评论数
+            if (commentMap.containsKey(record.getId())) {
+                record.setTotalNum(String.valueOf(commentMap.get(record.getId()).size()));
             }
+
         }
         if (lon == null || lat == null) {
             log.warn("获取更多推荐店铺失败,经纬度为空");