xiaoyong931011
2021-04-15 2c967b730b5647663b7bacd817b0a49bbf208dc1
Merge branch 'activity' of http://120.27.238.55:7000/r/exchange into activity
9 files modified
100 ■■■■■ changed files
src/main/java/com/xcong/excoin/common/contants/AppContants.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/common/system/controller/LoginController.java 19 ●●●●● 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 47 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java 20 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/platform/controller/PlatformController.java 1 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/utils/CalculateUtil.java 4 ●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/WholeTest.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/common/contants/AppContants.java
@@ -93,6 +93,7 @@
    public static final String BASE_URL_L1 = "http://124.70.205.195";
    public static final String BASE_URL_L2 = "http://123.60.45.251";
    public static final BigDecimal BASE_MIN_AMOUNT = new BigDecimal(100);
}
src/main/java/com/xcong/excoin/common/system/controller/LoginController.java
@@ -1,6 +1,7 @@
package com.xcong.excoin.common.system.controller;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.SecureUtil;
@@ -12,6 +13,7 @@
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.annotations.SubmitRepeat;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.common.system.bean.LoginUserBean;
import com.xcong.excoin.common.system.dto.LoginDto;
@@ -19,12 +21,19 @@
import com.xcong.excoin.common.system.vo.MemberInfoVo;
import com.xcong.excoin.configurations.properties.ApplicationProperties;
import com.xcong.excoin.configurations.properties.SecurityProperties;
import com.xcong.excoin.modules.coin.service.CoinService;
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.MemberWalletCoinEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import com.xcong.excoin.modules.member.service.MemberService;
import com.xcong.excoin.utils.CoinTypeConvert;
import com.xcong.excoin.utils.RedisUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
@@ -34,7 +43,9 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
@@ -60,6 +71,9 @@
    @Resource
    private AuthenticationManagerBuilder authenticationManagerBuilder;
    @Autowired
    private CoinService coinService;
    @Resource
    private RedisUtils redisUtils;
@@ -113,7 +127,12 @@
            authInfo.put("user", memberInfoVo);
        }
        BigDecimal total = coinService.getAllWalletAmount(memberEntity.getId());
        if (total.compareTo(AppContants.BASE_MIN_AMOUNT) > 0) {
        authInfo.put("baseUrl", AppContants.BASE_URL_L2);
        } else {
            authInfo.put("baseUrl", AppContants.BASE_URL_L1);
        }
        return Result.ok("success", authInfo);
    }
src/main/java/com/xcong/excoin/modules/coin/service/CoinService.java
@@ -52,4 +52,6 @@
    public Result coinInList(@Valid CoinInListDto coinInListDto);
    public BigDecimal getAllWalletAmount(Long memberId);
}
src/main/java/com/xcong/excoin/modules/coin/service/impl/CoinServiceImpl.java
@@ -1114,31 +1114,28 @@
    }
    
    
    @Override
    public BigDecimal getAllWalletAmount(Long memberId) {
        List<MemberWalletCoinEntity> memberWalletCoinList = memberWalletCoinDao.selectMemberWalletCoinsByMemberId(memberId);
        BigDecimal total = BigDecimal.ZERO;
        if (CollUtil.isNotEmpty(memberWalletCoinList)) {
            for (MemberWalletCoinEntity memberWalletCoinEntity : memberWalletCoinList) {
                if (memberWalletCoinEntity.getWalletCode().equals(CoinTypeEnum.USDT.name())) {
                    total = total.add(memberWalletCoinEntity.getTotalBalance());
                } else {
                    BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey(memberWalletCoinEntity.getWalletCode() + "/USDT")));
                    total = total.add(memberWalletCoinEntity.getTotalBalance().multiply(newPrice));
                }
            }
        }
    
        MemberWalletContractEntity contractWallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, CoinTypeEnum.USDT.name());
        total = total.add(contractWallet.getTotalBalance());
    
        MemberWalletAgentEntity walletAgent = memberWalletAgentDao.selectWalletAgentBymIdAndCode(memberId, CoinTypeEnum.USDT.name());
        if (walletAgent != null) {
            total = total.add(walletAgent.getTotalBalance());
        }
        return total;
    }
}
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -15,6 +15,7 @@
import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.common.system.service.CommonService;
import com.xcong.excoin.modules.coin.service.CoinService;
import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao;
import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
import com.xcong.excoin.modules.contract.dao.ContractOrderDao;
@@ -108,6 +109,9 @@
    @Autowired
    private FollowProducer followProducer;
    @Autowired
    private CoinService coinService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public Result submitOrder(SubmitOrderDto submitOrderDto) {
@@ -121,6 +125,14 @@
            return Result.loading("loading_type");
        }
        BigDecimal total = coinService.getAllWalletAmount(memberIdLong);
        Map<String, Object> data = new HashMap<>();
        if (total.compareTo(AppContants.BASE_MIN_AMOUNT) > 0) {
            data.put("baseUrl", AppContants.BASE_URL_L2);
        } else {
            data.put("baseUrl", AppContants.BASE_URL_L1);
        }
        // 判断当前对应的持仓/委托
        if (memberEntity.getContractPositionType() == ContractEntrustOrderEntity.POSITION_TYPE_ADD) {
            List<ContractHoldOrderEntity> holdList = contractHoldOrderDao.selectMemberHoldOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ALL, memberEntity.getId());
