feng_ting-ting 2 days ago
parent
commit
142ceb01a5
29 changed files with 968 additions and 0 deletions
  1. 24 0
      XiaoETech-admin/src/main/java/com/zhentao/web/controller/system/OrderController.java
  2. 5 0
      XiaoETech-system/pom.xml
  3. 63 0
      XiaoETech-system/src/main/java/com/zhentao/system/domain/Coupon.java
  4. 89 0
      XiaoETech-system/src/main/java/com/zhentao/system/domain/OrderDetail.java
  5. 78 0
      XiaoETech-system/src/main/java/com/zhentao/system/domain/OrderMaster.java
  6. 75 0
      XiaoETech-system/src/main/java/com/zhentao/system/domain/ProductSku.java
  7. 62 0
      XiaoETech-system/src/main/java/com/zhentao/system/domain/User.java
  8. 12 0
      XiaoETech-system/src/main/java/com/zhentao/system/dto/OrderDto.java
  9. 9 0
      XiaoETech-system/src/main/java/com/zhentao/system/dto/UserDto.java
  10. 19 0
      XiaoETech-system/src/main/java/com/zhentao/system/mapper/CouponMapper.java
  11. 18 0
      XiaoETech-system/src/main/java/com/zhentao/system/mapper/OrderDetailMapper.java
  12. 18 0
      XiaoETech-system/src/main/java/com/zhentao/system/mapper/OrderMasterMapper.java
  13. 21 0
      XiaoETech-system/src/main/java/com/zhentao/system/mapper/ProductSkuMapper.java
  14. 15 0
      XiaoETech-system/src/main/java/com/zhentao/system/mapper/UserMapper.java
  15. 10 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/CouponService.java
  16. 15 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/CourseCategoryService.java
  17. 10 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/OrderDetailService.java
  18. 13 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/OrderMasterService.java
  19. 9 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/ProductSkuService.java
  20. 17 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/impl/CouponServiceImpl.java
  21. 17 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/impl/OrderDetailServiceImpl.java
  22. 124 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/impl/OrderMasterServiceImpl.java
  23. 19 0
      XiaoETech-system/src/main/java/com/zhentao/system/service/impl/ProductSkuServiceImpl.java
  24. 94 0
      XiaoETech-system/src/main/java/com/zhentao/system/utils/TokenUtils.java
  25. 22 0
      XiaoETech-system/src/main/resources/mapper/system/CouponMapper.xml
  26. 27 0
      XiaoETech-system/src/main/resources/mapper/system/OrderDetailMapper.xml
  27. 26 0
      XiaoETech-system/src/main/resources/mapper/system/OrderMasterMapper.xml
  28. 41 0
      XiaoETech-system/src/main/resources/mapper/system/ProductSkuMapper.xml
  29. 16 0
      XiaoETech-system/src/main/resources/mapper/system/UserMapper.xml

+ 24 - 0
XiaoETech-admin/src/main/java/com/zhentao/web/controller/system/OrderController.java

@@ -0,0 +1,24 @@
+package com.zhentao.web.controller.system;
+
+import com.zhentao.system.dto.OrderDto;
+import com.zhentao.system.service.OrderMasterService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @date: 2025/5/9 20:29
+ * @author: ftt
+ */
+
+@RestController
+public class OrderController {
+    @Autowired
+    private OrderMasterService orderMasterService;
+
+    @PostMapping("/addOrder")
+    public void addOrder(@RequestBody OrderDto dto){
+        orderMasterService.addOrder(dto);
+    }
+}

+ 5 - 0
XiaoETech-system/pom.xml

@@ -50,6 +50,11 @@
             <groupId>com.zhentao</groupId>
             <artifactId>zhentao-common</artifactId>
         </dependency>
+        <dependency>
+            <groupId>com.baomidou</groupId>
+            <artifactId>mybatis-plus-extension</artifactId>
+            <version>3.5.4</version>
+        </dependency>
     </dependencies>
 
 </project>

+ 63 - 0
XiaoETech-system/src/main/java/com/zhentao/system/domain/Coupon.java

