feign api support

pull/1/head
fengyu.wang 5 years ago
parent dc0e7f543d
commit 2333adaf8f
  1. 24
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java
  2. 17
      blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java
  3. 18
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java
  4. 13
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java
  5. 14
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java
  6. 20
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java
  7. 29
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java
  8. 36
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java
  9. 29
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java
  10. 24
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java
  11. 7
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java
  12. 3
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java
  13. 2
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java
  14. 1
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java
  15. 2
      blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java
  16. 5
      blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml

@ -0,0 +1,24 @@
package com.blockchain.server.eth.inner;
import com.blockchain.common.base.dto.GasDTO;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.eth.common.constants.EthConfigConstants;
import com.blockchain.server.eth.service.IConfigWalletParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/inner/walletParam")
public class ConfigWalletParamInner {
@Autowired
private IConfigWalletParamService walletParamService;
@GetMapping("/getGasConfig")
public ResultDTO<GasDTO> getGasConfig(@RequestParam(value = "tokenSymbol", defaultValue = EthConfigConstants.MODULE_TYPE) String tokenSymbol) {
return ResultDTO.requstSuccess(walletParamService.getGasConfig(tokenSymbol));
}
}

@ -1,13 +1,9 @@
package com.blockchain.server.eth.inner; package com.blockchain.server.eth.inner;
import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.common.base.dto.SessionUserDTO;
import com.blockchain.common.base.util.SSOHelper; import com.blockchain.common.base.util.SSOHelper;
import com.blockchain.server.eth.common.enums.EthWalletEnums; import com.blockchain.server.eth.dto.EthWalletDTO;
import com.blockchain.server.eth.common.exception.EthWalletException;
import com.blockchain.server.eth.common.util.RedisPrivateUtil;
import com.blockchain.server.eth.inner.api.EthWalletApi; import com.blockchain.server.eth.inner.api.EthWalletApi;
import com.blockchain.server.eth.service.IEthWalletKeyService;
import com.blockchain.server.eth.service.IEthWalletService; import com.blockchain.server.eth.service.IEthWalletService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@ -16,10 +12,13 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date; import java.util.List;
/** /**
* @author YH * @author YH
@ -61,8 +60,8 @@ public class EthWalletInner {
} }
@GetMapping("/getWallets") @GetMapping("/getWallets")
public ResultDTO getWallets(@RequestParam("userId") String userId, public ResultDTO<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId,
@RequestParam(name = "walletType", required = false) String walletType) { @RequestParam(name = "walletType", required = false) String walletType) {
return ResultDTO.requstSuccess(ethWalletService.selectByUserOpenIdAndWalletType(userId, walletType)); return ResultDTO.requstSuccess(ethWalletService.selectByUserOpenIdAndWalletType(userId, walletType));
} }

@ -0,0 +1,18 @@
package com.blockchain.server.yyyf.feign;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.yyyf.feign.dto.BtcWalletDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient("dapp-btc-server")
public interface BtcFeign {
String CONTENT_PATH = "/inner/wallet";
@PostMapping(CONTENT_PATH + "/getWallets")
ResultDTO<List<BtcWalletDTO>> getWallets(@RequestParam("userId") String userId,
@RequestParam("walletType") String walletType);
}

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

@ -0,0 +1,14 @@
package com.blockchain.server.yyyf.feign;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.yyyf.feign.dto.EosWalletDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List;
@FeignClient("dapp-eos-server")
public interface EosFeign {
@GetMapping("/inner/walletTx/selectWalletByWalletType")
ResultDTO<List<EosWalletDTO>> selectWalletByWalletType(String userOpenId, String walletType);
}

@ -0,0 +1,20 @@
package com.blockchain.server.yyyf.feign;
import com.blockchain.common.base.dto.GasDTO;
import com.blockchain.common.base.dto.ResultDTO;
import com.blockchain.server.yyyf.feign.dto.EthWalletDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient("dapp-eth-server")
public interface EthFeign {
@GetMapping("/inner/wallet/getWallets")
ResultDTO<List<EthWalletDTO>> getWallets(@RequestParam("userId") String userId,
@RequestParam(name = "walletType") String walletType);
@GetMapping("/inner/walletParam/getGasConfig")
ResultDTO<GasDTO> getGasConfig(String tokenSymbol);
}

@ -0,0 +1,29 @@
package com.blockchain.server.yyyf.feign.dto;
import com.blockchain.common.base.entity.BaseModel;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* BtcWalletDTO 数据传输类
*
* @version 1.0
* @date 2019-02-16 15:08:16
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BtcWalletDTO extends BaseModel {
private String addr;
private Integer tokenId;
private String userOpenId;
private String tokenSymbol;
private Double balance;
private Double freeBalance;
private Double freezeBalance;
private java.util.Date createTime;
private java.util.Date updateTime;
private String walletType;
}

@ -0,0 +1,36 @@
package com.blockchain.server.yyyf.feign.dto;
import com.blockchain.common.base.dto.BaseDTO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CurrencyMarketDTO extends BaseDTO implements Comparable<CurrencyMarketDTO> {
private String currencyPair;
private BigDecimal amount;
private Long timestamp;
private float percent;
private double usdAmount;
private double cnyAmount;
private double hkdAmount;
private double eurAmount;
//最低
private BigDecimal lowest;
//最高
private BigDecimal highest;
//开盘
private BigDecimal open;
//成交量
private BigDecimal total;
@Override
public int compareTo(CurrencyMarketDTO o) {
return (int) (10000 * o.percent - 10000 * this.percent);
}
}

@ -0,0 +1,29 @@
package com.blockchain.server.yyyf.feign.dto;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.math.BigDecimal;
/**
* Wallet 数据传输类
* @date 2018-11-05 15:10:47
* @version 1.0
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class EosWalletDTO {
private Integer id;
private String tokenName;
private String userOpenId;
private String tokenSymbol;
private BigDecimal balance;
private BigDecimal freeBalance;
private BigDecimal freezeBalance;
private java.util.Date createTime;
private java.util.Date updateTime;
private String walletType;
}

@ -0,0 +1,24 @@
package com.blockchain.server.yyyf.feign.dto;
import lombok.Data;
/**
* EthWallet 数据传输类
*
* @version 1.0
* @date 2019-02-16 15:44:06
*/
@Data
public class EthWalletDTO {
private String addr;
private String tokenAddr;
private String userOpenId;
private String tokenSymbol;
private int tokenDecimals;
private String balance;
private String freeBalance;
private String freezeBalance;
private String walletType;
private java.util.Date createTime;
private java.util.Date updateTime;
}

