|
|
|
|
@ -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,48 +32,18 @@ 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,
|
|
|
|
|
List<ProductPropertyValueDetailRespBO> propertyValues) {
|
|
|
|
|
AppProductSpuDetailRespVO spuVO = convert02(spu)
|
|
|
|
|
.setSalesCount(spu.getSalesCount() + defaultIfNull(spu.getVirtualSalesCount(), 0));
|
|
|
|
|
spuVO.setSkus(convertList03(skus));
|
|
|
|
|
// 处理商品属性
|
|
|
|
|
Map<Long, ProductPropertyValueDetailRespBO> propertyValueMap = convertMap(propertyValues, ProductPropertyValueDetailRespBO::getValueId);
|
|
|
|
|
for (int i = 0; i < skus.size(); i++) {
|
|
|
|
|
List<ProductSkuDO.Property> properties = skus.get(i).getProperties();
|
|
|
|
|
if (CollUtil.isEmpty(properties)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
AppProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
|
|
|
|
|
sku.setProperties(new ArrayList<>(properties.size()));
|
|
|
|
|
// 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中
|
|
|
|
|
properties.forEach(property -> {
|
|
|
|
|
ProductPropertyValueDetailRespBO propertyValue = propertyValueMap.get(property.getValueId());
|
|
|
|
|
if (propertyValue == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sku.getProperties().add(convert03(propertyValue));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return spuVO;
|
|
|
|
|
}
|
|
|
|
|
AppProductSpuDetailRespVO convert02(ProductSpuDO spu);
|
|
|
|
|
List<AppProductSpuDetailRespVO.Sku> convertList03(List<ProductSkuDO> skus);
|
|
|
|
|
AppProductPropertyValueDetailRespVO convert03(ProductPropertyValueDetailRespBO propertyValue);
|
|
|
|
|
|
|
|
|
|
default ProductSpuDetailRespVO convert03(ProductSpuDO spu, List<ProductSkuDO> skus,
|
|
|
|
|
List<ProductPropertyValueDetailRespBO> propertyValues) {
|
|
|
|
|
@ -114,4 +83,33 @@ public interface ProductSpuConvert {
|
|
|
|
|
}
|
|
|
|
|
PageResult<AppProductSpuPageItemRespVO> convertPageForGetSpuPage0(PageResult<ProductSpuDO> page);
|
|
|
|
|
|
|
|
|
|
default AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu, List<ProductSkuDO> skus,
|
|
|
|
|
List<ProductPropertyValueDetailRespBO> propertyValues) {
|
|
|
|
|
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++) {
|
|
|
|
|
List<ProductSkuDO.Property> properties = skus.get(i).getProperties();
|
|
|
|
|
if (CollUtil.isEmpty(properties)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
AppProductSpuDetailRespVO.Sku sku = spuVO.getSkus().get(i);
|
|
|
|
|
sku.setProperties(new ArrayList<>(properties.size()));
|
|
|
|
|
// 遍历每个 properties,设置到 AppSpuDetailRespVO.Sku 中
|
|
|
|
|
properties.forEach(property -> {
|
|
|
|
|
ProductPropertyValueDetailRespBO propertyValue = propertyValueMap.get(property.getValueId());
|
|
|
|
|
if (propertyValue == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
sku.getProperties().add(convertForGetSpuDetail(propertyValue));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return spuVO;
|
|
|
|
|
}
|
|
|
|
|
AppProductSpuDetailRespVO convertForGetSpuDetail(ProductSpuDO spu);
|
|
|
|
|
List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus);
|
|
|
|
|
AppProductPropertyValueDetailRespVO convertForGetSpuDetail(ProductPropertyValueDetailRespBO propertyValue);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|