| | |
| | | @PostMapping("/add") |
| | | @ApiOperation("添加商品到购物车") |
| | | public Result<Object> addToCart(@Valid @RequestBody CartItemDTO cartItemDTO, |
| | | @RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | @RequestParam @NotNull String userId, |
| | | @RequestParam String unitId) { |
| | | try { |
| | | boolean result = cartService.addToCart(userId, unitId, cartItemDTO); |
| | | if (result) { |
| | |
| | | |
| | | @DeleteMapping("/remove") |
| | | @ApiOperation("从购物车移除商品") |
| | | public Result<Object> removeFromCart(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId, |
| | | public Result<Object> removeFromCart(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId, |
| | | @RequestParam @NotNull Long pricingId) { |
| | | try { |
| | | boolean result = cartService.removeFromCart(userId, unitId, pricingId); |
| | |
| | | |
| | | @PutMapping("/update") |
| | | @ApiOperation("更新购物车商品数量") |
| | | public Result<Object> updateCartItemQuantity(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId, |
| | | public Result<Object> updateCartItemQuantity(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId, |
| | | @RequestParam @NotNull Long pricingId, |
| | | @RequestParam @NotNull @Min(1) Integer quantity) { |
| | | try { |
| | |
| | | |
| | | @DeleteMapping("/clear") |
| | | @ApiOperation("清空购物车") |
| | | public Result<Object> clearCart(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> clearCart(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId) { |
| | | try { |
| | | boolean result = cartService.clearCart(userId, unitId); |
| | | if (result) { |
| | |
| | | |
| | | @GetMapping("/info") |
| | | @ApiOperation("获取购物车信息") |
| | | public Result<Object> getCart(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> getCart(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId) { |
| | | try { |
| | | CartVO cart = cartService.getCart(userId, unitId); |
| | | return Result.success(cart); |
| | |
| | | |
| | | @GetMapping("/items") |
| | | @ApiOperation("获取购物车商品列表") |
| | | public Result<Object> getCartItems(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> getCartItems(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId) { |
| | | try { |
| | | List<CartItemVO> items = cartService.getCartItems(userId, unitId); |
| | | return Result.success(items); |
| | |
| | | |
| | | @DeleteMapping("/batch-remove") |
| | | @ApiOperation("批量删除购物车商品") |
| | | public Result<Object> batchRemoveFromCart(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId, |
| | | public Result<Object> batchRemoveFromCart(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId, |
| | | @RequestBody List<Long> pricingIds) { |
| | | try { |
| | | boolean result = cartService.batchRemoveFromCart(userId, unitId, pricingIds); |
| | |
| | | |
| | | @GetMapping("/count") |
| | | @ApiOperation("获取购物车商品数量") |
| | | public Result<Object> getCartItemCount(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> getCartItemCount(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId) { |
| | | try { |
| | | Integer count = cartService.getCartItemCount(userId, unitId); |
| | | return Result.success(count); |
| | |
| | | |
| | | @PostMapping("/sync-to-db") |
| | | @ApiOperation("同步Redis购物车数据到数据库") |
| | | public Result<Object> syncCartToDatabase(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> syncCartToDatabase(@RequestParam @NotNull String userId, |
| | | @RequestParam @NotNull String unitId) { |
| | | try { |
| | | boolean result = cartService.syncCartToDatabase(userId, unitId); |
| | | if (result) { |
| | |
| | | |
| | | @PostMapping("/load-from-db") |
| | | @ApiOperation("从数据库加载购物车数据到Redis") |
| | | public Result<Object> loadCartFromDatabase(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> loadCartFromDatabase(@RequestParam @NotNull String userId, |
| | | @RequestParam @NotNull String unitId) { |
| | | try { |
| | | boolean result = cartService.loadCartFromDatabase(userId, unitId); |
| | | if (result) { |
| | |
| | | |
| | | @GetMapping("/consistency") |
| | | @ApiOperation("检查购物车数据一致性") |
| | | public Result<Object> checkCartConsistency(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | public Result<Object> checkCartConsistency(@RequestParam @NotNull String userId, |
| | | @RequestParam @NotNull String unitId) { |
| | | try { |
| | | boolean isConsistent = cartService.checkCartConsistency(userId, unitId); |
| | | if (isConsistent) { |