Helius
2021-04-15 629f5bdc2982e83fe13812f3a44a910ced630a00
modify
5 files modified
101 ■■■■■ 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 32 ●●●●● 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;
        }
    }
@@ -281,11 +297,7 @@
            ThreadPoolUtils.sendWholePrice(memberEntity.getId());
            // 提交成功
            Result result = Result.ok(MessageSourceUtils.getString("member_service_0024"));
            Map<String, Object> data = new HashMap<>();
            data.put("baseUrl", AppContants.BASE_URL_L2);
            result.setData(data);
            return result;
            return Result.ok(MessageSourceUtils.getString("member_service_0024"));
        }
        // 提交失败
        return Result.fail(MessageSourceUtils.getString("member_service_0067"));
@@ -393,11 +405,7 @@
//                ThreadPoolUtils.sendFollowOrderTask(holdOrderEntity.getId());
            }
            // 提交成功
            Result result = Result.ok(MessageSourceUtils.getString("member_service_0024"));
            Map<String, Object> data = new HashMap<>();
            data.put("baseUrl", AppContants.BASE_URL_L2);
            result.setData(data);
            return result;
            return Result.ok(MessageSourceUtils.getString("member_service_0024"));
        }
        // 提交失败
        return Result.fail(MessageSourceUtils.getString("member_service_0067"));