From 2333adaf8f7544fffe155353d7fd43da361e0462 Mon Sep 17 00:00:00 2001 From: "fengyu.wang" Date: Sat, 6 Jun 2020 23:06:19 +0800 Subject: [PATCH] feign api support --- .../eth/inner/ConfigWalletParamInner.java | 24 +++++++++++++ .../server/eth/inner/EthWalletInner.java | 17 +++++---- .../server/yyyf/feign/BtcFeign.java | 18 ++++++++++ .../server/yyyf/feign/CurrencyFeign.java | 13 +++++++ .../server/yyyf/feign/EosFeign.java | 14 ++++++++ .../server/yyyf/feign/EthFeign.java | 20 +++++++++++ .../server/yyyf/feign/dto/BtcWalletDTO.java | 29 +++++++++++++++ .../yyyf/feign/dto/CurrencyMarketDTO.java | 36 +++++++++++++++++++ .../server/yyyf/feign/dto/EosWalletDTO.java | 29 +++++++++++++++ .../server/yyyf/feign/dto/EthWalletDTO.java | 24 +++++++++++++ .../indicators/DefaultIndicatorsManager.java | 7 +++- .../yyyf/indicators/IndicatorsManager.java | 3 +- .../server/yyyf/mapper/AssessUserMapper.java | 4 ++- .../impl/AssetsReporterServiceImpl.java | 1 + .../server/yyyf/task/ExamProcessTask.java | 2 +- .../resources/mapper/AssessUserMapper.xml | 5 +++ 16 files changed, 233 insertions(+), 13 deletions(-) create mode 100644 blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java create mode 100644 blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java diff --git a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java new file mode 100644 index 0000000..c71e679 --- /dev/null +++ b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/ConfigWalletParamInner.java @@ -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 getGasConfig(@RequestParam(value = "tokenSymbol", defaultValue = EthConfigConstants.MODULE_TYPE) String tokenSymbol) { + return ResultDTO.requstSuccess(walletParamService.getGasConfig(tokenSymbol)); + } + +} diff --git a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java index 233af76..672dda1 100644 --- a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java +++ b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/inner/EthWalletInner.java @@ -1,13 +1,9 @@ package com.blockchain.server.eth.inner; import com.blockchain.common.base.dto.ResultDTO; -import com.blockchain.common.base.dto.SessionUserDTO; import com.blockchain.common.base.util.SSOHelper; -import com.blockchain.server.eth.common.enums.EthWalletEnums; -import com.blockchain.server.eth.common.exception.EthWalletException; -import com.blockchain.server.eth.common.util.RedisPrivateUtil; +import com.blockchain.server.eth.dto.EthWalletDTO; import com.blockchain.server.eth.inner.api.EthWalletApi; -import com.blockchain.server.eth.service.IEthWalletKeyService; import com.blockchain.server.eth.service.IEthWalletService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -16,10 +12,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; 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 java.util.Date; +import java.util.List; /** * @author YH @@ -61,8 +60,8 @@ public class EthWalletInner { } @GetMapping("/getWallets") - public ResultDTO getWallets(@RequestParam("userId") String userId, - @RequestParam(name = "walletType", required = false) String walletType) { + public ResultDTO> getWallets(@RequestParam("userId") String userId, + @RequestParam(name = "walletType", required = false) String walletType) { return ResultDTO.requstSuccess(ethWalletService.selectByUserOpenIdAndWalletType(userId, walletType)); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java new file mode 100644 index 0000000..6a9e3b2 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/BtcFeign.java @@ -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> getWallets(@RequestParam("userId") String userId, + @RequestParam("walletType") String walletType); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java new file mode 100644 index 0000000..c631a0c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/CurrencyFeign.java @@ -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 getList(@RequestParam("currencyPair") String currencyPair); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java new file mode 100644 index 0000000..e29f7c3 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EosFeign.java @@ -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> selectWalletByWalletType(String userOpenId, String walletType); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java new file mode 100644 index 0000000..3fff3ae --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/EthFeign.java @@ -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> getWallets(@RequestParam("userId") String userId, + @RequestParam(name = "walletType") String walletType); + + @GetMapping("/inner/walletParam/getGasConfig") + ResultDTO getGasConfig(String tokenSymbol); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java new file mode 100644 index 0000000..3a8322c --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/BtcWalletDTO.java @@ -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; + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java new file mode 100644 index 0000000..04501e7 --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/CurrencyMarketDTO.java @@ -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 { + + 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); + } +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java new file mode 100644 index 0000000..1826a8a --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EosWalletDTO.java @@ -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; + +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java new file mode 100644 index 0000000..542fdeb --- /dev/null +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/feign/dto/EthWalletDTO.java @@ -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; +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java index a212e4d..a20f726 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/DefaultIndicatorsManager.java @@ -1,8 +1,10 @@ package com.blockchain.server.yyyf.indicators; 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.indicators.dto.IndicatorsTypeEnum; +import com.blockchain.server.yyyf.mapper.AssessUserMapper; import com.blockchain.server.yyyf.mapper.AssessUserTargetMapper; import lombok.AllArgsConstructor; import org.springframework.context.ApplicationContext; @@ -20,6 +22,7 @@ import java.util.Map; public class DefaultIndicatorsManager implements IndicatorsManager { private final ApplicationContext applicationContext; private final AssessUserTargetMapper assessUserTargetMapper; + private final AssessUserMapper assessUserMapper; @Override public Map calculatePageIndicators(String assessUserId) { @@ -33,8 +36,10 @@ public class DefaultIndicatorsManager implements IndicatorsManager { } @Override - public BigDecimal calculateCurrentTotalAssets(String userId) { + public BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId) { //feign interface call + UserTimeMoneyDto timeMoneyDto = assessUserMapper.selectCurrentUserTimeMoneyDto(assessUserId, userId); + //1.获取 币币总资产 + 法币总资产 + 数字钱包 + 初始资产 + 挂单资金 //cache rate diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java index 8fbc58c..ab676ac 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/indicators/IndicatorsManager.java @@ -22,9 +22,10 @@ public interface IndicatorsManager { * calculate current total asset * * @param userId system user id + * @param assessUserId page result id * @return current total assets (RMB) * @author fengyu.wang * @date 2020-06-02 20:15:15 */ - BigDecimal calculateCurrentTotalAssets(String userId); + BigDecimal calculateCurrentTotalAssets(String userId, String assessUserId); } diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java index 3f6e8bc..b6cf679 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/mapper/AssessUserMapper.java @@ -50,4 +50,6 @@ public interface AssessUserMapper extends Mapper { * @return com.blockchain.server.yyyf.dto.UserTimeMoneyDto **/ UserTimeMoneyDto getUserTimeMoneyDtoByAssessUserId(@Param("assessUserId") String assessUserId); -} \ No newline at end of file + + UserTimeMoneyDto selectCurrentUserTimeMoneyDto(@Param("assessUserId") String assessUserId, @Param("qUserId")String qUserId); +} diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java index 25d895c..cf6b2c1 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/service/impl/AssetsReporterServiceImpl.java @@ -25,6 +25,7 @@ public class AssetsReporterServiceImpl implements AssetsReporterService { @Override public void saveList(List assetsReporterList) { + //TODO Transaction rollback, retry, log assetsReporterList.forEach(assetsReporter -> Optional.ofNullable(cacheManager.getCache(CACHE_ASSETS_REPORTER)) .ifPresent(cache -> cache.evict(CACHE_KEY_ASSETS_REPORTER.concat(assetsReporter.getAssessUserId())))); diff --git a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java index de72902..6ddae80 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java +++ b/blockchain-server/blockchain-server-yyyf/src/main/java/com/blockchain/server/yyyf/task/ExamProcessTask.java @@ -36,7 +36,7 @@ public class ExamProcessTask { List assetsReporterList = new ArrayList<>(userTimeMoneyList.size()); DateTime now = DateUtil.date(); userTimeMoneyList.forEach(entity -> { - BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId()); + BigDecimal assets = indicatorsManager.calculateCurrentTotalAssets(entity.getQUserId(), entity.getAssessUserId()); assetsReporterList.add(AssetsReporter.builder() .id(IdGenerator.uuid()) .assessUserId(entity.getAssessUserId()) diff --git a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml index b45903d..5ca4b33 100644 --- a/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml +++ b/blockchain-server/blockchain-server-yyyf/src/main/resources/mapper/AssessUserMapper.xml @@ -125,5 +125,10 @@ from yyyf_server_assess_user au,yyyf_money m where au.id=m.assess_user_id and au.id=#{assessUserId} +