xiongzhu 4 lat temu
rodzic
commit
cdc3f87cb4

+ 2 - 0
src/main/java/com/izouma/nineth/Application.java

@@ -4,6 +4,7 @@ import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.cache.annotation.EnableCaching;
 import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
+import org.springframework.retry.annotation.EnableRetry;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import springfox.documentation.swagger2.annotations.EnableSwagger2;
@@ -14,6 +15,7 @@ import springfox.documentation.swagger2.annotations.EnableSwagger2;
 @EnableCaching
 @EnableScheduling
 @EnableAsync
+@EnableRetry
 public class Application {
 
     public static void main(String[] args) {

+ 2 - 0
src/main/java/com/izouma/nineth/dto/UserRegister.java

@@ -34,4 +34,6 @@ public class UserRegister {
     private String phone;
 
     private String email;
+
+    private boolean admin;
 }

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

@@ -10,9 +10,7 @@ import com.izouma.nineth.enums.CollectionSource;
 import com.izouma.nineth.enums.CollectionType;
 import com.izouma.nineth.event.CreateAssetEvent;
 import com.izouma.nineth.exception.BusinessException;
-import com.izouma.nineth.repo.AssetRepo;
-import com.izouma.nineth.repo.CollectionRepo;
-import com.izouma.nineth.repo.UserRepo;
+import com.izouma.nineth.repo.*;
 import com.izouma.nineth.utils.JpaUtils;
 import io.ipfs.api.IPFS;
 import io.ipfs.api.MerkleNode;
@@ -23,6 +21,8 @@ import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.context.ApplicationContext;
 import org.springframework.data.domain.Page;
+import org.springframework.retry.annotation.Backoff;
+import org.springframework.retry.annotation.Retryable;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 

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

@@ -19,6 +19,8 @@ import com.izouma.nineth.utils.HashUtils;
 import com.izouma.nineth.utils.SnowflakeIdWorker;
 import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.retry.annotation.Backoff;
+import org.springframework.retry.annotation.Retryable;
 import org.springframework.stereotype.Service;
 
 import java.math.BigInteger;
@@ -56,6 +58,7 @@ public class NFTService {
         }
     }
 
+    @Retryable(maxAttempts = 10, backoff = @Backoff(delay = 5000), value = BusinessException.class)
     public NFT createToken(String toAccount) throws Exception {
         JSONArray jsonArray = new JSONArray();
         jsonArray.add(Utils.getIdentityByName(toAccount));

+ 5 - 0
src/main/java/com/izouma/nineth/service/OrderService.java

@@ -299,6 +299,11 @@ public class OrderService {
         }
     }
 
+    public void createAsset(Long orderId, Long itemId) {
+        assetService.createAsset(orderRepo.findById(orderId).orElseThrow(new BusinessException("订单不存在")),
+                blindBoxItemRepo.findById(itemId).orElseThrow(new BusinessException("item不存在")));
+    }
+
     @EventListener
     public void onCreateAsset(CreateAssetEvent event) {
         Order order = event.getOrder();

+ 3 - 4
src/main/java/com/izouma/nineth/web/FileUploadController.java

@@ -196,15 +196,14 @@ public class FileUploadController {
                 bi = aa.convert(f);
                 File thumbFile = null;
                 while (bi != null) {
-                    thumbFile = File.createTempFile("video_thumb_", ".png");
-                    PngQuant pngQuant = new PngQuant();
-                    ImageIO.write(pngQuant.getRemapped(bi), "png", thumbFile);
+                    thumbFile = File.createTempFile("video_thumb_", ".jpg");
+                    ImageIO.write(bi, "jpg", thumbFile);
                     f = frameGrabber.grabKeyFrame();
                     bi = aa.convert(f);
                 }
                 Objects.requireNonNull(thumbFile);
                 String thumbPath = "thumb_image/" + new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(new Date())
-                        + RandomStringUtils.randomAlphabetic(8) + ".png";
+                        + RandomStringUtils.randomAlphabetic(8) + ".jpg";
                 thumbUrl = storageService.uploadFromInputStream(new FileInputStream(thumbFile), thumbPath);
             } catch (Exception e) {
                 e.printStackTrace();

+ 4 - 0
src/main/java/com/izouma/nineth/web/OrderController.java

@@ -77,5 +77,9 @@ public class OrderController extends BaseController {
         return orderService.create(SecurityUtils.getAuthenticatedUser().getId(), collectionId, qty, addressId);
     }
 
+    @GetMapping("/createAsset")
+    public void createAsset(@RequestParam Long orderId, @RequestParam Long itemId) {
+        orderService.createAsset(orderId, itemId);
+    }
 }
 

+ 27 - 0
src/test/java/com/izouma/nineth/service/AssetServiceTest.java

@@ -0,0 +1,27 @@
+package com.izouma.nineth.service;
+
+import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.domain.BlindBoxItem;
+import com.izouma.nineth.domain.Order;
+import com.izouma.nineth.repo.BlindBoxItemRepo;
+import com.izouma.nineth.repo.OrderRepo;
+import org.junit.jupiter.api.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import static org.junit.jupiter.api.Assertions.*;
+
+class AssetServiceTest extends ApplicationTests {
+    @Autowired
+    private OrderRepo        orderRepo;
+    @Autowired
+    private BlindBoxItemRepo blindBoxItemRepo;
+    @Autowired
+    private AssetService     assetService;
+
+    @Test
+    void createAsset() {
+        BlindBoxItem item = blindBoxItemRepo.findById(1860L).get();
+        Order order = orderRepo.findById(1922L).get();
+        assetService.createAsset(order, item);
+    }
+}