From 4a39f2d9f8bfd7d104dd53c3060d9ff7c3d14d13 Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Thu, 25 Aug 2022 17:10:26 +0800 Subject: [PATCH] =?UTF-8?q?feature(uniapp=E5=95=86=E5=93=81):=20=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/optional/mall/mall.sql | 113 ++++++++---------- .../dal/mysql/sku/ProductSkuMapper.java | 5 + .../service/sku/ProductSkuServiceImpl.java | 25 ++-- .../service/spu/ProductSpuServiceImpl.java | 2 +- yudao-ui-app/manifest.json | 2 +- 5 files changed, 70 insertions(+), 77 deletions(-) diff --git a/sql/optional/mall/mall.sql b/sql/optional/mall/mall.sql index f6b3542e3..6ba64e747 100644 --- a/sql/optional/mall/mall.sql +++ b/sql/optional/mall/mall.sql @@ -211,24 +211,29 @@ COMMIT; -- Table structure for product_sku -- ---------------------------- DROP TABLE IF EXISTS `product_sku`; -CREATE TABLE `product_sku` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `spu_id` bigint NOT NULL COMMENT 'spu编号', - `properties` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]', - `price` int NOT NULL DEFAULT -1 COMMENT '销售价格,单位:分', - `original_price` int NOT NULL DEFAULT -1 COMMENT '原价, 单位: 分', - `cost_price` int NOT NULL DEFAULT -1 COMMENT '成本价,单位: 分', - `bar_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '条形码', - `pic_url` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '图片地址', - `status` tinyint NULL DEFAULT NULL COMMENT '状态: 0-正常 1-禁用', - `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人', - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品sku'; +CREATE TABLE `product_sku` ( +`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', +`spu_id` bigint NOT NULL COMMENT 'spu编号', +`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', +`name` varchar(128) DEFAULT NULL COMMENT '商品 SKU 名字', +`properties` varchar(128) DEFAULT NULL COMMENT '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]', +`price` int NOT NULL DEFAULT '-1' COMMENT '销售价格,单位:分', +`market_price` int DEFAULT NULL COMMENT '市场价', +`cost_price` int NOT NULL DEFAULT '-1' COMMENT '成本价,单位: 分', +`pic_url` varchar(128) NOT NULL COMMENT '图片地址', +`stock` int DEFAULT NULL COMMENT '库存', +`warn_stock` int DEFAULT NULL COMMENT '预警库存', +`volume` double DEFAULT NULL COMMENT '商品体积', +`weight` double DEFAULT NULL COMMENT '商品重量', +`bar_code` varchar(64) DEFAULT NULL COMMENT '条形码', +`status` tinyint DEFAULT NULL COMMENT '状态: 0-正常 1-禁用', +`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', +`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', +`creator` varchar(64) DEFAULT NULL COMMENT '创建人', +`updater` double(64,0) DEFAULT NULL COMMENT '更新人', +`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', +PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB COMMENT='商品sku'; -- ---------------------------- -- Records of product_sku @@ -240,26 +245,35 @@ COMMIT; -- Table structure for product_spu -- ---------------------------- DROP TABLE IF EXISTS `product_spu`; -CREATE TABLE `product_spu` ( - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', - `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品名称', - `sell_point` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '卖点', - `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '描述', - `category_id` bigint NOT NULL COMMENT '分类id', - `pic_urls` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '商品主图地址\n *\n * 数组,以逗号分隔\n 最多上传15张', - `sort` int NOT NULL DEFAULT 0 COMMENT '排序字段', - `like_count` int NULL DEFAULT NULL COMMENT '点赞初始人数', - `price` int NULL DEFAULT NULL COMMENT '价格 单位使用:分', - `quantity` int NULL DEFAULT NULL COMMENT '库存数量', - `status` bit(1) NULL DEFAULT NULL COMMENT '上下架状态: 0 上架(开启) 1 下架(禁用)', - `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', - `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人', - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', - PRIMARY KEY (`id`) USING BTREE -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品spu'; +CREATE TABLE `product_spu` ( +`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', +`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', +`brand_id` int DEFAULT NULL COMMENT '商品品牌编号', +`category_id` bigint NOT NULL COMMENT '分类id', +`spec_type` int NOT NULL COMMENT '规格类型:0 单规格 1 多规格', +`code` varchar(128) DEFAULT NULL COMMENT '商品编码', +`name` varchar(128) NOT NULL COMMENT '商品名称', +`sell_point` varchar(128) DEFAULT NULL COMMENT '卖点', +`description` text COMMENT '描述', +`pic_urls` varchar(1024) DEFAULT '' COMMENT '商品轮播图地址\n 数组,以逗号分隔\n 最多上传15张', +`video_url` varchar(128) DEFAULT NULL COMMENT '商品视频', +`market_price` int DEFAULT NULL COMMENT '市场价,单位使用:分', +`min_price` int DEFAULT NULL COMMENT '最小价格,单位使用:分', +`max_price` int DEFAULT NULL COMMENT '最大价格,单位使用:分', +`total_stock` int NOT NULL DEFAULT '0' COMMENT '总库存', +`show_stock` int DEFAULT '0' COMMENT '是否展示库存', +`sales_count` int DEFAULT '0' COMMENT '商品销量', +`virtual_sales_count` int DEFAULT '0' COMMENT '虚拟销量', +`click_count` int DEFAULT '0' COMMENT '商品点击量', +`status` bit(1) DEFAULT NULL COMMENT '上下架状态: 0 上架(开启) 1 下架(禁用)-1 回收', +`sort` int NOT NULL DEFAULT '0' COMMENT '排序字段', +`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', +`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', +`creator` varchar(64) DEFAULT NULL COMMENT '创建人', +`updater` varchar(64) DEFAULT NULL COMMENT '更新人', +`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', +PRIMARY KEY (`id`) USING BTREE +) ENGINE=InnoDB COMMENT='商品spu'; -- ---------------------------- -- Records of product_spu @@ -299,26 +313,3 @@ INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, ` INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2028, 'Banner更新', 'market:banner:update', 3, 3, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `status`, `visible`, `keep_alive`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (2029, 'Banner删除', 'market:banner:delete', 3, 4, 2025, '', '', '', 0, b'1', b'1', '', '2022-08-01 14:56:14', '', '2022-08-01 14:56:14', b'0'); -alter table product_spu add `code` varchar(128) COMMENT '商品编码'; -alter table product_spu add total_stock int COMMENT '总库存'; -alter table product_spu add warn_stock int COMMENT '预警预存'; -alter table product_spu add show_stock int COMMENT '是否展示库存'; -alter table product_spu add sales_count int COMMENT '商品销量'; -alter table product_spu add virtual_sales_count int COMMENT '虚拟销量'; -alter table product_spu add click_count int COMMENT '商品点击量'; -alter table product_spu add banner_url varchar(128) COMMENT '主图地址'; -alter table product_spu add spec_type int COMMENT '规格类型'; -alter table product_spu add brand_id int COMMENT '商品品牌编号'; -alter table product_spu add video_url varchar(128) COMMENT '商品视频'; -alter table product_spu add min_price int COMMENT '最小价格,单位使用:分'; -alter table product_spu add max_price int COMMENT '最大价格,单位使用:分'; -alter table product_spu add market_price int COMMENT '市场价,单位使用:分'; - - -alter table product_sku add `name` varchar(128) COMMENT '商品 SKU 名字'; -alter table product_sku add `stock` int COMMENT '库存'; -alter table product_sku add `weight` double COMMENT '商品重量'; -alter table product_sku add `volume` double COMMENT '商品体积'; - - -alter table product_sku DROP `original_price`; \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java index 134631650..7651e0c8c 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/mysql/sku/ProductSkuMapper.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReq import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; import org.apache.ibatis.annotations.Mapper; +import java.util.Collections; import java.util.List; /** @@ -38,6 +39,10 @@ public interface ProductSkuMapper extends BaseMapperX { .inIfPresent(ProductSkuDO::getSpuId, spuIds)); } + default List selectBySpuId(Long spuIds) { + return selectBySpuIds(Collections.singletonList(spuIds)); + } + default void deleteBySpuId(Long spuId) { // TODO @franky:直接 delete(new XXX) 即可,更简洁一些 LambdaQueryWrapperX lambdaQueryWrapperX = new LambdaQueryWrapperX() diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java index 18a9ec7df..1843617aa 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.product.service.sku; +import cn.hutool.core.collection.CollectionUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO; @@ -91,22 +92,22 @@ public class ProductSkuServiceImpl implements ProductSkuService { @Override public void validateProductSkus(List list, Integer specType) { // 多规格才需校验 - if(specType.equals(ProductSpuSpecTypeEnum.DISABLE.getType())){ + if (specType.equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { List skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); // 1、校验规格属性存在 List propertyIds = CollectionUtils.convertList(skuPropertyList, ProductSkuBaseVO.Property::getPropertyId); List propertyAndValueList = productPropertyService.selectByIds(propertyIds); - if (propertyAndValueList.size() == propertyIds.size()){ + if (propertyAndValueList.size() == propertyIds.size()) { throw exception(PROPERTY_NOT_EXISTS); } // 2. 校验,一个 Sku 下,没有重复的规格。校验方式是,遍历每个 Sku ,看看是否有重复的规格 attrId List collect = propertyAndValueList.stream() - .flatMap(v -> Optional.of(v.getPropertyValueList()) + .flatMap(v -> Optional.of(v.getPropertyValueList()) .orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); Map propertyValueRespVOMap = CollectionUtils.convertMap(collect, ProductPropertyValueRespVO::getId); - list.forEach(v->{ + list.forEach(v -> { Set keys = v.getProperties().stream().map(k -> propertyValueRespVOMap.get(k.getValueId()).getPropertyId()).collect(Collectors.toSet()); - if(keys.size() != v.getProperties().size()){ + if (keys.size() != v.getProperties().size()) { throw exception(ErrorCodeConstants.SKU_PROPERTIES_DUPLICATED); } }); @@ -133,7 +134,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { public void createProductSkus(List skuCreateReqList, Long spuId) { // 批量插入 SKU List skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList); - skuDOList.forEach(v->v.setSpuId(spuId)); + skuDOList.forEach(v -> v.setSpuId(spuId)); productSkuMapper.insertBatch(skuDOList); } @@ -156,10 +157,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { @Transactional public void updateProductSkus(Long spuId, List skus) { // 查询 spu 下已经存在的 sku 的集合 - // TODO @luowenfeng:selectListBySpuId 搞个 - List existsSkus = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId)); - // TODO @franky:使用 CollUtils 即可 - Map existsSkuMap = existsSkus.stream().collect(Collectors.toMap(ProductSkuDO::getId, p -> p)); + List existsSkus = productSkuMapper.selectBySpuId(spuId); + Map existsSkuMap = CollectionUtils.convertMap(existsSkus, ProductSkuDO::getId); // 拆分三个集合,新插入的、需要更新的、需要删除的 List insertSkus = new ArrayList<>(); @@ -170,8 +169,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { List allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus); allUpdateSkus.forEach(p -> { if (p.getId() != null) { - // TODO @luowenfeng:contains - if (existsSkuMap.get(p.getId()) != null) { + if (existsSkuMap.containsKey(p.getId())) { updateSkus.add(p); return; } @@ -182,8 +180,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { insertSkus.add(p); }); - // TODO @luowenfeng:使用 CollUtil.isNotEmpty 判断 - if (insertSkus.size() > 0) { + if (CollectionUtil.isNotEmpty(insertSkus)) { productSkuMapper.insertBatch(insertSkus); } if (updateSkus.size() > 0) { diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index dec092856..ad27ead18 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -60,7 +60,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { public Long createProductSpu(ProductSpuCreateReqVO createReqVO) { // 校验分类 categoryService.validateProductCategory(createReqVO.getCategoryId()); - // TODO @luowenfeng:校验品牌 + // TODO @:校验品牌 // 校验SKU List skuCreateReqList = createReqVO.getSkus(); diff --git a/yudao-ui-app/manifest.json b/yudao-ui-app/manifest.json index 7cce06e5f..0f85730b8 100644 --- a/yudao-ui-app/manifest.json +++ b/yudao-ui-app/manifest.json @@ -50,7 +50,7 @@ "quickapp" : {}, /* 小程序特有相关 */ "mp-weixin" : { - "appid" : "", + "appid" : "wx48d7c38b46f2e81c", "setting" : { "urlCheck" : false },