Bang Hu
2025-09-03 bd28d26d3da636718aeb73edca00f3da6ecbe4b2
src/main/java/com/webmanage/controller/CartController.java
@@ -35,8 +35,8 @@
    @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) {
@@ -52,8 +52,8 @@
    
    @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);
@@ -70,8 +70,8 @@
    
    @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 {
@@ -89,8 +89,8 @@
    
    @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) {
@@ -106,8 +106,8 @@
    
    @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);
@@ -119,8 +119,8 @@
    
    @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);
@@ -132,8 +132,8 @@
    
    @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);
@@ -150,8 +150,8 @@
    
    @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);
@@ -163,8 +163,8 @@
    
    @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) {
@@ -180,8 +180,8 @@
    
    @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) {
@@ -197,8 +197,8 @@
    
    @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) {