Browse Source

Merge branch 'dev' into 2D展厅

licailing 3 years ago
parent
commit
6b51cfbf56

+ 3 - 2
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -31,14 +31,15 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
             "c.properties = ?9, c.model3d = ?10, c.max_count = ?11, c.count_id = ?12, c.scan_code = ?13, " +
             "c.no_sold_out = ?14, c.assignment = ?15, c.coupon_payment = ?16, c.share_bg = ?17," +
             "c.register_bg = ?18, c.vip_quota = ?19, c.time_delay = ?20, c.sale_time = ?21, c.hold_days = ?22, " +
-            "c.open_quota = ?23, c.showroom_bg = ?24, c.max_collection = ?25 where c.id = ?1", nativeQuery = true)
+            "c.open_quota = ?23, c.showroom_bg = ?24, c.max_collection = ?25, c.total_quota = ?26 " +
+            "where c.id = ?1", nativeQuery = true)
     @CacheEvict(value = {"collection", "recommend"}, allEntries = true)
     void update(@Nonnull Long id, boolean onShelf, boolean salable, LocalDateTime startTime,
                 boolean schedule, int sort, String detail, String privileges,
                 String properties, String model3d, int maxCount, String countId, boolean scanCode,
                 boolean noSoldOut, int assignment, boolean couponPayment, String shareBg, String registerBg,
                 Integer vipQuota, Boolean timeDelay, LocalDateTime saleTime, Integer holdDays, Boolean openQuota,
-                String showroomBg, Integer maxCollection);
+                String showroomBg, Integer maxCollection, Integer totalQuota);
 
     @Cacheable("collection")
     Optional<Collection> findById(@Nonnull Long id);

+ 13 - 0
src/main/java/com/izouma/nineth/repo/UserRepo.java

@@ -13,6 +13,7 @@ import org.springframework.lang.NonNull;
 
 import javax.transaction.Transactional;
 import java.time.LocalDateTime;
+import java.util.Collection;
 import java.util.List;
 import java.util.Optional;
 
@@ -195,4 +196,16 @@ public interface UserRepo extends JpaRepository<User, Long>, JpaSpecificationExe
     @Transactional
     @Modifying
     void setAuthStatus(Long id, AuthStatus status, Long authId);
+
+    @Query(nativeQuery = true, value = "select collection_invitor" +
+            " from user" +
+            " where collection_id = ?1" +
+            " group by collection_invitor" +
+            " having count(id) >= ?2")
+    List<Long> findAllByCollectionId(Long collectionId, int size);
+
+    @Transactional
+    @Modifying
+    @Query("update User set vipPoint = 1 where vipPoint = 0 and id in ?1")
+    void updateAllByInvitor(Collection<Long> ids);
 }

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

@@ -156,7 +156,7 @@ public class CollectionService {
                 record.getMaxCount(), record.getCountId(), record.isScanCode(), record.isNoSoldOut(),
                 record.getAssignment(), record.isCouponPayment(), record.getShareBg(), record.getRegisterBg(),
                 record.getVipQuota(), record.getTimeDelay(), record.getSaleTime(), record.getHoldDays(),
-                record.getOpenQuota(), record.getShowroomBg(), record.getMaxCollection());
+                record.getOpenQuota(), record.getShowroomBg(), record.getMaxCollection(), record.getTotalQuota());
 
         record = collectionRepo.findById(record.getId()).orElseThrow(new BusinessException("无记录"));
         onShelfTask(record);

+ 3 - 0
src/main/java/com/izouma/nineth/service/IdentityAuthService.java

