| | |
| | | return currency; |
| | | } |
| | | |
| | | /** |
| | | * 根据股票类型获取对应USDT金额 |
| | | * |
| | | * @param currency 币种价值 |
| | | * @param type 股票类型 |
| | | * @return currency |
| | | */ |
| | | public BigDecimal getUsdtByType(List<ExchangeRate> list, BigDecimal currency, String type) { |
| | | if (StringUtils.isEmpty(type)) { |
| | | type = Item.US_STOCKS; |
| | | } |
| | | if (type.contains("A") && !Item.A_STOCKS.equalsIgnoreCase(type)) { |
| | | type = type.replace("A", ""); |
| | | } |
| | | //ExchangeRate rate = getOne(new LambdaQueryWrapper<ExchangeRate>().like(ExchangeRate::getType, type)); |
| | | String finalType = type; |
| | | ExchangeRate rate = list.stream() |
| | | .filter(x -> { |
| | | if (x.getType() == null || x.getType().isEmpty()) { |
| | | return false; // 若任一为 null,不匹配 |
| | | } |
| | | // 统一转为小写(或大写)后,判断是否包含目标子串 |
| | | return x.getType().toLowerCase().contains(finalType.toLowerCase()); |
| | | }) |
| | | .findFirst().orElse(null); |
| | | if (rate != null) { |
| | | BigDecimal rata = rate.getRata(); |
| | | currency = currency.divide(rata, 4, RoundingMode.FLOOR); |
| | | } |
| | | return currency; |
| | | } |
| | | |
| | | } |