xiongzhu пре 3 година
родитељ
комит
b30f687fa1

+ 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 - 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")