@@ -130,7 +142,9 @@
            }
            // 逐仓逻辑
            return doPositionTypeForAdd(submitOrderDto, memberEntity);
            Result result = doPositionTypeForAdd(submitOrderDto, memberEntity);
            result.setData(data);
            return result;
        } else {
            List<ContractHoldOrderEntity> holdList = contractHoldOrderDao.selectMemberHoldOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD, memberEntity.getId());
            List<ContractEntrustOrderEntity> entrustList = contractEntrustOrderDao.selectMemberEntrustOrderByPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD, memberEntity.getId());
@@ -139,7 +153,9 @@
            }
            // 全仓逻辑
            return doPositionTypeForWhole(submitOrderDto, memberEntity);
            Result result = doPositionTypeForWhole(submitOrderDto, memberEntity);
            result.setData(data);
            return result;
        }
    }
src/main/java/com/xcong/excoin/modules/platform/controller/PlatformController.java
@@ -39,7 +39,6 @@
    @ApiOperation(value = "findUsdtCnyExchange", notes = "Cny|Usdt兑换")
    @GetMapping(value = "/findUsdtCnyExchange")
    public Result findUsdtCnyExchange(@ApiParam(name = "type", value = "类型", type="string", required=true) @RequestParam("type") String type) {
        log.info("type值----->{}", type);
        return platformCnyUsdtExchangeService.findUsdtCnyExchange(type);
    }
    
src/main/java/com/xcong/excoin/modules/symbols/service/impl/SymbolsServiceImpl.java
@@ -141,7 +141,7 @@
        homeSymbolsVo.setUpOrDown(upOrDown);
        homeSymbolsVo.setVolume(symbolObject.getAmount());
        if (cnyUsdtExchange != null) {
            BigDecimal cnyPrice = newestPrice.multiply(cnyUsdtExchange.getValue()).setScale(2, BigDecimal.ROUND_HALF_UP);
            BigDecimal cnyPrice = newestPrice.multiply(cnyUsdtExchange.getValue().add(cnyUsdtExchange.getDiff())).setScale(2, BigDecimal.ROUND_HALF_UP);
            homeSymbolsVo.setCnyPrice(cnyPrice);
        }
src/main/java/com/xcong/excoin/utils/CalculateUtil.java
@@ -244,11 +244,11 @@
                // 开多
                if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) {
                    // (最新价-开仓价)*规格*张数
                    rewardRatio = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(contractHoldOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
                    rewardRatio = newPrice.subtract(holdOrderEntity.getOpeningPrice()).multiply(holdOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
                    // 开空
                } else {
                    // (开仓价-最新价)*规格*张数
                    rewardRatio = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(contractHoldOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
                    rewardRatio = holdOrderEntity.getOpeningPrice().subtract(newPrice).multiply(holdOrderEntity.getSymbolSku()).multiply(new BigDecimal(holdOrderEntity.getSymbolCntSale()));
                }
                if (memberEntity.getIsProfit() == MemberEntity.IS_PROFIT_Y) {
src/test/java/com/xcong/excoin/WholeTest.java
@@ -203,8 +203,8 @@
    public void wholeForceNewTest() {
        BigDecimal newPrice = new BigDecimal(redisUtils.getString(CoinTypeConvert.convertToKey("BTC/USDT")));
        MemberEntity memberEntity = memberDao.selectById(16L);
        ContractHoldOrderEntity holdOrder = contractHoldOrderDao.selectById(772L);
        MemberEntity memberEntity = memberDao.selectById(19L);
        ContractHoldOrderEntity holdOrder = contractHoldOrderDao.selectById(932L);
        System.out.println(CalculateUtil.calWholePriceTwo(memberEntity, holdOrder, 2));
    }