licailing преди 5 години
родител
ревизия
1cc94fb115

+ 4 - 0
src/main/java/com/izouma/dingdong/domain/backstage/Priority.java

@@ -25,15 +25,19 @@ public class Priority extends BaseEntity {
     @ApiModelProperty(value = "级别", name = "level")
     @ApiModelProperty(value = "级别", name = "level")
     private Integer level;
     private Integer level;
 
 
+    //升级条件
     @ApiModelProperty(value = "所需点赞", name = "likes")
     @ApiModelProperty(value = "所需点赞", name = "likes")
     private Integer likes;
     private Integer likes;
 
 
+    //升级条件
     @ApiModelProperty(value = "所需月销", name = "monthSales")
     @ApiModelProperty(value = "所需月销", name = "monthSales")
     private Integer monthSales;
     private Integer monthSales;
 
 
+    //降级条件
     @ApiModelProperty(value = "一个月销量可为0的天数", name = "zeroSalesDay")
     @ApiModelProperty(value = "一个月销量可为0的天数", name = "zeroSalesDay")
     private Integer zeroSalesDay;
     private Integer zeroSalesDay;
 
 
+    //降级条件
     @ApiModelProperty(value = "月最低销量", name = "lessMonthSales")
     @ApiModelProperty(value = "月最低销量", name = "lessMonthSales")
     private Integer lessMonthSales;
     private Integer lessMonthSales;
 
 

+ 9 - 0
src/main/java/com/izouma/dingdong/repo/backstage/PriorityRepo.java

@@ -7,10 +7,19 @@ import org.springframework.data.jpa.repository.Modifying;
 import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.jpa.repository.Query;
 
 
 import javax.transaction.Transactional;
 import javax.transaction.Transactional;
+import java.util.List;
 
 
 public interface PriorityRepo extends JpaRepository<Priority, Long>, JpaSpecificationExecutor<Priority> {
 public interface PriorityRepo extends JpaRepository<Priority, Long>, JpaSpecificationExecutor<Priority> {
     @Query("update Priority t set t.enabled = false where t.id = ?1")
     @Query("update Priority t set t.enabled = false where t.id = ?1")
     @Modifying
     @Modifying
     @Transactional
     @Transactional
     void deleteById(Long id);
     void deleteById(Long id);
+
+    List<Priority> findAllByTypeOrderByLevel(Integer type);
+
+    Priority findByTypeAndLevel(Integer type, Integer level);
+
+    @Query("select max(p.level) from Priority p where p.type = ?1")
+    Integer findByTypeAndLevelMax(Integer type);
+
 }
 }

+ 70 - 4
src/main/java/com/izouma/dingdong/service/merchant/GoodsService.java

@@ -1,16 +1,19 @@
 package com.izouma.dingdong.service.merchant;
 package com.izouma.dingdong.service.merchant;
 
 
+import cn.hutool.core.bean.BeanUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.ObjectUtil;
 import com.izouma.dingdong.config.Constants;
 import com.izouma.dingdong.config.Constants;
 import com.izouma.dingdong.converter.LongArrayConverter;
 import com.izouma.dingdong.converter.LongArrayConverter;
 import com.izouma.dingdong.converter.StringArrayConverter;
 import com.izouma.dingdong.converter.StringArrayConverter;
 import com.izouma.dingdong.domain.backstage.Email;
 import com.izouma.dingdong.domain.backstage.Email;
+import com.izouma.dingdong.domain.backstage.Priority;
 import com.izouma.dingdong.domain.merchant.*;
 import com.izouma.dingdong.domain.merchant.*;
 import com.izouma.dingdong.dto.AppraisalMerDTO;
 import com.izouma.dingdong.dto.AppraisalMerDTO;
 import com.izouma.dingdong.enums.ApplyStatus;
 import com.izouma.dingdong.enums.ApplyStatus;
 import com.izouma.dingdong.enums.GoodType;
 import com.izouma.dingdong.enums.GoodType;
 import com.izouma.dingdong.exception.BusinessException;
 import com.izouma.dingdong.exception.BusinessException;
 import com.izouma.dingdong.repo.backstage.EmailRepo;
 import com.izouma.dingdong.repo.backstage.EmailRepo;
+import com.izouma.dingdong.repo.backstage.PriorityRepo;
 import com.izouma.dingdong.repo.merchant.*;
 import com.izouma.dingdong.repo.merchant.*;
 import com.izouma.dingdong.service.AppraisalService;
 import com.izouma.dingdong.service.AppraisalService;
 import lombok.AllArgsConstructor;
 import lombok.AllArgsConstructor;
@@ -37,6 +40,7 @@ public class GoodsService {
     private SalesRepo salesRepo;
     private SalesRepo salesRepo;
     private MerchantSettingsService merchantSettingsService;
     private MerchantSettingsService merchantSettingsService;
     private MerchantService merchantService;
     private MerchantService merchantService;
+    private PriorityRepo priorityRepo;
 
 
     /**
     /**
      * 添加修改商品
      * 添加修改商品
@@ -283,15 +287,77 @@ public class GoodsService {
         LocalDate now = LocalDate.now();
         LocalDate now = LocalDate.now();
         //上个月日期
         //上个月日期
         LocalDate lastMonth = now.minusMonths(1);
         LocalDate lastMonth = now.minusMonths(1);
-        List<Sales> sales = salesRepo.findAllByGoodsIdAndDayBetween(goodsId, lastMonth, now);
 
 
+
+        LocalDate day = now.minusDays(1);
+        //月销为0天数
+        int countZeroSales = 0;
         //点赞数
         //点赞数
         Integer likes = 0;
         Integer likes = 0;
         //差评数
         //差评数
         Integer badReview = 0;
         Integer badReview = 0;
-        for (Sales s : sales) {
-            likes += s.getDayLikes();
-            badReview += s.getDayBad();
+        //销量
+        Integer sales = 0;
+
+        while (day.isBefore(lastMonth)) {
+            Sales daySales = salesRepo.findByGoodsIdAndDay(goodsId, now.minusDays(1));
+            if (ObjectUtil.isNull(daySales)) {
+                //月销为0天数
+                countZeroSales++;
+            } else {
+                likes += daySales.getDayLikes();
+                badReview += daySales.getDayBad();
+                sales += daySales.getDaySales();
+            }
+        }
+
+//        List<Sales> monthSales = salesRepo.findAllByGoodsIdAndDayBetween(goodsId, lastMonth, now);
+//        //点赞数
+//        Integer likes = 0;
+//        //差评数
+//        Integer badReview = 0;
+//        //销量
+//        Integer sales = 0;
+//        for (Sales s : monthSales) {
+//            likes += s.getDayLikes();
+//            badReview += s.getDayBad();
+//            sales += s.getDaySales();
+//        }
+
+        boolean add = true;
+        boolean plus = false;
+
+        //上一月该商品新增点赞数-新增差评数*10>0
+        if (likes - badReview * 10 < 0) {
+            add = false;
         }
         }
+
+        Integer priority = goods.getPriority();
+        Priority goodsPriority = priorityRepo.findByTypeAndLevel(1, priority);
+
+        //新增点赞数  月销量
+        if (likes < goodsPriority.getLikes() || sales < goodsPriority.getMonthSales()) {
+            add = false;
+        }
+
+        if (countZeroSales < goodsPriority.getZeroSalesDay()) {
+            plus = true;
+        } else if (likes - badReview * 3 < 0) {
+            plus = true;
+        } else if (sales < goodsPriority.getLessMonthSales()) {
+            plus = true;
+        }
+
+        if (add) {
+            if (!priority.equals(priorityRepo.findByTypeAndLevelMax(1))) {
+                goods.setPriority(priority + 1);
+            }
+        }
+        if (plus) {
+            if (!priority.equals(1)) {
+                goods.setPriority(priority - 1);
+            }
+        }
+
     }
     }
 }
 }

+ 9 - 3
src/main/java/com/izouma/dingdong/service/merchant/MerchantSettingsService.java

@@ -135,17 +135,23 @@ public class MerchantSettingsService {
         //优惠专区
         //优惠专区
         //主推荐位 2个
         //主推荐位 2个
         List<Promote> promote1 = promoteRepo.findAllByAction(1);
         List<Promote> promote1 = promoteRepo.findAllByAction(1);
-        promote1.subList(0, 2);
+        if (promote1.size() > 2) {
+            promote1.subList(0, 2);
+        }
         //副推荐位 4个
         //副推荐位 4个
         List<Promote> promote2 = promoteRepo.findAllByAction(2);
         List<Promote> promote2 = promoteRepo.findAllByAction(2);
-        promote2.subList(0, 4);
+        if (promote2.size() > 4) {
+            promote2.subList(0, 4);
+        }
 
 
         //新店推荐 最多8个
         //新店推荐 最多8个
         LocalDate date = LocalDate.now().minusMonths(1);
         LocalDate date = LocalDate.now().minusMonths(1);
         LocalTime time = LocalTime.parse("00:00:00");
         LocalTime time = LocalTime.parse("00:00:00");
         LocalDateTime dateTime = LocalDateTime.of(date, time);
         LocalDateTime dateTime = LocalDateTime.of(date, time);
         List<Merchant> newMerchants = merchantRepo.findAllByEstablishTimeAfter(dateTime);
         List<Merchant> newMerchants = merchantRepo.findAllByEstablishTimeAfter(dateTime);
-        newMerchants.subList(0, 8);
+        if (newMerchants.size() > 8) {
+            newMerchants.subList(0, 8);
+        }
 
 
 
 
         Map<String, Object> map = new HashMap<>();
         Map<String, Object> map = new HashMap<>();

+ 12 - 0
src/test/java/com/izouma/dingdong/service/MerchantServiceTest.java

@@ -126,4 +126,16 @@ public class MerchantServiceTest {
 
 
         //System.out.println(TencentLocationUtils.distanceBetween(31.981746, 118.734661, 31.990671, 118.754795));
         //System.out.println(TencentLocationUtils.distanceBetween(31.981746, 118.734661, 31.990671, 118.754795));
     }*/
     }*/
+
+    @Test
+    public void testIndex(){
+        Map<String, Object> index = merchantSettingsService.index(118.00, 31.0);
+        System.out.println(index.get("banner"));
+        System.out.println(index.get("categories"));
+        System.out.println(index.get("timeTag"));
+        System.out.println(index.get("promote1"));
+        System.out.println(index.get("promote2"));
+        System.out.println(index.get("newMerchants"));
+
+    }
 }
 }