购物车后台完成
parent
702046bc3e
commit
99df84c76b
|
@ -34,6 +34,11 @@ public class CartSkuModel {
|
|||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 商品Sku
|
||||
*/
|
||||
private String projectSku;
|
||||
|
||||
/**
|
||||
* 商品名称
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package com.muyu.shop.cart.domain.req;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
/**
|
||||
* @author DongZl
|
||||
* @description: 购物车状态修改
|
||||
* @Date 2024/4/8 下午8:02
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CartInfoIsSelectedUpdReq {
|
||||
|
||||
/**
|
||||
* 商品ID
|
||||
*/
|
||||
private Long projectId;
|
||||
|
||||
/**
|
||||
* 商品SKU
|
||||
*/
|
||||
private String projectSku;
|
||||
|
||||
/**
|
||||
* 选中状态
|
||||
*/
|
||||
private String isSelected;
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.muyu.shop.cart.controller;
|
|||
import java.util.List;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.muyu.shop.cart.domain.req.CartInfoIsSelectedUpdReq;
|
||||
import com.muyu.shop.cart.domain.resp.CartDetailResp;
|
||||
import io.swagger.annotations.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -104,6 +105,12 @@ public class CartInfoController extends BaseController {
|
|||
return toAjax(cartInfoService.updateById(CartInfo.editBuild(id,cartInfoEditReq)));
|
||||
}
|
||||
|
||||
@PostMapping("/selected")
|
||||
public Result<String> cartInfoIsSelected(@RequestBody List<CartInfoIsSelectedUpdReq> cartInfoIsSelectedUpdReqList){
|
||||
cartInfoService.cartInfoIsSelected(cartInfoIsSelectedUpdReqList);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除购物车
|
||||
*/
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.shop.cart.service;
|
|||
import java.util.List;
|
||||
import com.muyu.shop.cart.domain.CartInfo;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.shop.cart.domain.req.CartInfoIsSelectedUpdReq;
|
||||
import com.muyu.shop.cart.domain.resp.CartDetailResp;
|
||||
|
||||
/**
|
||||
|
@ -32,4 +33,11 @@ public interface CartInfoService extends IService<CartInfo> {
|
|||
* @return 购物车详情
|
||||
*/
|
||||
CartDetailResp detail ();
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
* @param cartInfoIsSelectedUpdReqList
|
||||
*/
|
||||
void cartInfoIsSelected (List<CartInfoIsSelectedUpdReq> cartInfoIsSelectedUpdReqList);
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.muyu.shop.cart.cache.key.CartHashKey;
|
|||
import com.muyu.shop.cart.domain.model.CartSkuModel;
|
||||
import com.muyu.shop.cart.domain.model.SkuRuleModel;
|
||||
import com.muyu.shop.cart.domain.model.StatisticsCartModel;
|
||||
import com.muyu.shop.cart.domain.req.CartInfoIsSelectedUpdReq;
|
||||
import com.muyu.shop.cart.domain.resp.CartDetailResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -33,6 +34,7 @@ import com.muyu.shop.cart.domain.CartInfo;
|
|||
import com.muyu.shop.cart.service.CartInfoService;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 购物车Service业务层处理
|
||||
|
@ -177,6 +179,7 @@ public class CartInfoServiceImpl extends ServiceImpl<CartInfoMapper, CartInfo>
|
|||
}
|
||||
return CartSkuModel.builder()
|
||||
.projectId(cartInfo.getProjectId())
|
||||
.projectSku(cartInfo.getProjectSku())
|
||||
.name(projectInfo.getName())
|
||||
.image(projectSkuInfo.getImage())
|
||||
.stock(stock)
|
||||
|
@ -193,24 +196,28 @@ public class CartInfoServiceImpl extends ServiceImpl<CartInfoMapper, CartInfo>
|
|||
StatisticsCartModel statisticsCartModel = StatisticsCartModel.builder()
|
||||
.total(
|
||||
cartSkuModelList.stream()
|
||||
.filter(cartSkuModel -> cartSkuModel.getStock() > 0)
|
||||
.mapToLong(CartSkuModel::getNum)
|
||||
.sum()
|
||||
)
|
||||
.selectTotal(
|
||||
cartSkuModelList.stream()
|
||||
.filter(cartSkuModel -> "Y".equals(cartSkuModel.getIsSelected()))
|
||||
.filter(cartSkuModel -> cartSkuModel.getStock() > 0)
|
||||
.mapToLong(CartSkuModel::getNum)
|
||||
.sum()
|
||||
)
|
||||
.priceTotal(
|
||||
cartSkuModelList.stream()
|
||||
.filter(cartSkuModel -> "Y".equals(cartSkuModel.getIsSelected()))
|
||||
.filter(cartSkuModel -> cartSkuModel.getStock() > 0)
|
||||
.map(CartSkuModel::getSubtotal)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
)
|
||||
.actualTotal(
|
||||
cartSkuModelList.stream()
|
||||
.filter(cartSkuModel -> "Y".equals(cartSkuModel.getIsSelected()))
|
||||
.filter(cartSkuModel -> cartSkuModel.getStock() > 0)
|
||||
.map(CartSkuModel::getSubtotal)
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add)
|
||||
)
|
||||
|
@ -221,4 +228,29 @@ public class CartInfoServiceImpl extends ServiceImpl<CartInfoMapper, CartInfo>
|
|||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改状态
|
||||
*
|
||||
* @param cartInfoIsSelectedUpdReqList
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void cartInfoIsSelected (List<CartInfoIsSelectedUpdReq> cartInfoIsSelectedUpdReqList) {
|
||||
for (CartInfoIsSelectedUpdReq cartInfoIsSelectedUpdReq : cartInfoIsSelectedUpdReqList) {
|
||||
LambdaUpdateWrapper<CartInfo> updateWrapper = new LambdaUpdateWrapper<>();
|
||||
updateWrapper.set(CartInfo::getIsSelected, cartInfoIsSelectedUpdReq.getIsSelected());
|
||||
updateWrapper.eq(CartInfo::getProjectId, cartInfoIsSelectedUpdReq.getProjectId());
|
||||
updateWrapper.eq(CartInfo::getProjectSku, cartInfoIsSelectedUpdReq.getProjectSku());
|
||||
this.update(updateWrapper);
|
||||
CartHashKey cartHashKey = CartHashKey.builder()
|
||||
.projectId(cartInfoIsSelectedUpdReq.getProjectId())
|
||||
.projectSku(cartInfoIsSelectedUpdReq.getProjectSku())
|
||||
.build();
|
||||
Long userId = SecurityUtils.getUserId();
|
||||
CartInfo cartInfo = this.cartCache.get(userId, cartHashKey);
|
||||
cartInfo.setIsSelected(cartInfoIsSelectedUpdReq.getIsSelected());
|
||||
this.cartCache.put(userId, cartHashKey, cartInfo);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue