|
|
@@ -12,6 +12,7 @@ import com.ylx.massage.domain.vo.SpecComboVO;
|
|
|
import com.ylx.massage.mapper.*;
|
|
|
import com.ylx.massage.service.ProductService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
@@ -236,25 +237,30 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 设置商品规格
|
|
|
+ * 新增商品规格
|
|
|
+ *
|
|
|
+ @param dto 规格设置请求DTO
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void setupSpec(ProductSpecSetupDTO dto) {
|
|
|
+ if (StringUtils.isBlank(dto.getProductNo())) {
|
|
|
+ throw new RuntimeException("商品编号不能为空");
|
|
|
+ }
|
|
|
// 保存新的规格
|
|
|
if (!CollectionUtils.isEmpty(dto.getSpecList())) {
|
|
|
AtomicInteger specIndex = new AtomicInteger(0);
|
|
|
for (ProductSpecSetupDTO.SpecItemDTO specItem : dto.getSpecList()) {
|
|
|
- // 保存规格名
|
|
|
- ProductSpec spec = new ProductSpec();
|
|
|
- spec.setProductNo(dto.getProductNo());
|
|
|
- // 检查规格名是否存在,如果存在,则直接通过,不插入
|
|
|
+ // 根据商品编号检查规格名是否存在,如果存在,则直接通过,不插入
|
|
|
LambdaQueryWrapper<ProductSpec> specWrapper = new LambdaQueryWrapper<>();
|
|
|
- specWrapper.eq(ProductSpec::getSpecName, specItem.getSpecName());
|
|
|
+ specWrapper.eq(ProductSpec::getProductNo, dto.getProductNo()).eq(ProductSpec::getSpecName, specItem.getSpecName());
|
|
|
ProductSpec existingSpec = productSpecMapper.selectOne(specWrapper);
|
|
|
if (existingSpec != null) {
|
|
|
continue;
|
|
|
}
|
|
|
+ // 保存规格名
|
|
|
+ ProductSpec spec = new ProductSpec();
|
|
|
+ spec.setProductNo(dto.getProductNo());
|
|
|
spec.setSpecName(specItem.getSpecName());
|
|
|
spec.setSort(specItem.getSort() != null ? specItem.getSort() : specIndex.get() + 1);
|
|
|
productSpecMapper.insert(spec);
|