This commit is contained in:
2026-03-29 00:11:29 +08:00
4 changed files with 621 additions and 398 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -237,7 +237,8 @@ public class AssetService {
trade.setCoinCode(coinCode.toUpperCase());
trade.setQuantity(BigDecimal.ZERO);
trade.setFrozen(BigDecimal.ZERO);
trade.setAvgPrice(BigDecimal.ZERO);
// USDT作为基准货币均价固定为1
trade.setAvgPrice("USDT".equals(coinCode.toUpperCase()) ? BigDecimal.ONE : BigDecimal.ZERO);
trade.setTotalBuy(BigDecimal.ZERO);
trade.setTotalSell(BigDecimal.ZERO);
trade.setCreateTime(LocalDateTime.now());

View File

@@ -4,8 +4,10 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.it.rattan.monisuo.entity.*;
import com.it.rattan.monisuo.mapper.AccountTradeMapper;
import com.it.rattan.monisuo.mapper.OrderTradeMapper;
import com.it.rattan.monisuo.util.OrderNoUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -23,6 +25,9 @@ public class TradeService {
@Autowired
private OrderTradeMapper orderTradeMapper;
@Autowired
private AccountTradeMapper accountTradeMapper;
@Autowired
private AssetService assetService;
@@ -55,6 +60,11 @@ public class TradeService {
// 扣减USDT
usdtAccount.setQuantity(usdtAccount.getQuantity().subtract(amount));
usdtAccount.setUpdateTime(LocalDateTime.now());
// 持久化USDT扣减
accountTradeMapper.update(null, new LambdaUpdateWrapper<AccountTrade>()
.eq(AccountTrade::getId, usdtAccount.getId())
.set(AccountTrade::getQuantity, usdtAccount.getQuantity())
.set(AccountTrade::getUpdateTime, usdtAccount.getUpdateTime()));
// 增加持仓
AccountTrade coinAccount = assetService.getOrCreateTradeAccount(userId, coinCode);
@@ -68,6 +78,13 @@ public class TradeService {
}
coinAccount.setTotalBuy(coinAccount.getTotalBuy().add(quantity));
coinAccount.setUpdateTime(LocalDateTime.now());
// 持久化币种持仓更新
accountTradeMapper.update(null, new LambdaUpdateWrapper<AccountTrade>()
.eq(AccountTrade::getId, coinAccount.getId())
.set(AccountTrade::getQuantity, coinAccount.getQuantity())
.set(AccountTrade::getAvgPrice, coinAccount.getAvgPrice())
.set(AccountTrade::getTotalBuy, coinAccount.getTotalBuy())
.set(AccountTrade::getUpdateTime, coinAccount.getUpdateTime()));
// 创建订单
OrderTrade order = new OrderTrade();
@@ -124,11 +141,22 @@ public class TradeService {
coinAccount.setQuantity(coinAccount.getQuantity().subtract(quantity));
coinAccount.setTotalSell(coinAccount.getTotalSell().add(quantity));
coinAccount.setUpdateTime(LocalDateTime.now());
// 持久化币种持仓扣减
accountTradeMapper.update(null, new LambdaUpdateWrapper<AccountTrade>()
.eq(AccountTrade::getId, coinAccount.getId())
.set(AccountTrade::getQuantity, coinAccount.getQuantity())
.set(AccountTrade::getTotalSell, coinAccount.getTotalSell())
.set(AccountTrade::getUpdateTime, coinAccount.getUpdateTime()));
// 增加USDT
AccountTrade usdtAccount = assetService.getOrCreateTradeAccount(userId, "USDT");
usdtAccount.setQuantity(usdtAccount.getQuantity().add(amount));
usdtAccount.setUpdateTime(LocalDateTime.now());
// 持久化USDT增加
accountTradeMapper.update(null, new LambdaUpdateWrapper<AccountTrade>()
.eq(AccountTrade::getId, usdtAccount.getId())
.set(AccountTrade::getQuantity, usdtAccount.getQuantity())
.set(AccountTrade::getUpdateTime, usdtAccount.getUpdateTime()));
// 创建订单
OrderTrade order = new OrderTrade();