瀏覽代碼

展厅热力值

licailing 4 年之前
父節點
當前提交
cc42ee19ff

+ 0 - 6
src/main/java/com/izouma/nineth/domain/Showroom.java

@@ -75,12 +75,6 @@ public class Showroom extends BaseEntity {
     @Transient
     private boolean liked;
 
-//    private int views;
-//
-//    private int buys;
-//
-//    private int registers;
-
     private int heats;
 
 }

+ 3 - 1
src/main/java/com/izouma/nineth/enums/HeatType.java

@@ -2,5 +2,7 @@ package com.izouma.nineth.enums;
 
 public enum HeatType {
     VIEW,
-    REGISTER
+    REGISTER,
+    BUY,
+    LIKE
 }

+ 2 - 0
src/main/java/com/izouma/nineth/event/CreateOrderEvent.java

@@ -26,4 +26,6 @@ public class CreateOrderEvent implements Serializable {
     @JsonSerialize(using = ToStringSerializer.class)
     private Long    invitor;
     private boolean vip;
+    @JsonSerialize(using = ToStringSerializer.class)
+    private Long    showroomId;
 }

+ 1 - 1
src/main/java/com/izouma/nineth/listener/CreateOrderListener.java

@@ -37,7 +37,7 @@ public class CreateOrderListener implements RocketMQListener<CreateOrderEvent> {
         try {
             Order order = orderService.create(event.getUserId(), event.getCollectionId(), event.getQty(),
                     event.getAddressId(), event.getUserCouponId(), event.getInvitor(), event.getId(),
-                    event.isVip());
+                    event.isVip(), event.getShowroomId());
             map.put("success", true);
             map.put("data", order);
         } catch (Exception e) {

+ 2 - 0
src/main/java/com/izouma/nineth/repo/HeatInfoRepo.java

@@ -11,4 +11,6 @@ public interface HeatInfoRepo extends JpaRepository<HeatInfo, Long>, JpaSpecific
 
     List<HeatInfo> findByUserIdAndShowroomIdAndType(Long userId, Long showroomId, HeatType type);
 
+    List<HeatInfo> findByUserIdAndOrderIdAndType(Long userId, Long orderId, HeatType type);
+
 }

+ 4 - 0
src/main/java/com/izouma/nineth/repo/ShowroomRepo.java

@@ -46,5 +46,9 @@ public interface ShowroomRepo extends JpaRepository<Showroom, Long>, JpaSpecific
     @Transactional
     void addHeat(Long id, int num);
 
+    @Query("update Showroom t set t.heats = t.heats + ?2, t.likes = t.likes + ?3 where t.id = ?1")
+    @Modifying
+    @Transactional
+    void addHeatAndLike(Long id, int heatNum, int likeNum);
 
 }

+ 17 - 4
src/main/java/com/izouma/nineth/service/NewsLikeService.java

@@ -1,7 +1,10 @@
 package com.izouma.nineth.service;
 
+import com.izouma.nineth.domain.HeatInfo;
 import com.izouma.nineth.domain.NewsLike;
 import com.izouma.nineth.dto.PageQuery;
+import com.izouma.nineth.enums.HeatType;
+import com.izouma.nineth.repo.HeatInfoRepo;
 import com.izouma.nineth.repo.NewsLikeRepo;
 import com.izouma.nineth.repo.NewsRepo;
 import com.izouma.nineth.repo.ShowroomRepo;
@@ -16,9 +19,11 @@ import java.util.List;
 @AllArgsConstructor
 public class NewsLikeService {
 
-    private NewsLikeRepo newsLikeRepo;
-    private NewsRepo     newsRepo;
-    private ShowroomRepo showroomRepo;
+    private NewsLikeRepo     newsLikeRepo;
+    private NewsRepo         newsRepo;
+    private ShowroomRepo     showroomRepo;
+    private SysConfigService sysConfigService;
+    private HeatInfoRepo     heatInfoRepo;
 
     public Page<NewsLike> all(PageQuery pageQuery) {
         return newsLikeRepo.findAll(JpaUtils.toSpecification(pageQuery, NewsLike.class), JpaUtils.toPageRequest(pageQuery));
@@ -49,7 +54,15 @@ public class NewsLikeService {
                 .userId(userId)
                 .showroomId(roomId)
                 .build());
-        showroomRepo.addLike(roomId, 1);
+        int weight = sysConfigService.getInt("heat_like_weight");
+        heatInfoRepo.save(HeatInfo.builder()
+                .showroomId(roomId)
+                .userId(userId)
+                .type(HeatType.LIKE)
+                .value(weight)
+                .build());
+        showroomRepo.addHeatAndLike(roomId, 1, weight);
+
     }
 
     public void unlikeRoom(Long userId, Long roomId) {

+ 27 - 1
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -1,5 +1,6 @@
 package com.izouma.nineth.service;
 
+import cn.hutool.core.collection.CollUtil;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
@@ -103,6 +104,8 @@ public class OrderService {
     private UserBankCardRepo              userBankCardRepo;
     private CacheService                  cacheService;
     private UserPropertyRepo              userPropertyRepo;
+    private HeatInfoRepo                  heatInfoRepo;
+    private ShowroomRepo                  showroomRepo;
 
     public Page<Order> all(PageQuery pageQuery) {
         return orderRepo.findAll(JpaUtils.toSpecification(pageQuery, Order.class), JpaUtils.toPageRequest(pageQuery));
@@ -143,7 +146,7 @@ public class OrderService {
 
         Long id = snowflakeIdWorker.nextId();
         SendResult result = rocketMQTemplate.syncSend(generalProperties.getCreateOrderTopic(),
-                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip), 100000);
+                new CreateOrderEvent(id, userId, collectionId, qty, addressId, userCouponId, invitor, vip, showroomId), 100000);
 
         log.info("发送订单到队列: {}, userId={}, result={}", id, userId, result);
         return String.valueOf(id);
@@ -352,6 +355,17 @@ public class OrderService {
                 userRepo.addVipPoint(userId, -usePoint);
                 cacheService.clearUserMy(userId);
             }
+
+            if (ObjectUtils.isNotEmpty(showroomId)) {
+                //通过展厅的购买数量
+                heatInfoRepo.save(HeatInfo.builder()
+                        .showroomId(showroomId)
+                        .userId(userId)
+                        .type(HeatType.BUY)
+                        .value(0)
+                        .orderId(order.getId())
+                        .build());
+            }
             rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), collectionId, 10000);
             log.info("订单创建完成, id={}, {}ms", order.getId(), System.currentTimeMillis() - t);
             return order;
@@ -692,6 +706,17 @@ public class OrderService {
                 if (collection.getAssetId() == null) {
                     collectionService.increaseSale(order.getCollectionId(), order.getQty());
                 }
+
+                //通过展厅购买加热力值
+                List<HeatInfo> heatInfos = heatInfoRepo.findByUserIdAndOrderIdAndType(order.getUserId(), orderId, HeatType.BUY);
+                if (CollUtil.isNotEmpty(heatInfos)) {
+                    HeatInfo heatInfo = heatInfos.get(0);
+                    int weight = sysConfigService.getInt("heat_buy_weight");
+                    heatInfo.setValue(weight);
+                    heatInfoRepo.save(heatInfo);
+                    showroomRepo.addHeat(heatInfo.getShowroomId(), weight);
+                }
+
             } else {
                 throw new BusinessException("状态错误 " + order.getStatus());
             }
@@ -837,6 +862,7 @@ public class OrderService {
                 collectionService.decreaseQuota(order.getCollectionId(), 1);
                 log.info("取消加藏品额度CollectionId:{}", order.getCollectionId());
             }
+
             rocketMQTemplate.syncSend(generalProperties.getUpdateQuotaTopic(), order.getCollectionId(), 10000);
             log.info("取消订单{}", order.getId());
         } catch (Exception e) {

+ 3 - 2
src/main/java/com/izouma/nineth/web/OrderController.java

@@ -113,11 +113,12 @@ public class OrderController extends BaseController {
                                             @RequestParam(required = false) Long couponId,
                                             @RequestParam(required = false) Long invitor,
                                             @RequestParam String sign,
-                                            @RequestParam(defaultValue = "false") boolean vip) {
+                                            @RequestParam(defaultValue = "false") boolean vip,
+                                            @RequestParam(required = false) Long showroomId) {
         final User user = SecurityUtils.getAuthenticatedUser();
         return new HashMap<>() {{
             put("id", orderService.mqCreate(user.getId(), collectionId, qty, addressId, couponId, invitor, sign,
-                    vip, user.getVipPurchase(), user.getVipPoint()));
+                    vip, showroomId));
         }};
     }
 

+ 5 - 1
src/main/java/com/izouma/nineth/web/ShowroomController.java

@@ -9,6 +9,7 @@ import com.izouma.nineth.enums.HeatType;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.service.ShowroomService;
+import com.izouma.nineth.service.SysConfigService;
 import com.izouma.nineth.utils.SecurityUtils;
 import com.izouma.nineth.utils.excel.ExcelUtils;
 import lombok.AllArgsConstructor;
@@ -32,6 +33,7 @@ public class ShowroomController extends BaseController {
     private NewsLikeRepo       newsLikeRepo;
     private CollectionRepo     collectionRepo;
     private HeatInfoRepo       heatInfoRepo;
+    private SysConfigService   sysConfigService;
 
     @PostMapping("/save")
     public Showroom save(@RequestBody Showroom record) {
@@ -144,12 +146,14 @@ public class ShowroomController extends BaseController {
         }
         List<HeatInfo> list = heatInfoRepo.findByUserIdAndShowroomIdAndType(userId, id, HeatType.VIEW);
         if (!list.isEmpty()) return;
+        int weight = sysConfigService.getInt("heat_view_weight");
         heatInfoRepo.save(HeatInfo.builder()
                 .userId(userId)
                 .showroomId(id)
                 .type(HeatType.VIEW)
+                .value(weight)
                 .build());
-        showroomRepo.addView(id, 1);
+        showroomRepo.addHeat(id, weight);
     }