Helius
2020-08-21 6107e978c64bc7ca9b3a238444e899932434e21d
Merge branch 'whole' of https://gitee.com/chonggaoxiao/new_excoin into whole
7 files modified
2 files added
197 ■■■■■ changed files
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java 26 ●●●●● 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/parameter/vo/ContractSymbolListVo.java 14 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java 114 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java 4 ●●●● 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/resources/mapper/member/MemberWalletContractDao.xml 6 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/coin/controller/CoinController.java
@@ -6,6 +6,7 @@
import javax.validation.Valid;
import com.xcong.excoin.modules.coin.parameter.vo.AllWalletCoinVo;
import com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo;
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;
@@ -21,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;
@@ -211,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
     */
@@ -235,5 +250,16 @@
        return coinService.agentTransferToWalletCoins(balance,transfertype,symbol);
    }
    
    /**
     * 合约账户列表
     * @return
     */
    @ApiOperation(value="合约账户列表", notes="合约账户列表")
    @ApiResponses({@ApiResponse( code = 200, message = "success", response = ContractSymbolListVo.class)})
    @GetMapping(value="/getContractSymbolList")
    public Result  getContractSymbolList() {
        return coinService.getContractSymbolList();
    }
}
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/parameter/vo/ContractSymbolListVo.java
New file
@@ -0,0 +1,14 @@
package com.xcong.excoin.modules.coin.parameter.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@Data
@ApiModel(value = "ContractSymbolListVo", description = "信息返回")
public class ContractSymbolListVo {
    @ApiModelProperty(value = "账户类型")
    private String walletCode;
}
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -45,4 +45,8 @@
    public Result agentTransferToWalletCoins(BigDecimal balance, Integer transfertype, String symbol);
    public Result getContractSymbolList();
    public Result contractInTransfer(BigDecimal balance, String symbolIn, String symbolOut);
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -22,6 +22,7 @@
import com.xcong.excoin.modules.coin.mapper.MemberAccountMoneyChangeMapper;
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.ContractSymbolListVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberAccountMoneyChangeInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletAgentInfoVo;
import com.xcong.excoin.modules.coin.parameter.vo.MemberWalletCoinInfoVo;
@@ -797,4 +798,117 @@
        return Result.ok(allWalletCoinVo);
    }
    @Override
    public Result getContractSymbolList() {
        //获取用户ID
        Long memberId = LoginUserUtils.getAppLoginUser().getId();
        List<ContractSymbolListVo> list = memberWalletContractDao.findContractSymbolListBymemberId(memberId);
        if(CollUtil.isNotEmpty(list)) {
            for(ContractSymbolListVo contractSymbolListVo : list) {
                String walletCode = contractSymbolListVo.getWalletCode();
                walletCode = walletCode+"/USDT";
                contractSymbolListVo.setWalletCode(walletCode);
            }
        }
        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/java/com/xcong/excoin/modules/member/dao/MemberWalletContractDao.java
@@ -3,9 +3,11 @@
import org.apache.ibatis.annotations.Param;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import java.math.BigDecimal;
import java.util.List;
public interface MemberWalletContractDao extends BaseMapper<MemberWalletContractEntity> {
    
@@ -19,4 +21,6 @@
     * @param id
     */
    void increaseWalletContractBalanceById(@Param("availableBalance") BigDecimal availableBalance,@Param("totalBalance") BigDecimal totalBalance,@Param("frozenBalance") BigDecimal frozenBalance,@Param("id") Long id);
    List<ContractSymbolListVo> findContractSymbolListBymemberId(@Param("memberId")Long memberId);
}
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=未登录
src/main/resources/mapper/member/MemberWalletContractDao.xml
@@ -9,6 +9,12 @@
                and wallet_code = #{symbol}
            </if>
    </select>
    <select id="findContractSymbolListBymemberId" resultType="com.xcong.excoin.modules.coin.parameter.vo.ContractSymbolListVo">
            select wallet_code
            from member_wallet_contract
            where member_id = #{memberId}
    </select>
    <update id="increaseWalletContractBalanceById" parameterType="map" >
        update member_wallet_contract