diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletController.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletController.java index 7e3ac04..e798914 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletController.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletController.java @@ -4,6 +4,7 @@ import com.blockchain.common.base.dto.ResultDTO; import com.blockchain.common.base.util.SSOHelper; import com.blockchain.server.btc.common.constants.BtcApplicationConstans; import com.blockchain.server.btc.controller.api.BtcWalletApi; +import com.blockchain.server.btc.controller.api.BtcWalletTransferApi; import com.blockchain.server.btc.service.BtcWalletService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; @@ -51,4 +52,15 @@ public class BtcWalletController { String userOpenId = SSOHelper.getUserId(redisTemplate, request); return ResultDTO.requstSuccess(btcWalletService.handleTransfer(userOpenId,fromType, toType, coinName, amount)); } + + + @ApiOperation(value = BtcWalletApi.ResetWallet.METHOD_API_NAME, notes = BtcWalletApi.ResetWallet.METHOD_API_NOTE) + @PostMapping("/resetWallet") + public ResultDTO resetWallet(HttpServletRequest request, + @ApiParam(BtcWalletApi.ResetWallet.TOADDR) @RequestParam("addr") String addr, + @ApiParam(BtcWalletApi.ResetWallet.TOKENID) @RequestParam("tokenId") String tokenId, + @ApiParam(BtcWalletApi.ResetWallet.WALLET_TYPE) @RequestParam(value = "walletType", defaultValue = BtcApplicationConstans.TYPE_CCT) String walletType) { + String userOpenId = SSOHelper.getUserId(redisTemplate, request); + return ResultDTO.requstSuccess(btcWalletService.resetWallet(userOpenId, addr, tokenId, walletType)); + } } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletTransferController.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletTransferController.java index e23897b..dbceca4 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletTransferController.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/BtcWalletTransferController.java @@ -69,14 +69,5 @@ public class BtcWalletTransferController extends BaseController { return ResultDTO.requstSuccess(btcWalletTransferService.handleWithdraw(userOpenId, password, toAddr, tokenId, amount, walletType)); } - @ApiOperation(value = BtcWalletTransferApi.ResetWallet.METHOD_API_NAME, notes = BtcWalletTransferApi.ResetWallet.METHOD_API_NOTE) - @PostMapping("/resetWallet") - public ResultDTO resetWallet(HttpServletRequest request, - @ApiParam(BtcWalletTransferApi.ResetWallet.TOADDR) @RequestParam("addr") String addr, - @ApiParam(BtcWalletTransferApi.ResetWallet.TOKENID) @RequestParam("tokenId") Integer tokenId, - @ApiParam(BtcWalletTransferApi.ResetWallet.WALLET_TYPE) @RequestParam(value = "walletType", defaultValue = BtcApplicationConstans.TYPE_CCT) String walletType) { - String userOpenId = SSOHelper.getUserId(redisTemplate, request); - return ResultDTO.requstSuccess(btcWalletTransferService.resetWallet(userOpenId, addr, tokenId, walletType)); - } } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletApi.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletApi.java index ac89a05..2229abf 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletApi.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletApi.java @@ -26,4 +26,14 @@ public class BtcWalletApi { public static final String METHOD_API_COINNAME = "划转币种的名称"; public static final String METHOD_API_AMOUNT = "金额"; } + + public static class ResetWallet { + public static final String METHOD_API_NAME = "充值"; + public static final String METHOD_API_NOTE = "充值"; + public static final String TOKENID = "币种id"; + public static final String WALLET_TYPE = "应用类型"; + public static final String TOADDR = "接收地址"; + public static final String AMOUNT = "提现数量"; + public static final String PASSWORD = "加密密码"; + } } diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletTransferApi.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletTransferApi.java index f7911df..cab2f28 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletTransferApi.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/controller/api/BtcWalletTransferApi.java @@ -29,14 +29,5 @@ public class BtcWalletTransferApi { public static final String AMOUNT = "提现数量"; public static final String PASSWORD = "加密密码"; } - public static class ResetWallet { - public static final String METHOD_API_NAME = "充值"; - public static final String METHOD_API_NOTE = "充值"; - public static final String TOKENID = "币种id"; - public static final String WALLET_TYPE = "应用类型"; - public static final String TOADDR = "接收地址"; - public static final String AMOUNT = "提现数量"; - public static final String PASSWORD = "加密密码"; - } } diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/mapper/BtcWalletMapper.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/mapper/BtcWalletMapper.java index 72a7b9d..ba8fb75 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/mapper/BtcWalletMapper.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/mapper/BtcWalletMapper.java @@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param; import org.springframework.stereotype.Repository; import tk.mybatis.mapper.common.Mapper; +import java.math.BigDecimal; import java.util.Date; import java.util.List; import java.util.Set; @@ -67,4 +68,14 @@ public interface BtcWalletMapper extends Mapper { * @return */ List selectAllByUserOpenId(@Param("userOpenId") String userOpenId, @Param("walletType") String walletType); + + /** + * 用户充值修改钱包金额 + * + */ + int updateWalletBalanceByUserOpenId(@Param("balance") BigDecimal balance, + @Param("userOpenId") String userOpenId, + @Param("tokenSymbol") String tokenSymbol, + @Param("walletType") String walletType, + @Param("modifyTime") Date modifyTime); } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletService.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletService.java index 15e970c..db4a62a 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletService.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletService.java @@ -102,4 +102,6 @@ public interface BtcWalletService { * @return */ BtcWalletTransfer handleTransfer(String userId, String fromType, String toType, String coinName, Double amount); + + int resetWallet(String userOpenId, String addr, String tokenId, String walletType); } diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletTransferService.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletTransferService.java index 5b0c1f7..1c584bf 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletTransferService.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/BtcWalletTransferService.java @@ -101,6 +101,4 @@ public interface BtcWalletTransferService { */ void updateStatus(String id, int status, Date date); - - BtcWalletDTO resetWallet(String userOpenId, String addr, Integer tokenId, String walletType); } diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java index 8858f43..fc03aa4 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletServiceImpl.java @@ -10,7 +10,9 @@ import com.blockchain.server.btc.dto.BtcWalletDTO; import com.blockchain.server.btc.entity.BtcToken; import com.blockchain.server.btc.entity.BtcWallet; import com.blockchain.server.btc.entity.BtcWalletTransfer; +import com.blockchain.server.btc.entity.WalletInitConfig; import com.blockchain.server.btc.mapper.BtcWalletMapper; +import com.blockchain.server.btc.mapper.WalletInitConfigMapper; import com.blockchain.server.btc.rpc.BtcUtils; import com.blockchain.server.btc.service.BtcApplicationService; import com.blockchain.server.btc.service.BtcTokenService; @@ -48,6 +50,8 @@ public class BtcWalletServiceImpl implements BtcWalletService { @Autowired private BtcWalletKeyServiceImpl btcWalletKeyService; + @Autowired + private WalletInitConfigMapper walletInitConfigMapper; @Override @Transactional @@ -194,4 +198,16 @@ public class BtcWalletServiceImpl implements BtcWalletService { return btcWalletTransfer; } + @Override + public int resetWallet(String userOpenId, String addr, String tokenId, String walletType) { + + WalletInitConfig walletInitConfig = new WalletInitConfig(); + walletInitConfig.setCoin(tokenId); + walletInitConfig.setWalletType(walletType); + WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig); + btcWalletMapper.updateWalletBalanceByUserOpenId(config.getBalance(),userOpenId,tokenId,walletType,new Date()); + + return 1; + } + } diff --git a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java index e6e04c6..8b254c0 100644 --- a/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java +++ b/blockchain-server/blockchain-server-btc/src/main/java/com/blockchain/server/btc/service/impl/BtcWalletTransferServiceImpl.java @@ -60,8 +60,6 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I @Autowired private UserServerFegin userServerFegin; - @Autowired - private WalletInitConfigMapper walletInitConfigMapper; @Autowired private BtcWalletTransferService btcWalletTransferService; @@ -340,32 +338,4 @@ public class BtcWalletTransferServiceImpl implements BtcWalletTransferService, I } } - @Override - public BtcWalletDTO resetWallet(String userOpenId, String addr, Integer tokenId, String walletType) { - //校验钱包类型 - btcApplicationService.checkWalletType(walletType); - //校验币种id - String tokenSymbol = btcTokenService.getAndVerifyTokenNameById(tokenId); - WalletInitConfig walletInitConfig = new WalletInitConfig(); - walletInitConfig.setCoin(tokenSymbol); - walletInitConfig.setWalletType(walletType); - WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig); - //修改该钱包余额,并插入一条充值记录 - BtcWalletTransfer btcWalletTransfer = new BtcWalletTransfer(); - btcWalletTransfer.setId(UUID.randomUUID().toString()); - btcWalletTransfer.setHash("zhixinlianResetWallet"); - btcWalletTransfer.setFromAddr("zhixinlianResetWallet"); - btcWalletTransfer.setToAddr(addr); - btcWalletTransfer.setAmount(config.getBalance().doubleValue()); - btcWalletTransfer.setGasPrice(0d); - btcWalletTransfer.setTokenId(tokenId); - btcWalletTransfer.setTokenSymbol(tokenSymbol); - btcWalletTransfer.setTransferType(BtcTransferConstans.TYPE_IN); - btcWalletTransfer.setStatus(BtcTransferConstans.STATUS_SUCCESS); - btcWalletTransfer.setCreateTime(new Date()); - btcWalletTransfer.setUpdateTime(btcWalletTransfer.getCreateTime()); - btcWalletTransferService.handleBlockRecharge(btcWalletTransfer); - //返回加减余额后的数据 - return btcWalletService.selectByAddr(addr, tokenId, walletType); - } } diff --git a/blockchain-server/blockchain-server-btc/src/main/resources/mapper/BtcWalletMapper.xml b/blockchain-server/blockchain-server-btc/src/main/resources/mapper/BtcWalletMapper.xml index 1bb166e..3f408c5 100644 --- a/blockchain-server/blockchain-server-btc/src/main/resources/mapper/BtcWalletMapper.xml +++ b/blockchain-server/blockchain-server-btc/src/main/resources/mapper/BtcWalletMapper.xml @@ -60,4 +60,17 @@ + + UPDATE + + wallet + SET + wallet.balance = wallet.freeze_balance + #{balance}, + wallet.free_balance = #{balance}, + wallet.update_time = #{modifyTime} + WHERE + wallet.user_open_id = #{userOpenId} + AND wallet.token_symbol = #{tokenSymbol} + AND wallet.wallet_type = #{walletType} + \ No newline at end of file diff --git a/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/mapper/WalletMapper.java b/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/mapper/WalletMapper.java index 2c9fe51..4e1785c 100644 --- a/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/mapper/WalletMapper.java +++ b/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/mapper/WalletMapper.java @@ -80,4 +80,14 @@ public interface WalletMapper extends Mapper { * @return */ WalletDTO selectWalletByTokenSymbol(@Param("userId") String userId, @Param("tokenSymbol") String tokenSymbol, @Param("walletType") String walletType); + /** + * 用户充值修改钱包金额 + * + */ + int updateWalletBalanceByUserOpenId(@Param("balance") BigDecimal balance, + @Param("userOpenId") String userOpenId, + @Param("tokenSymbol") String tokenSymbol, + @Param("walletType") String walletType, + @Param("modifyTime") Date modifyTime); + } diff --git a/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java b/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java index 503f22b..86e4ec3 100644 --- a/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java +++ b/blockchain-server/blockchain-server-eos/src/main/java/com/blockchain/server/eos/service/impl/EosWalletServiceImpl.java @@ -432,21 +432,13 @@ public class EosWalletServiceImpl implements EosWalletService, ITxTransaction { @Override public void resetWallet(String userOpenId, String addr, String tokenId, String walletType) { - + //查询配置信息 WalletInitConfig walletInitConfig = new WalletInitConfig(); walletInitConfig.setCoin(tokenId); walletInitConfig.setWalletType(walletType); WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig); // 修改钱包插入充值记录 -// eosWalletTransferService.handleWalletAndWalletTransfer(UUID.randomUUID().toString(), -// addr, -// null, -// EosConstant.TransferType.TRANSFER_IN, -// walletInitConfig.getBalance(), -// "eosio.token", -// tokenId,"" -// , -// null); + walletMapper.updateWalletBalanceByUserOpenId(config.getBalance(),userOpenId,tokenId,walletType,new Date()); } } diff --git a/blockchain-server/blockchain-server-eos/src/main/resources/mapper/WalletMapper.xml b/blockchain-server/blockchain-server-eos/src/main/resources/mapper/WalletMapper.xml index 5518a26..9721231 100644 --- a/blockchain-server/blockchain-server-eos/src/main/resources/mapper/WalletMapper.xml +++ b/blockchain-server/blockchain-server-eos/src/main/resources/mapper/WalletMapper.xml @@ -78,4 +78,19 @@ from where user_open_id = #{userId} + + + + UPDATE + + wallet + SET + wallet.balance = wallet.freeze_balance + #{balance}, + wallet.free_balance = #{balance}, + wallet.update_time = #{modifyTime} + WHERE + wallet.user_open_id = #{userOpenId} + AND wallet.token_symbol = #{tokenSymbol} + AND wallet.wallet_type = #{walletType} + \ No newline at end of file diff --git a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/mapper/EthWalletMapper.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/mapper/EthWalletMapper.java index 8b19c47..88c38ab 100644 --- a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/mapper/EthWalletMapper.java +++ b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/mapper/EthWalletMapper.java @@ -113,5 +113,13 @@ public interface EthWalletMapper extends Mapper { @Param("freezeBalance") BigDecimal freezeBalance, @Param("updateTime") Date updateTime); - + /** + * 用户充值修改钱包金额 + * + */ + int updateWalletBalanceByUserOpenId(@Param("balance") BigDecimal balance, + @Param("userOpenId") String userOpenId, + @Param("tokenSymbol") String tokenSymbol, + @Param("walletType") String walletType, + @Param("modifyTime") Date modifyTime); } \ No newline at end of file diff --git a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java index 135b551..519ac5d 100644 --- a/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java +++ b/blockchain-server/blockchain-server-eth/src/main/java/com/blockchain/server/eth/service/impl/EthWalletServiceImpl.java @@ -422,7 +422,7 @@ public class EthWalletServiceImpl implements IEthWalletService, ITxTransaction { walletInitConfig.setCoin(tokenId); walletInitConfig.setWalletType(walletType); WalletInitConfig config = walletInitConfigMapper.selectOne(walletInitConfig); - + ethWalletMapper.updateWalletBalanceByUserOpenId(config.getBalance(),userOpenId,tokenId,walletType,new Date()); EthWalletDTO walletDTO = selectByAddrAndTokenAddrAndWalletType(addr, addr, walletType); diff --git a/blockchain-server/blockchain-server-eth/src/main/resources/mapper/EthWalletMapper.xml b/blockchain-server/blockchain-server-eth/src/main/resources/mapper/EthWalletMapper.xml index 5d8f46b..4871e22 100644 --- a/blockchain-server/blockchain-server-eth/src/main/resources/mapper/EthWalletMapper.xml +++ b/blockchain-server/blockchain-server-eth/src/main/resources/mapper/EthWalletMapper.xml @@ -122,4 +122,17 @@ AND wallet.freeze_balance + #{freezeBalance} >= 0 + + UPDATE + + wallet + SET + wallet.balance = wallet.freeze_balance + #{balance}, + wallet.free_balance = #{balance}, + wallet.update_time = #{modifyTime} + WHERE + wallet.user_open_id = #{userOpenId} + AND wallet.token_symbol = #{tokenSymbol} + AND wallet.wallet_type = #{walletType} + \ No newline at end of file