Helius
2020-08-21 2bb8c9ae6db2668213d03d02cd8b38e6bc7aae83
Merge branch 'whole' of https://gitee.com/chonggaoxiao/new_excoin into whole
3 files modified
276 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java 43 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java 227 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
@@ -167,11 +167,23 @@
     * @return
     */
    @ApiOperation(value="币币账户USDT划转到合约账户", notes="币币账户USDT划转到合约账户")
    @PostMapping(value="/coinWalletTransferToContracts")
    public Result coinWalletTransferToContracts(@RequestBody @Valid TransferOfBalanceDto transferOfBalanceDto) {
        BigDecimal balance = transferOfBalanceDto.getBalance();
        String symbol = transferOfBalanceDto.getSymbol();
        return coinService.coinWalletTransferToContract(balance,symbol);
    }
    /**
     * 币币账户USDT划转到合约账户(合约多账户)
     * @return
     */
    @ApiOperation(value="币币账户USDT划转到合约账户(合约多账户)", notes="币币账户USDT划转到合约账户(合约多账户)")
    @PostMapping(value="/coinWalletTransferToContract")
    public Result coinWalletTransferToContract(@RequestBody @Valid TransferOfBalanceDto transferOfBalanceDto) {
        BigDecimal balance = transferOfBalanceDto.getBalance();
        String symbol = transferOfBalanceDto.getSymbol();
        return coinService.coinWalletTransferToContract(balance,symbol);
        return coinService.coinWalletTransferToContracts(balance,symbol);
    }
    
    /**
@@ -179,11 +191,23 @@
     * @return
     */
    @ApiOperation(value="合约账户划转到币币USDT账户", notes="合约账户划转到币币USDT账户")
    @PostMapping(value="/contractTransferToWalletCoins")
    public Result contractTransferToWalletCoins(@RequestBody @Valid TransferOfBalanceDto transferOfBalanceDto) {
        BigDecimal balance = transferOfBalanceDto.getBalance();
        String symbol = transferOfBalanceDto.getSymbol();
        return coinService.contractTransferToWalletCoin(balance,symbol);
    }
    /**
     * 合约账户划转到币币USDT账户(合约多账户)
     * @return
     */
    @ApiOperation(value="合约账户划转到币币USDT账户(合约多账户)", notes="合约账户划转到币币USDT账户(合约多账户)")
    @PostMapping(value="/contractTransferToWalletCoin")
    public Result contractTransferToWalletCoin(@RequestBody @Valid TransferOfBalanceDto transferOfBalanceDto) {
        BigDecimal balance = transferOfBalanceDto.getBalance();
        String symbol = transferOfBalanceDto.getSymbol();
        return coinService.contractTransferToWalletCoin(balance,symbol);
        return coinService.contractTransferToWalletCoins(balance,symbol);
    }
    
    /**
@@ -191,11 +215,24 @@
     * @return
     */
    @ApiOperation(value="代理账户划转到合约或币币USDT账户", notes="代理账户划转到合约或币币USDT账户")
    @PostMapping(value="/agentTransferToWalletCoins")
    public Result  agentTransferToWalletCoins(@RequestBody @Valid TransferOfBalanceFromAgentDto transferOfBalanceFromAgentDto) {
        BigDecimal balance = transferOfBalanceFromAgentDto.getBalance();
        Integer transfertype = transferOfBalanceFromAgentDto.getTransfertype();
        return coinService.agentTransferToWalletCoin(balance,transfertype);
    }
    /**
     * 代理账户划转到USDT账户
     * @return
     */
    @ApiOperation(value="代理账户划转到合约或币币USDT账户(合约多账户)", notes="代理账户划转到合约或币币USDT账户(合约多账户)")
    @PostMapping(value="/agentTransferToWalletCoin")
    public Result  agentTransferToWalletCoin(@RequestBody @Valid TransferOfBalanceFromAgentDto transferOfBalanceFromAgentDto) {
        BigDecimal balance = transferOfBalanceFromAgentDto.getBalance();
        Integer transfertype = transferOfBalanceFromAgentDto.getTransfertype();
        return coinService.agentTransferToWalletCoin(balance,transfertype);
        String symbol = transferOfBalanceFromAgentDto.getSymbol();
        return coinService.agentTransferToWalletCoins(balance,transfertype,symbol);
    }
    
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -39,4 +39,10 @@
    public Result getAllWalletCoin();
    public Result coinWalletTransferToContracts(BigDecimal balance, String symbol);
    public Result contractTransferToWalletCoins(BigDecimal balance, String symbol);
    public Result agentTransferToWalletCoins(BigDecimal balance, Integer transfertype, String symbol);
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -4,7 +4,6 @@
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import com.xcong.excoin.modules.platform.entity.PlatformCnyUsdtExchangeEntity;
import org.springframework.stereotype.Service;
@@ -24,15 +23,16 @@
import com.xcong.excoin.modules.coin.parameter.dto.RecordsPageDto;
import com.xcong.excoin.modules.coin.parameter.vo.AllWalletCoinVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberAgentIntoInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletContractInfoVo;
import com.xcong.excoin.modules.coin.service.CoinService;
import com.xcong.excoin.modules.member.dao.MemberDao;
import com.xcong.excoin.modules.member.dao.MemberWalletAgentDao;
import com.xcong.excoin.modules.member.dao.MemberWalletCoinDao;
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletAgentEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletCoinEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
@@ -40,6 +40,7 @@
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.MessageSourceUtils;
import com.xcong.excoin.utils.RedisUtils;
import com.xcong.excoin.utils.ThreadPoolUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -60,6 +61,8 @@
    MemberAccountMoneyChangeDao memberAccountMoneyChangeDao;
    @Resource
    MemberWalletAgentDao memberWalletAgentDao;
    @Resource
    MemberDao memberDao;
    @Resource
    RedisUtils redisUtils;
@@ -256,6 +259,71 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result coinWalletTransferToContracts(BigDecimal balance, String symbol) {
        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0004"));
        }
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        if (!StrUtil.isEmpty(memberId.toString())) {
            //获取对应的币种
            String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
            MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
            BigDecimal available = walletCoin.getAvailableBalance();
            // 扣币
            BigDecimal total = available.subtract(balance);
            if (total.compareTo(BigDecimal.ZERO) < 0) {
                return Result.fail(MessageSourceUtils.getString("member_service_0005"));
            }
            BigDecimal subtract = walletCoin.getTotalBalance().subtract(balance);
            walletCoin.setAvailableBalance(total);
            walletCoin.setTotalBalance(subtract);
            int updateWalletCoinById = memberWalletCoinDao.updateById(walletCoin);
            if (updateWalletCoinById < 1) {
                return Result.fail(MessageSourceUtils.getString("member_service_0096"));
            }
            // 加币
            // 查询合约账户
            MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbol);
            BigDecimal availableBalance = walletContract.getAvailableBalance();
            BigDecimal add = availableBalance.add(balance);
            walletContract.setAvailableBalance(add);
            BigDecimal totalBalance = walletContract.getTotalBalance();
            BigDecimal totalBigDecimal = totalBalance.add(balance);
            walletContract.setTotalBalance(totalBigDecimal);
            int updateWalletContractById = memberWalletContractDao.updateById(walletContract);
            if (updateWalletContractById < 1) {
                return Result.fail(MessageSourceUtils.getString("member_service_0096"));
            }
            //更新合约全仓模式下的订单权益
            MemberEntity memberEntity = memberDao.selectById(memberId);
            String symbols = symbol+"/USDT";
            ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
            //添加币币资金划转历史记录
            MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
            memberAccountRecord.setContent("转出至合约"+symbol+"账户");
            memberAccountRecord.setMemberId(memberId);
            memberAccountRecord.setAmount(balance.negate());
            memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
            memberAccountRecord.setSymbol(MemberWalletCoinEnum.WALLETCOINCODE.getValue());
            memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
            memberAccountMoneyChangeDao.insert(memberAccountRecord);
            //添加合约资金划转历史记录
            memberAccountRecord.setContent("由币币账户转入至合约"+symbol+"账户");
            memberAccountRecord.setSymbol(MemberWalletCoinEnum.WALLETCOINCODE.getValue());
            memberAccountRecord.setAmount(balance);
            memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
            memberAccountMoneyChangeDao.insert(memberAccountRecord);
        }
        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result contractTransferToWalletCoin(BigDecimal balance, String symbol) {
        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0004"));
@@ -306,6 +374,70 @@
        //添加资金划转历史记录
        memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTFROMCONTRACT.getValue());
        memberAccountRecord.setSymbol(walletCode);
        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
        memberAccountRecord.setAmount(balance);
        memberAccountMoneyChangeDao.insert(memberAccountRecord);
        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result contractTransferToWalletCoins(BigDecimal balance, String symbol) {
        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0004"));
        }
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
        MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbol);
        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"));
        }
        // 加币
        MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
        BigDecimal walletCoinAvailableBalance = walletCoin.getAvailableBalance();
        BigDecimal CoinAvailableBalance = walletCoinAvailableBalance.add(balance);
        BigDecimal walletCoinTotalBalance = walletCoin.getTotalBalance();
        BigDecimal CoinTotalBalance = walletCoinTotalBalance.add(balance);
        walletCoin.setAvailableBalance(CoinAvailableBalance);
        walletCoin.setTotalBalance(CoinTotalBalance);
        int updateById = memberWalletCoinDao.updateById(walletCoin);
        if (updateById < 1) {
            return Result.fail(MessageSourceUtils.getString("member_service_0096"));
        }
        //更新合约全仓模式下的订单权益
        MemberEntity memberEntity = memberDao.selectById(memberId);
        String symbols = symbol+"/USDT";
        ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
        //添加资金划转历史记录
        MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
        memberAccountRecord.setContent("合约"+symbol+"账户转出至币币账户");
        memberAccountRecord.setMemberId(memberId);
        memberAccountRecord.setAmount(balance.negate());
        memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
        memberAccountRecord.setSymbol(walletCode);
        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
        memberAccountMoneyChangeDao.insert(memberAccountRecord);
        //添加资金划转历史记录
        memberAccountRecord.setContent("由合约"+symbol+"账户转入");
        memberAccountRecord.setSymbol(walletCode);
        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
        memberAccountRecord.setAmount(balance);
