feat(新增): 更新选中状态,更新全部选中,批量选择购物车
This commit is contained in:
parent
493d91a515
commit
6ace927de5
|
@ -1,5 +1,6 @@
|
|||
package com.atguigu.ssyx.client;
|
||||
|
||||
import com.atguigu.ssyx.model.activity.CouponInfo;
|
||||
import com.atguigu.ssyx.model.order.CartInfo;
|
||||
import com.atguigu.ssyx.vo.order.OrderConfirmVo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
|
@ -24,4 +25,16 @@ public interface ActivityFeignClient {
|
|||
// 获取购物车满足条件的促销与优惠券信息
|
||||
@PostMapping("inner/findCartActivityAndCoupon/{userId}")
|
||||
OrderConfirmVo findCartActivityAndCoupon(@RequestBody List<CartInfo> cartInfoList, @PathVariable Long userId);
|
||||
|
||||
// 获取优惠券范围对应的购物车列表
|
||||
@PostMapping(value = "/api/activity/inner/findRangeSkuIdList/{couponId}")
|
||||
CouponInfo findRangeSkuIdList(@RequestBody List<CartInfo> cartInfoList, @PathVariable("couponId") Long couponId);
|
||||
|
||||
// 根据活动id获取活动skuId列表
|
||||
@GetMapping(value = "/api/activity/inner/findSkuIdList/{activityId}")
|
||||
List<Long> findSkuIdList(@PathVariable("activityId") Long activityId);
|
||||
|
||||
// 更新优惠券支付时间
|
||||
@GetMapping(value = "/api/activity/inner/updateCouponInfoUsedTime/{couponId}/{userId}")
|
||||
Boolean updateCouponInfoUsedTime(@PathVariable("couponId") Long couponId, @PathVariable("userId") Long userId);
|
||||
}
|
||||
|
|
|
@ -70,5 +70,29 @@ public class CartApiController {
|
|||
OrderConfirmVo orderTradeVo = activityFeignClient.findCartActivityAndCoupon(cartInfoList, userId);
|
||||
return Result.success(orderTradeVo);
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新选中状态")
|
||||
@GetMapping("checkCart/{skuId}/{isChecked}")
|
||||
public Result<CartInfo> checkCart(@PathVariable Long skuId, @PathVariable Integer isChecked) {
|
||||
Long userId = BaseContext.getUserId();
|
||||
cartInfoService.checkCart(userId, isChecked, skuId);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "更新全部选中")
|
||||
@GetMapping("checkAllCart/{isChecked}")
|
||||
public Result<CartInfo> checkAllCart(@PathVariable Integer isChecked) {
|
||||
Long userId = BaseContext.getUserId();
|
||||
cartInfoService.checkAllCart(userId, isChecked);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@ApiOperation(value = "批量选择购物车")
|
||||
@PostMapping("batchCheckCart/{isChecked}")
|
||||
public Result<CartInfo> batchCheckCart(@RequestBody List<Long> skuIdList, @PathVariable Integer isChecked) {
|
||||
Long userId = BaseContext.getUserId();
|
||||
cartInfoService.batchCheckCart(skuIdList, userId, isChecked);
|
||||
return Result.success();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public interface CartInfoService {
|
|||
* * 批量删除购物车
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param skuIdList 商品的id
|
||||
* @param skuIdList 商品的id列表
|
||||
*/
|
||||
void batchDeleteCart(Long userId, List<Long> skuIdList);
|
||||
|
||||
|
@ -45,4 +45,30 @@ public interface CartInfoService {
|
|||
* @return 购物车信息列表
|
||||
*/
|
||||
List<CartInfo> getCartList(Long userId);
|
||||
|
||||
/**
|
||||
* * 更新选中状态
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param isChecked 是否选中
|
||||
* @param skuId 商品Id
|
||||
*/
|
||||
void checkCart(Long userId, Integer isChecked, Long skuId);
|
||||
|
||||
/**
|
||||
* * 更新全部选中
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param isChecked 是否选中
|
||||
*/
|
||||
void checkAllCart(Long userId, Integer isChecked);
|
||||
|
||||
/**
|
||||
* * 批量选择购物车
|
||||
*
|
||||
* @param skuIdList 商品的id列表
|
||||
* @param userId 用户id
|
||||
* @param isChecked 是否选中
|
||||
*/
|
||||
void batchCheckCart(List<Long> skuIdList, Long userId, Integer isChecked);
|
||||
}
|
||||
|
|
|
@ -159,4 +159,68 @@ public class CartInfoServiceImpl implements CartInfoService {
|
|||
// 返回结果
|
||||
return cartInfoList;
|
||||
}
|
||||
|
||||
/**
|
||||
* * 更新选中状态
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param isChecked 是否选中
|
||||
* @param skuId 商品Id
|
||||
*/
|
||||
@Override
|
||||
public void checkCart(Long userId, Integer isChecked, Long skuId) {
|
||||
String cartKey = module.getCartKey(userId);
|
||||
BoundHashOperations<String, String, CartInfo> boundedHashOps = redisTemplate.boundHashOps(cartKey);
|
||||
CartInfo cartInfo = boundedHashOps.get(skuId.toString());
|
||||
if (cartInfo != null) {
|
||||
cartInfo.setIsChecked(isChecked);
|
||||
boundedHashOps.put(skuId.toString(), cartInfo);
|
||||
// 设置key过期时间
|
||||
module.setCartKeyExpire(cartKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * 更新全部选中
|
||||
*
|
||||
* @param userId 用户id
|
||||
* @param isChecked 是否选中
|
||||
*/
|
||||
@Override
|
||||
public void checkAllCart(Long userId, Integer isChecked) {
|
||||
String cartKey = module.getCartKey(userId);
|
||||
BoundHashOperations<String, String, CartInfo> boundHashOps = redisTemplate.boundHashOps(cartKey);
|
||||
List<CartInfo> cartInfoList = boundHashOps.values();
|
||||
|
||||
// 当列表不能为空时做处理
|
||||
if (cartInfoList != null) {
|
||||
cartInfoList.forEach(cartInfo -> {
|
||||
cartInfo.setIsChecked(isChecked);
|
||||
boundHashOps.put(cartInfo.getSkuId().toString(), cartInfo);
|
||||
});
|
||||
// 设置过期时间
|
||||
module.setCartKeyExpire(cartKey);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* * 批量选择购物车
|
||||
*
|
||||
* @param skuIdList 商品的id列表
|
||||
* @param userId 用户id
|
||||
* @param isChecked 是否选中
|
||||
*/
|
||||
@Override
|
||||
public void batchCheckCart(List<Long> skuIdList, Long userId, Integer isChecked) {
|
||||
String cartKey = module.getCartKey(userId);
|
||||
BoundHashOperations<String, String, CartInfo> boundHashOps = redisTemplate.boundHashOps(cartKey);
|
||||
|
||||
// 边路skuId将值更新
|
||||
skuIdList.forEach(skuId -> {
|
||||
CartInfo cartInfo = boundHashOps.get(skuId.toString());
|
||||
if (cartInfo != null) {
|
||||
cartInfo.setIsChecked(isChecked);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue