licailing 5 лет назад
Родитель
Сommit
e09554ca77

+ 7 - 7
src/main/java/com/izouma/dingdong/domain/merchant/Goods.java

@@ -48,16 +48,16 @@ public class Goods extends BaseEntity implements Serializable {
     private Integer inventory;
 
     @ApiModelProperty(value = "销量", name = "sales")
-    private Integer totalSales = 0;
+    private Integer totalSales;
 
 //    @ApiModelProperty(value = "日销售额", name = "daySales")
 //    private Integer daySales;
 
     @ApiModelProperty(value = "点赞数量", name = "likes")
-    private Integer likes = 0;
+    private Integer likes;
 
     @ApiModelProperty(value = "差评数量", name = "bad")
-    private Integer bad = 0;
+    private Integer bad;
 
     @ApiModelProperty(value = "价格", name = "amount")
     private BigDecimal amount;
@@ -66,16 +66,16 @@ public class Goods extends BaseEntity implements Serializable {
     private BigDecimal discountAmount;
 
     @ApiModelProperty(value = "招牌", name = "signboard")
-    private Boolean signboard = false;
+    private Boolean signboard;
 
     @ApiModelProperty(value = "下架", name = "takeOff")
-    private Boolean takeOff = false;
+    private Boolean takeOff;
 
 //    @ApiModelProperty(value = "排布", name = "sort")
 //    private Integer sort;
 
     @ApiModelProperty(value = "是否参与满减", name = "isFullReduction")
-    private Boolean isFullReduction = true;
+    private Boolean isFullReduction;
 
     @ApiModelProperty(value = "周几", name = "week")
     private String week;
@@ -103,7 +103,7 @@ public class Goods extends BaseEntity implements Serializable {
      * 首页推荐
      */
     @ApiModelProperty(value = "推荐", name = "recommend")
-    private Boolean recommend = false;
+    private Boolean recommend;
 
     @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
     @JoinColumn(name = "goodsId")

+ 3 - 26
src/main/java/com/izouma/dingdong/service/OrderInfoService.java

@@ -28,6 +28,7 @@ import com.izouma.dingdong.service.merchant.MerchantService;
 import com.izouma.dingdong.service.merchant.MerchantSettingsService;
 import com.izouma.dingdong.service.merchant.SalesService;
 import com.izouma.dingdong.service.rider.RiderService;
+import com.izouma.dingdong.service.user.ShoppingCartService;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
 
@@ -60,6 +61,7 @@ public class OrderInfoService {
     private RiderRepo riderRepo;
     private RiderService riderService;
     private MerchantSettingsService merchantSettingsService;
+    private ShoppingCartService shoppingCartService;
 
     /*
     用户下单
@@ -165,32 +167,6 @@ public class OrderInfoService {
                 }
         );
 
-//        //详细商品信息
-//        userOrderDTO.getGoodsSpecs().forEach(goodsSpecDTO -> {
-//                    //查库存是否足够
-//                    Goods goods = goodsService.buy(goodsSpecDTO.getGoodsId(), goodsSpecDTO.getNum());
-//
-//                    //商品销售时间内
-//                    if (goods.getStartTime().compareTo(nowTime) >= 0 || goods.getEndTime().compareTo(nowTime) <= 0) {
-//                        throw new BusinessException("非营业时间");
-//                    }
-//
-//                    //保存规格
-//                    orderGoodsSpecRepo.save(OrderGoodsSpec.builder()
-//                            .goodsId(goodsSpecDTO.getGoodsId())
-//                            .goodsPrice(goodsSpecDTO.getGoodsPrice())
-//                            .num(goodsSpecDTO.getNum())
-//                            .specification(goodsSpecDTO.getSpecification().toString())
-//                            .orderId(orderInfo.getId())
-//                            .build());
-//
-//                    //查商品数据,加商品销量,减商品库存
-//                    goods.setInventory(goods.getInventory() - goodsSpecDTO.getNum());
-//                    goods.setTotalSales(goods.getTotalSales() + goodsSpecDTO.getNum());
-//                    goodsRepo.save(goods);
-//                }
-//        );
-
         //商家是否自动接单
         if (merchantSettings.getAutomaticOrder()) {
             merReceiveOrder(save.getId(), true);
@@ -425,4 +401,5 @@ public class OrderInfoService {
     /*
     支付倒计时
      */
+
 }

+ 8 - 5
src/main/java/com/izouma/dingdong/service/merchant/MerchantService.java

@@ -266,11 +266,14 @@ public class MerchantService {
 
 //        Specification<Merchant> specification = toSpecification(pageQuery, Merchant.class);
 
-        List<Merchant> merchantList = merchantRepo.findAll((root, criteriaQuery, criteriaBuilder) ->
-                        criteriaQuery.where(
-                                criteriaBuilder.and(
-                                        criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")),
-                                criteriaBuilder.equal(root.get("status"), ApplyStatus.PASS)).getRestriction()
+        List<Merchant> merchantList = merchantRepo.findAll((root, criteriaQuery, criteriaBuilder) -> {
+                    List<Predicate> predicates = new ArrayList<>();
+                    predicates.add(criteriaBuilder.equal(root.get("status"), ApplyStatus.PASS));
+                    if (StrUtil.isNotBlank(pageQuery.getSearch())) {
+                        predicates.add(criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%"));
+                    }
+                    return criteriaBuilder.and(predicates.toArray(new Predicate[0]));
+                }
                 //criteriaBuilder.like(root.get("name"), "%" + pageQuery.getSearch() + "%")).getRestriction()
         );
 

+ 1 - 41
src/main/java/com/izouma/dingdong/service/merchant/SalesService.java

@@ -39,7 +39,6 @@ public class SalesService {
     下订单时插入销量
      */
     public void addSale(OrderInfo orderInfo) {
-
         //订单规格
         List<OrderGoodsSpec> orderGoodsSpecs = orderGoodsSpecRepo.findAllByOrderInfoId(orderInfo.getId());
 
@@ -47,38 +46,10 @@ public class SalesService {
                 spec -> {
                     //查商品销量表的销量数据
                     Sales daySales = this.newSales(spec.getGoodsId(), LocalDate.now());
-/*                    Sales daySales = salesRepo.findByGoodsIdAndDay(spec.getGoodsId(), localDate);
-                    if (daySales == null) {
-                        daySales = Sales.builder()
-                                .goodsId(spec.getGoodsId())
-                                .day(localDate)
-                                .dayLikes(0)
-                                .dayBad(0)
-                                .popularity(0)
-                                .praise(0)
-                                .daySales(0)
-                                .build();
-                    }*/
 
                     //有订单,销量 + 购买数量
                     daySales.setDaySales(daySales.getDaySales() + spec.getNum());
 
-                    /*//已评价
-                    if (orderInfo.getRated()) {
-                        Appraisal appraisal = appraisalRepo.findByOrderId(orderInfo.getId()).orElseThrow(new BusinessException("评价不存在"));
-                        if (appraisal.getGoodsLike()) {
-                            daySales.setDayLikes(daySales.getDayLikes() + 1);
-                            //查商品数据,加好评数
-                            goodsRepo.updateLikesById(spec.getGoodsId());
-                        }
-
-                        if (appraisal.getGoodsBad()) {
-                            daySales.setDayBad(daySales.getDayBad() + 1);
-                            //查商品数据,加差评数
-                            goodsRepo.updateBadById(spec.getGoodsId());
-                        }
-                    }*/
-
                     //保存
                     salesRepo.save(daySales);
                 }
@@ -89,23 +60,12 @@ public class SalesService {
     评价时加入销量
      */
     public void addLike(Appraisal appraisal) {
-        //ppraisal appraisal = appraisalRepo.findByOrderInfoId(appraisalId).orElseThrow(new BusinessException("评价不存在"));
+        //Appraisal appraisal = appraisalRepo.findByOrderInfoId(appraisalId).orElseThrow(new BusinessException("评价不存在"));
         List<OrderGoodsSpec> specs = orderGoodsSpecRepo.findAllByOrderInfoId(appraisal.getOrderInfoId());
 
         specs.forEach(spec -> {
             //Sales daySales = salesRepo.findByGoodsIdAndDay(spec.getGoodsId(), LocalDate.now());
             Sales daySales = this.newSales(spec.getGoodsId(), LocalDate.now());
-/*            if (daySales == null) {
-                daySales = Sales.builder()
-                        .goodsId(spec.getGoodsId())
-                        .day(LocalDate.now())
-                        .dayLikes(0)
-                        .dayBad(0)
-                        .popularity(0)
-                        .praise(0)
-                        .daySales(0)
-                        .build();
-            }*/
 
             if (appraisal.getGoodsLike()) {
                 daySales.setDayLikes(daySales.getDayLikes() + 1);

+ 15 - 0
src/main/java/com/izouma/dingdong/service/user/ShoppingCartService.java

@@ -16,6 +16,7 @@ import com.izouma.dingdong.repo.UserRepo;
 import com.izouma.dingdong.repo.merchant.FullReductionRepo;
 import com.izouma.dingdong.repo.merchant.GoodsRepo;
 import com.izouma.dingdong.repo.merchant.MerchantSettingsRepo;
+import com.izouma.dingdong.service.OrderGoodsSpecService;
 import com.izouma.dingdong.service.merchant.GoodsService;
 import lombok.AllArgsConstructor;
 import org.springframework.stereotype.Service;
@@ -38,6 +39,7 @@ public class ShoppingCartService {
     private MerchantSettingsRepo merchantSettingsRepo;
     private FullReductionRepo fullReductionRepo;
     private OrderGoodsSpecRepo orderGoodsSpecRepo;
+    private OrderGoodsSpecService orderGoodsSpecService;
 
     /*
     创建购物车
@@ -341,4 +343,17 @@ public class ShoppingCartService {
         return this.calculatePrice(cartId, userId);
     }
 
+    /*
+    再来一单
+     */
+    public OrderInfo again(Long id){
+        OrderInfo orderInfo = orderInfoRepo.findById(id).orElseThrow(new BusinessException("无订单"));
+        List<OrderGoodsSpec> orderGoodsSpecs = orderInfo.getOrderGoodsSpecs();
+        orderGoodsSpecs.forEach(o->{
+
+        });
+
+        return null;
+    }
+
 }

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

@@ -1,5 +1,6 @@
 package com.izouma.dingdong.web;
 
+import com.izouma.dingdong.domain.OrderGoodsSpec;
 import com.izouma.dingdong.domain.OrderInfo;
 import com.izouma.dingdong.domain.User;
 import com.izouma.dingdong.dto.OrderDTO;
@@ -141,5 +142,6 @@ public class OrderInfoController extends BaseController {
 
     //@GetMapping("/cancelCancelOrder")
 
+
 }
 

+ 1 - 0
src/main/java/com/izouma/dingdong/web/user/ShoppingCartController.java

@@ -110,5 +110,6 @@ public class ShoppingCartController extends BaseController {
         list.forEach(l -> orderGoodsSpecRepo.deleteAllByShoppingCartIdAndOrderInfoIdIsNull(l));
         shoppingCartRepo.deleteAllByUserId(id);
     }
+
 }
 

+ 22 - 0
src/test/java/com/izouma/dingdong/service/GoodsServiceTest.java

@@ -13,6 +13,7 @@ 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 com.izouma.dingdong.web.merchant.GoodsController;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -41,6 +42,9 @@ public class GoodsServiceTest {
     @Autowired
     private GoodsSpecificationService goodsSpecificationService;
 
+    @Autowired
+    private GoodsController goodsController;
+
     @Test
     public void testApp() {
         System.out.println(appraisalService.goodsAppraisals(214L));
@@ -176,4 +180,22 @@ public class GoodsServiceTest {
         });
 
     }
+
+
+    @Test
+    public void testSave(){
+        Goods goods = Goods.builder()
+                //.recommend(true)
+                .signboard(true)
+                .build();
+        goods.setId(310L);
+
+        Goods goods1 = Goods.builder()
+                .recommend(true)
+                .build();
+        goods1.setId(310L);
+
+        goodsController.save(goods);
+        //goodsController.save(goods1);
+    }
 }

+ 4 - 3
src/test/java/com/izouma/dingdong/service/MerchantServiceTest.java

@@ -109,11 +109,12 @@ public class MerchantServiceTest {
         PageQuery pageQuery = new PageQuery();
         pageQuery.setPage(0);
         pageQuery.setSize(50);
-        pageQuery.setSearch("");
+        pageQuery.setSearch(null);
         pageQuery.setSort("");
-        List<MerchantDTO> list = merchantService.showAll(pageQuery, 118.738275, 31.991961, null, 82L);
+        //118.738275 31.991961
+        List<MerchantDTO> list = merchantService.showAll(pageQuery, 1.0,1.0 , null, 82L);
 
-        System.out.println(list.get(0).getFullReductions());
+        System.out.println(list.size());
     }
 
 /*    @Test