From db3cab89b47378ee0482ad5183f4f542d48309b8 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 08 Jun 2020 14:50:23 +0800
Subject: [PATCH] modify

---
 src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java |   35 ++++++++++++++++++++++++-----------
 1 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java b/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java
index c705603..40a9490 100644
--- a/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java
+++ b/src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractEntrustOrderServiceImpl.java
@@ -1,8 +1,10 @@
 package com.xcong.excoin.modules.contract.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xcong.excoin.common.LoginUserUtils;
 import com.xcong.excoin.common.enumerates.MemberWalletCoinEnum;
+import com.xcong.excoin.common.enumerates.RabbitPriceTypeEnum;
 import com.xcong.excoin.common.response.Result;
 import com.xcong.excoin.common.system.service.CommonService;
 import com.xcong.excoin.modules.contract.dao.ContractEntrustOrderDao;
@@ -17,6 +19,8 @@
 import com.xcong.excoin.modules.member.entity.MemberEntity;
 import com.xcong.excoin.modules.member.entity.MemberWalletContractEntity;
 import com.xcong.excoin.modules.platform.entity.PlatformTradeSettingEntity;
+import com.xcong.excoin.rabbit.pricequeue.OrderModel;
+import com.xcong.excoin.rabbit.producer.OrderProducer;
 import com.xcong.excoin.utils.CacheSettingUtils;
 import com.xcong.excoin.utils.CoinTypeConvert;
 import com.xcong.excoin.utils.RedisUtils;
@@ -26,6 +30,7 @@
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.List;
 
 /**
@@ -53,6 +58,9 @@
 
     @Resource
     private CommonService commonService;
+
+    @Resource
+    private OrderProducer producer;
 
     @Transactional(rollbackFor = Exception.class)
     @Override
@@ -111,12 +119,19 @@
             // 暂默认逐仓
             entrustOrderEntity.setPositionType(ContractEntrustOrderEntity.POSITION_TYPE_ADD);
 
-//            int i = contractEntrustOrderDao.insert(entrustOrderEntity);
+            int i = contractEntrustOrderDao.insert(entrustOrderEntity);
 
-            walletContract.setFrozenBalance(walletContract.getFrozenBalance().add(entrustTotalAmount));
-            walletContract.setAvailableBalance(walletContract.getAvailableBalance().subtract(entrustTotalAmount));
-//            memberWalletContractDao.updateById(walletContract);
-            if (1 > 0) {
+            memberWalletContractDao.increaseWalletContractBalanceById(entrustTotalAmount.negate(), null, entrustOrderEntity.getBondAmount(), walletContract.getId());
+            if (i > 0) {
+
+                // 发送委托单队列消息
+                if (submitEntrustDto.getEntrustType() == ContractEntrustOrderEntity.ENTRUST_TYPE_OPEN_MORE) {
+                    OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_MORE.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol());
+                    producer.sendPriceOperate(JSONObject.toJSONString(model));
+                } else {
+                    OrderModel model = new OrderModel(entrustOrderEntity.getId(), RabbitPriceTypeEnum.ENTRUST_OPEN_LESS.getValue(), submitEntrustDto.getEntrustPrice().setScale(8, RoundingMode.HALF_UP).toPlainString(), submitEntrustDto.getSymbol());
+                    producer.sendPriceOperate(JSONObject.toJSONString(model));
+                }
                 return Result.ok("委托成功");
             } else {
                 return Result.fail("委托失败");
@@ -132,9 +147,9 @@
     }
 
     @Override
-    public Result findEntrustOrderList() {
+    public Result findEntrustOrderList(String symbol) {
         MemberEntity memberEntity = LoginUserUtils.getAppLoginUser();
-        List<ContractEntrustOrderEntity> list = contractEntrustOrderDao.selectEntrustOrderListByMemberId(memberEntity.getId());
+        List<ContractEntrustOrderEntity> list = contractEntrustOrderDao.selectEntrustOrderListByMemberIdAndSymbol(memberEntity.getId(), symbol);
         List<ContractEntrustVo> resultList = ContractEntrustOrderEntityMapper.INSTANCE.entityListToVoList(list);
         return Result.ok(resultList);
     }
@@ -153,13 +168,11 @@
         MemberWalletContractEntity walletContractEntity = memberWalletContractDao.findWalletContractByMemberIdAndSymbol(memberEntity.getId(), MemberWalletCoinEnum.WALLETCOINCODE.getValue());
 
         BigDecimal total = entrustOrderEntity.getEntrustAmount();
-        walletContractEntity.setAvailableBalance(walletContractEntity.getAvailableBalance().add(total));
-        walletContractEntity.setFrozenBalance(walletContractEntity.getFrozenBalance().subtract(total));
-        memberWalletContractDao.updateById(walletContractEntity);
+        memberWalletContractDao.increaseWalletContractBalanceById(total, null, entrustOrderEntity.getBondAmount().negate(), walletContractEntity.getId());
 
         ContractOrderEntity orderEntity = ContractEntrustOrderEntityMapper.INSTANCE.entrustOrderToOrder(entrustOrderEntity);
         orderEntity.setTradeType(ContractOrderEntity.TRADE_TYPE_MARK_PRICE);
-        orderEntity.setOrderType(ContractOrderEntity.ORDER_TYPE_CANCEL);
+        orderEntity.setOrderStatus(ContractOrderEntity.ORDER_STATUS_CANCEL);
         int i = contractOrderDao.insert(orderEntity);
 
         contractEntrustOrderDao.deleteById(entrustOrderEntity.getId());

--
Gitblit v1.9.1