refactor:商品重构提交

This commit is contained in:
Ray.Hao 2024-05-18 09:43:26 +08:00
parent 7d4ce59d11
commit 9d97580925
24 changed files with 379 additions and 230 deletions

View File

@ -11,7 +11,7 @@
Target Server Version : 80027
File Encoding : 65001
Date: 15/05/2024 22:18:32
Date: 18/05/2024 09:42:13
*/
SET NAMES utf8mb4;
@ -24,20 +24,29 @@ DROP TABLE IF EXISTS `pms_attribute`;
CREATE TABLE `pms_attribute` (
`id` bigint NOT NULL AUTO_INCREMENT,
`name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '属性名称',
`attribute_group_id` bigint NOT NULL COMMENT '属性组ID',
`type` tinyint NOT NULL COMMENT '属性类型[1-基础属性2-销售属性]',
`input_type` tinyint NOT NULL COMMENT '输入录入方式[1-手动输入2-从列表选择]',
`options` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '逗号分割的可选值列表仅当input_type是2使用',
`category_id` bigint NULL DEFAULT NULL COMMENT '分类ID',
`attribute_group_id` bigint NULL DEFAULT NULL COMMENT '属性组ID',
`type` tinyint NOT NULL COMMENT '属性类型1基础属性2销售属性',
`input_method` tinyint NOT NULL COMMENT '输入方式1手动输入2从列表选择',
`selectable_values` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '可选值列表以逗号分隔仅当输入方式为2时使用',
`category_id` bigint NOT NULL COMMENT '分类ID',
`sort` smallint NULL DEFAULT NULL COMMENT '排序',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识[0-未删除1-已删除]',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识0-未删除1-已删除)',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 9 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of pms_attribute
-- ----------------------------
INSERT INTO `pms_attribute` VALUES (1, '屏幕分辨率', 1, 1, 2, '1080P,2K,4K', 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (2, '屏幕尺寸', 1, 1, 1, NULL, 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (3, '屏幕材料', 1, 1, 1, 'LCD,AMOLED', 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (4, '摄像头像素', 2, 1, 1, NULL, 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (5, '指纹类型', 2, 1, 2, '屏下指纹,屏后指纹', 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (6, '刷新率', 2, 1, 2, '90HZ,120HZ', 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (7, '颜色', 3, 2, 1, NULL, 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
INSERT INTO `pms_attribute` VALUES (8, '存储容量', 4, 2, 2, '8+256G,12+512G,16+1T', 3, NULL, '2024-05-17 14:32:15', '2024-05-17 14:32:15', 0);
-- ----------------------------
-- Table structure for pms_attribute_group
@ -53,12 +62,15 @@ CREATE TABLE `pms_attribute_group` (
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识[0-未删除1-已删除]',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 5 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of pms_attribute_group
-- ----------------------------
INSERT INTO `pms_attribute_group` VALUES (1, '手机', 1, 1, NULL, NULL, NULL, 0);
INSERT INTO `pms_attribute_group` VALUES (1, '屏幕属性', 3, 1, NULL, NULL, NULL, 0);
INSERT INTO `pms_attribute_group` VALUES (2, '功能属性', 3, 2, NULL, NULL, NULL, 0);
INSERT INTO `pms_attribute_group` VALUES (3, '外观属性', 3, 1, NULL, NULL, NULL, 0);
INSERT INTO `pms_attribute_group` VALUES (4, '性能属性', 3, 2, NULL, NULL, NULL, 0);
-- ----------------------------
-- Table structure for pms_brand
@ -76,7 +88,7 @@ CREATE TABLE `pms_brand` (
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识[0-未删除1-已删除]',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品品牌表' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB AUTO_INCREMENT = 34 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品品牌表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pms_brand
@ -116,19 +128,19 @@ CREATE TABLE `pms_category` (
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识[0-未删除1-已删除]',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品分类表' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB AUTO_INCREMENT = 102 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品分类表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pms_category
-- ----------------------------
INSERT INTO `pms_category` VALUES (1, '手机配件', 0, NULL, NULL, 2, 1, NULL, '2022-07-07 22:56:53', 0);
INSERT INTO `pms_category` VALUES (4, '智能手机', 1, NULL, NULL, 1, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (5, '5g手机', 4, NULL, 'https://oss.youlai.tech/default/6ffb37110ac2434a9882b9e8968b2887.jpg', 1, 1, NULL, '2022-07-08 00:28:38', 0);
INSERT INTO `pms_category` VALUES (6, '电脑办公', 0, NULL, 'https://www.youlai.tech/files/default/776c21c1a71848069093033f461c5f4a.jpg', 1, 1, '2022-02-25 11:22:44', '2022-07-07 22:56:38', 0);
INSERT INTO `pms_category` VALUES (97, '笔记本电脑', 6, NULL, NULL, 100, 1, '2022-07-08 00:10:27', '2022-07-08 00:10:27', 0);
INSERT INTO `pms_category` VALUES (99, '三星轻薄本', 97, NULL, 'https://oss.youlai.tech/default/2f849b96ebb54ab3a94b1b90137f1b4d.png', 100, 1, '2022-07-08 00:14:03', '2022-07-08 00:26:52', 0);
INSERT INTO `pms_category` VALUES (100, '全能本', 97, NULL, 'https://oss.youlai.tech/default/37cc080ec61b4ce7b0583b002568ebaa.png', 100, 1, '2022-07-08 00:14:10', '2022-07-08 00:27:01', 0);
INSERT INTO `pms_category` VALUES (101, '游戏本', 97, NULL, 'https://oss.youlai.tech/default/5c1a2d5427534b48bc382caa55197f11.png', 100, 1, '2022-07-08 00:14:18', '2022-07-08 00:27:11', 0);
INSERT INTO `pms_category` VALUES (1, '手机配件', 0, NULL, NULL, 1, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (2, '智能手机', 1, NULL, NULL, 1, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (3, '5g手机', 2, NULL, 'https://oss.youlai.tech/default/6ffb37110ac2434a9882b9e8968b2887.jpg', 1, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (10, '电脑办公', 0, NULL, 'https://www.youlai.tech/files/default/776c21c1a71848069093033f461c5f4a.jpg', 2, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (97, '笔记本电脑', 6, NULL, NULL, 1, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (99, '轻薄本', 97, NULL, 'https://oss.youlai.tech/default/2f849b96ebb54ab3a94b1b90137f1b4d.png', 1, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (100, '全能本', 97, NULL, 'https://oss.youlai.tech/default/37cc080ec61b4ce7b0583b002568ebaa.png', 2, 1, NULL, NULL, 0);
INSERT INTO `pms_category` VALUES (101, '游戏本', 97, NULL, 'https://oss.youlai.tech/default/5c1a2d5427534b48bc382caa55197f11.png', 3, 1, NULL, NULL, 0);
-- ----------------------------
-- Table structure for pms_sku
@ -141,23 +153,22 @@ CREATE TABLE `pms_sku` (
`name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '商品名称',
`price` bigint NOT NULL COMMENT '商品价格(单位:分)',
`stock` int UNSIGNED NOT NULL COMMENT '库存数量',
`locked_stock` int NULL DEFAULT NULL COMMENT '库存锁定数量',
`locked_stock` int NULL DEFAULT 0 COMMENT '库存锁定数量',
`img_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'SKU 图片URL',
`create_time` datetime NULL DEFAULT NULL COMMENT '创建时间',
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识[0-未删除1-已删除]',
PRIMARY KEY (`id`) USING BTREE,
INDEX `fk_pms_sku_pms_spu`(`spu_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 758 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品库存表' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB AUTO_INCREMENT = 759 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品库存表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pms_sku
-- ----------------------------
INSERT INTO `pms_sku` VALUES (1, 'sn001', 288, '绿色', 699900, 100, 150, 'https://www.youlai.tech/files/default/c25b39470474494485633c49101a0f5d.png', '2021-08-08 00:43:26', '2024-05-08 10:51:34', 1);
INSERT INTO `pms_sku` VALUES (755, NULL, 288, '绿色 64GB', 699900, 100, NULL, NULL, '2024-05-08 10:54:43', '2024-05-08 10:54:43', 0);
INSERT INTO `pms_sku` VALUES (756, NULL, 290, '绿色 64GB', 699900, 100, NULL, NULL, '2024-05-08 10:58:20', '2024-05-08 16:22:56', 1);
INSERT INTO `pms_sku` VALUES (757, NULL, 290, '绿色 64GB', 699900, 100, NULL, NULL, '2024-05-08 16:22:56', '2024-05-08 16:22:56', 0);
INSERT INTO `pms_sku` VALUES (758, NULL, 290, '灰色 64GB', 699900, 100, NULL, NULL, '2024-05-08 16:22:57', '2024-05-08 16:22:57', 0);
INSERT INTO `pms_sku` VALUES (1, 'sn001', 1, '白色 8+256G', 699900, 100, 0, 'https://www.youlai.tech/files/default/c25b39470474494485633c49101a0f5d.png', '2021-08-08 00:43:26', '2024-05-08 10:51:34', 0);
INSERT INTO `pms_sku` VALUES (2, 'sn002', 1, '黑色 8+256G', 699900, 100, 0, 'https://www.youlai.tech/files/default/c25b39470474494485633c49101a0f5d.png', '2024-05-08 10:54:43', '2024-05-08 10:54:43', 0);
INSERT INTO `pms_sku` VALUES (3, 'sn003', 1, '白色 12+512G', 799900, 100, 0, 'https://www.youlai.tech/files/default/c25b39470474494485633c49101a0f5d.png', '2021-08-08 00:43:26', '2024-05-08 10:51:34', 0);
INSERT INTO `pms_sku` VALUES (4, 'sn004', 1, '黑色 12+512G', 799900, 100, 0, 'https://www.youlai.tech/files/default/c25b39470474494485633c49101a0f5d.png', '2021-08-08 00:43:26', '2024-05-08 10:51:34', 0);
-- ----------------------------
-- Table structure for pms_sku_attribute_value
@ -166,19 +177,23 @@ DROP TABLE IF EXISTS `pms_sku_attribute_value`;
CREATE TABLE `pms_sku_attribute_value` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '销售属性ID',
`sku_id` bigint NULL DEFAULT NULL COMMENT 'SKU ID',
`attr_id` bigint NULL DEFAULT NULL COMMENT '属性 ID',
`attr_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '属性名称',
`attr_value` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '属性值',
`attribute_id` bigint NULL DEFAULT NULL COMMENT '属性 ID',
`attribute_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '属性名称',
`attribute_value` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '属性值',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 10 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 11 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of pms_sku_attribute_value
-- ----------------------------
INSERT INTO `pms_sku_attribute_value` VALUES (7, 757, 1, '颜色', '绿色');
INSERT INTO `pms_sku_attribute_value` VALUES (8, 757, 2, '内存', '64GB');
INSERT INTO `pms_sku_attribute_value` VALUES (9, 758, 1, '颜色', '灰色');
INSERT INTO `pms_sku_attribute_value` VALUES (10, 758, 2, '内存', '64GB');
INSERT INTO `pms_sku_attribute_value` VALUES (1, 1, 7, '颜色', '白色');
INSERT INTO `pms_sku_attribute_value` VALUES (2, 1, 8, '存储容量', '8+256G');
INSERT INTO `pms_sku_attribute_value` VALUES (3, 2, 7, '颜色', '黑色');
INSERT INTO `pms_sku_attribute_value` VALUES (4, 2, 8, '存储容量', '8+256G');
INSERT INTO `pms_sku_attribute_value` VALUES (5, 3, 7, '颜色', '白色');
INSERT INTO `pms_sku_attribute_value` VALUES (6, 3, 8, '存储容量', '12+512G');
INSERT INTO `pms_sku_attribute_value` VALUES (7, 4, 7, '颜色', '黑色');
INSERT INTO `pms_sku_attribute_value` VALUES (8, 4, 8, '存储容量', '12+512G');
-- ----------------------------
-- Table structure for pms_spu
@ -199,14 +214,12 @@ CREATE TABLE `pms_spu` (
PRIMARY KEY (`id`) USING BTREE,
INDEX `fk_pms_spu_pms_brand`(`brand_id`) USING BTREE,
INDEX `fk_pms_spu_pms_category`(`category_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 290 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品表' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB AUTO_INCREMENT = 291 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pms_spu
-- ----------------------------
INSERT INTO `pms_spu` VALUES (1, '小米13', 1, 5, 10, 'https://oss.youlai.tech/youlai-boot/2023/06/08/6b83dd33eaa248ed8e11cff0003287ee.jpg', '', '好快,好稳,\n好一次强上加强。\n高通全新一代芯片赋能速度大幅提升。\n三大专业主摄影像加持能力全面进化。\n大师级设计理念新诠释质感简而不凡。\n斩获十五项纪录旗舰屏感官万般出众。', NULL, '2022-07-03 14:16:16', 0);
INSERT INTO `pms_spu` VALUES (288, 'Apple iPhone 12', 1, 1, 1, 'https://youlai-mall.oss-cn-shenzhen.aliyuncs.com/images/2021/04/23/1619163660000.jpg', '', 'Apple iPhone 12 64GB 绿色', '2024-05-07 17:35:42', '2024-05-08 10:54:43', 0);
INSERT INTO `pms_spu` VALUES (290, 'Apple iPhone 12', 1, 1, 1, 'https://youlai-mall.oss-cn-shenzhen.aliyuncs.com/images/2021/04/23/1619163660000.jpg', '', 'Apple iPhone 12 64GB 绿色', '2024-05-08 10:58:19', '2024-05-08 16:22:55', 0);
INSERT INTO `pms_spu` VALUES (1, '小米14', 1, 3, 10, 'https://oss.youlai.tech/youlai-boot/2023/06/08/6b83dd33eaa248ed8e11cff0003287ee.jpg', '', '好快,好稳,\n好一次强上加强。\n高通全新一代芯片赋能速度大幅提升。\n三大专业主摄影像加持能力全面进化。\n大师级设计理念新诠释质感简而不凡。\n斩获十五项纪录旗舰屏感官万般出众。', '2024-05-17 13:38:53', '2022-07-03 14:16:16', 0);
-- ----------------------------
-- Table structure for pms_spu_attribute_value
@ -215,19 +228,23 @@ DROP TABLE IF EXISTS `pms_spu_attribute_value`;
CREATE TABLE `pms_spu_attribute_value` (
`id` bigint NOT NULL AUTO_INCREMENT COMMENT '基础属性ID',
`spu_id` bigint NOT NULL COMMENT 'SPU ID',
`attr_id` bigint NULL DEFAULT NULL COMMENT '属性ID',
`attr_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '属性名称',
`attr_value` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '属性值',
`attribute_id` bigint NULL DEFAULT NULL COMMENT '属性ID',
`attribute_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '属性名称',
`attribute_value` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '属性值',
PRIMARY KEY (`id`) USING BTREE,
INDEX `fk_pms_spu_attribute_pms_attr`(`attr_name`) USING BTREE,
INDEX `fk_pms_spu_attribute_pms_attr`(`attribute_name`) USING BTREE,
INDEX `fk_pms_spu_attribute_pms_spu`(`spu_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 850 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品属性/规格表' ROW_FORMAT = DYNAMIC;
) ENGINE = InnoDB AUTO_INCREMENT = 851 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci COMMENT = '商品属性/规格表' ROW_FORMAT = DYNAMIC;
-- ----------------------------
-- Records of pms_spu_attribute_value
-- ----------------------------
INSERT INTO `pms_spu_attribute_value` VALUES (848, 288, 1, '上市时间', '2024-05-08');
INSERT INTO `pms_spu_attribute_value` VALUES (850, 290, 1, '上市时间', '2024-05-08');
INSERT INTO `pms_spu_attribute_value` VALUES (1, 1, 1, '屏幕分辨率', '2K');
INSERT INTO `pms_spu_attribute_value` VALUES (2, 1, 2, '屏幕尺寸', '6英寸');
INSERT INTO `pms_spu_attribute_value` VALUES (3, 1, 3, '屏幕材料', '123');
INSERT INTO `pms_spu_attribute_value` VALUES (4, 1, 4, '摄像头像素', '5000万');
INSERT INTO `pms_spu_attribute_value` VALUES (5, 1, 5, '指纹类型', '屏下指纹');
INSERT INTO `pms_spu_attribute_value` VALUES (6, 1, 6, '刷新率', '150HZ');
-- ----------------------------
-- Table structure for pms_spu_detail
@ -241,7 +258,7 @@ CREATE TABLE `pms_spu_detail` (
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除[0-未删除1-已删除]',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 2 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品详情' ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品详情' ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of pms_spu_detail
@ -262,7 +279,7 @@ CREATE TABLE `pms_spu_image` (
`update_time` datetime NULL DEFAULT NULL COMMENT '更新时间',
`is_deleted` tinyint NOT NULL DEFAULT 0 COMMENT '逻辑删除标识0-未删除1-已删除',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 6 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
) ENGINE = InnoDB AUTO_INCREMENT = 7 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of pms_spu_image

View File

@ -3,7 +3,6 @@ package com.youlai.mall.product.controller.admin;
import com.youlai.common.result.Result;
import com.youlai.common.web.model.Option;
import com.youlai.mall.product.model.form.CategoryForm;
import com.youlai.mall.product.model.query.CategoryQuery;
import com.youlai.mall.product.model.vo.CategoryVO;
import com.youlai.mall.product.service.CategoryService;
import io.swagger.v3.oas.annotations.Operation;

View File

@ -20,7 +20,7 @@ import java.util.List;
*/
@Tag(name = "App-商品库存接口")
@RestController
@RequestMapping("/app-api/v1/skus")
@RequestMapping("/app-api/v1/stocks")
@RequiredArgsConstructor
public class AppSkuController {

View File

@ -7,7 +7,7 @@ import com.youlai.mall.product.model.query.SpuPageQuery;
import com.youlai.mall.product.model.vo.SeckillingSpuVO;
import com.youlai.mall.product.model.vo.SpuDetailVO;
import com.youlai.mall.product.model.vo.SpuPageVO;
import com.youlai.mall.product.service.SpuService;
import com.youlai.mall.product.service.app.ProductService;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
@ -21,16 +21,16 @@ import java.util.List;
@Tag(name = "App-商品接口")
@RestController
@RequestMapping("/app-api/v1/spu")
@RequestMapping("/app-api/v1/product")
@RequiredArgsConstructor
public class AppSpuController {
public class ProductController {
private final SpuService spuService;
private final ProductService productService;
@Operation(summary = "商品分页列表")
@GetMapping("/pages")
@GetMapping("/page")
public PageResult<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams) {
IPage<SpuPageVO> result = spuService.listPagedSpuForApp(queryParams);
IPage<SpuPageVO> result = productService.listPagedSpuForApp(queryParams);
return PageResult.success(result);
}
@ -39,15 +39,8 @@ public class AppSpuController {
public Result<SpuDetailVO> getSpuDetail(
@Parameter(description ="商品ID") @PathVariable Long spuId
) {
SpuDetailVO spuDetailVO = spuService.getSpuDetailForApp(spuId);
SpuDetailVO spuDetailVO = productService.getSpuDetailForApp(spuId);
return Result.success(spuDetailVO);
}
@Operation(summary = "获取秒杀商品列表")
@GetMapping("/seckilling")
public Result<List<SeckillingSpuVO>> listSeckillingSpu() {
List<SeckillingSpuVO> list = spuService.listSeckillingSpu();
return Result.success(list);
}
}

View File

@ -9,6 +9,7 @@ import lombok.Getter;
* @author Ray Hao
* @since 2024/4/19
*/
@Getter
public enum AttributeInputTypeEnum implements IBaseEnum<Integer> {
MANUAL(1, "手动录入"),
@ -18,12 +19,10 @@ public enum AttributeInputTypeEnum implements IBaseEnum<Integer> {
this.value = value;
this.label = label;
}
@Getter
// @EnumValue // Mybatis-Plus 提供注解表示插入数据库时插入该值
private Integer value;
private final Integer value;
@Getter
// @JsonValue // 表示对枚举序列化时返回此字段
private String label;
private final String label;
}

View File

@ -4,25 +4,24 @@ import com.youlai.common.base.IBaseEnum;
import lombok.Getter;
/**
* 商品属性类型枚举
* 枚举类商品属性类型
*
* @author haoxr
* @since 2022/12/20
*/
@Getter
public enum AttributeTypeEnum implements IBaseEnum<Integer> {
BASE_ATTRIBUTE(1, "基础属性"), // 重量产地上市时间等
SALE_ATTRIBUTE(2, "销售属性"); // 影响价格的属性如颜色内存等
BASE_ATTRIBUTE(1, "基础属性"), // 例如重量产地上市时间等
SALE_ATTRIBUTE(2, "销售属性"); // 影响价格的属性如颜色内存等
AttributeTypeEnum(int value, String label) {
this.value = value;
this.label = label;
}
@Getter
private Integer value;
private final Integer value;
@Getter
private String label;
private final String label;
}

View File

@ -1,10 +0,0 @@
package com.youlai.mall.product.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.product.model.entity.SpuAttributeValue;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface SpuAttributeMapper extends BaseMapper<SpuAttributeValue> {
}

View File

@ -0,0 +1,23 @@
package com.youlai.mall.product.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.youlai.mall.product.model.entity.SpuAttributeValue;
import com.youlai.mall.product.model.form.SpuForm;
import org.apache.ibatis.annotations.Mapper;
import java.util.List;
/**
* SPU属性值 Mapper
*/
@Mapper
public interface SpuAttributeValueMapper extends BaseMapper<SpuAttributeValue> {
/**
* 根据SPU ID查询属性组&属性列表
*
* @param spuId SPU ID
* @return 属性列表
*/
List<SpuForm.AttributeGroup> listAttributeGroupsBySpuId(Long spuId);
}

View File

@ -27,18 +27,18 @@ public class Attribute extends BaseEntity {
private String name;
/**
* 属性类型1-规格2-参数
* 属性类型1基础属性2销售属性
* @see com.youlai.mall.product.enums.AttributeTypeEnum
*/
private Integer type;
/**
* 输入录入方式1-手动输入2-从列表选择
* 输入方式1手动输入2从列表选择
*/
private Integer inputType;
private Integer inputMethod;
/**
* 逗号分割的可选值列表仅当input_type是2使用
* 可选值列表以逗号分隔仅当输入方式为2时使用
*/
private String options;
private String selectableValues;
}

View File

@ -36,15 +36,15 @@ public class SkuAttributeValue implements Serializable {
/**
* 规格属性ID
*/
private Long attrId;
private Long attributeId;
/**
* 规格属性名称
*/
private String attrName;
private String attributeName;
/**
* 规格属性值
*/
private String attrValue;
private String attributeValue;
}

View File

@ -40,16 +40,16 @@ public class SpuAttributeValue implements Serializable {
/**
* 属性ID
*/
private Long attrId;
private Long attributeId;
/**
* 属性名称
*/
private String attrName;
private String attributeName;
/**
* 属性值
*/
private String attrValue;
private String attributeValue;
}

View File

@ -5,7 +5,6 @@ import lombok.Getter;
import lombok.Setter;
import java.io.Serializable;
import java.time.LocalDateTime;
/**
* 属性组表单对象
@ -32,8 +31,7 @@ public class AttributeGroupForm implements Serializable {
@Schema(description = "备注")
private String remark;
@Schema(description = "创建时间")
private LocalDateTime createTime;
@Schema(description = "分类ID")
private Long categoryId;
}

View File

@ -44,13 +44,13 @@ public class SpuForm {
@Schema(description = "商品详情", example = "<p>Apple iPhone 12 64GB 绿色</p>")
private String detail;
@Schema(description = "商品属性列表(仅返回用,提交时不填)", example = "[{\"attrId\":1,\"attrName\":\"颜色\",\"attrValues\":[\"红色\",\"绿色\"]}]")
private List<Attribute> attributes;
@Schema(description = "商品属性列表(仅返回用,提交时不填)", example = "[{\"attributeId\":1,\"attributeName\":\"颜色\",\"attributeValues\":[\"红色\",\"绿色\"]}]")
private List<SaleAttribute> saleAttributes;
@Schema(description = "商品基础属性值", example = "[{\"attrId\":1,\"attrName\":\"上市时间\",\"attrValue\":\"2024-05-08\"}]")
private List<AttributeValue> baseAttributeValues;
@Schema(description = "基础属性分组列表(仅返回用,提交时不填)", example = "[{\"attributeGroupId\":1,\"attributeGroupName\":\"基础属性\",\"attributeAttributeValues\":[{\"id\":1,\"attributeId\":1,\"attributeName\":\"颜色\",\"attributeValue\":\"红色\"}]}]")
private List<AttributeGroup> attributeGroups;
@Schema(description = "SKU列表", example = "[{\"name\":\"绿色 64GB\",\"price\":699900,\"stock\":100,\"imgUrl\":\"https://youlai-mall.oss-cn-shenzhen.aliyuncs.com/images/2021/04/23/1619163660000.jpg\",\"saleAttributeValues\":[{\"attrName\":\"颜色\",\"attrValue\":\"绿色\",\"attrId\":1},{\"attrName\":\"内存\",\"attrValue\":\"64GB\",\"attrId\":2}]}]")
@Schema(description = "SKU列表", example = "[{\"name\":\"绿色 64GB\",\"price\":699900,\"stock\":100,\"imgUrl\":\"https://youlai-mall.oss-cn-shenzhen.aliyuncs.com/images/2021/04/23/1619163660000.jpg\",\"saleAttributeValues\":[{\"attributeName\":\"颜色\",\"attributeValue\":\"绿色\",\"attributeId\":1},{\"attributeName\":\"内存\",\"attributeValue\":\"64GB\",\"attributeId\":2}]}]")
private List<Sku> skuList;
@Schema(description = "商品图片")
@ -68,6 +68,21 @@ public class SpuForm {
}
@Schema(description = "属性分组")
@Data
public static class AttributeGroup {
@Schema(description = "属性分组ID")
private Long attributeGroupId;
@Schema(description = "属性分组名称")
private String attributeGroupName;
@Schema(description = "属性列表")
private List<AttributeValue> attributeValues;
}
@Schema(description = "属性值对象")
@Data
public static class AttributeValue {
@ -76,13 +91,13 @@ public class SpuForm {
private Long id;
@Schema(description = "属性ID")
private Long attrId;
private Long attributeId;
@Schema(description = "属性名称")
private String attrName;
private String attributeName;
@Schema(description = "属性值")
private String attrValue;
private String attributeValue;
}
@ -110,17 +125,17 @@ public class SpuForm {
}
@Schema(description = "属性")
@Schema(description = "销售属性")
@Data
public static class Attribute {
public static class SaleAttribute {
@Schema(description = "属性ID", example = "1")
private Long attrId;
private Long attributeId;
@Schema(description = "属性名称", example = "颜色")
private String attrName;
private String attributeName;
@Schema(description = "属性值列表", example = "[\"红色\",\"绿\"]")
private List<String> attrValues;
@Schema(description = "属性值列表", example = "[\"白色\",\"\"]")
private List<String> attributeValues;
}
}

View File

@ -1,13 +1,10 @@
package com.youlai.mall.product.model.query;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.youlai.common.base.BasePageQuery;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
/**
* 属性组分页查询对象
*

View File

@ -20,6 +20,13 @@ public interface SpuAttributeValueService extends IService<SpuAttributeValue> {
* @param spuId SPU ID
* @param attributeList 属性列表
*/
void saveSpuAttributes(Long spuId, List<SpuForm.AttributeValue> attributeList);
void saveSpuAttributes(Long spuId, List<SpuForm.AttributeGroup> attributeList);
/**
* 根据SPU ID查询属性组&属性列表
*
* @param spuId SPU ID
* @return 商品属性列表
*/
List<SpuForm.AttributeGroup> listAttributeGroupsBySpuId(Long spuId);
}

View File

@ -26,22 +26,6 @@ public interface SpuService extends IService<Spu> {
*/
IPage<PmsSpuPageVO> listPagedSpu(SpuPageQuery queryParams);
/**
* 应用端商品分页列表
*
* @param queryParams
* @return
*/
IPage<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams);
/**
* 应用端获取商品详情
*
* @param spuId
* @return
*/
SpuDetailVO getSpuDetailForApp(Long spuId);
/**
@ -60,7 +44,6 @@ public interface SpuService extends IService<Spu> {
*/
SpuForm getSpuForm(Long spuId);
/**
* 删除商品
*
@ -69,13 +52,5 @@ public interface SpuService extends IService<Spu> {
*/
boolean removeBySpuIds(String ids);
/**
* 获取秒杀商品列表
* TODO
*
* @return
*/
List<SeckillingSpuVO> listSeckillingSpu();
}

View File

@ -0,0 +1,36 @@
package com.youlai.mall.product.service.app;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.youlai.mall.product.model.entity.Spu;
import com.youlai.mall.product.model.query.SpuPageQuery;
import com.youlai.mall.product.model.vo.SpuDetailVO;
import com.youlai.mall.product.model.vo.SpuPageVO;
/**
* 商品服务
*
* @author haoxr
* @since 2022/2/5
*/
public interface ProductService extends IService<Spu> {
/**
* 应用端商品分页列表
*
* @param queryParams
* @return
*/
IPage<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams);
/**
* 应用端获取商品详情
*
* @param spuId
* @return
*/
SpuDetailVO getSpuDetailForApp(Long spuId);
}

View File

@ -0,0 +1,7 @@
package com.youlai.mall.product.service.app;
public interface StockService {
}

View File

@ -0,0 +1,71 @@
package com.youlai.mall.product.service.app.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.product.mapper.SpuMapper;
import com.youlai.mall.product.model.entity.Spu;
import com.youlai.mall.product.model.query.SpuPageQuery;
import com.youlai.mall.product.model.vo.SeckillingSpuVO;
import com.youlai.mall.product.model.vo.SpuDetailVO;
import com.youlai.mall.product.model.vo.SpuPageVO;
import com.youlai.mall.product.service.app.ProductService;
import org.springframework.stereotype.Service;
import java.util.List;
/**
* 商品服务实现类
*
* @author haoxr
* @since 2024/5/17
*/
@Service
public class ProductServiceImpl extends ServiceImpl<SpuMapper, Spu> implements ProductService {
/**
* APP-商品分页列表
*
* @param queryParams 查询参数
* @return 商品分页列表 IPage<SpuPageVO>
*/
@Override
public IPage<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams) {
Page<SpuPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
List<SpuPageVO> list = this.baseMapper.listPagedSpuForApp(page, queryParams);
page.setRecords(list);
return page;
}
/**
* App-获取商品详情
*
* @param spuId 商品ID
* @return 商品详情
*/
@Override
public SpuDetailVO getSpuDetailForApp(Long spuId) {
SpuDetailVO spuDetailVO = new SpuDetailVO();
return spuDetailVO;
}
/**
* 获取商品秒杀接口
*
* @return 商品秒杀列表
*/
@Override
public List<SeckillingSpuVO> listSeckillingSpu() {
List<Spu> entities = this.list(new LambdaQueryWrapper<Spu>()
.select(Spu::getId, Spu::getName, Spu::getImgUrl)
.orderByDesc(Spu::getCreateTime)
);
return spuConverter.entity2SeckillingVO(entities);
}
}

View File

@ -0,0 +1,22 @@
package com.youlai.mall.product.service.app.impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.product.mapper.SkuMapper;
import com.youlai.mall.product.model.entity.Sku;
import com.youlai.mall.product.service.app.StockService;
import org.springframework.stereotype.Service;
/**
* 商品服务实现类
*
* @author haoxr
* @since 2024/5/17
*/
@Service
public class StockServiceImpl extends ServiceImpl<SkuMapper, Sku> implements StockService {
}

View File

@ -4,7 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.youlai.mall.product.converter.SpuAttributeValueConverter;
import com.youlai.mall.product.mapper.SpuAttributeMapper;
import com.youlai.mall.product.mapper.SpuAttributeValueMapper;
import com.youlai.mall.product.model.entity.SpuAttributeValue;
import com.youlai.mall.product.model.form.SpuForm;
import com.youlai.mall.product.service.SpuAttributeValueService;
@ -25,30 +25,34 @@ import java.util.stream.Collectors;
*/
@Service
@RequiredArgsConstructor
public class SpuAttributeValueServiceImpl extends ServiceImpl<SpuAttributeMapper, SpuAttributeValue> implements SpuAttributeValueService {
public class SpuAttributeValueServiceImpl extends ServiceImpl<SpuAttributeValueMapper, SpuAttributeValue> implements SpuAttributeValueService {
private final SpuAttributeValueConverter spuAttributeValueConverter;
/**
* 保存商品属性
*
* @param spuId SPU ID
* @param formAttributes 属性列表
* @param spuId SPU ID
* @param attributeGroupList 属性组列表
*/
@Override
public void saveSpuAttributes(Long spuId, List<SpuForm.AttributeValue> formAttributes) {
public void saveSpuAttributes(Long spuId, List<SpuForm.AttributeGroup> attributeGroupList) {
// 如果属性列表为空则删除所有旧属性
if (CollectionUtil.isEmpty(formAttributes)) {
if (CollectionUtil.isEmpty(attributeGroupList)) {
this.remove(new LambdaQueryWrapper<SpuAttributeValue>().eq(SpuAttributeValue::getSpuId, spuId));
} else {
// 获取当前数据库中的属性
Map<Long, SpuAttributeValue> existingAttributes = this.list(new LambdaQueryWrapper<SpuAttributeValue>()
.eq(SpuAttributeValue::getSpuId, spuId))
.stream().collect(Collectors.toMap(SpuAttributeValue::getId, Function.identity()));
return;
}
List<SpuAttributeValue> attributesToSave = new ArrayList<>();
for (SpuForm.AttributeValue formAttribute : formAttributes) {
// 获取当前数据库中的属性
Map<Long, SpuAttributeValue> existingAttributes = this.list(new LambdaQueryWrapper<SpuAttributeValue>()
.eq(SpuAttributeValue::getSpuId, spuId))
.stream().collect(Collectors.toMap(SpuAttributeValue::getId, Function.identity()));
List<SpuAttributeValue> attributesToSave = new ArrayList<>();
// 遍历属性组并处理属性值
for (SpuForm.AttributeGroup attributeGroup : attributeGroupList) {
for (SpuForm.AttributeValue formAttribute : attributeGroup.getAttributeValues()) {
SpuAttributeValue newAttr = spuAttributeValueConverter.convertToEntity(formAttribute);
newAttr.setSpuId(spuId);
@ -59,16 +63,27 @@ public class SpuAttributeValueServiceImpl extends ServiceImpl<SpuAttributeMapper
attributesToSave.add(newAttr);
}
}
// 删除不再存在的属性
if (!existingAttributes.isEmpty()) {
this.removeByIds(existingAttributes.keySet());
}
// 删除不再存在的属性
if (!existingAttributes.isEmpty()) {
this.removeByIds(existingAttributes.keySet());
}
// 保存所有属性
if (!attributesToSave.isEmpty()) {
this.saveOrUpdateBatch(attributesToSave);
}
// 保存或更新所有属性
if (!attributesToSave.isEmpty()) {
this.saveOrUpdateBatch(attributesToSave);
}
}
/**
* 根据SPU ID获取商品属性列表
*
* @param spuId SPU ID
* @return 商品属性列表
*/
@Override
public List<SpuForm.AttributeGroup> listAttributeGroupsBySpuId(Long spuId) {
return this.baseMapper.listAttributeGroupsBySpuId(spuId);
}
}

View File

@ -28,11 +28,10 @@ public class SpuImageServiceImpl extends ServiceImpl<SpuImageMapper, SpuImage> i
private final SpuImageConverter spuImageConverter;
/**
* 保存商品图册
*
* @param spuId 商品ID
* @param spuId 商品ID
* @param formImages 商品图册
*/
@ -46,14 +45,13 @@ public class SpuImageServiceImpl extends ServiceImpl<SpuImageMapper, SpuImage> i
List<SpuImage> newImages = spuImageConverter.convertToEntity(formImages);
if (CollectionUtil.isNotEmpty(newImages)) {
// 新增图片处理
List<SpuImage> addImages = newImages.stream()
.filter(item -> item.getId() == null)
.peek(item -> item.setSpuId(spuId))
.toList();
if(CollectionUtil.isNotEmpty(addImages)){
if (CollectionUtil.isNotEmpty(addImages)) {
this.saveBatch(addImages);
}

View File

@ -55,34 +55,6 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuSe
return page;
}
/**
* APP-商品分页列表
*
* @param queryParams 查询参数
* @return 商品分页列表 IPage<SpuPageVO>
*/
@Override
public IPage<SpuPageVO> listPagedSpuForApp(SpuPageQuery queryParams) {
Page<SpuPageVO> page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize());
List<SpuPageVO> list = this.baseMapper.listPagedSpuForApp(page, queryParams);
page.setRecords(list);
return page;
}
/**
* App-获取商品详情
*
* @param spuId 商品ID
* @return 商品详情
*/
@Override
public SpuDetailVO getSpuDetailForApp(Long spuId) {
SpuDetailVO spuDetailVO = new SpuDetailVO();
return spuDetailVO;
}
/**
* 保存商品
*
@ -102,8 +74,8 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuSe
List<SpuForm.Image> imgList = formData.getImgList();
spuImageService.saveSpuImages(spuId, imgList);
// 保存商品属性
List<SpuForm.AttributeValue> attributeList = formData.getBaseAttributeValues();
spuAttributeValueService.saveSpuAttributes(spuId, attributeList);
List<SpuForm.AttributeGroup> attributeGroupList = formData.getAttributeGroups();
spuAttributeValueService.saveSpuAttributes(spuId, attributeGroupList);
// 保存 SKU
List<SpuForm.Sku> skuList = formData.getSkuList();
skuService.saveSkus(spuId, skuList);
@ -146,17 +118,10 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuSe
}
// 商品基础属性
List<SpuForm.AttributeValue> baseAttributeValues = spuAttributeValueService.list(new LambdaQueryWrapper<SpuAttributeValue>()
.eq(SpuAttributeValue::getSpuId, spuId))
.stream().map(item -> {
SpuForm.AttributeValue attribute = new SpuForm.AttributeValue();
BeanUtil.copyProperties(item, attribute);
return attribute;
}).toList();
spuForm.setBaseAttributeValues(baseAttributeValues);
List<SpuForm.AttributeGroup> attributeGroups = spuAttributeValueService.listAttributeGroupsBySpuId(spuId);
spuForm.setAttributeGroups(attributeGroups);
List<Sku> skuList = skuService.list(new LambdaQueryWrapper<Sku>().eq(Sku::getSpuId, spuId));
if (CollectionUtil.isNotEmpty(skuList)) {
List<Long> skuIds = skuList.stream().map(Sku::getId).toList();
List<SkuAttributeValue> skuAttributeValueList = skuAttributeValueService.list(new LambdaQueryWrapper<SkuAttributeValue>()
@ -181,20 +146,20 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuSe
spuForm.setSkuList(skus);
// 转换销售属性为商品属性
Map<Long, SpuForm.Attribute> attributeMap = new HashMap<>();
Map<Long, SpuForm.SaleAttribute> attributeMap = new HashMap<>();
for (SkuAttributeValue skuAttrValue : skuAttributeValueList) {
SpuForm.Attribute attribute = attributeMap.computeIfAbsent(skuAttrValue.getAttrId(), k -> {
SpuForm.Attribute newAttr = new SpuForm.Attribute();
newAttr.setAttrId(k);
newAttr.setAttrName(skuAttrValue.getAttrName());
newAttr.setAttrValues(new ArrayList<>());
SpuForm.SaleAttribute attribute = attributeMap.computeIfAbsent(skuAttrValue.getAttributeId(), k -> {
SpuForm.SaleAttribute newAttr = new SpuForm.SaleAttribute();
newAttr.setAttributeId(k);
newAttr.setAttributeName(skuAttrValue.getAttributeName());
newAttr.setAttributeValues(new ArrayList<>());
return newAttr;
});
if (!attribute.getAttrValues().contains(skuAttrValue.getAttrValue())) {
attribute.getAttrValues().add(skuAttrValue.getAttrValue());
if (!attribute.getAttributeValues().contains(skuAttrValue.getAttributeValue())) {
attribute.getAttributeValues().add(skuAttrValue.getAttributeValue());
}
}
spuForm.setAttributes(new ArrayList<>(attributeMap.values()));
spuForm.setSaleAttributes(new ArrayList<>(attributeMap.values()));
}
return spuForm;
}
@ -225,19 +190,6 @@ public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements SpuSe
return true;
}
/**
* 获取商品秒杀接口
*
* @return 商品秒杀列表
*/
@Override
public List<SeckillingSpuVO> listSeckillingSpu() {
List<Spu> entities = this.list(new LambdaQueryWrapper<Spu>()
.select(Spu::getId, Spu::getName, Spu::getImgUrl)
.orderByDesc(Spu::getCreateTime)
);
return spuConverter.entity2SeckillingVO(entities);
}
}

View File

@ -0,0 +1,36 @@
<?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.youlai.mall.product.mapper.SpuAttributeValueMapper">
<!-- 定义属性组&属性列表的结果集 -->
<resultMap id="AttributeGroupMap" type="com.youlai.mall.product.model.form.SpuForm$AttributeGroup">
<result column="attribute_group_id" property="attributeGroupId"/>
<result column="attribute_group_name" property="attributeGroupName"/>
<collection property="attributeValues" ofType="com.youlai.mall.product.model.form.SpuForm$AttributeValue" javaType="java.util.List">
<result column="attribute_id" property="attributeId"/>
<result column="attribute_name" property="attributeName"/>
<result column="attribute_value" property="attributeValue"/>
</collection>
</resultMap>
<!-- 根据SPU ID查询属性组&属性列表 -->
<select id="listAttributeGroupsBySpuId" resultMap="AttributeGroupMap">
SELECT
psav.attribute_id,
psav.attribute_name,
psav.attribute_value,
pag.NAME attribute_group_name,
pag.id attribute_group_id
FROM
pms_spu_attribute_value psav
LEFT JOIN pms_attribute pa ON psav.attribute_id = pa.id
LEFT JOIN pms_attribute_group pag ON pa.attribute_group_id = pag.id
WHERE
psav.spu_id = #{spuId}
ORDER BY
pag.sort ASC,
pa.sort ASC
</select>
</mapper>