@@ -0,0 +1,63 @@
+package com.zhentao.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @TableName coupon
+ */
+@TableName(value ="coupon")
+@Data
+public class Coupon implements Serializable {
+    private String couponId;
+
+    private String userId;
+
+    private BigDecimal discountAmount;
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        Coupon other = (Coupon) that;
+        return (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId()))
+            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+            && (this.getDiscountAmount() == null ? other.getDiscountAmount() == null : this.getDiscountAmount().equals(other.getDiscountAmount()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode());
+        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+        result = prime * result + ((getDiscountAmount() == null) ? 0 : getDiscountAmount().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", couponId=").append(couponId);
+        sb.append(", userId=").append(userId);
+        sb.append(", discountAmount=").append(discountAmount);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 89 - 0
XiaoETech-system/src/main/java/com/zhentao/system/domain/OrderDetail.java

@@ -0,0 +1,89 @@
+package com.zhentao.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * @TableName order_detail
+ */
+@TableName(value ="order_detail")
+@Data
+public class OrderDetail implements Serializable {
+    private Long detailId;
+
+    private Long orderId;
+
+    private Long skuId;
+
+    private String productName;
+
+    private BigDecimal unitPrice;
+
+    private Integer quantity;
+
+    private BigDecimal amount;
+
+    private Date createTime;
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        OrderDetail other = (OrderDetail) that;
+        return (this.getDetailId() == null ? other.getDetailId() == null : this.getDetailId().equals(other.getDetailId()))
+            && (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId()))
+            && (this.getSkuId() == null ? other.getSkuId() == null : this.getSkuId().equals(other.getSkuId()))
+            && (this.getProductName() == null ? other.getProductName() == null : this.getProductName().equals(other.getProductName()))
+            && (this.getUnitPrice() == null ? other.getUnitPrice() == null : this.getUnitPrice().equals(other.getUnitPrice()))
+            && (this.getQuantity() == null ? other.getQuantity() == null : this.getQuantity().equals(other.getQuantity()))
+            && (this.getAmount() == null ? other.getAmount() == null : this.getAmount().equals(other.getAmount()))
+            && (this.getCreateTime() == null ? other.getCreateTime() == null : this.getCreateTime().equals(other.getCreateTime()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getDetailId() == null) ? 0 : getDetailId().hashCode());
+        result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode());
+        result = prime * result + ((getSkuId() == null) ? 0 : getSkuId().hashCode());
+        result = prime * result + ((getProductName() == null) ? 0 : getProductName().hashCode());
+        result = prime * result + ((getUnitPrice() == null) ? 0 : getUnitPrice().hashCode());
+        result = prime * result + ((getQuantity() == null) ? 0 : getQuantity().hashCode());
+        result = prime * result + ((getAmount() == null) ? 0 : getAmount().hashCode());
+        result = prime * result + ((getCreateTime() == null) ? 0 : getCreateTime().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", detailId=").append(detailId);
+        sb.append(", orderId=").append(orderId);
+        sb.append(", skuId=").append(skuId);
+        sb.append(", productName=").append(productName);
+        sb.append(", unitPrice=").append(unitPrice);
+        sb.append(", quantity=").append(quantity);
+        sb.append(", amount=").append(amount);
+        sb.append(", createTime=").append(createTime);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 78 - 0
XiaoETech-system/src/main/java/com/zhentao/system/domain/OrderMaster.java

