From c67081686f866f0c00b767a60d38d63f19b393b9 Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Tue, 21 Oct 2025 14:18:37 +0800
Subject: [PATCH] 1

---
 trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java |  145 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 145 insertions(+), 0 deletions(-)

diff --git a/trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java b/trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java
index c04f7af..84052b4 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/user/impl/UserStatisticsServiceImpl.java
@@ -1,11 +1,18 @@
 package com.yami.trading.service.user.impl;
 
 import cn.hutool.json.JSONUtil;
+import com.yami.trading.bean.data.domain.Realtime;
+import com.yami.trading.bean.item.domain.Item;
+import com.yami.trading.bean.model.CapitaltWallet;
 import com.yami.trading.bean.model.Wallet;
 import com.yami.trading.bean.model.WalletExtend;
+import com.yami.trading.common.domain.Result;
 import com.yami.trading.common.exception.YamiShopBindException;
+import com.yami.trading.common.util.Arith;
 import com.yami.trading.common.util.StringUtils;
+import com.yami.trading.service.CapitaltWalletService;
 import com.yami.trading.service.WalletService;
+import com.yami.trading.service.item.ItemService;
 import com.yami.trading.service.user.UserRecomService;
 import com.yami.trading.service.user.UserStatisticsService;
 import lombok.extern.slf4j.Slf4j;
@@ -13,9 +20,12 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import javax.servlet.http.HttpServletRequest;
 import java.math.BigDecimal;
 import java.math.RoundingMode;
+import java.text.DecimalFormat;
 import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 @Slf4j
@@ -26,6 +36,10 @@
     UserRecomService userRecomService;
     @Autowired
     WalletService walletService;
+    @Autowired
+    CapitaltWalletService capitaltWalletService;
+    @Autowired
+    ItemService itemService;
 
     @Override
      public List<Map<String,Object>> getAssetsAll(String loginPartyId,String targetPartyId) {
@@ -113,4 +127,135 @@
 
         return result;
     }
