<?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.muchinfo.mtp3interface.mapper.ITradepositionMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.muchinfo.mtp3pojos.entity.Tradeposition">
        <id column="ACCOUNTID" property="accountid" />
        <result column="GOODSID" property="goodsid" />
        <result column="HOLDERTYPE" property="holdertype" />
        <result column="BUYPOSITIONQTY" property="buypositionqty" />
        <result column="BUYHOLDERAMOUNT" property="buyholderamount" />
        <result column="BUYCURPOSITIONQTY" property="buycurpositionqty" />
        <result column="BUYCURHOLDERAMOUNT" property="buycurholderamount" />
        <result column="BUYFROZENQTY" property="buyfrozenqty" />
        <result column="BUYOTHERFROZENQTY" property="buyotherfrozenqty" />
        <result column="BUYOPENREQQTY" property="buyopenreqqty" />
        <result column="BUYOPENTOTALQTY" property="buyopentotalqty" />
        <result column="BUYCLOSETOTALQTY" property="buyclosetotalqty" />
        <result column="SELLPOSITIONQTY" property="sellpositionqty" />
        <result column="SELLHOLDERAMOUNT" property="sellholderamount" />
        <result column="SELLCURPOSITIONQTY" property="sellcurpositionqty" />
        <result column="SELLCURHOLDERAMOUNT" property="sellcurholderamount" />
        <result column="SELLFROZENQTY" property="sellfrozenqty" />
        <result column="SELLOTHERFROZENQTY" property="sellotherfrozenqty" />
        <result column="SELLOPENREQQTY" property="sellopenreqqty" />
        <result column="SELLOPENTOTALQTY" property="sellopentotalqty" />
        <result column="SELLCLOSETOTALQTY" property="sellclosetotalqty" />
        <result column="USEDMARGIN" property="usedmargin" />
        <result column="TRADEPROPERTY" property="tradeproperty" />
        <result column="BUYTNQTY" property="buytnqty" />
        <result column="BUYTNUSEDQTY" property="buytnusedqty" />
        <result column="SELLTNQTY" property="selltnqty" />
        <result column="SELLTNUSEDQTY" property="selltnusedqty" />
        <result column="BUYCURTDPOSITION" property="buycurtdposition" />
        <result column="BUYFRETDPOSITION" property="buyfretdposition" />
        <result column="SELLCURTDPOSITION" property="sellcurtdposition" />
        <result column="SELLFRETDPOSITION" property="sellfretdposition" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ACCOUNTID, GOODSID, HOLDERTYPE, BUYPOSITIONQTY, BUYHOLDERAMOUNT, BUYCURPOSITIONQTY, BUYCURHOLDERAMOUNT, BUYFROZENQTY, BUYOTHERFROZENQTY, BUYOPENREQQTY, BUYOPENTOTALQTY, BUYCLOSETOTALQTY, SELLPOSITIONQTY, SELLHOLDERAMOUNT, SELLCURPOSITIONQTY, SELLCURHOLDERAMOUNT, SELLFROZENQTY, SELLOTHERFROZENQTY, SELLOPENREQQTY, SELLOPENTOTALQTY, SELLCLOSETOTALQTY, USEDMARGIN, TRADEPROPERTY, BUYTNQTY, BUYTNUSEDQTY, SELLTNQTY, SELLTNUSEDQTY, BUYCURTDPOSITION, BUYFRETDPOSITION, SELLCURTDPOSITION, SELLFRETDPOSITION
    </sql>

    <select id="queryAmount" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select r.* from TradePosition r,Taaccount t
        where r.accountid = t.accountid and r.buycurpositionqty >0
          and r.sellcurpositionqty >0 and t.userid=#{areaid}
    </select>

    <select id="queryPositionByUserid" resultType="java.lang.Integer" parameterType="java.lang.Long">
        select count(t.*)
        from tradeposition t,
             taaccount ta,
             goods g,
             market m
        where t.accountid = ta.accountid
          and t.goodsid = g.goodsid
          and g.marketid = m.marketid
          and m.trademode = 10
          and t.tradeproperty = 1
          and ta.userid = #{userid}
    </select>
    <select id="getTradePosition" resultType="com.muchinfo.mtp3pojos.entity.Tradeposition">
        SELECT TP.BuyCurPositionQty,
               TP.BuyFrozenQty,
               TP.BuyOtherFrozenQty
        FROM quoter q,
             arearole A,
             TradePosition tp
        WHERE q.QUOTERSTATUS = 1
          AND q.DEFAULTMAKERID = A.USERID
          AND A.ROLETYPE = 8
          AND TP.ACCOUNTID = A.TRADEACCOUNTID
          AND q.QUOTERID = #{quoterid,jdbcType=DECIMAL}
          AND TP.GOODSID = #{goodsid,jdbcType=DECIMAL}
    </select>

</mapper>
