xiongzhu 3 years ago
parent
commit
235d334ba7

+ 5 - 0
src/main/java/com/izouma/nineth/domain/Asset.java

@@ -229,6 +229,9 @@ public class Asset extends CollectionBaseEntity {
 
     private LocalDateTime lockTo;
 
+    @Column(columnDefinition = "bigint default 1 not null")
+    private Long companyId;
+
     public static Asset create(Collection collection, User user) {
         return Asset.builder()
                 .userId(user.getId())
@@ -258,6 +261,7 @@ public class Asset extends CollectionBaseEntity {
                 .tags(new HashSet<>(collection.getTags()))
                 .prefixName(collection.getPrefixName())
                 .empower(collection.getEmpower())
+                .companyId(collection.getCompanyId())
                 .build();
     }
 
@@ -288,6 +292,7 @@ public class Asset extends CollectionBaseEntity {
                 .oldHoldDays(holdDays)
                 .source(AssetSource.OFFICIAL)
                 .opened(false)
+                .companyId(item.getCompanyId())
                 .build();
     }
 }

+ 3 - 0
src/main/java/com/izouma/nineth/domain/BlindBoxItem.java

@@ -100,4 +100,7 @@ public class BlindBoxItem extends BaseEntity {
 
 //    @ApiModelProperty("持有几天")
 //    private Integer holdDays;
+
+    @Column(columnDefinition = "bigint default 1 not null")
+    private Long companyId;
 }

+ 6 - 0
src/main/java/com/izouma/nineth/domain/Collection.java

@@ -50,6 +50,7 @@ import java.util.Set;
         @Index(columnList = "onShelf,del,source"),
         @Index(columnList = "onShelf,del,source,salable"),
         @Index(columnList = "onShelf,del,source,salable,price"),
+        @Index(columnList = "prefixName"),
 })
 @DynamicUpdate
 @AllArgsConstructor
@@ -269,9 +270,14 @@ public class Collection extends CollectionBaseEntity {
     private BigInteger hcGasUsed;
     private String     hcTokenId;
 
+    @ApiModelProperty("系列名称")
+    @Column(length = 100)
     private String prefixName;
 
     @ApiModelProperty("赋能列表")
     @Column(columnDefinition = "TEXT")
     private String empower;
+
+    @Column(columnDefinition = "bigint default 1 not null")
+    private Long companyId;
 }

+ 27 - 0
src/main/java/com/izouma/nineth/domain/Company.java

@@ -0,0 +1,27 @@
+package com.izouma.nineth.domain;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+import javax.persistence.Entity;
+
+@Data
+@Entity
+@AllArgsConstructor
+@NoArgsConstructor
+@Builder
+public class Company extends BaseEntity {
+
+    private String name;
+
+    private String description;
+
+    private String logo;
+
+    private Long adminUserId;
+
+    private boolean disabled;
+
+}

+ 3 - 0
src/main/java/com/izouma/nineth/domain/Order.java

@@ -219,4 +219,7 @@ public class Order extends BaseEntityNoID {
 
     @ApiModelProperty("卖家id")
     private Long sellerId;
+
+    @Column(columnDefinition = "bigint default 1 not null")
+    private Long companyId;
 }

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