+
+    @Override
+    public Result getWalletExtends(String partyId) {
+        Map<String, Object> mapRet = new LinkedHashMap<String, Object>();
+        DecimalFormat df2 = new DecimalFormat("#.########");
+        // 向下取整
+        df2.setRoundingMode(RoundingMode.FLOOR);
+
+        CapitaltWallet usdt = null;
+        if (StringUtils.isNotEmpty(partyId)) {
+            usdt = capitaltWalletService.getUserIdWallet(partyId);
+        }
+
+        // 其他币账户
+        List<Item> list_it = this.itemService.cacheGetByMarket("");
+        if (!list_it.isEmpty()) {
+            list_it = list_it.stream().filter(i -> Item.cryptos.equalsIgnoreCase(i.getType())).collect(Collectors.toList());
+        }
+        List<String> list_symbol = new ArrayList<String>();
+        // symbol为空,获取所有的
+        for (int i = 0; i < list_it.size(); i++) {
+
+            Item items = list_it.get(i);
+            list_symbol.add(items.getSymbol());
+        }
+
+        List<Item> items = itemService.cacheGetAll();
+        // 按id排序
+        Collections.sort(items, new Comparator<Item>() {
+            @Override
+            public int compare(Item arg0, Item arg1) {
+                return arg0.getUuid().toString().compareTo(arg1.getUuid().toString());
+            }
+        });
+        Map<String, Item> itemMap = new HashMap<String, Item>();
+        for (int i = 0; i < items.size(); i++) {
+            itemMap.put(items.get(i).getSymbol(), items.get(i));
+        }
+        List<WalletExtend> walletExtends = null;
+        log.info(list_symbol.toString() + "=============");
+        if (StringUtils.isNotEmpty(partyId)) {
+            walletExtends = this.walletService.findExtend(partyId, list_symbol);
+        }
+        if (null == walletExtends) {
+            walletExtends = new ArrayList<WalletExtend>();
+        }
+        List<WalletExtend> walletExtendsRet = new ArrayList<WalletExtend>();
+        int temp = 0;
+        for (int i = 0; i < list_symbol.size(); i++) {
+            for (int j = 0; j < walletExtends.size(); j++) {
+                WalletExtend walletExtend = walletExtends.get(j);
+                if (walletExtend.getWallettype().equals(list_symbol.get(i))) {
+                    walletExtend.setAmount(Double.valueOf(df2.format(walletExtend.getAmount())));
+                    walletExtend.setLockAmount(Double.valueOf(df2.format(walletExtend.getLockAmount())));
+                    walletExtend.setFreezeAmount(Double.valueOf(df2.format(walletExtend.getFreezeAmount())));
+                    walletExtend.setName(itemMap.get(list_symbol.get(i)).getName());
+                    walletExtendsRet.add(walletExtend);
+                    temp = 1;
+                }
+            }
+            if (0 == temp) {
+                WalletExtend walletExtend = new WalletExtend();
+                if (StringUtils.isNotEmpty(partyId)) {
+                    walletExtend.setPartyId(partyId);
+                }
+                walletExtend.setWallettype(list_symbol.get(i));
+                walletExtend.setAmount(0);
+                walletExtend.setLockAmount(0);
+                walletExtend.setFreezeAmount(0);
+                walletExtend.setName(itemMap.get(list_symbol.get(i)).getName());
+                walletExtendsRet.add(walletExtend);
+            }
+            temp = 0;
+        }
+        String symbolsStr = "";
+        for (int i = 0; i < list_symbol.size(); i++) {
+            if (i != 0) {
+                symbolsStr = symbolsStr + "," + list_symbol.get(i);
+            } else {
+                symbolsStr = list_symbol.get(i);
+            }
+        }
+
+        List<Map<String, Object>> extendsList = new ArrayList<Map<String, Object>>();
+        for (int i = 0; i < walletExtendsRet.size(); i++) {
+            Map<String, Object> map = new HashMap<String, Object>();
+            map.put("name", walletExtendsRet.get(i).getName());
+            String wallettype = walletExtendsRet.get(i).getWallettype();
+            map.put("symbol", wallettype);
+            map.put("symbol_data", itemMap.get(wallettype).getSymbolData());
+            double volume = Arith.add(walletExtendsRet.get(i).getAmount(), walletExtendsRet.get(i).getFreezeAmount());
+            map.put("volume", df2.format(volume));
+
+            extendsList.add(map);
+        }
+
+
+        // 添加usdt到列表最前面
+        Map<String, Object> mapUsdt = new HashMap<String, Object>();
+        mapUsdt.put("name", "USDT/USDT");
+        mapUsdt.put("symbol", "usdt");
+        mapUsdt.put("symbol_data", "usdt");
+        mapUsdt.put("volume", df2.format(usdt.getMoney().doubleValue()));
+        extendsList.add(0, mapUsdt);
+
+        // 分离 USDC 和 USDT,并保留其他数据
+        Map<String, Object> usdcEntry = null;
+        Map<String, Object> usdtEntry = null;
+        List<Map<String, Object>> otherEntries = new ArrayList<>();
+
+        for (Map<String, Object> entry : extendsList) {
+            String symbolData = (String) entry.get("symbol_data");
+            if ("usdc".equals(symbolData)) {
+                usdcEntry = entry;
+            } else if ("usdt".equals(symbolData)) {
+                usdtEntry = entry;
+            } else {
+                otherEntries.add(entry);
+            }
+        }
+
+        // 重新组合,USDC 第一,USDT 第二,其他保持原顺序
+        List<Map<String, Object>> newExtendsList = new ArrayList<>();
+        if (usdcEntry != null) newExtendsList.add(usdcEntry);
+        if (usdtEntry != null) newExtendsList.add(usdtEntry);
+        newExtendsList.addAll(otherEntries);
+
+        mapRet.put("extends", newExtendsList);
+
+        return Result.succeed(mapRet);
+    }
 }

--
Gitblit v1.9.3