xiaoyong931011
2021-04-06 bf68aa759bc3c0a858d80cb3d1ae1f1682cd6c94
Merge branch 'activity' of http://120.27.238.55:7000/r/exchange into activity

 Conflicts:
 src/test/java/com/xcong/excoin/FollowTest.java
8 files modified
629 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/blackchain/service/Impl/BlockSeriveImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/common/NoticeConstant.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/service/FollowOrderOperationService.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java 68 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/consumer/FollowConsumer.java 16 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/rabbit/producer/FollowProducer.java 22 ●●●●● patch | view | raw | blame | history
src/test/java/com/xcong/excoin/FollowTest.java 506 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/blackchain/service/Impl/BlockSeriveImpl.java
@@ -104,12 +104,12 @@
                        }
                        break;
                    case "EOS":
                        address = "biyicteos123";
                        address = "hibitdeposit";
                        map.put("address", address);
                        map.put("lable", uuid);
                        break;
                    case "XRP":
                        address = "biyicteos123";
                        address = "rUzWJkXyEtT8ekSSxkBYPqCvHpngcy6Fks";
                        map.put("address", address);
                        map.put("lable", uuid);
                        break;
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -851,6 +851,10 @@
        if (i > 0) {
            // 发送爆仓消息
            sendOrderBombMsg(holdOrderEntity.getId(), holdOrderEntity.getOpeningType(), forceClosingPrice, holdOrderEntity.getSymbol(), holdOrderEntity.getOperateNo(), holdOrderEntity.getMemberId());
            if (ContractOrderEntity.CONTRACTTYPE_DOCUMENTARY == holdOrderEntity.getContractType()) {
                followProducer.sendChangeFollowOrderBond(holdOrderEntity.getId(), changeBondDto.getAmount(), changeBondDto.getType());
            }
            return Result.ok("调整成功");
        }
        return Result.fail("调整失败");
src/main/java/com/xcong/excoin/modules/documentary/common/NoticeConstant.java
@@ -34,4 +34,9 @@
    public static final String RETURN_MONEY_CONTENT = "平仓成功,收到的合约{},币种{}的返利金额:{}";
    public static final String RETURN_MONEY_CONTENT_MAMC = "合约-{},订单{}的带单返利";
    public static final String CHANGE_BOND_TITLE = "跟单-调整保证金";
    public static final String CHANGE_BOND_ADD_CONTENT_FAIL = "金额不足无法跟随交易员调整保证金";
    public static final String CHANGE_BOND_CONTENT_SUCCESS = "跟随交易员调整保证金成功,金额为{}, 交易员:{}";
    public static final String CHANGE_BOND_REDUCE_CONTENT_FAIL = "超出保证金最大减少金额,无法跟随交易员调整保证金";
}
src/main/java/com/xcong/excoin/modules/documentary/service/FollowOrderOperationService.java
@@ -3,6 +3,8 @@
import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
import java.math.BigDecimal;
/**
 * @author helius
 */
