From a1fe1bac16b268b59ef6b78ecd682c17a75cb6c3 Mon Sep 17 00:00:00 2001 From: wangw <1594593906@qq.com> Date: Thu, 9 Apr 2026 17:11:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B6=E9=9F=B3=E6=9C=BA=20/=20=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=20=E5=95=86=E5=93=81=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/ProductController.java | 2 +- .../service/impl/ProductServiceImpl.java | 34 +++++++++++++------ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java b/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java index 61de19591..2622f7fb6 100644 --- a/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java +++ b/cash-api/product-server/src/main/java/com/czg/controller/admin/ProductController.java @@ -82,7 +82,7 @@ public class ProductController { */ @GetMapping("list") @OperationLog("商品-列表") - public CzgResult> getProductList(@RequestParam Long categoryId) { + public CzgResult> getProductList(@RequestParam(required = false) Long categoryId) { return CzgResult.success(productService.getProductCacheList(StpKit.USER.getShopId(), categoryId)); } diff --git a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java index f3f563e6f..00ae2ad10 100644 --- a/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java +++ b/cash-service/product-service/src/main/java/com/czg/service/product/service/impl/ProductServiceImpl.java @@ -338,20 +338,32 @@ public class ProductServiceImpl extends ServiceImpl impl @Override public Map getProductCacheList(Long shopId, Long categoryId) { - String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::" + categoryId; + String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId; List list; - if (!redisService.hasKey(key)) { - list = initProductCacheByCategoryId(shopId, categoryId); + if (categoryId == null) { + if (!redisService.hasKey(key)) { + ProductDTO param = new ProductDTO(); + param.setShopId(shopId); + list = getProductList(param); + redisService.setJsonStr(key, list); + } else { + list = redisService.getJsonToBeanList(key, ProductDTO.class); + } } else { - list = redisService.getJsonToBeanList(key, ProductDTO.class); + key = key + "::" + categoryId; + if (!redisService.hasKey(key)) { + list = initProductCacheByCategoryId(shopId, categoryId); + } else { + list = redisService.getJsonToBeanList(key, ProductDTO.class); + } + // 重新进行排序 + list = list.stream() + .sorted(Comparator.comparingInt(ProductDTO::getIsSoldStock)) + .sorted(Comparator.comparingInt(ProductDTO::getIsSale).reversed()) + .sorted(Comparator.comparingInt(ProductDTO::getSort).reversed()) + .sorted(Comparator.comparingLong(ProductDTO::getId).reversed()) + .toList(); } - // 重新进行排序 - list = list.stream() - .sorted(Comparator.comparingInt(ProductDTO::getIsSoldStock)) - .sorted(Comparator.comparingInt(ProductDTO::getIsSale).reversed()) - .sorted(Comparator.comparingInt(ProductDTO::getSort).reversed()) - .sorted(Comparator.comparingLong(ProductDTO::getId).reversed()) - .toList(); List consInfos = consInfoMapper.selectListByQuery(query().eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getStatus, SystemConstants.OneZero.ONE)); return Map.of("productList", list, "cons", consInfos); }