yujian
2020-05-09 7e7db2fa55a9a3af46d4fd8ede0dee147f101d64
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
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?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.ExtractMapper">
    <resultMap id="BaseResultMap" type="com.yeshi.fanli.entity.bus.user.Extract">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="account" property="account" jdbcType="VARCHAR" />
        <result column="extractTime" property="extractTime" jdbcType="BIGINT" />
        <result column="receiveTime" property="receiveTime" jdbcType="TIMESTAMP" />
 
        <result column="ip" property="ip" jdbcType="VARCHAR" />
        <result column="money" property="money" jdbcType="DECIMAL" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="reason" property="reason" jdbcType="VARCHAR" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="adminId" property="adminId" jdbcType="BIGINT" />
 
        <association property="userInfo" column="uid"
            select="com.yeshi.fanli.dao.mybatis.UserInfoMapper.selectByPrimaryKey">
        </association>
 
        <association property="system" column="sid"
            select="com.yeshi.fanli.dao.mybatis.BusinessSystemMapper.selectByPrimaryKey">
        </association>
    </resultMap>
    
    
    <resultMap id="SimplMap" type="com.yeshi.fanli.entity.bus.user.Extract">
        <id column="id" property="id" jdbcType="BIGINT" />
        <result column="account" property="account" jdbcType="VARCHAR" />
        <result column="extractTime" property="extractTime" jdbcType="BIGINT" />
        <result column="receiveTime" property="receiveTime" jdbcType="TIMESTAMP" />
        <result column="ip" property="ip" jdbcType="VARCHAR" />
        <result column="money" property="money" jdbcType="DECIMAL" />
        <result column="name" property="name" jdbcType="VARCHAR" />
        <result column="reason" property="reason" jdbcType="VARCHAR" />
        <result column="state" property="state" jdbcType="INTEGER" />
        <result column="type" property="type" jdbcType="INTEGER" />
        <result column="adminId" property="adminId" jdbcType="BIGINT" />
 
        <association column="uid" property="userInfo" javaType="com.yeshi.fanli.entity.bus.user.UserInfo">
            <id column="uid" property="id" jdbcType="BIGINT" />    
        </association>
        
        <association column=""sid"" property="system" javaType="com.yeshi.fanli.entity.system.BusinessSystem">
            <id column="sid" property="id" jdbcType="BIGINT" />    
        </association>
    </resultMap>
    
    
    
    <sql id="Base_Column_List">
        id,account,extractTime,ip,money,name,reason,state,type,uid,sid,adminId,receiveTime
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_extract
        where id = #{id,jdbcType=BIGINT}
    </select>
 
    <select id="selectByPrimaryKeyForUpdate" resultMap="BaseResultMap"
        parameterType="java.lang.Long">
        select
        <include refid="Base_Column_List" />
        from yeshi_ec_extract
        where id = #{id,jdbcType=BIGINT} for update
    </select>
 
 
    <select id="computeCompensateByUid" resultType="java.math.BigDecimal"
        parameterType="java.lang.Long">
        select
        sum(ecc_money)
        from yeshi_ec_extract_check_compensate
        where ecc_uid=#{0}
    </select>
 
 
 
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete from
        yeshi_ec_extract
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.yeshi.fanli.entity.bus.user.Extract"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_extract (id,
        account,extractTime,ip,money,name,reason,state,type,uid,sid,adminId,receiveTime)
        values
        (#{id,jdbcType=BIGINT},
        #{account,jdbcType=VARCHAR},
        #{extractTime,jdbcType=BIGINT},
        #{ip,jdbcType=VARCHAR},
        #{money,jdbcType=DECIMAL},
        #{name,jdbcType=VARCHAR},
        #{reason,jdbcType=VARCHAR},
        #{state,jdbcType=INTEGER},
        #{type,jdbcType=INTEGER},
        #{userInfo.id,jdbcType=BIGINT},
        #{system.id,jdbcType=BIGINT},
        #{adminId,jdbcType=BIGINT},
        #{receiveTime,jdbcType=TIMESTAMP}
        )
    </insert>
    <insert id="insertSelective" parameterType="com.yeshi.fanli.entity.bus.user.Extract"
        useGeneratedKeys="true" keyProperty="id">
        insert into yeshi_ec_extract
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="account != null">
                account,
            </if>
            <if test="extractTime != null">
                extractTime,
            </if>
            <if test="ip != null">
                ip,
            </if>
            <if test="money != null">
                money,
            </if>
            <if test="name != null">
                name,
            </if>
            <if test="reason != null">
                reason,
            </if>
            <if test="state != null">
                state,
            </if>
 
            <if test="type != null">
                type,
            </if>
            <if test="userInfo != null">
                uid,
            </if>
 
            <if test="system != null">
                sid,
            </if>
            <if test="system != null">
                adminId,
            </if>
 
            <if test="receiveTime != null">
                receiveTime,
            </if>
 
 
 
 
 
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="account != null">
                #{account,jdbcType=VARCHAR},
            </if>
            <if test="extractTime != null">
                #{extractTime,jdbcType=BIGINT},
            </if>
            <if test="ip != null">
                #{ip,jdbcType=VARCHAR},
            </if>
            <if test="money != null">
                #{money,jdbcType=DECIMAL},
            </if>
            <if test="name != null">
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="reason != null">
                #{reason,jdbcType=VARCHAR},
            </if>
            <if test="state != null">
                #{state,jdbcType=INTEGER},
            </if>
            <if test="type != null">
                #{type,jdbcType=INTEGER},
            </if>
            <if test="userInfo != null">
                #{userInfo.id,jdbcType=BIGINT},
            </if>
            <if test="system != null">
                #{system.id,jdbcType=BIGINT},
            </if>
            <if test="system != null">
                #{adminId,jdbcType=BIGINT},
            </if>
 
            <if test="receiveTime != null">
                #{receiveTime,jdbcType=TIMESTAMP},
            </if>
 
 
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.bus.user.Extract">
        update yeshi_ec_extract
        <set>
            <if test="account != null">
                account = #{account,jdbcType=VARCHAR},
            </if>
            <if test="extractTime != null">
                extractTime =
                #{extractTime,jdbcType=BIGINT},
            </if>
            <if test="ip != null">
                ip =
                #{ip,jdbcType=VARCHAR},
            </if>
            <if test="money != null">
                money =
                #{money,jdbcType=DECIMAL},
            </if>
            <if test="name != null">
                name =
                #{name,jdbcType=VARCHAR},
            </if>
            <if test="reason != null">
                reason = #{reason,jdbcType=VARCHAR},
            </if>
            <if test="state != null">
                state =
                #{state,jdbcType=INTEGER},
            </if>
            <if test="type != null">
                type =
                #{type,jdbcType=INTEGER},
            </if>
            <if test="userInfo != null">
                uid =
                #{userInfo.id,jdbcType=BIGINT},
            </if>
            <if test="system != null">
                sid = #{system.id,jdbcType=BIGINT},
            </if>
            <if test="system != null">
                adminId = #{adminId,jdbcType=BIGINT},
            </if>
 
            <if test="receiveTime != null">
                receiveTime=#{receiveTime,jdbcType=TIMESTAMP},
            </if>
 
 
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.yeshi.fanli.entity.bus.user.Extract">
        update
        yeshi_ec_extract
        set
        account = #{account,jdbcType=VARCHAR},
        extractTime =
        #{extractTime,jdbcType=BIGINT},
        ip =
        #{ip,jdbcType=VARCHAR},
        money =
        #{money,jdbcType=DECIMAL},
        name =
        #{name,jdbcType=VARCHAR},
        reason
        =#{reason,jdbcType=VARCHAR},
        state
        =#{state,jdbcType=INTEGER},
        type
        =#{type,jdbcType=INTEGER},
        uid
        =#{userInfo.id,jdbcType=BIGINT},
        adminId
        =#{adminId,jdbcType=BIGINT},
        sid
        =
        #{system.id,jdbcType=BIGINT},
        receiveTime
        =#{receiveTime,jdbcType=TIMESTAMP}
        where id =
        #{id,jdbcType=BIGINT}
    </update>
 
    <select id="checkExtract" resultType="java.lang.Integer">
        <![CDATA[
         SELECT ABS(ttt.totalmoney-ttt.hbmoney)<0.001
         ]]>
        FROM
        (
        SELECT u.my_hongBao,s.uid AS uid,s.money AS hbmoney,IF(ss.money
        IS NOT
        NULL,ss.money,0) + u.my_hongBao+IF( dd.`money` IS NOT
        NULL,dd.money,0)
        +IF( cc.`money` IS NOT NULL,cc.money,0) AS totalmoney
        FROM
        yeshi_ec_user u
        LEFT JOIN (SELECT h.hb_uid as uid,SUM(h.hb_money)
        AS money FROM yeshi_ec_hongbao_v2 h
        WHERE h.hb_state=3 AND h.hb_uid =
        #{uid,jdbcType=BIGINT} GROUP BY h.hb_uid)s ON
        u.id=s.uid
        LEFT JOIN
        (SELECT SUM(t.`money`)AS money,t.uid FROM yeshi_ec_extract t
        WHERE
        (t.state=0 OR t.state=1) AND t.`uid`=#{uid,jdbcType=BIGINT}
        GROUP BY
        t.uid)ss ON ss.uid=u.id
        LEFT JOIN (SELECT ABS (SUM(d.money)) AS
        money,d.`uid` FROM
        yeshi_ec_account_details d WHERE (d.type=10 OR
        d.type=9 ) AND d.uid=
        #{uid,jdbcType=BIGINT} GROUP BY d.`uid`) dd ON
        dd.uid=u.`id`
        LEFT JOIN (SELECT SUM(c.ecc_money) AS money,c.`ecc_uid`
        AS uid FROM
        `yeshi_ec_extract_check_compensate` c WHERE
        c.ecc_uid=#{uid,jdbcType=BIGINT} GROUP BY c.ecc_uid) cc ON
        cc.uid=u.`id`
        WHERE s.uid IS NOT NULL AND s.money!= u.my_hongbao) ttt
        LEFT JOIN yeshi_ec_user u ON ttt.uid=u.`id` WHERE
        ttt.hbmoney!=ttt.totalmoney
    </select>
 
    <select id="getTodayCount" resultType="java.util.HashMap">
        SELECT
        IFNULL(COUNT(et.id), 0)AS total,IFNULL(SUM(CASE WHEN et.state =
        1 THEN
        1 ELSE 0 END),0) AS succeed,IFNULL(SUM(CASE WHEN et.state = 2
        THEN 1
        ELSE 0 END),0) AS fails
        FROM yeshi_ec_extract et
        LEFT JOIN
        `yeshi_ec_extract_audit_record` ar ON ar.`extractId` = et.`id`
        WHERE
        ar.`id` IS NOT NULL
        AND FROM_UNIXTIME(ar.`auditTime`/1000,'%y%m%d') =
        CURDATE()
    </select>
 
    <select id="getTodayTotalSuccessMoney" resultType="java.math.BigDecimal">
        SELECT
        IFNULL(CAST(SUM(et.money)AS DECIMAL(19,2)),0) AS moneys
        FROM
        yeshi_ec_extract et
        LEFT JOIN `yeshi_ec_extract_audit_record` ar ON
        ar.`extractId` = et.`id`
        WHERE et.state=1 AND ar.`id` IS NOT NULL
        AND
        FROM_UNIXTIME(ar.`auditTime`/1000,'%y%m%d') = CURDATE()
    </select>
 
    <select id="countTotalSuccess" resultType="java.util.HashMap">
        <!-- 提现成功 次数、总金额 -->
        SELECT CAST(SUM(et.money)AS DECIMAL(19,2)) AS totalmoney,
        IFNULL(COUNT(et.id),0) AS totalamount FROM yeshi_ec_extract et
        WHERE
        et.state=1
    </select>
 
 
    <select id="getMyTaskInfo" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM yeshi_ec_extract
        WHERE adminId = ${adminId} and state=0 ORDER BY
        extractTime LIMIT 0,1
    </select>
 
    <select id="getNewTaskInfo" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM yeshi_ec_extract
        WHERE state=0 ORDER BY extractTime LIMIT 0,1
    </select>
 
 
    <select id="countRecordsByUid" resultType="java.util.HashMap">
        SELECT
        IFNULL(COUNT(et.id), 0) AS totalamount,IFNULL(SUM(CASE WHEN et.state
        =
        1 THEN 1 ELSE 0 END),0) AS succeed,
        IFNULL(SUM(CASE WHEN et.state = 2
        THEN 1 ELSE 0 END),0) AS fail
        FROM yeshi_ec_extract
        et WHERE (et.state=1
        OR et.state= 2) AND et.uid = ${uid}
    </select>
 
    <select id="countSuccessMoneysByUid" resultType="java.lang.Double">
        SELECT
        IFNULL(ROUND(SUM(et.money),2),0) AS moneys FROM yeshi_ec_extract et
        WHERE et.state=1 AND et.uid = ${uid}
    </select>
 
    <select id="countSuccessByUid" resultType="java.lang.Long">
        SELECT COUNT(et.id)
        FROM yeshi_ec_extract et
        WHERE et.state=1 AND et.uid = ${uid}
    </select>
 
    <select id="getFinishRecord" resultType="java.util.Map">
        SELECT ex.*,ar.* FROM yeshi_ec_extract ex LEFT JOIN
        yeshi_ec_extract_audit_record ar ON ar.extractId=ex.id
        WHERE 
      <![CDATA[
            FROM_UNIXTIME(ex.extractTime/1000)  >= #{startTime}
               AND  FROM_UNIXTIME(ex.extractTime/1000) <= #{endTime} 
       ]]>
        <if test='key != null and key != ""'>
            AND (ex.uid = #{key} OR ar.aid = #{key})
        </if>
        ORDER BY ex.extractTime DESC LIMIT ${start},${count}
    </select>
 
    <select id="countTodayApply" resultType="java.lang.Integer">
        SELECT count(id) FROM yeshi_ec_extract
        WHERE  <![CDATA[ FROM_UNIXTIME(extractTime/1000) >=CURDATE() ]]>
    </select>
 
    <select id="countTodayComplete" resultType="java.lang.Integer">
        SELECT count(id) FROM yeshi_ec_extract
        WHERE (state=1 OR state= 2) <![CDATA[AND  FROM_UNIXTIME(extractTime/1000) >=CURDATE() ]]>
    </select>
 
    <select id="countTodayMoney" resultType="java.lang.Double">
        SELECT IFNULL(SUM(t.`money`),0) FROM yeshi_ec_extract t
        WHERE t.`uid` =
        #{uid} AND t.state = 1
        AND <![CDATA[TO_DAYS( FROM_UNIXTIME(t.extractTime/1000)) = TO_DAYS(NOW())]]>
 
    </select>
    
    
    <select id="sumToadyApplyByUid" resultType="java.math.BigDecimal">
        SELECT IFNULL(SUM(t.`money`),0) FROM yeshi_ec_extract t
        WHERE t.`uid` = #{uid}
        AND  FROM_UNIXTIME(t.extractTime/1000,'%Y-%m-%d') = #{day}
    </select>
    
    
    <select id="sumMoneyByUidAndState" resultType="java.math.BigDecimal">
        SELECT IFNULL(SUM(t.`money`),0) FROM yeshi_ec_extract t
        WHERE t.`uid` = #{uid}
        <if test="stateList!=null">
        <foreach collection="stateList" item="state" open="and (" close=")" separator=" or ">
        `state`=#{state}
        </foreach>
        </if>
    </select>
    
    
    <select id="getExtractSucceedRecord" resultMap="SimplMap">
         SELECT * FROM yeshi_ec_extract t
         WHERE t.`uid` = #{uid} AND t.`state` = 1
         ORDER BY t.`id` DESC
         LIMIT #{start},#{count}
    </select>
    
    
    <select id="countExtractSucceedRecord" resultType="Long">
        SELECT COUNT(t.`id`) FROM yeshi_ec_extract t
        WHERE t.`uid` = 389677 AND t.`state` = 1
    </select>
    
</mapper>