记得上下班打卡 | git大法好,push需谨慎

Commit 863cf907 authored by 姜秀龙's avatar 姜秀龙

收钱 商品列表 缓存

parent fae7d062
......@@ -432,13 +432,12 @@ public class GoblinRedisConst {
/* ----------------------------------------------------------------- */
/* --------------------------------收钱吧相关--------------------------------- */
/**
* 收钱吧订单详情
*/
public static final String SQB_ORDER = PREFIX.concat("sqb:order:");
/**
* 演出关联收钱吧商品缓存
* 演出关联收钱吧商品缓存 performancesId
*/
public static final String SQB_PERFORMANCE_GOODS = PREFIX.concat("sqb:perf:goods:");
/**
......@@ -452,4 +451,9 @@ public class GoblinRedisConst {
*/
public static final String SQB_GOBLIN_ORDER_LIST = PREFIX.concat("sqb:order:id:list:");//用户订单id列表 key:$uid
/**
* 演出关联收钱吧商品换购价 缓存 performancesId:skuId
*/
public static final String SQB_SKU_PRICE = PREFIX.concat("sqb:sku:price:");
}
......@@ -13,6 +13,7 @@ import com.liquidnet.service.goblin.constant.GoblinRedisConst;
import com.liquidnet.service.goblin.constant.GoblinStatusConst;
import com.liquidnet.service.goblin.dto.vo.*;
import com.liquidnet.service.goblin.entity.*;
import com.liquidnet.service.goblin.entity.GoblinSqbPerformanceGoods;
import com.liquidnet.service.goblin.mapper.GoblinSqbPerformanceGoodsMapper;
import com.liquidnet.service.goblin.enums.GoblinStoreConf;
import com.liquidnet.service.goblin.service.GoblinCouponService;
......@@ -1072,64 +1073,74 @@ public class GoblinFrontServiceImpl implements GoblinFrontService {
int safePage = Math.max(page, 0);
int safePageSize = pageSize <= 0 ? 40 : Math.min(pageSize, 100);
ArrayList<GoblinGoodsInfoVo> allGoods = ObjectUtil.goblinGoodsInfoVoArrayList();
List<GoblinSqbPerformanceGoods> relations = goblinSqbPerformanceGoodsMapper.selectList(
new LambdaQueryWrapper<GoblinSqbPerformanceGoods>()
.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId)
.eq(GoblinSqbPerformanceGoods::getStatus, 1)
.groupBy(GoblinSqbPerformanceGoods::getSpuId)
.orderByAsc(GoblinSqbPerformanceGoods::getSort, GoblinSqbPerformanceGoods::getMid));
if (CollectionUtils.isEmpty(relations)) {
respVo.setCount(0);
respVo.setGoblinGoodsInfoVoList(ObjectUtil.goblinGoodsInfoVoArrayList());
return respVo;
}
// 1. 尝试从 Redis 缓存获取全量已关联商品关系(Raw Relations)提高性能
List<GoblinSqbPerformanceGoods> relations = goblinRedisUtils.getSqbPerformanceGoodsListCache(performancesId);
for (GoblinSqbPerformanceGoods rel : relations) {
if (rel == null || StringUtils.isBlank(rel.getSpuId())) {
continue;
}
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(rel.getSpuId());
if (goodsInfoVo == null) {
continue;
}
// 演出关联列表只保留可售商品,避免下架/删除商品混入
if (!"0".equals(goodsInfoVo.getDelFlg())) {
continue;
}
if (!"0".equals(goodsInfoVo.getSpuAppear())) {
continue;
}
// if (!"3".equals(goodsInfoVo.getShelvesStatus())) {
// continue;
// }
if (StringUtil.isNotBlank(goodsInfoVo.getMarketId())) {
continue;
if (relations == null) {
// 2. 缓存失效,查询数据库获取“原始关联关系”
relations = goblinSqbPerformanceGoodsMapper.selectList(
new LambdaQueryWrapper<GoblinSqbPerformanceGoods>()
.eq(GoblinSqbPerformanceGoods::getPerformancesId, performancesId)
.eq(GoblinSqbPerformanceGoods::getStatus, 1)
.groupBy(GoblinSqbPerformanceGoods::getSpuId)
.orderByAsc(GoblinSqbPerformanceGoods::getSort, GoblinSqbPerformanceGoods::getMid));
if (relations == null) {
relations = new ArrayList<>();
}
// 3. 将关联关系(SPU 列表及其结算价/排序等)写入 Redis 缓存
goblinRedisUtils.setSqbPerformanceGoodsListCache(performancesId, relations);
}
// 4. 每次请求都实时校验商品状态(delFlg, shelvesStatus 等)
// 这样如果商品在 SPU 层面下架,虽然关联关系还在缓存,但这里会动态过滤掉
ArrayList<GoblinGoodsInfoVo> allGoods = ObjectUtil.goblinGoodsInfoVoArrayList();
if (!CollectionUtils.isEmpty(relations)) {
for (GoblinSqbPerformanceGoods rel : relations) {
if (rel == null || StringUtil.isBlank(rel.getSpuId())) {
continue;
}
// 从 Redis SPU 缓存获取详情(SPU 详情由其他逻辑负责更新缓存,这里始终拿最新状态)
GoblinGoodsInfoVo goodsInfoVo = goblinRedisUtils.getGoodsInfoVo(rel.getSpuId());
if (goodsInfoVo == null) {
continue;
}
// 动态过滤:演出关联列表只展示在线、未删除、且上架状态为 3 的商品
if (!"0".equals(goodsInfoVo.getDelFlg())) {
continue;
}
if (!"0".equals(goodsInfoVo.getSpuAppear())) {
continue;
}
if (!"3".equals(goodsInfoVo.getShelvesStatus())) {
continue;
}
if (StringUtil.isNotBlank(goodsInfoVo.getMarketId())) {
continue;
}
GoblinSqbPerformanceGoodsInfoVo frontGoods = new GoblinSqbPerformanceGoodsInfoVo();
BeanUtils.copyProperties(goodsInfoVo, frontGoods);
BigDecimal normalPrice = resolveGoodsSellPrice(goodsInfoVo);
frontGoods.setSellPrice(normalPrice);
frontGoods.setPrice(normalPrice);
frontGoods.setSettlementPrice(rel.getSettlementPrice());
allGoods.add(frontGoods);
GoblinSqbPerformanceGoodsInfoVo frontGoods = new GoblinSqbPerformanceGoodsInfoVo();
BeanUtils.copyProperties(goodsInfoVo, frontGoods);
BigDecimal normalPrice = resolveGoodsSellPrice(goodsInfoVo);
frontGoods.setSellPrice(normalPrice);
frontGoods.setPrice(normalPrice);
frontGoods.setSettlementPrice(rel.getSettlementPrice());
allGoods.add(frontGoods);
}
}
int total = allGoods.size();
respVo.setCount(total);
int start = safePage * safePageSize;
if (start >= total) {
respVo.setCount(total);
respVo.setGoblinGoodsInfoVoList(ObjectUtil.goblinGoodsInfoVoArrayList());
return respVo;
}
int end = Math.min(start + safePageSize, total);
ArrayList<GoblinGoodsInfoVo> pageList = ObjectUtil.goblinGoodsInfoVoArrayList();
pageList.addAll(allGoods.subList(start, end));
respVo.setCount(total);
respVo.setGoblinGoodsInfoVoList(pageList);
return respVo;
}
......
......@@ -24,7 +24,9 @@ import com.liquidnet.service.goblin.entity.GoblinBraceletOrder;
import com.liquidnet.service.goblin.entity.GoblinFrontBanner;
import com.liquidnet.service.goblin.entity.GoblinFrontHotWord;
import com.liquidnet.service.goblin.entity.GoblinFrontNavigation;
import com.liquidnet.service.goblin.entity.GoblinSqbPerformanceGoods;
import com.liquidnet.service.goblin.mapper.GoblinBraceletOrderMapper;
import com.liquidnet.service.goblin.mapper.GoblinSqbPerformanceGoodsMapper;
import com.liquidnet.service.goblin.service.impl.inner.GoblinNftJobServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -3053,8 +3055,19 @@ public class GoblinRedisUtils {
}
/* ---------------------------------------- ---------------------------------------- */
/* ---------------------------------------- ---------------------------------------- */
/* ---------------------------------------- ---------------------------------------- */
/* ---------------------------------------- ---------------------------------------- */
/* --------------------------------收钱吧相关--------------------------------- */
public void setSqbPerformanceGoodsListCache(String performancesId, List<GoblinSqbPerformanceGoods> relations) {
String key = GoblinRedisConst.SQB_PERFORMANCE_GOODS.concat(performancesId);
redisUtil.set(key, relations, RedisKeyExpireConst.SQB_PERFORMANCE_GOODS_EXPIRE);
}
public List<GoblinSqbPerformanceGoods> getSqbPerformanceGoodsListCache(String performancesId) {
String key = GoblinRedisConst.SQB_PERFORMANCE_GOODS.concat(performancesId);
return (List<GoblinSqbPerformanceGoods>) redisUtil.get(key);
}
public void delPerformanceGoodsCache(String performancesId) {
redisUtil.del(GoblinRedisConst.SQB_PERFORMANCE_GOODS.concat(performancesId));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment