编写RuleCache

master
DongZeLiang 2024-04-07 20:03:18 +08:00
parent 3591b3624c
commit 132ea274f2
2 changed files with 44 additions and 0 deletions

View File

@ -29,6 +29,11 @@ public class CartSkuModel {
*/ */
private String image; private String image;
/**
* ID
*/
private Long projectId;
/** /**
* *
*/ */
@ -49,6 +54,11 @@ public class CartSkuModel {
*/ */
private Long num; private Long num;
/**
*
*/
private Long stock;
/** /**
* *
*/ */

View File

@ -10,8 +10,12 @@ import com.muyu.common.core.exception.ServiceException;
import com.muyu.common.core.text.Convert; import com.muyu.common.core.text.Convert;
import com.muyu.common.core.utils.ObjUtils; import com.muyu.common.core.utils.ObjUtils;
import com.muyu.common.security.utils.SecurityUtils; import com.muyu.common.security.utils.SecurityUtils;
import com.muyu.product.cache.ProjectInfoCache;
import com.muyu.product.cache.ProjectSkuCache;
import com.muyu.product.cache.ProjectSkuStockCache; import com.muyu.product.cache.ProjectSkuStockCache;
import com.muyu.product.cache.key.SkuStockKey; import com.muyu.product.cache.key.SkuStockKey;
import com.muyu.product.domain.ProjectInfo;
import com.muyu.product.domain.ProjectSkuInfo;
import com.muyu.shop.cart.cache.CartCache; import com.muyu.shop.cart.cache.CartCache;
import com.muyu.shop.cart.cache.key.CartHashKey; import com.muyu.shop.cart.cache.key.CartHashKey;
import com.muyu.shop.cart.domain.model.CartSkuModel; import com.muyu.shop.cart.domain.model.CartSkuModel;
@ -39,6 +43,12 @@ public class CartInfoServiceImpl extends ServiceImpl<CartInfoMapper, CartInfo>
@Autowired @Autowired
private CartCache cartCache; private CartCache cartCache;
@Autowired
private ProjectSkuCache projectSkuCache;
@Autowired
private ProjectInfoCache projectInfoCache;
@Autowired @Autowired
private ProjectSkuStockCache projectSkuStockCache; private ProjectSkuStockCache projectSkuStockCache;
@ -132,6 +142,30 @@ public class CartInfoServiceImpl extends ServiceImpl<CartInfoMapper, CartInfo>
Long userId = SecurityUtils.getUserId(); Long userId = SecurityUtils.getUserId();
List<CartInfo> cartInfoList = cartCache.getToList(userId); List<CartInfo> cartInfoList = cartCache.getToList(userId);
// CartInfo -> CartSkuModel // CartInfo -> CartSkuModel
List<CartSkuModel> cartSkuModelList = cartInfoList.stream()
.map(cartInfo -> {
ProjectSkuInfo projectSkuInfo
= projectSkuCache.get(cartInfo.getProjectId(), cartInfo.getProjectSku());
ProjectInfo projectInfo
= projectInfoCache.get(cartInfo.getProjectId());
Long stock = projectSkuStockCache.get(
SkuStockKey.builder()
.projectId(cartInfo.getProjectId())
.sku(cartInfo.getProjectSku())
.build()
);
// RuleCache
return CartSkuModel.builder()
.projectId(cartInfo.getProjectId())
.name(projectInfo.getName())
.image(projectSkuInfo.getImage())
.stock(stock)
.price(projectSkuInfo.getPrice())
.cartInfoId(cartInfo.getId())
.num(cartInfo.getNum())
.isSelected(cartInfo.getIsSelected())
.build();
}).toList();
List<CartSkuModel> cartSkuList = new ArrayList<>(); List<CartSkuModel> cartSkuList = new ArrayList<>();