|
|
@@ -3,6 +3,7 @@ package com.izouma.nineth.service;
|
|
|
import com.izouma.nineth.TokenHistory;
|
|
|
import com.izouma.nineth.config.GeneralProperties;
|
|
|
import com.izouma.nineth.domain.*;
|
|
|
+import com.izouma.nineth.domain.Collection;
|
|
|
import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.dto.UserHistory;
|
|
|
import com.izouma.nineth.enums.AssetStatus;
|
|
|
@@ -17,6 +18,7 @@ import com.izouma.nineth.utils.SecurityUtils;
|
|
|
import com.izouma.nineth.utils.TokenUtils;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.ObjectUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
|
|
import org.apache.rocketmq.common.message.Message;
|
|
|
@@ -32,10 +34,8 @@ import java.math.BigDecimal;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Predicate;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -344,10 +344,18 @@ public class AssetService {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- public Page<UserHistory> userHistory(Long userId, Pageable pageable) {
|
|
|
- Page<TokenHistory> page = tokenHistoryRepo.userHistory(userId, pageable);
|
|
|
+ public Page<UserHistory> userHistory(Long userId, Long toUserId, Long fromUserId, Pageable pageable) {
|
|
|
+ Page<TokenHistory> page;
|
|
|
+ if (ObjectUtils.isNotEmpty(toUserId)) {
|
|
|
+ page = tokenHistoryRepo.userHistoryTo(userId, toUserId, pageable);
|
|
|
+ } else if (ObjectUtils.isNotEmpty(fromUserId)) {
|
|
|
+ page = tokenHistoryRepo.userHistoryFrom(userId, fromUserId, pageable);
|
|
|
+ } else {
|
|
|
+ page = tokenHistoryRepo.userHistory(userId, pageable);
|
|
|
+ }
|
|
|
Set<String> tokenIds = page.stream().map(TokenHistory::getTokenId).collect(Collectors.toSet());
|
|
|
List<Asset> assets = tokenIds.isEmpty() ? new ArrayList<>() : assetRepo.findByTokenIdIn(tokenIds);
|
|
|
+
|
|
|
return page.map(tokenHistory -> {
|
|
|
UserHistory userHistory = new UserHistory();
|
|
|
BeanUtils.copyProperties(tokenHistory, userHistory);
|
|
|
@@ -378,4 +386,27 @@ public class AssetService {
|
|
|
return "ok";
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public Map<String, BigDecimal> userHistory(Long userId) {
|
|
|
+ List<TokenHistory> page = tokenHistoryRepo.userHistory(userId);
|
|
|
+ Set<String> tokenIds = page.stream().map(TokenHistory::getTokenId).collect(Collectors.toSet());
|
|
|
+ List<Asset> assets = tokenIds.isEmpty() ? new ArrayList<>() : assetRepo.findByTokenIdIn(tokenIds);
|
|
|
+ BigDecimal sales = BigDecimal.ZERO;
|
|
|
+ BigDecimal buy = BigDecimal.ZERO;
|
|
|
+ page.stream().map(tokenHistory -> {
|
|
|
+ Optional<Asset> asset = assets.stream().filter(a -> a.getTokenId().equals(tokenHistory.getTokenId()))
|
|
|
+ .findAny();
|
|
|
+
|
|
|
+// switch (tokenHistory.getOperation()) {
|
|
|
+// case "出售":
|
|
|
+// case "转让":
|
|
|
+// if (tokenHistory.getToUserId().equals(userId)) {
|
|
|
+// buy.add(asset.stream().map().getPrice())
|
|
|
+// }
|
|
|
+// break;
|
|
|
+// }
|
|
|
+ return null;
|
|
|
+ });
|
|
|
+ return null;
|
|
|
+ }
|
|
|
}
|