Merge branch 'EP-Indicator' of zhixinlian/client-server into master

integration
fengyu.wang 5 years ago
commit 5ebc3a8f8f
  1. 5
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/inner/BtcWalletInner.java
  2. 2
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/mapper/BtcWalletMapper.java
  3. 8
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletService.java
  4. 5
      blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java
  5. 6
      blockchain-server/blockchain-server-btc/src/main/resources/mapper/BtcWalletMapper.xml
  6. 7
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/inner/EosWalletInnerController.java
  7. 8
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/mapper/WalletMapper.java
  8. 8
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/EosWalletService.java
  9. 6
      blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java
  10. 6
      blockchain-server/blockchain-server-eos/src/main/resources/mapper/WalletMapper.xml
  11. 5
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java
  12. 8
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/mapper/EthWalletMapper.java
  13. 8
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/IEthWalletService.java
  14. 7
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java
  15. 6
      blockchain-server/blockchain-server-eth/src/main/resources/mapper/EthWalletMapper.xml
  16. 5
      blockchain-server/blockchain-server-yyyf/pom.xml
  17. 3
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java
  18. 6
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java
  19. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java
  20. 3
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java
  21. 94
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java
  22. 12
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/AppTypeEnum.java
  23. 24
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/CurrencyEnum.java
  24. 4
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/dto/IndicatorsTypeEnum.java
  25. 17
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/AssetLiabilityRiskRateIndicatorsHandler.java
  26. 13
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/handle/TotalGrowthRateIndicatorsHandler.java

@ -34,9 +34,8 @@ public class BtcWalletInner {
} }
@GetMapping("/getWallets") @GetMapping("/getWallets")
public ResultDTO<List<BtcWalletDTO>> getWallets(@RequestParam("userId") String userId, public ResultDTO<List<BtcWalletDTO>> getWallets(@RequestParam("userId") String userId) {
@RequestParam("walletType") String walletType) { return ResultDTO.requstSuccess(btcWalletService.selectAllByUserOpenId(userId));
return ResultDTO.requstSuccess(btcWalletService.selectAllByUserOpenId(userId, walletType));
} }
} }

