licailing před 5 roky
rodič
revize
156c1553e1

+ 1 - 0
src/main/java/com/izouma/dingdong/repo/user/ShoppingCartRepo.java

@@ -26,4 +26,5 @@ public interface ShoppingCartRepo extends JpaRepository<ShoppingCart, Long>, Jpa
     @Modifying
     @Transactional
     void deleteAllByUserId(Long userId);
+
 }

+ 1 - 0
src/main/java/com/izouma/dingdong/service/merchant/MerchantService.java

@@ -368,6 +368,7 @@ public class MerchantService {
                         break;
                 }
             } else {
+                merchantDTO.setFullReductions(fullReductionRepo.findAllByMerchantId(merchantDTO.getMid()));
                 merchantDTOS.add(merchantDTO);
             }
         }

+ 10 - 1
src/main/java/com/izouma/dingdong/service/merchant/MerchantSettingsService.java

@@ -27,6 +27,7 @@ import com.izouma.dingdong.service.backstage.CategoryService;
 import lombok.AllArgsConstructor;
 import org.springframework.data.domain.Sort;
 import org.springframework.stereotype.Service;
+import org.springframework.web.bind.annotation.PathVariable;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -53,7 +54,7 @@ public class MerchantSettingsService {
     private AppraisalRepo appraisalRepo;
     private GoodsSpecificationRepo goodsSpecificationRepo;
     private MerchantClassificationRepo merchantClassificationRepo;
-    // private FullReductionRepo fullReductionRepo;
+    private FullReductionRepo fullReductionRepo;
 
     /*
     显示所有订单
@@ -259,4 +260,12 @@ public class MerchantSettingsService {
         }
         merchantRepo.saveAll(merchants);
     }
+
+    public MerchantDTO getDTO(Long id) {
+        Merchant merchant = merchantRepo.findById(id).orElseThrow(new BusinessException("无记录"));
+        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(id).orElseThrow(new BusinessException("无记录"));
+        MerchantDTO dto = new MerchantDTO(merchant, merchantSettings);
+        dto.setFullReductions(fullReductionRepo.findAllByMerchantId(id));
+        return dto;
+    }
 }

+ 16 - 6
src/main/java/com/izouma/dingdong/service/user/ShoppingCartService.java

@@ -1,5 +1,6 @@
 package com.izouma.dingdong.service.user;
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.izouma.dingdong.domain.OrderGoodsSpec;
@@ -186,6 +187,7 @@ public class ShoppingCartService {
 
                         orderGoodsSpecRepo.save(o);
                         orderGoodsSpecRepo.deleteById(orderGoodsSpec.getId());
+                        //orderGoodsSpecRepo.delete(orderGoodsSpec);
                         f = false;
                         break;
                     }
@@ -346,14 +348,22 @@ public class ShoppingCartService {
     /*
     再来一单
      */
-    public OrderInfo again(Long id) {
-        OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无订单"));
+    public ShoppingCart again(Long orderId) {
+        OrderInfo orderInfo = orderInfoRepo.findById(orderId).orElseThrow(new BusinessException("无订单"));
         List<OrderGoodsSpec> orderGoodsSpecs = orderInfo.getOrderGoodsSpecs();
-        orderGoodsSpecs.forEach(o -> {
-
-        });
+        Long userId = orderInfo.getUserId();
+        ShoppingCart cart = new ShoppingCart();
+        for (OrderGoodsSpec o : orderGoodsSpecs) {
+            OrderGoodsSpec spec = new OrderGoodsSpec();
+            BeanUtil.copyProperties(o, spec);
+            spec.setOrderInfoId(null);
+            spec.setShoppingCartId(null);
+            spec.setId(null);
+            orderGoodsSpecRepo.save(spec);
+            cart = this.add(userId, spec);
+        }
 
-        return null;
+        return cart;
     }
 
 }

+ 2 - 0
src/main/java/com/izouma/dingdong/web/merchant/GoodsController.java

@@ -46,6 +46,8 @@ public class GoodsController extends BaseController {
             if (record.getName() != null || record.getImg() != null) {
                 record.setStatus(ApplyStatus.PENDING);
             }
+            //如果修改价格,购物车内的商品就要重新计算
+           // if (record.getAmount())
             ObjUtils.merge(orig, record);
             return goodsService.save(orig);
         }

+ 1 - 3
src/main/java/com/izouma/dingdong/web/merchant/MerchantController.java

@@ -84,9 +84,7 @@ public class MerchantController extends BaseController {
 
     @GetMapping("/getDTO/{id}")
     public MerchantDTO getDTO(@PathVariable Long id) {
-        Merchant merchant = merchantRepo.findById(id).orElseThrow(new BusinessException("无记录"));
-        MerchantSettings merchantSettings = merchantSettingsRepo.findByMerchantId(id).orElseThrow(new BusinessException("无记录"));
-        return new MerchantDTO(merchant, merchantSettings);
+        return merchantSettingsService.getDTO(id);
     }
 
     @PostMapping("/saveDTO")

+ 10 - 6
src/test/java/com/izouma/dingdong/service/MerchantServiceTest.java

@@ -2,6 +2,7 @@ package com.izouma.dingdong.service;
 
 import com.izouma.dingdong.dto.MerchantDTO;
 import com.izouma.dingdong.dto.PageQuery;
+import com.izouma.dingdong.repo.merchant.FullReductionRepo;
 import com.izouma.dingdong.repo.merchant.MerchantRepo;
 import com.izouma.dingdong.service.merchant.MerchantService;
 import com.izouma.dingdong.service.merchant.MerchantSettingsService;
@@ -25,13 +26,10 @@ public class MerchantServiceTest {
 
     @Autowired
     private MerchantService merchantService;
-
     @Autowired
     private MerchantController merchantController;
-
     @Autowired
-    private MerchantRepo merchantRepo;
-
+    private FullReductionRepo fullReductionRepo;
     @Autowired
     private MerchantSettingsService merchantSettingsService;
 
@@ -109,12 +107,12 @@ public class MerchantServiceTest {
         PageQuery pageQuery = new PageQuery();
         pageQuery.setPage(0);
         pageQuery.setSize(50);
-        pageQuery.setSearch(null);
+        pageQuery.setSearch("走马");
         pageQuery.setSort("");
         //118.738275 31.991961
         List<MerchantDTO> list = merchantService.showAll(pageQuery, 1.0,1.0 , null, 82L);
 
-        System.out.println(list.size());
+        System.out.println(list);
     }
 
 /*    @Test
@@ -143,4 +141,10 @@ public class MerchantServiceTest {
 
         System.out.println(index);
     }
+
+    @Test
+    public void testFull(){
+        //System.out.println(fullReductionRepo.findAllByMerchantId(189L));
+        System.out.println(merchantSettingsService.getDTO(189L));
+    }
 }

+ 13 - 0
src/test/java/com/izouma/dingdong/service/ShoppingCartServiceTest.java

@@ -1,6 +1,7 @@
 package com.izouma.dingdong.service;
 
 import com.izouma.dingdong.domain.OrderGoodsSpec;
+import com.izouma.dingdong.exception.BusinessException;
 import com.izouma.dingdong.repo.OrderGoodsSpecRepo;
 import com.izouma.dingdong.repo.user.ShoppingCartRepo;
 import com.izouma.dingdong.service.user.ShoppingCartService;
@@ -45,4 +46,16 @@ public class ShoppingCartServiceTest {
         System.out.println(shoppingCartService.add(82L, add));
         //System.out.println(shoppingCartService.sub(1500L, 83L));
     }
+
+    @Test
+    public void testFalse(){
+        //System.out.println(shoppingCartRepo.findByIdAndEnabledIsFalse(1759L));
+
+        System.out.println(shoppingCartRepo.findById(1759L).orElse(null));
+    }
+
+    @Test
+    public void testAgain(){
+        System.out.println(shoppingCartService.again(1729L));
+    }
 }