后端创建订单接口完成;删除service层interface
This commit is contained in:
		
							
								
								
									
										7
									
								
								TODOs.md
									
									
									
									
									
								
							
							
						
						
									
										7
									
								
								TODOs.md
									
									
									
									
									
								
							@@ -32,6 +32,13 @@ rathole.exe ../conf/client.toml
 | 
				
			|||||||
https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html
 | 
					https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/userProfile.html
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					优点:
 | 
				
			||||||
 | 
					订单id使用 雪花id(分布式)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					遇到的问题:
 | 
				
			||||||
 | 
					nacos CPU占满问题,解决方案:提issue,多次测试,找到问题(HTTPDebug),问题解决
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-----
 | 
					-----
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Nacos CPU 跑满问题 我提的 GitHub issue
 | 
					Nacos CPU 跑满问题 我提的 GitHub issue
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,19 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.common.enums;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public enum OrderStatus {
 | 
				
			||||||
 | 
					    PENDING("Pending"),
 | 
				
			||||||
 | 
					    PROCESSING("Processing"),
 | 
				
			||||||
 | 
					    SHIPPED("Shipped"),
 | 
				
			||||||
 | 
					    DELIVERED("Delivered"),
 | 
				
			||||||
 | 
					    CANCELLED("Cancelled");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private final String value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private OrderStatus(String value) {
 | 
				
			||||||
 | 
					        this.value = value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public String getValue() {
 | 
				
			||||||
 | 
					        return value;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -15,6 +15,7 @@ public class Good {
 | 
				
			|||||||
    String gallery;
 | 
					    String gallery;
 | 
				
			||||||
    String brief;
 | 
					    String brief;
 | 
				
			||||||
    Boolean isOnSale;
 | 
					    Boolean isOnSale;
 | 
				
			||||||
 | 
					    Integer sortOrder;
 | 
				
			||||||
    String picUrl;
 | 
					    String picUrl;
 | 
				
			||||||
    Integer type;
 | 
					    Integer type;
 | 
				
			||||||
    String unit;
 | 
					    String unit;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,18 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.common.pojo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.enums.OrderStatus;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import lombok.NoArgsConstructor;
 | 
				
			||||||
 | 
					import lombok.experimental.Accessors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.time.LocalDateTime;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					@NoArgsConstructor
 | 
				
			||||||
 | 
					@Accessors(chain = true) // 链式写法
 | 
				
			||||||
 | 
					public class Order {
 | 
				
			||||||
 | 
					    private Long id;
 | 
				
			||||||
 | 
					    private Integer userId;
 | 
				
			||||||
 | 
					    private LocalDateTime orderDate;
 | 
				
			||||||
 | 
					    private OrderStatus orderStatus;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.common.pojo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import lombok.NoArgsConstructor;
 | 
				
			||||||
 | 
					import lombok.experimental.Accessors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					@NoArgsConstructor
 | 
				
			||||||
 | 
					@Accessors(chain = true) // 链式写法
 | 
				
			||||||
 | 
					public class OrderDetail {
 | 
				
			||||||
 | 
					    private Long id;
 | 
				
			||||||
 | 
					    private Long orderId;
 | 
				
			||||||
 | 
					    private Long goodId;
 | 
				
			||||||
 | 
					    private Integer goodCount;
 | 
				
			||||||
 | 
					    private Double unitPrice;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,85 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.common.utils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.security.SecureRandom;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					public class SnowflakeManager {
 | 
				
			||||||
 | 
					    private static final long EPOCH_STAMP = 1262275200000L;
 | 
				
			||||||
 | 
					    private static final long SEQUENCE_BIT = 12L;
 | 
				
			||||||
 | 
					    private static final long MACHINE_BIT = 5L;
 | 
				
			||||||
 | 
					    private static final long DATA_CENTER_BIT = 5L;
 | 
				
			||||||
 | 
					    private static final long MAX_SEQUENCE_NUM = -1L ^ (-1L << SEQUENCE_BIT);
 | 
				
			||||||
 | 
					    private static final long MAX_MACHINE_NUM = -1L ^ (-1L << MACHINE_BIT);
 | 
				
			||||||
 | 
					    private static final long MAX_DATA_CENTER_NUM = -1L ^ (-1L << DATA_CENTER_BIT);
 | 
				
			||||||
 | 
					    private static final long MACHINE_LEFT = SEQUENCE_BIT;
 | 
				
			||||||
 | 
					    private static final long DATA_CENTER_LEFT = SEQUENCE_BIT + MACHINE_BIT;
 | 
				
			||||||
 | 
					    private static final long TIMESTAMP_LEFT = SEQUENCE_BIT + MACHINE_BIT + DATA_CENTER_BIT;
 | 
				
			||||||
 | 
					    private final long machineId;
 | 
				
			||||||
 | 
					    private final long dataCenterId;
 | 
				
			||||||
 | 
					    private long sequence = 0L;
 | 
				
			||||||
 | 
					    private long lastTimestamp = -1L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public SnowflakeManager(long machineId, long dataCenterId) {
 | 
				
			||||||
 | 
					        if (machineId > MAX_MACHINE_NUM || machineId < 0) {
 | 
				
			||||||
 | 
					            throw new IllegalArgumentException(String.format("machine id can't be greater than %d or less than 0", MAX_MACHINE_NUM));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        if (dataCenterId > MAX_DATA_CENTER_NUM || dataCenterId < 0) {
 | 
				
			||||||
 | 
					            throw new IllegalArgumentException(String.format("data center id can't be greater than %d or less than 0", MAX_DATA_CENTER_NUM));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        this.machineId = machineId;
 | 
				
			||||||
 | 
					        this.dataCenterId = dataCenterId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public synchronized long nextValue() throws Exception {
 | 
				
			||||||
 | 
					        String os = System.getProperty("os.name");
 | 
				
			||||||
 | 
					        SecureRandom secureRandom;
 | 
				
			||||||
 | 
					        if (os.toLowerCase().startsWith("win")) {
 | 
				
			||||||
 | 
					            // windows机器用
 | 
				
			||||||
 | 
					            secureRandom = new SecureRandom(); // SecureRandom.getInstanceStrong();
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            // linux机器用
 | 
				
			||||||
 | 
					            secureRandom = SecureRandom.getInstance("NativePRNGNonBlocking");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        //SecureRandom secureRandom = SecureRandom.getInstanceStrong();
 | 
				
			||||||
 | 
					        long currentTimeMillis = this.currentTimeMillis();
 | 
				
			||||||
 | 
					        if(currentTimeMillis < this.lastTimestamp) {
 | 
				
			||||||
 | 
					            throw new Exception(String.format("Clock moved backwards. Refusing to generate id for %d milliseconds", (this.lastTimestamp-currentTimeMillis)));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if(this.lastTimestamp == currentTimeMillis) {
 | 
				
			||||||
 | 
					            this.sequence = (this.sequence+1) & MAX_SEQUENCE_NUM;
 | 
				
			||||||
 | 
					            if (this.sequence == 0) {
 | 
				
			||||||
 | 
					                this.sequence = secureRandom.nextInt(Long.valueOf(SEQUENCE_BIT).intValue());
 | 
				
			||||||
 | 
					                currentTimeMillis = this.tilNextMillis(this.lastTimestamp);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            this.sequence = secureRandom.nextInt(Long.valueOf(SEQUENCE_BIT).intValue());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        this.lastTimestamp = currentTimeMillis;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 64 Bit ID (42(Millis)+5(Data Center ID)+5(Machine ID)+12(Repeat Sequence Summation))
 | 
				
			||||||
 | 
					        long nextId = ((currentTimeMillis-EPOCH_STAMP) << TIMESTAMP_LEFT)
 | 
				
			||||||
 | 
					                | (this.dataCenterId << DATA_CENTER_LEFT)
 | 
				
			||||||
 | 
					                | (this.machineId << MACHINE_LEFT)
 | 
				
			||||||
 | 
					                | this.sequence;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return nextId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private long tilNextMillis(long lastTimestamp) {
 | 
				
			||||||
 | 
					        long currentTimeMillis = this.currentTimeMillis();
 | 
				
			||||||
 | 
					        while (currentTimeMillis <= lastTimestamp) {
 | 
				
			||||||
 | 
					            currentTimeMillis = this.currentTimeMillis();
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return currentTimeMillis;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private long currentTimeMillis() {
 | 
				
			||||||
 | 
					        return System.currentTimeMillis();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static void main(String[] args) throws Exception {
 | 
				
			||||||
 | 
					        SnowflakeManager snowflakeManager = new SnowflakeManager(0L,0L);
 | 
				
			||||||
 | 
					        long l = snowflakeManager.nextValue();
 | 
				
			||||||
 | 
					        System.out.println(l);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -24,6 +24,7 @@ public class GoodVO implements Serializable {
 | 
				
			|||||||
    String gallery;
 | 
					    String gallery;
 | 
				
			||||||
    String brief;
 | 
					    String brief;
 | 
				
			||||||
    Boolean isOnSale;
 | 
					    Boolean isOnSale;
 | 
				
			||||||
 | 
					    Integer sortOrder;
 | 
				
			||||||
    String picUrl;
 | 
					    String picUrl;
 | 
				
			||||||
    Integer type;
 | 
					    Integer type;
 | 
				
			||||||
    String unit;
 | 
					    String unit;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,40 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.common.vo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.OrderDetail;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import lombok.NoArgsConstructor;
 | 
				
			||||||
 | 
					import lombok.experimental.Accessors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.Serializable;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 数据库关系映射
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					@NoArgsConstructor
 | 
				
			||||||
 | 
					@Accessors(chain = true) // 链式写法
 | 
				
			||||||
 | 
					// 微服务必须要实现Serializable
 | 
				
			||||||
 | 
					public class OrderDetailVO implements Serializable {
 | 
				
			||||||
 | 
					    private Long id;
 | 
				
			||||||
 | 
					    private Long orderId;
 | 
				
			||||||
 | 
					    private Long goodId;
 | 
				
			||||||
 | 
					    private Integer goodCount;
 | 
				
			||||||
 | 
					    private Double unitPrice;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static OrderDetailVO convertFrom(OrderDetail orderDetail) {
 | 
				
			||||||
 | 
					        if (orderDetail == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        OrderDetailVO orderDetailVO = new OrderDetailVO();
 | 
				
			||||||
 | 
					        // BeanUtils.copyProperties(orderDetail, orderDetailVO);
 | 
				
			||||||
 | 
					        return orderDetailVO;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static List<OrderDetailVO> convertFrom(List<OrderDetail> orderDetailList) {
 | 
				
			||||||
 | 
					        if (orderDetailList == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        return orderDetailList.stream().map(OrderDetailVO::convertFrom).collect(Collectors.toList());
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -0,0 +1,44 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.common.vo;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.enums.OrderStatus;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.Order;
 | 
				
			||||||
 | 
					import lombok.Data;
 | 
				
			||||||
 | 
					import lombok.NoArgsConstructor;
 | 
				
			||||||
 | 
					import lombok.experimental.Accessors;
 | 
				
			||||||
 | 
					import org.springframework.beans.BeanUtils;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.Serializable;
 | 
				
			||||||
 | 
					import java.time.LocalDate;
 | 
				
			||||||
 | 
					import java.time.LocalDateTime;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					import java.util.stream.Collectors;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// 数据库关系映射
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					@NoArgsConstructor
 | 
				
			||||||
 | 
					@Accessors(chain = true) // 链式写法
 | 
				
			||||||
 | 
					// 微服务必须要实现Serializable
 | 
				
			||||||
 | 
					public class OrderVO implements Serializable {
 | 
				
			||||||
 | 
					    private Long id;
 | 
				
			||||||
 | 
					    private Integer userId;
 | 
				
			||||||
 | 
					    private LocalDateTime orderDate;
 | 
				
			||||||
 | 
					    private OrderStatus orderStatus;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static OrderVO convertFrom(Order order) {
 | 
				
			||||||
 | 
					        if (order == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        OrderVO orderVO = new OrderVO();
 | 
				
			||||||
 | 
					        BeanUtils.copyProperties(order, orderVO);
 | 
				
			||||||
 | 
					        return orderVO;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public static List<OrderVO> convertFrom(List<Order> orderList) {
 | 
				
			||||||
 | 
					        if (orderList == null) {
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        List<OrderVO> goodsOrdersVOList = orderList.stream().map(OrderVO::convertFrom).collect(Collectors.toList());
 | 
				
			||||||
 | 
					        return goodsOrdersVOList;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -13,8 +13,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    <properties>
 | 
					    <properties>
 | 
				
			||||||
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
					        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 | 
				
			||||||
        <maven.compiler.source>1.7</maven.compiler.source>
 | 
					        <maven.compiler.source>11</maven.compiler.source>
 | 
				
			||||||
        <maven.compiler.target>1.7</maven.compiler.target>
 | 
					        <maven.compiler.target>11</maven.compiler.target>
 | 
				
			||||||
    </properties>
 | 
					    </properties>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <dependencies>
 | 
					    <dependencies>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,7 +3,7 @@ package com.cxyxiaomo.epp.shop.controller;
 | 
				
			|||||||
import com.cxyxiaomo.epp.common.response.Res;
 | 
					import com.cxyxiaomo.epp.common.response.Res;
 | 
				
			||||||
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
 | 
					import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
 | 
				
			||||||
import com.cxyxiaomo.epp.common.vo.GoodVO;
 | 
					import com.cxyxiaomo.epp.common.vo.GoodVO;
 | 
				
			||||||
import com.cxyxiaomo.epp.shop.service.GoodsServiceImpl;
 | 
					import com.cxyxiaomo.epp.shop.service.GoodsService;
 | 
				
			||||||
import org.springframework.web.bind.annotation.GetMapping;
 | 
					import org.springframework.web.bind.annotation.GetMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
					import org.springframework.web.bind.annotation.RequestParam;
 | 
				
			||||||
@@ -17,7 +17,7 @@ import java.util.List;
 | 
				
			|||||||
public class GoodsController {
 | 
					public class GoodsController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Resource
 | 
					    @Resource
 | 
				
			||||||
    GoodsServiceImpl goodsService;
 | 
					    GoodsService goodsService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * 小程序端商品列表
 | 
					     * 小程序端商品列表
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,72 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.shop.controller;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.alibaba.fastjson2.JSONArray;
 | 
				
			||||||
 | 
					import com.alibaba.fastjson2.JSONObject;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.OrderDetail;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.response.Res;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.shop.service.OrderService;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Resource;
 | 
				
			||||||
 | 
					import java.util.LinkedList;
 | 
				
			||||||
 | 
					import java.util.Map;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@RestController
 | 
				
			||||||
 | 
					@RequestMapping("/shop/order")
 | 
				
			||||||
 | 
					public class OrderController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Resource
 | 
				
			||||||
 | 
					    OrderService orderService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 小程序端创建订单
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param userId    下单用户
 | 
				
			||||||
 | 
					     * @param orderList 下单商品 [ { goodId, count }, ... ]
 | 
				
			||||||
 | 
					     * @param orderList 下单商品 [ { goodId, count }, ... ]
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @PostMapping("/miniprogram/createOrder")
 | 
				
			||||||
 | 
					    @ResponseBody
 | 
				
			||||||
 | 
					    public Res createOrder(@RequestBody JSONObject params) {
 | 
				
			||||||
 | 
					        Integer userId = params.getInteger("userId");
 | 
				
			||||||
 | 
					        JSONArray orderList = params.getJSONArray("orderList");
 | 
				
			||||||
 | 
					        if (userId == null || orderList == null) {
 | 
				
			||||||
 | 
					            return Res.error("参数错误");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        LinkedList<OrderDetail> orderDetailList = new LinkedList<>();
 | 
				
			||||||
 | 
					        for (Object o : orderList) {
 | 
				
			||||||
 | 
					            if (o == null || o instanceof JSONObject) {
 | 
				
			||||||
 | 
					                return Res.error("参数错误");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            JSONObject order = new JSONObject((Map) o);
 | 
				
			||||||
 | 
					            Long goodId = order.getLong("goodId");
 | 
				
			||||||
 | 
					            Integer count = order.getInteger("count");
 | 
				
			||||||
 | 
					            if (goodId == null || goodId < 1 || count == null || count < 1) {
 | 
				
			||||||
 | 
					                return Res.error("参数错误");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            OrderDetail orderDetail = new OrderDetail();
 | 
				
			||||||
 | 
					            orderDetail.setGoodId(goodId);
 | 
				
			||||||
 | 
					            orderDetail.setGoodCount(count);
 | 
				
			||||||
 | 
					            orderDetailList.add(orderDetail);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (orderDetailList.size() == 0) {
 | 
				
			||||||
 | 
					            return Res.error("订单中不包含商品,不能创建空订单");
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        try {
 | 
				
			||||||
 | 
					            long orderId = orderService.createOrder(userId, orderDetailList);
 | 
				
			||||||
 | 
					            return Res.success(orderId);
 | 
				
			||||||
 | 
					        } catch (Exception e) {
 | 
				
			||||||
 | 
					            String message = e.getMessage();
 | 
				
			||||||
 | 
					            if (message.contains("Exception")) {
 | 
				
			||||||
 | 
					                // 内部异常不打印出去
 | 
				
			||||||
 | 
					                return Res.error("创建订单失败,请重试");
 | 
				
			||||||
 | 
					            } else {
 | 
				
			||||||
 | 
					                return Res.error(message);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -14,4 +14,12 @@ public interface GoodsDao {
 | 
				
			|||||||
    List<Good> list(@Param("cateId") Integer cateId, @Param("searchText") String searchText);
 | 
					    List<Good> list(@Param("cateId") Integer cateId, @Param("searchText") String searchText);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Good getById(Long id);
 | 
					    Good getById(Long id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Good selectById(Long id);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Integer insert(Good good);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Integer update(Good good);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Integer deleteById(Integer id);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,52 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.shop.dao;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.Order;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.OrderDetail;
 | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Mapper;
 | 
				
			||||||
 | 
					import org.apache.ibatis.annotations.Param;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Repository;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Mapper
 | 
				
			||||||
 | 
					@Repository
 | 
				
			||||||
 | 
					public interface OrderDao {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 根据订单 ID 查询订单信息
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param orderId
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    Order getOrderById(Integer orderId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 根据用户 ID 查询订单列表
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param userId
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    List<Order> listOrdersByUserId(Integer userId);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 创建订单
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param order
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    int insertOrder(Order order);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 批量插入订单详情
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param details
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    int batchInsertOrderDetail(List<OrderDetail> details);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 更新订单状态
 | 
				
			||||||
 | 
					    int updateOrderStatus(@Param("orderId") Integer orderId, @Param("status") String status);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // 根据订单 ID 删除订单信息及订单详情信息
 | 
				
			||||||
 | 
					    int deleteOrderById(Integer orderId);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -1,15 +1,40 @@
 | 
				
			|||||||
package com.cxyxiaomo.epp.shop.service;
 | 
					package com.cxyxiaomo.epp.shop.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.Good;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.GoodCategory;
 | 
				
			||||||
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
 | 
					import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
 | 
				
			||||||
import com.cxyxiaomo.epp.common.vo.GoodVO;
 | 
					import com.cxyxiaomo.epp.common.vo.GoodVO;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.shop.dao.GoodsCategoryDao;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.shop.dao.GoodsDao;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Resource;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public interface GoodsService {
 | 
					@Service
 | 
				
			||||||
 | 
					public class GoodsService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    List<GoodVO> list(Integer cateId, String searchText);
 | 
					    @Resource
 | 
				
			||||||
 | 
					    GoodsDao goodsDao;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    GoodVO getById(Long id);
 | 
					    @Resource
 | 
				
			||||||
 | 
					    GoodsCategoryDao goodsCategoryDao;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    List<GoodCategoryVO> cateList();
 | 
					    public List<GoodVO> list(Integer cateId, String searchText) {
 | 
				
			||||||
 | 
					        List<Good> list = goodsDao.list(cateId, searchText);
 | 
				
			||||||
 | 
					        List<GoodVO> goodVOS = GoodVO.convertFrom(list);
 | 
				
			||||||
 | 
					        return goodVOS;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public GoodVO getById(Long id) {
 | 
				
			||||||
 | 
					        Good good = goodsDao.getById(id);
 | 
				
			||||||
 | 
					        GoodVO goodVO = GoodVO.convertFrom(good);
 | 
				
			||||||
 | 
					        return goodVO;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public List<GoodCategoryVO> cateList() {
 | 
				
			||||||
 | 
					        List<GoodCategory> list = goodsCategoryDao.list();
 | 
				
			||||||
 | 
					        List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(list);
 | 
				
			||||||
 | 
					        return goodCategoryVOList;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,43 +0,0 @@
 | 
				
			|||||||
package com.cxyxiaomo.epp.shop.service;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import com.cxyxiaomo.epp.common.pojo.Good;
 | 
					 | 
				
			||||||
import com.cxyxiaomo.epp.common.pojo.GoodCategory;
 | 
					 | 
				
			||||||
import com.cxyxiaomo.epp.common.vo.GoodCategoryVO;
 | 
					 | 
				
			||||||
import com.cxyxiaomo.epp.common.vo.GoodVO;
 | 
					 | 
				
			||||||
import com.cxyxiaomo.epp.shop.dao.GoodsCategoryDao;
 | 
					 | 
				
			||||||
import com.cxyxiaomo.epp.shop.dao.GoodsDao;
 | 
					 | 
				
			||||||
import org.springframework.stereotype.Service;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
import javax.annotation.Resource;
 | 
					 | 
				
			||||||
import java.util.List;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
@Service
 | 
					 | 
				
			||||||
public class GoodsServiceImpl implements GoodsService {
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Resource
 | 
					 | 
				
			||||||
    GoodsDao goodsDao;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Resource
 | 
					 | 
				
			||||||
    GoodsCategoryDao goodsCategoryDao;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<GoodVO> list(Integer cateId, String searchText) {
 | 
					 | 
				
			||||||
        List<Good> list = goodsDao.list(cateId, searchText);
 | 
					 | 
				
			||||||
        List<GoodVO> goodVOS = GoodVO.convertFrom(list);
 | 
					 | 
				
			||||||
        return goodVOS;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public GoodVO getById(Long id) {
 | 
					 | 
				
			||||||
        Good good = goodsDao.getById(id);
 | 
					 | 
				
			||||||
        GoodVO goodVO = GoodVO.convertFrom(good);
 | 
					 | 
				
			||||||
        return goodVO;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					 | 
				
			||||||
    public List<GoodCategoryVO> cateList() {
 | 
					 | 
				
			||||||
        List<GoodCategory> list = goodsCategoryDao.list();
 | 
					 | 
				
			||||||
        List<GoodCategoryVO> goodCategoryVOList = GoodCategoryVO.convertFrom(list);
 | 
					 | 
				
			||||||
        return goodCategoryVOList;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
@@ -0,0 +1,71 @@
 | 
				
			|||||||
 | 
					package com.cxyxiaomo.epp.shop.service;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.enums.OrderStatus;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.Good;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.Order;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.pojo.OrderDetail;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.common.utils.SnowflakeManager;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.shop.dao.GoodsDao;
 | 
				
			||||||
 | 
					import com.cxyxiaomo.epp.shop.dao.OrderDao;
 | 
				
			||||||
 | 
					import org.springframework.stereotype.Service;
 | 
				
			||||||
 | 
					import org.springframework.transaction.annotation.Transactional;
 | 
				
			||||||
 | 
					import org.springframework.transaction.interceptor.TransactionAspectSupport;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import javax.annotation.Resource;
 | 
				
			||||||
 | 
					import java.time.LocalDateTime;
 | 
				
			||||||
 | 
					import java.util.List;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@Service
 | 
				
			||||||
 | 
					public class OrderService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Resource
 | 
				
			||||||
 | 
					    private GoodsDao goodsDao;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Resource
 | 
				
			||||||
 | 
					    private OrderDao orderDao;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /**
 | 
				
			||||||
 | 
					     * 创建订单,返回订单编号
 | 
				
			||||||
 | 
					     *
 | 
				
			||||||
 | 
					     * @param userId
 | 
				
			||||||
 | 
					     * @param orderItemList
 | 
				
			||||||
 | 
					     * @return
 | 
				
			||||||
 | 
					     * @throws Exception
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					    @Transactional(rollbackFor = Exception.class)
 | 
				
			||||||
 | 
					    public long createOrder(int userId, List<OrderDetail> orderItemList) throws Exception {
 | 
				
			||||||
 | 
					        // 创建订单编号
 | 
				
			||||||
 | 
					        SnowflakeManager snowflakeManager = new SnowflakeManager(1L, 1L);
 | 
				
			||||||
 | 
					        long orderId = snowflakeManager.nextValue();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 创建订单
 | 
				
			||||||
 | 
					        Order order = new Order();
 | 
				
			||||||
 | 
					        order.setId(orderId);
 | 
				
			||||||
 | 
					        order.setUserId(userId);
 | 
				
			||||||
 | 
					        order.setOrderDate(LocalDateTime.now());
 | 
				
			||||||
 | 
					        order.setOrderStatus(OrderStatus.PENDING);
 | 
				
			||||||
 | 
					        orderDao.insertOrder(order);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        // 创建订单详情
 | 
				
			||||||
 | 
					        for (OrderDetail orderItem : orderItemList) {
 | 
				
			||||||
 | 
					            if (orderItem == null || orderItem.getGoodId() == null || orderItem.getGoodCount() == null) {
 | 
				
			||||||
 | 
					                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
 | 
				
			||||||
 | 
					                throw new IllegalArgumentException("商品不存在");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 查询商品价格
 | 
				
			||||||
 | 
					            Good good = goodsDao.selectById(orderItem.getGoodId());
 | 
				
			||||||
 | 
					            if (good == null || good.getDeleted() || good.getRetailPrice() == null) {
 | 
				
			||||||
 | 
					                throw new IllegalArgumentException("商品已删除或状态异常,无法下单");
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            Double retailPrice = good.getRetailPrice();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            // 手动塞入信息
 | 
				
			||||||
 | 
					            orderItem.setId(null);
 | 
				
			||||||
 | 
					            orderItem.setOrderId(orderId);
 | 
				
			||||||
 | 
					            orderItem.setUnitPrice(retailPrice);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        orderDao.batchInsertOrderDetail(orderItemList);
 | 
				
			||||||
 | 
					        return orderId;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -21,3 +21,8 @@ spring:
 | 
				
			|||||||
    url: jdbc:mysql://127.0.0.1:3306/epp?useUnicode=true&characterEncoding=utf8&useSSL=false
 | 
					    url: jdbc:mysql://127.0.0.1:3306/epp?useUnicode=true&characterEncoding=utf8&useSSL=false
 | 
				
			||||||
    username: root
 | 
					    username: root
 | 
				
			||||||
    password: root
 | 
					    password: root
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					logging:
 | 
				
			||||||
 | 
					  level:
 | 
				
			||||||
 | 
					    org.mybatis.spring.SqlSessionFactoryBean: DEBUG
 | 
				
			||||||
 | 
					    # org.mybatis.spring.SqlSessionFactoryBean: TRACE
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,24 @@
 | 
				
			|||||||
        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 | 
					        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 | 
				
			||||||
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
					        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
				
			||||||
<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodsDao">
 | 
					<mapper namespace="com.cxyxiaomo.epp.shop.dao.GoodsDao">
 | 
				
			||||||
 | 
					    <resultMap id="GoodsResultMap" type="com.cxyxiaomo.epp.common.pojo.Good">
 | 
				
			||||||
 | 
					        <id column="id" property="id" />
 | 
				
			||||||
 | 
					        <result column="goods_name" property="goodsName" />
 | 
				
			||||||
 | 
					        <result column="category_id" property="categoryId" />
 | 
				
			||||||
 | 
					        <result column="brand" property="brand" />
 | 
				
			||||||
 | 
					        <result column="gallery" property="gallery" />
 | 
				
			||||||
 | 
					        <result column="brief" property="brief" />
 | 
				
			||||||
 | 
					        <result column="is_on_sale" property="isOnSale" />
 | 
				
			||||||
 | 
					        <result column="sort_order" property="sortOrder" />
 | 
				
			||||||
 | 
					        <result column="pic_url" property="picUrl" />
 | 
				
			||||||
 | 
					        <result column="type" property="type" />
 | 
				
			||||||
 | 
					        <result column="unit" property="unit" />
 | 
				
			||||||
 | 
					        <result column="counter_price" property="counterPrice" />
 | 
				
			||||||
 | 
					        <result column="retail_price" property="retailPrice" />
 | 
				
			||||||
 | 
					        <result column="detail" property="detail" />
 | 
				
			||||||
 | 
					        <result column="deleted" property="deleted" />
 | 
				
			||||||
 | 
					    </resultMap>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <!--<insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good">-->
 | 
					    <!--<insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good">-->
 | 
				
			||||||
    <!--    INSERT INTO report (`user_id`, `name`, `address`, `time`, `temperature`)-->
 | 
					    <!--    INSERT INTO report (`user_id`, `name`, `address`, `time`, `temperature`)-->
 | 
				
			||||||
    <!--    VALUES (#{userId}, #{name}, #{address}, #{time}, #{temperature})-->
 | 
					    <!--    VALUES (#{userId}, #{name}, #{address}, #{time}, #{temperature})-->
 | 
				
			||||||
@@ -25,4 +43,50 @@
 | 
				
			|||||||
        WHERE id = #{id}
 | 
					        WHERE id = #{id}
 | 
				
			||||||
        order by `sort_order` asc
 | 
					        order by `sort_order` asc
 | 
				
			||||||
    </select>
 | 
					    </select>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <select id="selectById" resultMap="GoodsResultMap">
 | 
				
			||||||
 | 
					        SELECT *
 | 
				
			||||||
 | 
					        FROM goods
 | 
				
			||||||
 | 
					        WHERE id = #{id}
 | 
				
			||||||
 | 
					    </select>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!--<select id="selectByCategoryId" resultMap="GoodsResultMap">-->
 | 
				
			||||||
 | 
					    <!--    SELECT *-->
 | 
				
			||||||
 | 
					    <!--    FROM goods-->
 | 
				
			||||||
 | 
					    <!--    WHERE category_id = #{categoryId}-->
 | 
				
			||||||
 | 
					    <!--</select>-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!--<select id="selectAll" resultMap="GoodsResultMap">-->
 | 
				
			||||||
 | 
					    <!--    SELECT *-->
 | 
				
			||||||
 | 
					    <!--    FROM goods-->
 | 
				
			||||||
 | 
					    <!--</select>-->
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <insert id="insert" parameterType="com.cxyxiaomo.epp.common.pojo.Good" useGeneratedKeys="true" keyProperty="id">
 | 
				
			||||||
 | 
					        INSERT INTO goods (goods_name, category_id, brand, gallery, brief, is_on_sale, sort_order, pic_url, type, unit, counter_price, retail_price, detail, deleted)
 | 
				
			||||||
 | 
					        VALUES (#{goodsName}, #{categoryId}, #{brand}, #{gallery}, #{brief}, #{isOnSale}, #{sortOrder}, #{picUrl}, #{type}, #{unit}, #{counterPrice}, #{retailPrice}, #{detail}, #{deleted})
 | 
				
			||||||
 | 
					    </insert>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <update id="update" parameterType="com.cxyxiaomo.epp.common.pojo.Good">
 | 
				
			||||||
 | 
					        UPDATE goods
 | 
				
			||||||
 | 
					        SET goods_name = #{goodsName},
 | 
				
			||||||
 | 
					            category_id = #{categoryId},
 | 
				
			||||||
 | 
					            brand = #{brand},
 | 
				
			||||||
 | 
					            gallery = #{gallery},
 | 
				
			||||||
 | 
					            brief = #{brief},
 | 
				
			||||||
 | 
					            is_on_sale = #{isOnSale},
 | 
				
			||||||
 | 
					            sort_order = #{sortOrder},
 | 
				
			||||||
 | 
					            pic_url = #{picUrl},
 | 
				
			||||||
 | 
					            type = #{type},
 | 
				
			||||||
 | 
					            unit = #{unit},
 | 
				
			||||||
 | 
					            counter_price = #{counterPrice},
 | 
				
			||||||
 | 
					            retail_price = #{retailPrice},
 | 
				
			||||||
 | 
					            detail = #{detail},
 | 
				
			||||||
 | 
					            deleted = #{deleted}
 | 
				
			||||||
 | 
					        WHERE id = #{id}
 | 
				
			||||||
 | 
					    </update>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <delete id="deleteById">
 | 
				
			||||||
 | 
					        DELETE FROM goods
 | 
				
			||||||
 | 
					        WHERE id = #{id}
 | 
				
			||||||
 | 
					    </delete>
 | 
				
			||||||
</mapper>
 | 
					</mapper>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -0,0 +1,62 @@
 | 
				
			|||||||
 | 
					<?xml version="1.0" encoding="UTF-8" ?>
 | 
				
			||||||
 | 
					<!DOCTYPE mapper
 | 
				
			||||||
 | 
					        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
 | 
				
			||||||
 | 
					        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 | 
				
			||||||
 | 
					<mapper namespace="com.cxyxiaomo.epp.shop.dao.OrderDao">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <resultMap id="OrderResultMap" type="com.cxyxiaomo.epp.common.pojo.Order">
 | 
				
			||||||
 | 
					        <id column="id" property="id"/>
 | 
				
			||||||
 | 
					        <result column="user_id" property="userId"/>
 | 
				
			||||||
 | 
					        <result column="order_date" property="orderDate"/>
 | 
				
			||||||
 | 
					        <result column="order_status" property="orderStatus"/>
 | 
				
			||||||
 | 
					    </resultMap>
 | 
				
			||||||
 | 
					    <resultMap id="OrderDetailResultMap" type="com.cxyxiaomo.epp.common.pojo.OrderDetail">
 | 
				
			||||||
 | 
					        <id property="id" column="id" />
 | 
				
			||||||
 | 
					        <result property="orderId" column="order_id" />
 | 
				
			||||||
 | 
					        <result property="goodId" column="good_id" />
 | 
				
			||||||
 | 
					        <result property="goodCount" column="good_count" />
 | 
				
			||||||
 | 
					        <result property="unitPrice" column="unit_price" />
 | 
				
			||||||
 | 
					    </resultMap>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- 根据订单 ID 查询订单信息 -->
 | 
				
			||||||
 | 
					    <select id="getOrderById" resultMap="OrderResultMap">
 | 
				
			||||||
 | 
					        SELECT * FROM order WHERE order_id=#{orderId}
 | 
				
			||||||
 | 
					    </select>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- 根据用户 ID 查询订单列表 -->
 | 
				
			||||||
 | 
					    <select id="listOrdersByUserId" resultType="com.cxyxiaomo.epp.common.pojo.Order">
 | 
				
			||||||
 | 
					        SELECT *
 | 
				
			||||||
 | 
					        FROM order
 | 
				
			||||||
 | 
					        WHERE user_id = #{userId}
 | 
				
			||||||
 | 
					    </select>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- 创建订单 -->
 | 
				
			||||||
 | 
					    <insert id="insertOrder" parameterType="com.cxyxiaomo.epp.common.pojo.Order" useGeneratedKeys="true" keyProperty="orderId">
 | 
				
			||||||
 | 
					        INSERT INTO `order` (id, user_id, order_date, order_status) VALUES
 | 
				
			||||||
 | 
					            (#{id}, #{userId}, #{orderDate,javaType=java.time.LocalDateTime,jdbcType=TIMESTAMP}, #{orderStatus})
 | 
				
			||||||
 | 
					    </insert>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- 批量插入订单详情 -->
 | 
				
			||||||
 | 
					    <insert id="batchInsertOrderDetail" parameterType="java.util.List">
 | 
				
			||||||
 | 
					        INSERT INTO order_detail (order_id, good_id, good_count, unit_price)
 | 
				
			||||||
 | 
					        VALUES
 | 
				
			||||||
 | 
					        <if test="list != null and list.size() > 0">
 | 
				
			||||||
 | 
					            <foreach collection="list" item="detail" separator=",">
 | 
				
			||||||
 | 
					                (#{detail.orderId}, #{detail.goodId}, #{detail.goodCount}, #{detail.unitPrice})
 | 
				
			||||||
 | 
					            </foreach>
 | 
				
			||||||
 | 
					        </if>
 | 
				
			||||||
 | 
					        <if test="list == null or list.size() == 0">
 | 
				
			||||||
 | 
					            ()
 | 
				
			||||||
 | 
					        </if>
 | 
				
			||||||
 | 
					    </insert>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <update id="updateOrderStatus" parameterType="com.cxyxiaomo.epp.common.pojo.Order">
 | 
				
			||||||
 | 
					        UPDATE order SET order_status=#{orderStatus} WHERE order_id=#{orderId}
 | 
				
			||||||
 | 
					    </update>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <!-- 根据订单 ID 删除订单信息及订单详情信息 -->
 | 
				
			||||||
 | 
					    <delete id="deleteOrderById" parameterType="java.lang.Integer">
 | 
				
			||||||
 | 
					        DELETE FROM order WHERE order_id = #{orderId};
 | 
				
			||||||
 | 
					        DELETE FROM goods_order_details WHERE order_id = #{orderId};
 | 
				
			||||||
 | 
					    </delete>
 | 
				
			||||||
 | 
					</mapper>
 | 
				
			||||||
@@ -9,5 +9,9 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        <!--下划线转小驼峰-->
 | 
					        <!--下划线转小驼峰-->
 | 
				
			||||||
        <setting name="mapUnderscoreToCamelCase" value="true"/>
 | 
					        <setting name="mapUnderscoreToCamelCase" value="true"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <!-- 打印 SQL 日志  -->
 | 
				
			||||||
 | 
					        <!-- 设置logImpl为STDOUT_LOGGING,表示使用标准输出打印SQL日志 -->
 | 
				
			||||||
 | 
					        <setting name="logImpl" value="STDOUT_LOGGING"/>
 | 
				
			||||||
    </settings>
 | 
					    </settings>
 | 
				
			||||||
</configuration>
 | 
					</configuration>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -11,7 +11,7 @@
 | 
				
			|||||||
 Target Server Version : 80012
 | 
					 Target Server Version : 80012
 | 
				
			||||||
 File Encoding         : 65001
 | 
					 File Encoding         : 65001
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 Date: 19/03/2023 01:32:37
 | 
					 Date: 19/03/2023 17:36:14
 | 
				
			||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SET NAMES utf8mb4;
 | 
					SET NAMES utf8mb4;
 | 
				
			||||||
@@ -174,35 +174,35 @@ INSERT INTO `goods` VALUES (55, '百事可乐', 7, '百事公司', '[]', '百事
 | 
				
			|||||||
INSERT INTO `goods` VALUES (56, '康师傅冰红茶', 7, '康师傅集团', '[]', '康师傅冰红茶', 1, 98, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 4.00, 2.50, '康师傅冰红茶是一种深受广大消费者喜爱的茶饮料,口感香甜,清新解渴。康师傅是中国著名的食品生产企业,其产品包括方便面、速冻食品、饮料等。', 0);
 | 
					INSERT INTO `goods` VALUES (56, '康师傅冰红茶', 7, '康师傅集团', '[]', '康师傅冰红茶', 1, 98, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 4.00, 2.50, '康师傅冰红茶是一种深受广大消费者喜爱的茶饮料,口感香甜,清新解渴。康师傅是中国著名的食品生产企业,其产品包括方便面、速冻食品、饮料等。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (57, '怡宝矿泉水', 7, '怡宝集团', '[]', '怡宝矿泉水', 1, 97, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 3.00, 2.00, '怡宝矿泉水是一种天然的矿泉水,口感清新,无任何添加剂,非常适合日常饮用。怡宝集团是中国知名的饮料生产企业,其产品包括矿泉水、纯净水、茶饮料等。', 0);
 | 
					INSERT INTO `goods` VALUES (57, '怡宝矿泉水', 7, '怡宝集团', '[]', '怡宝矿泉水', 1, 97, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 3.00, 2.00, '怡宝矿泉水是一种天然的矿泉水,口感清新,无任何添加剂,非常适合日常饮用。怡宝集团是中国知名的饮料生产企业,其产品包括矿泉水、纯净水、茶饮料等。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (58, '沐浴露', 2, '施巴', '[]', '施巴舒缓滋润沐浴露', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 49.90, 39.90, '施巴舒缓滋润沐浴露,富含甘油和天然植物精华,能够滋润肌肤', 0);
 | 
					INSERT INTO `goods` VALUES (58, '沐浴露', 2, '施巴', '[]', '施巴舒缓滋润沐浴露', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 49.90, 39.90, '施巴舒缓滋润沐浴露,富含甘油和天然植物精华,能够滋润肌肤', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (59, '洗衣液', 2, '威露士', '[]', '威露士洗衣液', 1, 100, NULL, 0, '瓶', 25.00, 29.90, '威露士洗衣液,洁净彻底,去除顽渍,衣物柔软舒适。适用于各种布料。', 0);
 | 
					INSERT INTO `goods` VALUES (59, '洗衣液', 2, '威露士', '[]', '威露士洗衣液', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 25.00, 29.90, '威露士洗衣液,洁净彻底,去除顽渍,衣物柔软舒适。适用于各种布料。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (60, '洗碗布', 2, '无品牌', '[]', '柔软吸水,耐用不掉毛', 1, 100, NULL, 0, '个', 3.00, 5.00, '适用于洗涤餐具、清洁厨房等', 0);
 | 
					INSERT INTO `goods` VALUES (60, '洗碗布', 2, '无品牌', '[]', '柔软吸水,耐用不掉毛', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '个', 3.00, 5.00, '适用于洗涤餐具、清洁厨房等', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (61, '一次性餐具套装', 2, '无品牌', '[]', '一次性餐具套装,方便卫生', 1, 99, NULL, 0, '套', 8.00, 12.00, '包含一次性碗、盘、刀、叉、勺等,使用后方便清理,卫生方便', 0);
 | 
					INSERT INTO `goods` VALUES (61, '一次性餐具套装', 2, '无品牌', '[]', '一次性餐具套装,方便卫生', 1, 99, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '套', 8.00, 12.00, '包含一次性碗、盘、刀、叉、勺等,使用后方便清理,卫生方便', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (62, '剃须刀', 2, '飞利浦', '[]', '飞利浦电动剃须刀,充电式', 1, 80, NULL, 0, '个', 199.00, 299.00, '适用于男性剃须,充电式方便携带,刀片锋利,剃须干净', 0);
 | 
					INSERT INTO `goods` VALUES (62, '剃须刀', 2, '飞利浦', '[]', '飞利浦电动剃须刀,充电式', 1, 80, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '个', 199.00, 299.00, '适用于男性剃须,充电式方便携带,刀片锋利,剃须干净', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (63, '马桶刷', 2, '无品牌', '[]', '马桶清洁必备,柄部防滑设计', 1, 150, NULL, 0, '个', 5.00, 9.90, '适用于马桶清洁,柄部采用防滑设计,方便操作', 0);
 | 
					INSERT INTO `goods` VALUES (63, '马桶刷', 2, '无品牌', '[]', '马桶清洁必备,柄部防滑设计', 1, 150, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '个', 5.00, 9.90, '适用于马桶清洁,柄部采用防滑设计,方便操作', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (64, '抽纸', 2, '维达', '[]', '维达软抽3层130抽面纸', 1, 50, NULL, 0, '包', 14.50, 18.00, '适用于日常生活,柔软舒适,吸水性好,可重复使用', 0);
 | 
					INSERT INTO `goods` VALUES (64, '抽纸', 2, '维达', '[]', '维达软抽3层130抽面纸', 1, 50, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '包', 14.50, 18.00, '适用于日常生活,柔软舒适,吸水性好,可重复使用', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (65, '剪刀', 2, '晨光', '[]', '晨光不锈钢剪刀', 1, 120, NULL, 0, '把', 9.90, 12.00, '适用于日常生活、办公等,剪刀锋利,手感舒适', 0);
 | 
					INSERT INTO `goods` VALUES (65, '剪刀', 2, '晨光', '[]', '晨光不锈钢剪刀', 1, 120, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '把', 9.90, 12.00, '适用于日常生活、办公等,剪刀锋利,手感舒适', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (66, '防晒霜', 2, '兰蔻', '[]', '兰蔻防晒霜SPF50+', 1, 60, NULL, 0, '瓶', 299.00, 399.00, '适用于户外活动、日常生活等,有效防止紫外线伤害,清爽不油腻,易于吸收', 0);
 | 
					INSERT INTO `goods` VALUES (66, '防晒霜', 2, '兰蔻', '[]', '兰蔻防晒霜SPF50+', 1, 60, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 299.00, 399.00, '适用于户外活动、日常生活等,有效防止紫外线伤害,清爽不油腻,易于吸收', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (67, '纸巾盒', 2, '普乐士', '[]', '普乐士魔法盒抽纸盒', 1, 100, NULL, 0, '个', 12.50, 15.00, '', 0);
 | 
					INSERT INTO `goods` VALUES (67, '纸巾盒', 2, '普乐士', '[]', '普乐士魔法盒抽纸盒', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '个', 12.50, 15.00, '', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (68, '洗洁精', 2, '威露士', '[]', '威露士洗洁精', 1, 100, NULL, 0, '瓶', 9.99, 12.99, '威露士洗洁精,有效去除油渍和污垢,轻松清洁厨房餐具。', 0);
 | 
					INSERT INTO `goods` VALUES (68, '洗洁精', 2, '威露士', '[]', '威露士洗洁精', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 9.99, 12.99, '威露士洗洁精,有效去除油渍和污垢,轻松清洁厨房餐具。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (69, '洗手液', 2, '蜜芽', '[]', '蜜芽儿童无刺激洗手液', 1, 99, NULL, 0, '瓶', 19.99, 22.99, '蜜芽儿童无刺激洗手液,温和配方,不刺激肌肤,适合儿童使用。', 0);
 | 
					INSERT INTO `goods` VALUES (69, '洗手液', 2, '蜜芽', '[]', '蜜芽儿童无刺激洗手液', 1, 99, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 19.99, 22.99, '蜜芽儿童无刺激洗手液,温和配方,不刺激肌肤,适合儿童使用。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (70, '电动牙刷', 2, '飞利浦', '[]', '飞利浦声波震动电动牙刷', 1, 98, NULL, 0, '支', 299.00, 399.00, '飞利浦声波震动电动牙刷,高效清洁牙齿,深入去除牙渍,呵护牙齿健康。', 0);
 | 
					INSERT INTO `goods` VALUES (70, '电动牙刷', 2, '飞利浦', '[]', '飞利浦声波震动电动牙刷', 1, 98, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '支', 299.00, 399.00, '飞利浦声波震动电动牙刷,高效清洁牙齿,深入去除牙渍,呵护牙齿健康。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (71, '梳子', 2, '宝洁', '[]', '宝洁双面按摩梳', 1, 97, NULL, 0, '把', 12.99, 15.99, '宝洁双面按摩梳,双面设计,可以按摩头皮,缓解疲劳,也可以梳理发丝,让发型更加完美。', 0);
 | 
					INSERT INTO `goods` VALUES (71, '梳子', 2, '宝洁', '[]', '宝洁双面按摩梳', 1, 97, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '把', 12.99, 15.99, '宝洁双面按摩梳,双面设计,可以按摩头皮,缓解疲劳,也可以梳理发丝,让发型更加完美。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (72, '洗衣液', 2, '妙洁', '[]', '妙洁深层洁净洗衣液', 1, 96, NULL, 0, '瓶', 29.99, 39.99, '妙洁深层洁净洗衣液,有效去除衣物污渍,保护衣物纤维,让衣服更柔软。', 0);
 | 
					INSERT INTO `goods` VALUES (72, '洗衣液', 2, '妙洁', '[]', '妙洁深层洁净洗衣液', 1, 96, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 29.99, 39.99, '妙洁深层洁净洗衣液,有效去除衣物污渍,保护衣物纤维,让衣服更柔软。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (73, '纸巾', 2, '维达', '[]', '维达抽纸', 1, 95, NULL, 0, '盒', 19.99, 22.99, '维达抽纸,柔软舒适,吸水性好,不易破碎。', 0);
 | 
					INSERT INTO `goods` VALUES (73, '纸巾', 2, '维达', '[]', '维达抽纸', 1, 95, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '盒', 19.99, 22.99, '维达抽纸,柔软舒适,吸水性好,不易破碎。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (74, '剪刀', 2, '福尺', '[]', '福尺多功能剪刀', 1, 94, NULL, 0, '把', 9.99, 12.99, '福尺多功能剪刀', 0);
 | 
					INSERT INTO `goods` VALUES (74, '剪刀', 2, '福尺', '[]', '福尺多功能剪刀', 1, 94, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '把', 9.99, 12.99, '福尺多功能剪刀', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (75, '薯片', 5, '乐事', '[]', '薯片', 1, 100, NULL, 0, '袋', 8.00, 10.00, '美味薯片,酥脆可口,适合下午茶。', 0);
 | 
					INSERT INTO `goods` VALUES (75, '薯片', 5, '乐事', '[]', '薯片', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 8.00, 10.00, '美味薯片,酥脆可口,适合下午茶。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (76, '巧克力', 5, '德芙', '[]', '德芙巧克力', 1, 100, NULL, 0, '盒', 20.00, 25.00, '德芙巧克力,甜美可口,适合送礼。', 0);
 | 
					INSERT INTO `goods` VALUES (76, '巧克力', 5, '德芙', '[]', '德芙巧克力', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '盒', 20.00, 25.00, '德芙巧克力,甜美可口,适合送礼。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (77, '蜜饯', 5, '三只松鼠', '[]', '三只松鼠夏威夷果', 1, 100, NULL, 0, '袋', 18.00, 20.00, '三只松鼠夏威夷果,口感香甜,健康零食。', 0);
 | 
					INSERT INTO `goods` VALUES (77, '蜜饯', 5, '三只松鼠', '[]', '三只松鼠夏威夷果', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 18.00, 20.00, '三只松鼠夏威夷果,口感香甜,健康零食。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (78, '牛肉干', 5, '卫龙', '[]', '麻辣牛肉干', 1, 100, NULL, 0, '袋', 15.00, 20.00, '卫龙麻辣牛肉干,辣味十足,爽口不腻。', 0);
 | 
					INSERT INTO `goods` VALUES (78, '牛肉干', 5, '卫龙', '[]', '麻辣牛肉干', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 15.00, 20.00, '卫龙麻辣牛肉干,辣味十足,爽口不腻。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (79, '薄荷糖', 5, '金丝猴', '[]', '金丝猴薄荷糖', 1, 100, NULL, 0, '袋', 10.00, 12.00, '金丝猴薄荷糖,口感清新,适合口气不佳的人。', 0);
 | 
					INSERT INTO `goods` VALUES (79, '薄荷糖', 5, '金丝猴', '[]', '金丝猴薄荷糖', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 10.00, 12.00, '金丝猴薄荷糖,口感清新,适合口气不佳的人。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (80, '奥利奥饼干', 5, 'Oreo', '[]', '经典口味奥利奥饼干', 1, 100, NULL, 0, '盒', 18.00, 16.99, '经典口味奥利奥饼干,酥脆可口,一口一个,让你停不下来。', 0);
 | 
					INSERT INTO `goods` VALUES (80, '奥利奥饼干', 5, 'Oreo', '[]', '经典口味奥利奥饼干', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '盒', 18.00, 16.99, '经典口味奥利奥饼干,酥脆可口,一口一个,让你停不下来。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (81, '可口可乐', 7, 'Coca-Cola', '[]', '经典可口可乐', 1, 100, NULL, 0, '瓶', 3.00, 2.50, '可口可乐,清爽解渴,适合任何场合。', 0);
 | 
					INSERT INTO `goods` VALUES (81, '可口可乐', 7, 'Coca-Cola', '[]', '经典可口可乐', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '瓶', 3.00, 2.50, '可口可乐,清爽解渴,适合任何场合。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (82, '大白兔奶糖', 5, '大白兔', '[]', '经典奶香味道', 1, 100, NULL, 0, '袋', 5.00, 4.50, '大白兔奶糖,经典奶香味道,口感绵软。', 0);
 | 
					INSERT INTO `goods` VALUES (82, '大白兔奶糖', 5, '大白兔', '[]', '经典奶香味道', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 5.00, 4.50, '大白兔奶糖,经典奶香味道,口感绵软。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (83, '卫龙辣条', 5, '卫龙', '[]', '经典辣味', 1, 100, NULL, 0, '袋', 6.00, 5.50, '卫龙辣条,经典辣味,辣爽可口,不同于其他辣条。', 0);
 | 
					INSERT INTO `goods` VALUES (83, '卫龙辣条', 5, '卫龙', '[]', '经典辣味', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 6.00, 5.50, '卫龙辣条,经典辣味,辣爽可口,不同于其他辣条。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (84, '雀巢咖啡', 5, 'Nestle', '[]', '拿铁口味', 1, 100, NULL, 0, '袋', 20.00, 18.99, '雀巢咖啡,拿铁口味,浓郁香醇,唤醒你的味蕾。', 0);
 | 
					INSERT INTO `goods` VALUES (84, '雀巢咖啡', 5, 'Nestle', '[]', '拿铁口味', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '袋', 20.00, 18.99, '雀巢咖啡,拿铁口味,浓郁香醇,唤醒你的味蕾。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (85, '伊利纯牛奶', 7, '伊利', '[]', '高端纯牛奶', 1, 100, NULL, 0, '盒', 5.00, 4.80, '伊利纯牛奶,高端纯牛奶,口感绵密,适合慢慢品尝。', 0);
 | 
					INSERT INTO `goods` VALUES (85, '伊利纯牛奶', 7, '伊利', '[]', '高端纯牛奶', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '盒', 5.00, 4.80, '伊利纯牛奶,高端纯牛奶,口感绵密,适合慢慢品尝。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (86, '太平梳打饼干', 5, '太平', '[]', '酥脆可口', 1, 100, NULL, 0, '盒', 10.00, 8.50, '太平梳打饼干,酥脆可口,咬一口,满口的香脆声。', 0);
 | 
					INSERT INTO `goods` VALUES (86, '太平梳打饼干', 5, '太平', '[]', '酥脆可口', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '盒', 10.00, 8.50, '太平梳打饼干,酥脆可口,咬一口,满口的香脆声。', 0);
 | 
				
			||||||
INSERT INTO `goods` VALUES (87, '德芙巧克力', 5, 'Dove', '[]', '丝滑绵密', 1, 100, NULL, 0, '盒', 30.00, 28.50, '德芙巧克力,丝滑绵密,一口一个,舌尖上的享受。', 0);
 | 
					INSERT INTO `goods` VALUES (87, '德芙巧克力', 5, 'Dove', '[]', '丝滑绵密', 1, 100, 'https://cdn-we-retail.ym.tencent.com/tsr/goods/muy-3a.png?imageMogr2/thumbnail/320x320/quality/70/strip/format/webp', 0, '盒', 30.00, 28.50, '德芙巧克力,丝滑绵密,一口一个,舌尖上的享受。', 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
-- Table structure for goods_category
 | 
					-- Table structure for goods_category
 | 
				
			||||||
@@ -247,6 +247,45 @@ INSERT INTO `notice1` VALUES (7, '11', '22', '2022-03-22');
 | 
				
			|||||||
INSERT INTO `notice1` VALUES (8, '22', '22', '2022-04-14');
 | 
					INSERT INTO `notice1` VALUES (8, '22', '22', '2022-04-14');
 | 
				
			||||||
INSERT INTO `notice1` VALUES (9, '33', '33', '2022-04-14');
 | 
					INSERT INTO `notice1` VALUES (9, '33', '33', '2022-04-14');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- Table structure for order
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					DROP TABLE IF EXISTS `order`;
 | 
				
			||||||
 | 
					CREATE TABLE `order`  (
 | 
				
			||||||
 | 
					  `id` bigint(20) NOT NULL COMMENT '订单ID',
 | 
				
			||||||
 | 
					  `user_id` int(11) NOT NULL COMMENT '用户ID',
 | 
				
			||||||
 | 
					  `order_date` datetime NOT NULL COMMENT '订单日期',
 | 
				
			||||||
 | 
					  `order_status` enum('Pending','Processing','Shipped','Delivered','Cancelled') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '订单状态',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`id`) USING BTREE,
 | 
				
			||||||
 | 
					  INDEX `user_id`(`user_id`) USING BTREE,
 | 
				
			||||||
 | 
					  UNIQUE INDEX `id`(`id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- Records of order
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- Table structure for order_detail
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					DROP TABLE IF EXISTS `order_detail`;
 | 
				
			||||||
 | 
					CREATE TABLE `order_detail`  (
 | 
				
			||||||
 | 
					  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '订单详情ID',
 | 
				
			||||||
 | 
					  `order_id` bigint(20) NOT NULL COMMENT '订单ID',
 | 
				
			||||||
 | 
					  `good_id` bigint(20) UNSIGNED NOT NULL COMMENT '商品ID',
 | 
				
			||||||
 | 
					  `good_count` int(11) NOT NULL COMMENT '商品数量',
 | 
				
			||||||
 | 
					  `unit_price` decimal(10, 2) NOT NULL COMMENT '下单时商品单价',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`id`) USING BTREE,
 | 
				
			||||||
 | 
					  INDEX `order_id`(`order_id`) USING BTREE,
 | 
				
			||||||
 | 
					  INDEX `good_id`(`good_id`) USING BTREE,
 | 
				
			||||||
 | 
					  CONSTRAINT `order_detail_ibfk_1` FOREIGN KEY (`good_id`) REFERENCES `goods` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT,
 | 
				
			||||||
 | 
					  CONSTRAINT `order_detail_ibfk_2` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					-- Records of order_detail
 | 
				
			||||||
 | 
					-- ----------------------------
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
-- Table structure for report
 | 
					-- Table structure for report
 | 
				
			||||||
-- ----------------------------
 | 
					-- ----------------------------
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										47
									
								
								docs/ChatGPT/写Service.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								docs/ChatGPT/写Service.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,47 @@
 | 
				
			|||||||
 | 
					我在用Springboot构建商城网站后台,请帮我写出商品下单部分Service层代码,只需要写出核心代码即可,不用输出完整代码。
 | 
				
			||||||
 | 
					不要用@Autowired(使用@Resource代替)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `goods`  (
 | 
				
			||||||
 | 
					  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
 | 
				
			||||||
 | 
					  `goods_name` varchar(127) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '商品名称',
 | 
				
			||||||
 | 
					  `category_id` int(11) NULL DEFAULT 0 COMMENT '商品所属类目ID',
 | 
				
			||||||
 | 
					  `brand` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '0' COMMENT '商品品牌',
 | 
				
			||||||
 | 
					  `gallery` varchar(1023) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '[]' COMMENT '商品宣传图片列表,采用JSON数组格式',
 | 
				
			||||||
 | 
					  `brief` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品简介',
 | 
				
			||||||
 | 
					  `is_on_sale` tinyint(1) NULL DEFAULT 1 COMMENT '是否上架 0为下架 1为上架',
 | 
				
			||||||
 | 
					  `sort_order` smallint(4) NULL DEFAULT 100 COMMENT '排序',
 | 
				
			||||||
 | 
					  `pic_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品页面商品图片',
 | 
				
			||||||
 | 
					  `type` tinyint(1) NULL DEFAULT 0 COMMENT '商品类型',
 | 
				
			||||||
 | 
					  `unit` varchar(31) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '件' COMMENT '商品单位,例如件、盒',
 | 
				
			||||||
 | 
					  `counter_price` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '专柜价格(原价 / 划线价)',
 | 
				
			||||||
 | 
					  `retail_price` decimal(10, 2) NULL DEFAULT 100000.00 COMMENT '零售价格(售价 / 未划线价)',
 | 
				
			||||||
 | 
					  `detail` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '商品详细介绍,是富文本格式',
 | 
				
			||||||
 | 
					  `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '逻辑删除 0为正常 1为删除',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`id`) USING BTREE,
 | 
				
			||||||
 | 
					  INDEX `category_id`(`category_id`) USING BTREE,
 | 
				
			||||||
 | 
					  INDEX `brand_id`(`brand`) USING BTREE,
 | 
				
			||||||
 | 
					  INDEX `sort_order`(`sort_order`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB AUTO_INCREMENT = 23 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '商品基本信息表' ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `goods_category`  (
 | 
				
			||||||
 | 
					  `id` bigint(11) NOT NULL AUTO_INCREMENT,
 | 
				
			||||||
 | 
					  `category_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT NULL COMMENT '商品分类名',
 | 
				
			||||||
 | 
					  `order` int(11) NULL DEFAULT NULL COMMENT '排序',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `orders`  (
 | 
				
			||||||
 | 
					  `order_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID',
 | 
				
			||||||
 | 
					  `user_id` int(11) NOT NULL COMMENT '用户ID',
 | 
				
			||||||
 | 
					  `order_date` date NOT NULL COMMENT '订单日期',
 | 
				
			||||||
 | 
					  `order_status` enum('Pending','Processing','Shipped','Delivered','Cancelled') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '订单状态',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`order_id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `goods_order_details`  (
 | 
				
			||||||
 | 
					  `order_detail_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单详情ID',
 | 
				
			||||||
 | 
					  `order_id` int(11) NOT NULL COMMENT '订单ID',
 | 
				
			||||||
 | 
					  `product_id` int(11) NOT NULL COMMENT '商品ID',
 | 
				
			||||||
 | 
					  `product_quantity` int(11) NOT NULL COMMENT '商品数量',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`order_detail_id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
							
								
								
									
										38
									
								
								docs/ChatGPT/转换为POJO对象.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								docs/ChatGPT/转换为POJO对象.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
				
			|||||||
 | 
					请帮我将以下表转换为Java POJO对象,不需要getter和setter
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `goods_order_details`  (
 | 
				
			||||||
 | 
					  `order_detail_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单详情ID',
 | 
				
			||||||
 | 
					  `order_id` int(11) NOT NULL COMMENT '订单ID',
 | 
				
			||||||
 | 
					  `product_id` int(11) NOT NULL COMMENT '商品ID',
 | 
				
			||||||
 | 
					  `product_quantity` int(11) NOT NULL COMMENT '商品数量',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`order_detail_id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					CREATE TABLE `orders`  (
 | 
				
			||||||
 | 
					  `order_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单ID',
 | 
				
			||||||
 | 
					  `user_id` int(11) NOT NULL COMMENT '用户ID',
 | 
				
			||||||
 | 
					  `order_date` date NOT NULL COMMENT '订单日期',
 | 
				
			||||||
 | 
					  `order_status` enum('Pending','Processing','Shipped','Delivered','Cancelled') CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '订单状态',
 | 
				
			||||||
 | 
					  PRIMARY KEY (`order_id`) USING BTREE
 | 
				
			||||||
 | 
					) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					例如:Good的对象为
 | 
				
			||||||
 | 
					@Data
 | 
				
			||||||
 | 
					public class Good {
 | 
				
			||||||
 | 
					    Long id;
 | 
				
			||||||
 | 
					    String goodsName;
 | 
				
			||||||
 | 
					    Integer categoryId;
 | 
				
			||||||
 | 
					    String brand;
 | 
				
			||||||
 | 
					    String gallery;
 | 
				
			||||||
 | 
					    String brief;
 | 
				
			||||||
 | 
					    Boolean isOnSale;
 | 
				
			||||||
 | 
					    String picUrl;
 | 
				
			||||||
 | 
					    Integer type;
 | 
				
			||||||
 | 
					    String unit;
 | 
				
			||||||
 | 
					    Double counterPrice;
 | 
				
			||||||
 | 
					    Double retailPrice;
 | 
				
			||||||
 | 
					    String detail;
 | 
				
			||||||
 | 
					    Boolean deleted;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Reference in New Issue
	
	Block a user