From e73c7fd66e6afdc139374f788515164acc6e8670 Mon Sep 17 00:00:00 2001
From: gao <gaoleox@163>
Date: Fri, 05 Jun 2020 11:56:46 +0800
Subject: [PATCH] 充值撤单
---
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java | 129 +++++++++++++++++++++++++++++--------------
1 files changed, 87 insertions(+), 42 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
index 858b2af..796710d 100644
--- a/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -3,6 +3,8 @@
import cn.hutool.core.collection.CollUtil;
import com.alibaba.druid.sql.visitor.functions.If;
import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xcong.excoin.common.LoginUserUtils;
import com.xcong.excoin.common.enumerates.CoinTypeEnum;
@@ -16,12 +18,12 @@
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.parameter.dto.ProfitOrLessDto;
-import com.xcong.excoin.modules.contract.parameter.dto.SubmitOrderDto;
-import com.xcong.excoin.modules.contract.parameter.dto.SymbolDto;
+import com.xcong.excoin.modules.contract.mapper.ContractOrderEntityMapper;
+import com.xcong.excoin.modules.contract.parameter.dto.*;
import com.xcong.excoin.modules.contract.parameter.vo.ContractMoneyInfoVo;
+import com.xcong.excoin.modules.contract.parameter.vo.HoldOrderDetailVo;
import com.xcong.excoin.modules.contract.parameter.vo.HoldOrderListVo;
+import com.xcong.excoin.modules.contract.parameter.vo.OrderListVo;
import com.xcong.excoin.modules.contract.service.ContractHoldOrderService;
import com.xcong.excoin.modules.member.dao.MemberLevelRateDao;
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
@@ -159,14 +161,13 @@
contractOrderEntity.setOpeningTime(new Date());
contractHoldOrderDao.insert(holdOrderEntity);
int i = contractOrderDao.insert(contractOrderEntity);
- memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), null, null, walletContract.getId());
-
- // 计算佣金
- ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN);
if (i > 0) {
- return Result.ok("success");
+ memberWalletContractDao.increaseWalletContractBalanceById(prePaymentAmount.negate(), openFeePrice.negate(), null, walletContract.getId());
+ // 计算佣金
+ ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getOpeningFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_OPEN);
+ return Result.ok("提交成功");
}
- return Result.fail("fail");
+ return Result.fail("提交失败");
}
@Override
@@ -189,6 +190,7 @@
MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
List<ContractHoldOrderEntity> list = contractHoldOrderDao.selectHoldOrderListByMemberIdAndSymbol(memberEntity.getId(), symbol);
+ MemberWalletContractEntity walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), CoinTypeEnum.USDT.name());
if (CollUtil.isNotEmpty(list)) {
BigDecimal totalProfitOrLoss = BigDecimal.ZERO;
List<HoldOrderListVo> resultList = new ArrayList<>();
@@ -228,12 +230,17 @@
.divide(new BigDecimal(holdOrderEntity.getLeverRatio()), 8, BigDecimal.ROUND_DOWN);
// 可增加最大保证金
- BigDecimal canAddMaxBond = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()).subtract(costPrice);
- if (canAddMaxBond.compareTo(BigDecimal.ZERO) < 0) {
- canAddMaxBond = BigDecimal.ZERO;
+// BigDecimal canAddMaxBond = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getOpeningFeeAmount()).subtract(costPrice);
+// if (canAddMaxBond.compareTo(BigDecimal.ZERO) < 0) {
+// canAddMaxBond = BigDecimal.ZERO;
+// }
+ BigDecimal canReduceMaxBond = holdOrderEntity.getBondAmount().subtract(holdOrderEntity.getPrePaymentAmount());
+ if (canReduceMaxBond.compareTo(BigDecimal.ZERO) < 0) {
+ canReduceMaxBond = BigDecimal.ZERO;
}
- holdOrderListVo.setCanAddMaxBond(canAddMaxBond);
+ holdOrderListVo.setCanReduceMaxBond(canReduceMaxBond);
+ holdOrderListVo.setCanAddMaxBond(walletContractEntity.getAvailableBalance());
holdOrderListVo.setReturnRate(returnRate);
holdOrderListVo.setProfitOrLoss(rewardRatio);
resultList.add(holdOrderListVo);
@@ -299,82 +306,86 @@
// 开仓价
BigDecimal openPrice = holdOrderEntity.getOpeningPrice();
// 设置的止盈止损价
- BigDecimal price = profitOrLessDto.getPrice();
+ BigDecimal stopProfitPrice = profitOrLessDto.getStopProfitPrice();
+
+ BigDecimal stopLessPrice = profitOrLessDto.getStopLessPrice();
// 开多
if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) {
- if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) {
+ if (stopProfitPrice != null) {
// 当前价大于开仓价
if (newPrice.compareTo(openPrice) > 0) {
// 如果止盈价小于当前价
- if (price.compareTo(newPrice) < 0) {
+ if (stopProfitPrice.compareTo(newPrice) < 0) {
return Result.fail("止盈价必须高于当前价");
}
} else {
- if (price.compareTo(openPrice) < 0) {
+ if (stopProfitPrice.compareTo(openPrice) < 0) {
return Result.fail("止盈价必须高于开仓价");
}
}
- } else {
+ }
+
+ if (stopLessPrice != null) {
if (newPrice.compareTo(openPrice) > 0) {
- if (price.compareTo(openPrice) > 0) {
+ if (stopLessPrice.compareTo(openPrice) > 0) {
return Result.fail("止损价必须低于开仓价");
}
} else {
- if (price.compareTo(newPrice) > 0) {
+ if (stopLessPrice.compareTo(newPrice) > 0) {
return Result.fail("止损价必须低于当前价");
}
}
}
// 开空
} else {
- if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) {
+ if (stopProfitPrice != null) {
if (newPrice.compareTo(openPrice) > 0) {
- if (price.compareTo(openPrice) > 0) {
+ if (stopProfitPrice.compareTo(openPrice) > 0) {
return Result.fail("止损价必须低于开仓价");
}
} else {
- if (price.compareTo(newPrice) > 0) {
+ if (stopProfitPrice.compareTo(newPrice) > 0) {
return Result.fail("止损价必须低于当前价");
}
}
- } else {
+ }
+ if (stopLessPrice != null) {
if (newPrice.compareTo(openPrice) > 0) {
- if (price.compareTo(newPrice) < 0) {
+ if (stopLessPrice.compareTo(newPrice) < 0) {
return Result.fail("止损价必须高于当前价");
}
} else {
- if (price.compareTo(openPrice) < 0) {
+ if (stopLessPrice.compareTo(openPrice) < 0) {
return Result.fail("止损价必须高于开仓价");
}
}
}
}
- if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) {
- holdOrderEntity.setStopProfitPrice(price);
- } else {
- holdOrderEntity.setStopLossPrice(price);
- }
+ holdOrderEntity.setStopProfitPrice(stopProfitPrice);
+ holdOrderEntity.setStopLossPrice(stopLessPrice);
int i = contractHoldOrderDao.updateById(holdOrderEntity);
if (i > 0) {
OrderModel model = null;
if (ContractHoldOrderEntity.OPENING_TYPE_MORE == holdOrderEntity.getOpeningType()) {
// 开多止盈
- if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) {
- model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
- // 开多止损
- } else {
- model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
+ if (stopProfitPrice != null) {
+ model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
+ }
+ // 开多止损
+ if (stopLessPrice != null) {
+ model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_MORE_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
}
} else {
// 开空止盈
- if (ProfitOrLessDto.TYPE_PROFIT == profitOrLessDto.getType()) {
- model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
- // 开空止损
- } else {
- model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), price.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
+ if (stopProfitPrice != null) {
+ model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_PROFIT.getValue(), stopProfitPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
+ }
+ // 开空止损
+ if (stopLessPrice != null) {
+ model = new OrderModel(holdOrderEntity.getId(), RabbitPriceTypeEnum.CLOSE_LESS_STOP_LESS.getValue(), stopLessPrice.setScale(8, RoundingMode.HALF_UP).toPlainString(), holdOrderEntity.getSymbol());
}
}
producer.sendPriceOperate(JSONObject.toJSONString(model));
@@ -505,4 +516,38 @@
contractMoneyInfoVo.setLeverRate(rateEntity.getLevelRateUp());
return Result.ok(contractMoneyInfoVo);
}
+
+ @Override
+ public Result changeLeverRate(ChangeLeverRateDto changeLeverRateDto) {
+ MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
+ MemberLevelRateEntity levelRateEntity = memberLevelRateDao.selectLeverRateByMemberIdAndSymbol(memberEntity.getId(), changeLeverRateDto.getSymbol());
+ levelRateEntity.setLevelRateUp(changeLeverRateDto.getLeverRate());
+ levelRateEntity.setLevelRateDown(changeLeverRateDto.getLeverRate());
+ int i = memberLevelRateDao.updateById(levelRateEntity);
+ if (i > 0) {
+ return Result.ok("调整成功");
+ }
+ return Result.fail("调整失败");
+ }
+
+ @Override
+ public Result findHoldOrderDetailById(Long id) {
+ MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
+ ContractHoldOrderEntity holdOrderEntity = contractHoldOrderDao.selectHoldOrderByMemberIdAndId(memberEntity.getId(), id);
+ if (holdOrderEntity == null) {
+ return Result.fail("订单不存在");
+ }
+
+ HoldOrderDetailVo holdOrderDetailVo = ContractHoldOrderEntityMapper.INSTANCE.holdOrderToOrderDetailVo(holdOrderEntity);
+ return Result.ok(holdOrderDetailVo);
+ }
+
+ @Override
+ public Result findOrderList(OrderListDto orderListDto) {
+ MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
+ Page<ContractOrderEntity> page = new Page<>(orderListDto.getPageNum(), orderListDto.getPageSize());
+ IPage<ContractOrderEntity> list = contractOrderDao.selectContractOrderInPage(page, memberEntity.getId());
+ Page<OrderListVo> result = ContractOrderEntityMapper.INSTANCE.pageEntityToPageVo(list);
+ return Result.ok(result);
+ }
}
--
Gitblit v1.9.1