Browse Source

分类商品列表速度慢

fubojin 1 week ago
parent
commit
cbf05796dd

+ 1 - 1
yami-shop-api/src/main/java/com/yami/shop/api/controller/OrderController.java

@@ -118,7 +118,7 @@ public class OrderController {
         System.out.println("orderParam.getBasketIds()"+orderParam.getBasketIds());
         System.out.println("orderItem"+orderItem);
         System.out.println("userId"+userId);
-        List<ShopCartItemDto> shopCartItems = basketService.getShopCartItemsByOrderItems(orderParam.getBasketIds(), orderItem, userId);
+        List<ShopCartItemDto> shopCartItems = basketService.getShopCartItemsByOrderItems(orderParam.getBasketIds(), orderItem, userId,orderParam.getChannelId());
         if (CollectionUtil.isEmpty(shopCartItems)) {
             throw new GlobalException("请选择您需要的商品加入购物车");
         }

+ 29 - 32
yami-shop-api/src/main/java/com/yami/shop/api/controller/ShopCartController.java

@@ -53,34 +53,33 @@ public class ShopCartController {
 
     private UserCollectionService userCollectionService;
 
-    /**
-     * 获取用户购物车信息
-     *
-     * @param shopCartParams 购物车参数对象列表
-     * @return
-     */
-    @PostMapping("/info")
-    @ApiOperation(value = "获取用户购物车信息", notes = "获取用户购物车信息,参数为用户选中的活动项数组")
-    public ResponseEntity<List<ShopCartDto>> info(@RequestBody List<ShopCartParam> shopCartParams) {
-        String userId = SecurityUtils.getUser().getUserId();
-//        String userId = "5e31932043984353beb4c1a2622f5182";
-
-        // 更新购物车信息,
-        if (CollectionUtil.isNotEmpty(shopCartParams)) {
-            basketService.updateBasketByShopCartParam(userId, shopCartParams);
-        }
-
-        // 拿到购物车的所有item
-        List<ShopCartItemDto> shopCartItems = basketService.getShopCartItems(userId);
-        List<Long> prodIds = new ArrayList<>();
-        for (ShopCartItemDto shopCartItemDto : shopCartItems) {
-            prodIds.add(shopCartItemDto.getProdId());
-        }
-        Long shopId = 0L;
-        if (!shopCartParams.isEmpty()) shopId = shopCartParams.get(0).getShopId();
-        return ResponseEntity.ok(basketService.getShopCarts(shopCartItems, shopId));
-
-    }
+//    /**
+//     * 获取用户购物车信息
+//     *
+//     * @param shopCartParams 购物车参数对象列表
+//     * @return
+//     */
+//    @PostMapping("/info")
+//    @ApiOperation(value = "获取用户购物车信息", notes = "获取用户购物车信息,参数为用户选中的活动项数组")
+//    public ResponseEntity<List<ShopCartDto>> info(@RequestParam("channelId") Long channelId,@RequestBody List<ShopCartParam> shopCartParams) {
+//        String userId = SecurityUtils.getUser().getUserId();
+//
+//        // 更新购物车信息,
+//        if (CollectionUtil.isNotEmpty(shopCartParams)) {
+//            basketService.updateBasketByShopCartParam(userId, shopCartParams);
+//        }
+//
+//        // 拿到购物车的所有item
+//        List<ShopCartItemDto> shopCartItems = basketService.getShopCartItems(userId, channelId);
+//        List<Long> prodIds = new ArrayList<>();
+//        for (ShopCartItemDto shopCartItemDto : shopCartItems) {
+//            prodIds.add(shopCartItemDto.getProdId());
+//        }
+//        Long shopId = 0L;
+//        if (!shopCartParams.isEmpty()) shopId = shopCartParams.get(0).getShopId();
+//        return ResponseEntity.ok(basketService.getShopCarts(shopCartItems, shopId));
+//
+//    }
 
     /**
      * 获取用户购物车信息
@@ -229,12 +228,10 @@ public class ShopCartController {
 
     @PostMapping("/totalPay")
     @ApiOperation(value = "获取选中购物项总计、选中的商品数量", notes = "获取选中购物项总计、选中的商品数量,参数为购物车id数组")
-    public ResponseEntity<ShopCartAmountDto> getTotalPay(@RequestBody List<Long> basketIds) {
+    public ResponseEntity<ShopCartAmountDto> getTotalPay(@RequestParam("channelId") Long channelId, @RequestBody List<Long> basketIds) {
 
         // 拿到购物车的所有item
-        //List<ShopCartItemDto> dbShopCartItems = basketService.getShopCartItems(SecurityUtils.getUser().getUserId());
-        List<ShopCartItemDto> dbShopCartItems = basketService.getShopCartItems(SecurityUtils.getUser().getUserId());
-
+        List<ShopCartItemDto> dbShopCartItems = basketService.getShopCartItems(SecurityUtils.getUser().getUserId(), channelId);
         List<ShopCartItemDto> chooseShopCartItems = dbShopCartItems
                 .stream()
                 .filter(shopCartItemDto -> {

+ 0 - 5
yami-shop-bean/src/main/java/com/yami/shop/bean/app/param/OrderParam.java

@@ -57,11 +57,6 @@ public class OrderParam {
     @ApiModelProperty(value = "门店ID")
     private Long shopId;
 
-//	@ApiModelProperty(value = "每次订单提交时的uuid")
-//	private String uuid;
-//	@ApiModelProperty(value = "订单入口 SHOP_CART购物车,BUY_NOW立即购买")
-//	private OrderEntry orderEntry;
-
 
 
 }

+ 5 - 1
yami-shop-bean/src/main/java/com/yami/shop/bean/model/Basket.java

@@ -22,7 +22,6 @@ public class Basket implements Serializable {
      * 主键
      */
     @TableId
-
     private Long basketId;
 
     /**
@@ -31,6 +30,11 @@ public class Basket implements Serializable {
 
     private Long shopId;
 
+    /**
+     * 渠道 ID
+     */
+    private Long channelId;
+
     /**
      * 产品ID
      */

+ 2 - 2
yami-shop-platform/src/main/resources/application.yml

@@ -1,8 +1,8 @@
 spring:
   # 环境 dev|prod|docker quartz定时任务
   profiles:
-#    active: dev
-    active: prod
+    active: dev
+#    active: prod
   #文件上传设置
   servlet:
 

+ 3 - 3
yami-shop-service/src/main/java/com/yami/shop/service/BasketService.java

@@ -33,7 +33,7 @@ public interface BasketService extends IService<Basket> {
 
     void deleteAllShopCartItems(String userId);
 
-    List<ShopCartItemDto> getShopCartItems(String userId);
+//    List<ShopCartItemDto> getShopCartItems(Long channelId,String userId);
 
     List<ShopCartItemDto> getShopCartItems(String userId, Long channelId);
 
@@ -61,11 +61,11 @@ public interface BasketService extends IService<Basket> {
 
     /**
      * 组装获取用户提交的购物车商品项
-     * @param orderItems 提交订单时携带的商品信息
+     * @param orderItem 提交订单时携带的商品信息
      * @param userId 当前用户的用户id
      * @return 所有的商品购物项
      */
-    List<ShopCartItemDto> getShopCartItemsByOrderItems(List<Long> basketId, OrderItemParam orderItem,String userId);
+    List<ShopCartItemDto> getShopCartItemsByOrderItems(List<Long> basketId, OrderItemParam orderItem,String userId,Long channelId);
 
     /**
      * 获取立即购买积分商城的商品

+ 15 - 25
yami-shop-service/src/main/java/com/yami/shop/service/impl/BasketServiceImpl.java

@@ -74,9 +74,10 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
         basket.setBasketDate(new Date());
         basket.setProdId(param.getProdId());
         basket.setShopId(param.getShopId());
+        basket.setChannelId(param.getChannelId());
         basket.setUserId(userId);
         basket.setSkuId(param.getSkuId());
-        basket.setDistributionCardNo(param.getDistributionCardNo());
+//        basket.setDistributionCardNo(param.getDistributionCardNo());
         basketMapper.insert(basket);
     }
 
@@ -92,39 +93,28 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
         basketMapper.deleteAllShopCartItems(userId);
     }
 
-    @Override
-    public List<ShopCartItemDto> getShopCartItems(String userId) {
-        // 在这个类里面要调用这里的缓存信息,并没有使用aop,所以不使用注解
-        //List<ShopCartItemDto> shopCartItemDtoList = cacheManagerUtil.getCache("ShopCartItems", userId);
-//        List<ShopCartItemDto> shopCartItemDtoList = Lists.newArrayList();
-//        if (ObjectUtils.isNotEmpty(shopCartItemDtoList)) {
-//            return shopCartItemDtoList;
+//    @Override
+//    public List<ShopCartItemDto> getShopCartItems(Long channelId,String userId) {
+//        // 在这个类里面要调用这里的缓存信息,并没有使用aop,所以不使用注解
+//
+//        List<ShopCartItemDto> shopCartItemDtoList = basketMapper.getShopCartItems(userId);
+//        for (ShopCartItemDto shopCartItemDto : shopCartItemDtoList) {
+//            shopCartItemDto.setProductTotalAmount(Arith.mul(shopCartItemDto.getProdCount(), shopCartItemDto.getPrice()));
+//            shopCartItemDto.setWeight(shopCartItemDto.getWeight());
+//            shopCartItemDto.setWeightUnit(shopCartItemDto.getWeightUnit());
 //        }
-        List<ShopCartItemDto> shopCartItemDtoList = basketMapper.getShopCartItems(userId);
-        for (ShopCartItemDto shopCartItemDto : shopCartItemDtoList) {
-            shopCartItemDto.setProductTotalAmount(Arith.mul(shopCartItemDto.getProdCount(), shopCartItemDto.getPrice()));
-            shopCartItemDto.setWeight(shopCartItemDto.getWeight());
-            shopCartItemDto.setWeightUnit(shopCartItemDto.getWeightUnit());
-        }
-        //cacheManagerUtil.putCache("ShopCartItems", userId, shopCartItemDtoList);
-        return shopCartItemDtoList;
-    }
+//        return shopCartItemDtoList;
+//    }
 
     @Override
     public List<ShopCartItemDto> getShopCartItems(String userId, Long channelId) {
         // 在这个类里面要调用这里的缓存信息,并没有使用aop,所以不使用注解
-//        List<ShopCartItemDto> shopCartItemDtoList = cacheManagerUtil.getCache("ShopCartItems", userId);
-//        List<ShopCartItemDto> shopCartItemDtoList = Lists.newArrayList();
-//        if (ObjectUtils.isNotEmpty(shopCartItemDtoList)) {
-//            return shopCartItemDtoList;
-//        }
         List<ShopCartItemDto> shopCartItemDtoList = basketMapper.getShopCartItemsByPlatform(userId, channelId);
         for (ShopCartItemDto shopCartItemDto : shopCartItemDtoList) {
             shopCartItemDto.setProductTotalAmount(Arith.mul(shopCartItemDto.getProdCount(), shopCartItemDto.getPrice()));
             shopCartItemDto.setWeight(shopCartItemDto.getWeight());
             shopCartItemDto.setWeightUnit(shopCartItemDto.getWeightUnit());
         }
-//        cacheManagerUtil.putCache("ShopCartItems", userId, shopCartItemDtoList);
         return shopCartItemDtoList;
     }
 
@@ -203,7 +193,7 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
     }
 
     @Override
-    public List<ShopCartItemDto> getShopCartItemsByOrderItems(List<Long> basketId, OrderItemParam orderItem, String userId) {
+    public List<ShopCartItemDto> getShopCartItemsByOrderItems(List<Long> basketId, OrderItemParam orderItem, String userId,Long channelId) {
         if (orderItem == null && CollectionUtil.isEmpty(basketId)) {
             return Collections.emptyList();
         }
@@ -212,7 +202,7 @@ public class BasketServiceImpl extends ServiceImpl<BasketMapper, Basket> impleme
             return Collections.singletonList(getShopCartItem(orderItem));
         }
 
-        List<ShopCartItemDto> dbShopCartItems = getShopCartItems(userId);
+        List<ShopCartItemDto> dbShopCartItems = getShopCartItems(userId,channelId);
 
         // 返回购物车选择的商品信息
         List<ShopCartItemDto> collect = dbShopCartItems

+ 2 - 1
yami-shop-service/src/main/resources/mapper/BasketMapper.xml

@@ -58,7 +58,8 @@
                 LEFT JOIN tz_channel_prod tcp ON (tb.sku_id=tcp.sku_id AND tb.shop_id=tcp.shop_id)
                 LEFT JOIN tz_shop_sku cs on cs.sku_id=ts.sku_id and cs.is_delete=0 and cs.shop_id = tb.shop_id
         WHERE
-            tp.STATUS = 1
+            tb.channel_id = #{channelId}
+          AND tp.STATUS = 1
           AND ts.STATUS = 1
           AND tb.user_id = #{userId}
           AND tcp.channel_id=#{channelId}

+ 3 - 4
yami-shop-service/src/main/resources/mapper/ProductMapper.xml

@@ -1001,12 +1001,11 @@
         max(b.basket_count ) as prodCount
         FROM tz_category_prod cp
         INNER JOIN tz_prod p on p.prod_id = cp.prod_id
-        LEFT JOIN tz_shop_sku ss on ss.spu_id = cp.prod_id and ss.is_delete = 0
-        INNER JOIN tz_channel_prod cha on cha.sku_id = ss.sku_id and cha.is_delete = 0 and cha.channel_id =  #{channelId}
+        LEFT JOIN tz_shop_sku ss on ss.spu_id = cp.prod_id and ss.is_delete = 0 and ss.shop_id = #{shopId}
+        INNER JOIN tz_channel_prod cha on cha.sku_id = ss.sku_id and cha.is_delete = 0
         LEFT JOIN tz_basket b ON b.prod_id = p.prod_id AND b.user_id = COALESCE(NULLIF(#{userId}, ''), '0')
         where p.is_delete = 0 and
-        <if test="channelId == null">cha.channel_id = 1</if>
-        <if test="channelId != null">cha.channel_id = #{channelId}</if>
+        cha.channel_id = #{channelId} and cha.shop_id = #{shopId}
 
         and(cp.code in (select sc.code
         FROM tz_category_prod cp