trade:【商品】sku 表增加 spu_name 字段,冗余

This commit is contained in:
YunaiV 2022-11-19 12:25:53 +08:00
parent 964f8cb35b
commit af71a19241
7 changed files with 24 additions and 24 deletions

View File

@ -19,7 +19,7 @@ public class ProductSkuRespDTO {
*/
private Long id;
/**
* 商品 SKU 名字
* SPU 名字
*/
private String name;
/**

View File

@ -32,7 +32,13 @@ public interface ProductSkuConvert {
List<ProductSkuRespVO> convertList(List<ProductSkuDO> list);
List<ProductSkuDO> convertSkuDOList(List<ProductSkuCreateOrUpdateReqVO> list);
List<ProductSkuDO> convertList06(List<ProductSkuCreateOrUpdateReqVO> list);
default List<ProductSkuDO> convertList06(List<ProductSkuCreateOrUpdateReqVO> list, String spuName) {
List<ProductSkuDO> result = convertList06(list);
result.forEach(item -> item.setSpuName(spuName));
return result;
}
ProductSkuRespDTO convert02(ProductSkuDO bean);

View File

@ -35,17 +35,18 @@ public class ProductSkuDO extends BaseDO {
*/
@TableId
private Long id;
/**
* 商品 SKU 名字
*/
@Deprecated // TODO 芋艿参考有赞不需要 sku 的标题
private String name;
/**
* SPU 编号
* <p>
* 关联 {@link ProductSpuDO#getId()}
*/
private Long spuId;
/**
* SPU 名字
*
* 冗余 {@link ProductSkuDO#getSpuName()}
*/
private String spuName;
/**
* 规格值数组JSON 格式
*/

View File

@ -55,17 +55,19 @@ public interface ProductSkuService {
* 批量创建 SKU
*
* @param spuId 商品 SPU 编号
* @para spuName 商品 SPU 名称
* @param list SKU 对象集合
*/
void createSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> list);
void createSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> list);
/**
* 根据 SPU 编号批量更新它的 SKU 信息
*
* @param spuId SPU 编码
* @para spuName 商品 SPU 名称
* @param skus SKU 的集合
*/
void updateSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus);
void updateSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> skus);
/**
* 更新 SKU 库存增量

View File

@ -119,9 +119,9 @@ public class ProductSkuServiceImpl implements ProductSkuService {
}
@Override
public void createSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList) {
public void createSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList) {
// 批量插入 SKU
List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList);
List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertList06(skuCreateReqList, spuName);
skuDOList.forEach(v -> v.setSpuId(spuId));
productSkuMapper.insertBatch(skuDOList);
}
@ -148,7 +148,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override
@Transactional
public void updateSkus(Long spuId, List<ProductSkuCreateOrUpdateReqVO> skus) {
public void updateSkus(Long spuId, String spuName, List<ProductSkuCreateOrUpdateReqVO> skus) {
// 查询 SPU 下已经存在的 SKU 的集合
List<ProductSkuDO> existsSkus = productSkuMapper.selectListBySpuId(spuId);
// 构建规格与 SKU 的映射关系;
@ -168,7 +168,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
List<ProductSkuDO> updateSkus = new ArrayList<>();
List<Long> deleteSkus = new ArrayList<>();
List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertSkuDOList(skus);
List<ProductSkuDO> allUpdateSkus = ProductSkuConvert.INSTANCE.convertList06(skus, spuName);
allUpdateSkus.forEach(p -> {
String propertiesKey = p.getProperties() == null? "null": p.getProperties().stream().map(m -> String.valueOf(m.getValueId())).collect(Collectors.joining());
// 1找得到的进行更新

View File

@ -79,7 +79,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
spu.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum));
productSpuMapper.insert(spu);
// 插入 SKU
productSkuService.createSkus(spu.getId(), skuCreateReqList);
productSkuService.createSkus(spu.getId(), spu.getName(), skuCreateReqList);
// 返回
return spu.getId();
}
@ -105,7 +105,7 @@ public class ProductSpuServiceImpl implements ProductSpuService {
updateObj.setTotalStock(CollectionUtils.getSumValue(skuCreateReqList, ProductSkuCreateOrUpdateReqVO::getStock, Integer::sum));
productSpuMapper.updateById(updateObj);
// 批量更新 SKU
productSkuService.updateSkus(updateObj.getId(), updateReqVO.getSkus());
productSkuService.updateSkus(updateObj.getId(), updateObj.getName(), updateReqVO.getSkus());
}
@Override

View File

@ -80,15 +80,6 @@
<ImageUpload v-model="scope.row.picUrl" :limit="1" :isShowTip="false" style="width: 100px; height: 50px"/>
</template>
</el-table-column>
<template v-if="this.specSwitch">
<el-table-column label="sku名称" :render-header="addRedStar" key="91">
<template slot-scope="scope">
<el-form-item :prop="'rates.'+ scope.$index + '.name'" :rules="[{required: true, trigger: 'change'}]">
<el-input v-model="scope.row.name"/>
</el-form-item>
</template>
</el-table-column>
</template>
<el-table-column label="市场价(元)" :render-header="addRedStar" key="92">
<template slot-scope="scope">
<el-form-item :prop="'rates.'+ scope.$index + '.marketPrice'" :rules="[{required: true, trigger: 'change'}]">