| | |
| | | |
| | | 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; |
| | | |
| | |
| | | * 仓位计算工具类 |
| | | * */ |
| | | public class UserPointUtil { |
| | | private static final Logger log = LoggerFactory.getLogger(UserPointUtil.class); |
| | | |
| | | |
| | | /** |
| | |
| | | userPositionVO.setStockPlate(position.getStockPlate()); |
| | | userPositionVO.setSpreadRatePrice(position.getSpreadRatePrice()); |
| | | PositionProfitVO positionProfitVO = getPositionProfitVO(position,nowPrice); |
| | | BigDecimal ss = positionProfitVO.getProfitAndLose().divide(userPositionVO.getOrderTotalPrice(),BigDecimal.ROUND_CEILING) |
| | | .multiply(new BigDecimal(100)); |
| | | 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()); |
| | |
| | | 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()); |