Ver Fonte

资产记录区分平台

licailing há 4 anos atrás
pai
commit
b235348956

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

@@ -35,4 +35,6 @@ public class TokenHistory extends BaseEntity {
     private Long   toUserId;
 
     private String toAvatar;
+
+    private int projectId;
 }

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

@@ -30,8 +30,6 @@ public interface AssetRepo extends JpaRepository<Asset, Long>, JpaSpecificationE
 
     List<Asset> findByTokenIdIn(Iterable<String> tokenId);
 
-    List<Asset> findByTokenIdInAndProjectId(Iterable<String> tokenId, int projectId);
-
     List<Asset> findByTokenIdOrderByCreatedAt(String tokenId);
 
     List<Asset> findByOrderId(Long orderId);

+ 4 - 0
src/main/java/com/izouma/nineth/repo/TokenHistoryRepo.java

@@ -17,6 +17,10 @@ public interface TokenHistoryRepo extends JpaRepository<TokenHistory, Long>, Jpa
     @Query("select t from TokenHistory t where t.toUserId = ?1 or t.fromUserId = ?1 order by t.createdAt desc")
     Page<TokenHistory> userHistory(Long userId, Pageable pageable);
 
+    @Query("select t from TokenHistory t where t.projectId = ?2 and (t.toUserId = ?1 or t.fromUserId = ?1) order by t.createdAt desc")
+    Page<TokenHistory> userHistoryAndProjectId(Long userId, int projectId, Pageable pageable);
+
+
     @Transactional
     @Modifying
     int deleteByTokenId(String tokenId);

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

@@ -68,6 +68,7 @@ public class AssetService {
                 .toAvatar(user.getAvatar())
                 .operation(type)
                 .price(price)
+                .projectId(asset.getProjectId())
                 .build());
         assetMintService.mint(asset);
         return asset;
@@ -91,6 +92,7 @@ public class AssetService {
                 .toAvatar(user.getAvatar())
                 .operation(type)
                 .price(price)
+                .projectId(asset.getProjectId())
                 .build());
         assetMintService.mint(asset.getId(), user.getId());
         return asset;
@@ -290,6 +292,7 @@ public class AssetService {
                 .toAvatar(toUser.getAvatar())
                 .operation(reason)
                 .price("转赠".equals(reason) ? null : price)
+                .projectId(asset.getProjectId())
                 .build());
 
         asset.setPublicShow(false);
@@ -337,6 +340,7 @@ public class AssetService {
                         .toAvatar(owner.getAvatar())
                         .operation("出售")
                         .price(order.getPrice())
+                        .projectId(asset.getProjectId())
                         .build();
                 t.setCreatedAt(asset.getCreatedAt());
                 tokenHistoryRepo.save(t);
@@ -345,10 +349,10 @@ public class AssetService {
         });
     }
 
-    public Page<UserHistory> userHistory(Long userId, Pageable pageable, int projectId) {
-        Page<TokenHistory> page = tokenHistoryRepo.userHistory(userId, pageable);
+    public Page<UserHistory> userHistory(Long userId, int projectId, Pageable pageable) {
+        Page<TokenHistory> page = tokenHistoryRepo.userHistoryAndProjectId(userId, projectId, pageable);
         Set<String> tokenIds = page.stream().map(TokenHistory::getTokenId).collect(Collectors.toSet());
-        List<Asset> assets = tokenIds.isEmpty() ? new ArrayList<>() : assetRepo.findByTokenIdInAndProjectId(tokenIds, projectId);
+        List<Asset> assets = tokenIds.isEmpty() ? new ArrayList<>() : assetRepo.findByTokenIdIn(tokenIds);
         return page.map(tokenHistory -> {
             UserHistory userHistory = new UserHistory();
             BeanUtils.copyProperties(tokenHistory, userHistory);

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

@@ -115,8 +115,8 @@ public class AssetController extends BaseController {
 
     @GetMapping("/userHistory")
     @ApiOperation("交易历史")
-    public Page<UserHistory> userHistory(Pageable pageable, int projectId) {
-        return assetService.userHistory(SecurityUtils.getAuthenticatedUser().getId(), pageable, projectId);
+    public Page<UserHistory> userHistory(int projectId, Pageable pageable) {
+        return assetService.userHistory(SecurityUtils.getAuthenticatedUser().getId(), projectId, pageable);
     }
 
     @PostMapping("/holdQuery")

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

@@ -5,6 +5,7 @@ import com.izouma.nineth.domain.*;
 import com.izouma.nineth.repo.*;
 import org.junit.jupiter.api.Test;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Pageable;
 
 import java.time.LocalDateTime;
 import java.util.Arrays;
@@ -77,7 +78,7 @@ class AssetServiceTest extends ApplicationTests {
     @Test
     public void stat() {
         Map<User, Integer> match = assetService.holdQuery(Arrays.asList(
-                       "【熊猫柯斯】-虎虎生威"),
+                        "【熊猫柯斯】-虎虎生威"),
                 LocalDateTime.of(2021, 12, 31, 9, 59, 59),
                 LocalDateTime.of(2021, 12, 31, 10, 0, 0));
         System.out.println("用户ID,昵称,手机,持有套数");
@@ -87,4 +88,9 @@ class AssetServiceTest extends ApplicationTests {
         }
 
     }
+
+    @Test
+    public void userHistory() {
+        assetService.userHistory(44L, 1, Pageable.unpaged());
+    }
 }