From 30e592bd0975b41e0b4b4140c4b794c2e1e121de Mon Sep 17 00:00:00 2001
From: zyy <zyy@email.com>
Date: Mon, 09 Feb 2026 15:21:44 +0800
Subject: [PATCH] 平仓
---
src/main/java/com/nq/service/impl/UserPositionServiceImpl.java | 41 +++++++++++++++++++++++------------------
1 files changed, 23 insertions(+), 18 deletions(-)
diff --git a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
index 5c9e9d9..1f635c4 100644
--- a/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
+++ b/src/main/java/com/nq/service/impl/UserPositionServiceImpl.java
@@ -306,9 +306,9 @@
.eq(UserAssets::getUserId, userPosition.getUserId())
.eq(UserAssets::getAccectType, "JP")
);
- if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ /*if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
return ServerResponse.createByErrorMsg("用户待补资金未补齐,禁止平仓");
- }
+ }*/
if (userPosition.getSellOrderId() != null) {
return ServerResponse.createByErrorMsg("平仓失败, 订单已平仓");
}
@@ -327,16 +327,21 @@
BigDecimal sellOrderTotel = nowPrice.multiply(new BigDecimal(userPosition.getOrderNum()));
BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);
userPositionMapper.updateById(userPosition);
- userAssetsServices.availablebalanceChange(stock.getStockType(),
+
+ PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, priceServices.getNowPrice(userPosition.getStockCode()));
+ /*userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
+ profitVO.getAllProfitAndLose(), "", "");*/
+
+ //从保证金里计算盈亏
+ BigDecimal returnAmt = userPosition.getOrderTotalPrice().add(profitVO.getAllProfitAndLose());
+
+ userAssetsServices.availablebalanceSell(stock.getStockType(),
userPosition.getUserId(), EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT,
- userPosition.getOrderTotalPrice(), "", "");
+ returnAmt, userPosition.getOrderTotalPrice());
userAssetsServices.availablebalanceChange(stock.getStockType(),
userPosition.getUserId(), EUserAssets.HANDLING_CHARGE,
xsPrice, "", "");
- PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, priceServices.getNowPrice(userPosition.getStockCode()));
- userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
- profitVO.getAllProfitAndLose(), "", "");
return ServerResponse.createBySuccessMsg("平仓成功!");
}
@@ -360,9 +365,9 @@
.eq(UserAssets::getUserId, userPosition.getUserId())
.eq(UserAssets::getAccectType, "JP")
);
- if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
+ /*if(userAssets.getAmountToBeCovered().compareTo(BigDecimal.ZERO) > 0){
return ServerResponse.createByErrorMsg("请先缴清待补资金", request);
- }
+ }*/
StockSubscribe stockSubscribe = stockSubscribeMapper.selectOne(new LambdaQueryWrapper<StockSubscribe>()
.eq(StockSubscribe::getCode, userPosition.getStockCode()));
if (null != stockSubscribe && DateUtil.date().before(stockSubscribe.getListDate())) {
@@ -444,20 +449,20 @@
BigDecimal xsPrice = sellOrderTotel.multiply(siitteBuyFee);
userPosition.setOrderFee(userPosition.getOrderFee().add(xsPrice));
userPositionMapper.updateById(userPosition);
- userAssetsServices.availablebalanceChange(stock.getStockType(),
+ PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition, priceServices.getNowPrice(userPosition.getStockCode()));
+ /*userAssetsServices.availablebalanceChange(stock.getStockType(), userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
+ profitVO.getAllProfitAndLose(), "", "");*/
+
+ //从保证金里计算盈亏
+ BigDecimal returnAmt = userPosition.getOrderTotalPrice().add(profitVO.getAllProfitAndLose());
+
+ userAssetsServices.availablebalanceSell(stock.getStockType(),
userPosition.getUserId(),
EUserAssets.CLOSE_POSITION_RETURN_SECURITY_DEPOSIT,
- userPosition.getOrderTotalPrice(), "", "");
+ returnAmt, userPosition.getOrderTotalPrice());
userAssetsServices.availablebalanceChange(stock.getStockType(),
userPosition.getUserId(), EUserAssets.HANDLING_CHARGE,
xsPrice, "", "");
-
- PositionProfitVO profitVO = UserPointUtil.getPositionProfitVO(userPosition,
- priceServices.getNowPrice(userPosition.getStockCode()));
-
- userAssetsServices.availablebalanceChange(stock.getStockType(),
- userPosition.getUserId(), EUserAssets.CLOSE_POSITION,
- profitVO.getAllProfitAndLose(), "", "");
return ServerResponse.createBySuccessMsg("平仓成功!", request);
}
--
Gitblit v1.9.3