Helius
2022-05-27 4351e71d782741143a98f86f6648acd16689165f
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
<?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.matrix.system.shopXcx.dao.ShopRefundRecordDao">
    <!-- 定义ShopRefundRecord 的复杂关联map -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopRefundRecord" id="ShopRefundRecordMap">
        <id property="id" column="id" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
            <result property="refundNo" column="refund_no" />
            <result property="orderId" column="order_id" />
            <result property="userId" column="user_id" />
            <result property="refundCause" column="refund_cause" />
            <result property="refundMoney" column="refund_money" />
            <result property="handler" column="handler" />
            <result property="handingTime" column="handing_time" />
            <result property="refundTransactionNo" column="refund_transaction_no" />
            <result property="remarks" column="remarks" />
            <result property="refundWaybillNo" column="refund_waybill_no" />
            <result property="logisticsCompany" column="logistics_company" />
            <result property="applyTime" column="apply_time" />
            <result property="refundTime" column="refund_time" />
            <result property="refundType" column="refund_type" />
            <result property="auditStatus" column="audit_status" />
            <result property="refundStatus" column="refund_status" />
            <result property="refundGoodsStatus" column="refund_goods_status" />
            <result property="refundRefuseReason" column="refund_refuse_reason" />
            <result property="orderNo" column="order_no" />
            <result property="nickName" column="nick_name" />
            <result property="discountAmount" column="discount_amount" />
        <result property="companyId" column="company_id" />
    </resultMap>
 
    <!-- 定义ShopRefundRecord 的复杂关联map -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopRefundRecordDetails" id="ShopRefundRecordDetailsMap">
        <id property="id" column="id" />
        <result property="refundNo" column="refund_no" />
        <result property="refundCause" column="refund_cause" />
        <result property="refundMoney" column="refund_money" />
        <result property="orderNo" column="order_no" />
        <result property="orderMoney" column="order_money" />
        <result property="title" column="title" />
        <result property="price" column="price" />
        <result property="count" column="count" />
        <result property="totalPrice" column="total_price" />
        <result property="skuName" column="s_title" />
        <result property="discountAmount" column="discount_amount" />
        <result property="postage" column="postage" />
    </resultMap>
    
    
    <!-- 定义ShopRefundRecord 的简单map  ,本map不添加其他的关联属性 -->
    <resultMap type="com.matrix.system.shopXcx.bean.ShopRefundRecord" id="ShopRefundRecordComplexMap">
        <id property="id" column="id" />
        <result property="createBy" column="create_by" />
        <result property="createTime" column="create_time" />
        <result property="updateBy" column="update_by" />
        <result property="updateTime" column="update_time" />
            <result property="refundNo" column="refund_no" />
            <result property="orderId" column="order_id" />
            <result property="userId" column="user_id" />
            <result property="refundCause" column="refund_cause" />
            <result property="refundMoney" column="refund_money" />
            <result property="handler" column="handler" />
            <result property="handingTime" column="handing_time" />
            <result property="refundTransactionNo" column="refund_transaction_no" />
            <result property="remarks" column="remarks" />
            <result property="refundWaybillNo" column="refund_waybill_no" />
            <result property="logisticsCompany" column="logistics_company" />
            <result property="applyTime" column="apply_time" />
            <result property="refundTime" column="refund_time" />
            <result property="refundType" column="refund_type" />
            <result property="auditStatus" column="audit_status" />
            <result property="refundStatus" column="refund_status" />
            <result property="refundGoodsStatus" column="refund_goods_status" />
            <result property="refundRefuseReason" column="refund_refuse_reason" />
        <result property="companyId" column="company_id" />
            <!--返回详情列表-->
            <collection property="shopOrder" column="{orderId=order_id}"
                        select="com.matrix.system.shopXcx.dao.ShopOrderDao.selectMyOrderById"/>
    </resultMap>
    
    <!-- 字段sql -->
    <sql id="columns">
        create_by,
        create_time,
        update_by,
        update_time,
            id,
            refund_no,
            order_id,
            user_id,
            refund_cause,
            refund_money,
            handler,
            handing_time,
            refund_transaction_no,
            remarks,
            refund_waybill_no,
            logistics_company,
            apply_time,
            refund_time,
            refund_type,
            audit_status,
            refund_status,
            refund_goods_status,
            refund_refuse_reason,
            company_id
    </sql>
    
    <!-- 属性sql -->
    <sql id="propertys">
        #{item.createBy},
        now(),
        #{item.updateBy},
        now(),
            #{item.id},
            #{item.refundNo},
            #{item.orderId},
            #{item.userId},
            #{item.refundCause},
            #{item.refundMoney},
            #{item.handler},
            #{item.handingTime},
            #{item.refundTransactionNo},
            #{item.remarks},
            #{item.refundWaybillNo},
            #{item.logisticsCompany},
            #{item.applyTime},
            #{item.refundTime},
            #{item.refundType},
            #{item.auditStatus},
            #{item.refundStatus},
            #{item.refundGoodsStatus},
            #{item.refundRefuseReason},
            #{item.companyId}
    </sql>
    
    <!-- where sql -->
    <sql id="where_sql">
         
         <if test="record!=null">
            <if test="(record.id!=null and record.id!='') or  (record.id!='' and record.id==0)  ">
                and id  = #{record.id} 
            </if>
            <if test="(record.refundNo!=null and record.refundNo!='') or  (record.refundNo!='' and record.refundNo==0)  ">
                and refund_no  = #{record.refundNo} 
            </if>
            <if test="(record.orderId!=null and record.orderId!='') or  (record.orderId!='' and record.orderId==0)  ">
                and order_id  = #{record.orderId} 
            </if>
            <if test="(record.userId!=null and record.userId!='') or  (record.userId!='' and record.userId==0)  ">
                and user_id  = #{record.userId} 
            </if>
            <if test="(record.refundCause!=null and record.refundCause!='') or  (record.refundCause!='' and record.refundCause==0)  ">
                and refund_cause  = #{record.refundCause} 
            </if>
            <if test="(record.refundMoney!=null and record.refundMoney!='') or  (record.refundMoney!='' and record.refundMoney==0)  ">
                and refund_money  = #{record.refundMoney} 
            </if>
            <if test="(record.handler!=null and record.handler!='') or  (record.handler!='' and record.handler==0)  ">
                and handler like concat('%',#{record.handler},'%')
            </if>
            <if test="(record.handingTime!=null and record.handingTime!='') or  (record.handingTime!='' and record.handingTime==0)  ">
                and handing_time  = #{record.handingTime} 
            </if>
            <if test="(record.refundTransactionNo!=null and record.refundTransactionNo!='') or  (record.refundTransactionNo!='' and record.refundTransactionNo==0)  ">
                and refund_transaction_no  = #{record.refundTransactionNo} 
            </if>
            <if test="(record.remarks!=null and record.remarks!='') or  (record.remarks!='' and record.remarks==0)  ">
                and remarks  = #{record.remarks} 
            </if>
            <if test="(record.refundWaybillNo!=null and record.refundWaybillNo!='') or  (record.refundWaybillNo!='' and record.refundWaybillNo==0)  ">
                and refund_waybill_no like concat('%', #{record.refundWaybillNo}, '%')
            </if>
            <if test="(record.logisticsCompany!=null and record.logisticsCompany!='') or  (record.logisticsCompany!='' and record.logisticsCompany==0)  ">
                and logistics_company like concat('%',#{record.logisticsCompany},'%')
            </if>
            <if test="(record.applyTime!=null and record.applyTime!='') or  (record.applyTime!='' and record.applyTime==0)  ">
                and apply_time  = #{record.applyTime} 
            </if>
            <if test="(record.refundTime!=null and record.refundTime!='') or  (record.refundTime!='' and record.refundTime==0)  ">
                and refund_time  = #{record.refundTime} 
            </if>
            <if test="(record.refundType!=null and record.refundType!='') or  (record.refundType!='' and record.refundType==0)  ">
                and refund_type  = #{record.refundType} 
            </if>
            <if test="(record.auditStatus!=null and record.auditStatus!='') or  (record.auditStatus!='' and record.auditStatus==0)  ">
                and audit_status  = #{record.auditStatus} 
            </if>
            <if test="(record.refundStatus!=null and record.refundStatus!='') or  (record.refundStatus!='' and record.refundStatus==0)  ">
                and refund_status  = #{record.refundStatus} 
            </if>
            <if test="(record.refundGoodsStatus!=null and record.refundGoodsStatus!='') or  (record.refundGoodsStatus!='' and record.refundGoodsStatus==0)  ">
                and refund_goods_status  = #{record.refundGoodsStatus} 
            </if>
            <if test="(record.refundRefuseReason!=null and record.refundRefuseReason!='') or  (record.refundRefuseReason!='' and record.refundRefuseReason==0)  ">
                and refund_refuse_reason  = #{record.refundRefuseReason} 
            </if>
             <if test="(record.nickName!=null and record.nickName!='') or  (record.nickName!='' and record.nickName==0)  ">
                 and u.nick_name like concat('%',#{record.nickName},'%')
             </if>
             <if test="(record.orderNo!=null and record.orderNo!='') or  (record.orderNo!='' and record.orderNo==0)  ">
                 and o.order_no like concat('%', #{record.orderNo}, '%')
             </if>
             <if test="(record.refundBeginTime!=null and record.refundBeginTime!='')">
                 and date_format(apply_time, '%Y-%m-%d') >= #{record.refundBeginTime}
             </if>
             <if test="(record.refundEndTime!=null and record.refundEndTime!='')">
                 and  #{record.refundEndTime} >= date_format(apply_time, '%Y-%m-%d')
             </if>
             <if test="(record.companyId!=null and record.companyId!='') or  (record.companyId!='' and record.companyId==0)  ">
                 and r.company_id  = #{record.companyId}
             </if>
        </if>
         
    </sql>
    
    <!--  插入方法   -->
    <insert id="insert" parameterType="com.matrix.system.shopXcx.bean.ShopRefundRecord"
        useGeneratedKeys="true" keyProperty="item.id">
        INSERT INTO shop_refund_record (
             <include refid="columns"></include>
        )
    VALUES (
         <include refid="propertys"></include>
    )
    </insert>
    
    
    
    <!--  批量插入   -->
    <insert id="batchInsert" parameterType="java.util.List">
        INSERT INTO shop_refund_record (
        <include refid="columns"></include>    
        )
    VALUES 
    <foreach collection="list" item="item" index="index" separator=",">(
        <include refid="propertys"></include>    
    )</foreach>
    </insert>
    
    
    
    
    
    <!--  根据Map更新 部分更新   -->
    <update id="updateByMap" parameterType="java.util.HashMap" >
        UPDATE shop_refund_record
        <set>
            <if test="_parameter.containsKey('refundNo')">
                    refund_no = #{refundNo},
                </if>        
            <if test="_parameter.containsKey('orderId')">
                    order_id = #{orderId},
                </if>        
            <if test="_parameter.containsKey('userId')">
                    user_id = #{userId},
                </if>        
            <if test="_parameter.containsKey('refundCause')">
                    refund_cause = #{refundCause},
                </if>        
            <if test="_parameter.containsKey('refundMoney')">
                    refund_money = #{refundMoney},
                </if>        
            <if test="_parameter.containsKey('handler')">
                    handler = #{handler},
                </if>        
            <if test="_parameter.containsKey('handingTime')">
                    handing_time = #{handingTime},
                </if>        
            <if test="_parameter.containsKey('refundTransactionNo')">
                    refund_transaction_no = #{refundTransactionNo},
                </if>        
            <if test="_parameter.containsKey('remarks')">
                    remarks = #{remarks},
                </if>        
            <if test="_parameter.containsKey('refundWaybillNo')">
                    refund_waybill_no = #{refundWaybillNo},
                </if>        
            <if test="_parameter.containsKey('logisticsCompany')">
                    logistics_company = #{logisticsCompany},
                </if>        
            <if test="_parameter.containsKey('applyTime')">
                    apply_time = #{applyTime},
                </if>        
            <if test="_parameter.containsKey('refundTime')">
                    refund_time = #{refundTime},
                </if>        
            <if test="_parameter.containsKey('refundType')">
                    refund_type = #{refundType},
                </if>        
            <if test="_parameter.containsKey('auditStatus')">
                    audit_status = #{auditStatus},
                </if>        
            <if test="_parameter.containsKey('refundStatus')">
                    refund_status = #{refundStatus},
                </if>        
            <if test="_parameter.containsKey('refundGoodsStatus')">
                    refund_goods_status = #{refundGoodsStatus},
                </if>        
            <if test="_parameter.containsKey('refundRefuseReason')">
                    refund_refuse_reason = #{refundRefuseReason},
                </if>        
        </set>
        WHERE id=#{id} 
    </update> 
    
    
    <!--  根据对象更新 部分更新   -->
    <update id="updateByModel" parameterType="Integer">
        UPDATE shop_refund_record
        <set>
            <if test="record.refundNo != null and record.refundNo != '' ">
                refund_no  = #{record.refundNo}, 
            </if>
            <if test="record.orderId != null ">
                order_id  = #{record.orderId}, 
            </if>
            <if test="record.userId != null and record.userId != '' ">
                user_id  = #{record.userId}, 
            </if>
            <if test="record.refundCause != null and record.refundCause != '' ">
                refund_cause  = #{record.refundCause}, 
            </if>
            <if test="record.refundMoney != null ">
                refund_money  = #{record.refundMoney}, 
            </if>
            <if test="record.handler != null and record.handler != '' ">
                handler  = #{record.handler}, 
            </if>
            <if test="record.handingTime != null ">
                handing_time  = #{record.handingTime}, 
            </if>
            <if test="record.refundTransactionNo != null and record.refundTransactionNo != '' ">
                refund_transaction_no  = #{record.refundTransactionNo}, 
            </if>
            <if test="record.remarks != null and record.remarks != '' ">
                remarks  = #{record.remarks}, 
            </if>
            <if test="record.refundWaybillNo != null and record.refundWaybillNo != '' ">
                refund_waybill_no  = #{record.refundWaybillNo}, 
            </if>
            <if test="record.logisticsCompany != null and record.logisticsCompany != '' ">
                logistics_company  = #{record.logisticsCompany}, 
            </if>
            <if test="record.applyTime != null ">
                apply_time  = #{record.applyTime}, 
            </if>
            <if test="record.refundTime != null ">
                refund_time  = #{record.refundTime}, 
            </if>
            <if test="record.refundType != null ">
                refund_type  = #{record.refundType}, 
            </if>
            <if test="record.auditStatus != null ">
                audit_status  = #{record.auditStatus}, 
            </if>
            <if test="record.refundStatus != null ">
                refund_status  = #{record.refundStatus}, 
            </if>
            <if test="record.refundGoodsStatus != null ">
                refund_goods_status  = #{record.refundGoodsStatus}, 
            </if>
            <if test="record.refundRefuseReason != null and record.refundRefuseReason != '' ">
                refund_refuse_reason  = #{record.refundRefuseReason}, 
            </if>
        </set>
        WHERE id=#{record.id} 
    </update>
 
    <!-- 根据ID批量更新退货退款状态 -->
    <update id="updateRefundTypeByIds">
        update shop_refund_record
        <set>
            <if test="state == 1 or state == 2">
                refund_goods_status = #{state},
            </if>
        </set>
        where id in
        <foreach collection="list" index="index" item="item" open="("
                 separator="," close=")">
            #{item}
        </foreach>
    </update>
 
    <!-- 根据ID批量更新申请退款状态 -->
    <update id="updateRefundStatusByIds">
        update shop_refund_record
        <set>
            <if test="state == 1 or state == 2">
                refund_status = #{state},
            </if>
            refund_time = now(),
        </set>
        where id = #{id}
    </update>
 
    <!-- 根据ID更新申请退款(失败)状态 -->
    <update id="updateRefundStatusByFail">
        update shop_refund_record
        <set>
            <if test="state == 1 or state == 2">
                refund_status = #{state},
            </if>
        </set>
        where id = #{id}
    </update>
 
    <!-- 批量删除 -->
    <delete id="deleteByIds" parameterType="java.util.List">
        delete from shop_refund_record where  id in
        <foreach collection="list" index="index" item="item" open="("
            separator="," close=")">
            #{item}
        </foreach>
    </delete>
        
    <!-- 根据id删除-->
    <delete id="deleteById" parameterType="Integer">
        DELETE FROM shop_refund_record
        where  id=#{id} 
    </delete>
    
    <!-- 根据对象删除-->
    <delete id="deleteByModel" parameterType="com.matrix.system.shopXcx.bean.ShopRefundRecord">
        DELETE FROM shop_refund_record
        <where>
        <include refid="where_sql" ></include>
        </where>
    </delete>
    
    
    
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="ShopRefundRecordMap">
        select
        r.create_by,
        r.create_time,
        r.update_by,
        r.update_time,
        r.id,
        r.refund_no,
        r.order_id,
        r.user_id,
        r.refund_cause,
        r.refund_money,
        r.handler,
        r.handing_time,
        r.refund_transaction_no,
        r.remarks,
        r.refund_waybill_no,
        r.logistics_company,
        r.apply_time,
        r.refund_time,
        r.refund_type,
        r.audit_status,
        r.refund_status,
        r.refund_goods_status,
        r.refund_refuse_reason,
        o.order_no,
        u.nick_name
        from shop_refund_record r
        left join shop_order o on r.order_id = o.id
        LEFT JOIN sys_vip_info u ON r.user_id = u.id
        <where>
          <include refid="where_sql"></include>
         </where>
        <if test="pageVo !=null"><!-- 判断这个pageVo对象是否为空 -->
            order by r.create_time desc
            <if test="pageVo.offset >=0  and pageVo.limit >0">
                limit
                #{pageVo.offset},#{pageVo.limit}
            </if>
        </if>
    </select>
    
    <!-- 查询总条数 -->
    <select id="selectTotalRecord" parameterType="long"   resultType="java.lang.Integer">
    select count(*)
        from shop_refund_record r
        left join shop_order o on r.order_id = o.id
        LEFT JOIN sys_vip_info u ON r.user_id = u.id
        <where>
           <include refid="where_sql"></include>
        </where>
    </select>
 
    <!-- 根据id查询-->
    <select id="selectById" resultMap="ShopRefundRecordMap">
        select 
        r.create_by,
        r.create_time,
        r.update_by,
        r.update_time,
        r.id,
        r.refund_no,
        r.order_id,
        r.user_id,
        r.refund_cause,
        r.refund_money,
        r.handler,
        r.handing_time,
        r.refund_transaction_no,
        r.remarks,
        r.refund_waybill_no,
        r.logistics_company,
        r.apply_time,
        r.refund_time,
        r.refund_type,
        r.audit_status,
        r.refund_status,
        r.refund_goods_status,
        r.refund_refuse_reason,
        o.order_no,
        o.discount_amount,
        u.nick_name
        from shop_refund_record r
        left join shop_order o on r.order_id = o.id
        LEFT JOIN sys_vip_info u ON r.user_id = u.id
        where  r.id=#{id}
    </select>
 
    <!-- 根据id查询-->
    <select id="selectDetailsById" resultMap="ShopRefundRecordDetailsMap">
        SELECT
            r.id,
            r.refund_no,
            r.refund_cause,
            r.refund_money,
            o.order_no,
            o.order_money,
            o.postage,
            d.price,
            d.count,
            d.total_price,
            d.s_title,
            d.discount_amount,
            p.title
        FROM
            shop_refund_record r
            LEFT JOIN shop_order o ON r.order_id = o.id
            LEFT JOIN shop_order_details d ON r.order_id = d.order_id
            LEFT JOIN shop_product p ON d.p_id = p.id
        WHERE
            r.order_id = #{orderId}
    </select>
 
    <!-- 根据id查询带出订单产品等-->
    <select id="selectRefundById" resultMap="ShopRefundRecordComplexMap">
        select
        <include refid="columns" ></include>
        from shop_refund_record
        where  id=#{id}
    </select>
 
    <!-- 根据用户id查询-->
    <select id="selectByRefundUserId" resultMap="ShopRefundRecordComplexMap">
        select
        <include refid="columns" ></include>
        from shop_refund_record
        <where>
            <if test="record!=null">
                <if test="(record.userId!=null and record.userId!='') or  (record.userId!='' and record.userId==0)  ">
                    and user_id = #{record.userId}
                </if>
            </if>
        </where>
        order by create_time desc
        <if test="record.offset >=0  and record.limit >0">
            limit
            #{record.offset},#{record.limit}
        </if>
    </select>
 
 
    <!-- 根据id 锁表查询-->
    <select id="selectForUpdate" resultMap="ShopRefundRecordMap">
        select 
        <include refid="columns" ></include>
        from shop_refund_record
        where  id=#{id} 
        for update
    </select>    
    
    
    
    <!-- 根据对象查询-->
    <select id="selectByModel" resultMap="ShopRefundRecordMap">
        select 
        <include refid="columns" ></include>
        from shop_refund_record
        <where>
          <include refid="where_sql"></include>
         </where>
    </select>
</mapper>