yujian
2019-01-22 88b54772dbcf5ecab1e2316e4e4626ac901b8908
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?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.yeshi.fanli.dao.mybatis.HongBaoV2Mapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.HongBaoV2">
        <id column="hb_id" property="id" jdbcType="BIGINT" />
        <result column="hb_urank" property="urank" jdbcType="INTEGER" />
        <result column="hb_money" property="money" jdbcType="DECIMAL" />
        <result column="hb_type" property="type" jdbcType="INTEGER" />
        <result column="hb_state" property="state" jdbcType="INTEGER" />
        <result column="hb_version" property="version" jdbcType="INTEGER" />
        <result column="hb_beizhu" property="beizhu" jdbcType="VARCHAR" />
        <result column="hb_pre_get_time" property="preGetTime"
            jdbcType="TIMESTAMP" />
        <result column="hb_get_time" property="getTime" jdbcType="TIMESTAMP" />
        <result column="hb_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="hb_update_time" property="updateTime" jdbcType="TIMESTAMP" />
 
        <association property="userInfo" column="hb_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="hb_uid" property="id" jdbcType="BIGINT" />
        </association>
 
        <association property="parent" column="hb_pid"
            javaType="com.yeshi.fanli.entity.bus.user.HongBaoV2">
            <id column="hb_pid" property="id" jdbcType="BIGINT" />
        </association>
 
        <!-- <association property="userInfo" column="hb_uid" resultMap="com.yeshi.fanli.dao.mybatis.UserInfoMapper.BaseResultMap"/> -->
    </resultMap>
 
 
 
    <resultMap id="BaseDTOResultMap" type="com.yeshi.fanli.dto.HongBaoDTO">
        <id column="hb_id" property="id" jdbcType="BIGINT" />
        <result column="hb_urank" property="urank" jdbcType="INTEGER" />
        <result column="hb_money" property="money" jdbcType="DECIMAL" />
        <result column="hb_type" property="type" jdbcType="INTEGER" />
        <result column="hb_state" property="state" jdbcType="INTEGER" />
        <result column="hb_version" property="version" jdbcType="INTEGER" />
        <result column="hb_beizhu" property="beizhu" jdbcType="VARCHAR" />
        <result column="hb_pre_get_time" property="preGetTime"
            jdbcType="TIMESTAMP" />
        <result column="hb_get_time" property="getTime" jdbcType="TIMESTAMP" />
        <result column="hb_create_time" property="createTime" jdbcType="TIMESTAMP" />
        <result column="hb_update_time" property="updateTime" jdbcType="TIMESTAMP" />
 
        <result column="orderId" property="orderId" jdbcType="VARCHAR" />
 
        <result column="payMoney" property="payMoney" jdbcType="DECIMAL" />
 
        <result column="settlement" property="settlement" jdbcType="DECIMAL" />
 
        <association property="userInfo" column="hb_uid"
            javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="hb_uid" property="id" jdbcType="BIGINT" />
        </association>
 
        <association property="parent" column="hb_pid"
            javaType="com.yeshi.fanli.entity.bus.user.HongBaoV2">
            <id column="hb_pid" property="id" jdbcType="BIGINT" />
        </association>
 
    </resultMap>
 
 
 
 
 
 
 
 
 
    <sql id="Base_Column_List">hb_id,hb_uid,hb_urank,hb_pid,hb_money,hb_type,hb_state,hb_version,hb_beizhu,hb_pre_get_time,hb_get_time,hb_create_time,hb_update_time
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_v2 where hb_id = #{id,jdbcType=BIGINT}
    </select>
 
 
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_v2 where hb_id = #{id,jdbcType=BIGINT} for
        update
    </select>
 
 
 
    <select id="listChildrenById" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_v2 where hb_pid = #{0}
    </select>
 
 
    <select id="listCanBalanceHongBaoByType" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        FROM yeshi_ec_hongbao_v2 h WHERE h.`hb_version`=2 AND
        h.`hb_type`=#{type} AND (h.`hb_state`=2) AND
        h.`hb_pre_get_time` IS NOT
        NULL AND h.`hb_pre_get_time`
        <![CDATA[ <]]>
        NOW() limit #{count}
    </select>
 
    <!-- 获取用户奖金列表 -->
    <select id="listJiangJinByUid" resultMap="BaseDTOResultMap">
        SELECT
        hhh.*,co.`co_order_no` AS orderId,co.`co_payment` AS
        payMoney,co.`co_settlement` AS settlement FROM
        (
        SELECT
        hh.*,IF(h.`hb_id` IS NOT NULL,h.`hb_id`,hh.hb_id) AS hid FROM
        (
        SELECT
        h.* FROM yeshi_ec_hongbao_v2 h WHERE h.hb_uid=#{uid} and
        (h.`hb_type`=6 OR h.`hb_type`=7
        OR h.`hb_type`=20 OR h.`hb_type`=21 OR
        h.`hb_type`=22) AND
        h.`hb_version`=2 ORDER BY h.`hb_create_time` DESC
        limit #{start},#{count}
        ) hh
        LEFT JOIN yeshi_ec_hongbao_v2 h ON
        hh.hb_pid IS NOT NULL AND
        h.`hb_id`=hh.hb_pid
        ) hhh LEFT JOIN
        yeshi_ec_hongbao_order ho ON ho.`ho_hongbao_id`=hhh.hid
        LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id`
    </select>
 
 
    <!-- 获取用户奖金列表 -->
    <select id="countJiangJinByUid" resultType="java.lang.Long">
        SELECT count(h.hb_id)
        FROM yeshi_ec_hongbao_v2 h WHERE h.hb_uid=#{0} and (h.`hb_type`=6 OR
        h.`hb_type`=7
        OR h.`hb_type`=20 OR h.`hb_type`=21 OR h.`hb_type`=22)
        AND
        h.`hb_version`=2
    </select>
 
    <!-- 获取总的提成金额 -->
    <select id="getTotalTiChengMoney" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        SELECT IF(a.money IS NULL,0,a.money ) FROM (SELECT
        SUM(h.`hb_money`) AS money FROM `yeshi_ec_hongbao_v2` h WHERE
        h.`hb_uid`=#{0}
        AND h.`hb_state`=3 AND (h.`hb_type`=20 OR
        h.`hb_type`=21 OR h.`hb_type`=22 OR
        h.`hb_type`=6 OR h.`hb_type`=7)) a
    </select>
 
    <!-- 获取总的提成笔数 -->
    <select id="getTotalTiChengCount" resultType="java.lang.Integer"
        parameterType="java.lang.Long">
        SELECT
        count(*) FROM `yeshi_ec_hongbao_v2` h
        WHERE
        h.`hb_uid`=#{0} AND (h.`hb_type`=20 OR h.`hb_type`=21 OR
        h.`hb_type`=22 OR
        h.`hb_type`=6 OR h.`hb_type`=7)
    </select>
 
    <!-- 获取还未到账的提成金额 -->
    <select id="getUnGetTiChengMoney" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        SELECT IF(a.money IS NULL,0,a.money ) FROM (SELECT
        SUM(h.`hb_money`) AS money FROM `yeshi_ec_hongbao_v2` h WHERE
        h.`hb_uid`=#{0}
        AND (h.`hb_state`=1 OR h.hb_state=2 )AND
        (h.`hb_type`=20 OR h.`hb_type`=21 OR
        h.`hb_type`=22 OR h.`hb_type`=6 OR
        h.`hb_type`=7)) a
    </select>
 
 
    <select id="getTotalFanLiMoney" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        SELECT SUM(h.`hb_money`) FROM yeshi_ec_hongbao_v2 h
        WHERE h.`hb_uid`=#{uid} AND h.`hb_type`=1 AND h.`hb_state`=3
    </select>
 
    <select id="getUnRecievedFanLiMoney" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        SELECT SUM(h.`hb_money`) FROM yeshi_ec_hongbao_v2 h
        WHERE h.`hb_uid`=#{uid} AND h.`hb_type`=1 AND (h.`hb_state`=1 OR
        h.`hb_state`=2)
    </select>
 
 
    <select id="listUidCanBanlanceShareAndInvite" resultType="java.lang.Long"
        parameterType="java.lang.Integer">
 
        SELECT DISTINCT( h.`hb_uid`) FROM yeshi_ec_hongbao_v2 h
        WHERE
        (`hb_type`=6 OR
        `hb_type`=7 OR `hb_type`=20 OR `hb_type`=21 OR
        `hb_type`=22 ) AND
        `hb_version`=2 AND (hb_state=1 OR hb_state=2) AND
        hb_pre_get_time IS
        NOT NULL AND hb_pre_get_time>0 AND
        NOW()>=hb_pre_get_time limit #{0}
 
    </select>
 
 
    <select id="listCanBalanceHongBaoByTypeAndUid" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_hongbao_v2 where hb_uid=#{uid} and `hb_version`=2
 
        <foreach collection="types" item="type" open=" and ("
            separator=" or " close=")">
            hb_type =
            #{type}
        </foreach>
 
        and
        (hb_state=1 or hb_state=2) and
        hb_pre_get_time IS NOT NULL AND
        hb_pre_get_time>0 AND
        NOW()>=hb_pre_get_time limit
        #{count}
    </select>
 
    <select id="countInviteOrderCountByUidAndSettleTime" resultType="java.lang.Long">
        SELECT COUNT(h.hb_id) FROM yeshi_ec_hongbao_v2 h LEFT JOIN
        yeshi_ec_hongbao_order ho ON h.`hb_pid`=ho.`ho_hongbao_id` LEFT JOIN
        yeshi_ec_common_order co ON co.`co_id`=ho.`ho_order_id` WHERE
        h.`hb_uid`=#{uid} and (h.`hb_type`=6 or h.`hb_type`=7 OR
        h.`hb_type`=21 OR h.`hb_type`=22) and co.`co_state`=#{state} and
        co.`co_settle_time` is not null and co.`co_settle_time`>=#{minDate}
        and #{maxDate}>co.`co_settle_time`;
    </select>
 
 
 
 
    <select id="getUnRecievedMoneyWithCreateTime" resultType="java.math.BigDecimal">
        SELECT
        SUM(h.`hb_money`) FROM yeshi_ec_hongbao_v2 h
        WHERE h.`hb_uid`=#{uid}
        AND (h.`hb_state`=1 OR
        h.`hb_state`=2) and hb_create_time>=#{minDate}
        and #{maxDate} > hb_create_time
    </select>
 
 
 
    <select id="getUnRecievedMoneyWithPreGetTime" resultType="java.math.BigDecimal">
        SELECT
        SUM(h.`hb_money`) FROM yeshi_ec_hongbao_v2 h
        WHERE h.`hb_uid`=#{uid}
        AND (h.`hb_state`=1 OR
        h.`hb_state`=2) and hb_pre_get_time is not null
        and hb_pre_get_time>=#{minDate}
        and #{maxDate} > hb_pre_get_time
    </select>
 
 
    <select id="countByUidAndState" resultType="java.lang.Long">
        SELECT
        SUM(h.`hb_money`) FROM yeshi_ec_hongbao_v2 h
        WHERE h.`hb_uid`=#{uid}
        AND h.`hb_state`=#{state}
    </select>
 
 
 
 
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
        yeshi_ec_hongbao_v2 where hb_id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.HongBaoV2"
        useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_hongbao_v2
        (hb_id,hb_uid,hb_urank,hb_pid,hb_money,hb_type,hb_state,hb_version,hb_beizhu,hb_pre_get_time,hb_get_time,hb_create_time,hb_update_time)
        values
        (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{urank,jdbcType=INTEGER},#{parent.id,jdbcType=BIGINT},#{money,jdbcType=DECIMAL},#{type,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{version,jdbcType=INTEGER},#{beizhu,jdbcType=VARCHAR},#{preGetTime,jdbcType=TIMESTAMP},#{getTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.HongBaoV2"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_hongbao_v2
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">hb_id,</if>
            <if test="userInfo != null">hb_uid,</if>
            <if test="urank != null">hb_urank,</if>
            <if test="parent != null">hb_pid,</if>
            <if test="money != null">hb_money,</if>
            <if test="type != null">hb_type,</if>
            <if test="state != null">hb_state,</if>
            <if test="version != null">hb_version,</if>
            <if test="beizhu != null">hb_beizhu,</if>
            <if test="preGetTime != null">hb_pre_get_time,</if>
            <if test="getTime != null">hb_get_time,</if>
            <if test="createTime != null">hb_create_time,</if>
            <if test="updateTime != null">hb_update_time,</if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id,jdbcType=BIGINT},</if>
            <if test="userInfo != null">#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="urank != null">#{urank,jdbcType=INTEGER},</if>
            <if test="parent != null">#{parent.id,jdbcType=BIGINT},</if>
            <if test="money != null">#{money,jdbcType=DECIMAL},</if>
            <if test="type != null">#{type,jdbcType=INTEGER},</if>
            <if test="state != null">#{state,jdbcType=INTEGER},</if>
            <if test="version != null">#{version,jdbcType=INTEGER},</if>
            <if test="beizhu != null">#{beizhu,jdbcType=VARCHAR},</if>
            <if test="preGetTime != null">#{preGetTime,jdbcType=TIMESTAMP},</if>
            <if test="getTime != null">#{getTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">#{updateTime,jdbcType=TIMESTAMP},</if>
        </trim>
    </insert>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.HongBaoV2">update
        yeshi_ec_hongbao_v2 set hb_uid =
        #{userInfo.id,jdbcType=BIGINT},hb_urank =
        #{urank,jdbcType=INTEGER},hb_pid =
        #{parent.id,jdbcType=BIGINT},hb_money =
        #{money,jdbcType=DECIMAL},hb_type = #{type,jdbcType=INTEGER},hb_state
        = #{state,jdbcType=INTEGER},hb_version =
        #{version,jdbcType=INTEGER},hb_beizhu =
        #{beizhu,jdbcType=VARCHAR},hb_pre_get_time =
        #{preGetTime,jdbcType=TIMESTAMP},hb_get_time =
        #{getTime,jdbcType=TIMESTAMP},hb_create_time =
        #{createTime,jdbcType=TIMESTAMP},hb_update_time =
        #{updateTime,jdbcType=TIMESTAMP} where hb_id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.HongBaoV2">
        update yeshi_ec_hongbao_v2
        <set>
            <if test="userInfo != null">hb_uid=#{userInfo.id,jdbcType=BIGINT},</if>
            <if test="urank != null">hb_urank=#{urank,jdbcType=INTEGER},</if>
            <if test="parent != null">hb_pid=#{parent.id,jdbcType=BIGINT},</if>
            <if test="money != null">hb_money=#{money,jdbcType=DECIMAL},</if>
            <if test="type != null">hb_type=#{type,jdbcType=INTEGER},</if>
            <if test="state != null">hb_state=#{state,jdbcType=INTEGER},</if>
            <if test="version != null">hb_version=#{version,jdbcType=INTEGER},</if>
            <if test="beizhu != null">hb_beizhu=#{beizhu,jdbcType=VARCHAR},</if>
            <if test="preGetTime != null">hb_pre_get_time=#{preGetTime,jdbcType=TIMESTAMP},</if>
            <if test="getTime != null">hb_get_time=#{getTime,jdbcType=TIMESTAMP},</if>
            <if test="createTime != null">hb_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
            <if test="updateTime != null">hb_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
        </set>
        where hb_id = #{id,jdbcType=BIGINT}
    </update>
</mapper>