Sfoglia il codice sorgente

fix 获取首页配置管理

zoujiajian 2 anni fa
parent
commit
caa6db4254

+ 4 - 1
netflix-dao/src/main/java/com/cyksj/model/views/HomeManagementFrontView.java

@@ -24,7 +24,7 @@ import java.util.List;
 @Setter
 @SearchBean(tables = "(select * from home_management_config where status is true and deleted is true) hc left join goods_don g on g.id = hc.goods_id",
 		where = ":condition:",
-		orderBy = "hc.sorted desc")
+		orderBy = "hc.sorted asc")
 @JsonInclude(JsonInclude.Include.NON_NULL)
 public class HomeManagementFrontView {
 	@DbField("hc.id")
@@ -48,6 +48,9 @@ public class HomeManagementFrontView {
 	@DbField("hc.type")
 	private HomeManagementConfig.Type type;
 
+	@DbField("hc.ad_type")
+	private HomeManagementConfig.AdType adType;
+
 	@DbField("hc.pic")
 	private String pic;
 

+ 1 - 0
netflix-service/src/main/java/com/cyksj/redis/RedisService.java

@@ -625,6 +625,7 @@ public class RedisService {
         PC_WEB_CACHE("pc_web_cache", "首页平台缓存", 10 * 60),
         H5_WEB_CACHE("h5_web_cache", "h5首页平台缓存", 10 * 60),
         YH_HOME_PAGHE_CACHE("yh_home_paghe_cache:", "银河首页缓存", 30 * 60),
+        YH_HOME_PAGHE_CACHE_SHOP("yh_home_paghe_cache:shop:", "银河首页店铺缓存", 40 * 60),
         REGISTER_HOME_PAGE_CACHE("register_home_page_cache:", "注册首页缓存", 10 * 60),
         CPS_BACK_LOGIN_KEY("cps_back_login:", "cps商务后台登录key", 3 * 60),
         CPS_AUTH_SUCCESS_KEY("cps_auth_success_key:%s", "cps后台微信授权", 60 * 10),

+ 135 - 0
netflix-web/src/main/java/com/cyksj/web/controller/goods/GoodsDonController.java

@@ -35,7 +35,9 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * @author chan
@@ -406,6 +408,84 @@ public class GoodsDonController {
         return GatewayResponse.SUCCESS.newBuilder().toResult(map);
     }
 
+
+    /**
+     * 获取h5首页配置列表
+     */
+    @GetMapping("/get/homeManage")
+    public Result<Map<String, List<HomeManagementFrontView>>> getHomeManagementFrontPage(String customId) {
+        String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "homeManage";
+        Long yhsId = null;
+        if (StrUtil.isNotBlank(customId)) {
+            yhsId = yhShopFrontService.getYhsIdByCustomId(customId);
+            key = RedisService.key.YH_HOME_PAGHE_CACHE_SHOP.getEnvName() + yhsId + ":homeManage";
+        }
+        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 -> {
+                        MapBuilder builder = MapUtils.builder()
+                                .field(HomeManagementFrontView::getType, type.name());
+                        if (type == HomeManagementConfig.Type.ex || type == HomeManagementConfig.Type.vg) {
+                            builder.put("condition", conditionSql);
+                        }
+                        if (type == HomeManagementConfig.Type.ad) {
+                            builder.field(HomeManagementFrontView::getAdType, HomeManagementConfig.AdType.h5.name());
+                        }
+                        List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
+                        map.putIfAbsent(type.name(), homeManagementFrontViews);
+                    });
+            redisService.setNx(key, map, 50 * 60l);
+            o = redisService.get(key);
+        }
+        Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
+        if (map.containsKey(HomeManagementConfig.Type.ex.name()) || map.containsKey(HomeManagementConfig.Type.vg.name())) {
+            try {
+                //设置特定价格
+                List<HomeManagementFrontView> exList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.ex.name())), HomeManagementFrontView.class);
+                if (CollUtil.isNotEmpty(exList)) {
+                    setHomeManageSpecific(exList, fUid);
+                    map.put(HomeManagementConfig.Type.ex.name(), exList);
+                }
+                //设置特定价格
+                List<HomeManagementFrontView> vgList = Jsons.parseList(Jsons.toJson(map.get(HomeManagementConfig.Type.vg.name())), HomeManagementFrontView.class);
+                if (CollUtil.isNotEmpty(vgList)) {
+                    setHomeManageSpecific(vgList, fUid);
+                    map.put(HomeManagementConfig.Type.vg.name(), vgList);
+                }
+            } catch (Exception e) {
+            }
+        }
+        return GatewayResponse.SUCCESS.newBuilder().toResult(map);
+    }
+
+    /**
+     * 获取pc广告配置
+     */
+    @GetMapping("/get/pc/homeManage")
+    public Result<Map<String, List<HomeManagementFrontView>>> getPcHomeManagementFrontPage() {
+        String key = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "pc:homeManage";
+        Object o = redisService.get(key);
+        if (o == null) {
+            MapBuilder builder = MapUtils.builder()
+                    .field(HomeManagementFrontView::getAdType, List.of(HomeManagementConfig.AdType.pc.name(), HomeManagementConfig.AdType.pcSec.name(), HomeManagementConfig.AdType.pcDis.name())).op(Operator.InList);
+            List<HomeManagementFrontView> homeManagementFrontViews = beanSearcher.searchAll(HomeManagementFrontView.class, builder.build());
+            Map<HomeManagementConfig.AdType, List<HomeManagementFrontView>> map = homeManagementFrontViews.stream().collect(Collectors.groupingBy(HomeManagementFrontView::getAdType));
+            redisService.setNx(key, map, 50 * 60l);
+            o = redisService.get(key);
+        }
+        Map<String, List<HomeManagementFrontView>> map = Jsons.parseObject(o, Map.class);
+        return GatewayResponse.SUCCESS.newBuilder().toResult(map);
+    }
+
+
     public List<Long> getFilterGoodsIds() {
         //过滤杭州Ai ChatGPT平台
         //获取当前ip地址
@@ -549,6 +629,61 @@ public class GoodsDonController {
         }
     }
 
