Helius
2020-06-03 c86848ad0a97033f7a8bdcdf901b46bf866d9fb7
src/main/java/com/xcong/excoin/modules/contract/service/impl/OrderWebsocketServiceImpl.java
@@ -23,8 +23,11 @@
import com.xcong.excoin.rabbit.producer.OrderProducer;
import com.xcong.excoin.utils.CacheSettingUtils;
import com.xcong.excoin.utils.CalculateUtil;
import com.xcong.excoin.utils.ThreadPoolUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
@@ -34,6 +37,7 @@
/**
 * @author helius
 */
@Slf4j
@Service
public class OrderWebsocketServiceImpl {
@@ -122,6 +126,7 @@
    /**
     * 开多止盈
     */
    @Transactional(rollbackFor = Exception.class)
    public void dealForMoreStopPro(List<ContractHoldOrderEntity> orderList, List<OrderModel> list) {
        if (CollectionUtils.isNotEmpty(orderList)) {
            Map<Long, BigDecimal> modelMap = new HashMap<Long, BigDecimal>();
@@ -148,8 +153,8 @@
                    System.out.println("执行操作");
                    // 止盈价
                    String symbol = order.getSymbol();
                    // 本次需要退回的预付款
                    BigDecimal prePrice = order.getPrePaymentAmount();
                    // 本次需要退回的保证金
                    BigDecimal prePrice = order.getBondAmount();
                    Long memberId = order.getMemberId();
                    MemberWalletContractEntity wallet = memberWalletContractService.findWalletContractByMemberIdAndSymbol(memberId, "USDT");
                    if (wallet != null) {
@@ -164,7 +169,7 @@
                        // 盈亏额度= (当前的币种的平仓价-下单时的建仓价)*购买的手数/规格*倍率
                        BigDecimal profitLossPrice = (closePrice
                                .subtract(order.getOpeningPrice()))
                                .multiply(new BigDecimal(currentFlat + ""))
                                .multiply(new BigDecimal(currentFlat))
                                .multiply(symbolSku).setScale(8, BigDecimal.ROUND_DOWN);
                        MemberEntity memberEntity = memberService.getById(memberId);
@@ -177,7 +182,7 @@
                            }
                        }
                        //回报率
                        BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getClosingFeeAmount())), 8, BigDecimal.ROUND_DOWN);
                        BigDecimal returnRate = profitLossPrice.divide((order.getPrePaymentAmount().subtract(contractOrderEntity.getOpeningFeeAmount())), 8, BigDecimal.ROUND_DOWN);
                        contractOrderEntity.setRewardAmount(profitLossPrice);
                        contractOrderEntity.setRewardRatio(returnRate);
                        contractOrderEntity.setClosingFeeAmount(order.getOpeningFeeAmount());
@@ -185,11 +190,12 @@
                        contractOrderEntity.setClosingType(6);
                        BigDecimal totalReturn = BigDecimal.ZERO;
                        contractOrderService.save(contractOrderEntity);
                        contractEntrustOrderService.removeById(order.getId());
                        // 将需要退回的减去手续费
                        BigDecimal needReturn = prePrice.add(profitLossPrice);
                        //总退回金额=保证金+收益-手续费
                        totalReturn = needReturn.subtract(contractOrderEntity.getClosingFeeAmount());
                        // 更新钱包
                        // 总的是收益-平仓手续费
                        BigDecimal totalBalance = profitLossPrice.subtract(contractOrderEntity.getClosingFeeAmount());
                        memberWalletContractService.increaseWalletContractBalanceById(totalBalance, totalReturn, null, wallet.getId());
@@ -198,7 +204,7 @@
                        insertAccountFlow(order, wallet, profitLossPrice, "止盈平仓");
                        //返佣
                        calYj(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, 2);
                        ThreadPoolUtils.calReturnMoney(order.getMemberId(), order.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_CLOSE);
                    }
                }
            }
@@ -554,7 +560,7 @@
                    producer.sendPriceOperate(JSONObject.toJSONString(model));
                }
                // 扣除手续费
                BigDecimal totalBalance = wallet.getTotalBalance().subtract(openFeePrice);
                BigDecimal totalBalance = openFeePrice.negate();
                contractEntrustOrderService.removeById(coinsCoinsOrder.getId());
                memberWalletContractService.increaseWalletContractBalanceById(null, totalBalance, null, wallet.getId());
                // TODO 531 待写