Helius
2020-08-10 bc60c2e83e277421336c0583c6105d9da9308c4b
src/main/java/com/xcong/excoin/modules/contract/service/impl/RabbitOrderServiceImpl.java
@@ -13,6 +13,7 @@
import com.xcong.excoin.modules.contract.service.RabbitOrderService;
import com.xcong.excoin.modules.documentary.common.NoticeConstant;
import com.xcong.excoin.modules.documentary.dao.FollowFollowerOrderRelationDao;
import com.xcong.excoin.modules.documentary.dao.FollowFollowerProfitDao;
import com.xcong.excoin.modules.documentary.dao.FollowTraderInfoDao;
import com.xcong.excoin.modules.documentary.dao.FollowTraderProfitDetailDao;
import com.xcong.excoin.modules.documentary.entity.FollowFollowerOrderRelationEntity;
@@ -76,6 +77,8 @@
    private FollowTraderInfoDao followTraderInfoDao;
    @Resource
    private FollowTraderProfitDetailDao followTraderProfitDetailDao;
    @Resource
    private FollowFollowerProfitDao followFollowerProfitDao;
    @Transactional(rollbackFor = Exception.class)
    @Override
@@ -143,6 +146,9 @@
                }
            }
            // 盈亏比例(回报率)
            BigDecimal rewardRatio = profitOrLoss.divide(holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()), 8, BigDecimal.ROUND_DOWN);
            FollowTraderInfoEntity traderInfoEntity = null;
            // 判断当前订单是否为跟单
            if (ContractOrderEntity.CONTRACTTYPE_DOCUMENTARY == holdOrderEntity.getContractType()) {
@@ -151,7 +157,7 @@
                    traderInfoEntity = followTraderInfoDao.selectTraderInfoByOrderId(holdOrderEntity.getId());
                    if (profitOrLoss.compareTo(BigDecimal.ZERO) > 0) {
                        // 计算需返利给交易员的金额
                        BigDecimal returnMoney = profitOrLoss.subtract(traderInfoEntity.getProfitRatio());
                        BigDecimal returnMoney = profitOrLoss.multiply(traderInfoEntity.getProfitRatio());
                        profitOrLoss = profitOrLoss.subtract(returnMoney);
                        MemberWalletContractEntity traderWallet = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(traderInfoEntity.getMemberId(), CoinTypeEnum.USDT.name());
                        memberWalletContractDao.increaseWalletContractBalanceById(returnMoney, returnMoney, null, traderWallet.getId());
@@ -159,9 +165,6 @@
                    }
                }
            }
            // 盈亏比例(回报率)
            BigDecimal rewardRatio = profitOrLoss.divide(holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()), 8, BigDecimal.ROUND_DOWN);
            ContractOrderEntity contractOrderEntity = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToOrder(holdOrderEntity);
            contractOrderEntity.setId(null);
@@ -192,7 +195,8 @@
                if (MemberEntity.IS_TRADER_Y.equals(memberEntity.getIsTrader())) {
                    followOrderOperationService.closingFollowOrders(holdOrderEntity.getOrderNo());
                } else {
                    LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CLOSE_ORDER_TITLE, StrUtil.format(NoticeConstant.CLOSE_ORDER_CONTENT, contractOrderEntity.getSymbol(), contractOrderEntity.getClosingPrice(), profitOrLoss));
                    followFollowerProfitDao.updateFollowerProfitByTradeMemberId(holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()), profitOrLoss, traderInfoEntity.getMemberId(), memberEntity.getId());
                    LogRecordUtils.insertFollowerNotice(memberEntity.getId(), NoticeConstant.CLOSE_ORDER_TITLE, StrUtil.format(NoticeConstant.CLOSE_ORDER_CONTENT, contractOrderEntity.getSymbol(), contractOrderEntity.getClosingPrice(), profitOrLoss, traderInfoEntity.getNickname()));
                }
            }
        }
@@ -230,4 +234,11 @@
        profitDetailEntity.setOrderNo(orderNo);
        followTraderProfitDetailDao.insert(profitDetailEntity);
    }
    /**
     * 全仓模式平仓逻辑
     */
    public void closingWholeOrder(ContractHoldOrderEntity contractHoldOrderEntity) {
    }
}