|
|
@@ -1,10 +1,11 @@
|
|
|
package com.izouma.nineth.service;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.izouma.nineth.ApplicationTests;
|
|
|
-import com.izouma.nineth.domain.*;
|
|
|
+import com.izouma.nineth.domain.BlindBoxItem;
|
|
|
import com.izouma.nineth.domain.Collection;
|
|
|
+import com.izouma.nineth.domain.FileObject;
|
|
|
import com.izouma.nineth.dto.CreateBlindBox;
|
|
|
-import com.izouma.nineth.enums.CollectionSource;
|
|
|
import com.izouma.nineth.enums.CollectionType;
|
|
|
import com.izouma.nineth.repo.CollectionRepo;
|
|
|
import com.izouma.nineth.repo.PrivilegeOptionRepo;
|
|
|
@@ -14,16 +15,13 @@ import org.apache.commons.io.FileUtils;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.IOException;
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.nio.file.Files;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.regex.Pattern;
|
|
|
@@ -52,90 +50,74 @@ class CollectionServiceTest extends ApplicationTests {
|
|
|
|
|
|
@Test
|
|
|
public void batchUpload() throws IOException {
|
|
|
- File imgDir = new File("/Users/drew/Downloads/images");
|
|
|
AtomicInteger num = new AtomicInteger(1);
|
|
|
- User minter = userRepo.findById(71579L).get();
|
|
|
- List<PrivilegeOption> privilegeOptions = privilegeOptionRepo.findAll();
|
|
|
- List<Collection> collections = new ArrayList<>();
|
|
|
List<BlindBoxItem> items = new ArrayList<>();
|
|
|
- Arrays.stream(imgDir.list((dir, name) -> Pattern.matches(".*\\.(png|jpg)", name))).parallel().forEach(file -> {
|
|
|
- try {
|
|
|
- File img = new File(imgDir, file);
|
|
|
- Collection collection = Collection.builder()
|
|
|
- .name(String.format("OASIS尼尔斯 #%03d", num.getAndIncrement()))
|
|
|
- .pic(Collections.singletonList(uploadFile(img)))
|
|
|
- .minter(minter.getNickname())
|
|
|
- .minterAvatar(minter.getAvatar())
|
|
|
- .minterId(minter.getId())
|
|
|
- .detail(FileUtils.readFileToString(new File("/Users/drew/Desktop/detail.txt"), "UTF-8"))
|
|
|
- .type(CollectionType.DEFAULT)
|
|
|
- .properties(new ArrayList<>())
|
|
|
- .privileges(privilegeOptions.stream().filter(p -> p.getName().equals("悄悄话")).map(p -> {
|
|
|
- Privilege p1 = new Privilege();
|
|
|
- BeanUtils.copyProperties(p, p1);
|
|
|
- p1.setDetail("绿洲元宇宙在现实世界入口位置是东经121.911305,北纬30.919856");
|
|
|
- return p1;
|
|
|
- }).collect(Collectors.toList()))
|
|
|
- .canResale(true)
|
|
|
- .royalties(10)
|
|
|
- .serviceCharge(5)
|
|
|
- .category("收藏品")
|
|
|
- .source(CollectionSource.OFFICIAL)
|
|
|
- .sale(0)
|
|
|
- .stock(1)
|
|
|
- .total(1)
|
|
|
- .likes(0)
|
|
|
- .onShelf(false)
|
|
|
- .salable(false)
|
|
|
- .price(new BigDecimal("59.9"))
|
|
|
- .originalPrice(new BigDecimal("59.9"))
|
|
|
- .build();
|
|
|
- collectionRepo.save(collection);
|
|
|
- collections.add(collection);
|
|
|
+ String jsonStr = FileUtils.readFileToString(new File("/Users/drew/Downloads/003.json"), "UTF-8");
|
|
|
+ Arrays.stream(new File("/Users/drew/Downloads/MAYBEMAN套装池2000张").listFiles())
|
|
|
+ .filter(f -> Pattern.matches("^BJ.*\\.png$", f.getName()))
|
|
|
+ .parallel().forEach(file -> {
|
|
|
+ try {
|
|
|
+ Collection collection = JSON.parseObject(jsonStr, Collection.class);
|
|
|
+ collection.setId(null);
|
|
|
+ collection.setName(String.format("MAYBEMAN #%05d", num.getAndIncrement()));
|
|
|
+ collection.setStock(1);
|
|
|
+ collection.setTotal(1);
|
|
|
+ collection.setSale(0);
|
|
|
+ collection.setMinterId(8666L);
|
|
|
+ collection.setOnShelf(false);
|
|
|
+ collection.setSalable(false);
|
|
|
+ collection.setPic(Collections.singletonList(new FileObject("", "https://raex-meta.oss-cn-shenzhen.aliyuncs.com/image/MAYBEMAN/" + file.getName(), null, "png")));
|
|
|
|
|
|
- items.add(BlindBoxItem
|
|
|
- .builder()
|
|
|
- .collectionId(collection.getId())
|
|
|
- .total(1)
|
|
|
- .stock(1)
|
|
|
- .rare(file.startsWith("qie_"))
|
|
|
- .build());
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- });
|
|
|
+ collectionRepo.save(collection);
|
|
|
|
|
|
- Collection blindBox = Collection.builder()
|
|
|
- .name("1M001:绿洲海洋尼尔斯限定盲盒")
|
|
|
- .pic(Collections.singletonList(uploadFile(new File("/Users/drew/Downloads/WechatIMG6.jpeg"))))
|
|
|
- .minter(minter.getNickname())
|
|
|
- .minterAvatar(minter.getAvatar())
|
|
|
- .minterId(minter.getId())
|
|
|
- .detail(FileUtils.readFileToString(new File("/Users/drew/Desktop/detail.txt"), "UTF-8"))
|
|
|
- .type(CollectionType.BLIND_BOX)
|
|
|
- .properties(new ArrayList<>())
|
|
|
- .privileges(privilegeOptions.stream().filter(p -> p.getName().equals("悄悄话")).map(p -> {
|
|
|
- Privilege p1 = new Privilege();
|
|
|
- BeanUtils.copyProperties(p, p1);
|
|
|
- p1.setDetail("绿洲元宇宙在现实世界入口位置是东经121.911305,北纬30.919856");
|
|
|
- return p1;
|
|
|
- }).collect(Collectors.toList()))
|
|
|
- .canResale(true)
|
|
|
- .royalties(10)
|
|
|
- .serviceCharge(5)
|
|
|
- .category("收藏品")
|
|
|
- .source(CollectionSource.OFFICIAL)
|
|
|
- .sale(0)
|
|
|
- .stock(1)
|
|
|
- .total(1)
|
|
|
- .likes(0)
|
|
|
- .onShelf(true)
|
|
|
- .salable(false)
|
|
|
- .price(new BigDecimal("59.9"))
|
|
|
- .originalPrice(new BigDecimal("59.9"))
|
|
|
- .scheduleSale(true)
|
|
|
- .startTime(LocalDateTime.of(2021, 12, 24, 15, 0, 0))
|
|
|
- .build();
|
|
|
- collectionService.createBlindBox(new CreateBlindBox(blindBox, items));
|
|
|
+ items.add(BlindBoxItem
|
|
|
+ .builder()
|
|
|
+ .collectionId(collection.getId())
|
|
|
+ .total(1)
|
|
|
+ .stock(1)
|
|
|
+ .rare(false)
|
|
|
+ .build());
|
|
|
+ } catch (Exception e) {
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void createBlindBox() throws IOException {
|
|
|
+ List<Collection> items = collectionRepo.findByNameLike("MAYBEMAN #%");
|
|
|
+
|
|
|
+ String jsonStr = FileUtils.readFileToString(new File("/Users/drew/Downloads/003.json"), "UTF-8");
|
|
|
+ Collection blindBox = JSON.parseObject(jsonStr, Collection.class);
|
|
|
+ blindBox.setType(CollectionType.BLIND_BOX);
|
|
|
+ blindBox.setId(null);
|
|
|
+ blindBox.setOnShelf(false);
|
|
|
+ blindBox.setSalable(false);
|
|
|
+ blindBox.setMinterId(8666L);
|
|
|
+ blindBox.setName("MAYBEMAN潮流艺术限定盲盒S1");
|
|
|
+ blindBox.setPic(Arrays.asList(new FileObject(null, "https://raex-meta.oss-cn-shenzhen.aliyuncs.com/nft/2022-01-07-10-08-30DpIYYBOv.jpg", null, null)));
|
|
|
+ collectionService.createBlindBox(new CreateBlindBox(blindBox, items.subList(0, 1000).stream().map(i -> {
|
|
|
+ BlindBoxItem item = new BlindBoxItem();
|
|
|
+ item.setCollectionId(i.getId());
|
|
|
+ item.setTotal(1);
|
|
|
+ return item;
|
|
|
+ }).collect(Collectors.toList())));
|
|
|
+
|
|
|
+ Collection blindBox1 = JSON.parseObject(jsonStr, Collection.class);
|
|
|
+ blindBox1.setType(CollectionType.BLIND_BOX);
|
|
|
+ blindBox1.setId(null);
|
|
|
+ blindBox1.setOnShelf(false);
|
|
|
+ blindBox1.setSalable(false);
|
|
|
+ blindBox1.setMinterId(8666L);
|
|
|
+ blindBox1.setName("MAYBEMAN潮流艺术限定盲盒S2");
|
|
|
+ blindBox1.setPic(Arrays.asList(new FileObject(null, "https://raex-meta.oss-cn-shenzhen.aliyuncs.com/nft/2022-01-07-10-08-30DpIYYBOv.jpg", null, null)));
|
|
|
+ collectionService.createBlindBox(new CreateBlindBox(blindBox1, items.subList(1000, 2000).stream().map(i -> {
|
|
|
+ BlindBoxItem item = new BlindBoxItem();
|
|
|
+ item.setCollectionId(i.getId());
|
|
|
+ item.setTotal(1);
|
|
|
+ return item;
|
|
|
+ }).collect(Collectors.toList())));
|
|
|
}
|
|
|
|
|
|
public FileObject uploadFile(File file) throws IOException {
|