zainali5120
2021-04-25 f9748a7b1d4d0c3638c758dd538459e635e92388
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package com.xcong.excoin.utils;
 
import cn.hutool.core.collection.CollUtil;
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao;
import com.xcong.excoin.modules.contract.dao.ContractHoldOrderDao;
import com.xcong.excoin.modules.contract.dao.ContractOrderDao;
import com.xcong.excoin.modules.contract.entity.ContractEntrustOrderEntity;
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.service.impl.OrderWebsocketServiceImpl;
import com.xcong.excoin.modules.documentary.service.FollowOrderOperationService;
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
import com.xcong.excoin.modules.member.entity.MemberEntity;
import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
import com.xcong.excoin.rabbit.pricequeue.whole.HoldOrderDataModel;
import com.xcong.excoin.rabbit.pricequeue.whole.WholePriceDataModel;
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.dingtalk.DingTalkUtils;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
 
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
 
/**
 * @author wzy
 * @date 2020-06-01
 **/
@Slf4j
public class ThreadPoolUtils {
 
    public static final ExecutorService EXECUTOR = Executors.newFixedThreadPool(20);
 
    /**
     * 计算佣金
     *
     * @param id     用户ID
     * @param price  手续费
     * @param entity 订单实体
     * @param type   订单类型
     */
    public static void calReturnMoney(Long id, BigDecimal price, ContractOrderEntity entity, int type) {
        OrderWebsocketServiceImpl orderWebsocketService = SpringContextHolder.getBean(OrderWebsocketServiceImpl.class);
        EXECUTOR.execute(new Runnable() {
            @Override
            public void run() {
                orderWebsocketService.calYj(id, price, entity, type);
            }
        });
    }
 
    /**
     * 发送钉钉消息
     *
     * @param type 类型
     */
    public static void sendDingTalk(int type) {
        EXECUTOR.execute(new Runnable() {
            @Override
            public void run() {
                DingTalkUtils.sendActionCard(type);
            }
        });
    }
 
    public static void sendFollowOrderTask(Long id) {
        FollowOrderOperationService followOrderOperationService = SpringContextHolder.getBean(FollowOrderOperationService.class);
        EXECUTOR.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    followOrderOperationService.addFollowerOrder(id);
                } catch (Exception e) {
                    log.error("产生跟单任务报错", e);
                }
            }
        });
    }
 
    /**
     * 全仓模式 -- 预估强平价
     *
     * @param symbol       币种
     * @param memberEntity 会员信息
     */
    public static void sendWholeForceClosingPrice(@NotNull String symbol, @NotNull MemberEntity memberEntity) {
        EXECUTOR.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    CalculateUtil.getForceSetPriceForWhole(null, memberEntity);
                } catch (Exception e) {
                    log.error("全仓模式预估强平价", e);
                }
            }
        });
    }
 
    /**
     * 发送全仓价格操作
     *
     * @param memberId
     */
    public static void sendWholePrice(@NotNull Long memberId) {
        EXECUTOR.execute(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(500);
                log.info("全仓操作价格");
                OrderProducer orderProducer = SpringContextHolder.getBean(OrderProducer.class);
                orderProducer.sendWholePrice(memberId.toString());
            }
        });
    }
}