| | |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!accetType.equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(accetType); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency( |
| | | stockType.getSymbol(), EStockType.MX.getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | //转换为墨西哥币 |
| | | amount = exchangeAmountByRate(amount, exchangeRate.getRata()); |
| | | } else { |
| | | log.error("availablebalanceChange ExchangeRate is null:{}>>{}", stockType.getSymbol(), EStockType.MX.getSymbol()); |
| | | throw new Exception("货币转换汇率未设置"); |
| | | } |
| | | amount = exchangeAmountByRate(accetType, amount); |
| | | } |
| | | UserPosition userPosition = userPositionMapper.selectOne(new LambdaQueryWrapper<UserPosition>().gt(UserPosition::getAmountToBeCovered, BigDecimal.ZERO).eq(UserPosition::getUserId,userAssets.getUserId())); |
| | | String type = eUserAssets.getDesc(); |
| | |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!accetType.equals(EStockType.MX.getCode())) { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(accetType); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency( |
| | | stockType.getSymbol(), EStockType.MX.getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | //转换为墨西哥币 |
| | | amount = exchangeAmountByRate(amount, exchangeRate.getRata()); |
| | | } else { |
| | | log.error("ExchangeRate is null:{}>>{}", stockType.getSymbol(), EStockType.MX.getSymbol()); |
| | | throw new Exception("货币转换汇率未设置"); |
| | | } |
| | | amount = exchangeAmountByRate(accetType, amount); |
| | | } |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | | if (eUserAssets.getCode().equals(EUserAssets.BUY_AI.getCode())) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal exchangeAmountByRate(BigDecimal amount, BigDecimal rate) { |
| | | //保留5位小数 |
| | | return amount.multiply(rate).setScale(5, RoundingMode.HALF_UP); |
| | | public BigDecimal exchangeAmountByRate(String accetType, BigDecimal amount) throws Exception { |
| | | EStockType stockType = EStockType.getEStockTypeByCode(accetType); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency( |
| | | stockType.getSymbol(), EStockType.MX.getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | //转换为墨西哥币 保留5位小数 |
| | | return amount.multiply(exchangeRate.getRata()).setScale(5, RoundingMode.HALF_UP); |
| | | } else { |
| | | log.error("exchangeAmountByRate is null:{}>>{}", stockType.getSymbol(), EStockType.MX.getSymbol()); |
| | | throw new Exception("货币转换汇率未设置"); |
| | | } |
| | | |
| | | |
| | | } |
| | | } |