@@ -287,6 +287,7 @@ public class AssetService {
                 .number(asset.getNumber())
                 .tags(new HashSet<>())
                 .prefixName(asset.getPrefixName())
+                .companyId(asset.getCompanyId())
                 .build();
         if (asset.getTags() != null) {
             collection.getTags().addAll(asset.getTags());
@@ -399,6 +400,7 @@ public class AssetService {
                 .number(asset.getNumber())
                 .tags(new HashSet<>())
                 .prefixName(asset.getPrefixName())
+                .companyId(asset.getCompanyId())
                 .build();
         if (asset.getTags() != null) {
             collection.getTags().addAll(asset.getTags());
@@ -949,21 +951,6 @@ public class AssetService {
                 .build());
     }
 
-    @Async
-    public void giveBonus() {
-        List<TokenHistory> list = tokenHistoryRepo.findByOperationAndCreatedAtBefore("销毁", LocalDateTime.of(2022, 7, 23, 21, 0, 0));
-        list.parallelStream().forEach(tokenHistory -> {
-            String name = assetRepo.findFirstByTokenId(tokenHistory.getTokenId()).getName();
-            if (Pattern.matches(".*僵尸动物园SSR #.*", name)) {
-                log.info("SSR奖励 {}", name);
-                userBalanceService.modifyBalance(tokenHistory.getFromUserId(), new BigDecimal("1000"), BalanceType.BONUS, null, false, null);
-            } else if (Pattern.matches(".*僵尸动物园SR #.*", name)) {
-                log.info("SR奖励 {}", name);
-                userBalanceService.modifyBalance(tokenHistory.getFromUserId(), new BigDecimal("25"), BalanceType.BONUS, null, false, null);
-            }
-        });
-    }
-
     public List<MetaPlayerRole> metaPlayerRole(Long userId) {
         List<MetaPlayerRole> metaPlayerRoles = new ArrayList<>();
         metaPlayerRoles.add(build(userId, "艾弗森", 1L));

+ 23 - 18
src/main/java/com/izouma/nineth/service/CollectionService.java

@@ -46,6 +46,8 @@ import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
@@ -370,7 +372,7 @@ public class CollectionService {
     }
 
     @Transactional
-    public Collection createBlindBox(CreateBlindBox createBlindBox) {
+    public Collection createBlindBox(CreateBlindBox createBlindBox) throws Exception {
         Collection blindBox = createBlindBox.getBlindBox();
         if (blindBox.getId() != null) {
             throw new BusinessException("无法完成此操作");
@@ -398,23 +400,26 @@ public class CollectionService {
         blindBox.setStock(blindBox.getTotal());
         blindBox.setSale(0);
         collectionRepo.save(blindBox);
-        createBlindBox.getItems().stream().parallel().forEach(item -> {
-            Collection collection = list.stream().filter(i -> i.getId().equals(item.getCollectionId())).findAny()
-                    .orElseThrow(new BusinessException("所选藏品不存在"));
-            decreaseStock(collection.getId(), item.getTotal());
-            BlindBoxItem blindBoxItem = new BlindBoxItem();
-            BeanUtils.copyProperties(collection, blindBoxItem);
-            blindBoxItem.setId(null);
-            blindBoxItem.setOasisId(collection.getOasisId());
-            blindBoxItem.setCollectionId(item.getCollectionId());
-            blindBoxItem.setSale(0);
-            blindBoxItem.setTotal(item.getTotal());
-            blindBoxItem.setStock(item.getTotal());
-            blindBoxItem.setRare(item.isRare());
-            blindBoxItem.setBlindBoxId(blindBox.getId());
-            blindBoxItemRepo.saveAndFlush(blindBoxItem);
-            log.info("createBlindBoxItemSuccess" + blindBoxItem.getId());
-        });
+        new ForkJoinPool(128).submit(() -> {
+            createBlindBox.getItems().stream().parallel().forEach(item -> {
+                Collection collection = list.stream().filter(i -> i.getId().equals(item.getCollectionId()))
+                        .findFirst().get();
+                decreaseStock(collection.getId(), item.getTotal());
+                BlindBoxItem blindBoxItem = new BlindBoxItem();
+                BeanUtils.copyProperties(collection, blindBoxItem);
+                blindBoxItem.setId(null);
+                blindBoxItem.setOasisId(collection.getOasisId());
+                blindBoxItem.setCollectionId(item.getCollectionId());
+                blindBoxItem.setSale(0);
+                blindBoxItem.setTotal(item.getTotal());
+                blindBoxItem.setStock(item.getTotal());
+                blindBoxItem.setRare(item.isRare());
+                blindBoxItem.setBlindBoxId(blindBox.getId());
+                blindBoxItem.setCompanyId(collection.getCompanyId());
+                blindBoxItemRepo.saveAndFlush(blindBoxItem);
+                log.info("createBlindBoxItemSuccess" + blindBoxItem.getId());
+            });
+        }).get();
         return blindBox;
     }
 

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

@@ -376,6 +376,7 @@ public class OrderService {
                     .countId(collection.getCountId())
                     .vip(vip)
                     .vipPoint(usePoint)
+                    .companyId(collection.getCompanyId())
                     .build();
             if (coupon != null) {
                 coupon.setUsed(true);

+ 0 - 6
src/main/java/com/izouma/nineth/web/AssetController.java

@@ -231,12 +231,6 @@ public class AssetController extends BaseController {
         assetService.lockAsset(SecurityUtils.getAuthenticatedUser().getId(), assetId, duration);
     }
 
-    @PreAuthorize("hasRole('ADMIN')")
-    @GetMapping("/giveBonus")
-    public void giveBonus() {
-        assetService.giveBonus();
-    }
-
     @GetMapping("/{userId}/metaPlayerRole")
     public List<MetaPlayerRole> MetaPlayerRoles(@PathVariable Long userId) {
         return assetService.metaPlayerRole(userId);

+ 10 - 8
src/main/java/com/izouma/nineth/web/CollectionController.java

@@ -29,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
 import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
 import java.util.stream.Collectors;
 
 @RestController
@@ -77,6 +78,7 @@ public class CollectionController extends BaseController {
     @PostMapping("/all")
     @JsonView(Collection.View.Basic.class)
     public Page<Collection> all(@RequestBody PageQuery pageQuery) {
+        pageQuery.getQuery().putIfAbsent("companyId", 0);
         Page<Collection> page = collectionService.all(pageQuery).toPage();
         collectionService.queryUserDetail(page.getContent());
         return page;
@@ -128,7 +130,7 @@ public class CollectionController extends BaseController {
 
     @PreAuthorize("hasRole('ADMIN')")
     @PostMapping("/createBlindBox")
-    public Collection createBlindBox(@RequestBody CreateBlindBox createBlindBox) {
+    public Collection createBlindBox(@RequestBody CreateBlindBox createBlindBox) throws Exception {
         return collectionService.createBlindBox(createBlindBox);
     }
 
@@ -239,17 +241,17 @@ public class CollectionController extends BaseController {
         PageQuery pageQuery = new PageQuery();
         pageQuery.setPage(0);
         pageQuery.setSize(1);
-        pageQuery.getQuery().put("onShelf",true);
-        pageQuery.getQuery().put("source","TRANSFER");
-        pageQuery.getQuery().put("del",false);
+        pageQuery.getQuery().put("onShelf", true);
+        pageQuery.getQuery().put("source", "TRANSFER");
+        pageQuery.getQuery().put("del", false);
         pageQuery.setSearch(search);
-        pageQuery.getQuery().put("salable",false);
+        pageQuery.getQuery().put("salable", false);
         long onlyShowNum = collectionService.all(pageQuery).getTotal();
-        pageQuery.getQuery().put("salable",true);
+        pageQuery.getQuery().put("salable", true);
         long consignmentNum = collectionService.all(pageQuery).getTotal();
         pageQuery.getQuery().remove("salable");
-        pageQuery.getQuery().put("inPaying",true);
-        long  transactingNum= collectionService.all(pageQuery).getTotal();
+        pageQuery.getQuery().put("inPaying", true);
+        long transactingNum = collectionService.all(pageQuery).getTotal();
         Map<String, String> map = new HashMap<>();
         map.put("onlyShowNum", String.valueOf(onlyShowNum));
         map.put("consignmentNum", String.valueOf(consignmentNum));

+ 3 - 2
src/test/java/com/izouma/nineth/service/CollectionServiceTest.java

@@ -32,6 +32,7 @@ import java.nio.file.Files;
 import java.text.SimpleDateFormat;
 import java.time.LocalDateTime;
 import java.util.*;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -106,7 +107,7 @@ class CollectionServiceTest extends ApplicationTests {
     }
 
     @Test
-    public void createBlindBox() throws IOException {
+    public void createBlindBox() throws Exception {
 //        List<Long> arr = Arrays.asList(6862110L, 6862511L, 6862516L, 6862533L, 6862689L, 6862792L, 6862867L, 6863009L, 6863047L,
 //                6863188L, 6863438L, 6863449L, 6863588L, 6863608L, 6863671L, 6863745L, 6863760L, 6863938L, 6863954L, 6864008L, 6864081L);
         List<Collection> items = collectionRepo.findByNameLike("MUGEN无限:未央宗#%")
@@ -218,7 +219,7 @@ class CollectionServiceTest extends ApplicationTests {
     }
 
     @Test
-    public void createBlindBox1() throws IOException {
+    public void createBlindBox1() throws Exception {
 
         File file = new File("/Users/qiufangchao/Desktop/mingdan.xlsx");
         UploadDataListener<TestExcelDTO> listener = new UploadDataListener<>();