From b38469269d05b02cd67afbbbae65f0ae28f87b4e Mon Sep 17 00:00:00 2001
From: zj <1772600164@qq.com>
Date: Tue, 12 Aug 2025 01:00:22 +0800
Subject: [PATCH] 1
---
trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java | 63 +++++++++++--------------------
1 files changed, 23 insertions(+), 40 deletions(-)
diff --git a/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java b/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
index 06cbca9..b06ca1d 100644
--- a/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
+++ b/trading-order-service/src/main/java/com/yami/trading/service/impl/WalletServiceImpl.java
@@ -57,6 +57,7 @@
import java.time.LocalTime;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
@Slf4j
@@ -216,45 +217,6 @@
List<ContractOrder> contractOrders = getContractOrders(partyId);
if (contractOrders != null) {
-// for (ContractOrder order : contractOrders) {
-// String symbol = order.getSymbol();
-// Item bySymbol = itemService.findBySymbol(symbol);
-// if (bySymbol == null) {
-// continue;
-// }
-// // 类型不对直接continue
-// if (StringUtils.isNotEmpty(symbolType)) {
-// if (!bySymbol.getType().equalsIgnoreCase(symbolType)) {
-// continue;
-// }
-//
-// }
-// // 真正下单里
-// double order_volume = 1;
-//
-// if (order.getLeverRate() != null && order.getLeverRate().compareTo(BigDecimal.ZERO) != 0) {
-// order_volume = order.getVolumeOpen().divide(order.getLeverRate()).doubleValue();
-// } else {
-// order_volume = order.getVolumeOpen().doubleValue();
-// }
-//
-// double amount = Arith.add(Arith.mul(order_volume, order.getUnitAmount().doubleValue()), order.getProfit().doubleValue());
-// money_contract = Arith.add(amount, money_contract);
-// money_contract_deposit = Arith.add(order.getDeposit().doubleValue(), money_contract_deposit);
-// money_contract_profit = Arith.add(order.getProfit().doubleValue(), money_contract_profit);
-// // 只需要计算当日盈亏比例*金额就是当日盈亏
-//
-// List<Realtime> realtimes = dataService.realtime(symbol);
-// if (CollectionUtils.isNotEmpty(realtimes)) {
-// Realtime realtime = realtimes.get(0);
-// // 当前每张金额*加杠杆后多少金额
-// // 今天总体涨跌幅
-// BigDecimal changeRatio = realtime.getClose().subtract(realtime.getOpen()).divide(realtime.getOpen(), 10, RoundingMode.HALF_UP);
-// Double todayProfit = order.getUnitAmount().multiply(order.getVolumeOpen()).multiply(changeRatio).setScale(10, RoundingMode.HALF_UP).doubleValue();
-// money_contract_profit_today += todayProfit;
-// }
-// }
-
Map<String, List<ContractOrder>> groupedOrders = contractOrders.stream()
.collect(Collectors.groupingBy(ContractOrder::getState));
@@ -310,13 +272,34 @@
if (!"".equals(partyId) && partyId != null) {
wallet = findByUserId(partyId.toString());
}
+ List<WalletExtend> walletExtends = walletExtendService.findByUserId(partyId);
+ AtomicReference<BigDecimal> walletExtendMoneyRef = new AtomicReference<>(BigDecimal.ZERO);
+ walletExtends.forEach(f -> {
+ double closePrice = getRealtimePrice(f.getWallettype());
+ BigDecimal amount = new BigDecimal(String.valueOf(f.getAmount()));
+ BigDecimal price = new BigDecimal(String.valueOf(closePrice));
+ BigDecimal money = amount.multiply(price);
+ walletExtendMoneyRef.updateAndGet(current -> current.add(money));
+ });
+ BigDecimal walletExtendMoney = walletExtendMoneyRef.get();
CapitaltWallet userIdWallet = capitaltWalletMapper.selectOne(new LambdaQueryWrapper<CapitaltWallet>()
.eq(CapitaltWallet::getUserId,partyId.toString()));
moneys_contract.put("money_wallet", wallet.getMoney().doubleValue());//可用余额
- moneys_contract.put("money_contract", userIdWallet.getMoney().doubleValue()+wallet.getMoney().doubleValue()+money_contract);
+ moneys_contract.put("money_contract", userIdWallet.getMoney().doubleValue()+wallet.getMoney().doubleValue()+money_contract+walletExtendMoney.doubleValue());
return moneys_contract;
}
+ @Override
+ public double getRealtimePrice(String symbol) {
+ List<Realtime> realtimes = dataService.realtime(symbol);
+ double close = 1;
+ if (realtimes != null && realtimes.size() > 0) {
+ close = realtimes.get(0).getClose().doubleValue();
+ } else {
+ throw new YamiShopBindException("参数错误");
+ }
+ return close;
+ }
private static LocalDateTime toLocalDateTime(Date date) {
return LocalDateTime.ofInstant(date.toInstant(), java.time.ZoneId.systemDefault());
}
--
Gitblit v1.9.3