Parcourir la source

首页缓存修改

chenbiao il y a 9 mois
Parent
commit
9f8d6683a8

+ 34 - 28
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -633,34 +633,40 @@ public class GoodsDonController {
 		Long fUid = StpUserUtil.getUserIdAfterLogin();
 		Object o = redisService.get(key);
 		if (o == null) {
-			String condition = "g.deleted is true and g.status is true";
-			if (yhsId != null) {
-				condition += String.format(" and g.id in (select distinct goods_id from yh_shop_goods_sku where yhs_id = %s and status is true and deleted is true) and g.is_distribute is true", yhsId);
-			}
-			Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
-			final String conditionSql = condition;
-			Stream.of(HomeManagementConfig.Type.values())
-					.forEach(type -> {
-						if (isRemoveRg.get() && type == HomeManagementConfig.Type.rg) {
-							return;
-						}
-						MapBuilder builder = MapUtils.builder()
-								.field(HomeManagementFrontView::getType, type.name());
-						if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
-							builder.put("condition", conditionSql);
-							if (CollUtil.isNotEmpty(filter_goodsIds)) {
-								builder.field(HomeManagementFrontView::getGoodsId, filter_goodsIds).op(Operator.NotIn);
-							}
-						}
-						List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
-						//实物推荐多语言
-						if (language.get() && type == HomeManagementConfig.Type.rg) {
-							backInfoTranslationsFrontService.getHomeConfigRealGoodsLanguage(homeManagementFrontViews, lang);
-						}
-						map.putIfAbsent(type.name(), homeManagementFrontViews);
-					});
-			redisService.setNx(key, map, 50 * 60l);
-			o = redisService.get(key);
+			try {
+                String condition = "g.deleted is true and g.status is true";
+                if (yhsId != null) {
+                    condition += String.format(" and g.id in (select distinct goods_id from yh_shop_goods_sku where yhs_id = %s and status is true and deleted is true) and g.is_distribute is true", yhsId);
+                }
+                Map<String, List<HomeManagementFrontView>> map = new ConcurrentHashMap<>();
+                final String conditionSql = condition;
+                Stream.of(HomeManagementConfig.Type.values())
+                        .forEach(type -> {
+                            if (isRemoveRg.get() && type == HomeManagementConfig.Type.rg) {
+                                return;
+                            }
+                            MapBuilder builder = MapUtils.builder()
+                                    .field(HomeManagementFrontView::getType, type.name());
+                            if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
+                                builder.put("condition", conditionSql);
+                                if (CollUtil.isNotEmpty(filter_goodsIds)) {
+                                    builder.field(HomeManagementFrontView::getGoodsId, filter_goodsIds).op(Operator.NotIn);
+                                }
+                            }
+                            List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
+                            //实物推荐多语言
+                            if (language.get() && type == HomeManagementConfig.Type.rg) {
+                                backInfoTranslationsFrontService.getHomeConfigRealGoodsLanguage(homeManagementFrontViews, lang);
+                            }
+                            map.putIfAbsent(type.name(), homeManagementFrontViews);
+                        });
+                redisService.setNx(key, map, 60 * 60l * 24 * 7);
+                o = redisService.get(key);
+            }catch (Exception e) {
+                //如果出现异常,先缓存空map
+                redisService.setNx(key, new ConcurrentHashMap<>(), 10L);
+                o = redisService.get(key);
+            }
 		}
 		AtomicLong dsUserId = new AtomicLong();
 		AtomicBoolean existsChannel = new AtomicBoolean(true);