feat(新增): 选中的购物车
Signed-off-by: bunny <1319900154@qq.com>
This commit is contained in:
parent
b47bfeafb6
commit
068e7f116d
|
@ -62,4 +62,11 @@ public class CartController {
|
||||||
cartService.clearCart();
|
cartService.clearCart();
|
||||||
return Result.success();
|
return Result.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "选中的购物车")
|
||||||
|
@GetMapping(value = "/auth/getAllCkecked")
|
||||||
|
public Result<List<CartInfo>> getAllChecked() {
|
||||||
|
List<CartInfo> cartInfoList = cartService.getAllChecked();
|
||||||
|
return Result.success(cartInfoList);
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -46,4 +46,11 @@ public interface CartService {
|
||||||
* 清空购物车
|
* 清空购物车
|
||||||
*/
|
*/
|
||||||
void clearCart();
|
void clearCart();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选中的购物车
|
||||||
|
*
|
||||||
|
* @return CartInfo列表
|
||||||
|
*/
|
||||||
|
List<CartInfo> getAllChecked();
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,4 +157,27 @@ public class CartServiceImpl implements CartService {
|
||||||
String cartKey = RedisUtils.getCartKey(userId);
|
String cartKey = RedisUtils.getCartKey(userId);
|
||||||
redisTemplate.delete(cartKey);
|
redisTemplate.delete(cartKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 选中的购物车
|
||||||
|
*
|
||||||
|
* @return CartInfo列表
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<CartInfo> getAllChecked() {
|
||||||
|
// 获取用户id
|
||||||
|
Long userId = BaseContext.getUserInfo().getId();
|
||||||
|
String cartKey = RedisUtils.getCartKey(userId);
|
||||||
|
|
||||||
|
// 根据key获取购物车所有商品
|
||||||
|
List<Object> objectList = redisTemplate.opsForHash().values(cartKey);
|
||||||
|
|
||||||
|
if (!CollectionUtils.isEmpty(objectList)) {
|
||||||
|
return objectList.stream()
|
||||||
|
.map(object -> JSON.parseObject(object.toString(), CartInfo.class))
|
||||||
|
.filter(cartInfo -> cartInfo.getIsChecked() == 1)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue