Bladeren bron

定时任务

wangqifan 3 jaren geleden
bovenliggende
commit
8aa8dcae21

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

@@ -4,6 +4,7 @@ import com.izouma.nineth.domain.Collection;
 import com.izouma.nineth.dto.CollectionInfoDTO;
 import com.izouma.nineth.dto.CollectionStockAndSale;
 import com.izouma.nineth.dto.RecommendCollection;
+import com.izouma.nineth.enums.CollectionSource;
 import org.springframework.cache.annotation.CacheEvict;
 import org.springframework.cache.annotation.CachePut;
 import org.springframework.cache.annotation.Cacheable;
@@ -18,6 +19,7 @@ import java.math.BigDecimal;
 import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Optional;
+import java.util.Set;
 
 public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpecificationExecutor<Collection> {
     @Query("update Collection t set t.del = true where t.id = ?1")
@@ -148,4 +150,7 @@ public interface CollectionRepo extends JpaRepository<Collection, Long>, JpaSpec
     @Query("select c.vipQuota from Collection c where c.id = ?1")
     Integer getVipQuota(Long id);
 
+    @Query("select c.assetId from Collection  c where c.price >= ?1 and c.source = ?2 and c.startTime <= ?3 and c.salable = ?4")
+    Set<Long> findResaleCollectionPriceOver20K(BigDecimal price, CollectionSource source, LocalDateTime startTime, boolean salable);
+
 }

+ 13 - 0
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -28,6 +28,7 @@ import org.springframework.context.ApplicationContext;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.Pageable;
 import org.springframework.scheduling.annotation.Async;
+import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 
 import javax.persistence.criteria.Predicate;
@@ -527,4 +528,16 @@ public class AssetService {
         return url.replaceAll("https://raex-meta\\.oss-cn-shenzhen\\.aliyuncs\\.com",
                 "https://cdn.raex.vip");
     }
+
+
+    //    @Scheduled(cron = "0 0 0/2 * * ?")
+    @Scheduled(cron = "0 */1 * * * ?")
+    public void offTheShelf() {
+        LocalDateTime lastTime = LocalDateTime.now().minusHours(1);
+        Set<Long> assetIds = collectionRepo
+                .findResaleCollectionPriceOver20K(BigDecimal
+                        .valueOf(20000L), CollectionSource.TRANSFER, lastTime, true);
+        assetIds.forEach(this::cancelConsignment);
+    }
+
 }