@ -69,6 +69,8 @@ public interface BtcWalletMapper extends Mapper<BtcWallet> {
*/ */
List<BtcWalletDTO> selectAllByUserOpenId(@Param("userOpenId") String userOpenId, @Param("walletType") String walletType); List<BtcWalletDTO> selectAllByUserOpenId(@Param("userOpenId") String userOpenId, @Param("walletType") String walletType);
List<BtcWalletDTO> selectAll(@Param("userOpenId") String userOpenId);
/** /**
* 用户充值修改钱包金额 * 用户充值修改钱包金额
* *

@ -27,6 +27,14 @@ public interface BtcWalletService {
*/ */
List<BtcWalletDTO> selectAllByUserOpenId(String userOpenId, String walletType); List<BtcWalletDTO> selectAllByUserOpenId(String userOpenId, String walletType);
/**
* 获取用户某应用钱包的所有区块
*
* @param userOpenId 用户id
* @return
*/
List<BtcWalletDTO> selectAllByUserOpenId(String userOpenId);
/** /**
* 获取用户钱包 * 获取用户钱包
* *

@ -91,6 +91,11 @@ public class BtcWalletServiceImpl<psvm> implements BtcWalletService {
return btcWalletMapper.selectAllByUserOpenId(userOpenId, walletType); return btcWalletMapper.selectAllByUserOpenId(userOpenId, walletType);
} }
@Override
public List<BtcWalletDTO> selectAllByUserOpenId(String userOpenId) {
return btcWalletMapper.selectAll(userOpenId);
}
@Override @Override
public BtcWalletDTO selectByUserOpenId(String userOpenId, Integer tokenId, String walletType) { public BtcWalletDTO selectByUserOpenId(String userOpenId, Integer tokenId, String walletType) {
return btcWalletMapper.selectByUserOpenId(userOpenId, tokenId, walletType); return btcWalletMapper.selectByUserOpenId(userOpenId, tokenId, walletType);

@ -30,6 +30,12 @@
WHERE user_open_id = #{userOpenId} AND wallet_type = #{walletType} WHERE user_open_id = #{userOpenId} AND wallet_type = #{walletType}
</select> </select>
<select id="selectAll" resultMap="BtcWalletMap">
SELECT * FROM
<include refid="tableName"/>
WHERE user_open_id = #{userOpenId}
</select>
<select id="selectByAddr" resultMap="BtcWalletMap"> <select id="selectByAddr" resultMap="BtcWalletMap">
SELECT * FROM SELECT * FROM
<include refid="tableName"/> <include refid="tableName"/>

@ -54,10 +54,9 @@ public class EosWalletInnerController {
return ResultDTO.requstSuccess(); return ResultDTO.requstSuccess();
} }
@GetMapping("/selectWalletByWalletType") @GetMapping("/selectWalletByUserOpenId")
public ResultDTO<List<WalletDTO>> selectWalletByWalletType(@RequestParam("userOpenId") String userOpenId, public ResultDTO<List<WalletDTO>> selectWalletByWalletType(@RequestParam("userOpenId") String userOpenId) {
@RequestParam("walletType") String walletType) { return ResultDTO.requstSuccess(eosWalletService.listWalletByUserOpenId(userOpenId));
return ResultDTO.requstSuccess(eosWalletService.listWalletByWalletType(walletType, userOpenId));
} }
} }

@ -35,6 +35,14 @@ public interface WalletMapper extends Mapper<Wallet> {
*/ */
List<WalletDTO> listWalletByWalletType(@Param("walletType") String walletType, @Param("userOpenId") String userOpenId); List<WalletDTO> listWalletByWalletType(@Param("walletType") String walletType, @Param("userOpenId") String userOpenId);
/**
* 根据用户id查询用户钱包
*
* @param userOpenId
* @return
*/
List<WalletDTO> listWalletByUserOpenId(@Param("userOpenId") String userOpenId);
/** /**
* 通过用户id和币种名称和钱包标识查找用户 * 通过用户id和币种名称和钱包标识查找用户
* *

@ -55,6 +55,14 @@ public interface EosWalletService {
*/ */
List<WalletDTO> listWalletByWalletType(String walletType, String userOpenId); List<WalletDTO> listWalletByWalletType(String walletType, String userOpenId);
/**
* 查询钱包
*
* @param userOpenId
* @return
*/
List<WalletDTO> listWalletByUserOpenId(String userOpenId);
/** /**
* 冻结与解冻方法 * 冻结与解冻方法
* *

@ -147,6 +147,12 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction {
return walletMapper.listWalletByWalletType(walletType, userOpenId); return walletMapper.listWalletByWalletType(walletType, userOpenId);
} }
@Override
public List<WalletDTO> listWalletByUserOpenId(String userOpenId) {
ExceptionPreconditionUtils.notEmpty(userOpenId);
return walletMapper.listWalletByUserOpenId(userOpenId);
}
/** /**
* 冻结与解冻方法 * 冻结与解冻方法
* *

@ -52,6 +52,12 @@
and wallet_type = #{walletType} and wallet_type = #{walletType}
</select> </select>
<select id="listWalletByUserOpenId" parameterType="java.lang.String" resultMap="walletMap">
select id, token_name, user_open_id, token_symbol, balance, free_balance, freeze_balance, create_time, update_time, wallet_type
from <include refid="tableName"/>
where user_open_id = #{userOpenId}
</select>
<select id="selectWallet" parameterType="java.lang.String" resultMap="walletMap"> <select id="selectWallet" parameterType="java.lang.String" resultMap="walletMap">
select id, token_name, user_open_id, token_symbol, balance, free_balance, freeze_balance, create_time, update_time, wallet_type select id, token_name, user_open_id, token_symbol, balance, free_balance, freeze_balance, create_time, update_time, wallet_type
from <include refid="tableName"/> from <include refid="tableName"/>

@ -60,9 +60,8 @@ public class EthWalletInner {
} }
@GetMapping("/getWallets") @GetMapping("/getWallets")
public ResultDTO<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId, public ResultDTO<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId) {
@RequestParam(name = "walletType", required = false) String walletType) { return ResultDTO.requstSuccess(ethWalletService.selectByUserOpenId(userId));
return ResultDTO.requstSuccess(ethWalletService.selectByUserOpenIdAndWalletType(userId, walletType));
} }
} }

@ -74,6 +74,14 @@ public interface EthWalletMapper extends Mapper<EthWallet> {
List<EthWalletDTO> selectByUserOpenIdAndWalletType(@Param("userOpenId") String userOpenId, List<EthWalletDTO> selectByUserOpenIdAndWalletType(@Param("userOpenId") String userOpenId,
@Param("walletType") String walletType); @Param("walletType") String walletType);
/**
* 根据用户ID钱包类型查询钱包信息
*
* @param userOpenId 用户ID
* @return
*/
List<EthWalletDTO> selectByUserOpenId(@Param("userOpenId") String userOpenId);
/** /**
* 修改用户指定钱包的金额 * 修改用户指定钱包的金额

@ -101,6 +101,14 @@ public interface IEthWalletService {
*/ */
List<EthWalletDTO> selectByUserOpenIdAndWalletType(String userOpenId, String walletType); List<EthWalletDTO> selectByUserOpenIdAndWalletType(String userOpenId, String walletType);
/**
* 根据用户ID币种地址钱包类型查询钱包信息
*
* @param userOpenId 用户ID
* @return
*/
List<EthWalletDTO> selectByUserOpenId(String userOpenId);
/** /**
* 根据钱包地址币种地址钱包类型查询钱包信息 * 根据钱包地址币种地址钱包类型查询钱包信息
* *

@ -189,6 +189,13 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction {
return list; return list;
} }
@Override
public List<EthWalletDTO> selectByUserOpenId(String userOpenId) {
ExceptionPreconditionUtils.checkStringNotBlank(userOpenId,
new EthWalletException(EthWalletEnums.NULL_USEROPENID));
return ethWalletMapper.selectByUserOpenId(userOpenId);
}
@Override @Override
public List<EthWalletDTO> selectByAddrAndWalletType(String addr, String walletType) { public List<EthWalletDTO> selectByAddrAndWalletType(String addr, String walletType) {
// 数据格式判断 // 数据格式判断

@ -86,6 +86,12 @@
and wallet_type = #{walletType} and wallet_type = #{walletType}
</select> </select>
<select id="selectByUserOpenId" resultMap="EthWalletDTO">
<include refid="selectEthWalletVo"/>
WHERE
user_open_id = #{userOpenId}
</select>
<update id="updateBalanceByUserIdInRowLock"> <update id="updateBalanceByUserIdInRowLock">
UPDATE UPDATE
<include refid="tableName"/> <include refid="tableName"/>

@ -73,6 +73,11 @@
<artifactId>hutool-core</artifactId> <artifactId>hutool-core</artifactId>
<version>5.3.6</version> <version>5.3.6</version>
</dependency> </dependency>
<dependency>
<groupId>com.github.ben-manes.caffeine</groupId>
<artifactId>caffeine</artifactId>
<version>2.8.4</version>
</dependency>
</dependencies> </dependencies>

@ -13,6 +13,5 @@ public interface BtcFeign {
String CONTENT_PATH = "/inner/wallet"; String CONTENT_PATH = "/inner/wallet";
@PostMapping(CONTENT_PATH + "/getWallets") @PostMapping(CONTENT_PATH + "/getWallets")
ResultDTO<List<BtcWalletDTO>> getWallets(@RequestParam("userId") String userId, ResultDTO<List<BtcWalletDTO>> getWallets(@RequestParam("userId") String userId);
@RequestParam("walletType") String walletType);
} }

@ -1,13 +1,13 @@
package com.blockchain.server.yyyf.feign; package com.blockchain.server.yyyf.feign;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.yyyf.feign.dto.CurrencyMarketDTO; import com.blockchain.server.yyyf.feign.dto.CurrencyMarketDTO;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(name = "dapp-currency-server") @FeignClient(name = "dapp-currency-server")
public interface CurrencyFeign { public interface CurrencyFeign {
@GetMapping("/inner/market/getList") @GetMapping("/inner/market/getList")
ResultDTO<CurrencyMarketDTO> getList(@RequestParam("currencyPair") String currencyPair); List<CurrencyMarketDTO> getList();
} }

@ -9,6 +9,6 @@ import java.util.List;
@FeignClient("dapp-eos-server") @FeignClient("dapp-eos-server")
public interface EosFeign { public interface EosFeign {
@GetMapping("/inner/walletTx/selectWalletByWalletType") @GetMapping("/inner/walletTx/selectWalletByUserOpenId")
ResultDTO<List<EosWalletDTO>> selectWalletByWalletType(String userOpenId, String walletType); ResultDTO<List<EosWalletDTO>> selectWalletByWalletType(String userOpenId);
} }

@ -12,8 +12,7 @@ import java.util.List;
@FeignClient("dapp-eth-server") @FeignClient("dapp-eth-server")
public interface EthFeign { public interface EthFeign {
@GetMapping("/inner/wallet/getWallets") @GetMapping("/inner/wallet/getWallets")
ResultDTO<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId, ResultDTO<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId);
@RequestParam(name = "walletType") String walletType);
@GetMapping("/inner/walletParam/getGasConfig") @GetMapping("/inner/walletParam/getGasConfig")
ResultDTO<GasDTO> getGasConfig(String tokenSymbol); ResultDTO<GasDTO> getGasConfig(String tokenSymbol);

@ -1,11 +1,24 @@
package com.blockchain.server.yyyf.indicators; package com.blockchain.server.yyyf.indicators;
import cn.hutool.core.map.MapUtil; import cn.hutool.core.map.MapUtil;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.yyyf.dto.UserTimeMoneyDto; import com.blockchain.server.yyyf.dto.UserTimeMoneyDto;
import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.AssessUserTarget;
import com.blockchain.server.yyyf.feign.BtcFeign;
import com.blockchain.server.yyyf.feign.CurrencyFeign;
import com.blockchain.server.yyyf.feign.EosFeign;
import com.blockchain.server.yyyf.feign.EthFeign;
import com.blockchain.server.yyyf.feign.dto.BtcWalletDTO;
import com.blockchain.server.yyyf.feign.dto.CurrencyMarketDTO;
import com.blockchain.server.yyyf.feign.dto.EosWalletDTO;
import com.blockchain.server.yyyf.feign.dto.EthWalletDTO;
import com.blockchain.server.yyyf.indicators.dto.AppTypeEnum;
import com.blockchain.server.yyyf.indicators.dto.CurrencyEnum;
import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum; import com.blockchain.server.yyyf.indicators.dto.IndicatorsTypeEnum;
import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserMapper;
import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper;
import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -13,6 +26,11 @@ import org.springframework.stereotype.Service;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static cn.hutool.core.util.NumberUtil.add;
import static cn.hutool.core.util.NumberUtil.mul;
/** /**
* @author fengyu * @author fengyu
@ -23,6 +41,16 @@ public class DefaultIndicatorsManager implements IndicatorsManager {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final AssessUserTargetMapper assessUserTargetMapper; private final AssessUserTargetMapper assessUserTargetMapper;
private final AssessUserMapper assessUserMapper; private final AssessUserMapper assessUserMapper;
private final BtcFeign btcFeign;
private final EosFeign eosFeign;
private final EthFeign ethFeign;
private final CurrencyFeign currencyFeign;
private static final String CURRENCY_CACHE_KEY = "currency";
private static final Cache<String, List<CurrencyMarketDTO>> CURRENCY_MARKET_CACHE = Caffeine.newBuilder()
.expireAfterWrite(1, TimeUnit.HOURS)
.maximumSize(5)
.build();
@Override @Override
public Map<String, Float> calculatePageIndicators(String assessUserId) { public Map<String, Float> calculatePageIndicators(String assessUserId) {
@ -37,17 +65,70 @@ public class DefaultIndicatorsManager implements IndicatorsManager {
@Override @Override
public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) { public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) {
//feign interface call //币币总资产 + 法币总资产 + 冻结资金
List<CurrencyMarketDTO> currencyMarketDto = CURRENCY_MARKET_CACHE.get(CURRENCY_CACHE_KEY, t -> currencyFeign.getList());
assert currencyMarketDto != null;
Map<String, BigDecimal> currencyPairMap = currencyMarketDto.stream()
.collect(Collectors.toMap(CurrencyMarketDTO::getCurrencyPair, CurrencyMarketDTO::getAmount));
BigDecimal currencyAssets = getAssetsByUserId(userId, currencyPairMap);
//数字钱包
UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId); UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId);
BigDecimal digitalAssets = getDigitalAssets(timeMoneyDto, currencyPairMap);
//初始资产剩余资产 单位RMB
BigDecimal remainingAssets = getRemainingAssets(timeMoneyDto);
//计算总资产 转换成RMB
Double rmbRate = currencyMarketDto.stream().filter(dto -> dto.getCurrencyPair().equals(CurrencyEnum.BTC_USDT.getCode())).map(CurrencyMarketDTO::getCnyAmount).findFirst().orElse(7.0);
return add(mul(add(currencyAssets, digitalAssets), rmbRate), remainingAssets);
}
private BigDecimal getRemainingAssets(UserTimeMoneyDto timeMoneyDto) {
return add(timeMoneyDto.getAliPay(), timeMoneyDto.getWxPay(), timeMoneyDto.getBankCard());
}
private BigDecimal getDigitalAssets(UserTimeMoneyDto timeMoneyDto, Map<String, BigDecimal> currencyPairMap) {
BigDecimal btcMoney = mul(timeMoneyDto.getBtc(), currencyPairMap.get(CurrencyEnum.BTC_USDT.getCode()));
BigDecimal usdtMoney = timeMoneyDto.getUsdt();
BigDecimal eosMoney = mul(timeMoneyDto.getEos(), currencyPairMap.get(CurrencyEnum.EOS_USDT.getCode()));
BigDecimal ethMoney = mul(timeMoneyDto.getEth(), currencyPairMap.get(CurrencyEnum.ETH_USDT.getCode()));
return add(btcMoney, usdtMoney, eosMoney, ethMoney);
}
//1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金 private BigDecimal getAssetsByUserId(String userId, Map<String, BigDecimal> currencyPairMap) {
//cache rate ResultDTO<List<BtcWalletDTO>> btcWallets = btcFeign.getWallets(userId);
//2.计算总资产 转换成RMB ResultDTO<List<EthWalletDTO>> ethWallets = ethFeign.getWallets(userId);
//cache RMB rate ResultDTO<List<EosWalletDTO>> eosWallets = eosFeign.selectWalletByWalletType(userId);
return null; BigDecimal c2cAssets = getAssetsByType(AppTypeEnum.C2C, currencyPairMap, btcWallets.getData(), ethWallets.getData(), eosWallets.getData());
BigDecimal cctAssets = getAssetsByType(AppTypeEnum.CCT, currencyPairMap, btcWallets.getData(), ethWallets.getData(), eosWallets.getData());
return add(c2cAssets, cctAssets);
} }
private BigDecimal getAssetsByType(AppTypeEnum appType, Map<String, BigDecimal> currencyPairMap,
List<BtcWalletDTO> btcWallets, List<EthWalletDTO> ethWallets,
List<EosWalletDTO> eosWallets) {
//BTC
Map<String, BigDecimal> btcBalanceMap = btcWallets.stream()
.filter(dto -> dto.getWalletType().equals(appType.name()))
.collect(Collectors.toMap(BtcWalletDTO::getTokenSymbol, dto -> BigDecimal.valueOf(dto.getBalance() + dto.getFreezeBalance())));
BigDecimal btcAmount = currencyPairMap.get(CurrencyEnum.BTC_USDT.getCode());
BigDecimal btcPrice = mul(btcAmount, btcBalanceMap.get(CurrencyEnum.BTC.getCode()));
//USDT
BigDecimal usdtPrice = btcBalanceMap.get(CurrencyEnum.USDT.getCode());
//ETH
Map<String, BigDecimal> ethBalanceMap = ethWallets.stream()
.filter(dto -> dto.getWalletType().equals(appType.name()))
.collect(Collectors.toMap(EthWalletDTO::getTokenSymbol, dto -> BigDecimal.valueOf(Double.parseDouble(dto.getBalance()) + Double.parseDouble(dto.getFreezeBalance()))));
BigDecimal ethAmount = currencyPairMap.get(CurrencyEnum.ETH_USDT.getCode());
BigDecimal ethPrice = mul(ethAmount, ethBalanceMap.get(CurrencyEnum.ETH.getCode()));
//EOS
Map<String, BigDecimal> eosBalanceMap = eosWallets.stream()
.filter(dto -> dto.getWalletType().equals(appType.name()))
.collect(Collectors.toMap(EosWalletDTO::getTokenSymbol, dto -> add(dto.getBalance(), dto.getFreezeBalance())));
BigDecimal eosAmount = currencyPairMap.get(CurrencyEnum.EOS_USDT.getCode());
BigDecimal eosPrice = mul(eosAmount, eosBalanceMap.get(CurrencyEnum.EOS.getCode()));
return add(btcPrice, usdtPrice, ethPrice, eosPrice);
}
/** /**
* calculate single indicator * calculate single indicator
@ -62,4 +143,5 @@ public class DefaultIndicatorsManager implements IndicatorsManager {
IndicatorsHandler indicatorsHandler = applicationContext.getBean(type.getCode(), IndicatorsHandler.class); IndicatorsHandler indicatorsHandler = applicationContext.getBean(type.getCode(), IndicatorsHandler.class);
return indicatorsHandler.handleIndicator(assessUserId); return indicatorsHandler.handleIndicator(assessUserId);
} }
} }

@ -0,0 +1,12 @@
package com.blockchain.server.yyyf.indicators.dto;
/**
* @author fengyu
*/
public enum AppTypeEnum {
/*法币交易*/
C2C,
/*币币交易*/
CCT
}

@ -0,0 +1,24 @@
package com.blockchain.server.yyyf.indicators.dto;
import lombok.Getter;
/**
* @author fengyu
*/
public enum CurrencyEnum {
/*btc*/
BTC("BTC"),
ETH("ETH"),
EOS("EOS"),
USDT("USDT"),
BTC_USDT("BTC-USDT"),
ETH_USDT("ETH-USDT"),
EOS_USDT("EOS-USDT");
@Getter
private final String code;
CurrencyEnum(String code) {
this.code = code;
}
}

@ -23,9 +23,7 @@ public enum IndicatorsTypeEnum {
MAX_DRAWDOWN_RATE("MaxDrawdownRate"), MAX_DRAWDOWN_RATE("MaxDrawdownRate"),
/*最大亏损率*/ /*最大亏损率*/
MAX_LOSS_RATE("MaxLossRate"), MAX_LOSS_RATE("MaxLossRate"),
/*风险率(资产负债比)*/ /*Total Value to Paid-in Capital*/
ASSET_LIABILITY_RISK_RATE("AssetLiabilityRiskRate"),
/*TVPI*/
TVPI("TVPI"); TVPI("TVPI");
@Getter @Getter

@ -1,17 +0,0 @@
package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import org.springframework.stereotype.Component;
/**
* @author fengyu
*/
@Component(AssetLiabilityRiskRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME)
public class AssetLiabilityRiskRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "AssetLiabilityRiskRate";
@Override
public Float handleIndicator(String assessUserId) {
return null;
}
}

@ -1,9 +1,12 @@
package com.blockchain.server.yyyf.indicators.handle; package com.blockchain.server.yyyf.indicators.handle;
import com.blockchain.server.yyyf.dto.UserTimeMoneyDto;
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; import com.blockchain.server.yyyf.indicators.IndicatorsHandler;
import com.blockchain.server.yyyf.indicators.IndicatorsUtils; import com.blockchain.server.yyyf.indicators.IndicatorsUtils;
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; import com.blockchain.server.yyyf.indicators.dto.AssetsReporter;
import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto; import com.blockchain.server.yyyf.indicators.dto.LastAndFirstAssetsDto;
import com.blockchain.server.yyyf.mapper.AssessUserMapper;
import com.blockchain.server.yyyf.service.AssessUserService;
import com.blockchain.server.yyyf.service.AssetsReporterService; import com.blockchain.server.yyyf.service.AssetsReporterService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -11,6 +14,8 @@ import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
import static cn.hutool.core.util.NumberUtil.add;
/** /**
* @author fengyu * @author fengyu
*/ */
@ -20,6 +25,8 @@ public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler {
public static final String HANDLER_NAME = "TotalGrowthRate"; public static final String HANDLER_NAME = "TotalGrowthRate";
private final AssetsReporterService assetsReporterService; private final AssetsReporterService assetsReporterService;
private final AssessUserService assessUserService;
private final AssessUserMapper assessUserMapper;
@Override @Override
public Float handleIndicator(String assessUserId) { public Float handleIndicator(String assessUserId) {
@ -31,8 +38,10 @@ public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler {
AssetsReporter firstAssets = lastAndFirstAssetsDto.getFirstAssets(); AssetsReporter firstAssets = lastAndFirstAssetsDto.getFirstAssets();
//充值的总金额 //充值的总金额
//todo 不知道如何获取 List<UserTimeMoneyDto> userTimeMoneyList = assessUserService.selectUserTimeMoneyDtosForNotEnd();
BigDecimal rechargeAmount=null; String sysUserId = userTimeMoneyList.stream().filter(dto -> dto.getAssessUserId().equals(assessUserId)).findFirst().map(UserTimeMoneyDto::getQUserId).get();
UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, sysUserId);
BigDecimal rechargeAmount = add(timeMoneyDto.getAliPayInit(), timeMoneyDto.getWxPayInit(), timeMoneyDto.getBankCardInit());
return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(rechargeAmount, 4, BigDecimal.ROUND_HALF_UP) return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(rechargeAmount, 4, BigDecimal.ROUND_HALF_UP)
.multiply(BigDecimal.valueOf(100)).floatValue(); .multiply(BigDecimal.valueOf(100)).floatValue();

Loading…
Cancel
Save