| | |
| | | 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.ContractHoldOrderDao; |
| | | import com.xcong.excoin.modules.contract.dao.ContractOrderDao; |
| | | 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.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); |
| | |
| | | EXECUTOR.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | followOrderOperationService.addFollowerOrder(id); |
| | | 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() { |
| | | @Override |
| | | public void run() { |
| | | log.info("全仓操作价格"); |
| | | ContractHoldOrderDao contractHoldOrderDao = SpringContextHolder.getBean(ContractHoldOrderDao.class); |
| | | RedisUtils redisUtils = SpringContextHolder.getBean(RedisUtils.class); |
| | | MemberWalletContractDao memberWalletContractDao = SpringContextHolder.getBean(MemberWalletContractDao.class); |
| | | |
| | | List<ContractHoldOrderEntity> holdOrders = contractHoldOrderDao.selectHoldOrderListByMemberId(memberId); |
| | | if (CollUtil.isEmpty(holdOrders)) { |
| | | return; |
| | | } |
| | | MemberWalletContractEntity wallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberId, CoinTypeEnum.USDT.name()); |
| | | |
| | | WholePriceDataModel wholePriceData = new WholePriceDataModel(); |
| | | List<HoldOrderDataModel> holdOrderDataModels = ContractHoldOrderEntityMapper.INSTANCE.entitiesToDataModels(holdOrders); |
| | | wholePriceData.setList(holdOrderDataModels); |
| | | |
| | | BigDecimal totalHoldBond = BigDecimal.ZERO; |
| | | for (ContractHoldOrderEntity holdOrder : holdOrders) { |
| | | totalHoldBond = totalHoldBond.add(holdOrder.getHoldBond() == null ? BigDecimal.ZERO : holdOrder.getHoldBond()); |
| | | } |
| | | |
| | | wholePriceData.setHoldBond(totalHoldBond); |
| | | wholePriceData.setBalance(wallet.getTotalBalance()); |
| | | wholePriceData.setMemberId(memberId); |
| | | |
| | | OrderProducer orderProducer = SpringContextHolder.getBean(OrderProducer.class); |
| | | |
| | | orderProducer.sendWholePrice(JSONObject.toJSONString(wholePriceData)); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | } |