|
|
@@ -1,6 +1,7 @@
|
|
|
package com.izouma.dingdong.service.merchant;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.izouma.dingdong.domain.merchant.GoodsSpecification;
|
|
|
import com.izouma.dingdong.exception.BusinessException;
|
|
|
@@ -62,4 +63,34 @@ public class GoodsSpecificationService {
|
|
|
return all;
|
|
|
}
|
|
|
|
|
|
+ public List<GoodsSpecification> save(List<GoodsSpecification> specifications){
|
|
|
+ List<GoodsSpecification> all = new ArrayList<>();
|
|
|
+ specifications.forEach(s -> {
|
|
|
+ goodsRepo.findById(s.getGoodsId()).orElseThrow(new BusinessException("商品不存在"));
|
|
|
+ GoodsSpecification save;
|
|
|
+ if (s.getId() != null) {
|
|
|
+ GoodsSpecification specification = goodsSpecificationRepo.findById(s.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ ObjUtils.merge(specification, s);
|
|
|
+ save = goodsSpecificationRepo.save(specification);
|
|
|
+ } else {
|
|
|
+ save = goodsSpecificationRepo.save(s);
|
|
|
+ }
|
|
|
+ all.add(save);
|
|
|
+ if (CollUtil.isNotEmpty(s.getChildren())) {
|
|
|
+ s.getChildren().forEach(c -> {
|
|
|
+ c.setParent(save.getId());
|
|
|
+ if (c.getId() != null) {
|
|
|
+ GoodsSpecification specification = goodsSpecificationRepo.findById(s.getId()).orElseThrow(new BusinessException("无记录"));
|
|
|
+ ObjUtils.merge(specification, s);
|
|
|
+ all.add(goodsSpecificationRepo.save(specification));
|
|
|
+ } else {
|
|
|
+ all.add(goodsSpecificationRepo.save(c));
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return all;
|
|
|
+ }
|
|
|
+
|
|
|
}
|