1
zj
2025-05-06 621f2eb73b862920a395a1b74d1fd9e4c26a85d3
src/main/java/com/nq/utils/UserPointUtil.java
@@ -3,8 +3,11 @@
import com.github.pagehelper.util.StringUtil;
import com.nq.pojo.UserPosition;
import com.nq.service.impl.UserServiceImpl;
import com.nq.vo.position.PositionProfitVO;
import com.nq.vo.position.UserPositionVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.math.BigDecimal;
@@ -12,6 +15,7 @@
 * 仓位计算工具类
 * */
public class UserPointUtil {
    private static final Logger log = LoggerFactory.getLogger(UserPointUtil.class);
    /**
@@ -50,8 +54,18 @@
        userPositionVO.setStockPlate(position.getStockPlate());
        userPositionVO.setSpreadRatePrice(position.getSpreadRatePrice());
        PositionProfitVO positionProfitVO = getPositionProfitVO(position,nowPrice);
       BigDecimal ss =  positionProfitVO.getProfitAndLose().divide(userPositionVO.getOrderTotalPrice(),BigDecimal.ROUND_CEILING)
        BigDecimal profitAndLose = positionProfitVO.getProfitAndLose();
        BigDecimal orderTotalPrice = userPositionVO.getOrderTotalPrice();
        BigDecimal ss = BigDecimal.ZERO;
        if (orderTotalPrice.compareTo(BigDecimal.ZERO) == 0) {
            // 如果分母为0,可以选择返回一个默认值,比如BigDecimal.ZERO
            // 或者根据业务逻辑进行其他处理
            ss = BigDecimal.ZERO;
        } else {
            ss = profitAndLose.divide(orderTotalPrice, BigDecimal.ROUND_CEILING)
               .multiply(new BigDecimal(100));
        }
        userPositionVO.setProfitAndLoseParent(ss.setScale(2, BigDecimal.ROUND_DOWN)+"%");
        userPositionVO.setProfitAndLose(positionProfitVO.getProfitAndLose());
        userPositionVO.setAllProfitAndLose(positionProfitVO.getAllProfitAndLose());
@@ -70,7 +84,6 @@
    public static PositionProfitVO getPositionProfitVO(UserPosition position,BigDecimal nowPrice) {
        BigDecimal profitAndLose = new BigDecimal("0");
        BigDecimal allProfitAndLose = new BigDecimal("0");
        if (position.getSellOrderId() != null) {
            BigDecimal subPrice = position.getSellOrderPrice().subtract(position.getBuyOrderPrice());