+    /**
+     * 获取特定规格
+     */
+    public List<GoodsDonSku> getSpecificSku(Long goodsId) {
+        //查找所有特定规格最小价格 满足条件
+        String specificGoodsKey = RedisService.key.YH_HOME_PAGHE_CACHE.getEnvName() + "specific:" + goodsId;
+        Object speciObj = redisService.get(specificGoodsKey);
+        List<GoodsDonSku> specificSkus = null;
+        if (speciObj != null) {
+            specificSkus = Jsons.parseList(speciObj, GoodsDonSku.class);
+        } else {
+            specificSkus = goodsDonSkuMapper.selectList(
+                    Wrappers.lambdaQuery(GoodsDonSku.class)
+                            .eq(GoodsDonSku::getGoodsId, goodsId)
+                            .eq(GoodsDonSku::getStatus, true)
+                            .gt(GoodsDonSku::getSpecificPrice, 0));
+            redisService.setNx(specificGoodsKey, specificSkus, RedisService.key.YH_HOME_PAGHE_CACHE.getTimeout());
+        }
+        specificSkus = Optional.ofNullable(specificSkus).orElse(new ArrayList<>());
+        return specificSkus;
+    }
+
+    /**
+     * 设置首页配置 涉及平台特定价格
+     */
+    public void setHomeManageSpecific(List<HomeManagementFrontView> list, Long fUid) {
+        DateTime now = DateTime.now();
+        list.forEach(data -> {
+            if (data.getIsSp() != null && data.getIsSp() && fUid != null) {
+                //查找所有特定规格最小价格 满足条件
+                List<GoodsDonSku> specificSkus = getSpecificSku(data.getGoodsId());
+                specificSkus.forEach(specificSku -> {
+                    String specificGoodsIdsStr = specificSku.getSpecificGoodsIds();
+                    if (isPaySpecificGoodsIds(specificGoodsIdsStr, fUid)) {
+                        BigDecimal specificPrice = data.getSpecificPrice();
+                        BigDecimal skuSpecificPrice = specificSku.getSpecificPrice();
+                        Long specificSkuId = specificSku.getId();
+                        if (specificPrice == null) {
+                            data.setSpecificPrice(skuSpecificPrice);
+                            data.setSpecificSkuId(specificSkuId);
+                        } else if (specificPrice.compareTo(skuSpecificPrice) > 0) {
+                            data.setSpecificPrice(skuSpecificPrice);
+                            data.setSpecificSkuId(specificSkuId);
+                        }
+                    }
+                });
+            }
+            Integer sold = orderDonMapper.selectCount(Wrappers.lambdaQuery(OrderDon.class)
+                    .eq(OrderDon::getGoodsId, data.getGoodsId()).notIn(OrderDon::getStatus, Constant.noOrderStatus));
+            data.setSold(sold + data.getSold());
+            data.setNotifyMsg(getPayMsgTime(data.getGoodsId(), now, 1, null));
+        });
+    }
+
+
     /**
      * 店铺平台列表
      */