Helius
2020-08-04 ea8eb9c441bb4452d153579b456467b2f5e958e4
add trader closing order
8 files modified
75 ■■■■ changed files
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/RabbitOrderServiceImpl.java 34 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerOrderRelationDao.java 4 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/entity/FollowFollowerOrderRelationEntity.java 2 ●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/service/FollowOrderOperationService.java 5 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java 19 ●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/utils/ThreadPoolUtils.java 2 ●●● patch | view | raw | blame | history
src/main/resources/mapper/documentary/FollowFollowerOrderRelationDao.xml 7 ●●●●● patch | view | raw | blame | history
src/main/java/com/xcong/excoin/modules/contract/service/impl/ContractHoldOrderServiceImpl.java
@@ -213,7 +213,7 @@
                relationEntity.setOrderType(FollowFollowerOrderRelationEntity.ORDER_TYPE_HOLD);
                relationEntity.setTradeId(tradeInfo.getId());
                relationEntity.setTradeMemberId(tradeInfo.getMemberId());
                relationEntity.setTradeOrderId(holdOrderEntity.getId());
                relationEntity.setTradeOrderNo(holdOrderEntity.getOrderNo());
                followFollowerOrderRelationDao.insert(relationEntity);
                ThreadPoolUtils.sendFollowOrderTask(holdOrderEntity.getId());
src/main/java/com/xcong/excoin/modules/contract/service/impl/RabbitOrderServiceImpl.java
@@ -10,6 +10,9 @@
import com.xcong.excoin.modules.contract.entity.ContractOrderEntity;
import com.xcong.excoin.modules.contract.mapper.ContractHoldOrderEntityMapper;
import com.xcong.excoin.modules.contract.service.RabbitOrderService;
import com.xcong.excoin.modules.documentary.dao.FollowFollowerOrderRelationDao;
import com.xcong.excoin.modules.documentary.entity.FollowFollowerOrderRelationEntity;
import com.xcong.excoin.modules.documentary.service.FollowOrderOperationService;
import com.xcong.excoin.modules.member.dao.MemberDao;
import com.xcong.excoin.modules.member.dao.MemberWalletContractDao;
import com.xcong.excoin.modules.member.entity.AgentReturnEntity;
@@ -58,6 +61,11 @@
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private FollowFollowerOrderRelationDao followFollowerOrderRelationDao;
    @Resource
    private FollowOrderOperationService followOrderOperationService;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public void cancelHoldOrder(List<Long> ids) {
@@ -76,6 +84,7 @@
        }
    }
    @Transactional(rollbackFor = Exception.class)
    public void cancelHoldOrderMethod(ContractHoldOrderEntity holdOrderEntity) {
        String symbol = holdOrderEntity.getSymbol();
        // 获取最新价
@@ -141,7 +150,32 @@
            // 计算佣金
            ThreadPoolUtils.calReturnMoney(memberEntity.getId(), contractOrderEntity.getClosingFeeAmount(), contractOrderEntity, AgentReturnEntity.ORDER_TYPE_CLOSE);
            // 判断当前持仓是否为跟单订单
            if (ContractOrderEntity.CONTRACTTYPE_DOCUMENTARY == holdOrderEntity.getContractType()) {
                updateFollowOrderRelation(holdOrderEntity.getId(), contractOrderEntity.getId());
                // 若为交易员,则平仓跟随者订单
                if (MemberEntity.IS_TRADER_Y.equals(memberEntity.getIsTrader())) {
                    followOrderOperationService.closingFollowOrders(holdOrderEntity.getOrderNo());
                }
            }
        }
    }
    /**
     * 更新跟单订单关系
     *
     * @param oldOrderId 当前持仓ID
     * @param newOrderId 历史订单ID
     */
    public void updateFollowOrderRelation(Long oldOrderId, Long newOrderId) {
        FollowFollowerOrderRelationEntity orderRelationEntity = followFollowerOrderRelationDao.selectNowOneByorderId(oldOrderId);
        if (orderRelationEntity != null) {
            orderRelationEntity.setOrderId(newOrderId);
            orderRelationEntity.setOrderType(FollowFollowerOrderRelationEntity.ORDER_TYPE_HISTORY);
            followFollowerOrderRelationDao.updateById(orderRelationEntity);
        }
    }
}
src/main/java/com/xcong/excoin/modules/documentary/dao/FollowFollowerOrderRelationDao.java
@@ -4,6 +4,8 @@
import com.xcong.excoin.modules.documentary.entity.FollowFollowerOrderRelationEntity;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
 * @author helius
 */
