licailing 4 лет назад
Родитель
Сommit
c32f750e49

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

@@ -426,24 +426,19 @@ public class AssetService {
     }
 
 
-    public Map<String, BigDecimal> userHistory(Long userId) {
+    public Map<String, BigDecimal> breakdown(Long userId) {
         List<TokenHistory> page = tokenHistoryRepo.userHistory(userId);
-        Set<String> tokenIds = page.stream().map(TokenHistory::getTokenId).collect(Collectors.toSet());
-        BigDecimal sales = BigDecimal.ZERO;
-        BigDecimal buy = BigDecimal.ZERO;
-        page.stream().map(tokenHistory -> {
-
-
-//            switch (tokenHistory.getOperation()) {
-//                case "出售":
-//                case "转让":
-//                    if (tokenHistory.getToUserId().equals(userId)) {
-//                        buy.add(asset.stream().map().getPrice())
-//                    }
-//                    break;
-//            }
-            return null;
-        });
-        return null;
+        BigDecimal sale = page.stream()
+                .filter(th -> th.getFromUserId().equals(userId) && ObjectUtils.isNotEmpty(th.getPrice()))
+                .map(TokenHistory::getPrice)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        BigDecimal buy = page.stream()
+                .filter(th -> th.getToUserId().equals(userId) && ObjectUtils.isNotEmpty(th.getPrice()))
+                .map(TokenHistory::getPrice)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        Map<String, BigDecimal> map = new HashMap<>();
+        map.put("sale", sale);
+        map.put("buy", buy);
+        return map;
     }
 }

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

@@ -23,6 +23,7 @@ import javax.servlet.http.HttpServletResponse;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.Map;
 
 @RestController
 @RequestMapping("/asset")
@@ -120,6 +121,12 @@ public class AssetController extends BaseController {
     public String mint() {
         return assetService.mint();
     }
+
+    @GetMapping("/breakdown")
+    @ApiOperation("收支总计")
+    public Map<String, BigDecimal> breakdown() {
+        return assetService.breakdown(SecurityUtils.getAuthenticatedUser().getId());
+    }
 }