编写RuleCache
parent
3591b3624c
commit
132ea274f2
|
@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 购物车小计
|
* 购物车小计
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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<>();
|
||||||
|
|
Loading…
Reference in New Issue