<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.copy.trade.dao.CopiedTradeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.copy.trade.entity.po.CopiedTrade">
    <result column="id" property="id" />
    <result column="created_time" property="createdTime" />
    <result column="updated_time" property="updatedTime" />
        <result column="customer_id" property="customerId" />
        <result column="trader_id" property="traderId" />
        <result column="entrust_no" property="entrustNo" />
        <result column="contract_order_entrust_id" property="contractOrderEntrustId" />
        <result column="symbol" property="symbol" />
        <result column="contract_symbol_id" property="contractSymbolId" />
        <result column="order_type" property="orderType" />
        <result column="direction" property="direction" />
        <result column="entrust_price" property="entrustPrice" />
        <result column="trigger_price" property="triggerPrice" />
        <result column="leverage" property="leverage" />
        <result column="type" property="type" />
        <result column="volume" property="volume" />
        <result column="stop_loss_price" property="stopLossPrice" />
        <result column="stop_profit_price" property="stopProfitPrice" />
        <result column="copy_contract_order_entrust_id" property="copyContractOrderEntrustId" />
        <result column="principal_amount" property="principalAmount" />
        <result column="status" property="status" />
        <result column="entrust_time" property="entrustTime" />
        <result column="error" property="error" />
        <result column="open_price" property="openPrice" />
        <result column="position_id" property="positionId" />
    </resultMap>
    
    <select id="getOpenPriceByPositionId" resultType="java.math.BigDecimal">
     	select (sum(open_price*volume))/sum(volume) 
     	from copied_trade where position_id = #{positionId}

    </select>
    
</mapper>
