| | |
| | | |
| | | @Override |
| | | public UserAssets assetsByTypeAndUserId(String accetType, Integer userId) { |
| | | /*if(accetType.equals("SZHB")){ |
| | | accetType = "US"; |
| | | }*/ |
| | | if(accetType.equals(EStockType.US.getCode()) || accetType.equals("IN")){ |
| | | accetType = EStockType.MX.getCode(); |
| | | if(!accetType.equals(EStockType.US.getCode())){ |
| | | accetType = EStockType.US.getCode(); |
| | | } |
| | | QueryWrapper<UserAssets> queryWrapper = new QueryWrapper<>(); |
| | | queryWrapper.eq("accect_type",accetType); |
| | |
| | | |
| | | @Override |
| | | public Boolean availablebalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount, String desc, String descType) throws Exception { |
| | | //UserAssets userAssets = assetsByTypeAndUserId(accetType,userId); |
| | | //查询墨西哥账户 |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!accetType.equals(EStockType.MX.getCode())) { |
| | | //查询账户 |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.getDefault().getCode(), userId); |
| | | //是否需要转换金额 |
| | | if (!accetType.equals(EStockType.getDefault().getCode())) { |
| | | 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(); |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | |
| | | |
| | | |
| | | public Boolean aiAvailableBalanceChange(String accetType, Integer userId, EUserAssets eUserAssets, BigDecimal amount) throws Exception { |
| | | //查询墨西哥账户 |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.MX.getCode(), userId); |
| | | //如果不是墨西哥币需要转换金额 |
| | | if (!accetType.equals(EStockType.MX.getCode())) { |
| | | //查询账户 |
| | | UserAssets userAssets = assetsByTypeAndUserId(EStockType.getDefault().getCode(), userId); |
| | | //是否需要转换金额 |
| | | if (!accetType.equals(EStockType.getDefault().getCode())) { |
| | | amount = exchangeAmountByRate(accetType, amount); |
| | | } |
| | | String before = userAssets.getAvailableBalance().toString(); |
| | |
| | | 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); |
| | | stockType.getSymbol(), EStockType.getDefault().getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | | //转换为墨西哥币 保留5位小数 |
| | | //转换为默认货币 保留5位小数 |
| | | return amount.multiply(exchangeRate.getRata()).setScale(5, RoundingMode.HALF_UP); |
| | | } else { |
| | | log.error("exchangeAmountByRate is null:{}>>{}", stockType.getSymbol(), EStockType.MX.getSymbol()); |
| | | log.error("exchangeAmountByRate is null:{}>>{}", stockType.getSymbol(), EStockType.getDefault().getSymbol()); |
| | | throw new Exception("货币转换汇率未设置"); |
| | | } |
| | | |