@@ -13,4 +15,6 @@
    FollowFollowerOrderRelationEntity selectHistoryOneByorderId(@Param("orderId")Long orderId);
    
    FollowFollowerOrderRelationEntity selectNowOneByorderId(@Param("orderId")Long orderId);
    List<FollowFollowerOrderRelationEntity> selectFollowHoldOrderByTradeOrderNo(@Param("orderNo") String orderNo);
}
src/main/java/com/xcong/excoin/modules/documentary/entity/FollowFollowerOrderRelationEntity.java
@@ -38,7 +38,7 @@
    /**
     * 跟单订单ID
     */
    private Long tradeOrderId;
    private String tradeOrderNo;
    /**
     * 交易员用户ID
src/main/java/com/xcong/excoin/modules/documentary/service/FollowOrderOperationService.java
@@ -19,7 +19,8 @@
    /**
     * 跟随者订单平仓
     *
     * @param id 交易员持仓ID
     * @param oldOrderId 交易员持仓ID
     * @param newOrderId 交易员平仓后历史ID
     */
    public void closingFollowOrders(Long id);
    public void closingFollowOrders(String orderNo);
}
src/main/java/com/xcong/excoin/modules/documentary/service/impl/FollowOrderOperationServiceImpl.java
@@ -13,6 +13,7 @@
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.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;
@@ -41,6 +42,7 @@
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -71,6 +73,9 @@
    private OrderProducer producer;
    @Resource
    private FollowTraderInfoDao followTraderInfoDao;
    @Resource
    private RabbitOrderService rabbitOrderService;
    @Override
@@ -178,7 +183,7 @@
                    relationEntity.setOrderType(FollowFollowerOrderRelationEntity.ORDER_TYPE_HOLD);
                    relationEntity.setTradeId(followTraderInfoEntity.getId());
                    relationEntity.setTradeMemberId(followTraderInfoEntity.getMemberId());
                    relationEntity.setTradeOrderId(id);
                    relationEntity.setTradeOrderNo(holdOrderEntity.getOrderNo());
                    followFollowerOrderRelationDao.insert(relationEntity);
                    // 发送爆仓消息
@@ -212,8 +217,16 @@
        producer.sendPriceOperate(JSONObject.toJSONString(model));
    }
    @Override
    public void closingFollowOrders(Long id) {
    @Override
    public void closingFollowOrders(String orderNo) {
        List<FollowFollowerOrderRelationEntity> orderRelations = followFollowerOrderRelationDao.selectFollowHoldOrderByTradeOrderNo(orderNo);
        if (CollUtil.isNotEmpty(orderRelations)) {
            for (FollowFollowerOrderRelationEntity orderRelation : orderRelations) {
                List<Long> ids= new ArrayList<>();
                ids.add(orderRelation.getOrderId());
                rabbitOrderService.cancelHoldOrder(ids);
            }
        }
    }
}
src/main/java/com/xcong/excoin/utils/ThreadPoolUtils.java
@@ -59,7 +59,7 @@
                try {
                    followOrderOperationService.addFollowerOrder(id);
                } catch (Exception e) {
                    log.info("--->", e);
                    log.error("产生跟单任务报错", e);
                }
            }
        });
src/main/resources/mapper/documentary/FollowFollowerOrderRelationDao.xml
@@ -25,5 +25,12 @@
            follow_follower_order_relation 
        WHERE order_id = #{orderId} and order_type = 1
    </select>
    <select id="selectFollowHoldOrderByTradeOrderNo" resultType="com.xcong.excoin.modules.documentary.entity.FollowFollowerOrderRelationEntity">
        select a.*
        from follow_follower_order_relation a, follow_follower_profit b
        where a.trade_member_id=b.trade_member_id and a.trade_order_no=#{orderNo} and b.is_follow=1
        and a.order_type=1
    </select>
    
</mapper>