|
|
|
@ -1,10 +1,15 @@ |
|
|
|
package com.qniao.dam.application.service.product; |
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
|
|
import com.qniao.dam.domain.aggregate.product.ProductAggregate; |
|
|
|
import com.qniao.dam.domain.aggregate.product.entity.Product; |
|
|
|
import com.qniao.dam.domain.aggregate.product.repository.ProductRepository; |
|
|
|
import com.qniao.dam.domain.aggregate.productspec.entity.ProductSpec; |
|
|
|
import com.qniao.dam.domain.service.product.CreateProductDomainService; |
|
|
|
import com.qniao.dam.domain.service.product.EditProductDomainService; |
|
|
|
import com.qniao.dam.domian.aggregate.product.constant.ProductStatusEnum; |
|
|
|
import com.qniao.dam.infrastructure.persistent.dao.domain.ProductDao; |
|
|
|
import com.qniao.framework.exception.BizException; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
@ -18,6 +23,10 @@ public class ProductApplicationService { |
|
|
|
private EditProductDomainService editProductDomainService; |
|
|
|
@Resource |
|
|
|
private ProductAggregate productAggregate; |
|
|
|
@Resource |
|
|
|
private ProductRepository productRepository; |
|
|
|
@Resource |
|
|
|
private ProductDao productDao; |
|
|
|
|
|
|
|
public Long create(Product product, ProductSpec productSpec) { |
|
|
|
createProductDomainService.handle(product, productSpec); |
|
|
|
@ -29,6 +38,15 @@ public class ProductApplicationService { |
|
|
|
} |
|
|
|
|
|
|
|
public void operate(Product product) { |
|
|
|
if (ProductStatusEnum.SHELVED.equals(product.getStatus())) { |
|
|
|
Product oldProduct = productRepository.load(product.getId()); |
|
|
|
if (productDao.selectCount(new LambdaQueryWrapper<Product>() |
|
|
|
.eq(Product::getSubCategory, oldProduct.getSubCategory()) |
|
|
|
.eq(Product::getStatus, true) |
|
|
|
.ne(Product::getId, product.getId())) > 0) { |
|
|
|
throw new BizException("不能同时上架相同类型的产品"); |
|
|
|
} |
|
|
|
} |
|
|
|
productAggregate.operate(product); |
|
|
|
} |
|
|
|
} |