Explorar o código

Merge branch 'dev'

xiongzhu %!s(int64=4) %!d(string=hai) anos
pai
achega
500868b952

+ 19 - 0
src/main/java/com/izouma/nineth/config/SchedulingConfig.java

@@ -0,0 +1,19 @@
+package com.izouma.nineth.config;
+
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.TaskScheduler;
+import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
+
+@Configuration
+public class SchedulingConfig {
+    @Bean
+    public TaskScheduler taskScheduler() {
+        ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
+        // 定时任务执行线程池核心线程数
+        taskScheduler.setPoolSize(50);
+        taskScheduler.setRemoveOnCancelPolicy(true);
+        taskScheduler.setThreadNamePrefix("Scheduler-");
+        return taskScheduler;
+    }
+}

+ 8 - 0
src/main/java/com/izouma/nineth/repo/CollectionRepo.java

@@ -78,6 +78,14 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @CacheEvict(value = "collection", key = "#id")
     void setOnShelf(Long id, boolean onShelf);
 
+    @Transactional
+    @Modifying
+    @Query("update Collection c set c.onShelf = ?2, c.salable = ?2 where c.id = ?1")
+    @CacheEvict(value = "collection", key = "#id")
+    void scheduleOnShelf(Long id, boolean onShelf);
+
     @Query("select c.currentNumber from Collection c where c.id = ?1")
     Optional<Integer> getCurrentNumber(Long id);
+
+    List<Collection> findByScheduleSaleTrue();
 }

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

@@ -24,9 +24,11 @@ import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.jpa.domain.Specification;
 import org.springframework.data.redis.core.RedisTemplate;
+import org.springframework.scheduling.TaskScheduler;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
+import javax.annotation.PostConstruct;
 import javax.persistence.criteria.Predicate;
 import javax.transaction.Transactional;
 import java.time.LocalDateTime;
@@ -44,6 +46,11 @@ public class CollectionService {
     private UserRepo                      userRepo;
     private AssetService                  assetService;
     private RedisTemplate<String, Object> redisTemplate;
+    private TaskScheduler                 taskScheduler;
+
+    @PostConstruct
+    public void init() {
+    }
 
     @CacheEvict(value = "collection", allEntries = true)
     public void clearCache() {
@@ -209,11 +216,11 @@ public class CollectionService {
                 .build());
     }
 
-    @Scheduled(fixedRate = 60000)
+    @Scheduled(fixedRate = 10000)
     public void scheduleOnShelf() {
         List<Collection> collections = collectionRepo.findByScheduleSaleTrueAndOnShelfFalseAndStartTimeBeforeAndDelFalse(LocalDateTime.now());
         for (Collection collection : collections) {
-            collectionRepo.setOnShelf(collection.getId(), true);
+            collectionRepo.scheduleOnShelf(collection.getId(), true);
         }
     }
 

+ 2 - 2
src/test/java/com/izouma/nineth/service/CollectionServiceTest.java

@@ -54,7 +54,7 @@ class CollectionServiceTest extends ApplicationTests {
     public void batchUpload() throws IOException {
         File imgDir = new File("/Users/drew/Downloads/images");
         AtomicInteger num = new AtomicInteger(1);
-        User minter = userRepo.findById(53099L).get();
+        User minter = userRepo.findById(71579L).get();
         List<PrivilegeOption> privilegeOptions = privilegeOptionRepo.findAll();
         List<Collection> collections = new ArrayList<>();
         List<BlindBoxItem> items = new ArrayList<>();
@@ -133,7 +133,7 @@ class CollectionServiceTest extends ApplicationTests {
                 .price(new BigDecimal("59.9"))
                 .originalPrice(new BigDecimal("59.9"))
                 .scheduleSale(true)
-                .startTime(LocalDateTime.of(2021, 12, 23, 20, 0, 0))
+                .startTime(LocalDateTime.of(2021, 12, 24, 15, 0, 0))
                 .build();
         collectionService.createBlindBox(new CreateBlindBox(blindBox, items));
     }

+ 6 - 0
src/test/java/com/izouma/nineth/service/OrderServiceTest.java

@@ -11,6 +11,7 @@ import com.izouma.nineth.dto.UserBankCard;
 import com.izouma.nineth.enums.AssetStatus;
 import com.izouma.nineth.enums.AuthStatus;
 import com.izouma.nineth.enums.OrderStatus;
+import com.izouma.nineth.enums.PayMethod;
 import com.izouma.nineth.exception.BusinessException;
 import com.izouma.nineth.repo.*;
 import com.izouma.nineth.utils.FileUtils;
@@ -224,4 +225,9 @@ public class OrderServiceTest extends ApplicationTests {
         });
 
     }
+
+    @Test
+    public void notifyOrder() {
+        orderService.notifyOrder(923604613259591680L, PayMethod.ALIPAY, "11111");
+    }
 }