licailing пре 4 година
родитељ
комит
289df86515

+ 4 - 1
src/main/java/com/izouma/nineth/repo/AssetRepo.java

@@ -55,7 +55,10 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
 
     Asset findFirstByTxHashIsNullAndTokenIdNotNullAndStatusOrderByCreatedAt(AssetStatus status);
 
-    List<Asset> findByTxHashIsNullAndTokenIdNotNullAndCreatedAtBefore(LocalDateTime time);
+    @Query("select a from Asset a where a.txHash is null and a.tokenId is not null " +
+            "and a.status = com.izouma.nineth.enums.AssetStatus.NORMAL and a.createdAt < ?1 " +
+            "order by a.createdAt desc")
+    List<Asset> toMint(LocalDateTime time);
 
     List<Asset> findAllByIdInAndUserId(Collection<Long> id, Long userId);
 

+ 5 - 2
src/main/java/com/izouma/nineth/service/AssetService.java

@@ -441,8 +441,11 @@ public class AssetService {
         });
     }
 
-    public String mint() {
-        for (Asset asset : assetRepo.findByTxHashIsNullAndTokenIdNotNullAndCreatedAtBefore(LocalDateTime.now())) {
+    public String mint(LocalDateTime time) {
+        if (time == null) {
+            time = LocalDateTime.now();
+        }
+        for (Asset asset : assetRepo.toMint(time)) {
             rocketMQTemplate.syncSend(generalProperties.getMintTopic(), asset.getId());
         }
         return "ok";

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

@@ -192,8 +192,8 @@ public class UserService {
 
         // 加积分
         if (collectionId != null && invitor != null) {
-            // 额度或者额度为空
-            if (collection.getVipQuota() > 0 || ObjectUtils.isEmpty(collection.getVipQuota())) {
+            // 额度或者额度为空, 库存不为空
+            if (collection.getStock() > 0 && (collection.getVipQuota() > 0 || ObjectUtils.isEmpty(collection.getVipQuota()))) {
                 int countUser = userRepo.countAllByCollectionIdAndCollectionInvitor(collectionId, invitor);
                 // 邀请人数
                 if (countUser >= collection.getAssignment()) {
@@ -210,7 +210,7 @@ public class UserService {
                                     .point(1)
                                     .build());
                             // 扣除藏品额度
-                            if(ObjectUtils.isNotEmpty(collection.getVipQuota())){
+                            if (ObjectUtils.isNotEmpty(collection.getVipQuota())) {
                                 collectionService.decreaseQuota(collectionId, 1);
                             }
                         }

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

@@ -22,6 +22,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.time.LocalDateTime;
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutionException;
@@ -121,8 +122,8 @@ public class AssetController extends BaseController {
     }
 
     @GetMapping("/mint")
-    public String mint() {
-        return assetService.mint();
+    public String mint(@RequestParam(required = false) LocalDateTime time) {
+        return assetService.mint(time);
     }
 
     @GetMapping("/breakdown")