Commit 4a39f2d9f8bfd7d104dd53c3060d9ff7c3d14d13
1 parent
0bc2ef1d
feature(uniapp商品): 代码调整
Showing
5 changed files
with
70 additions
and
77 deletions
sql/optional/mall/mall.sql
| @@ -211,24 +211,29 @@ COMMIT; | @@ -211,24 +211,29 @@ COMMIT; | ||
| 211 | -- Table structure for product_sku | 211 | -- Table structure for product_sku |
| 212 | -- ---------------------------- | 212 | -- ---------------------------- |
| 213 | DROP TABLE IF EXISTS `product_sku`; | 213 | DROP TABLE IF EXISTS `product_sku`; |
| 214 | -CREATE TABLE `product_sku` ( | ||
| 215 | - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 216 | - `spu_id` bigint NOT NULL COMMENT 'spu编号', | ||
| 217 | - `properties` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]', | ||
| 218 | - `price` int NOT NULL DEFAULT -1 COMMENT '销售价格,单位:分', | ||
| 219 | - `original_price` int NOT NULL DEFAULT -1 COMMENT '原价, 单位: 分', | ||
| 220 | - `cost_price` int NOT NULL DEFAULT -1 COMMENT '成本价,单位: 分', | ||
| 221 | - `bar_code` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '条形码', | ||
| 222 | - `pic_url` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '图片地址', | ||
| 223 | - `status` tinyint NULL DEFAULT NULL COMMENT '状态: 0-正常 1-禁用', | ||
| 224 | - `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 225 | - `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 226 | - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人', | ||
| 227 | - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', | ||
| 228 | - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', | ||
| 229 | - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 230 | - PRIMARY KEY (`id`) USING BTREE | ||
| 231 | -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品sku'; | 214 | +CREATE TABLE `product_sku` ( |
| 215 | +`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 216 | +`spu_id` bigint NOT NULL COMMENT 'spu编号', | ||
| 217 | +`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | ||
| 218 | +`name` varchar(128) DEFAULT NULL COMMENT '商品 SKU 名字', | ||
| 219 | +`properties` varchar(128) DEFAULT NULL COMMENT '规格值数组-json格式, [{propertId: , valueId: }, {propertId: , valueId: }]', | ||
| 220 | +`price` int NOT NULL DEFAULT '-1' COMMENT '销售价格,单位:分', | ||
| 221 | +`market_price` int DEFAULT NULL COMMENT '市场价', | ||
| 222 | +`cost_price` int NOT NULL DEFAULT '-1' COMMENT '成本价,单位: 分', | ||
| 223 | +`pic_url` varchar(128) NOT NULL COMMENT '图片地址', | ||
| 224 | +`stock` int DEFAULT NULL COMMENT '库存', | ||
| 225 | +`warn_stock` int DEFAULT NULL COMMENT '预警库存', | ||
| 226 | +`volume` double DEFAULT NULL COMMENT '商品体积', | ||
| 227 | +`weight` double DEFAULT NULL COMMENT '商品重量', | ||
| 228 | +`bar_code` varchar(64) DEFAULT NULL COMMENT '条形码', | ||
| 229 | +`status` tinyint DEFAULT NULL COMMENT '状态: 0-正常 1-禁用', | ||
| 230 | +`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 231 | +`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 232 | +`creator` varchar(64) DEFAULT NULL COMMENT '创建人', | ||
| 233 | +`updater` double(64,0) DEFAULT NULL COMMENT '更新人', | ||
| 234 | +`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 235 | +PRIMARY KEY (`id`) USING BTREE | ||
| 236 | +) ENGINE=InnoDB COMMENT='商品sku'; | ||
| 232 | 237 | ||
| 233 | -- ---------------------------- | 238 | -- ---------------------------- |
| 234 | -- Records of product_sku | 239 | -- Records of product_sku |
| @@ -240,26 +245,35 @@ COMMIT; | @@ -240,26 +245,35 @@ COMMIT; | ||
| 240 | -- Table structure for product_spu | 245 | -- Table structure for product_spu |
| 241 | -- ---------------------------- | 246 | -- ---------------------------- |
| 242 | DROP TABLE IF EXISTS `product_spu`; | 247 | DROP TABLE IF EXISTS `product_spu`; |
| 243 | -CREATE TABLE `product_spu` ( | ||
| 244 | - `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 245 | - `name` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '商品名称', | ||
| 246 | - `sell_point` varchar(128) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '卖点', | ||
| 247 | - `description` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '描述', | ||
| 248 | - `category_id` bigint NOT NULL COMMENT '分类id', | ||
| 249 | - `pic_urls` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '商品主图地址\n *\n * 数组,以逗号分隔\n 最多上传15张', | ||
| 250 | - `sort` int NOT NULL DEFAULT 0 COMMENT '排序字段', | ||
| 251 | - `like_count` int NULL DEFAULT NULL COMMENT '点赞初始人数', | ||
| 252 | - `price` int NULL DEFAULT NULL COMMENT '价格 单位使用:分', | ||
| 253 | - `quantity` int NULL DEFAULT NULL COMMENT '库存数量', | ||
| 254 | - `status` bit(1) NULL DEFAULT NULL COMMENT '上下架状态: 0 上架(开启) 1 下架(禁用)', | ||
| 255 | - `create_time` datetime NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 256 | - `update_time` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 257 | - `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建人', | ||
| 258 | - `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新人', | ||
| 259 | - `tenant_id` bigint NOT NULL DEFAULT 0 COMMENT '租户编号', | ||
| 260 | - `deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 261 | - PRIMARY KEY (`id`) USING BTREE | ||
| 262 | -) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '商品spu'; | 248 | +CREATE TABLE `product_spu` ( |
| 249 | +`id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键', | ||
| 250 | +`tenant_id` bigint NOT NULL DEFAULT '0' COMMENT '租户编号', | ||
| 251 | +`brand_id` int DEFAULT NULL COMMENT '商品品牌编号', | ||
| 252 | +`category_id` bigint NOT NULL COMMENT '分类id', | ||
| 253 | +`spec_type` int NOT NULL COMMENT '规格类型:0 单规格 1 多规格', | ||
| 254 | +`code` varchar(128) DEFAULT NULL COMMENT '商品编码', | ||
| 255 | +`name` varchar(128) NOT NULL COMMENT '商品名称', | ||
| 256 | +`sell_point` varchar(128) DEFAULT NULL COMMENT '卖点', | ||
| 257 | +`description` text COMMENT '描述', | ||
| 258 | +`pic_urls` varchar(1024) DEFAULT '' COMMENT '商品轮播图地址\n 数组,以逗号分隔\n 最多上传15张', | ||
| 259 | +`video_url` varchar(128) DEFAULT NULL COMMENT '商品视频', | ||
| 260 | +`market_price` int DEFAULT NULL COMMENT '市场价,单位使用:分', | ||
| 261 | +`min_price` int DEFAULT NULL COMMENT '最小价格,单位使用:分', | ||
| 262 | +`max_price` int DEFAULT NULL COMMENT '最大价格,单位使用:分', | ||
| 263 | +`total_stock` int NOT NULL DEFAULT '0' COMMENT '总库存', | ||
| 264 | +`show_stock` int DEFAULT '0' COMMENT '是否展示库存', | ||
| 265 | +`sales_count` int DEFAULT '0' COMMENT '商品销量', | ||
| 266 | +`virtual_sales_count` int DEFAULT '0' COMMENT '虚拟销量', | ||
| 267 | +`click_count` int DEFAULT '0' COMMENT '商品点击量', | ||
| 268 | +`status` bit(1) DEFAULT NULL COMMENT '上下架状态: 0 上架(开启) 1 下架(禁用)-1 回收', | ||
| 269 | +`sort` int NOT NULL DEFAULT '0' COMMENT '排序字段', | ||
| 270 | +`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', | ||
| 271 | +`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ||
| 272 | +`creator` varchar(64) DEFAULT NULL COMMENT '创建人', | ||
| 273 | +`updater` varchar(64) DEFAULT NULL COMMENT '更新人', | ||
| 274 | +`deleted` bit(1) NOT NULL DEFAULT b'0' COMMENT '是否删除', | ||
| 275 | +PRIMARY KEY (`id`) USING BTREE | ||
| 276 | +) ENGINE=InnoDB COMMENT='商品spu'; | ||
| 263 | 277 | ||
| 264 | -- ---------------------------- | 278 | -- ---------------------------- |
| 265 | -- Records of product_spu | 279 | -- Records of product_spu |
| @@ -299,26 +313,3 @@ INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, ` | @@ -299,26 +313,3 @@ INSERT INTO `ruoyi-vue-pro`.`system_menu` (`id`, `name`, `permission`, `type`, ` | ||
| 299 | 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'); | 313 | 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'); |
| 300 | 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'); | 314 | 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'); |
| 301 | 315 | ||
| 302 | -alter table product_spu add `code` varchar(128) COMMENT '商品编码'; | ||
| 303 | -alter table product_spu add total_stock int COMMENT '总库存'; | ||
| 304 | -alter table product_spu add warn_stock int COMMENT '预警预存'; | ||
| 305 | -alter table product_spu add show_stock int COMMENT '是否展示库存'; | ||
| 306 | -alter table product_spu add sales_count int COMMENT '商品销量'; | ||
| 307 | -alter table product_spu add virtual_sales_count int COMMENT '虚拟销量'; | ||
| 308 | -alter table product_spu add click_count int COMMENT '商品点击量'; | ||
| 309 | -alter table product_spu add banner_url varchar(128) COMMENT '主图地址'; | ||
| 310 | -alter table product_spu add spec_type int COMMENT '规格类型'; | ||
| 311 | -alter table product_spu add brand_id int COMMENT '商品品牌编号'; | ||
| 312 | -alter table product_spu add video_url varchar(128) COMMENT '商品视频'; | ||
| 313 | -alter table product_spu add min_price int COMMENT '最小价格,单位使用:分'; | ||
| 314 | -alter table product_spu add max_price int COMMENT '最大价格,单位使用:分'; | ||
| 315 | -alter table product_spu add market_price int COMMENT '市场价,单位使用:分'; | ||
| 316 | - | ||
| 317 | - | ||
| 318 | -alter table product_sku add `name` varchar(128) COMMENT '商品 SKU 名字'; | ||
| 319 | -alter table product_sku add `stock` int COMMENT '库存'; | ||
| 320 | -alter table product_sku add `weight` double COMMENT '商品重量'; | ||
| 321 | -alter table product_sku add `volume` double COMMENT '商品体积'; | ||
| 322 | - | ||
| 323 | - | ||
| 324 | -alter table product_sku DROP `original_price`; | ||
| 325 | \ No newline at end of file | 316 | \ No newline at end of file |
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 | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.product.controller.admin.sku.vo.ProductSkuPageReq | ||
| 7 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; | 7 | import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO; |
| 8 | import org.apache.ibatis.annotations.Mapper; | 8 | import org.apache.ibatis.annotations.Mapper; |
| 9 | 9 | ||
| 10 | +import java.util.Collections; | ||
| 10 | import java.util.List; | 11 | import java.util.List; |
| 11 | 12 | ||
| 12 | /** | 13 | /** |
| @@ -38,6 +39,10 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | @@ -38,6 +39,10 @@ public interface ProductSkuMapper extends BaseMapperX<ProductSkuDO> { | ||
| 38 | .inIfPresent(ProductSkuDO::getSpuId, spuIds)); | 39 | .inIfPresent(ProductSkuDO::getSpuId, spuIds)); |
| 39 | } | 40 | } |
| 40 | 41 | ||
| 42 | + default List<ProductSkuDO> selectBySpuId(Long spuIds) { | ||
| 43 | + return selectBySpuIds(Collections.singletonList(spuIds)); | ||
| 44 | + } | ||
| 45 | + | ||
| 41 | default void deleteBySpuId(Long spuId) { | 46 | default void deleteBySpuId(Long spuId) { |
| 42 | // TODO @franky:直接 delete(new XXX) 即可,更简洁一些 | 47 | // TODO @franky:直接 delete(new XXX) 即可,更简洁一些 |
| 43 | LambdaQueryWrapperX<ProductSkuDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<ProductSkuDO>() | 48 | LambdaQueryWrapperX<ProductSkuDO> lambdaQueryWrapperX = new LambdaQueryWrapperX<ProductSkuDO>() |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| 1 | package cn.iocoder.yudao.module.product.service.sku; | 1 | package cn.iocoder.yudao.module.product.service.sku; |
| 2 | 2 | ||
| 3 | +import cn.hutool.core.collection.CollectionUtil; | ||
| 3 | import cn.iocoder.yudao.framework.common.pojo.PageResult; | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 4 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 5 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO; | 6 | import cn.iocoder.yudao.module.product.controller.admin.property.vo.ProductPropertyRespVO; |
| @@ -91,22 +92,22 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -91,22 +92,22 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 91 | @Override | 92 | @Override |
| 92 | public void validateProductSkus(List<ProductSkuCreateOrUpdateReqVO> list, Integer specType) { | 93 | public void validateProductSkus(List<ProductSkuCreateOrUpdateReqVO> list, Integer specType) { |
| 93 | // 多规格才需校验 | 94 | // 多规格才需校验 |
| 94 | - if(specType.equals(ProductSpuSpecTypeEnum.DISABLE.getType())){ | 95 | + if (specType.equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { |
| 95 | List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); | 96 | List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); |
| 96 | // 1、校验规格属性存在 | 97 | // 1、校验规格属性存在 |
| 97 | List<Long> propertyIds = CollectionUtils.convertList(skuPropertyList, ProductSkuBaseVO.Property::getPropertyId); | 98 | List<Long> propertyIds = CollectionUtils.convertList(skuPropertyList, ProductSkuBaseVO.Property::getPropertyId); |
| 98 | List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds); | 99 | List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds); |
| 99 | - if (propertyAndValueList.size() == propertyIds.size()){ | 100 | + if (propertyAndValueList.size() == propertyIds.size()) { |
| 100 | throw exception(PROPERTY_NOT_EXISTS); | 101 | throw exception(PROPERTY_NOT_EXISTS); |
| 101 | } | 102 | } |
| 102 | // 2. 校验,一个 Sku 下,没有重复的规格。校验方式是,遍历每个 Sku ,看看是否有重复的规格 attrId | 103 | // 2. 校验,一个 Sku 下,没有重复的规格。校验方式是,遍历每个 Sku ,看看是否有重复的规格 attrId |
| 103 | List<ProductPropertyValueRespVO> collect = propertyAndValueList.stream() | 104 | List<ProductPropertyValueRespVO> collect = propertyAndValueList.stream() |
| 104 | - .flatMap(v -> Optional.of(v.getPropertyValueList()) | 105 | + .flatMap(v -> Optional.of(v.getPropertyValueList()) |
| 105 | .orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); | 106 | .orElse(new ArrayList<>()).stream()).collect(Collectors.toList()); |
| 106 | Map<Long, ProductPropertyValueRespVO> propertyValueRespVOMap = CollectionUtils.convertMap(collect, ProductPropertyValueRespVO::getId); | 107 | Map<Long, ProductPropertyValueRespVO> propertyValueRespVOMap = CollectionUtils.convertMap(collect, ProductPropertyValueRespVO::getId); |
| 107 | - list.forEach(v->{ | 108 | + list.forEach(v -> { |
| 108 | Set<Long> keys = v.getProperties().stream().map(k -> propertyValueRespVOMap.get(k.getValueId()).getPropertyId()).collect(Collectors.toSet()); | 109 | Set<Long> keys = v.getProperties().stream().map(k -> propertyValueRespVOMap.get(k.getValueId()).getPropertyId()).collect(Collectors.toSet()); |
| 109 | - if(keys.size() != v.getProperties().size()){ | 110 | + if (keys.size() != v.getProperties().size()) { |
| 110 | throw exception(ErrorCodeConstants.SKU_PROPERTIES_DUPLICATED); | 111 | throw exception(ErrorCodeConstants.SKU_PROPERTIES_DUPLICATED); |
| 111 | } | 112 | } |
| 112 | }); | 113 | }); |
| @@ -133,7 +134,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -133,7 +134,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 133 | public void createProductSkus(List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList, Long spuId) { | 134 | public void createProductSkus(List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList, Long spuId) { |
| 134 | // 批量插入 SKU | 135 | // 批量插入 SKU |
| 135 | List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList); | 136 | List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList); |
| 136 | - skuDOList.forEach(v->v.setSpuId(spuId)); | 137 | + skuDOList.forEach(v -> v.setSpuId(spuId)); |
| 137 | productSkuMapper.insertBatch(skuDOList); | 138 | productSkuMapper.insertBatch(skuDOList); |
| 138 | } | 139 | } |
| 139 | 140 | ||
| @@ -156,10 +157,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -156,10 +157,8 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 156 | @Transactional | 157 | @Transactional |
| 157 | public void updateProductSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) { | 158 | public void updateProductSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) { |
| 158 | // 查询 spu 下已经存在的 sku 的集合 | 159 | // 查询 spu 下已经存在的 sku 的集合 |
| 159 | - // TODO @luowenfeng:selectListBySpuId 搞个 | ||
| 160 | - List<ProductSkuDO> existsSkus = productSkuMapper.selectBySpuIds(Collections.singletonList(spuId)); | ||
| 161 | - // TODO @franky:使用 CollUtils 即可 | ||
| 162 | - Map<Long, ProductSkuDO> existsSkuMap = existsSkus.stream().collect(Collectors.toMap(ProductSkuDO::getId, p -> p)); | 160 | + List<ProductSkuDO> existsSkus = productSkuMapper.selectBySpuId(spuId); |
| 161 | + Map<Long, ProductSkuDO> existsSkuMap = CollectionUtils.convertMap(existsSkus, ProductSkuDO::getId); | ||
| 163 | 162 | ||
| 164 | // 拆分三个集合,新插入的、需要更新的、需要删除的 | 163 | // 拆分三个集合,新插入的、需要更新的、需要删除的 |
| 165 | List<ProductSkuDO> insertSkus = new ArrayList<>(); | 164 | List<ProductSkuDO> insertSkus = new ArrayList<>(); |
| @@ -170,8 +169,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -170,8 +169,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 170 | List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus); | 169 | List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus); |
| 171 | allUpdateSkus.forEach(p -> { | 170 | allUpdateSkus.forEach(p -> { |
| 172 | if (p.getId() != null) { | 171 | if (p.getId() != null) { |
| 173 | - // TODO @luowenfeng:contains | ||
| 174 | - if (existsSkuMap.get(p.getId()) != null) { | 172 | + if (existsSkuMap.containsKey(p.getId())) { |
| 175 | updateSkus.add(p); | 173 | updateSkus.add(p); |
| 176 | return; | 174 | return; |
| 177 | } | 175 | } |
| @@ -182,8 +180,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | @@ -182,8 +180,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { | ||
| 182 | insertSkus.add(p); | 180 | insertSkus.add(p); |
| 183 | }); | 181 | }); |
| 184 | 182 | ||
| 185 | - // TODO @luowenfeng:使用 CollUtil.isNotEmpty 判断 | ||
| 186 | - if (insertSkus.size() > 0) { | 183 | + if (CollectionUtil.isNotEmpty(insertSkus)) { |
| 187 | productSkuMapper.insertBatch(insertSkus); | 184 | productSkuMapper.insertBatch(insertSkus); |
| 188 | } | 185 | } |
| 189 | if (updateSkus.size() > 0) { | 186 | if (updateSkus.size() > 0) { |
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 { | @@ -60,7 +60,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { | ||
| 60 | public Long createProductSpu(ProductSpuCreateReqVO createReqVO) { | 60 | public Long createProductSpu(ProductSpuCreateReqVO createReqVO) { |
| 61 | // 校验分类 | 61 | // 校验分类 |
| 62 | categoryService.validateProductCategory(createReqVO.getCategoryId()); | 62 | categoryService.validateProductCategory(createReqVO.getCategoryId()); |
| 63 | - // TODO @luowenfeng:校验品牌 | 63 | + // TODO @:校验品牌 |
| 64 | 64 | ||
| 65 | // 校验SKU | 65 | // 校验SKU |
| 66 | List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus(); | 66 | List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus(); |
yudao-ui-app/manifest.json