初始化美若彩妆销售平台项目
This commit is contained in:
86
meiruo-backend/pom.xml
Normal file
86
meiruo-backend/pom.xml
Normal file
@@ -0,0 +1,86 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>3.2.0</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<groupId>com.meiruo</groupId>
|
||||
<artifactId>meiruo-cosmetics</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<name>meiruo-cosmetics</name>
|
||||
<description>美若彩妆销售平台</description>
|
||||
|
||||
<properties>
|
||||
<java.version>17</java.version>
|
||||
<mybatis-spring-boot.version>3.0.3</mybatis-spring-boot.version>
|
||||
<sa-token.version>1.38.0</sa-token.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>${mybatis-spring-boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mysql</groupId>
|
||||
<artifactId>mysql-connector-j</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-jwt</artifactId>
|
||||
<version>${sa-token.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<configuration>
|
||||
<excludes>
|
||||
<exclude>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
135
meiruo-backend/sql/database.sql
Normal file
135
meiruo-backend/sql/database.sql
Normal file
@@ -0,0 +1,135 @@
|
||||
-- 创建数据库
|
||||
CREATE DATABASE IF NOT EXISTS meiruo_cosmetics DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
|
||||
USE meiruo_cosmetics;
|
||||
|
||||
-- 用户表
|
||||
CREATE TABLE IF NOT EXISTS `user` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '用户ID',
|
||||
`username` VARCHAR(50) NOT NULL UNIQUE COMMENT '用户名',
|
||||
`password` VARCHAR(100) NOT NULL COMMENT '密码',
|
||||
`nickname` VARCHAR(50) COMMENT '昵称',
|
||||
`phone` VARCHAR(20) COMMENT '手机号',
|
||||
`email` VARCHAR(100) COMMENT '邮箱',
|
||||
`avatar` VARCHAR(255) COMMENT '头像',
|
||||
`role` TINYINT DEFAULT 0 COMMENT '角色:0-普通用户,1-管理员',
|
||||
`status` TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-正常',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
INDEX idx_username (`username`),
|
||||
INDEX idx_phone (`phone`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='用户表';
|
||||
|
||||
-- 分类表
|
||||
CREATE TABLE IF NOT EXISTS `category` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '分类ID',
|
||||
`name` VARCHAR(50) NOT NULL COMMENT '分类名称',
|
||||
`description` VARCHAR(255) COMMENT '分类描述',
|
||||
`sort` INT DEFAULT 0 COMMENT '排序',
|
||||
`status` TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-正常',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
INDEX idx_status (`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品分类表';
|
||||
|
||||
-- 商品表
|
||||
CREATE TABLE IF NOT EXISTS `product` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '商品ID',
|
||||
`name` VARCHAR(100) NOT NULL COMMENT '商品名称',
|
||||
`description` TEXT COMMENT '商品描述',
|
||||
`price` DECIMAL(10,2) NOT NULL COMMENT '价格',
|
||||
`stock` INT DEFAULT 0 COMMENT '库存',
|
||||
`category_id` BIGINT COMMENT '分类ID',
|
||||
`image` VARCHAR(255) COMMENT '主图',
|
||||
`images` TEXT COMMENT '图片列表',
|
||||
`status` TINYINT DEFAULT 1 COMMENT '状态:0-下架,1-正常',
|
||||
`sales` INT DEFAULT 0 COMMENT '销量',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
INDEX idx_category (`category_id`),
|
||||
INDEX idx_status (`status`),
|
||||
INDEX idx_sales (`sales`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商品表';
|
||||
|
||||
-- 购物车表
|
||||
CREATE TABLE IF NOT EXISTS `cart` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '购物车ID',
|
||||
`user_id` BIGINT NOT NULL COMMENT '用户ID',
|
||||
`product_id` BIGINT NOT NULL COMMENT '商品ID',
|
||||
`quantity` INT NOT NULL DEFAULT 1 COMMENT '数量',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
UNIQUE KEY uk_user_product (`user_id`, `product_id`),
|
||||
INDEX idx_user (`user_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='购物车表';
|
||||
|
||||
-- 订单表
|
||||
CREATE TABLE IF NOT EXISTS `order` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '订单ID',
|
||||
`order_no` VARCHAR(32) NOT NULL UNIQUE COMMENT '订单号',
|
||||
`user_id` BIGINT NOT NULL COMMENT '用户ID',
|
||||
`total_amount` DECIMAL(10,2) NOT NULL COMMENT '总金额',
|
||||
`status` TINYINT DEFAULT 1 COMMENT '状态:1-待付款,2-已付款,3-已发货,4-已完成,5-已取消',
|
||||
`receiver_name` VARCHAR(50) COMMENT '收货人姓名',
|
||||
`receiver_phone` VARCHAR(20) COMMENT '收货人电话',
|
||||
`receiver_address` VARCHAR(255) COMMENT '收货地址',
|
||||
`remark` VARCHAR(255) COMMENT '备注',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`pay_time` DATETIME COMMENT '付款时间',
|
||||
`ship_time` DATETIME COMMENT '发货时间',
|
||||
`receive_time` DATETIME COMMENT '收货时间',
|
||||
INDEX idx_user (`user_id`),
|
||||
INDEX idx_order_no (`order_no`),
|
||||
INDEX idx_status (`status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单表';
|
||||
|
||||
-- 订单项表
|
||||
CREATE TABLE IF NOT EXISTS `order_item` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '订单项ID',
|
||||
`order_id` BIGINT NOT NULL COMMENT '订单ID',
|
||||
`product_id` BIGINT NOT NULL COMMENT '商品ID',
|
||||
`product_name` VARCHAR(100) NOT NULL COMMENT '商品名称',
|
||||
`product_image` VARCHAR(255) COMMENT '商品图片',
|
||||
`price` DECIMAL(10,2) NOT NULL COMMENT '商品价格',
|
||||
`quantity` INT NOT NULL COMMENT '数量',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
INDEX idx_order (`order_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单项表';
|
||||
|
||||
-- 轮播图表
|
||||
CREATE TABLE IF NOT EXISTS `banner` (
|
||||
`id` BIGINT PRIMARY KEY AUTO_INCREMENT COMMENT '轮播图ID',
|
||||
`title` VARCHAR(50) COMMENT '标题',
|
||||
`image` VARCHAR(255) NOT NULL COMMENT '图片地址',
|
||||
`link` VARCHAR(255) COMMENT '链接地址',
|
||||
`sort` INT DEFAULT 0 COMMENT '排序',
|
||||
`status` TINYINT DEFAULT 1 COMMENT '状态:0-禁用,1-正常',
|
||||
`create_time` DATETIME DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
INDEX idx_status (`status`),
|
||||
INDEX idx_sort (`sort`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='轮播图表';
|
||||
|
||||
-- 插入默认管理员账号
|
||||
INSERT INTO `user` (`username`, `password`, `nickname`, `role`, `status`) VALUES
|
||||
('admin', 'e10adc3949ba59abbe56e057f20f883e', '管理员', 1, 1);
|
||||
|
||||
-- 插入默认分类
|
||||
INSERT INTO `category` (`name`, `description`, `sort`) VALUES
|
||||
('面部彩妆', '粉底液、遮瑕膏、粉饼等', 1),
|
||||
('眼妆', '眼影、眼线、睫毛膏等', 2),
|
||||
('唇妆', '口红、唇釉、唇彩等', 3),
|
||||
('腮红', '腮红、修容等', 4),
|
||||
('卸妆', '卸妆油、卸妆水等', 5);
|
||||
|
||||
-- 插入示例商品
|
||||
INSERT INTO `product` (`name`, `description`, `price`, `stock`, `category_id`, `image`, `status`, `sales`) VALUES
|
||||
('水润粉底液', '轻薄水润,遮瑕保湿,打造自然裸妆感', 168.00, 100, 1, '/images/product1.jpg', 1, 50),
|
||||
('大地色眼影盘', '12色日常大地色眼影盘,珠光哑光搭配', 128.00, 80, 2, '/images/product2.jpg', 1, 30),
|
||||
('哑光正红色口红', '经典正红色,哑光质地,持久显色', 89.00, 200, 3, '/images/product3.jpg', 1, 100),
|
||||
('腮红', '柔美腮红,轻薄自然,打造好气色', 68.00, 150, 4, '/images/product4.jpg', 1, 25),
|
||||
('卸妆油', '温和卸妆油,深层清洁不紧绷', 98.00, 120, 5, '/images/product5.jpg', 1, 40);
|
||||
|
||||
-- 插入示例轮播图
|
||||
INSERT INTO `banner` (`title`, `image`, `link`, `sort`) VALUES
|
||||
('新品上市', '/images/banner1.jpg', '/product/1', 1),
|
||||
('限时优惠', '/images/banner2.jpg', '/product/2', 2),
|
||||
('热销推荐', '/images/banner3.jpg', '/product/3', 3);
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.meiruo.cosmetics;
|
||||
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@MapperScan("com.meiruo.cosmetics.mapper")
|
||||
public class MeiruoCosmeticsApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(MeiruoCosmeticsApplication.class, args);
|
||||
System.out.println("====================================");
|
||||
System.out.println(" 美若彩妆销售平台启动成功!");
|
||||
System.out.println("====================================");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.meiruo.cosmetics.config;
|
||||
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.jwt.SaJwtManager;
|
||||
import cn.dev33.satoken.jwt.StpLogicJwtForSimple;
|
||||
import cn.dev33.satoken.stp.StpInterface;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class SaTokenConfig implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
public StpLogicJwtForSimple stpLogicJwtForSimple() {
|
||||
return new StpLogicJwtForSimple();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public StpInterface stpInterface() {
|
||||
return new StpInterface() {
|
||||
@Override
|
||||
public List<String> getPermissionList(Object loginId, String loginType) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getRoleList(Object loginId, String loginType) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new SaInterceptor()).addPathPatterns("/api/**").excludePathPatterns("/api/user/login", "/api/user/register");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.meiruo.cosmetics.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/upload/**")
|
||||
.addResourceLocations("file:src/main/resources/static/upload/")
|
||||
.addResourceLocations("classpath:/static/upload/");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import com.meiruo.cosmetics.service.BannerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/banner")
|
||||
public class BannerController {
|
||||
|
||||
@Autowired
|
||||
private BannerService bannerService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Banner> list = bannerService.getList(status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", bannerService.getById(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Map<String, Object> add(@RequestBody Banner banner) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.add(banner);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Map<String, Object> update(@RequestBody Banner banner) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.update(banner);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/sort/{id}")
|
||||
public Map<String, Object> updateSort(@PathVariable Long id, @RequestParam Integer sort) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
bannerService.updateSort(id, sort);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.meiruo.cosmetics.service.CartService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/cart")
|
||||
public class CartController {
|
||||
|
||||
@Autowired
|
||||
private CartService cartService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
result.put("code", 200);
|
||||
result.put("data", cartService.getCartList(userId));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/add")
|
||||
public Map<String, Object> add(@RequestParam Long productId, @RequestParam Integer quantity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
cartService.add(userId, productId, quantity);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/quantity/{id}")
|
||||
public Map<String, Object> updateQuantity(@PathVariable Long id, @RequestParam Integer quantity) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
cartService.updateQuantity(id, quantity);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
cartService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/clear")
|
||||
public Map<String, Object> clear() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
cartService.clear(userId);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "清空成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import com.meiruo.cosmetics.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/category")
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired
|
||||
private CategoryService categoryService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Category> list = categoryService.getList(status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", categoryService.getById(id));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Map<String, Object> add(@RequestBody Category category) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
categoryService.add(category);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Map<String, Object> update(@RequestBody Category category) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
categoryService.update(category);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
categoryService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import com.meiruo.cosmetics.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/order")
|
||||
public class OrderController {
|
||||
|
||||
@Autowired
|
||||
private OrderService orderService;
|
||||
|
||||
@PostMapping("/create")
|
||||
public Map<String, Object> create(
|
||||
@RequestBody Map<String, Object> params) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
List<Long> cartIds = (List<Long>) params.get("cartIds");
|
||||
String receiverName = (String) params.get("receiverName");
|
||||
String receiverPhone = (String) params.get("receiverPhone");
|
||||
String receiverAddress = (String) params.get("receiverAddress");
|
||||
String remark = (String) params.get("remark");
|
||||
|
||||
Order order = orderService.create(userId, cartIds, receiverName, receiverPhone, receiverAddress, remark);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "下单成功");
|
||||
result.put("data", order);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
List<Order> list = orderService.getByUserId(userId, status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/admin/list")
|
||||
public Map<String, Object> adminList(@RequestParam(required = false) String keyword, @RequestParam(required = false) Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Order> list = orderService.getList(keyword, status);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Order order = orderService.getById(id);
|
||||
result.put("code", 200);
|
||||
result.put("data", order);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/status/{id}")
|
||||
public Map<String, Object> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
orderService.updateStatus(id, status);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "操作成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/revenue/{type}")
|
||||
public Map<String, Object> getRevenueStatistics(@PathVariable String type) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", orderService.getRevenueStatistics(type));
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/top/{limit}")
|
||||
public Map<String, Object> getTopProducts(@PathVariable Integer limit) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", orderService.getTopProducts(limit));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import com.meiruo.cosmetics.service.ProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/product")
|
||||
public class ProductController {
|
||||
|
||||
@Autowired
|
||||
private ProductService productService;
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(
|
||||
@RequestParam(required = false) Long categoryId,
|
||||
@RequestParam(required = false) String keyword) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
List<Product> list = productService.getList(categoryId, keyword);
|
||||
result.put("code", 200);
|
||||
result.put("data", list);
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/recommend")
|
||||
public Map<String, Object> getRecommend() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", productService.getRecommend());
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public Map<String, Object> getById(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Product product = productService.getById(id);
|
||||
result.put("code", 200);
|
||||
result.put("data", product);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping
|
||||
public Map<String, Object> add(@RequestBody Product product) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
productService.add(product);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "添加成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping
|
||||
public Map<String, Object> update(@RequestBody Product product) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
productService.update(product);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public Map<String, Object> delete(@PathVariable Long id) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
productService.delete(id);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "删除成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.*;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/upload")
|
||||
@CrossOrigin
|
||||
public class UploadController {
|
||||
|
||||
private static final String UPLOAD_PATH = "src/main/resources/static/upload/";
|
||||
|
||||
@PostMapping("/image")
|
||||
public Map<String, Object> uploadImage(@RequestParam("file") MultipartFile file) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
|
||||
if (file.isEmpty()) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "请选择要上传的文件");
|
||||
return result;
|
||||
}
|
||||
|
||||
try {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
String ext = originalFilename.substring(originalFilename.lastIndexOf("."));
|
||||
|
||||
String dateDir = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd"));
|
||||
String fileName = System.currentTimeMillis() + ext;
|
||||
|
||||
Path uploadDir = Paths.get(UPLOAD_PATH + dateDir);
|
||||
if (!Files.exists(uploadDir)) {
|
||||
Files.createDirectories(uploadDir);
|
||||
}
|
||||
|
||||
Path filePath = uploadDir.resolve(fileName);
|
||||
Files.copy(file.getInputStream(), filePath, StandardCopyOption.REPLACE_EXISTING);
|
||||
|
||||
String url = "/upload/" + dateDir + "/" + fileName;
|
||||
|
||||
result.put("code", 200);
|
||||
result.put("msg", "上传成功");
|
||||
result.put("url", url);
|
||||
return result;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
result.put("code", 500);
|
||||
result.put("msg", "文件上传失败");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.meiruo.cosmetics.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import com.meiruo.cosmetics.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@PostMapping("/login")
|
||||
public Map<String, Object> login(@RequestBody User user) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
User loginUser = userService.login(user.getUsername(), user.getPassword());
|
||||
if (loginUser == null) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "用户名或密码错误");
|
||||
return result;
|
||||
}
|
||||
Map<String, Object> data = new HashMap<>();
|
||||
data.put("id", loginUser.getId());
|
||||
data.put("username", loginUser.getUsername());
|
||||
data.put("nickname", loginUser.getNickname());
|
||||
data.put("avatar", loginUser.getAvatar());
|
||||
data.put("role", loginUser.getRole());
|
||||
result.put("code", 200);
|
||||
result.put("msg", "登录成功");
|
||||
result.put("data", data);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/register")
|
||||
public Map<String, Object> register(@RequestBody User user) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
User registerUser = userService.register(user);
|
||||
if (registerUser == null) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "用户名已存在");
|
||||
return result;
|
||||
}
|
||||
result.put("code", 200);
|
||||
result.put("msg", "注册成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/info")
|
||||
public Map<String, Object> getInfo() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
User user = userService.getById(userId);
|
||||
if (user == null) {
|
||||
result.put("code", 500);
|
||||
result.put("msg", "用户不存在");
|
||||
return result;
|
||||
}
|
||||
result.put("code", 200);
|
||||
result.put("data", user);
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/info")
|
||||
public Map<String, Object> updateInfo(@RequestBody User user) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
user.setId(userId);
|
||||
userService.update(user);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "修改成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@PostMapping("/logout")
|
||||
public Map<String, Object> logout() {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
StpUtil.logout();
|
||||
result.put("code", 200);
|
||||
result.put("msg", "退出成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
public Map<String, Object> getList(@RequestParam(required = false) String query) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("code", 200);
|
||||
result.put("data", userService.getList(query));
|
||||
return result;
|
||||
}
|
||||
|
||||
@PutMapping("/status/{id}")
|
||||
public Map<String, Object> updateStatus(@PathVariable Long id, @RequestParam Integer status) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
userService.updateStatus(id, status);
|
||||
result.put("code", 200);
|
||||
result.put("msg", "操作成功");
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Banner {
|
||||
private Long id;
|
||||
private String title;
|
||||
private String image;
|
||||
private String link;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Cart {
|
||||
private Long id;
|
||||
private Long userId;
|
||||
private Long productId;
|
||||
private Integer quantity;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Category {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private Integer sort;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Order {
|
||||
private Long id;
|
||||
private String orderNo;
|
||||
private Long userId;
|
||||
private BigDecimal totalAmount;
|
||||
private Integer status;
|
||||
private String receiverName;
|
||||
private String receiverPhone;
|
||||
private String receiverAddress;
|
||||
private String remark;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime payTime;
|
||||
private LocalDateTime shipTime;
|
||||
private LocalDateTime receiveTime;
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class OrderItem {
|
||||
private Long id;
|
||||
private Long orderId;
|
||||
private Long productId;
|
||||
private String productName;
|
||||
private String productImage;
|
||||
private BigDecimal price;
|
||||
private Integer quantity;
|
||||
private LocalDateTime createTime;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class Product {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private BigDecimal price;
|
||||
private Integer stock;
|
||||
private Long categoryId;
|
||||
private String image;
|
||||
private String images;
|
||||
private Integer status;
|
||||
private Integer sales;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.meiruo.cosmetics.entity;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Data
|
||||
public class User {
|
||||
private Long id;
|
||||
private String username;
|
||||
private String password;
|
||||
private String nickname;
|
||||
private String phone;
|
||||
private String email;
|
||||
private String avatar;
|
||||
private Integer role;
|
||||
private Integer status;
|
||||
private LocalDateTime createTime;
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface BannerMapper {
|
||||
|
||||
List<Banner> selectList(@Param("status") Integer status);
|
||||
|
||||
Banner selectById(@Param("id") Long id);
|
||||
|
||||
int insert(Banner banner);
|
||||
|
||||
int update(Banner banner);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int updateSort(@Param("id") Long id, @Param("sort") Integer sort);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Cart;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CartMapper {
|
||||
|
||||
Cart selectByUserAndProduct(@Param("userId") Long userId, @Param("productId") Long productId);
|
||||
|
||||
List<Cart> selectByUserId(@Param("userId") Long userId);
|
||||
|
||||
int insert(Cart cart);
|
||||
|
||||
int update(Cart cart);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int deleteByUserId(@Param("userId") Long userId);
|
||||
|
||||
int updateQuantity(@Param("id") Long id, @Param("quantity") Integer quantity);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CategoryMapper {
|
||||
|
||||
Category selectById(@Param("id") Long id);
|
||||
|
||||
List<Category> selectList(@Param("status") Integer status);
|
||||
|
||||
int insert(Category category);
|
||||
|
||||
int update(Category category);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.OrderItem;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface OrderItemMapper {
|
||||
|
||||
List<OrderItem> selectByOrderId(@Param("orderId") Long orderId);
|
||||
|
||||
int insert(OrderItem orderItem);
|
||||
|
||||
int insertBatch(@Param("items") List<OrderItem> items);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mapper
|
||||
public interface OrderMapper {
|
||||
|
||||
Order selectById(@Param("id") Long id);
|
||||
|
||||
Order selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
List<Order> selectByUserId(@Param("userId") Long userId, @Param("status") Integer status);
|
||||
|
||||
List<Order> selectList(@Param("keyword") String keyword, @Param("status") Integer status);
|
||||
|
||||
int insert(Order order);
|
||||
|
||||
int update(Order order);
|
||||
|
||||
int updateStatus(@Param("id") Long id, @Param("status") Integer status);
|
||||
|
||||
List<Map<String, Object>> selectRevenueStatistics(@Param("type") String type);
|
||||
|
||||
List<Map<String, Object>> selectTopProducts(@Param("limit") Integer limit);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ProductMapper {
|
||||
|
||||
Product selectById(@Param("id") Long id);
|
||||
|
||||
List<Product> selectList(@Param("categoryId") Long categoryId, @Param("keyword") String keyword);
|
||||
|
||||
List<Product> selectRecommend();
|
||||
|
||||
List<Product> selectByIds(@Param("ids") List<Long> ids);
|
||||
|
||||
int insert(Product product);
|
||||
|
||||
int update(Product product);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int updateStock(@Param("id") Long id, @Param("count") Integer count);
|
||||
|
||||
int incrementSales(@Param("id") Long id, @Param("count") Integer count);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.meiruo.cosmetics.mapper;
|
||||
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface UserMapper {
|
||||
|
||||
User selectById(@Param("id") Long id);
|
||||
|
||||
User selectByUsername(@Param("username") String username);
|
||||
|
||||
User selectByPhone(@Param("phone") String phone);
|
||||
|
||||
List<User> selectList(@Param("query") String query);
|
||||
|
||||
int insert(User user);
|
||||
|
||||
int update(User user);
|
||||
|
||||
int delete(@Param("id") Long id);
|
||||
|
||||
int updateStatus(@Param("id") Long id, @Param("status") Integer status);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import java.util.List;
|
||||
|
||||
public interface BannerService {
|
||||
|
||||
List<Banner> getList(Integer status);
|
||||
|
||||
Banner getById(Long id);
|
||||
|
||||
void add(Banner banner);
|
||||
|
||||
void update(Banner banner);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateSort(Long id, Integer sort);
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Cart;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface CartService {
|
||||
|
||||
List<Map<String, Object>> getCartList(Long userId);
|
||||
|
||||
void add(Long userId, Long productId, Integer quantity);
|
||||
|
||||
void updateQuantity(Long id, Integer quantity);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void clear(Long userId);
|
||||
|
||||
void mergeFromCookie(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import java.util.List;
|
||||
|
||||
public interface CategoryService {
|
||||
|
||||
Category getById(Long id);
|
||||
|
||||
List<Category> getList(Integer status);
|
||||
|
||||
void add(Category category);
|
||||
|
||||
void update(Category category);
|
||||
|
||||
void delete(Long id);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface OrderService {
|
||||
|
||||
Order create(Long userId, List<Long> cartIds, String receiverName, String receiverPhone, String receiverAddress, String remark);
|
||||
|
||||
Order getById(Long id);
|
||||
|
||||
Order getByOrderNo(String orderNo);
|
||||
|
||||
List<Order> getByUserId(Long userId, Integer status);
|
||||
|
||||
List<Order> getList(String keyword, Integer status);
|
||||
|
||||
void updateStatus(Long id, Integer status);
|
||||
|
||||
Map<String, Object> getRevenueStatistics(String type);
|
||||
|
||||
List<Map<String, Object>> getTopProducts(Integer limit);
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import java.util.List;
|
||||
|
||||
public interface ProductService {
|
||||
|
||||
Product getById(Long id);
|
||||
|
||||
List<Product> getList(Long categoryId, String keyword);
|
||||
|
||||
List<Product> getRecommend();
|
||||
|
||||
List<Product> getByIds(List<Long> ids);
|
||||
|
||||
void add(Product product);
|
||||
|
||||
void update(Product product);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateStock(Long id, Integer count);
|
||||
|
||||
void incrementSales(Long id, Integer count);
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.meiruo.cosmetics.service;
|
||||
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import java.util.List;
|
||||
|
||||
public interface UserService {
|
||||
|
||||
User login(String username, String password);
|
||||
|
||||
User register(User user);
|
||||
|
||||
User getById(Long id);
|
||||
|
||||
User getByUsername(String username);
|
||||
|
||||
List<User> getList(String query);
|
||||
|
||||
void update(User user);
|
||||
|
||||
void delete(Long id);
|
||||
|
||||
void updateStatus(Long id, Integer status);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Banner;
|
||||
import com.meiruo.cosmetics.mapper.BannerMapper;
|
||||
import com.meiruo.cosmetics.service.BannerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class BannerServiceImpl implements BannerService {
|
||||
|
||||
@Autowired
|
||||
private BannerMapper bannerMapper;
|
||||
|
||||
@Override
|
||||
public List<Banner> getList(Integer status) {
|
||||
return bannerMapper.selectList(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Banner getById(Long id) {
|
||||
return bannerMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Banner banner) {
|
||||
banner.setStatus(1);
|
||||
bannerMapper.insert(banner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Banner banner) {
|
||||
bannerMapper.update(banner);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
bannerMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSort(Long id, Integer sort) {
|
||||
bannerMapper.updateSort(id, sort);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Cart;
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import com.meiruo.cosmetics.mapper.CartMapper;
|
||||
import com.meiruo.cosmetics.mapper.ProductMapper;
|
||||
import com.meiruo.cosmetics.service.CartService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Service
|
||||
public class CartServiceImpl implements CartService {
|
||||
|
||||
@Autowired
|
||||
private CartMapper cartMapper;
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getCartList(Long userId) {
|
||||
return cartMapper.selectByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Long userId, Long productId, Integer quantity) {
|
||||
Cart existCart = cartMapper.selectByUserAndProduct(userId, productId);
|
||||
if (existCart != null) {
|
||||
cartMapper.updateQuantity(existCart.getId(), existCart.getQuantity() + quantity);
|
||||
} else {
|
||||
Cart cart = new Cart();
|
||||
cart.setUserId(userId);
|
||||
cart.setProductId(productId);
|
||||
cart.setQuantity(quantity);
|
||||
cartMapper.insert(cart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateQuantity(Long id, Integer quantity) {
|
||||
cartMapper.updateQuantity(id, quantity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
cartMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(Long userId) {
|
||||
cartMapper.deleteByUserId(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void mergeFromCookie(Long userId) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Category;
|
||||
import com.meiruo.cosmetics.mapper.CategoryMapper;
|
||||
import com.meiruo.cosmetics.service.CategoryService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class CategoryServiceImpl implements CategoryService {
|
||||
|
||||
@Autowired
|
||||
private CategoryMapper categoryMapper;
|
||||
|
||||
@Override
|
||||
public Category getById(Long id) {
|
||||
return categoryMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Category> getList(Integer status) {
|
||||
return categoryMapper.selectList(status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Category category) {
|
||||
category.setStatus(1);
|
||||
categoryMapper.insert(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Category category) {
|
||||
categoryMapper.update(category);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
categoryMapper.delete(id);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Order;
|
||||
import com.meiruo.cosmetics.entity.OrderItem;
|
||||
import com.meiruo.cosmetics.mapper.OrderItemMapper;
|
||||
import com.meiruo.cosmetics.mapper.OrderMapper;
|
||||
import com.meiruo.cosmetics.mapper.ProductMapper;
|
||||
import com.meiruo.cosmetics.service.OrderService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Service
|
||||
public class OrderServiceImpl implements OrderService {
|
||||
|
||||
@Autowired
|
||||
private OrderMapper orderMapper;
|
||||
@Autowired
|
||||
private OrderItemMapper orderItemMapper;
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Order create(Long userId, List<Long> cartIds, String receiverName, String receiverPhone, String receiverAddress, String remark) {
|
||||
Order order = new Order();
|
||||
order.setOrderNo(UUID.randomUUID().toString().replace("-", ""));
|
||||
order.setUserId(userId);
|
||||
order.setReceiverName(receiverName);
|
||||
order.setReceiverPhone(receiverPhone);
|
||||
order.setReceiverAddress(receiverAddress);
|
||||
order.setRemark(remark);
|
||||
order.setStatus(1);
|
||||
|
||||
List<OrderItem> orderItems = new ArrayList<>();
|
||||
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||
|
||||
for (Long cartId : cartIds) {
|
||||
}
|
||||
|
||||
order.setTotalAmount(totalAmount);
|
||||
orderMapper.insert(order);
|
||||
|
||||
for (OrderItem item : orderItems) {
|
||||
item.setOrderId(order.getId());
|
||||
orderItemMapper.insert(item);
|
||||
productMapper.updateStock(item.getProductId(), item.getQuantity());
|
||||
productMapper.incrementSales(item.getProductId(), item.getQuantity());
|
||||
}
|
||||
|
||||
return order;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getById(Long id) {
|
||||
return orderMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Order getByOrderNo(String orderNo) {
|
||||
return orderMapper.selectByOrderNo(orderNo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> getByUserId(Long userId, Integer status) {
|
||||
return orderMapper.selectByUserId(userId, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Order> getList(String keyword, Integer status) {
|
||||
return orderMapper.selectList(keyword, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Long id, Integer status) {
|
||||
orderMapper.updateStatus(id, status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Object> getRevenueStatistics(String type) {
|
||||
List<Map<String, Object>> statistics = orderMapper.selectRevenueStatistics(type);
|
||||
BigDecimal total = BigDecimal.ZERO;
|
||||
for (Map<String, Object> stat : statistics) {
|
||||
total = total.add(new BigDecimal(stat.get("amount").toString()));
|
||||
}
|
||||
return Map.of("list", statistics, "total", total);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Map<String, Object>> getTopProducts(Integer limit) {
|
||||
return orderMapper.selectTopProducts(limit);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import com.meiruo.cosmetics.entity.Product;
|
||||
import com.meiruo.cosmetics.mapper.ProductMapper;
|
||||
import com.meiruo.cosmetics.service.ProductService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class ProductServiceImpl implements ProductService {
|
||||
|
||||
@Autowired
|
||||
private ProductMapper productMapper;
|
||||
|
||||
@Override
|
||||
public Product getById(Long id) {
|
||||
return productMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Product> getList(Long categoryId, String keyword) {
|
||||
return productMapper.selectList(categoryId, keyword);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Product> getRecommend() {
|
||||
return productMapper.selectRecommend();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Product> getByIds(List<Long> ids) {
|
||||
return productMapper.selectByIds(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(Product product) {
|
||||
product.setStatus(1);
|
||||
product.setSales(0);
|
||||
productMapper.insert(product);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Product product) {
|
||||
productMapper.update(product);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
productMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStock(Long id, Integer count) {
|
||||
productMapper.updateStock(id, count);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void incrementSales(Long id, Integer count) {
|
||||
productMapper.incrementSales(id, count);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.meiruo.cosmetics.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.meiruo.cosmetics.entity.User;
|
||||
import com.meiruo.cosmetics.mapper.UserMapper;
|
||||
import com.meiruo.cosmetics.service.UserService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
@Autowired
|
||||
private UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public User login(String username, String password) {
|
||||
User user = userMapper.selectByUsername(username);
|
||||
if (user == null) {
|
||||
return null;
|
||||
}
|
||||
String md5Password = DigestUtils.md5DigestAsHex(password.getBytes(StandardCharsets.UTF_8));
|
||||
if (!md5Password.equals(user.getPassword())) {
|
||||
return null;
|
||||
}
|
||||
if (user.getStatus() != 1) {
|
||||
return null;
|
||||
}
|
||||
StpUtil.login(user.getId());
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User register(User user) {
|
||||
User existUser = userMapper.selectByUsername(user.getUsername());
|
||||
if (existUser != null) {
|
||||
return null;
|
||||
}
|
||||
user.setPassword(DigestUtils.md5DigestAsHex(user.getPassword().getBytes(StandardCharsets.UTF_8)));
|
||||
user.setRole(0);
|
||||
user.setStatus(1);
|
||||
userMapper.insert(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getById(Long id) {
|
||||
return userMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getByUsername(String username) {
|
||||
return userMapper.selectByUsername(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<User> getList(String query) {
|
||||
return userMapper.selectList(query);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(User user) {
|
||||
userMapper.update(user);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delete(Long id) {
|
||||
userMapper.delete(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStatus(Long id, Integer status) {
|
||||
userMapper.updateStatus(id, status);
|
||||
}
|
||||
}
|
||||
31
meiruo-backend/src/main/resources/application.yml
Normal file
31
meiruo-backend/src/main/resources/application.yml
Normal file
@@ -0,0 +1,31 @@
|
||||
server:
|
||||
port: 8080
|
||||
|
||||
spring:
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
url: jdbc:mysql://localhost:3306/meiruo_cosmetics?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
|
||||
username: root
|
||||
password: root
|
||||
|
||||
mybatis:
|
||||
mapper-locations: classpath:mapper/*.xml
|
||||
type-aliases-package: com.meiruo.cosmetics.entity
|
||||
configuration:
|
||||
map-underscore-to-camel-case: true
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
sa-token:
|
||||
token-name: Authorization
|
||||
header: Authorization
|
||||
type: jwt
|
||||
jwt-secret-key: meiruo-cosmetics-secret-key-2024
|
||||
token-prefix: Bearer
|
||||
expiration: 2592000
|
||||
is-share: true
|
||||
is-log: true
|
||||
|
||||
pagehelper:
|
||||
helper-dialect: mysql
|
||||
reasonable: true
|
||||
support-methods-arguments: true
|
||||
52
meiruo-backend/src/main/resources/mapper/BannerMapper.xml
Normal file
52
meiruo-backend/src/main/resources/mapper/BannerMapper.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?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.meiruo.cosmetics.mapper.BannerMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.Banner">
|
||||
<id column="id" property="id"/>
|
||||
<result column="title" property="title"/>
|
||||
<result column="image" property="image"/>
|
||||
<result column="link" property="link"/>
|
||||
<result column="sort" property="sort"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT * FROM banner
|
||||
<where>
|
||||
<if test="status != null">AND status = #{status}</if>
|
||||
</where>
|
||||
ORDER BY sort ASC, create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM banner WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO banner (title, image, link, sort, status, create_time)
|
||||
VALUES (#{title}, #{image}, #{link}, #{sort}, #{status}, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE banner
|
||||
<set>
|
||||
<if test="title != null">title = #{title},</if>
|
||||
<if test="image != null">image = #{image},</if>
|
||||
<if test="link != null">link = #{link},</if>
|
||||
<if test="sort != null">sort = #{sort},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM banner WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="updateSort">
|
||||
UPDATE banner SET sort = #{sort} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
62
meiruo-backend/src/main/resources/mapper/CartMapper.xml
Normal file
62
meiruo-backend/src/main/resources/mapper/CartMapper.xml
Normal file
@@ -0,0 +1,62 @@
|
||||
<?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.meiruo.cosmetics.mapper.CartMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.Cart">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="quantity" property="quantity"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="CartWithProductResultMap" type="java.util.Map">
|
||||
<id column="id" property="id"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="quantity" property="quantity"/>
|
||||
<result column="product_name" property="productName"/>
|
||||
<result column="product_price" property="productPrice"/>
|
||||
<result column="product_image" property="productImage"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByUserAndProduct" resultMap="BaseResultMap">
|
||||
SELECT * FROM cart WHERE user_id = #{userId} AND product_id = #{productId}
|
||||
</select>
|
||||
|
||||
<select id="selectByUserId" resultMap="CartWithProductResultMap">
|
||||
SELECT c.id, c.user_id, c.product_id, c.quantity,
|
||||
p.name as product_name, p.price as product_price, p.image as product_image
|
||||
FROM cart c
|
||||
LEFT JOIN product p ON c.product_id = p.id
|
||||
WHERE c.user_id = #{userId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO cart (user_id, product_id, quantity, create_time, update_time)
|
||||
VALUES (#{userId}, #{productId}, #{quantity}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE cart
|
||||
<set>
|
||||
<if test="quantity != null">quantity = #{quantity},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM cart WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<delete id="deleteByUserId">
|
||||
DELETE FROM cart WHERE user_id = #{userId}
|
||||
</delete>
|
||||
|
||||
<update id="updateQuantity">
|
||||
UPDATE cart SET quantity = #{quantity}, update_time = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
46
meiruo-backend/src/main/resources/mapper/CategoryMapper.xml
Normal file
46
meiruo-backend/src/main/resources/mapper/CategoryMapper.xml
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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.meiruo.cosmetics.mapper.CategoryMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.Category">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="description" property="description"/>
|
||||
<result column="sort" property="sort"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM category WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT * FROM category
|
||||
<where>
|
||||
<if test="status != null">AND status = #{status}</if>
|
||||
</where>
|
||||
ORDER BY sort ASC, create_time DESC
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO category (name, description, sort, status, create_time)
|
||||
VALUES (#{name}, #{description}, #{sort}, #{status}, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE category
|
||||
<set>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="sort != null">sort = #{sort},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM category WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
33
meiruo-backend/src/main/resources/mapper/OrderItemMapper.xml
Normal file
33
meiruo-backend/src/main/resources/mapper/OrderItemMapper.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?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.meiruo.cosmetics.mapper.OrderItemMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.OrderItem">
|
||||
<id column="id" property="id"/>
|
||||
<result column="order_id" property="orderId"/>
|
||||
<result column="product_id" property="productId"/>
|
||||
<result column="product_name" property="productName"/>
|
||||
<result column="product_image" property="productImage"/>
|
||||
<result column="price" property="price"/>
|
||||
<result column="quantity" property="quantity"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectByOrderId" resultMap="BaseResultMap">
|
||||
SELECT * FROM order_item WHERE order_id = #{orderId}
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO order_item (order_id, product_id, product_name, product_image, price, quantity, create_time)
|
||||
VALUES (#{orderId}, #{productId}, #{productName}, #{productImage}, #{price}, #{quantity}, NOW())
|
||||
</insert>
|
||||
|
||||
<insert id="insertBatch">
|
||||
INSERT INTO order_item (order_id, product_id, product_name, product_image, price, quantity, create_time)
|
||||
VALUES
|
||||
<foreach collection="items" item="item" separator=",">
|
||||
(#{item.orderId}, #{item.productId}, #{item.productName}, #{item.productImage}, #{item.price}, #{item.quantity}, NOW())
|
||||
</foreach>
|
||||
</insert>
|
||||
|
||||
</mapper>
|
||||
119
meiruo-backend/src/main/resources/mapper/OrderMapper.xml
Normal file
119
meiruo-backend/src/main/resources/mapper/OrderMapper.xml
Normal file
@@ -0,0 +1,119 @@
|
||||
<?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.meiruo.cosmetics.mapper.OrderMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.Order">
|
||||
<id column="id" property="id"/>
|
||||
<result column="order_no" property="orderNo"/>
|
||||
<result column="user_id" property="userId"/>
|
||||
<result column="total_amount" property="totalAmount"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="receiver_name" property="receiverName"/>
|
||||
<result column="receiver_phone" property="receiverPhone"/>
|
||||
<result column="receiver_address" property="receiverAddress"/>
|
||||
<result column="remark" property="remark"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="pay_time" property="payTime"/>
|
||||
<result column="ship_time" property="shipTime"/>
|
||||
<result column="receive_time" property="receiveTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM `order` WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectByOrderNo" resultMap="BaseResultMap">
|
||||
SELECT * FROM `order` WHERE order_no = #{orderNo}
|
||||
</select>
|
||||
|
||||
<select id="selectByUserId" resultMap="BaseResultMap">
|
||||
SELECT * FROM `order`
|
||||
<where>
|
||||
<if test="userId != null">user_id = #{userId}</if>
|
||||
<if test="status != null">AND status = #{status}</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT * FROM `order`
|
||||
<where>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (order_no LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR receiver_name LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
<if test="status != null">AND status = #{status}</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO `order` (order_no, user_id, total_amount, status, receiver_name, receiver_phone, receiver_address, remark, create_time)
|
||||
VALUES (#{orderNo}, #{userId}, #{totalAmount}, #{status}, #{receiverName}, #{receiverPhone}, #{receiverAddress}, #{remark}, NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE `order`
|
||||
<set>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="receiverName != null">receiver_name = #{receiverName},</if>
|
||||
<if test="receiverPhone != null">receiver_phone = #{receiverPhone},</if>
|
||||
<if test="receiverAddress != null">receiver_address = #{receiverAddress},</if>
|
||||
<if test="remark != null">remark = #{remark},</if>
|
||||
<if test="payTime != null">pay_time = #{payTime},</if>
|
||||
<if test="shipTime != null">ship_time = #{shipTime},</if>
|
||||
<if test="receiveTime != null">receive_time = #{receiveTime},</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="updateStatus">
|
||||
UPDATE `order`
|
||||
<set>
|
||||
status = #{status}
|
||||
<if test="status == 2">, pay_time = NOW()</if>
|
||||
<if test="status == 3">, ship_time = NOW()</if>
|
||||
<if test="status == 4">, receive_time = NOW()</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<select id="selectRevenueStatistics" resultType="java.util.Map">
|
||||
SELECT
|
||||
<choose>
|
||||
<when test="type == 'week'">
|
||||
DATE(create_time) as date,
|
||||
</when>
|
||||
<when test="type == 'month'">
|
||||
DATE(create_time) as date,
|
||||
</when>
|
||||
<otherwise>
|
||||
DATE(create_time) as date,
|
||||
</otherwise>
|
||||
</choose>
|
||||
SUM(total_amount) as amount,
|
||||
COUNT(*) as orderCount
|
||||
FROM `order`
|
||||
WHERE status IN (2, 3, 4)
|
||||
<if test="type == 'week'">
|
||||
AND create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)
|
||||
</if>
|
||||
<if test="type == 'month'">
|
||||
AND create_time >= DATE_SUB(CURDATE(), INTERVAL 30 DAY)
|
||||
</if>
|
||||
GROUP BY DATE(create_time)
|
||||
ORDER BY date
|
||||
</select>
|
||||
|
||||
<select id="selectTopProducts" resultType="java.util.Map">
|
||||
SELECT p.id, p.name, p.image, SUM(oi.quantity) as totalSales
|
||||
FROM order_item oi
|
||||
LEFT JOIN product p ON oi.product_id = p.id
|
||||
LEFT JOIN `order` o ON oi.order_id = o.id
|
||||
WHERE o.status IN (2, 3, 4)
|
||||
GROUP BY p.id
|
||||
ORDER BY totalSales DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
81
meiruo-backend/src/main/resources/mapper/ProductMapper.xml
Normal file
81
meiruo-backend/src/main/resources/mapper/ProductMapper.xml
Normal file
@@ -0,0 +1,81 @@
|
||||
<?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.meiruo.cosmetics.mapper.ProductMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.Product">
|
||||
<id column="id" property="id"/>
|
||||
<result column="name" property="name"/>
|
||||
<result column="description" property="description"/>
|
||||
<result column="price" property="price"/>
|
||||
<result column="stock" property="stock"/>
|
||||
<result column="category_id" property="categoryId"/>
|
||||
<result column="image" property="image"/>
|
||||
<result column="images" property="images"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="sales" property="sales"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM product WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT * FROM product
|
||||
<where>
|
||||
<if test="categoryId != null">AND category_id = #{categoryId}</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (name LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR description LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
AND status = 1
|
||||
</where>
|
||||
ORDER BY sales DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectRecommend" resultMap="BaseResultMap">
|
||||
SELECT * FROM product WHERE status = 1 ORDER BY sales DESC LIMIT 10
|
||||
</select>
|
||||
|
||||
<select id="selectByIds" resultMap="BaseResultMap">
|
||||
SELECT * FROM product WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO product (name, description, price, stock, category_id, image, images, status, sales, create_time, update_time)
|
||||
VALUES (#{name}, #{description}, #{price}, #{stock}, #{categoryId}, #{image}, #{images}, #{status}, 0, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE product
|
||||
<set>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="price != null">price = #{price},</if>
|
||||
<if test="stock != null">stock = #{stock},</if>
|
||||
<if test="categoryId != null">category_id = #{categoryId},</if>
|
||||
<if test="image != null">image = #{image},</if>
|
||||
<if test="images != null">images = #{images},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM product WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="updateStock">
|
||||
UPDATE product SET stock = stock - #{count} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<update id="incrementSales">
|
||||
UPDATE product SET sales = sales + #{count} WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
70
meiruo-backend/src/main/resources/mapper/UserMapper.xml
Normal file
70
meiruo-backend/src/main/resources/mapper/UserMapper.xml
Normal file
@@ -0,0 +1,70 @@
|
||||
<?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.meiruo.cosmetics.mapper.UserMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.meiruo.cosmetics.entity.User">
|
||||
<id column="id" property="id"/>
|
||||
<result column="username" property="username"/>
|
||||
<result column="password" property="password"/>
|
||||
<result column="nickname" property="nickname"/>
|
||||
<result column="phone" property="phone"/>
|
||||
<result column="email" property="email"/>
|
||||
<result column="avatar" property="avatar"/>
|
||||
<result column="role" property="role"/>
|
||||
<result column="status" property="status"/>
|
||||
<result column="create_time" property="createTime"/>
|
||||
<result column="update_time" property="updateTime"/>
|
||||
</resultMap>
|
||||
|
||||
<select id="selectById" resultMap="BaseResultMap">
|
||||
SELECT * FROM user WHERE id = #{id}
|
||||
</select>
|
||||
|
||||
<select id="selectByUsername" resultMap="BaseResultMap">
|
||||
SELECT * FROM user WHERE username = #{username}
|
||||
</select>
|
||||
|
||||
<select id="selectByPhone" resultMap="BaseResultMap">
|
||||
SELECT * FROM user WHERE phone = #{phone}
|
||||
</select>
|
||||
|
||||
<select id="selectList" resultMap="BaseResultMap">
|
||||
SELECT * FROM user
|
||||
<where>
|
||||
<if test="query != null and query != ''">
|
||||
AND (username LIKE CONCAT('%', #{query}, '%')
|
||||
OR nickname LIKE CONCAT('%', #{query}, '%')
|
||||
OR phone LIKE CONCAT('%', #{query}, '%'))
|
||||
</if>
|
||||
</where>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<insert id="insert" useGeneratedKeys="true" keyProperty="id">
|
||||
INSERT INTO user (username, password, nickname, phone, email, avatar, role, status, create_time, update_time)
|
||||
VALUES (#{username}, #{password}, #{nickname}, #{phone}, #{email}, #{avatar}, #{role}, #{status}, NOW(), NOW())
|
||||
</insert>
|
||||
|
||||
<update id="update">
|
||||
UPDATE user
|
||||
<set>
|
||||
<if test="nickname != null">nickname = #{nickname},</if>
|
||||
<if test="phone != null">phone = #{phone},</if>
|
||||
<if test="email != null">email = #{email},</if>
|
||||
<if test="avatar != null">avatar = #{avatar},</if>
|
||||
<if test="password != null">password = #{password},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
update_time = NOW()
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
<delete id="delete">
|
||||
DELETE FROM user WHERE id = #{id}
|
||||
</delete>
|
||||
|
||||
<update id="updateStatus">
|
||||
UPDATE user SET status = #{status}, update_time = NOW() WHERE id = #{id}
|
||||
</update>
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user