| | |
| | | @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 String productId, |
| | | @RequestParam @NotNull Long pricingId) { |
| | | try { |
| | | boolean result = cartService.removeFromCart(userId, unitId, pricingId); |
| | | boolean result = cartService.removeFromCart(userId, unitId, productId, pricingId); |
| | | if (result) { |
| | | return Result.success("从购物车移除商品成功"); |
| | | } else { |
| | |
| | | |
| | | @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 String productId, |
| | | @RequestParam @NotNull Long pricingId, |
| | | @RequestParam @NotNull @Min(1) Integer quantity) { |
| | | try { |
| | | boolean result = cartService.updateCartItemQuantity(userId, unitId, pricingId, quantity); |
| | | boolean result = cartService.updateCartItemQuantity(userId, unitId, productId, pricingId, quantity); |
| | | if (result) { |
| | | return Result.success("更新购物车商品数量成功"); |
| | | } else { |
| | | return Result.error("更新购物车商品数量失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("更新购物车商品数量失败", e); |
| | | return Result.error("更新购物车商品数量失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | @PutMapping("/update/duration") |
| | | @ApiOperation("更新购物车商品数量") |
| | | public Result<Object> updateCartItemDuration(@RequestParam @NotNull String userId, |
| | | @RequestParam String unitId, |
| | | @RequestParam @NotNull String productId, |
| | | @RequestParam @NotNull Long pricingId, |
| | | @RequestParam @NotNull @Min(1) Integer duration) { |
| | | try { |
| | | boolean result = cartService.updateCartItemDuration(userId, unitId, productId, pricingId, duration); |
| | | if (result) { |
| | | return Result.success("更新购物车商品数量成功"); |
| | | } else { |
| | |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId) { |
| | | try { |
| | | boolean result = cartService.clearCart(userId, unitId); |
| | | boolean result = cartService.clearCart(userId, unitId, productId); |
| | | if (result) { |
| | | return Result.success("清空购物车成功"); |
| | | } else { |
| | |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId ) { |
| | | try { |
| | | CartVO cart = cartService.getCart(userId, unitId); |
| | | CartVO cart = cartService.getCart(userId, unitId, productId); |
| | | return Result.success(cart); |
| | | } catch (Exception e) { |
| | | log.error("获取购物车信息失败", e); |
| | |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId) { |
| | | try { |
| | | List<CartItemVO> items = cartService.getCartItems(userId, unitId); |
| | | List<CartItemVO> items = cartService.getCartItems(userId, unitId, productId); |
| | | return Result.success(items); |
| | | } catch (Exception e) { |
| | | log.error("获取购物车商品列表失败", e); |
| | |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId, |
| | | @RequestBody List<Long> pricingIds) { |
| | | try { |
| | | boolean result = cartService.batchRemoveFromCart(userId, unitId, pricingIds); |
| | | boolean result = cartService.batchRemoveFromCart(userId, unitId, productId, pricingIds); |
| | | if (result) { |
| | | return Result.success("批量删除购物车商品成功"); |
| | | } else { |
| | |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId ) { |
| | | try { |
| | | Integer count = cartService.getCartItemCount(userId, unitId); |
| | | Integer count = cartService.getCartItemCount(userId, unitId, productId); |
| | | return Result.success(count); |
| | | } catch (Exception e) { |
| | | log.error("获取购物车商品数量失败", e); |
| | |
| | | |
| | | @PostMapping("/sync-to-db") |
| | | @ApiOperation("同步Redis购物车数据到数据库") |
| | | public Result<Object> syncCartToDatabase(@RequestParam @NotNull Long userId, |
| | | @RequestParam @NotNull Long unitId) { |
| | | try { |
| | | boolean result = cartService.syncCartToDatabase(userId, unitId); |
| | | if (result) { |
| | | return Result.success("同步购物车数据到数据库成功"); |
| | | } else { |
| | | return Result.error("同步购物车数据到数据库失败"); |
| | | public Result<Object> syncCartToDatabase(@RequestParam @NotNull String userId, |
| | | @RequestParam @NotNull String unitId, |
| | | @RequestParam @NotNull String productId ) { |
| | | try { |
| | | boolean result = cartService.syncCartToDatabase(userId, unitId, productId); |
| | | if (result) { |
| | | return Result.success("同步购物车数据到数据库成功"); |
| | | } else { |
| | | return Result.error("同步购物车数据到数据库失败"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("同步购物车数据到数据库失败", e); |
| | | return Result.error("同步购物车数据到数据库失败:" + e.getMessage()); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("同步购物车数据到数据库失败", e); |
| | | return Result.error("同步购物车数据到数据库失败:" + e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId ) { |
| | | try { |
| | | boolean result = cartService.loadCartFromDatabase(userId, unitId); |
| | | boolean result = cartService.loadCartFromDatabase(userId, unitId,productId); |
| | | if (result) { |
| | | return Result.success("从数据库加载购物车数据成功"); |
| | | } else { |
| | |
| | | |
| | | @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, |
| | | @RequestParam @NotNull String productId) { |
| | | try { |
| | | boolean isConsistent = cartService.checkCartConsistency(userId, unitId); |
| | | boolean isConsistent = cartService.checkCartConsistency(userId, unitId, productId); |
| | | if (isConsistent) { |
| | | return Result.success("购物车数据一致"); |
| | | } else { |