zyy
2026-02-09 30e592bd0975b41e0b4b4140c4b794c2e1e121de
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())) {
@@ -416,17 +421,16 @@
            position.setId(null);
            position.setPositionSn(KeyUtils.getUniqueKey());
            position.setOrderNum(number);
            position.setOrderTotalPrice(position.getBuyOrderPrice().multiply(new BigDecimal(number)));
            position.setOrderTotalPrice(position.getBuyOrderPrice().multiply(new BigDecimal(number)).divide(new BigDecimal(position.getOrderLever()), 5, RoundingMode.HALF_UP));
            position.setBuyOrderId(GeneratePosition.getPositionId());
            //修改拆分订单手续费
            BigDecimal BuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.BUY_HANDLING_CHARGE.getCode()).getCValue());
            BigDecimal buyPrice = position.getBuyOrderPrice().multiply(new BigDecimal(position.getOrderNum()));
            BigDecimal xsPrice = buyPrice.multiply(BuyFee);
            BigDecimal xsPrice = position.getOrderTotalPrice().multiply(BuyFee);
            position.setOrderFee(xsPrice);
            //修改原订单
            userPosition.setOrderNum(userPosition.getOrderNum()-number);
            userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(userPosition.getOrderNum())));
            userPosition.setOrderTotalPrice(userPosition.getBuyOrderPrice().multiply(new BigDecimal(userPosition.getOrderNum())).divide(new BigDecimal(position.getOrderLever()), 5, RoundingMode.HALF_UP));
            userPosition.setOrderFee(userPosition.getOrderFee().subtract(position.getOrderFee()));
            userPositionMapper.insert(position);
            userPositionMapper.updateById(userPosition);
@@ -445,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);
    }