|
|
@@ -1,5 +1,7 @@
|
|
|
package com.izouma.dingdong.service;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.izouma.dingdong.domain.merchant.Goods;
|
|
|
import com.izouma.dingdong.domain.merchant.GoodsSpecification;
|
|
|
import com.izouma.dingdong.domain.merchant.MerchantClassification;
|
|
|
@@ -9,6 +11,7 @@ import com.izouma.dingdong.repo.merchant.GoodsRepo;
|
|
|
import com.izouma.dingdong.repo.merchant.GoodsSpecificationRepo;
|
|
|
import com.izouma.dingdong.service.merchant.GoodsService;
|
|
|
import com.izouma.dingdong.service.merchant.GoodsSpecificationService;
|
|
|
+import com.izouma.dingdong.utils.ObjUtils;
|
|
|
import com.izouma.dingdong.utils.SecurityUtils;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
@@ -39,27 +42,27 @@ public class GoodsServiceTest {
|
|
|
private GoodsSpecificationService goodsSpecificationService;
|
|
|
|
|
|
@Test
|
|
|
- public void testApp(){
|
|
|
+ public void testApp() {
|
|
|
System.out.println(appraisalService.goodsAppraisals(214L));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void showGoods(){
|
|
|
+ public void showGoods() {
|
|
|
HashMap<String, Object> map = new HashMap<>();
|
|
|
Goods goods = goodsRepo.findById(214L).orElseThrow(new BusinessException("无记录"));
|
|
|
- map.put("goods",goods);
|
|
|
+ map.put("goods", goods);
|
|
|
|
|
|
List<AppraisalMerDTO> appraisals = appraisalService.goodsAppraisals(214L);
|
|
|
- map.put("appraisal",appraisals);
|
|
|
+ map.put("appraisal", appraisals);
|
|
|
|
|
|
List<GoodsSpecification> specifications = goodsSpecificationRepo.findAllByGoodsId(214L);
|
|
|
- map.put("specification",specifications);
|
|
|
+ map.put("specification", specifications);
|
|
|
|
|
|
System.out.println(map);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
- public void goodsSpec(){
|
|
|
+ public void goodsSpec() {
|
|
|
GoodsSpecification spec1 = GoodsSpecification.builder()
|
|
|
.multiple(false)
|
|
|
.name("甜度")
|
|
|
@@ -87,7 +90,7 @@ public class GoodsServiceTest {
|
|
|
.goodsId(121L)
|
|
|
.build();
|
|
|
spec4.setId(-4L);*/
|
|
|
- GoodsSpecification spec5 = GoodsSpecification.builder()
|
|
|
+ GoodsSpecification spec5 = GoodsSpecification.builder()
|
|
|
.amount(BigDecimal.ONE)
|
|
|
.name("半糖")
|
|
|
.goodsId(1258L)
|
|
|
@@ -110,7 +113,6 @@ public class GoodsServiceTest {
|
|
|
spec7.setId(-7L);*/
|
|
|
|
|
|
|
|
|
-
|
|
|
List<GoodsSpecification> specifications = new ArrayList<>(3);
|
|
|
specifications.add(spec1);
|
|
|
specifications.add(spec2);
|
|
|
@@ -121,4 +123,57 @@ public class GoodsServiceTest {
|
|
|
// specifications.add(spec7);
|
|
|
goodsSpecificationService.saveAll(specifications);
|
|
|
}
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void t() {
|
|
|
+ List<GoodsSpecification> spec = new ArrayList<>();
|
|
|
+ GoodsSpecification spec5 = GoodsSpecification.builder()
|
|
|
+ .amount(BigDecimal.ZERO)
|
|
|
+ .name("少糖")
|
|
|
+ .goodsId(1258L)
|
|
|
+ .build();
|
|
|
+ //spec5.setId(1513L);
|
|
|
+ spec.add(spec5);
|
|
|
+ GoodsSpecification spec6 = GoodsSpecification.builder()
|
|
|
+ // .amount(BigDecimal.ZERO)
|
|
|
+ .name("糖量")
|
|
|
+ //.goodsId(1258L)
|
|
|
+ //.multiple(false)
|
|
|
+ // .parent(-4L)
|
|
|
+ .children(spec)
|
|
|
+ .build();
|
|
|
+ spec6.setId(1512L);
|
|
|
+
|
|
|
+ List<GoodsSpecification> spec1 = new ArrayList<>();
|
|
|
+ spec1.add(spec6);
|
|
|
+ String str = JSONObject.toJSONString(spec1);
|
|
|
+ System.out.println(str);
|
|
|
+ List<GoodsSpecification> specifications = JSONObject.parseArray(str, GoodsSpecification.class);
|
|
|
+ System.out.println(specifications);
|
|
|
+
|
|
|
+ specifications.forEach(s -> {
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+
|
|
|
+ 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);
|
|
|
+ goodsSpecificationRepo.save(specification);
|
|
|
+ } else {
|
|
|
+ goodsSpecificationRepo.save(c);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
}
|