Selaa lähdekoodia

折叠companyId

sunkean 3 vuotta sitten
vanhempi
commit
8bdf421f5f

+ 1 - 4
src/main/java/com/izouma/nineth/aspect/AssetSaveAspect.java

@@ -2,18 +2,15 @@ package com.izouma.nineth.aspect;
 
 import com.izouma.nineth.domain.Asset;
 import com.izouma.nineth.service.UserAssetSummaryService;
-import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.aspectj.lang.JoinPoint;
 import org.aspectj.lang.annotation.After;
 import org.aspectj.lang.annotation.Aspect;
-import org.springframework.scheduling.TaskScheduler;
 import org.springframework.stereotype.Component;
 
 import java.util.HashMap;
 import java.util.Map;
 import java.util.Optional;
-import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
@@ -46,7 +43,7 @@ public class AssetSaveAspect {
                             f.cancel(false);
                         });
                 futureMap.put(asset.getUserId(), executorService.schedule(() -> {
-                    userAssetSummaryService.calculateNum(asset.getUserId());
+                    userAssetSummaryService.calculateNum(asset.getUserId(), asset.getCompanyId());
                 }, 500, TimeUnit.MILLISECONDS));
             }
         } catch (Exception e) {

+ 4 - 0
src/main/java/com/izouma/nineth/domain/UserAssetSummary.java

@@ -99,7 +99,11 @@ public class UserAssetSummary {
     @ApiModelProperty("最新创建时间")
     private LocalDateTime createdAt;
 
+    @ApiModelProperty("companyId")
+    private Long companyId;
+
     public UserAssetSummary(Asset asset) {
+        this.companyId = asset.getCompanyId();
         this.assetId = asset.getId();
         this.userId = asset.getUserId();
         this.minter = asset.getMinter();

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

@@ -102,7 +102,7 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
 
     List<Asset> findByStatus(AssetStatus status);
 
-    List<Asset> findAllByUserIdAndTypeAndOpened(Long userId, CollectionType type, Boolean opened);
+    List<Asset> findAllByUserIdAndTypeAndOpenedAndCompanyId(Long userId, CollectionType type, Boolean opened, Long companyId);
 
     @Query(nativeQuery = true, value = "SELECT asset.user_id userId,user.nickname nickname,user.username username,user.avatar avatar,asset.name,asset.prefix_name prefixName,count(*) num FROM asset left join user on asset.user_id = user.id where asset.user_id not in (1435297,4273750, 56302) and asset.status in ('NORMAL','TRADING','GIFTING','MINTING','AUCTIONING') GROUP BY asset.user_id ORDER BY count(*) DESC limit ?1,?2")
     List<Map<String, String>> findByPage(int start, int end);

+ 16 - 1
src/main/java/com/izouma/nineth/repo/UserAssetSummaryRepo.java

@@ -31,6 +31,7 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "  a.name, " +
             "  a.public_show, " +
             "  a.consignment, " +
+            "  a.company_id, " +
             "  IF(b.auctioning_num IS NULL, 0, b.auctioning_num) auctioning_num,  " +
             "  IF(c.consignment_num IS NULL, 0, c.consignment_num) consignment_num,  " +
             "  IF(d.open_show_num IS NULL, 0, d.open_show_num) open_show_num,  " +
@@ -52,11 +53,13 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "    public_show, " +
             "    consignment, " +
             "    count(*) num,  " +
+            "    company_id,  " +
             "    max(created_at) created_at  " +
             "  FROM " +
             "    asset  " +
             "  WHERE " +
             "    user_id = ?1  " +
+            "    AND company_id = ?2" +
             "    AND STATUS IN ( 'NORMAL', 'TRADING', 'GIFTING', 'MINTING', 'AUCTIONING' )  " +
             "    AND type IN ( 'BLIND_BOX', 'DEFAULT' )  " +
             "    AND id NOT IN ( SELECT id FROM asset WHERE type = 'BLIND_BOX' AND opened = 0 )  " +
@@ -67,11 +70,13 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "  SELECT " +
             "    user_id userId, " +
             "    prefix_name prefixName, " +
+            "    company_id, " +
             "    count(*) auctioning_num  " +
             "  FROM " +
             "    asset  " +
             "  WHERE " +
             "    user_id = ?1  " +
+            "    AND company_id = ?2" +
             "    AND STATUS IN ( 'AUCTIONING' )  " +
             "    AND type IN ( 'BLIND_BOX', 'DEFAULT' )  " +
             "    AND id NOT IN ( SELECT id FROM asset WHERE type = 'BLIND_BOX' AND opened = 0 )  " +
@@ -79,15 +84,18 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "    prefix_name  " +
             "  ) b ON a.user_id = b.userId  " +
             "  AND a.prefix_name = b.prefixName " +
+            "  AND a.cpmpany_id = b.cpmpany_id " +
             "  LEFT JOIN ( " +
             "  SELECT " +
             "    user_id userId, " +
             "    prefix_name prefixName, " +
+            "    company_id, " +
             "    count(*) consignment_num  " +
             "  FROM " +
             "    asset  " +
             "  WHERE " +
             "    user_id = ?1  " +
+            "    AND company_id = ?2" +
             "    AND STATUS IN ( 'NORMAL', 'TRADING', 'GIFTING', 'MINTING', 'AUCTIONING' )  " +
             "    AND type IN ( 'BLIND_BOX', 'DEFAULT' )  " +
             "    AND consignment = 1  " +
@@ -96,15 +104,18 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "    prefix_name  " +
             "  ) c ON a.user_id = c.userId  " +
             "  AND a.prefix_name = c.prefixName " +
+            "  AND a.company_id = c.company_id " +
             "  LEFT JOIN ( " +
             "  SELECT " +
             "    user_id userId, " +
             "    prefix_name prefixName, " +
+            "    company_id, " +
             "    count(*) open_show_num  " +
             "  FROM " +
             "    asset  " +
             "  WHERE " +
             "    user_id = ?1  " +
+            "    AND company_id = ?2" +
             "    AND STATUS IN ( 'NORMAL', 'TRADING', 'GIFTING', 'MINTING', 'AUCTIONING' )  " +
             "    AND type IN ( 'BLIND_BOX', 'DEFAULT' )  " +
             "    AND consignment = 0  " +
@@ -113,16 +124,19 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "  GROUP BY " +
             "    prefix_name  " +
             "  ) d ON a.user_id = d.userId  " +
+            "  AND a.company_id = d.company_id " +
             "  AND a.prefix_name = d.prefixName " +
             "  LEFT JOIN ( " +
             "  SELECT " +
             "    user_id userId, " +
             "    prefix_name prefixName, " +
+            "    company_id, " +
             "    count(*) close_show_num  " +
             "  FROM " +
             "    asset  " +
             "  WHERE " +
             "    user_id = ?1  " +
+            "    AND company_id = ?2" +
             "    AND STATUS IN ( 'NORMAL', 'TRADING', 'GIFTING', 'MINTING', 'AUCTIONING' )  " +
             "    AND type IN ( 'BLIND_BOX', 'DEFAULT' )  " +
             "    AND consignment = 0  " +
@@ -131,6 +145,7 @@ public interface UserAssetSummaryRepo extends JpaRepository<UserAssetSummary, Lo
             "  GROUP BY " +
             "    prefix_name  " +
             "  ) e ON a.user_id = e.userId  " +
+            "  AND a.company_id = e.company_id " +
             "  AND a.prefix_name = e.prefixName", nativeQuery = true)
-    List<UserAssetSummary> find(Long userId);
+    List<UserAssetSummary> find(Long userId, Long companyId);
 }

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

@@ -245,9 +245,9 @@ public class AssetService {
 
     public void publicShow(Long id) {
         Asset asset = assetRepo.findById(id).orElseThrow(new BusinessException("无记录"));
-        if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
-            throw new BusinessException("此藏品不属于你");
-        }
+//        if (!asset.getUserId().equals(SecurityUtils.getAuthenticatedUser().getId())) {
+//            throw new BusinessException("此藏品不属于你");
+//        }
         if (asset.getLockTo() != null && asset.getLockTo().isAfter(LocalDateTime.now())) {
             throw new BusinessException("已锁仓,不能上架展示");
         }

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

@@ -30,16 +30,16 @@ public class UserAssetSummaryService {
         return userAssetSummaryRepo.findAll(JpaUtils.toSpecification(pageQuery, UserAssetSummary.class), JpaUtils.toPageRequest(pageQuery));
     }
 
-    public void calculateNum(Long userId) {
+    public void calculateNum(Long userId, Long companyId) {
         log.info("开始重新计算用户:{}的资产数量", userId);
         List<UserAssetSummary> userAssetSummaries = new ArrayList<>();
         // 查询盲盒数量
-        List<Asset> blindBoxAssets = assetRepo.findAllByUserIdAndTypeAndOpened(userId, CollectionType.BLIND_BOX, Boolean.FALSE);
+        List<Asset> blindBoxAssets = assetRepo.findAllByUserIdAndTypeAndOpenedAndCompanyId(userId, CollectionType.BLIND_BOX, Boolean.FALSE, companyId);
         blindBoxAssets.forEach(asset -> {
             userAssetSummaries.add(new UserAssetSummary(asset));
         });
         // 查询非盲盒数量
-        List<UserAssetSummary> notBlindBoxAssets = userAssetSummaryRepo.find(userId);
+        List<UserAssetSummary> notBlindBoxAssets = userAssetSummaryRepo.find(userId, companyId);
         notBlindBoxAssets.forEach(userAssetSummary -> {
             UserAssetSummary newUserAssetSummary = new UserAssetSummary();
             BeanUtils.copyProperties(userAssetSummary, newUserAssetSummary);

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

@@ -2,7 +2,6 @@ package com.izouma.nineth.service;
 
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.annotation.ExcelProperty;
-import com.alibaba.fastjson.JSONObject;
 import com.izouma.nineth.ApplicationTests;
 import com.izouma.nineth.TokenHistory;
 import com.izouma.nineth.domain.*;
@@ -292,6 +291,7 @@ class AssetServiceTest extends ApplicationTests {
 
     @Test
     public void aspect() {
+//        assetService.publicShow(8109261L);
         assetRepo.save(assetRepo.findById(8033654L).get());
     }
 }