收音机 / 客户端 商品列表

This commit is contained in:
2026-04-09 17:11:37 +08:00
parent 084baf89b1
commit a1fe1bac16
2 changed files with 24 additions and 12 deletions

View File

@@ -82,7 +82,7 @@ public class ProductController {
*/
@GetMapping("list")
@OperationLog("商品-列表")
public CzgResult<Map<String, Object>> getProductList(@RequestParam Long categoryId) {
public CzgResult<Map<String, Object>> getProductList(@RequestParam(required = false) Long categoryId) {
return CzgResult.success(productService.getProductCacheList(StpKit.USER.getShopId(), categoryId));
}

View File

@@ -338,20 +338,32 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Override
public Map<String, Object> getProductCacheList(Long shopId, Long categoryId) {
String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId + "::" + categoryId;
String key = ADMIN_CLIENT_PRODUCT_LIST + "::" + shopId;
List<ProductDTO> 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<ConsInfo> consInfos = consInfoMapper.selectListByQuery(query().eq(ConsInfo::getShopId, shopId).eq(ConsInfo::getStatus, SystemConstants.OneZero.ONE));
return Map.of("productList", list, "cons", consInfos);
}