From 53c315297a3906e567b01107a85836528a664206 Mon Sep 17 00:00:00 2001
From: seatonwan9
Date: 星期二, 19 八月 2025 18:11:38 +0800
Subject: [PATCH] 产品订购sql

---
 src/main/java/com/webmanage/service/impl/CartPersistenceServiceImpl.java |   64 ++++++++++++++++++++++++++++++++
 1 files changed, 64 insertions(+), 0 deletions(-)

diff --git a/src/main/java/com/webmanage/service/impl/CartPersistenceServiceImpl.java b/src/main/java/com/webmanage/service/impl/CartPersistenceServiceImpl.java
new file mode 100644
index 0000000..cdbe2c2
--- /dev/null
+++ b/src/main/java/com/webmanage/service/impl/CartPersistenceServiceImpl.java
@@ -0,0 +1,64 @@
+package com.webmanage.service.impl;
+
+import com.webmanage.entity.Cart;
+import com.webmanage.mapper.CartMapper;
+import com.webmanage.service.CartPersistenceService;
+import com.webmanage.vo.CartItemVO;
+import org.springframework.beans.BeanUtils;
+import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.AsyncConfigurer;
+import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.time.LocalDateTime;
+
+@Service
+public class CartPersistenceServiceImpl implements CartPersistenceService {
+
+    @Resource
+    private CartMapper cartMapper;
+
+    @Override
+    @Async("asyncExecutor")
+    public void saveOrUpdate(Long userId, Long unitId, CartItemVO item) {
+        try {
+            Cart cart = new Cart();
+            BeanUtils.copyProperties(item, cart);
+            cart.setUserId(userId);
+            cart.setUnitId(unitId);
+            cart.setUpdateTime(LocalDateTime.now());
+            Cart existing = cartMapper.selectByUserIdUnitIdAndPricingId(userId, unitId, item.getPricingId());
+            if (existing != null) {
+                cart.setId(existing.getId());
+                cartMapper.updateById(cart);
+            } else {
+                cart.setAddTime(LocalDateTime.now());
+                cartMapper.insert(cart);
+            }
+        } catch (Exception ignored) {}
+    }
+
+    @Override
+    @Async("asyncExecutor")
+    public void remove(Long userId, Long unitId, Long pricingId) {
+        try {
+            Cart existing = cartMapper.selectByUserIdUnitIdAndPricingId(userId, unitId, pricingId);
+            if (existing != null) {
+                cartMapper.deleteById(existing.getId());
+            }
+        } catch (Exception ignored) {}
+    }
+
+    @Override
+    @Async("asyncExecutor")
+    public void clear(Long userId, Long unitId) {
+        try {
+            java.util.List<Cart> cartItems = cartMapper.selectByUserIdAndUnitId(userId, unitId);
+            for (Cart item : cartItems) {
+                cartMapper.deleteById(item.getId());
+            }
+        } catch (Exception ignored) {}
+    }
+}
+
+

--
Gitblit v1.8.0