@@ -23,4 +25,6 @@
     * @param newOrderId 交易员平仓后历史ID
     */
    public void closingFollowOrders(String orderNo);
    public void changeFollowOrdersBond(Long id, BigDecimal bond, Integer type);
}
src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java
@@ -10,6 +10,7 @@
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum;
import com.xcong.excoin.common.exception.GlobalException;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.common.system.service.CommonService;
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
@@ -19,6 +20,7 @@
import com.xcong.excoin.modules.contract.entity.ContractHoldOrderEntity;
import com.xcong.excoin.modules.contract.entity.ContractOrderEntity;
import com.xcong.excoin.modules.contract.mapper.ContractHoldOrderEntityMapper;
import com.xcong.excoin.modules.contract.parameter.dto.ChangeBondDto;
import com.xcong.excoin.modules.contract.service.RabbitOrderService;
import com.xcong.excoin.modules.documentary.common.NoticeConstant;
import com.xcong.excoin.modules.documentary.dao.*;
@@ -368,4 +370,70 @@
            }
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void changeFollowOrdersBond(Long id, BigDecimal bond, Integer type) {
        log.info("==跟单调整保证金:{}, {}, {}==", id, bond, type);
        ContractHoldOrderEntity contractHoldOrderEntity = contractHoldOrderDao.selectById(id);
        if (contractHoldOrderEntity == null) {
            log.info("持仓不存在:{}", id);
            return;
        }
        // 交易员信息
        FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(contractHoldOrderEntity.getMemberId());
        List<FollowFollowerOrderRelationEntity> relations = followFollowerOrderRelationDao.selectFollowHoldOrderByTradeOrderNo(contractHoldOrderEntity.getOrderNo());
        if (CollUtil.isNotEmpty(relations)) {
            for (FollowFollowerOrderRelationEntity relation : relations) {
                ContractHoldOrderEntity followHoldOrder = contractHoldOrderDao.selectById(relation.getOrderId());
                MemberEntity memberEntity = memberDao.selectById(relation.getMemberId());
                MemberWalletContractEntity wallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name());
                // 增加保证金
                if (type == ChangeBondDto.TYPE_ADD) {
                    if (bond.compareTo(wallet.getAvailableBalance()) > 0) {
                        log.info("可用金额不足:{}, {}", memberEntity.getId(), followHoldOrder.getOrderNo());
                        LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CHANGE_BOND_TITLE, NoticeConstant.CHANGE_BOND_ADD_CONTENT_FAIL);
                        continue;
                    }
                    memberWalletContractDao.increaseWalletContractBalanceById(bond.negate(), null, null, wallet.getId());
                    followHoldOrder.setBondAmount(followHoldOrder.getBondAmount().add(bond));
                    LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CHANGE_BOND_TITLE, StrUtil.format(NoticeConstant.CHANGE_BOND_CONTENT_SUCCESS, bond, followTraderInfoEntity.getNickname()));
                } else {
                    if (followHoldOrder.getBondAmount().subtract(followHoldOrder.getPrePaymentAmount()).subtract(bond).compareTo(BigDecimal.ZERO) < 0) {
                        log.info("超出保证金最大减少金额-1");
                        LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CHANGE_BOND_TITLE, NoticeConstant.CHANGE_BOND_ADD_CONTENT_FAIL);
                        continue;
                    }
                    BigDecimal profitOrLoss = CalculateUtil.calProfitOrLoss(followHoldOrder, memberEntity);
                    if (profitOrLoss.compareTo(BigDecimal.ZERO) < 0) {
                        BigDecimal canReduceMax = followHoldOrder.getBondAmount().subtract(followHoldOrder.getPrePaymentAmount()).add(profitOrLoss);
                        if (canReduceMax.subtract(bond).compareTo(BigDecimal.ZERO) < 0) {
                            log.info("超出保证金最大减少金额-2");
                            LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CHANGE_BOND_TITLE, NoticeConstant.CHANGE_BOND_ADD_CONTENT_FAIL);
                            continue;
                        }
                    }
                    memberWalletContractDao.increaseWalletContractBalanceById(bond, null, null, wallet.getId());
                    followHoldOrder.setBondAmount(followHoldOrder.getBondAmount().subtract(bond));
                    LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CHANGE_BOND_TITLE, StrUtil.format(NoticeConstant.CHANGE_BOND_CONTENT_SUCCESS, bond.negate(), followTraderInfoEntity.getNickname()));
                }
                BigDecimal forceClosingPrice = CalculateUtil.getForceSetPrice(followHoldOrder.getBondAmount(), followHoldOrder.getOpeningPrice(), followHoldOrder.getSymbolCnt(), followHoldOrder.getSymbolSku(), followHoldOrder.getOpeningType(), memberEntity);
                followHoldOrder.setForceClosingPrice(forceClosingPrice);
                followHoldOrder.setOperateNo(followHoldOrder.getOperateNo() + 1);
                int i = contractHoldOrderDao.updateById(followHoldOrder);
                if (i > 0) {
                    sendOrderBombMsg(followHoldOrder.getId(), followHoldOrder.getOpeningType(), forceClosingPrice, followHoldOrder.getSymbol(), followHoldOrder.getOperateNo(), followHoldOrder.getMemberId());
                } else {
                    throw new GlobalException("更新失败");
                }
            }
        }
    }
}
src/main/java/com/xcong/excoin/rabbit/consumer/FollowConsumer.java
@@ -1,5 +1,6 @@
package com.xcong.excoin.rabbit.consumer;
import com.alibaba.fastjson.JSONObject;
import com.rabbitmq.client.Channel;
import com.xcong.excoin.configurations.RabbitMqConfig;
import com.xcong.excoin.modules.documentary.service.FollowOrderOperationService;
@@ -9,6 +10,10 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;
import org.web3j.abi.datatypes.Int;
import java.math.BigDecimal;
import java.util.Map;
/**
 * @author wzy
@@ -29,4 +34,15 @@
        followOrderOperationService.addFollowerOrder(Long.parseLong(content));
    }
//    @RabbitListener(queues = RabbitMqConfig.QUEUE_FOLLOW_CHANGE_BOND)
    public void changeFollowOrderBond(Message message, Channel channel) {
        String content = new String(message.getBody());
        log.info("==收到跟单保证金调整消息 : {}", content);
        Map map = JSONObject.parseObject(content, Map.class);
        Integer id = (Integer) map.get("id");
        BigDecimal bond = (BigDecimal) map.get("bond");
        Integer type = (Integer) map.get("type");
        followOrderOperationService.changeFollowOrdersBond(id.longValue(), bond, type);
    }
}
src/main/java/com/xcong/excoin/rabbit/producer/FollowProducer.java
@@ -1,13 +1,19 @@
package com.xcong.excoin.rabbit.producer;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.configurations.RabbitMqConfig;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSON;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.web3j.abi.datatypes.Int;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
@@ -41,4 +47,20 @@
        log.info("发送跟单下单消息: {}, {}", id, correlationData.getId());
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_FOLLOW_ORDER, id.toString(), correlationData);
    }
    /**
     * 发送跟单调整保证金信息
     *
     * @param id
     */
    public void sendChangeFollowOrderBond(Long id, BigDecimal changeBond, Integer type) {
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("bond", changeBond);
        map.put("type", type);
        String msg = JSONObject.toJSONString(map);
        log.info("发送跟单保证金调整消息: {}, {}", msg, correlationData.getId());
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_FOLLOW_CHANGE_BOND, msg, correlationData);
    }
}
src/test/java/com/xcong/excoin/FollowTest.java
@@ -1,57 +1,16 @@
package com.xcong.excoin;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
import com.xcong.excoin.common.response.Result;
import com.xcong.excoin.modules.activity.dao.ActivityMainDao;
import com.xcong.excoin.modules.activity.dao.ActivityMemberDetailDao;
import com.xcong.excoin.modules.activity.dao.ActivityReceiveRecordDao;
import com.xcong.excoin.modules.activity.dao.ActivitySubDao;
import com.xcong.excoin.modules.activity.entity.ActivityMain;
import com.xcong.excoin.modules.activity.entity.ActivityMemberDetail;
import com.xcong.excoin.modules.activity.entity.ActivityReceiveRecord;
import com.xcong.excoin.modules.activity.entity.ActivitySub;
import com.xcong.excoin.modules.coin.entity.MemberAccountMoneyChange;
import com.xcong.excoin.modules.contract.dao.ContractOrderDao;
import com.xcong.excoin.modules.contract.entity.ContractOrderEntity;
import com.xcong.excoin.modules.documentary.common.NoticeConstant;
import com.xcong.excoin.modules.documentary.dao.*;
import com.xcong.excoin.modules.documentary.dto.MyFollowOrderDto;
import com.xcong.excoin.modules.documentary.dto.TradeOrderInfoDto;
import com.xcong.excoin.modules.documentary.entity.FollowFollowerOrderRelationEntity;
import com.xcong.excoin.modules.documentary.entity.FollowFollowerProfitEntity;
import com.xcong.excoin.modules.documentary.entity.FollowTraderInfoEntity;
import com.xcong.excoin.modules.documentary.entity.FollowTraderProfitInfoEntity;
import com.xcong.excoin.modules.documentary.service.FollowOrderOperationService;
import com.xcong.excoin.modules.documentary.vo.MyFollowOrderVo;
import com.xcong.excoin.modules.documentary.vo.TradeHistoryOrderInfoVo;
import com.xcong.excoin.modules.member.dao.MemberDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.quartz.job.FollowProfitUpdateJob;
import com.xcong.excoin.utils.LogRecordUtils;
import com.xcong.excoin.rabbit.producer.FollowProducer;
import com.xcong.excoin.utils.ThreadPoolUtils;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import jnr.ffi.Struct.int16_t;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import javax.validation.Valid;
import java.math.BigDecimal;
/**
 * @author wzy
@@ -63,456 +22,27 @@
    @Resource
    private FollowOrderOperationService followOrderOperationService;
    @Resource
    private ActivityMainDao activityMainDao;
    @Resource
    private ActivitySubDao activitySubDao;
    @Resource
    private ActivityMemberDetailDao activityMemberDetailDao;
    @Resource
    private ActivityReceiveRecordDao activityReceiveRecordDao;
    @Resource
    private MemberDao memberDao;
    @Resource
    private FollowFollowerProfitDao followFollowerProfitDao;
    @Resource
    private FollowFollowerOrderRelationDao followFollowerOrderRelationDao;
    @Resource
    private FollowTraderInfoDao followTraderInfoDao;
    @Resource
    private FollowTraderProfitInfoDao followTraderProfitInfoDao;
    @Resource
    private ContractOrderDao contractOrderDao;
    @Resource
    private FollowTraderProfitDetailDao followTraderProfitDetailDao;
//    public static void main(String[] args) {
//        String orderNo = "2021033112500017";
//        System.out.println(orderNo.substring(8));
//    }
//
//    @Test
//    public void getReturn(){
//        String orderNo = "2021033112880019";
//
//        //生成返利记录和资金变化记录
//        List<FollowFollowerOrderRelationEntity> orderRelationDone = followFollowerOrderRelationDao.selectFollowOrderByTradeOrderNo(orderNo);
//        if(CollUtil.isNotEmpty(orderRelationDone)) {
//            List<Long> orderIds = new ArrayList<>();
//            for (FollowFollowerOrderRelationEntity orderRelationd : orderRelationDone) {
//                orderIds.add(orderRelationd.getOrderId());
//            }
//
//            if(CollUtil.isNotEmpty(orderIds)){
//                //获取对应的平仓记录单号
//                List<String> orderNosList = new ArrayList<>();
//                for(Long orderId : orderIds) {
//                    String orderNos = contractOrderDao.selectOrderNoByOrderIds(orderId);
//                    orderNosList.add(orderNos);
//                }
//                //获取总返佣
//                BigDecimal totalAmount = followTraderProfitDetailDao.selectFollowHoldOrderByFollowOrderNo(orderNosList);
//                totalAmount = (totalAmount == null?BigDecimal.ZERO:totalAmount.setScale(2, BigDecimal.ROUND_DOWN));
//                if(totalAmount.compareTo(BigDecimal.ZERO) > 0){
//                    //增加返佣提醒
//                    String symbol = contractOrderDao.selectById(orderIds.get(0)).getSymbol();
//                    String orderNoTrader = orderRelationDone.get(0).getTradeOrderNo();
//                    Long traderMemberId = orderRelationDone.get(0).getTradeMemberId();
//                    LogRecordUtils.insertFollowerNotice(traderMemberId,
//                            NoticeConstant.RETURN_MONEY_TITLE,
//                            StrUtil.format(NoticeConstant.RETURN_MONEY_CONTENT,
//                                    orderNoTrader,
//                                    symbol,
//                                    totalAmount));
//                    //带单返利的记录要在资产页面的其他记录
//                    LogRecordUtils.insertMemberAccountMoneyChange(
//                            traderMemberId,
//                            StrUtil.format(NoticeConstant.RETURN_MONEY_CONTENT_MAMC,
//                                    orderNoTrader,
//                                    symbol),
//                            totalAmount,
//                            MemberWalletCoinEnum.WALLETCOINCODE.getValue(),
//                            MemberAccountMoneyChange.STATUS_SUCCESS_INTEGER,
//                            MemberAccountMoneyChange.TYPE_WALLET_AGENT);
//                }
//            }
//        }
//    }
//    @Test
//    public void getTradeHistoryOrderInfo() {
//        //获取用户ID
//        Long memberId = 14L;
//        List<TradeHistoryOrderInfoVo> myFollowOrderVos = new ArrayList<>();
//        //历史跟单
//        Page<ContractOrderEntity> page = new Page<>(1, 5);
//        IPage<ContractOrderEntity> contractOrderEntitys = followFollowerProfitDao.getMyFollowOrderHistoryRecords(page, memberId);
//
//        List<ContractOrderEntity> records = contractOrderEntitys.getRecords();
//        if(CollUtil.isNotEmpty(records)) {
//            for(ContractOrderEntity contractOrderEntity : records) {
//                TradeHistoryOrderInfoVo myFollowOrderVo = new TradeHistoryOrderInfoVo();
//                //获取【跟随者-订单关联表】中的累计数据
//                BigDecimal allRewardAmount = BigDecimal.ZERO;
//                BigDecimal allRewardRatio = BigDecimal.ZERO;
//
//                Long orderId = contractOrderEntity.getId();
//                String orderNo = contractOrderEntity.getOrderNo();
//                Map<String, Object> columnMapRelation = new HashMap<>();
//                columnMapRelation.put("trade_order_no", orderNo);
//                columnMapRelation.put("trade_member_id", memberId);
//                columnMapRelation.put("order_type", 2);
//                columnMapRelation.put("is_show", 1);
//                List<FollowFollowerOrderRelationEntity> followFollowerOrderRelations = followFollowerOrderRelationDao.selectByMap(columnMapRelation);
//                if(CollUtil.isNotEmpty(followFollowerOrderRelations)) {
//                    int size = followFollowerOrderRelations.size() - 1;
//                    myFollowOrderVo.setFollowerNumber(size);
//                    for(FollowFollowerOrderRelationEntity followFollowerOrderRelation : followFollowerOrderRelations) {
//                        Long followerMemberId = followFollowerOrderRelation.getMemberId();
//                        if(!memberId.equals(followerMemberId)) {
//                            Long followerOrderId = followFollowerOrderRelation.getOrderId();
//                            ContractOrderEntity orderEntity = contractOrderDao.selectById(followerOrderId);
//                            BigDecimal rewardAmount = orderEntity.getRewardAmount();
//                            allRewardAmount = allRewardAmount.add(rewardAmount);
//                            BigDecimal rewardRatio = orderEntity.getRewardRatio();
//                            rewardRatio = rewardRatio == null ? BigDecimal.ZERO : rewardRatio;
//                            allRewardRatio = allRewardRatio.add(rewardRatio);
//                        }
//                    }
//                }else {
//                    myFollowOrderVo.setFollowerNumber(0);
//                }
//                myFollowOrderVo.setFollowerRewardAmount(allRewardAmount);
//                myFollowOrderVo.setFollowerRewardRatio(allRewardRatio);
//
//                //获取交易员信息
//                FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId);
//                String nickname = followTraderInfoEntity.getNickname();
//                myFollowOrderVo.setNickname(nickname);
//                myFollowOrderVo.setOrderId(orderId);
//                String symbol = contractOrderEntity.getSymbol();
//                myFollowOrderVo.setSymbol(symbol);
//                int orderType = contractOrderEntity.getOrderType();
//                myFollowOrderVo.setOrderType(orderType);
//                int leverRatio = contractOrderEntity.getLeverRatio();
//                myFollowOrderVo.setLeverRatio(leverRatio);
//                BigDecimal rewardAmount = contractOrderEntity.getRewardAmount().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setRewardAmount(rewardAmount);
//                BigDecimal rewardRatio = contractOrderEntity.getRewardRatio() == null ? BigDecimal.ZERO : contractOrderEntity.getRewardRatio().setScale(4, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setRewardRatio(rewardRatio);
//                int symbolCnt = contractOrderEntity.getSymbolCnt();
//                myFollowOrderVo.setSymbolCnt(symbolCnt);
//                BigDecimal bondAmount = contractOrderEntity.getBondAmount().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setBondAmount(bondAmount);
//                BigDecimal openingPrice = contractOrderEntity.getOpeningPrice().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setOpeningPrice(openingPrice);
//                BigDecimal closingPrice = contractOrderEntity.getClosingPrice().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setClosingPrice(closingPrice);
//                Date openingTime = contractOrderEntity.getOpeningTime();
//                myFollowOrderVo.setOpeningTime(openingTime);
//                Date closingTime = contractOrderEntity.getClosingTime();
//                myFollowOrderVo.setClosingTime(closingTime);
//
//                myFollowOrderVo.setOrderNo(orderNo);
//                myFollowOrderVos.add(myFollowOrderVo);
//            }
//        }
//        System.out.println(myFollowOrderVos);
//    }
    @Test
    public void traderProfitUpdate() {
        log.info("交易员定时任务执行");
        // 查询所有交易员信息
        List<FollowTraderInfoEntity> allTraders = followTraderInfoDao.selectAllTraderInfo();
        if (CollUtil.isNotEmpty(allTraders)) {
            for (FollowTraderInfoEntity trader : allTraders) {
                Long tradeMemberId = trader.getMemberId();
                //获取交易员的当前跟随者
                Map<String, Object> hashMap = new HashMap<>();
                hashMap.put("trade_member_id", tradeMemberId);
                hashMap.put("is_follow", FollowFollowerProfitEntity.IS_FOLLOW_Y);
                List<FollowFollowerProfitEntity> followFollowerProfitEntityList = followFollowerProfitDao.selectByMap(hashMap);
                if(CollUtil.isNotEmpty(followFollowerProfitEntityList)) {
                    for(FollowFollowerProfitEntity followFollowerProfitEntity : followFollowerProfitEntityList) {
                        //获取当前跟随者的跟随本金
                        Long memberId = followFollowerProfitEntity.getMemberId();
                        BigDecimal sumBondAmountBigDecimal = followFollowerProfitDao.selectSumBondAmountBymemberId(memberId,trader.getId());
                        sumBondAmountBigDecimal = (sumBondAmountBigDecimal == null?BigDecimal.ZERO:sumBondAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN));
                        followFollowerProfitEntity.setTotalPrincipal(sumBondAmountBigDecimal);
                        //获取当前的盈亏
                        BigDecimal sumRewardAmountBigDecimal = followFollowerProfitDao.selectSumRewardAmountByMemberId(memberId,trader.getId());
                        sumRewardAmountBigDecimal = (sumRewardAmountBigDecimal == null?BigDecimal.ZERO:sumRewardAmountBigDecimal.setScale(2, BigDecimal.ROUND_DOWN));
                        followFollowerProfitEntity.setTotalProfit(sumRewardAmountBigDecimal);
                        followFollowerProfitDao.updateById(followFollowerProfitEntity);
                    }
    public void addFollowTest() {
        followOrderOperationService.addFollowerOrder(601L);
//        ThreadPoolUtils.sendFollowOrderTask(601L);
                }
    @Test
    public void strContainsTest() {
        String symbols = "BTC,ETH,LTC,BCH";
        String symbol = "BTC/USDT";
                FollowTraderProfitInfoEntity traderInfoProfit = followTraderProfitInfoDao.selectTraderInfoProfitByMemberId(tradeMemberId);
                // 累计收益率
                BigDecimal ljsyl = contractOrderDao.selectFollowOrderTotalProfitByMemberId(tradeMemberId);
                BigDecimal totalProfitRatio = (ljsyl == null?BigDecimal.ZERO:ljsyl.setScale(2, BigDecimal.ROUND_DOWN));
                traderInfoProfit.setTotalProfitRatio(totalProfitRatio);
                // 带单总收益,只查询交易员自己的带单总收益
                BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfitSelf(tradeMemberId);
                //BigDecimal totalProfit = followFollowerOrderRelationDao.selectTraderTotalProfit(tradeMemberId);
                traderInfoProfit.setTotalProfit(totalProfit);
                // 交易笔数
//                List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderByMemberId(tradeMemberId);
                List<ContractOrderEntity> orders = contractOrderDao.selectFollowOrderListByMemberId(tradeMemberId);
                traderInfoProfit.setTotalOrderCnt(CollUtil.isNotEmpty(orders) ? orders.size() : 0);
                // 近三周胜率
                Integer winCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, 1);
                Integer allCnt = contractOrderDao.selectFollowOrderCntForWinRate(tradeMemberId, null);
                if (winCnt != null && allCnt != null && allCnt!=0) {
                    BigDecimal winRate = BigDecimal.valueOf(winCnt).divide(BigDecimal.valueOf(allCnt), 4, BigDecimal.ROUND_DOWN);
                    traderInfoProfit.setWinRate(winRate);
                }
                Date date = new Date();
                DateTime offsetDay = DateUtil.offsetDay(new Date(), -30);
                //30天胜率(30天盈利总张数/30平仓总张数)
                BigDecimal thirtyTotalCnt = contractOrderDao.selectThirtyTotalCntByMemberId(tradeMemberId,date,offsetDay);
                BigDecimal thirtyWinCnt = contractOrderDao.selectThirtyWinCntByMemberId(tradeMemberId,date,offsetDay);
                BigDecimal thirtyTotalCntRatio = (thirtyTotalCnt == null?BigDecimal.ZERO:thirtyTotalCnt.setScale(2, BigDecimal.ROUND_DOWN));
                BigDecimal thirtyWinCntRatio = (thirtyWinCnt == null?BigDecimal.ZERO:thirtyWinCnt.setScale(2, BigDecimal.ROUND_DOWN));
                BigDecimal thirtyProfitRatio = BigDecimal.ZERO.setScale(2, BigDecimal.ROUND_DOWN);;
                if(thirtyTotalCnt.compareTo(BigDecimal.ZERO) > 0) {
                    thirtyProfitRatio = thirtyWinCntRatio.divide(thirtyTotalCntRatio, 2, BigDecimal.ROUND_DOWN).setScale(2, BigDecimal.ROUND_DOWN);
                }
                traderInfoProfit.setThirtyProfitRatio(thirtyProfitRatio);
                //30天最大回撤率(30天最高收益率-30天最低收益率)
                BigDecimal thirtyMaxRatio = contractOrderDao.selectThirtyMaxRatioByMemberId(tradeMemberId,date,offsetDay);
                BigDecimal thirtyMinRatio = contractOrderDao.selectThirtyMinRatioByMemberId(tradeMemberId,date,offsetDay);
                BigDecimal thirtyRatio = (thirtyMaxRatio == null?BigDecimal.ZERO:thirtyMaxRatio.setScale(2, BigDecimal.ROUND_DOWN))
                        .subtract((thirtyMinRatio == null?BigDecimal.ZERO:thirtyMinRatio.setScale(2, BigDecimal.ROUND_DOWN)));
                traderInfoProfit.setThirtyRatio(thirtyRatio);
                // 当前跟随者总收益
                BigDecimal followerProfit = followFollowerProfitDao.selectAllFollowerProfit(tradeMemberId);
                traderInfoProfit.setFollowerTotalProfit(followerProfit);
                // 当前跟随人数
                int followerCnt = followFollowerProfitDao.selectFollowerCntByTradeMemberId(tradeMemberId);
                traderInfoProfit.setTotalFollowerCnt(followerCnt);
                followTraderProfitInfoDao.updateById(traderInfoProfit);
            }
        }
        System.out.println(symbols.contains(symbol.replace("/USDT", "")));
    }
//    @Test
//    public void getTradeHistoryOrderInfo() {
//        //获取用户ID
//        Long memberId = 3L;
//        List<TradeHistoryOrderInfoVo> myFollowOrderVos = new ArrayList<>();
//        //历史跟单
//        Page<ContractOrderEntity> page = new Page<>(1, 5);
//        IPage<ContractOrderEntity> contractOrderEntitys = followFollowerProfitDao.getMyFollowOrderHistoryRecords(page, memberId);
//
//        List<ContractOrderEntity> records = contractOrderEntitys.getRecords();
//        if(CollUtil.isNotEmpty(records)) {
//            for(ContractOrderEntity contractOrderEntity : records) {
//                TradeHistoryOrderInfoVo myFollowOrderVo = new TradeHistoryOrderInfoVo();
//                //获取【跟随者-订单关联表】中的累计数据
//                BigDecimal allRewardAmount = BigDecimal.ZERO;
//                BigDecimal allRewardRatio = BigDecimal.ZERO;
//
//                Long orderId = contractOrderEntity.getId();
//                String orderNo = contractOrderEntity.getOrderNo();
//                Map<String, Object> columnMapRelation = new HashMap<>();
//                columnMapRelation.put("trade_order_no", orderNo);
//                columnMapRelation.put("trade_member_id", memberId);
//                columnMapRelation.put("order_type", 2);
//                columnMapRelation.put("is_show", 1);
//                List<FollowFollowerOrderRelationEntity> followFollowerOrderRelations = followFollowerOrderRelationDao.selectByMap(columnMapRelation);
//                if(CollUtil.isNotEmpty(followFollowerOrderRelations)) {
//                    int size = followFollowerOrderRelations.size() - 1;
//                    myFollowOrderVo.setFollowerNumber(size);
//                    for(FollowFollowerOrderRelationEntity followFollowerOrderRelation : followFollowerOrderRelations) {
//                        Long followerMemberId = followFollowerOrderRelation.getMemberId();
//                        if(!memberId.equals(followerMemberId)) {
//                            Long followerOrderId = followFollowerOrderRelation.getOrderId();
//                            ContractOrderEntity orderEntity = contractOrderDao.selectById(followerOrderId);
//                            BigDecimal rewardAmount = orderEntity.getRewardAmount();
//                            allRewardAmount = allRewardAmount.add(rewardAmount);
//                            BigDecimal rewardRatio = orderEntity.getRewardRatio();
//                            allRewardRatio = allRewardRatio.add(rewardRatio);
//                        }
//                    }
//                }else {
//                    myFollowOrderVo.setFollowerNumber(0);
//                }
//                myFollowOrderVo.setFollowerRewardAmount(allRewardAmount);
//                myFollowOrderVo.setFollowerRewardRatio(allRewardRatio);
//
//                //获取交易员信息
//                FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectTraderInfoByMemberId(memberId);
//                String nickname = followTraderInfoEntity.getNickname();
//                myFollowOrderVo.setNickname(nickname);
//                myFollowOrderVo.setOrderId(orderId);
//                String symbol = contractOrderEntity.getSymbol();
//                myFollowOrderVo.setSymbol(symbol);
//                int orderType = contractOrderEntity.getOrderType();
//                myFollowOrderVo.setOrderType(orderType);
//                int leverRatio = contractOrderEntity.getLeverRatio();
//                myFollowOrderVo.setLeverRatio(leverRatio);
//                BigDecimal rewardAmount = contractOrderEntity.getRewardAmount().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setRewardAmount(rewardAmount);
//                BigDecimal rewardRatio = contractOrderEntity.getRewardRatio().setScale(4, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setRewardRatio(rewardRatio);
//                int symbolCnt = contractOrderEntity.getSymbolCnt();
//                myFollowOrderVo.setSymbolCnt(symbolCnt);
//                BigDecimal bondAmount = contractOrderEntity.getBondAmount().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setBondAmount(bondAmount);
//                BigDecimal openingPrice = contractOrderEntity.getOpeningPrice().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setOpeningPrice(openingPrice);
//                BigDecimal closingPrice = contractOrderEntity.getClosingPrice().setScale(2, BigDecimal.ROUND_DOWN);
//                myFollowOrderVo.setClosingPrice(closingPrice);
//                Date openingTime = contractOrderEntity.getOpeningTime();
//                myFollowOrderVo.setOpeningTime(openingTime);
//                Date closingTime = contractOrderEntity.getClosingTime();
//                myFollowOrderVo.setClosingTime(closingTime);
//
//                myFollowOrderVo.setOrderNo(orderNo);
//                myFollowOrderVos.add(myFollowOrderVo);
//            }
//        }
//        System.out.println(myFollowOrderVos);
//    }
    @Autowired
    private FollowProducer followProducer;
    
//    @Test
//    public void getHistoryMyFollowOrderRecords() {
//        //获取用户ID
//        Long memberId = 4L;
//        List<MyFollowOrderVo> myFollowOrderVos = new ArrayList<>();
//        //历史跟单
//            Page<ContractOrderEntity> page = new Page<>(1, 5);
//            IPage<ContractOrderEntity> contractOrderEntitys = followFollowerProfitDao.getMyFollowOrderHistoryRecords(page, memberId);
//
//            List<ContractOrderEntity> records = contractOrderEntitys.getRecords();
//            if(CollUtil.isNotEmpty(records)) {
//                for(ContractOrderEntity contractOrderEntity : records) {
//                    MyFollowOrderVo myFollowOrderVo = new MyFollowOrderVo();
//                    //获取交易员信息
//                    Long orderId = contractOrderEntity.getId();
//                    FollowFollowerOrderRelationEntity FollowFollowerOrderRelation = followFollowerOrderRelationDao.selectHistoryOneByorderId(orderId);
//                    if(ObjectUtil.isNotEmpty(FollowFollowerOrderRelation)) {
//                        myFollowOrderVo.setOrderId(orderId);
//                        Long tradeId = FollowFollowerOrderRelation.getTradeId();
//                        FollowTraderInfoEntity followTraderInfoEntity = followTraderInfoDao.selectById(tradeId);
//                        if(ObjectUtil.isNotEmpty(followTraderInfoEntity)) {
//                            String nickname = followTraderInfoEntity.getNickname();
//                            myFollowOrderVo.setNickname(nickname);
//                        }
//                        String symbol = contractOrderEntity.getSymbol();
//                        myFollowOrderVo.setSymbol(symbol);
//                        int orderType = contractOrderEntity.getOrderType();
//                        myFollowOrderVo.setOrderType(orderType);
//                        int leverRatio = contractOrderEntity.getLeverRatio();
//                        myFollowOrderVo.setLeverRatio(leverRatio);
//                        BigDecimal rewardAmount = contractOrderEntity.getRewardAmount().setScale(2, BigDecimal.ROUND_DOWN);
//                        myFollowOrderVo.setRewardAmount(rewardAmount);
//                        BigDecimal rewardRatio = contractOrderEntity.getRewardRatio().setScale(4, BigDecimal.ROUND_DOWN);
//                        myFollowOrderVo.setRewardRatio(rewardRatio);
//                        int symbolCnt = contractOrderEntity.getSymbolCnt();
//                        myFollowOrderVo.setSymbolCnt(symbolCnt);
//                        BigDecimal bondAmount = contractOrderEntity.getBondAmount().setScale(2, BigDecimal.ROUND_DOWN);
//                        myFollowOrderVo.setBondAmount(bondAmount);
//                        BigDecimal openingPrice = contractOrderEntity.getOpeningPrice().setScale(2, BigDecimal.ROUND_DOWN);
//                        myFollowOrderVo.setOpeningPrice(openingPrice);
//                        BigDecimal closingPrice = contractOrderEntity.getClosingPrice().setScale(2, BigDecimal.ROUND_DOWN);
//                        myFollowOrderVo.setClosingPrice(closingPrice);
//                        Date openingTime = contractOrderEntity.getOpeningTime();
//                        myFollowOrderVo.setOpeningTime(openingTime);
//                        Date closingTime = contractOrderEntity.getClosingTime();
//                        myFollowOrderVo.setClosingTime(closingTime);
//                        String orderNo = contractOrderEntity.getOrderNo();
//                        myFollowOrderVo.setOrderNo(orderNo);
//                        myFollowOrderVos.add(myFollowOrderVo);
//                    }
//                }
//            }
//        System.out.println(myFollowOrderVos);
//    }
//    @Test
//    public void test() {
//        //查询是否可以点击平仓按钮
//        Long memberIdLong = Long.parseLong("102");
//        MemberEntity selectById = memberDao.selectById(memberIdLong);
//        Integer pcState = selectById.getPcState();
//        if(memberEntity.PCSTATE_N == pcState) {
//            return Result.loading("loading_type");
//        }
//    }
//    @Test
//    public void add() {
//        Map<String, Object> columnMap = new HashMap<>();
//        List<MemberEntity> memberEntitys = memberDao.selectByMap(columnMap);
//        int i =0;
//        for(MemberEntity member :memberEntitys) {
//            System.out.println(i++);
//            Long id = member.getId();
//            if(ObjectUtil.isNotEmpty(id)) {
//                //获取开始中的活动
//                ActivityMain activityMain = activityMainDao.selectById(1);
//                if(ObjectUtil.isNotEmpty(activityMain)) {
//                    if(ActivityMain.STATE_START == activityMain.getState()) {
//                        //新增【活动记录表】信息
//                        ActivityReceiveRecord activityReceiveRecord = new ActivityReceiveRecord();
//                        activityReceiveRecord.setMemberId(member.getId());
//                        activityReceiveRecord.setMainId(activityMain.getId());
//                        activityReceiveRecord.setReceiveCoinAmount(BigDecimal.ZERO);
//                        activityReceiveRecord.setReceiveState(ActivityReceiveRecord.RECEIVESTATE_TWO);
//                        Date startTime = new Date();
//                        Date date = new Date(startTime.getTime() + ActivityReceiveRecord.DAYS*24*60*60*1000);
//                        activityReceiveRecord.setInvalidTime(date);
//                        Map<String, Object> activitySubMap = new HashMap<>();
//                        activitySubMap.put("main_id", activityMain.getId());
//                        List<ActivitySub> activitySubs = activitySubDao.selectByMap(activitySubMap );
//                        if(CollUtil.isNotEmpty(activitySubs)) {
//                            for(ActivitySub ActivitySub : activitySubs) {
//                                Long subId = ActivitySub.getId();
//                                activityReceiveRecord.setSubId(subId);
//                                activityReceiveRecordDao.insert(activityReceiveRecord);
//                            }
//                        }
//                        //新增【活动个人详情表】信息
//                        ActivityMemberDetail activityMemberDetail = new ActivityMemberDetail();
//                        activityMemberDetail.setMainId(activityMain.getId());
//                        activityMemberDetail.setBurstUsdt(BigDecimal.ZERO);
//                        activityMemberDetail.setReceivedUsdt(BigDecimal.ZERO);
//                        activityMemberDetail.setSurplusUsdt(activityMain.getAmount());
//                        activityMemberDetail.setMemberId(member.getId());
//                        activityMemberDetailDao.insert(activityMemberDetail);
//                    }
//                }
//            }
//        }
//    }
//    @Test
//    public void addFollowTest() {
//        followOrderOperationService.addFollowerOrder(601L);
////        ThreadPoolUtils.sendFollowOrderTask(601L);
//
//    }
//
//    @Test
//    public void strContainsTest() {
//        String symbols = "BTC,ETH,LTC,BCH";
//        String symbol = "BTC/USDT";
//
//        System.out.println(symbols.contains(symbol.replace("/USDT", "")));
//    }
//
//    @Resource
//    private FollowProfitUpdateJob followProfitUpdateJob;
//
//    @Test
//    public void updateJobTest() {
//        followProfitUpdateJob.traderProfitUpdate();
//    }
    @Test
    public void sendMsgTest() {
//        followProducer.sendChangeFollowOrderBond(11L, new BigDecimal("1234.1234"));
    }
}