@@ -40,6 +40,7 @@ public class IdentityAuthService {
     private RedisTemplate<String, Object> redisTemplate;
     private Environment                   env;
     private SysConfigService              sysConfigService;
+    private CacheService                  cacheService;
 
     public Page<IdentityAuth> all(PageQuery pageQuery) {
         return identityAuthRepo.findAll(JpaUtils.toSpecification(pageQuery, IdentityAuth.class), JpaUtils.toPageRequest(pageQuery));
@@ -61,6 +62,7 @@ public class IdentityAuthService {
         identityAuthRepo.save(identityAuth);
         user.setAuthStatus(AuthStatus.PENDING);
         userRepo.save(user);
+        cacheService.clearUserMy(user.getId());
 
         identityAuthRepo.deleteDuplicated(identityAuth.getUserId(), identityAuth.getId());
     }
@@ -82,6 +84,7 @@ public class IdentityAuthService {
         auth.setReason(reason);
         auth.setAutoValidated(true);
         identityAuthRepo.save(auth);
+        cacheService.clearUserMy(user.getId());
 
         identityAuthRepo.deleteDuplicated(auth.getUserId(), auth.getId());
     }

+ 10 - 3
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -299,7 +299,11 @@ public class OrderService {
             if (usePoint > 0) {
                 // 扣除积分
                 userRepo.addVipPoint(userId, usePoint);
-                log.info("取消加积分用户ID:{}, 积分:{}", userId, usePoint);
+                log.info("订单失败加积分用户ID:{}, 积分:{}", userId, usePoint);
+            }
+            if (vip) {
+                collectionService.decreaseQuota(collectionId, 1);
+                log.info("订单失败加藏品额度CollectionId:{}", collectionId);
             }
             throw e;
         }
@@ -752,8 +756,11 @@ public class OrderService {
                 userRepo.updateVipPoint(order.getUserId(), order.getVipPoint());
                 log.info("取消加积分用户ID:{},订单ID:{},积分:{}", order.getUserId(), order.getId(), order.getVipPoint());
             }
-
-            rocketMQTemplate.syncSend(generalProperties.getUpdateStockTopic(), order.getCollectionId(), 10000);
+            if (order.isVip()) {
+                collectionService.decreaseQuota(order.getCollectionId(), 1);
+                log.info("取消加藏品额度CollectionId:{}", order.getCollectionId());
+            }
+            rocketMQTemplate.syncSend(generalProperties.getUpdateQuotaTopic(), order.getCollectionId(), 10000);
             log.info("取消订单{}", order.getId());
         } catch (Exception e) {
             if (e instanceof BusinessException) {

+ 7 - 0
src/main/java/com/izouma/nineth/web/StatisticController.java

@@ -6,6 +6,7 @@ import lombok.AllArgsConstructor;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
 import org.springframework.scheduling.annotation.Scheduled;
+import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
@@ -69,4 +70,10 @@ public class StatisticController {
         int monthValue = LocalDate.now().getMonthValue();
         cacheService.clearTop(monthValue);
     }
+
+    @PreAuthorize("hasRole('ADMIN')")
+    @GetMapping("/clearWeekTop")
+    public void clearWeekTop(){
+        cacheService.clearWeekTop();
+    }
 }

+ 8 - 4
src/test/java/com/izouma/nineth/repo/UserRepoTest.java

@@ -13,10 +13,7 @@ import org.springframework.test.context.junit4.SpringRunner;
 
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.util.Arrays;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Locale;
+import java.util.*;
 
 @RunWith(SpringRunner.class)
 @SpringBootTest
@@ -67,4 +64,11 @@ public class UserRepoTest {
         LocalDate start = end.minusDays(6);
         System.out.println(start);
     }
+
+    @Test
+    public void test1() {
+        List<Long> userIds = userRepo.findAllByCollectionId(3460186L, 2);
+        System.out.println(userIds.size());
+        userRepo.updateAllByInvitor(userIds);
+    }
 }

+ 21 - 0
src/test/java/com/izouma/nineth/service/StatisticServiceTest.java

@@ -6,6 +6,10 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.LocalTime;
+
 
 @SpringBootTest
 @RunWith(SpringRunner.class)
@@ -13,6 +17,8 @@ public class StatisticServiceTest {
 
     @Autowired
     private StatisticService statisticService;
+    @Autowired
+    private CacheService     cacheService;
 
     @Test
     public void total() {
@@ -33,4 +39,19 @@ public class StatisticServiceTest {
     public void orderPriceTrend() {
         System.out.println(statisticService.orderPriceTrend(7));
     }
+
+    @Test
+    public void top() {
+        LocalDate now = LocalDate.now();
+        LocalDate endDate = now.minusDays(now.getDayOfWeek().getValue());
+        LocalDateTime start = LocalDateTime.of(endDate.minusDays(6), LocalTime.MIN);
+        System.out.println(start);
+        String top = statisticService.top(start, LocalDateTime.of(endDate, LocalTime.MAX), 50);
+        System.out.println(top);
+    }
+
+    @Test
+    public void test() {
+        cacheService.clearWeekTop();
+    }
 }