@@ -0,0 +1,78 @@
+package com.zhentao.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @TableName order_master
+ */
+@TableName(value ="order_master")
+@Data
+public class OrderMaster implements Serializable {
+    private String orderId;
+
+    private String userId;
+
+    private BigDecimal totalAmount;
+
+    private BigDecimal discountAmount;
+
+    private BigDecimal actualAmount;
+
+    private Long couponId;
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        OrderMaster other = (OrderMaster) that;
+        return (this.getOrderId() == null ? other.getOrderId() == null : this.getOrderId().equals(other.getOrderId()))
+            && (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+            && (this.getTotalAmount() == null ? other.getTotalAmount() == null : this.getTotalAmount().equals(other.getTotalAmount()))
+            && (this.getDiscountAmount() == null ? other.getDiscountAmount() == null : this.getDiscountAmount().equals(other.getDiscountAmount()))
+            && (this.getActualAmount() == null ? other.getActualAmount() == null : this.getActualAmount().equals(other.getActualAmount()))
+            && (this.getCouponId() == null ? other.getCouponId() == null : this.getCouponId().equals(other.getCouponId()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getOrderId() == null) ? 0 : getOrderId().hashCode());
+        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+        result = prime * result + ((getTotalAmount() == null) ? 0 : getTotalAmount().hashCode());
+        result = prime * result + ((getDiscountAmount() == null) ? 0 : getDiscountAmount().hashCode());
+        result = prime * result + ((getActualAmount() == null) ? 0 : getActualAmount().hashCode());
+        result = prime * result + ((getCouponId() == null) ? 0 : getCouponId().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", orderId=").append(orderId);
+        sb.append(", userId=").append(userId);
+        sb.append(", totalAmount=").append(totalAmount);
+        sb.append(", discountAmount=").append(discountAmount);
+        sb.append(", actualAmount=").append(actualAmount);
+        sb.append(", couponId=").append(couponId);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 75 - 0
XiaoETech-system/src/main/java/com/zhentao/system/domain/ProductSku.java

@@ -0,0 +1,75 @@
+package com.zhentao.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * @TableName product_sku
+ */
+@TableName(value ="product_sku")
+@Data
+public class ProductSku implements Serializable {
+    @TableId
+    private Long skuId;
+
+    private Long productId;
+
+    private String productName;
+
+    private BigDecimal unitPrice;
+
+    private Integer stock;
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        ProductSku other = (ProductSku) that;
+        return (this.getSkuId() == null ? other.getSkuId() == null : this.getSkuId().equals(other.getSkuId()))
+            && (this.getProductId() == null ? other.getProductId() == null : this.getProductId().equals(other.getProductId()))
+            && (this.getProductName() == null ? other.getProductName() == null : this.getProductName().equals(other.getProductName()))
+            && (this.getUnitPrice() == null ? other.getUnitPrice() == null : this.getUnitPrice().equals(other.getUnitPrice()))
+            && (this.getStock() == null ? other.getStock() == null : this.getStock().equals(other.getStock()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getSkuId() == null) ? 0 : getSkuId().hashCode());
+        result = prime * result + ((getProductId() == null) ? 0 : getProductId().hashCode());
+        result = prime * result + ((getProductName() == null) ? 0 : getProductName().hashCode());
+        result = prime * result + ((getUnitPrice() == null) ? 0 : getUnitPrice().hashCode());
+        result = prime * result + ((getStock() == null) ? 0 : getStock().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", skuId=").append(skuId);
+        sb.append(", productId=").append(productId);
+        sb.append(", productName=").append(productName);
+        sb.append(", unitPrice=").append(unitPrice);
+        sb.append(", stock=").append(stock);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 62 - 0
XiaoETech-system/src/main/java/com/zhentao/system/domain/User.java

@@ -0,0 +1,62 @@
+package com.zhentao.system.domain;
+
+import com.baomidou.mybatisplus.annotation.TableName;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * @TableName user
+ */
+@TableName(value ="user")
+@Data
+public class User implements Serializable {
+    private String userId;
+
+    private String username;
+
+    private String password;
+
+    private static final long serialVersionUID = 1L;
+
+    @Override
+    public boolean equals(Object that) {
+        if (this == that) {
+            return true;
+        }
+        if (that == null) {
+            return false;
+        }
+        if (getClass() != that.getClass()) {
+            return false;
+        }
+        User other = (User) that;
+        return (this.getUserId() == null ? other.getUserId() == null : this.getUserId().equals(other.getUserId()))
+            && (this.getUsername() == null ? other.getUsername() == null : this.getUsername().equals(other.getUsername()))
+            && (this.getPassword() == null ? other.getPassword() == null : this.getPassword().equals(other.getPassword()));
+    }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((getUserId() == null) ? 0 : getUserId().hashCode());
+        result = prime * result + ((getUsername() == null) ? 0 : getUsername().hashCode());
+        result = prime * result + ((getPassword() == null) ? 0 : getPassword().hashCode());
+        return result;
+    }
+
+    @Override
+    public String toString() {
+        StringBuilder sb = new StringBuilder();
+        sb.append(getClass().getSimpleName());
+        sb.append(" [");
+        sb.append("Hash = ").append(hashCode());
+        sb.append(", userId=").append(userId);
+        sb.append(", username=").append(username);
+        sb.append(", password=").append(password);
+        sb.append(", serialVersionUID=").append(serialVersionUID);
+        sb.append("]");
+        return sb.toString();
+    }
+}

+ 12 - 0
XiaoETech-system/src/main/java/com/zhentao/system/dto/OrderDto.java

@@ -0,0 +1,12 @@
+package com.zhentao.system.dto;
+
+import com.zhentao.system.domain.OrderDetail;
+import lombok.Data;
+
+import java.util.List;
+@Data
+public class OrderDto {
+    private List<OrderDetail> orderDetails;
+    private String token;
+    private Long couponId;
+}

+ 9 - 0
XiaoETech-system/src/main/java/com/zhentao/system/dto/UserDto.java

@@ -0,0 +1,9 @@
+package com.zhentao.system.dto;
+
+import lombok.Data;
+
+@Data
+public class UserDto {
+    private String username;
+    private String password;
+}

+ 19 - 0
XiaoETech-system/src/main/java/com/zhentao/system/mapper/CouponMapper.java

@@ -0,0 +1,19 @@
+package com.zhentao.system.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.zhentao.system.domain.Coupon;
+
+/**
+* @author ASUS
+* @description 针对表【coupon(优惠券表)】的数据库操作Mapper
+* @createDate 2025-05-09 20:31:23
+* @Entity com.zhentao.domain.Coupon
+*/
+public interface CouponMapper {
+
+    Coupon getOne(QueryWrapper<Coupon> queryWrapper);
+}
+
+
+
+

+ 18 - 0
XiaoETech-system/src/main/java/com/zhentao/system/mapper/OrderDetailMapper.java

@@ -0,0 +1,18 @@
+package com.zhentao.system.mapper;
+
+import com.zhentao.system.domain.OrderDetail;
+
+/**
+* @author ASUS
+* @description 针对表【order_detail(订单明细表)】的数据库操作Mapper
+* @createDate 2025-05-09 20:31:23
+* @Entity com.zhentao.domain.OrderDetail
+*/
+public interface OrderDetailMapper {
+
+    void save(OrderDetail orderDetail);
+}
+
+
+
+

+ 18 - 0
XiaoETech-system/src/main/java/com/zhentao/system/mapper/OrderMasterMapper.java

@@ -0,0 +1,18 @@
+package com.zhentao.system.mapper;
+
+import com.zhentao.system.domain.OrderMaster;
+
+/**
+* @author ASUS
+* @description 针对表【order_master(订单主表)】的数据库操作Mapper
+* @createDate 2025-05-09 20:31:23
+* @Entity com.zhentao.domain.OrderMaster
+*/
+public interface OrderMasterMapper {
+
+    void save(OrderMaster orderMaster);
+}
+
+
+
+

+ 21 - 0
XiaoETech-system/src/main/java/com/zhentao/system/mapper/ProductSkuMapper.java

@@ -0,0 +1,21 @@
+package com.zhentao.system.mapper;
+
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.zhentao.system.domain.ProductSku;
+
+/**
+* @author ASUS
+* @description 针对表【product_sku(商品SKU表)】的数据库操作Mapper
+* @createDate 2025-05-09 20:31:23
+* @Entity com.zhentao.domain.ProductSku
+*/
+public interface ProductSkuMapper{
+
+    ProductSku getOne(QueryWrapper<ProductSku> queryWrapper);
+
+    void updateById(ProductSku skus);
+}
+
+
+
+

+ 15 - 0
XiaoETech-system/src/main/java/com/zhentao/system/mapper/UserMapper.java

@@ -0,0 +1,15 @@
+package com.zhentao.system.mapper;
+
+/**
+* @author ASUS
+* @description 针对表【user(用户表)】的数据库操作Mapper
+* @createDate 2025-05-09 20:31:23
+* @Entity com.zhentao.domain.User
+*/
+public interface UserMapper {
+
+}
+
+
+
+

+ 10 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/CouponService.java

@@ -0,0 +1,10 @@
+package com.zhentao.system.service;
+
+/**
+* @author ASUS
+* @description 针对表【coupon(优惠券表)】的数据库操作Service
+* @createDate 2025-05-09 20:31:23
+*/
+public interface CouponService{
+
+}

+ 15 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/CourseCategoryService.java

@@ -0,0 +1,15 @@
+package com.zhentao.system.service;
+
+import com.zhentao.system.domain.CourseCategory;
+
+import java.util.List;
+
+/**
+* @author ASUS
+* @description 针对表【course_category(课程分类表)】的数据库操作Service
+* @createDate 2025-05-12 09:05:20
+*/
+public interface CourseCategoryService {
+
+    List<CourseCategory> findAll();
+}

+ 10 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/OrderDetailService.java

@@ -0,0 +1,10 @@
+package com.zhentao.system.service;
+
+/**
+* @author ASUS
+* @description 针对表【order_detail(订单明细表)】的数据库操作Service
+* @createDate 2025-05-09 20:31:23
+*/
+public interface OrderDetailService  {
+
+}

+ 13 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/OrderMasterService.java

@@ -0,0 +1,13 @@
+package com.zhentao.system.service;
+
+import com.zhentao.system.dto.OrderDto;
+
+/**
+* @author ASUS
+* @description 针对表【order_master(订单主表)】的数据库操作Service
+* @createDate 2025-05-09 20:31:23
+*/
+public interface OrderMasterService {
+
+    void addOrder(OrderDto dto);
+}

+ 9 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/ProductSkuService.java

@@ -0,0 +1,9 @@
+package com.zhentao.system.service;
+
+/**
+* @author ASUS
+* @description 针对表【product_sku(商品SKU表)】的数据库操作Service
+* @createDate 2025-05-09 20:31:23
+*/
+public interface ProductSkuService {
+}

+ 17 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/impl/CouponServiceImpl.java

@@ -0,0 +1,17 @@
+package com.zhentao.system.service.impl;
+
+import org.springframework.stereotype.Service;
+
+/**
+* @author ASUS
+* @description 针对表【coupon(优惠券表)】的数据库操作Service实现
+* @createDate 2025-05-09 20:31:23
+*/
+@Service
+public class CouponServiceImpl {
+
+}
+
+
+
+

+ 17 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/impl/OrderDetailServiceImpl.java

@@ -0,0 +1,17 @@
+package com.zhentao.system.service.impl;
+
+import org.springframework.stereotype.Service;
+
+/**
+* @author ASUS
+* @description 针对表【order_detail(订单明细表)】的数据库操作Service实现
+* @createDate 2025-05-09 20:31:23
+*/
+@Service
+public class OrderDetailServiceImpl {
+
+}
+
+
+
+

+ 124 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/impl/OrderMasterServiceImpl.java

@@ -0,0 +1,124 @@
+package com.zhentao.system.service.impl;
+
+import cn.hutool.core.util.IdUtil;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
+import com.zhentao.system.domain.Coupon;
+import com.zhentao.system.domain.OrderDetail;
+import com.zhentao.system.domain.OrderMaster;
+import com.zhentao.system.domain.ProductSku;
+import com.zhentao.system.dto.OrderDto;
+import com.zhentao.system.mapper.CouponMapper;
+import com.zhentao.system.mapper.OrderDetailMapper;
+import com.zhentao.system.mapper.OrderMasterMapper;
+import com.zhentao.system.mapper.ProductSkuMapper;
+import com.zhentao.system.service.OrderMasterService;
+import com.zhentao.system.utils.TokenUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.redis.core.StringRedisTemplate;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+* @author ASUS
+* @description 针对表【order_master(订单主表)】的数据库操作Service实现
+* @createDate 2025-05-09 20:31:23
+*/
+@Service
+public class OrderMasterServiceImpl implements OrderMasterService {
+
+    @Autowired
+    private StringRedisTemplate stringRedisTemplate;
+
+    @Autowired
+    private ProductSkuMapper productSkuMapper;
+
+    @Autowired
+    private CouponMapper couponMapper;
+
+    @Autowired
+    private OrderDetailMapper orderDetailMapper;
+
+    @Autowired
+    OrderMasterMapper orderMasterMapper;
+
+    @Override
+    public void addOrder(OrderDto dto) {
+        // 创建一个对象
+        OrderMaster orderMaster = new OrderMaster();
+        // 雪花算法id
+        Long id = IdUtil.getSnowflake(1, 1).nextId();
+        orderMaster.setOrderId(String.valueOf(id));
+        // 判断order是否为空, 设置用户id
+        String userIdFromToken = TokenUtils.getUserIdFromToken(dto.getToken());
+        System.err.println("用户id: " + userIdFromToken);
+        if(userIdFromToken == null){
+            String userId = stringRedisTemplate.opsForValue().get("userId");
+            String userIdFromToken1 = TokenUtils.getUserIdFromToken(userId);
+            orderMaster.setUserId(userIdFromToken1);
+        }else{
+            orderMaster.setUserId(userIdFromToken);
+        }
+
+        // 查询商品信息转化为Map
+        List<Long> collect = dto.getOrderDetails().stream().map(OrderDetail::getSkuId).collect(Collectors.toList());
+        System.err.println("所有的skuId: " + collect);
+        List<ProductSku> productSkus = new ArrayList<>();
+        for (Long aLong : collect) {
+            QueryWrapper<ProductSku> queryWrapper = new QueryWrapper<>();
+            queryWrapper.eq("sku_id", aLong);
+            ProductSku one = productSkuMapper.getOne(queryWrapper);
+            productSkus.add(one);
+        }
+        System.err.println("商品信息: " + productSkus);
+        Map<Long, ProductSku> collect1 = productSkus.stream().collect(Collectors.toMap(ProductSku::getSkuId, p -> p));
+        System.err.println("商品信息Map: " + collect1);
+        // 计算总价格
+        BigDecimal totalAmount = new BigDecimal("0");
+        List<OrderDetail> orderDetails = dto.getOrderDetails();
+        for (OrderDetail orderDetail : orderDetails) {
+            // 获取sku的基本信息
+            ProductSku productSku = collect1.get(orderDetail.getSkuId());
+            // 小计
+            BigDecimal amount = productSku.getUnitPrice().multiply(new BigDecimal(orderDetail.getQuantity()));
+            orderDetail.setAmount(amount);
+            totalAmount = totalAmount.add(amount);
+        }
+        orderMaster.setTotalAmount(totalAmount);
+        System.err.println("总价格: " + totalAmount);
+        // 扣减的优惠券
+        QueryWrapper<Coupon> queryWrapper = new QueryWrapper<>();
+        queryWrapper.eq("coupon_id", dto.getCouponId());
+        Coupon one = couponMapper.getOne(queryWrapper);
+        // 设置优惠券id
+        orderMaster.setCouponId(Long.valueOf(String.valueOf(one.getCouponId())));
+        // 设置优惠券优惠金额
+        orderMaster.setDiscountAmount(one.getDiscountAmount());
+        // 设置实际支付金额
+        orderMaster.setActualAmount(totalAmount.subtract(one.getDiscountAmount()));
+        System.err.println("订单的所有信息: " + orderMaster);
+        orderMasterMapper.save(orderMaster);
+        for (OrderDetail orderDetail : orderDetails) {
+            long id1 = IdUtil.getSnowflake(1, 1).nextId();
+            orderDetail.setDetailId(id);
+            orderDetail.setOrderId(id);
+            orderDetailMapper.save(orderDetail);
+        }
+        for (ProductSku skus : productSkus) {
+            for (OrderDetail orderDetail : orderDetails) {
+                if(skus.getSkuId().equals(orderDetail.getSkuId())){
+                    skus.setStock(skus.getStock() - orderDetail.getQuantity());
+                    productSkuMapper.updateById(skus);
+                }
+            }
+        }
+    }
+}
+
+
+
+

+ 19 - 0
XiaoETech-system/src/main/java/com/zhentao/system/service/impl/ProductSkuServiceImpl.java

@@ -0,0 +1,19 @@
+package com.zhentao.system.service.impl;
+
+import com.zhentao.system.service.ProductSkuService;
+import org.springframework.stereotype.Service;
+
+/**
+* @author ASUS
+* @description 针对表【product_sku(商品SKU表)】的数据库操作Service实现
+* @createDate 2025-05-09 20:31:23
+*/
+@Service
+public class ProductSkuServiceImpl
+    implements ProductSkuService{
+
+}
+
+
+
+

+ 94 - 0
XiaoETech-system/src/main/java/com/zhentao/system/utils/TokenUtils.java

@@ -0,0 +1,94 @@
+package com.zhentao.system.utils;
+
+import io.jsonwebtoken.Claims;
+import io.jsonwebtoken.Jwts;
+import io.jsonwebtoken.SignatureAlgorithm;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+public class TokenUtils {
+
+    // 密钥,生产环境应该从配置文件中读取
+    private static final String SECRET_KEY = "your-secret-key-here";
+
+    // Token有效期(毫秒),这里设置为24小时
+    private static final long EXPIRATION_TIME = 24 * 60 * 60 * 1000;
+
+    /**
+     * 生成JWT Token
+     * @param userId 用户ID
+     * @return JWT Token
+     */
+    public static String generateToken(String userId) {
+        Map<String, Object> claims = new HashMap<>();
+        claims.put("userId", userId);
+
+        return Jwts.builder()
+                .setClaims(claims)
+                .setSubject(userId)
+                .setIssuedAt(new Date(System.currentTimeMillis()))
+                .setExpiration(new Date(System.currentTimeMillis() + EXPIRATION_TIME)) // 修正此处
+                .signWith(SignatureAlgorithm.HS512, SECRET_KEY)
+                .compact();
+    }
+    /**
+     * 从Token中获取用户ID
+     * @param token JWT Token
+     * @return 用户ID
+     */
+    public static String getUserIdFromToken(String token) {
+        try {
+            Claims claims = Jwts.parser()
+                    .setSigningKey(SECRET_KEY)
+                    .parseClaimsJws(token)
+                    .getBody();
+
+            return claims.get("userId", String.class);
+        } catch (Exception e) {
+            // 处理Token解析异常
+            e.printStackTrace();
+            return null;
+        }
+    }
+
+    /**
+     * 验证Token是否有效
+     * @param token JWT Token
+     * @return 是否有效
+     */
+    public static boolean validateToken(String token) {
+        try {
+            Jwts.parser().setSigningKey(SECRET_KEY).parseClaimsJws(token);
+            return true;
+        } catch (Exception e) {
+            // 处理Token验证异常
+            e.printStackTrace();
+            return false;
+        }
+    }
+
+    /**
+     * 从Token中获取所有Claims
+     * @param token JWT Token
+     * @return Claims
+     */
+    private static Claims getAllClaimsFromToken(String token) {
+        return Jwts.parser()
+                .setSigningKey(SECRET_KEY)
+                .parseClaimsJws(token)
+                .getBody();
+    }
+
+    /**
+     * 检查Token是否已过期
+     * @param token JWT Token
+     * @return 是否过期
+     */
+    private static boolean isTokenExpired(String token) {
+        Date expiration = getAllClaimsFromToken(token).getExpiration();
+        return expiration.before(new Date());
+    }
+
+}

+ 22 - 0
XiaoETech-system/src/main/resources/mapper/system/CouponMapper.xml

@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhentao.system.mapper.CouponMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.system.domain.Coupon">
+            <result property="couponId" column="coupon_id" jdbcType="VARCHAR"/>
+            <result property="userId" column="user_id" jdbcType="VARCHAR"/>
+            <result property="discountAmount" column="discount_amount" jdbcType="DECIMAL"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        coupon_id,user_id,discount_amount
+    </sql>
+    <select id="getOne" resultType="com.zhentao.system.domain.Coupon">
+        select
+        <include refid="Base_Column_List"/>
+        from coupon
+        where coupon_id = #{couponId}
+    </select>
+</mapper>

+ 27 - 0
XiaoETech-system/src/main/resources/mapper/system/OrderDetailMapper.xml

@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhentao.system.mapper.OrderDetailMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.system.domain.OrderDetail">
+            <result property="detailId" column="detail_id" jdbcType="BIGINT"/>
+            <result property="orderId" column="order_id" jdbcType="BIGINT"/>
+            <result property="skuId" column="sku_id" jdbcType="BIGINT"/>
+            <result property="productName" column="product_name" jdbcType="VARCHAR"/>
+            <result property="unitPrice" column="unit_price" jdbcType="DECIMAL"/>
+            <result property="quantity" column="quantity" jdbcType="INTEGER"/>
+            <result property="amount" column="amount" jdbcType="DECIMAL"/>
+            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        detail_id,order_id,sku_id,
+        product_name,unit_price,quantity,
+        amount,create_time
+    </sql>
+    <insert id="save">
+        insert into order_detail (order_id,sku_id,product_name,unit_price,quantity,amount,create_time)
+        values (#{orderId},#{skuId},#{productName},#{unitPrice},#{quantity},#{amount},#{createTime})
+    </insert>
+</mapper>

+ 26 - 0
XiaoETech-system/src/main/resources/mapper/system/OrderMasterMapper.xml

@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhentao.system.mapper.OrderMasterMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.system.domain.OrderMaster">
+            <result property="orderId" column="order_id" jdbcType="VARCHAR"/>
+            <result property="userId" column="user_id" jdbcType="VARCHAR"/>
+            <result property="totalAmount" column="total_amount" jdbcType="DECIMAL"/>
+            <result property="discountAmount" column="discount_amount" jdbcType="DECIMAL"/>
+            <result property="actualAmount" column="actual_amount" jdbcType="DECIMAL"/>
+            <result property="couponId" column="coupon_id" jdbcType="BIGINT"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        order_id,user_id,total_amount,
+        discount_amount,actual_amount,coupon_id
+    </sql>
+    <insert id="save">
+        insert into order_master(order_id,user_id,total_amount,
+        discount_amount,actual_amount,coupon_id)
+        values(#{orderId},#{userId},#{totalAmount},
+        #{discountAmount},#{actualAmount},#{couponId})
+    </insert>
+</mapper>

+ 41 - 0
XiaoETech-system/src/main/resources/mapper/system/ProductSkuMapper.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhentao.system.mapper.ProductSkuMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.system.domain.ProductSku">
+            <result property="skuId" column="sku_id" jdbcType="BIGINT"/>
+            <result property="productId" column="product_id" jdbcType="BIGINT"/>
+            <result property="productName" column="product_name" jdbcType="VARCHAR"/>
+            <result property="unitPrice" column="unit_price" jdbcType="DECIMAL"/>
+            <result property="stock" column="stock" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        sku_id,product_id,product_name,
+        unit_price,stock
+    </sql>
+    <update id="updateById">
+        update product_sku
+        <set>
+            <if test="productId != null">
+                product_id = #{productId},
+            </if>
+            <if test="productName != null">
+                product_name = #{productName},
+            </if>
+            <if test="unitPrice != null">
+                unit_price = #{unitPrice},
+            </if>
+            <if test="stock != null">
+                stock = #{stock},
+            </if>
+        </set>
+        where sku_id = #{skuId}
+    </update>
+    <select id="getOne" resultType="com.zhentao.system.domain.ProductSku">
+        select
+        <include refid="Base_Column_List"/>
+    </select>
+</mapper>

+ 16 - 0
XiaoETech-system/src/main/resources/mapper/system/UserMapper.xml

@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper
+        PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
+        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="com.zhentao.system.mapper.UserMapper">
+
+    <resultMap id="BaseResultMap" type="com.zhentao.system.domain.User">
+            <result property="userId" column="user_id" jdbcType="VARCHAR"/>
+            <result property="username" column="username" jdbcType="VARCHAR"/>
+            <result property="password" column="password" jdbcType="VARCHAR"/>
+    </resultMap>
+
+    <sql id="Base_Column_List">
+        user_id,username,password
+    </sql>
+</mapper>