@@ -460,6 +592,97 @@
        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result agentTransferToWalletCoins(BigDecimal balance, Integer transfertype, String symbol) {
        if (balance.compareTo(BigDecimal.ZERO) <= 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0004"));
        }
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        // 扣币
        String walletCode = MemberWalletCoinEnum.WALLETCOINCODE.getValue();
        MemberWalletAgentEntity walletAgent = memberWalletAgentDao.selectWalletAgentBymIdAndCode(memberId, walletCode);
        BigDecimal availableBalance = walletAgent.getAvailableBalance();
        BigDecimal totalBalance = walletAgent.getTotalBalance();
        BigDecimal available = availableBalance.subtract(balance);
        if (available.compareTo(BigDecimal.ZERO) < 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0008"));
        }
        BigDecimal total = totalBalance.subtract(balance);
        if (total.compareTo(BigDecimal.ZERO) < 0) {
            return Result.fail(MessageSourceUtils.getString("member_service_0008"));
        }
        walletAgent.setAvailableBalance(available);
        walletAgent.setTotalBalance(total);
        int i = memberWalletAgentDao.updateById(walletAgent);
        if (i < 1) {
            return Result.fail(MessageSourceUtils.getString("member_service_0095"));
        }
        //添加资金划转历史记录
        MemberAccountMoneyChange memberAccountRecord = new MemberAccountMoneyChange();
        //代理账户转币币
        if (MemberAccountMoneyChange.TYPE_WALLET_COIN.equals(transfertype)) {
            MemberWalletCoinEntity walletCoin = memberWalletCoinDao.selectWalletCoinBymIdAndCode(memberId, walletCode);
            BigDecimal walletCoinAvailableBalance = walletCoin.getAvailableBalance();
            BigDecimal walletCoinTotalBalance = walletCoin.getTotalBalance();
            walletCoin.setAvailableBalance(walletCoinAvailableBalance.add(balance));
            walletCoin.setTotalBalance(walletCoinTotalBalance.add(balance));
            int updateById = memberWalletCoinDao.updateById(walletCoin);
            if (updateById < 1) {
                return Result.fail(MessageSourceUtils.getString("member_service_0095"));
            }
            //添加资金划转历史记录
            memberAccountRecord.setMemberId(memberId);
            memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
            memberAccountRecord.setSymbol(walletCode);
            memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTFROMAGENT.getValue());
            memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_COIN);
            memberAccountRecord.setAmount(balance);
            memberAccountMoneyChangeDao.insert(memberAccountRecord);
            memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTTOWALLETCOIN.getValue());
        } else if (MemberAccountMoneyChange.TYPE_WALLET_CONTRACT.equals(transfertype)) {
            //代理账户转合约
            MemberWalletContractEntity walletContract = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, symbol);
            BigDecimal walletContractAvailableBalance = walletContract.getAvailableBalance();
            BigDecimal walletContractTotalBalance = walletContract.getTotalBalance();
            walletContract.setAvailableBalance(walletContractAvailableBalance.add(balance));
            walletContract.setTotalBalance(walletContractTotalBalance.add(balance));
            int updateById = memberWalletContractDao.updateById(walletContract);
            if (updateById < 1) {
                return Result.fail(MessageSourceUtils.getString("member_service_0095"));
            }
            //更新合约全仓模式下的订单权益
            MemberEntity memberEntity = memberDao.selectById(memberId);
            String symbols = symbol+"/USDT";
            ThreadPoolUtils.sendWholeForceClosingPrice(symbols, memberEntity);
            //添加资金划转历史记录
            memberAccountRecord.setMemberId(memberId);
            memberAccountRecord.setStatus(MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER);
            memberAccountRecord.setSymbol(walletCode);
            memberAccountRecord.setContent("由代理账户转入合约"+symbol+"账户");
            memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_CONTRACT);
            memberAccountRecord.setAmount(balance);
            memberAccountMoneyChangeDao.insert(memberAccountRecord);
            memberAccountRecord.setContent(MemberWalletCoinEnum.CONTENTTOCONTRACT.getValue());
        }
        memberAccountRecord.setAmount(balance.negate());
        memberAccountRecord.setType(MemberAccountMoneyChange.TYPE_WALLET_AGENT);
        memberAccountMoneyChangeDao.insert(memberAccountRecord);
        return Result.ok(MessageSourceUtils.getString("member_service_0006"));
    }
    @Override
    public Result findWalletAgentBySymbol() {