From 9d975809257632adff24a9bea46cfb4360e55193 Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Sat, 18 May 2024 09:43:26 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=E5=95=86=E5=93=81=E9=87=8D=E6=9E=84?= =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/sql/mysql8/youlai_mall_pms.sql | 113 ++++++++++-------- .../controller/admin/CategoryController.java | 1 - .../controller/app/AppSkuController.java | 2 +- ...Controller.java => ProductController.java} | 21 ++-- .../product/enums/AttributeInputTypeEnum.java | 7 +- .../mall/product/enums/AttributeTypeEnum.java | 13 +- .../product/mapper/SpuAttributeMapper.java | 10 -- .../mapper/SpuAttributeValueMapper.java | 23 ++++ .../mall/product/model/entity/Attribute.java | 10 +- .../model/entity/SkuAttributeValue.java | 6 +- .../model/entity/SpuAttributeValue.java | 6 +- .../model/form/AttributeGroupForm.java | 6 +- .../mall/product/model/form/SpuForm.java | 43 ++++--- .../model/query/AttributeGroupPageQuery.java | 3 - .../service/SpuAttributeValueService.java | 9 +- .../mall/product/service/SpuService.java | 25 ---- .../product/service/app/ProductService.java | 36 ++++++ .../product/service/app/StockService.java | 7 ++ .../service/app/impl/ProductServiceImpl.java | 71 +++++++++++ .../service/app/impl/StockServiceImpl.java | 22 ++++ .../impl/SpuAttributeValueServiceImpl.java | 59 +++++---- .../service/impl/SpuImageServiceImpl.java | 6 +- .../product/service/impl/SpuServiceImpl.java | 74 ++---------- .../mapper/SpuAttributeValueMapper.xml | 36 ++++++ 24 files changed, 379 insertions(+), 230 deletions(-) rename mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/{AppSpuController.java => ProductController.java} (69%) delete mode 100644 mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeMapper.java create mode 100644 mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeValueMapper.java create mode 100644 mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/ProductService.java create mode 100644 mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/StockService.java create mode 100644 mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/ProductServiceImpl.java create mode 100644 mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/StockServiceImpl.java create mode 100644 mall-product/product-boot/src/main/resources/mapper/SpuAttributeValueMapper.xml diff --git a/docs/sql/mysql8/youlai_mall_pms.sql b/docs/sql/mysql8/youlai_mall_pms.sql index 73fcac0b8..5c4043673 100644 --- a/docs/sql/mysql8/youlai_mall_pms.sql +++ b/docs/sql/mysql8/youlai_mall_pms.sql @@ -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 diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/CategoryController.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/CategoryController.java index 17033c9b6..7d9f8190b 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/CategoryController.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/admin/CategoryController.java @@ -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; diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSkuController.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSkuController.java index 8c852f313..7459493a2 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSkuController.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSkuController.java @@ -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 { diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSpuController.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/ProductController.java similarity index 69% rename from mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSpuController.java rename to mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/ProductController.java index b7f3fa0cf..f8e22d28b 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/AppSpuController.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/controller/app/ProductController.java @@ -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 listPagedSpuForApp(SpuPageQuery queryParams) { - IPage result = spuService.listPagedSpuForApp(queryParams); + IPage result = productService.listPagedSpuForApp(queryParams); return PageResult.success(result); } @@ -39,15 +39,8 @@ public class AppSpuController { public Result 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> listSeckillingSpu() { - List list = spuService.listSeckillingSpu(); - return Result.success(list); - } - } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeInputTypeEnum.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeInputTypeEnum.java index 32c01034f..a3b4aa892 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeInputTypeEnum.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeInputTypeEnum.java @@ -9,6 +9,7 @@ import lombok.Getter; * @author Ray Hao * @since 2024/4/19 */ +@Getter public enum AttributeInputTypeEnum implements IBaseEnum { MANUAL(1, "手动录入"), @@ -18,12 +19,10 @@ public enum AttributeInputTypeEnum implements IBaseEnum { 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; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeTypeEnum.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeTypeEnum.java index 9d52e5337..b208f38fe 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeTypeEnum.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/enums/AttributeTypeEnum.java @@ -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 { - 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; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeMapper.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeMapper.java deleted file mode 100644 index e1fbf512e..000000000 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeMapper.java +++ /dev/null @@ -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 { - -} diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeValueMapper.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeValueMapper.java new file mode 100644 index 000000000..e3d39b700 --- /dev/null +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/mapper/SpuAttributeValueMapper.java @@ -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 { + + /** + * 根据SPU ID查询属性组&属性列表 + * + * @param spuId SPU ID + * @return 属性列表 + */ + List listAttributeGroupsBySpuId(Long spuId); +} diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/Attribute.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/Attribute.java index 3f7ff0c50..e9705edde 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/Attribute.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/Attribute.java @@ -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; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SkuAttributeValue.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SkuAttributeValue.java index d3f382674..f45264b5d 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SkuAttributeValue.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SkuAttributeValue.java @@ -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; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SpuAttributeValue.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SpuAttributeValue.java index d9220854d..96ba9b119 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SpuAttributeValue.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/entity/SpuAttributeValue.java @@ -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; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/AttributeGroupForm.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/AttributeGroupForm.java index 46084d4a0..f1dc8da3a 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/AttributeGroupForm.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/AttributeGroupForm.java @@ -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; } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/SpuForm.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/SpuForm.java index 3d113146b..eac4e4b6a 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/SpuForm.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/form/SpuForm.java @@ -44,13 +44,13 @@ public class SpuForm { @Schema(description = "商品详情", example = "

Apple iPhone 12 64GB 绿色

") private String detail; - @Schema(description = "商品属性列表(仅返回用,提交时不填)", example = "[{\"attrId\":1,\"attrName\":\"颜色\",\"attrValues\":[\"红色\",\"绿色\"]}]") - private List attributes; + @Schema(description = "商品属性列表(仅返回用,提交时不填)", example = "[{\"attributeId\":1,\"attributeName\":\"颜色\",\"attributeValues\":[\"红色\",\"绿色\"]}]") + private List saleAttributes; - @Schema(description = "商品基础属性值", example = "[{\"attrId\":1,\"attrName\":\"上市时间\",\"attrValue\":\"2024-05-08\"}]") - private List baseAttributeValues; + @Schema(description = "基础属性分组列表(仅返回用,提交时不填)", example = "[{\"attributeGroupId\":1,\"attributeGroupName\":\"基础属性\",\"attributeAttributeValues\":[{\"id\":1,\"attributeId\":1,\"attributeName\":\"颜色\",\"attributeValue\":\"红色\"}]}]") + private List 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 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 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 attrValues; + @Schema(description = "属性值列表", example = "[\"白色\",\"黑色\"]") + private List attributeValues; } } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/query/AttributeGroupPageQuery.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/query/AttributeGroupPageQuery.java index 48c83bebe..1d5ff4afd 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/query/AttributeGroupPageQuery.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/model/query/AttributeGroupPageQuery.java @@ -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; - /** * 属性组分页查询对象 * diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttributeValueService.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttributeValueService.java index 164231b45..7dba91dd8 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttributeValueService.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuAttributeValueService.java @@ -20,6 +20,13 @@ public interface SpuAttributeValueService extends IService { * @param spuId SPU ID * @param attributeList 属性列表 */ - void saveSpuAttributes(Long spuId, List attributeList); + void saveSpuAttributes(Long spuId, List attributeList); + /** + * 根据SPU ID查询属性组&属性列表 + * + * @param spuId SPU ID + * @return 商品属性列表 + */ + List listAttributeGroupsBySpuId(Long spuId); } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuService.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuService.java index bf84cfb5c..c3fcdf830 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuService.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/SpuService.java @@ -26,22 +26,6 @@ public interface SpuService extends IService { */ IPage listPagedSpu(SpuPageQuery queryParams); - /** - * 「应用端」商品分页列表 - * - * @param queryParams - * @return - */ - IPage listPagedSpuForApp(SpuPageQuery queryParams); - - - /** - * 「应用端」获取商品详情 - * - * @param spuId - * @return - */ - SpuDetailVO getSpuDetailForApp(Long spuId); /** @@ -60,7 +44,6 @@ public interface SpuService extends IService { */ SpuForm getSpuForm(Long spuId); - /** * 删除商品 * @@ -69,13 +52,5 @@ public interface SpuService extends IService { */ boolean removeBySpuIds(String ids); - /** - * 获取秒杀商品列表 - * TODO - * - * @return - */ - List listSeckillingSpu(); - } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/ProductService.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/ProductService.java new file mode 100644 index 000000000..2dd2b5799 --- /dev/null +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/ProductService.java @@ -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 { + + /** + * 「应用端」商品分页列表 + * + * @param queryParams + * @return + */ + IPage listPagedSpuForApp(SpuPageQuery queryParams); + + + /** + * 「应用端」获取商品详情 + * + * @param spuId + * @return + */ + SpuDetailVO getSpuDetailForApp(Long spuId); + + +} diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/StockService.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/StockService.java new file mode 100644 index 000000000..2321746d7 --- /dev/null +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/StockService.java @@ -0,0 +1,7 @@ +package com.youlai.mall.product.service.app; + +public interface StockService { + + + +} diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/ProductServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/ProductServiceImpl.java new file mode 100644 index 000000000..ae8cf4bee --- /dev/null +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/ProductServiceImpl.java @@ -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 implements ProductService { + + /** + * APP-商品分页列表 + * + * @param queryParams 查询参数 + * @return 商品分页列表 IPage + */ + @Override + public IPage listPagedSpuForApp(SpuPageQuery queryParams) { + Page page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize()); + List 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 listSeckillingSpu() { + List entities = this.list(new LambdaQueryWrapper() + .select(Spu::getId, Spu::getName, Spu::getImgUrl) + .orderByDesc(Spu::getCreateTime) + ); + return spuConverter.entity2SeckillingVO(entities); + } + + +} diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/StockServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/StockServiceImpl.java new file mode 100644 index 000000000..99b3a2b85 --- /dev/null +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/app/impl/StockServiceImpl.java @@ -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 implements StockService { + + + + + +} diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttributeValueServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttributeValueServiceImpl.java index 4f2858fb4..ebe10a1ed 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttributeValueServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuAttributeValueServiceImpl.java @@ -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 implements SpuAttributeValueService { +public class SpuAttributeValueServiceImpl extends ServiceImpl 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 formAttributes) { + public void saveSpuAttributes(Long spuId, List attributeGroupList) { // 如果属性列表为空,则删除所有旧属性 - if (CollectionUtil.isEmpty(formAttributes)) { + if (CollectionUtil.isEmpty(attributeGroupList)) { this.remove(new LambdaQueryWrapper().eq(SpuAttributeValue::getSpuId, spuId)); - } else { - // 获取当前数据库中的属性 - Map existingAttributes = this.list(new LambdaQueryWrapper() - .eq(SpuAttributeValue::getSpuId, spuId)) - .stream().collect(Collectors.toMap(SpuAttributeValue::getId, Function.identity())); + return; + } - List attributesToSave = new ArrayList<>(); - for (SpuForm.AttributeValue formAttribute : formAttributes) { + // 获取当前数据库中的属性 + Map existingAttributes = this.list(new LambdaQueryWrapper() + .eq(SpuAttributeValue::getSpuId, spuId)) + .stream().collect(Collectors.toMap(SpuAttributeValue::getId, Function.identity())); + + List 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 listAttributeGroupsBySpuId(Long spuId) { + return this.baseMapper.listAttributeGroupsBySpuId(spuId); + } } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuImageServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuImageServiceImpl.java index ef3f3020e..2252fdcf4 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuImageServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuImageServiceImpl.java @@ -28,11 +28,10 @@ public class SpuImageServiceImpl extends ServiceImpl i private final SpuImageConverter spuImageConverter; - /** * 保存商品图册 * - * @param spuId 商品ID + * @param spuId 商品ID * @param formImages 商品图册 */ @@ -46,14 +45,13 @@ public class SpuImageServiceImpl extends ServiceImpl i List newImages = spuImageConverter.convertToEntity(formImages); if (CollectionUtil.isNotEmpty(newImages)) { - // 新增图片处理 List 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); } diff --git a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java index 0f2fc9481..6f53e0c25 100644 --- a/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java +++ b/mall-product/product-boot/src/main/java/com/youlai/mall/product/service/impl/SpuServiceImpl.java @@ -55,34 +55,6 @@ public class SpuServiceImpl extends ServiceImpl implements SpuSe return page; } - /** - * APP-商品分页列表 - * - * @param queryParams 查询参数 - * @return 商品分页列表 IPage - */ - @Override - public IPage listPagedSpuForApp(SpuPageQuery queryParams) { - Page page = new Page<>(queryParams.getPageNum(), queryParams.getPageSize()); - List 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 implements SpuSe List imgList = formData.getImgList(); spuImageService.saveSpuImages(spuId, imgList); // 保存商品属性 - List attributeList = formData.getBaseAttributeValues(); - spuAttributeValueService.saveSpuAttributes(spuId, attributeList); + List attributeGroupList = formData.getAttributeGroups(); + spuAttributeValueService.saveSpuAttributes(spuId, attributeGroupList); // 保存 SKU List skuList = formData.getSkuList(); skuService.saveSkus(spuId, skuList); @@ -146,17 +118,10 @@ public class SpuServiceImpl extends ServiceImpl implements SpuSe } // 商品基础属性 - List baseAttributeValues = spuAttributeValueService.list(new LambdaQueryWrapper() - .eq(SpuAttributeValue::getSpuId, spuId)) - .stream().map(item -> { - SpuForm.AttributeValue attribute = new SpuForm.AttributeValue(); - BeanUtil.copyProperties(item, attribute); - return attribute; - }).toList(); - spuForm.setBaseAttributeValues(baseAttributeValues); + List attributeGroups = spuAttributeValueService.listAttributeGroupsBySpuId(spuId); + spuForm.setAttributeGroups(attributeGroups); List skuList = skuService.list(new LambdaQueryWrapper().eq(Sku::getSpuId, spuId)); - if (CollectionUtil.isNotEmpty(skuList)) { List skuIds = skuList.stream().map(Sku::getId).toList(); List skuAttributeValueList = skuAttributeValueService.list(new LambdaQueryWrapper() @@ -181,20 +146,20 @@ public class SpuServiceImpl extends ServiceImpl implements SpuSe spuForm.setSkuList(skus); // 转换销售属性为商品属性 - Map attributeMap = new HashMap<>(); + Map 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 implements SpuSe return true; } - /** - * 获取商品秒杀接口 - * - * @return 商品秒杀列表 - */ - @Override - public List listSeckillingSpu() { - List entities = this.list(new LambdaQueryWrapper() - .select(Spu::getId, Spu::getName, Spu::getImgUrl) - .orderByDesc(Spu::getCreateTime) - ); - return spuConverter.entity2SeckillingVO(entities); - } } diff --git a/mall-product/product-boot/src/main/resources/mapper/SpuAttributeValueMapper.xml b/mall-product/product-boot/src/main/resources/mapper/SpuAttributeValueMapper.xml new file mode 100644 index 000000000..404f8bce0 --- /dev/null +++ b/mall-product/product-boot/src/main/resources/mapper/SpuAttributeValueMapper.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + +