|
|
@@ -4,10 +4,10 @@ import com.izouma.dingdong.domain.merchant.GoodsSpecification;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsSpecificationRepo;
|
|
|
+import com.izouma.dingdong.utils.ObjUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Set;
|
|
|
@@ -24,12 +24,11 @@ public class GoodsSpecificationService {
|
|
|
public List<GoodsSpecification> saveAll(List<GoodsSpecification> spec) {
|
|
|
List<GoodsSpecification> all = new ArrayList<>();
|
|
|
spec.forEach(s -> {
|
|
|
- goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
|
|
|
-
|
|
|
/* if (s.getAmount().compareTo(BigDecimal.ZERO) < 0) {
|
|
|
throw new BusinessException("规格价钱不得小于零");
|
|
|
}*/
|
|
|
if (s.getId() != null && s.getId() < 0 && s.getParent() == null) {
|
|
|
+ goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
|
|
|
GoodsSpecification save = goodsSpecificationRepo.save(s);
|
|
|
// if (s.getParent() == null) {
|
|
|
Set<GoodsSpecification> collect = spec.stream().filter(g -> g.getParent() != null && g.getParent().equals(s.getId())).collect(Collectors.toSet());
|
|
|
@@ -43,9 +42,16 @@ public class GoodsSpecificationService {
|
|
|
});
|
|
|
// }
|
|
|
all.add(save);
|
|
|
- } else if (s.getParent() > 0) {
|
|
|
+ } else if ((s.getId() == null || s.getId() < 0) && s.getParent() > 0) {
|
|
|
+ goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
|
|
|
goodsSpecificationRepo.findById(s.getParent()).orElseThrow(new BusinessException("无分类"));
|
|
|
all.add(goodsSpecificationRepo.save(s));
|
|
|
+ } else if (s.getId() > 0) {
|
|
|
+ //修改
|
|
|
+ GoodsSpecification goodsSpecification = goodsSpecificationRepo.findById(s.getId()).orElseThrow(new BusinessException("不存在"));
|
|
|
+ ObjUtils.merge(goodsSpecification, s);
|
|
|
+ goodsRepo.findById(goodsSpecification.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
|
|
|
+ all.add(goodsSpecificationRepo.save(goodsSpecification));
|
|
|
}
|
|
|
});
|
|
|
|