@ -1,8 +1,10 @@
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.server.yyyf.dto.UserTimeMoneyDto;
import com.blockchain.server.yyyf.entity.AssessUserTarget; import com.blockchain.server.yyyf.entity.AssessUserTarget;
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.AssessUserTargetMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -20,6 +22,7 @@ import java.util.Map;
public class DefaultIndicatorsManager implements IndicatorsManager { 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;
@Override @Override
public Map<String, Float> calculatePageIndicators(String assessUserId) { public Map<String, Float> calculatePageIndicators(String assessUserId) {
@ -33,8 +36,10 @@ public class DefaultIndicatorsManager implements IndicatorsManager {
} }
@Override @Override
public BigDecimal calculateCurrentTotalAssets(String userId) { public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) {
//feign interface call //feign interface call
UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId);
//1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金 //1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金
//cache rate //cache rate

@ -22,9 +22,10 @@ public interface IndicatorsManager {
* calculate current total asset * calculate current total asset
* *
* @param userId system user id * @param userId system user id
* @param assessUserId page result id
* @return current total assets (RMB) * @return current total assets (RMB)
* @author fengyu.wang * @author fengyu.wang
* @date 2020-06-02 20:15:15 * @date 2020-06-02 20:15:15
*/ */
BigDecimal calculateCurrentTotalAssets(String userId); BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId);
} }

@ -50,4 +50,6 @@ public interface AssessUserMapper extends Mapper<AssessUser> {
* @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto * @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto
**/ **/
UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(@Param("assessUserId") String assessUserId); UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(@Param("assessUserId") String assessUserId);
UserTimeMoneyDto selectCurrentUserTimeMoneyDto(@Param("assessUserId") String assessUserId, @Param("qUserId")String qUserId);
} }

@ -25,6 +25,7 @@ public class AssetsReporterServiceImpl implements AssetsReporterService {
@Override @Override
public void saveList(List<AssetsReporter> assetsReporterList) { public void saveList(List<AssetsReporter> assetsReporterList) {
//TODO Transaction rollback, retry, log
assetsReporterList.forEach(assetsReporter -> assetsReporterList.forEach(assetsReporter ->
Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER)) Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER))
.ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId())))); .ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId()))));

@ -36,7 +36,7 @@ public class ExamProcessTask {
List<AssetsReporter> assetsReporterList = new ArrayList<>(userTimeMoneyList.size()); List<AssetsReporter> assetsReporterList = new ArrayList<>(userTimeMoneyList.size());
DateTime now = DateUtil.date(); DateTime now = DateUtil.date();
userTimeMoneyList.forEach(entity -> { userTimeMoneyList.forEach(entity -> {
BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId(), entity.getAssessUserId());
assetsReporterList.add(AssetsReporter.builder() assetsReporterList.add(AssetsReporter.builder()
.id(IdGenerator.uuid()) .id(IdGenerator.uuid())
.assessUserId(entity.getAssessUserId()) .assessUserId(entity.getAssessUserId())

@ -125,5 +125,10 @@
from yyyf_server_assess_user au,yyyf_money m from yyyf_server_assess_user au,yyyf_money m
where au.id=m.assess_user_id and au.id=#{assessUserId} where au.id=m.assess_user_id and au.id=#{assessUserId}
</select> </select>
<select id="selectCurrentUserTimeMoneyDto" resultMap="UserTimeMoneyDtoMap">
SELECT au.id,au.user_id,au.q_user_id,au.alipay_init_money,au.wechat_init_money,au.bankcard_init_money,au.start_time,m.wx_pay,m.ali_pay,m.bank_card,m.btc,m.eth,m.usdt,m.eos
from yyyf_server_assess_user au,yyyf_money m
where au.id=m.assess_user_id and au.q_user_id=#{qUserId} and au.id={assessUserId}
</select>
</mapper> </mapper>

Loading…
Cancel
Save