xiaoyong931011
2020-08-21 965450925b22fb9166687caa5bb663cd846cba14
20200821
1 files added
5 files modified
143 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java 27 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java 2 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java 98 ●●●●● patch | view | raw | blame | history
src/main/resources/i18n/messages_en_US.properties 1 ●●●● patch | view | raw | blame | history
src/main/resources/i18n/messages_zh_CN.properties 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
@@ -22,6 +22,7 @@
import org.springframework.web.bind.annotation.RestController;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.coin.parameter.dto.ContractInTransferDto;
import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
import com.xcong.excoin.modules.coin.parameter.dto.TransferOfBalanceDto;
import com.xcong.excoin.modules.coin.parameter.dto.TransferOfBalanceFromAgentDto;
@@ -212,6 +213,19 @@
    }
    
    /**
     * 合约账户内部划转(合约多账户)
     * @return
     */
    @ApiOperation(value="合约账户内部划转(合约多账户)", notes="合约账户内部划转(合约多账户)")
    @PostMapping(value="/contractInTransfer")
    public Result contractInTransfer(@RequestBody @Valid ContractInTransferDto contractInTransferDto) {
        BigDecimal balance = contractInTransferDto.getBalance();
        String symbolIn = contractInTransferDto.getSymbolIn();
        String symbolOut = contractInTransferDto.getSymbolOut();
        return coinService.contractInTransfer(balance,symbolIn,symbolOut);
    }
    /**
     * 代理账户划转到USDT账户
     * @return
     */
src/main/java/com/xcong/excoin/modules/coin/parameter/dto/ContractInTransferDto.java
New file
@@ -0,0 +1,27 @@
package com.xcong.excoin.modules.coin.parameter.dto;
import java.math.BigDecimal;
import javax.validation.constraints.NotNull;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "ContractInTransferDto", description = "参数接收类")
public class ContractInTransferDto {
    @NotNull(message = "划转金额不能为空")
    @ApiModelProperty(value = "划转金额", example = "100")
    private BigDecimal balance;
    @NotNull(message = "币种不能为空")
    @ApiModelProperty(value = "转入币种", example = "USDT")
    private String symbolIn;
    @NotNull(message = "币种不能为空")
    @ApiModelProperty(value = "转出币种", example = "BTC")
    private String symbolOut;
}
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -47,4 +47,6 @@
    public Result getContractSymbolList();
    public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut);
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -813,4 +813,102 @@
        return Result.ok(list);
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut) {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        //转入转出不能是同一账户
        if(symbolIn.equals(symbolOut)) {
            return Result.fail(MessageSourceUtils.getString("member_service_0098"));
        }
        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0004"));
        }
        MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolOut);
        BigDecimal availableBalance = walletContract.getAvailableBalance();
        // 扣币
        BigDecimal availableSubtract = availableBalance.subtract(balance);
        if (availableSubtract.compareTo(BigDecimal.ZERO) < 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0007"));
        }
        BigDecimal totalBalance = walletContract.getTotalBalance();
        BigDecimal totalSubtract = totalBalance.subtract(balance);
        walletContract.setAvailableBalance(availableSubtract);
        walletContract.setTotalBalance(totalSubtract);
        int updateWalletCoinById = memberWalletContractDao.updateById(walletContract);
        if (updateWalletCoinById < 1) {
            return Result.fail(MessageSourceUtils.getString("member_service_0096"));
        }
        //更新合约全仓模式下的订单权益
        MemberEntity memberEntity = memberDao.selectById(memberId);
        String symbols = symbolOut+"/USDT";
        ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
        // 加币
        // 查询合约账户
        MemberWalletContractEntity walletContractIn = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbolIn);
        BigDecimal availableBalanceIn = walletContractIn.getAvailableBalance();
        BigDecimal addIn = availableBalanceIn.add(balance);
        walletContractIn.setAvailableBalance(addIn);
        BigDecimal totalBalanceIn = walletContractIn.getTotalBalance();
        BigDecimal totalBigDecimalIn = totalBalanceIn.add(balance);
        walletContractIn.setTotalBalance(totalBigDecimalIn);
        int updateWalletContractById = memberWalletContractDao.updateById(walletContractIn);
        if (updateWalletContractById < 1) {
            return Result.fail(MessageSourceUtils.getString("member_service_0096"));
        }
        //更新合约全仓模式下的订单权益
        String symbolIns = symbolIn+"/USDT";
        ThreadPoolUtils.sendWholeForceClosingPrice(symbolIns, memberEntity);
        //添加币币资金划转历史记录
        MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
        memberAccountRecord.setContent("转出至合约"+symbolIn+"账户");
        memberAccountRecord.setMemberId(memberId);
        memberAccountRecord.setAmount(balance.negate());
        memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
        memberAccountMoneyChangeDao.insert(memberAccountRecord);
        //添加合约资金划转历史记录
        memberAccountRecord.setContent("由合约"+symbolOut+"账户转入至合约"+symbolIn+"账户");
        memberAccountRecord.setAmount(balance);
        memberAccountMoneyChangeDao.insert(memberAccountRecord);
        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
    }
}
src/main/resources/i18n/messages_en_US.properties
@@ -139,6 +139,7 @@
member_service_0095=Insufficient available balance of agent usdt account
member_service_0096=Transfer fail
member_service_0097=Payment method already exists
member_service_0098=Please select another account
order_service_0001=Wrong parameter value
order_service_0002=Not logged in
src/main/resources/i18n/messages_zh_CN.properties
@@ -139,6 +139,7 @@
member_service_0095=代理USDT账户可用余额不足
member_service_0096=划转失败
member_service_0097=支付方式已存在
member_service_0098=请选择其他账户
order_service_0001=参值有误
order_service_0002=未登录