商品模块移除对营销模块的依赖

This commit is contained in:
puhui999 2023-10-23 17:29:26 +08:00
parent 6723cae781
commit 3672d0f245
5 changed files with 5 additions and 69 deletions

View File

@ -28,11 +28,6 @@
<artifactId>yudao-module-member-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-promotion-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>

View File

@ -11,8 +11,6 @@ import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import cn.iocoder.yudao.module.product.service.spu.ProductSpuService;
import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -45,9 +43,6 @@ public class ProductSpuController {
@Resource
private ProductSkuService productSkuService;
@Resource
private CouponTemplateApi couponTemplateApi;
@PostMapping("/create")
@Operation(summary = "创建商品 SPU")
@PreAuthorize("@ss.hasPermission('product:spu:create')")
@ -92,11 +87,7 @@ public class ProductSpuController {
}
// 查询商品 SKU
List<ProductSkuDO> skus = productSkuService.getSkuListBySpuId(spu.getId());
// 查询优惠卷
// TODO @puhui999优惠劵的信息要不交给前端读取主要是为了避免商品依赖 promotion 模块哈
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(
spu.getGiveCouponTemplateIds());
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus, couponTemplateList));
return success(ProductSpuConvert.INSTANCE.convertForSpuDetailRespVO(spu, skus));
}
@GetMapping("/list-all-simple")

View File

@ -96,9 +96,6 @@ public class ProductSpuBaseVO {
@NotNull(message = "商品赠送积分不能为空")
private Integer giveIntegral;
@Schema(description = "赠送的优惠劵数组包含优惠券编号和名称")
private List<GiveCouponTemplate> giveCouponTemplates;
@Schema(description = "分销类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
@NotNull(message = "商品分销类型不能为空")
private Boolean subCommissionType;
@ -111,16 +108,4 @@ public class ProductSpuBaseVO {
@Schema(description = "虚拟销量", example = "66")
private Integer virtualSalesCount;
@Schema(description = "管理后台 - 商品 SPU 赠送的优惠卷")
@Data
public static class GiveCouponTemplate {
@Schema(description = "模板编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Long id;
@Schema(description = "优惠劵名", requiredMode = Schema.RequiredMode.REQUIRED, example = "春节送送送")
private String name;
}
}

View File

@ -12,7 +12,6 @@ import cn.iocoder.yudao.module.product.convert.sku.ProductSkuConvert;
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.enums.DictTypeConstants;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
@ -101,14 +100,8 @@ public interface ProductSpuConvert {
List<AppProductSpuDetailRespVO.Sku> convertListForGetSpuDetail(List<ProductSkuDO> skus);
List<ProductSpuDetailRespVO.GiveCouponTemplate> convertList04(List<CouponTemplateRespDTO> couponTemplateList);
default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus,
List<CouponTemplateRespDTO> couponTemplateList) {
ProductSpuDetailRespVO respVO = convert03(spu);
respVO.setSkus(ProductSkuConvert.INSTANCE.convertList(skus));
respVO.setGiveCouponTemplates(convertList04(couponTemplateList));
return respVO;
default ProductSpuDetailRespVO convertForSpuDetailRespVO(ProductSpuDO spu, List<ProductSkuDO> skus) {
return convert03(spu).setSkus(ProductSkuConvert.INSTANCE.convertList(skus));
}
default List<ProductSpuDetailRespVO> convertForSpuDetailRespListVO(List<ProductSpuDO> spus, List<ProductSkuDO> skus) {

View File

@ -17,9 +17,6 @@ import cn.iocoder.yudao.module.product.enums.spu.ProductSpuStatusEnum;
import cn.iocoder.yudao.module.product.service.brand.ProductBrandService;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
import cn.iocoder.yudao.module.promotion.api.coupon.CouponTemplateApi;
import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponTemplateRespDTO;
import cn.iocoder.yudao.module.promotion.enums.common.PromotionTypeEnum;
import com.google.common.collect.Maps;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;
@ -28,10 +25,10 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.util.*;
import java.util.stream.Collectors;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getMinValue;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue;
import static cn.iocoder.yudao.module.product.dal.dataobject.category.ProductCategoryDO.CATEGORY_LEVEL;
import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.*;
@ -55,19 +52,12 @@ public class ProductSpuServiceImpl implements ProductSpuService {
@Resource
private ProductCategoryService categoryService;
@Resource
@Lazy
private CouponTemplateApi couponTemplateApi;
@Override
@Transactional(rollbackFor = Exception.class)
public Long createSpu(ProductSpuCreateReqVO createReqVO) {
// 校验分类品牌
validateCategory(createReqVO.getCategoryId());
brandService.validateProductBrand(createReqVO.getBrandId());
// 校验优惠券
Set<Long> giveCouponTemplateIds = convertSet(createReqVO.getGiveCouponTemplates(), ProductSpuCreateReqVO.GiveCouponTemplate::getId);
validateCouponTemplate(giveCouponTemplateIds);
// 校验 SKU
List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = createReqVO.getSkus();
productSkuService.validateSkuList(skuSaveReqList, createReqVO.getSpecType());
@ -75,8 +65,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
// 初始化 SPU SKU 相关属性
initSpuFromSkus(spu, skuSaveReqList);
// 设置优惠券
spu.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds));
// 插入 SPU
productSpuMapper.insert(spu);
// 插入 SKU
@ -93,9 +81,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
// 校验分类品牌
validateCategory(updateReqVO.getCategoryId());
brandService.validateProductBrand(updateReqVO.getBrandId());
// 校验优惠券
Set<Long> giveCouponTemplateIds = convertSet(updateReqVO.getGiveCouponTemplates(), ProductSpuUpdateReqVO.GiveCouponTemplate::getId);
validateCouponTemplate(giveCouponTemplateIds);
// 校验SKU
List<ProductSkuCreateOrUpdateReqVO> skuSaveReqList = updateReqVO.getSkus();
productSkuService.validateSkuList(skuSaveReqList, updateReqVO.getSpecType());
@ -103,8 +88,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
// 更新 SPU
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
initSpuFromSkus(updateObj, skuSaveReqList);
// 设置优惠券
updateObj.setGiveCouponTemplateIds(CollUtil.newArrayList(giveCouponTemplateIds));
productSpuMapper.updateById(updateObj);
// 批量更新 SKU
productSkuService.updateSkuList(updateObj.getId(), updateReqVO.getSkus());
@ -138,10 +121,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
// 默认商品浏览量
spu.setBrowseCount(0);
}
// 如果活动顺序为空则默认初始化
if (CollUtil.isEmpty(spu.getActivityOrders())) {
spu.setActivityOrders(Arrays.stream(PromotionTypeEnum.ARRAYS).boxed().collect(Collectors.toList()));
}
}
/**
@ -157,13 +136,6 @@ public class ProductSpuServiceImpl implements ProductSpuService {
}
}
private void validateCouponTemplate(Collection<Long> ids) {
List<CouponTemplateRespDTO> couponTemplateList = couponTemplateApi.getCouponTemplateListByIds(ids);
if (couponTemplateList.size() != ids.size()) {
throw exception(SPU_SAVE_FAIL_COUPON_TEMPLATE_NOT_EXISTS);
}
}
@Override
public List<ProductSpuDO> validateSpuList(Collection<Long> ids) {
if (CollUtil.isEmpty(ids)) {