zj
2024-06-03 287ac389edd047696d956afafdb855a93830bc0c
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
<?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.nq.dao.SiteSpreadMapper">
 
    <resultMap id="BaseResultMap" type="com.nq.pojo.SiteSpread" >
        <result column="id" property="id" />
        <result column="type_name" property="typeName" />
        <result column="unit" property="unit" />
        <result column="start_interval" property="startInterval" />
        <result column="end_interval" property="endInterval" />
        <result column="spread_rate" property="spreadRate" />
        <result column="add_time" property="addTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>
 
    <sql id="Base_Column_List">
                id,
                type_name,
                unit,
                start_interval,
                end_interval,
                spread_rate,
                add_time,
                update_time
    </sql>
 
    <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id" parameterType="com.nq.pojo.SiteSpread">
        INSERT INTO site_spread
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test ='null != typeName'>
                type_name,
            </if>
            <if test ='null != unit'>
                unit,
            </if>
            <if test ='null != startInterval'>
                start_interval,
            </if>
            <if test ='null != endInterval'>
                end_interval,
            </if>
            <if test ='null != spreadRate'>
                spread_rate,
            </if>
            add_time,
            <if test ='null != updateTime'>
                update_time
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test ='null != typeName'>
                #{typeName},
            </if>
            <if test ='null != unit'>
                #{unit},
            </if>
            <if test ='null != startInterval'>
                #{startInterval},
            </if>
            <if test ='null != endInterval'>
                #{endInterval},
            </if>
            <if test ='null != spreadRate'>
                #{spreadRate},
            </if>
            now(),
            <if test ='null != updateTime'>
                #{updateTime}
            </if>
        </trim>
    </insert>
 
    <delete id="delete" >
        DELETE FROM site_spread
        WHERE id = #{id}
    </delete>
 
    <update id="update" parameterType="com.nq.pojo.SiteSpread">
        UPDATE site_spread
        <set>
            <if test ='null != typeName'>type_name = #{typeName},</if>
            <if test ='null != unit'>unit = #{unit},</if>
            <if test ='null != startInterval'>start_interval = #{startInterval},</if>
            <if test ='null != endInterval'>end_interval = #{endInterval},</if>
            <if test ='null != spreadRate'>spread_rate = #{spreadRate},</if>
            <if test ='null != addTime'>add_time = #{addTime},</if>
            update_time = now()
        </set>
        WHERE id = #{id}
    </update>
 
 
    <select id="load" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM site_spread
        WHERE id = #{id}
    </select>
 
    <select id="pageList" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM site_spread
        where 1=1
        <if test="null != typeName and typeName != ''">
            and type_name = #{typeName}
        </if>
        order by id asc,type_name asc
    </select>
 
    <select id="pageListCount" resultType="java.lang.Integer">
        SELECT count(1)
        FROM site_spread
    </select>
 
    <!--查询点差费率-->
    <select id="findSpreadRateOne" resultMap="BaseResultMap">
        SELECT * from (
            SELECT type_name,spread_rate FROM `site_spread` WHERE type_name='涨跌幅' and start_interval &lt;=#{applies} and end_interval>#{applies}
            UNION ALL
            SELECT type_name,spread_rate FROM `site_spread` WHERE type_name='成交额' and start_interval &lt;=#{turnover} and end_interval>#{turnover}
            UNION ALL
            SELECT type_name,spread_rate FROM `site_spread` WHERE type_name='开头收取' and unit=left(#{code}, 3)
            UNION ALL
            SELECT type_name,spread_rate FROM `site_spread` WHERE type_name='低于收取' and start_interval &lt;=#{unitprice} and end_interval>#{unitprice}
            UNION ALL
            SELECT '股票点差' type_name,spread_rate FROM stock WHERE stock_code=#{code} and spread_rate>0
        ) k ORDER BY k.spread_rate desc
        limit 1
    </select>
 
</mapper>