Commit af71a19241c37271ec5241cd6b9908ff8ea8cb79
1 parent
964f8cb3
trade:【商品】sku 表增加 spu_name 字段,冗余
Showing
7 changed files
with
24 additions
and
24 deletions
yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/convert/sku/ProductSkuConvert.java
| ... | ... | @@ -32,7 +32,13 @@ public interface ProductSkuConvert { |
| 32 | 32 | |
| 33 | 33 | List<ProductSkuRespVO> convertList(List<ProductSkuDO> list); |
| 34 | 34 | |
| 35 | - List<ProductSkuDO> convertSkuDOList(List<ProductSkuCreateOrUpdateReqVO> list); | |
| 35 | + List<ProductSkuDO> convertList06(List<ProductSkuCreateOrUpdateReqVO> list); | |
| 36 | + | |
| 37 | + default List<ProductSkuDO> convertList06(List<ProductSkuCreateOrUpdateReqVO> list, String spuName) { | |
| 38 | + List<ProductSkuDO> result = convertList06(list); | |
| 39 | + result.forEach(item -> item.setSpuName(spuName)); | |
| 40 | + return result; | |
| 41 | + } | |
| 36 | 42 | |
| 37 | 43 | ProductSkuRespDTO convert02(ProductSkuDO bean); |
| 38 | 44 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/dal/dataobject/sku/ProductSkuDO.java
| ... | ... | @@ -36,17 +36,18 @@ public class ProductSkuDO extends BaseDO { |
| 36 | 36 | @TableId |
| 37 | 37 | private Long id; |
| 38 | 38 | /** |
| 39 | - * 商品 SKU 名字 | |
| 40 | - */ | |
| 41 | - @Deprecated // TODO 芋艿:参考有赞,不需要 sku 的标题 | |
| 42 | - private String name; | |
| 43 | - /** | |
| 44 | 39 | * SPU 编号 |
| 45 | 40 | * <p> |
| 46 | 41 | * 关联 {@link ProductSpuDO#getId()} |
| 47 | 42 | */ |
| 48 | 43 | private Long spuId; |
| 49 | 44 | /** |
| 45 | + * SPU 名字 | |
| 46 | + * | |
| 47 | + * 冗余 {@link ProductSkuDO#getSpuName()} | |
| 48 | + */ | |
| 49 | + private String spuName; | |
| 50 | + /** | |
| 50 | 51 | * 规格值数组,JSON 格式 |
| 51 | 52 | */ |
| 52 | 53 | @TableField(typeHandler = PropertyTypeHandler.class) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuService.java
| ... | ... | @@ -55,17 +55,19 @@ public interface ProductSkuService { |
| 55 | 55 | * 批量创建 SKU |
| 56 | 56 | * |
| 57 | 57 | * @param spuId 商品 SPU 编号 |
| 58 | + * @para spuName 商品 SPU 名称 | |
| 58 | 59 | * @param list SKU 对象集合 |
| 59 | 60 | */ |
| 60 | - void createSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> list); | |
| 61 | + void createSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> list); | |
| 61 | 62 | |
| 62 | 63 | /** |
| 63 | 64 | * 根据 SPU 编号,批量更新它的 SKU 信息 |
| 64 | 65 | * |
| 65 | 66 | * @param spuId SPU 编码 |
| 67 | + * @para spuName 商品 SPU 名称 | |
| 66 | 68 | * @param skus SKU 的集合 |
| 67 | 69 | */ |
| 68 | - void updateSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus); | |
| 70 | + void updateSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> skus); | |
| 69 | 71 | |
| 70 | 72 | /** |
| 71 | 73 | * 更新 SKU 库存(增量) | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/sku/ProductSkuServiceImpl.java
| ... | ... | @@ -119,9 +119,9 @@ public class ProductSkuServiceImpl implements ProductSkuService { |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | @Override |
| 122 | - public void createSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList) { | |
| 122 | + public void createSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList) { | |
| 123 | 123 | // 批量插入 SKU |
| 124 | - List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList); | |
| 124 | + List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertList06(skuCreateReqList, spuName); | |
| 125 | 125 | skuDOList.forEach(v -> v.setSpuId(spuId)); |
| 126 | 126 | productSkuMapper.insertBatch(skuDOList); |
| 127 | 127 | } |
| ... | ... | @@ -148,7 +148,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { |
| 148 | 148 | |
| 149 | 149 | @Override |
| 150 | 150 | @Transactional |
| 151 | - public void updateSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) { | |
| 151 | + public void updateSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> skus) { | |
| 152 | 152 | // 查询 SPU 下已经存在的 SKU 的集合 |
| 153 | 153 | List<ProductSkuDO> existsSkus = productSkuMapper.selectListBySpuId(spuId); |
| 154 | 154 | // 构建规格与 SKU 的映射关系; |
| ... | ... | @@ -168,7 +168,7 @@ public class ProductSkuServiceImpl implements ProductSkuService { |
| 168 | 168 | List<ProductSkuDO> updateSkus = new ArrayList<>(); |
| 169 | 169 | List<Long> deleteSkus = new ArrayList<>(); |
| 170 | 170 | |
| 171 | - List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus); | |
| 171 | + List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertList06(skus, spuName); | |
| 172 | 172 | allUpdateSkus.forEach(p -> { |
| 173 | 173 | String propertiesKey = p.getProperties() == null? "null": p.getProperties().stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining()); |
| 174 | 174 | // 1、找得到的,进行更新 | ... | ... |
yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java
| ... | ... | @@ -79,7 +79,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 79 | 79 | spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum)); |
| 80 | 80 | productSpuMapper.insert(spu); |
| 81 | 81 | // 插入 SKU |
| 82 | - productSkuService.createSkus(spu.getId(), skuCreateReqList); | |
| 82 | + productSkuService.createSkus(spu.getId(), spu.getName(), skuCreateReqList); | |
| 83 | 83 | // 返回 |
| 84 | 84 | return spu.getId(); |
| 85 | 85 | } |
| ... | ... | @@ -105,7 +105,7 @@ public class ProductSpuServiceImpl implements ProductSpuService { |
| 105 | 105 | updateObj.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum)); |
| 106 | 106 | productSpuMapper.updateById(updateObj); |
| 107 | 107 | // 批量更新 SKU |
| 108 | - productSkuService.updateSkus(updateObj.getId(), updateReqVO.getSkus()); | |
| 108 | + productSkuService.updateSkus(updateObj.getId(), updateObj.getName(), updateReqVO.getSkus()); | |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | @Override | ... | ... |
yudao-ui-admin/src/views/mall/product/spu/save.vue
| ... | ... | @@ -80,15 +80,6 @@ |
| 80 | 80 | <ImageUpload v-model="scope.row.picUrl" :limit="1" :isShowTip="false" style="width: 100px; height: 50px"/> |
| 81 | 81 | </template> |
| 82 | 82 | </el-table-column> |
| 83 | - <template v-if="this.specSwitch"> | |
| 84 | - <el-table-column label="sku名称" :render-header="addRedStar" key="91"> | |
| 85 | - <template slot-scope="scope"> | |
| 86 | - <el-form-item :prop="'rates.'+ scope.$index + '.name'" :rules="[{required: true, trigger: 'change'}]"> | |
| 87 | - <el-input v-model="scope.row.name"/> | |
| 88 | - </el-form-item> | |
| 89 | - </template> | |
| 90 | - </el-table-column> | |
| 91 | - </template> | |
| 92 | 83 | <el-table-column label="市场价(元)" :render-header="addRedStar" key="92"> |
| 93 | 84 | <template slot-scope="scope"> |
| 94 | 85 | <el-form-item :prop="'rates.'+ scope.$index + '.marketPrice'" :rules="[{required: true, trigger: 'change'}]"> | ... | ... |