|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import javax.annotation.Resource; | 
|---|
|  |  |  | import java.math.BigDecimal; | 
|---|
|  |  |  | import java.math.RoundingMode; | 
|---|
|  |  |  | import java.util.List; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private CommonService commonService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Resource | 
|---|
|  |  |  | private OrderProducer producer; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Transactional(rollbackFor = Exception.class) | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 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("委托失败"); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @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); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | 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()); | 
|---|