Helius
2021-09-07 1e4cab335b1cb68ad3438e522ea410c2d2e753ed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?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.xcong.excoin.modules.contract.dao.ContractOrderDao">
 
    <select id="selectOrderNoByOrderIds" resultType="java.lang.String">
        SELECT
            order_no
        FROM
            contract_order
        WHERE
              id = #{orderId}
    </select>
 
    <select id="selectFollowOrderListByMemberId" resultType="com.xcong.excoin.modules.contract.entity.ContractOrderEntity">
        SELECT
            *
        FROM
            contract_order
        WHERE
            member_id = #{tradeMemberId}
          AND contract_type = 2
          AND closing_price IS NOT NULL;
    </select>
 
    <select id="selectContractOrderInPage" resultType="com.xcong.excoin.modules.contract.entity.ContractOrderEntity">
        select
            create_time,
            id,
            member_id,
            order_no,
            position_type,
            trade_type,
            order_type,
            order_status,
            entrust_opening_price,
            entrust_time,
            symbol,
            symbol_cnt,
            symbol_sku,
            closing_price,
            closing_time,
            closing_fee_amount*(select fee_spread_ratio from platform_trade_setting) closing_fee_amount,
            closing_type,
            lever_ratio,
            stop_loss_price,
            stop_profit_price,
            reward_amount,
            reward_ratio,
            opening_price,
            opening_time,
            pre_payment_amount,
            bond_amount,
            mark_price,
            force_closing_price,
            hold_amount,
            opening_fee_amount*(select fee_spread_ratio from platform_trade_setting) opening_fee_amount
        from contract_order
        <if test="record != null">
            <where>
                <if test="record.memberId != null" >
                    and member_id=#{record.memberId}
                </if>
                <if test="record.symbol != null and record.symbol != ''">
                    and symbol = #{record.symbol}
                </if>
            </where>
        </if>
        order by create_time desc, id desc
    </select>
 
    <select id="selectOrderDetailByIdAndMemberId" resultType="com.xcong.excoin.modules.contract.entity.ContractOrderEntity">
        select * from contract_order where id=#{id} and member_id=#{memberId}
    </select>
 
    <select id="selectFollowOrderByMemberId" resultType="com.xcong.excoin.modules.contract.entity.ContractOrderEntity">
        select *
        from contract_order a, follow_follower_order_relation b
        where a.id=b.order_id and a.member_id=#{memberId}
    </select>
 
    <select id="selectFollowOrderTotalProfitByMemberId" resultType="java.math.BigDecimal">
        select sum(reward_ratio)*100
        from contract_order
        where member_id=#{memberId} and contract_type=2
    </select>
 
    <select id="selectFollowOrderCntForWinRate" resultType="java.math.BigDecimal">
        select count(1)
        from contract_order a
        where member_id=#{memberId}
        and contract_type=2
          and closing_time is not null
        <if test="type!=null and type==1">
            and reward_amount > 0
        </if>
        <if test="type!=null and type==2">
            and 0 > reward_amount
        </if>
    </select>
 
    <select id="selectWholeOpenOrderByOrderNo" resultType="com.xcong.excoin.modules.contract.entity.ContractOrderEntity">
        select * from contract_order
        where order_no=#{orderNo}
        and order_type in (1,2) and order_status=1
    </select>
 
    <select id="selectWholeFeeAmountByOrderNo" resultType="java.math.BigDecimal">
        select sum(opening_fee_amount)
        from contract_order
        where order_no=#{orderNo}
        and order_type in (1,2) and order_status=1
    </select>
 
    <update id="updateOrderProfitOrLessById">
        update contract_order
        set reward_amount=#{rewardAmount},
        reward_ratio=#{rewardRatio}
        where id=#{id}
    </update>
 
    <select id="getBurstUsdtByMemberId" resultType="java.math.BigDecimal">
        SELECT
            IFNULL(SUM(reward_amount), 0)
        FROM
            contract_order
        WHERE
            closing_type IN (4, 5)
            and member_id=#{memberId}
    </select>
 
    <select id="selectThirtyTotalCntByMemberId" resultType="java.math.BigDecimal">
        select count(id)
        from contract_order
        where
              member_id=#{memberId}
          and contract_type=2
          and closing_time is not null
          and create_time BETWEEN #{offsetDay} and #{date}
    </select>
 
    <select id="selectThirtyWinCntByMemberId" resultType="java.math.BigDecimal">
        select count(id)
        from contract_order
        where
        member_id=#{memberId}
        and contract_type=2
        and create_time BETWEEN #{offsetDay} and #{date}
        and reward_ratio > 0
    </select>
 
    <select id="selectThirtyMaxRatioByMemberId" resultType="java.math.BigDecimal">
        select MAX(reward_ratio)*100
        from contract_order
        where
        member_id=#{memberId}
        and contract_type=2
        and create_time BETWEEN #{offsetDay} and #{date}
    </select>
 
    <select id="selectThirtyMinRatioByMemberId" resultType="java.math.BigDecimal">
        select MIN(reward_ratio)*100
        from contract_order
        where
        member_id=#{memberId}
        and contract_type=2
        and create_time BETWEEN #{offsetDay} and #{date}
    </select>
</mapper>