|
|
|
|
@ -13,7 +13,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
|
|
|
|
|
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
|
|
|
|
|
import cn.iocoder.yudao.module.product.service.property.bo.ProductPropertyValueDetailRespBO;
|
|
|
|
|
import org.mapstruct.Mapper;
|
|
|
|
|
import org.mapstruct.Named;
|
|
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
@ -33,25 +32,23 @@ public interface ProductSpuConvert {
|
|
|
|
|
|
|
|
|
|
ProductSpuConvert INSTANCE = Mappers.getMapper(ProductSpuConvert.class);
|
|
|
|
|
|
|
|
|
|
ProductSpuDO convert(ProductSpuCreateReqVO bean);
|
|
|
|
|
ProductSpuDO convertForGetSpuDetail(ProductSpuCreateReqVO bean);
|
|
|
|
|
|
|
|
|
|
ProductSpuDO convert(ProductSpuUpdateReqVO bean);
|
|
|
|
|
ProductSpuDO convertForGetSpuDetail(ProductSpuUpdateReqVO bean);
|
|
|
|
|
|
|
|
|
|
List<ProductSpuDO> convertList(List<ProductSpuDO> list);
|
|
|
|
|
|
|
|
|
|
PageResult<ProductSpuRespVO> convertPage(PageResult<ProductSpuDO> page);
|
|
|
|
|
|
|
|
|
|
ProductSpuPageReqVO convert(AppProductSpuPageReqVO bean);
|
|
|
|
|
|
|
|
|
|
List<ProductSpuRespDTO> convertList2(List<ProductSpuDO> list);
|
|
|
|
|
|
|
|
|
|
List<ProductSpuSimpleRespVO> convertList02(List<ProductSpuDO> list);
|
|
|
|
|
|
|
|
|
|
default AppProductSpuDetailRespVO convert(ProductSpuDO spu, List<ProductSkuDO> skus,
|
|
|
|
|
|
|
|
|
|
default ProductSpuDetailRespVO convert03(ProductSpuDO spu, List<ProductSkuDO> skus,
|
|
|
|
|
List<ProductPropertyValueDetailRespBO> propertyValues) {
|
|
|
|
|
AppProductSpuDetailRespVO spuVO = convert02(spu)
|
|
|
|
|
.setSalesCount(spu.getSalesCount() + defaultIfNull(spu.getVirtualSalesCount(), 0));
|
|
|
|
|
spuVO.setSkus(convertList03(skus));
|
|
|
|
|
ProductSpuDetailRespVO spuVO = convert03(spu);
|
|
|
|
|
spuVO.setSkus(convertList04(skus));
|
|
|
|
|
// 处理商品属性
|
|
|
|
|
Map<Long, ProductPropertyValueDetailRespBO> propertyValueMap = convertMap(propertyValues, ProductPropertyValueDetailRespBO::getValueId);
|
|
|
|
|
for (int i = 0; i < skus.size(); i++) {
|
|
|
|
|
@ -59,7 +56,7 @@ public interface ProductSpuConvert {
|
|
|
|
|
if (CollUtil.isEmpty(properties)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
AppProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
|
|
|
|
|
ProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
|
|
|
|
|
sku.setProperties(new ArrayList<>(properties.size()));
|
|
|
|
|
// 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中
|
|
|
|
|
properties.forEach(property -> {
|
|
|
|
|
@ -67,19 +64,30 @@ public interface ProductSpuConvert {
|
|
|
|
|
if (propertyValue == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sku.getProperties().add(convert03(propertyValue));
|
|
|
|
|
sku.getProperties().add(convert04(propertyValue));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return spuVO;
|
|
|
|
|
}
|
|
|
|
|
AppProductSpuDetailRespVO convert02(ProductSpuDO spu);
|
|
|
|
|
List<AppProductSpuDetailRespVO.Sku> convertList03(List<ProductSkuDO> skus);
|
|
|
|
|
AppProductPropertyValueDetailRespVO convert03(ProductPropertyValueDetailRespBO propertyValue);
|
|
|
|
|
ProductSpuDetailRespVO convert03(ProductSpuDO spu);
|
|
|
|
|
List<ProductSpuDetailRespVO.Sku> convertList04(List<ProductSkuDO> skus);
|
|
|
|
|
ProductPropertyValueDetailRespVO convert04(ProductPropertyValueDetailRespBO propertyValue);
|
|
|
|
|
|
|
|
|
|
default ProductSpuDetailRespVO convert03(ProductSpuDO spu, List<ProductSkuDO> skus,
|
|
|
|
|
// ========== 用户 App 相关 ==========
|
|
|
|
|
|
|
|
|
|
default PageResult<AppProductSpuPageItemRespVO> convertPageForGetSpuPage(PageResult<ProductSpuDO> page) {
|
|
|
|
|
// 累加虚拟销量
|
|
|
|
|
page.getList().forEach(spu -> spu.setSalesCount(spu.getSalesCount() + spu.getVirtualSalesCount()));
|
|
|
|
|
// 然后进行转换
|
|
|
|
|
return convertPageForGetSpuPage0(page);
|
|
|
|
|
}
|
|
|
|
|
PageResult<AppProductSpuPageItemRespVO> convertPageForGetSpuPage0(PageResult<ProductSpuDO> page);
|
|
|
|
|
|
|
|
|
|
default AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu, List<ProductSkuDO> skus,
|
|
|
|
|
List<ProductPropertyValueDetailRespBO> propertyValues) {
|
|
|
|
|
ProductSpuDetailRespVO spuVO = convert03(spu);
|
|
|
|
|
spuVO.setSkus(convertList04(skus));
|
|
|
|
|
AppProductSpuDetailRespVO spuVO = convertForGetSpuDetail(spu)
|
|
|
|
|
.setSalesCount(spu.getSalesCount() + defaultIfNull(spu.getVirtualSalesCount(), 0));
|
|
|
|
|
spuVO.setSkus(convertListForGetSpuDetail(skus));
|
|
|
|
|
// 处理商品属性
|
|
|
|
|
Map<Long, ProductPropertyValueDetailRespBO> propertyValueMap = convertMap(propertyValues, ProductPropertyValueDetailRespBO::getValueId);
|
|
|
|
|
for (int i = 0; i < skus.size(); i++) {
|
|
|
|
|
@ -87,7 +95,7 @@ public interface ProductSpuConvert {
|
|
|
|
|
if (CollUtil.isEmpty(properties)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
|
|
|
|
|
AppProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
|
|
|
|
|
sku.setProperties(new ArrayList<>(properties.size()));
|
|
|
|
|
// 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中
|
|
|
|
|
properties.forEach(property -> {
|
|
|
|
|
@ -95,23 +103,13 @@ public interface ProductSpuConvert {
|
|
|
|
|
if (propertyValue == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sku.getProperties().add(convert04(propertyValue));
|
|
|
|
|
sku.getProperties().add(convertForGetSpuDetail(propertyValue));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return spuVO;
|
|
|
|
|
}
|
|
|
|
|
ProductSpuDetailRespVO convert03(ProductSpuDO spu);
|
|
|
|
|
List<ProductSpuDetailRespVO.Sku> convertList04(List<ProductSkuDO> skus);
|
|
|
|
|
ProductPropertyValueDetailRespVO convert04(ProductPropertyValueDetailRespBO propertyValue);
|
|
|
|
|
|
|
|
|
|
// ========== 用户 App 相关 ==========
|
|
|
|
|
|
|
|
|
|
default PageResult<AppProductSpuPageItemRespVO> convertPageForGetSpuPage(PageResult<ProductSpuDO> page) {
|
|
|
|
|
// 累加虚拟销量
|
|
|
|
|
page.getList().forEach(spu -> spu.setSalesCount(spu.getSalesCount() + spu.getVirtualSalesCount()));
|
|
|
|
|
// 然后进行转换
|
|
|
|
|
return convertPageForGetSpuPage0(page);
|
|
|
|
|
}
|
|
|
|
|
PageResult<AppProductSpuPageItemRespVO> convertPageForGetSpuPage0(PageResult<ProductSpuDO> page);
|
|
|
|
|
AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu);
|
|
|
|
|
List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus);
|
|
|
|
|
AppProductPropertyValueDetailRespVO convertForGetSpuDetail(ProductPropertyValueDetailRespBO propertyValue);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|