| | |
| | | @ResponseBody |
| | | public ServerResponse transfer(@RequestParam("fromType") String fromType, @RequestParam("toType") String toType, |
| | | @RequestParam("amt") String amt, HttpServletRequest request) { |
| | | if (fromType.equals(toType)) { |
| | | return ServerResponse.createByErrorMsg("货币类型不能相同", request); |
| | | try { |
| | | if (fromType.equals(toType)) { |
| | | return ServerResponse.createByErrorMsg("货币类型不能相同", request); |
| | | } |
| | | return iUserService.transfer(fromType, toType, amt,request); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | } |
| | | return iUserService.transfer(fromType, toType, amt,request); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | ServerResponse getMoney(Integer userId); |
| | | |
| | | ServerResponse transfer(String fromType,String toType,String amt,HttpServletRequest paramHttpServletRequest); |
| | | ServerResponse transfer(String fromType,String toType,String amt,HttpServletRequest paramHttpServletRequest) throws Exception; |
| | | |
| | | void ForceSellTask(); |
| | | void ForceSellOneStockTask(); |
| | |
| | | |
| | | @Override |
| | | public BigDecimal exchangeAmountByRate(String fromType, String toType, BigDecimal amount) throws Exception { |
| | | EStockType stockType = EStockType.getEStockTypeBySymbol(fromType); |
| | | EStockType toStockType = EStockType.getEStockTypeBySymbol(toType); |
| | | EStockType stockType = EStockType.getEStockTypeByCode(fromType); |
| | | EStockType toStockType = EStockType.getEStockTypeByCode(toType); |
| | | ExchangeRate exchangeRate = exchangeRateRepository.findExchangeRateByCurrencyAndConversionCurrency( |
| | | stockType.getSymbol(), toStockType.getSymbol()).orElse(null); |
| | | if (exchangeRate != null) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ServerResponse transfer(String fromType, String toType, String amt,HttpServletRequest request) { |
| | | try { |
| | | User user = userService.getCurrentUser(request); |
| | | UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId()); |
| | | BigDecimal amtBig = new BigDecimal(amt).abs(); |
| | | @Transactional |
| | | public ServerResponse transfer(String fromType, String toType, String amt,HttpServletRequest request) throws Exception { |
| | | User user = userService.getCurrentUser(request); |
| | | UserAssets formAssets = userAssetsServices.assetsByTypeAndUserId(fromType,user.getId()); |
| | | BigDecimal amtBig = new BigDecimal(amt).abs(); |
| | | |
| | | // 转换手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.EXCHANGE_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(amtBig); |
| | | //资金校验 |
| | | BigDecimal needAmt = amtBig.add(orderFree); |
| | | if(formAssets.getAvailableBalance().compareTo(needAmt)<0){ |
| | | return ServerResponse.createByErrorMsg("余额不足", request); |
| | | } |
| | | |
| | | if (orderFree.compareTo(BigDecimal.ZERO) > 0) { |
| | | userAssetsServices.availablebalanceChange(fromType, user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | } |
| | | |
| | | userAssetsServices.availablebalanceChange(fromType, user.getId(), EUserAssets.TRANSFER, amtBig.negate(),fromType+"/"+toType,""); |
| | | //转换金额 |
| | | amtBig = userAssetsServices.exchangeAmountByRate(fromType, toType, amtBig); |
| | | userAssetsServices.availablebalanceChange(toType,user.getId(), EUserAssets.TRANSFER, amtBig.setScale(5,RoundingMode.HALF_DOWN),fromType+"/"+toType,""); |
| | | |
| | | return ServerResponse.createBySuccess("操作成功", request); |
| | | } catch (Exception e) { |
| | | return ServerResponse.createByErrorMsg(e.getMessage()); |
| | | // 转换手续费率 |
| | | BigDecimal siteSettingBuyFee = new BigDecimal(iStockConfigServices.queryByKey(EConfigKey.EXCHANGE_HANDLING_CHARGE.getCode()).getCValue()) ; |
| | | BigDecimal orderFree = siteSettingBuyFee.multiply(amtBig); |
| | | //资金校验 |
| | | BigDecimal needAmt = amtBig.add(orderFree); |
| | | if(formAssets.getAvailableBalance().compareTo(needAmt)<0){ |
| | | return ServerResponse.createByErrorMsg("余额不足", request); |
| | | } |
| | | |
| | | if (orderFree.compareTo(BigDecimal.ZERO) > 0) { |
| | | userAssetsServices.availablebalanceChange(fromType, user.getId(), EUserAssets.HANDLING_CHARGE, orderFree, "", ""); |
| | | } |
| | | |
| | | userAssetsServices.availablebalanceChange(fromType, user.getId(), EUserAssets.TRANSFER, amtBig.negate(),fromType+"/"+toType,""); |
| | | //转换金额 |
| | | amtBig = userAssetsServices.exchangeAmountByRate(fromType, toType, amtBig); |
| | | userAssetsServices.availablebalanceChange(toType,user.getId(), EUserAssets.TRANSFER, amtBig.setScale(5,RoundingMode.HALF_DOWN),fromType+"/"+toType,""); |
| | | |
| | | return ServerResponse.createBySuccess("操作成功", request); |
| | | } |
| | | |
| | | |