zhouxiang
2023-02-23 bec88badaeb0341a1d5429b31357eb37c0b16fb0
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
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
package com.hx.phip.util.api;
 
import com.alibaba.fastjson.JSON;
import com.hx.common.service.CommonService;
import com.hx.mybatisTool.SqlSentence;
import com.hx.phiappt.common.*;
import com.hx.phiappt.constants.enums.GroupTypeEnum;
import com.hx.phiappt.constants.tool.RefundToolUtil;
import com.hx.phiappt.constants.tool.SqlSplicingTool;
import com.hx.phiappt.model.BaseEntity;
import com.hx.phiappt.model.UserMoney;
import com.hx.phiappt.model.activity.ActivityAction;
import com.hx.phiappt.model.activity.ActivityRule;
import com.hx.phiappt.model.consume.ConsumePay;
import com.hx.phiappt.model.coupon.CouponNumber;
import com.hx.phiappt.model.coupon.CouponOrderDiscountLog;
import com.hx.phiappt.model.order.*;
import com.hx.phiappt.model.refund.*;
import com.hx.phiappt.model.user.UserCard;
import com.hx.phiappt.model.user.UserCardUsed;
import com.hx.phiappt.model.user.UserProject;
import com.hx.phiappt.model.user.UserProjectItem;
import com.hx.phiappt.model.userMoney.UserMoneyUnclaimed;
import com.hx.phip.config.CustomParameter;
import com.hx.phip.dao.mapper.*;
import com.hx.util.StringUtils;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @Author
 */
public class PartialRefundUtil {
    private static final Logger logger = LoggerFactory.getLogger(PartialRefundUtil.class);
    /**
     * 退款总流程工具
     * @param commonService
     * @param operationId
     * @param operationNme
     * @param refundId
     * @param
     * @param appIdCode
     */
    public static OrdersTotal refundProcess(CommonService commonService, String operationId, String operationNme, String refundId, CustomParameter customParameter, String appIdCode) {
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> map=new HashMap<>();
        sqlSentence.setM(map);
        //退款成功
        map.put("refundStatus", RefundStatus.STATUS_APPLY_REFUND);
        map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND);
        map.put("refundId", refundId);
        sqlSentence.setSqlSentence("select * from refund_record where isDel=0 and refundStatus=#{m.refundStatus} and id=#{m.refundId}");
        RefundRecord refundRecord =commonService.selectOne(RefundRecordMapper.class,sqlSentence);
        if(refundRecord ==null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"找不到该退款信息!");
        }
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append("select name,actualTotal,refundRecordId,refundNumberNo as numberNo,id,consumePayId from refund_record_method WHERE refundRecordId  in (");
        SqlSplicingTool.selectIn(stringBuffer, Arrays.asList((String) map.get("refundId")));
        sqlSentence.setSqlSentence(stringBuffer.toString());
        List<Map<String, Object>> refundMethodList = commonService.selectListMap(RefundRecordMethodMapper.class,sqlSentence);
        if(refundMethodList==null && refundMethodList.size()==0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"没有找到该退款订单对应的支付方式");
        }
        //查看订单信息
        OrdersTotal ordersTotal=commonService.selectOneByKeyBlob(OrdersTotalMapper.class,refundRecord.getOrderId());
        if(ordersTotal==null ){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到订单信息!");
        }
        //查看订单其他信息
        map.put("orderId", ordersTotal.getId());
        sqlSentence.setSqlSentence("select * from orders_info where isDel=0 and orderId=#{m.orderId}");
        OrderInfo orderInfo=commonService.selectOne(OrderInfoMapper.class,sqlSentence);
 
        //查询用户是否有账户信息,退款需要处理资金
        map.put("userId",refundRecord.getUserId());
        sqlSentence.setSqlSentence("select * from user_money WHERE  userId=#{m.userId} and isDel=0");
        UserMoney userMoney=commonService.selectOne(UserMoneyMapper.class,sqlSentence);
        if(userMoney==null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到该用户的资金信息");
        }
        //处理优惠券
        handCoupon(commonService, sqlSentence, map, refundRecord,ordersTotal);
 
        if(OrderTotalConstants.TYPE_RECHARGE.equals(ordersTotal.getType())){
            //充值订单需要把充值的储值金 拿回来   因为储值金需要开单来处理,所以不需要增加日志
            //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
            if(ordersTotal.getTotal().compareTo(BigDecimal.ZERO)!=0){
                UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式储值金额退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),new BigDecimal(String.valueOf(ordersTotal.getTotal())).negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
                OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, "储值金客户退回金额:"+ordersTotal.getTotal(), 0, OrderLogConstants.LOG_TYPE_REFUND);
                commonService.insert(OrderLogMapper.class,orderLog);
                //活动规则退款处理
                handActivityRule(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,orderInfo);
            }
 
        }else if(OrderTotalConstants.TYPE_CARD_BAG.equals(ordersTotal.getType())){
            //卡包处理
            numberOfRefunds(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,customParameter);
        } else {
            //普通订单处理
            if(refundRecord.getRefundType() ==0){
                numberOfRefunds(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,customParameter);
            }
        }
 
 
 
        //增加增值金
        boolean cashStatus=false;//判断是否有现金或者其他现金支付
        ConsumePay consumePay;
        for(Map<String,Object> methodMap:refundMethodList){
            BigDecimal actualTotal=(BigDecimal) methodMap.get("actualTotal");
            String name=(String) methodMap.get("name");
            String id=(String) methodMap.get("id");
            String consumePayId=(String) methodMap.get("consumePayId");
            if(PayMethodTypeConstants.PAY_STORED.equals(methodMap.get("numberNo"))){
 
                //储值金额 
                //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                if(actualTotal.compareTo(BigDecimal.ZERO)!=0){
                    UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式储值金额退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
                    OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord, operationId, operationNme, name+"退款金额:"+actualTotal, 0, OrderLogConstants.LOG_TYPE_REFUND);
                    commonService.insert(OrderLogMapper.class,orderLog);
                }
            }else if(PayMethodTypeConstants.PAY_ADD_FUND.equals(methodMap.get("numberNo"))){
                //增值金
                //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                if(actualTotal.compareTo(BigDecimal.ZERO)!=0){
                    UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式增值金退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                    OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name,0, OrderLogConstants.LOG_TYPE_REFUND);
                    commonService.insert(OrderLogMapper.class,orderLog);
                }
            }else if(PayMethodTypeConstants.PAY_INTEGRAL.equals(methodMap.get("numberNo"))){
                //积分
                //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                if(actualTotal.compareTo(BigDecimal.ZERO)!=0){
                    UserMoneyUtil.setNewUserMoneyUnclaimed(ordersTotal.getPayUserId()==null?ordersTotal.getUserId():ordersTotal.getPayUserId(),refundRecord.getRemarks(),"审核通过退款:支付方式积分退回",operationId,refundRecord.getOrderId(),appIdCode,refundRecord.getId(),actualTotal, UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                    OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name+"退款金额:"+actualTotal,0, OrderLogConstants.LOG_TYPE_REFUND);
                    commonService.insert(OrderLogMapper.class,orderLog);
                }
            }else {
                cashStatus=true;
                //现金支付
                if(actualTotal.compareTo(BigDecimal.ZERO)<1){
                    continue;
                }
                OrderLog orderLog = RefundToolUtil.setOrderLog(refundRecord,operationId,operationNme,name+"退款金额:"+actualTotal,0, OrderLogConstants.LOG_TYPE_REFUND);
                orderLog.setOrderId(ordersTotal.getId());
                commonService.insert(OrderLogMapper.class,orderLog);
 
                //现金支付需要创建创建退款单进行退款
                RefundNote refundNote=new RefundNote(actualTotal, (String) methodMap.get("numberNo"),name,ordersTotal.getId(),refundRecord.getUserId());
                refundNote.setRefundRecordId(refundRecord.getId());
                commonService.insert(RefundNoteMapper.class,refundNote);
            }
            //修改实际退款金额
            sqlSentence.setSqlSentence(" realRefundTotal=#{m.realRefundTotal} where   id=#{m.refundMethodId}");
            map.put("realRefundTotal",actualTotal);
            map.put("refundMethodId",id);
            commonService.updateWhere(RefundRecordMethodMapper.class,sqlSentence);
 
            //修改支付方式已退款金额
            consumePay=commonService.selectOneByKey(ConsumePayMapper.class,consumePayId);
            consumePay.setRefundTotal(consumePay.getRefundTotal().add(actualTotal));
            commonService.updateAll(ConsumePayMapper.class,consumePay);
 
        }
 
        //退款总订单
        map.put("refundStatus", RefundStatus.STATUS_SUCC_REFUND);
        map.put("oldRefundStatus", RefundStatus.STATUS_APPLY_REFUND);
        map.put("editTime", new Date());
        map.put("refundId", refundId);
        map.put("isDel", BaseEntity.NO);
        sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus},editTime=#{m.editTime} where id=#{m.refundId} and isDel=#{m.isDel} and refundStatus=#{m.oldRefundStatus}");
        commonService.updateWhere(RefundRecordMapper.class,sqlSentence);
 
        //更改总订单退款状态
        map.put("orderId",ordersTotal.getId());
        sqlSentence.setSqlSentence("select * from order_item WHERE  orderId=#{m.orderId} and isDel=0");
        List<OrderItem> orderItemList=commonService.selectList(OrderItemMapper.class,sqlSentence);
 
        List<Integer> collect = orderItemList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList());
        if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
            ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
            ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
            ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
            ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
            ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE);
        }else {
            ordersTotal.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
            ordersTotal.setStatus(OrderTotalConstants.STATUS_CANCEL);
            ordersTotal.setReTotal(orderItemList.stream().map(OrderItem::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }
        ordersTotal.setIsSyncOrder(BaseEntity.NO);
        ordersTotal.setEditTime(new Date());
        commonService.updateAll(OrdersTotalMapper.class,ordersTotal);
        return ordersTotal;
    }
    /**
     * 退款-处理优惠券
     * @param commonService
     * @param sqlSentence
     * @param map
     * @param refundRecord
     */
    public static void handCoupon(CommonService commonService,  SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal) {
        map.put("refundRecordId",refundRecord.getId());
        sqlSentence.setSqlSentence("select * from refund_record_coupon where  refundRecordId=#{m.refundRecordId} and isDel=0 ");
        List<RefundRecordCoupon> refundRecordCouponList=commonService.selectList(RefundRecordCouponMapper.class,sqlSentence);
        //退款成功
        map.put("status", BaseEntity.YES);
        CouponOrderDiscountLog couponOrderDiscountLog=null;
        for (RefundRecordCoupon refundRecordCoupon : refundRecordCouponList) {
            sqlSentence.setSqlSentence("  status=#{m.status} WHERE id = #{m.id}  ");
            map.put("id", refundRecordCoupon.getCouponOrderId());
            couponOrderDiscountLog=commonService.selectOneByKey(CouponOrderDiscountLogMapper.class,refundRecordCoupon.getCouponOrderId());
            if(couponOrderDiscountLog==null){
                throw new PlatTipsException(PlatformCode.ERROR_TIPS,"订单优惠卷id不正确");
            }
            commonService.updateWhere(CouponOrderDiscountLogMapper.class,sqlSentence);
 
            if("his_coupon_code".equals(couponOrderDiscountLog.getCouponNumberId())){
                continue;
            }
            map.put("isUse", BaseEntity.NO);
            map.put("useTime", null);
            map.put("useType", CouponNumber.USE_TYPE_UNKNOW);
            map.put("id", couponOrderDiscountLog.getCouponNumberId());
            sqlSentence.setSqlSentence("  isUse=#{m.isUse},useTime=#{m.useTime},useType=#{m.useType},isUse=#{m.isUse} WHERE id = #{m.id}  ");
            commonService.updateWhere(CouponNumberMapper.class,sqlSentence);
        }
 
 
    }
 
    /**
     * 退款-处理活动规则增值金和积分
     * @param commonService
     * @param operationId
     * @param operationNme
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param ordersTotal
     */
    private static void handActivityRule(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence,
                                         Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, OrderInfo orderInfo) {
        if(orderInfo!=null && StringUtils.noNull(orderInfo.getActivityId())){
            ActivityRule activityRule=commonService.selectOneByKeyBlob(ActivityRuleMapper.class,orderInfo.getActivityId());
            if(activityRule!=null){
                map.put("activityRuleId",activityRule.getId());
                map.put("type", ActivityAction.TYPE_INTEGRAL);
                map.put("type1",ActivityAction.TYPE_VALUEADDEDFUND);
                map.put("type2",ActivityAction.TYPE_COUPON);
                sqlSentence.setSqlSentence("select * from activity_action where activityRuleId=#{m.activityRuleId} and (type=#{m.type} or type=#{m.type1} or type=#{m.type2}) and isDel=0");
                List<ActivityAction> activityActions = commonService.selectList(ActivityActionMapper.class, sqlSentence);
                if(activityActions!=null && activityActions.size()>0){
                    for (ActivityAction activityAction : activityActions) {
                        if(ActivityAction.TYPE_INTEGRAL.equals(activityAction.getType())){
                            //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                            if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){
                                UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"退款扣减活动规则赠送积分",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                            }
                        }else if(ActivityAction.TYPE_VALUEADDEDFUND.equals(activityAction.getType())){
                            //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                            if(new BigDecimal(activityAction.getWorth()).negate().compareTo(BigDecimal.ZERO)!=0){
                                UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"退款扣减活动规则赠送增值金",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),new BigDecimal(activityAction.getWorth()).negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                            }
                        }else if(ActivityAction.TYPE_COUPON.equals(activityAction.getType())){
                            map.put("oldValidState",BaseEntity.YES);
                            map.put("newValidState",BaseEntity.NO);
                            map.put("couponId",activityAction.getCrmCouponId());
                            map.put("commonId",ordersTotal.getId());
                            sqlSentence.setSqlSentence(" validState=#{m.newValidState} where couponId=#{m.couponId} and commonId=#{m.commonId} and validState=#{m.oldValidState} ");
                            commonService.updateWhere(CouponNumberMapper.class,sqlSentence);
                        }
                    }
                }
            }
        }
 
    }
    /**
     * 退款-处理普通订单信息(比如:项目、促销、卡项)
     * @param commonService
     * @param operationId               操作人标识
     * @param operationNme              操作人名称
     * @param sqlSentence
     * @param map
     * @param refundRecord
     */
    public static void numberOfRefunds(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence,
                                       Map<String, Object> map, RefundRecord refundRecord,OrdersTotal ordersTotal,CustomParameter customParameter) {
        map.put("refundId",map.get("refundId"));
        sqlSentence.setSqlSentence("select * from refund_record_item where isDel=0 and refundRecordId=#{m.refundId}");
        List<RefundRecordItem> refundRecordItems =commonService.selectList(RefundRecordItemMapper.class,sqlSentence);
        if(refundRecordItems==null && refundRecordItems.size()==0){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到退款子订单信息");
        }
        for (RefundRecordItem v: refundRecordItems) {
            switch (v.getType()){
                case OrderItemConstants.TYPE_RETAIL:
                    handRefundRerail(commonService, sqlSentence, map, refundRecord, v);
                    break;
                case OrderItemConstants.TYPE_DRUG:
                    handRefundRerail(commonService, sqlSentence, map, refundRecord, v);
                    break;
                case OrderItemConstants.TYPE_PROJECT:
                    handRefundNoExecution(commonService, operationId, operationNme, sqlSentence, map, refundRecord, v);
                    break;
                case OrderItemConstants.TYPE_PROMOTION:
                    handRefundPromotion(commonService, operationId, operationNme, sqlSentence, map, refundRecord, ordersTotal, v);
                    break;
                case OrderItemConstants.TYPE_CARD:
                    handRefundCard(commonService, operationId, sqlSentence, map, refundRecord, ordersTotal, v);
                    break;
                case OrderItemConstants.CARD_BAG:
                    handCardBag(commonService, operationId, operationNme, sqlSentence, map, refundRecord,ordersTotal,v,customParameter);
                    break;
                default:break;
            }
        }
    }
 
    /**
     * 退款一级是商品
     * @param commonService
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param v
     */
    private static void handRefundRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) {
 
        //判断操作完了去修改子订单状态
        OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
        if (orderItem==null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
        }
        map.put("isDel", BaseEntity.NO);
        map.put("orderItemId", v.getOrderItemId());
        map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
        Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum();
        map.put("hasReNum",hasReNum);
        if (hasReNum==orderItem.getBuyNum()){
            map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH);
        }else {
            map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART);
        }
 
        sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
        commonService.updateWhere(OrderItemMapper.class,sqlSentence);
    }
    /**
     * 退款-处理未执行划扣   项目类型
     * @param commonService
     * @param operationId               操作人
     * @param operationNme              操作人名称
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param v
     */
    private static void handRefundNoExecution(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItem v) {
        sqlSentence.setSqlSentence("select * from user_project_item where isDel=0 and commonId='"+v.getOrderItemId()+"' and shopId='"+refundRecord.getRefundShopId()+"' " +
                " and userId ='"+refundRecord.getUserId()+"'");
        UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence);
        if (userProjectItem == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到用户子项项目信息");
        }
        Integer usedNum=userProjectItem.getNotUsedNum()-v.getRefundNum();
        Integer cancelNum=userProjectItem.getCancelNum()+v.getRefundNum();
 
        map.put("usedNum", usedNum);
        map.put("isDel", BaseEntity.NO);
        map.put("cancelNum", cancelNum);
        map.put("userProjectItemId", userProjectItem.getId());
        sqlSentence.setSqlSentence(" cancelNum=#{m.cancelNum},notUsedNum=#{m.usedNum} where isDel=#{m.isDel} AND id=#{m.userProjectItemId} AND notUsedNum > 0 ");
        commonService.updateWhere(UserProjectItemMapper.class,sqlSentence);
 
        UserProject userProject=commonService.selectOneByKey(UserProjectMapper.class,userProjectItem.getUserProjectId());
        userProject.setNotUsedNum(userProject.getNotUsedNum()-v.getRefundNum());
        commonService.updateAll(UserProjectMapper.class,userProject);
        //判断操作完了去修改子订单状态
        OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
        if (orderItem==null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
        }
 
        Integer refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
        if(usedNum==0){
            //已经没有可以执行数量
            refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH;
        }else {
            refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
        }
        map.put("orderItemId", v.getOrderItemId());
        map.put("refundStatus", refundStatus);
        map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
        map.put("hasReNum",cancelNum/(orderItem.getUsedTotal()/orderItem.getBuyNum()));
 
        sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
        commonService.updateWhere(OrderItemMapper.class,sqlSentence);
    }
    /**
     * 退款-处理卡项
     * @param commonService
     * @param operationId
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param ordersTotal
     * @param v
     */
    public static void handRefundCard(CommonService commonService, String operationId, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) {
 
        //判断操作完了去修改子订单状态
        OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
        if (orderItem==null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息");
        }
        //作废卡包
 
        map.put("hisOrderId",ordersTotal.getHisOrderId());
        map.put("orderId",ordersTotal.getId());
        map.put("effectiveStatus",UserProjectConstants.EFF_STATUS_YES);
        map.put("status",UserCard.TYPE_NO_USED);
        map.put("isDel",BaseEntity.NO);
        sqlSentence.setSqlSentence("select id from user_card where (hisOrderId =#{m.hisOrderId} OR orderId =#{m.orderId})  AND effectiveStatus=#{m.effectiveStatus} AND status=#{m.status} AND doneeUserId IS NULL AND isDel=#{m.isDel}  ");
        List<UserCard> userCards = commonService.selectList(UserCardMapper.class, sqlSentence);
        if(userCards==null || userCards.size()==0){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"退款作废卡包提示:没有找到对应的卡包可退:"+ordersTotal.getId());
        }else {
            UserCard userCard=null;
            for (int i = 0; i < v.getRefundNum(); i++) {
                userCard=userCards.get(i);
                map.put("id",userCard.getId());
                map.put("effectiveStatus", UserProjectConstants.EFF_STATUS_CANCEL);
                sqlSentence.setSqlSentence(" effectiveStatus=#{m.effectiveStatus} where id=#{m.id} ");
                commonService.updateWhere(UserCardMapper.class,sqlSentence);
            }
        }
 
        //更改订单子订单状态
        map.put("orderItemId", v.getOrderItemId());
        map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
        Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum();
        map.put("hasReNum",hasReNum);
        if (hasReNum==orderItem.getBuyNum()){
            map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH);
        }else {
            map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART);
        }
 
 
        sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
        commonService.updateWhere(OrderItemMapper.class,sqlSentence);
    }
 
    /**
     * 退款-处理卡包
     * @param commonService
     * @param operationId
     * @param operationNme
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param ordersTotal
     * @param v
     */
    public static void handCardBag(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map,
                                   RefundRecord refundRecord, OrdersTotal ordersTotal,RefundRecordItem v,CustomParameter customParameter) {
        //查看订单信息
        OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
        if(orderItem==null ){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息!");
        }
        map.put("refundRecordItemId",v.getId());
        sqlSentence.setSqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}");
        List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence);
        if( sons!=null && sons.size()>0 ){
            for (RefundRecordItemSource son : sons) {
                switch (GroupTypeEnum.getCode(son.getType())){
                    case PROJECT:
                        handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son);
                        deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem);
                        break;
                    case RETAIL:
                        handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son);
                        deleteUserCardUsed(sqlSentence,map,ordersTotal,commonService,son,orderItem);
                        break;
                    case INCREMENT:
                        //增值金
                        //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                        if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
                            UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送增值金扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                        }
                        break;
                    case STORED:
                        //储值金额
                        //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                        if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
                            UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送储值金额扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
                        }
                        break;
                    case INTEGRAL:
                        //积分
                        //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                        if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
                            UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送积分扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                        }
                        break;
                }
            }
        }
        //更改二级子订单退款状态
 
        map.put("orderItemId",orderItem.getId());
        sqlSentence.setSqlSentence("select * from order_item_source WHERE  orderItemId=#{m.orderItemId} and isDel=0");
        List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence);
 
        List<Integer> collect = orderItemSonList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList());
        if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
            orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
            orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE);
        }else {
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
            orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
            orderItem.setHasReNum(orderItem.getBuyNum());
        }
 
        commonService.updateAll(OrderItemMapper.class,orderItem);
    }
 
    /**
     * 退款需要删除用户卡包使用记录
     * @param sqlSentence
     * @param map
     * @param ordersTotal
     * @param commonService
     * @param son
     */
    public static void deleteUserCardUsed(SqlSentence sqlSentence, Map<String, Object> map,OrdersTotal ordersTotal,CommonService commonService,RefundRecordItemSource son,OrderItem orderItem){
 
 
        OrderItemSon orderItemSon=commonService.selectOneByKey(OrderItemSonMapper.class,son.getOrderItemSonId());
        Integer hasReNum=orderItemSon.getHasReNum();
 
        map.put("isDel",BaseEntity.NO);
        map.put("orderId",ordersTotal.getId());
        map.put("commonId",orderItemSon.getGoodsId());
        sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE orderId = #{m.orderId} and commonId=#{m.commonId} ORDER BY isDel,createTime  ");
        List<UserCardUsed> userCardUsedList=commonService.selectList(UserCardUsedMapper.class,sqlSentence);
 
        if(userCardUsedList==null || userCardUsedList.size()==0){
            //因为可能领建的老订单所以伪造的操作记录是没数据的
            map.put("userCardId",orderItem.getCommonId());
            sqlSentence.setSqlSentence(" SELECT * FROM user_card_used WHERE commonId=#{m.commonId} and userCardId=#{m.userCardId} ORDER BY isDel,createTime  ");
            userCardUsedList=commonService.selectList(UserCardUsedMapper.class,sqlSentence);
        }
 
        UserCardUsed userCardUsed;
        for (int i = 0; i < hasReNum; i++) {
            userCardUsed=userCardUsedList.get(i);
            userCardUsed.setIsDel(BaseEntity.YES);
            commonService.updateAll(UserCardUsedMapper.class,userCardUsed);
        }
    }
    /**
     * 退款-处理促销
     * @param commonService
     * @param operationId
     * @param operationNme
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param ordersTotal
     * @param v
     */
    private static void handRefundPromotion(CommonService commonService, String operationId, String operationNme, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, OrdersTotal ordersTotal, RefundRecordItem v) {
        //查看订单信息
        OrderItem orderItem=commonService.selectOneByKey(OrderItemMapper.class,v.getOrderItemId());
        if(orderItem==null ){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到子订单信息!");
        }
 
        map.put("refundRecordItemId",v.getId());
        sqlSentence.setSqlSentence("select * from refund_record_item_source where refundRecordItemId =#{m.refundRecordItemId}");
        List<RefundRecordItemSource> sons = commonService.selectList(RefundRecordItemSourceMapper.class, sqlSentence);
        if( sons!=null && sons.size()>0 ){
            for (RefundRecordItemSource son : sons) {
                switch (GroupTypeEnum.getCode(son.getType())){
                    case PROJECT:
                        v.setOrderItemId(son.getId());
                        v.setRefundNum(son.getRefundNum());
                        handRefundNoSonExecution(commonService, sqlSentence, map, refundRecord, son);
                        break;
                    case RETAIL:
                        v.setOrderItemId(son.getId());
                        v.setRefundNum(son.getRefundNum());
                        handRefundSonRerail(commonService, sqlSentence, map, refundRecord, son);
                        break;
                    case INCREMENT:
                        //增值金
                        //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                        if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
                            UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送增值金扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_VALUE_ADDED_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                        }
                        break;
                    case STORED:
                        //储值金额
                        //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                        if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
                            UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送储值金额扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_STORED_VALUE_FUND, OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.NO);
                        }
                        break;
                    case INTEGRAL:
                        //积分
                        //判断金额不等于0,才执行操作,不然操作余额的时候会爆操作数量或金额不能为0
                        if(son.getRealRefundTotal().negate().compareTo(BigDecimal.ZERO)!=0){
                            UserMoneyUtil.setNewUserMoneyUnclaimed(refundRecord.getUserId(),refundRecord.getRemarks(),"审核通过退款:促销赠送积分扣减",operationId,refundRecord.getOrderId(),ordersTotal.getAppIdCode(),refundRecord.getId(),son.getRealRefundTotal().negate(), UserMoneyUnclaimed.FUND_TYPE_INTEGRAL,OperationReasonConstants.OP_REASON_RECHARGE_REFUND,commonService,UserMoneyUnclaimed.YES);
                        }
                        break;
                }
            }
        }
 
        //更改二级子订单退款状态
 
        map.put("orderItemId",orderItem.getId());
        sqlSentence.setSqlSentence("select * from order_item_source WHERE  orderItemId=#{m.orderItemId} and isDel=0");
        List<OrderItemSon> orderItemSonList=commonService.selectList(OrderItemSonMapper.class,sqlSentence);
 
        List<Integer> collect = orderItemSonList.stream().map(o -> o.getRefundStatus()).collect(Collectors.toList());
        if(collect.contains(OrderTotalConstants.STATUS_REFUND_PART)){
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
            orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE) && collect.contains(OrderTotalConstants.STATUS_REFUND_FINSH)){
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_PART);
            orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
        }else if (collect.contains(OrderTotalConstants.STATUS_REFUND_NONE)){
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_NONE);
        }else {
            orderItem.setRefundStatus(OrderTotalConstants.STATUS_REFUND_FINSH);
            orderItem.setReTotal(orderItemSonList.stream().map(OrderItemSon::getReTotal).reduce(BigDecimal.ZERO,BigDecimal::add));
            orderItem.setHasReNum(orderItem.getBuyNum());
        }
 
        commonService.updateAll(OrderItemMapper.class,orderItem);
    }
    /**
     * 退款-处理二级子订单未执行划扣   项目类型
     * @param commonService
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param v
     */
    private static void handRefundNoSonExecution(CommonService commonService, SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) {
        sqlSentence.setSqlSentence("select * from user_project_item where isDel=0 and commonId='"+v.getOrderItemSonId()+"' and shopId='"+refundRecord.getRefundShopId()+"' " +
                " and userId ='"+refundRecord.getUserId()+"'");
        UserProjectItem userProjectItem =commonService.selectOne(UserProjectItemMapper.class,sqlSentence);
        if (userProjectItem == null) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到用户子项项目信息");
        }
        Integer usedNum=userProjectItem.getNotUsedNum()-v.getRefundNum();
        Integer cancelNum=userProjectItem.getCancelNum()+v.getRefundNum();
 
        map.put("usedNum", usedNum);
        map.put("isDel", BaseEntity.NO);
        map.put("cancelNum", cancelNum);
        map.put("userProjectItemId", userProjectItem.getId());
        sqlSentence.setSqlSentence(" cancelNum=#{m.cancelNum},notUsedNum=#{m.usedNum} where isDel=#{m.isDel} AND id=#{m.userProjectItemId} AND notUsedNum > 0 ");
        commonService.updateWhere(UserProjectItemMapper.class,sqlSentence);
 
        UserProject userProject=commonService.selectOneByKey(UserProjectMapper.class,userProjectItem.getUserProjectId());
        userProject.setNotUsedNum(userProject.getNotUsedNum()-v.getRefundNum());
        commonService.updateAll(UserProjectMapper.class,userProject);
        //判断操作完了去修改子订单状态
        OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId());
        if (orderItem==null){
            logger.info("二级子订单id:{}",v.getOrderItemSonId());
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息");
        }
        Integer refundStatus=OrderTotalConstants.STATUS_REFUND_NONE;
        if(usedNum==0){
            //已经没有可以执行数量
            refundStatus=OrderTotalConstants.STATUS_REFUND_FINSH;
        }else {
            refundStatus=OrderTotalConstants.STATUS_REFUND_PART;
        }
        map.put("orderItemId", v.getOrderItemSonId());
        map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
        map.put("hasReNum",cancelNum/(orderItem.getUsedTotal()/orderItem.getBuyNum()));
        map.put("refundStatus", refundStatus);
        sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
        commonService.updateWhere(OrderItemSonMapper.class,sqlSentence);
    }
    /**
     * 退款二级是商品
     * @param commonService
     * @param sqlSentence
     * @param map
     * @param refundRecord
     * @param v
     */
    private static void handRefundSonRerail(CommonService commonService,SqlSentence sqlSentence, Map<String, Object> map, RefundRecord refundRecord, RefundRecordItemSource v) {
 
        //判断操作完了去修改子订单状态
        OrderItemSon orderItem=commonService.selectOneByKey(OrderItemSonMapper.class,v.getOrderItemSonId());
        if (orderItem==null){
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"未找到二级子订单信息");
        }
 
        map.put("orderItemId", v.getOrderItemSonId());
        map.put("reTotal",orderItem.getReTotal().add(v.getRefundMoney()));
        Integer hasReNum=orderItem.getHasReNum()+v.getRefundNum();
        map.put("hasReNum",hasReNum);
        map.put("isDel",BaseEntity.NO);
        if (hasReNum==orderItem.getBuyNum()){
            map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_FINSH);
        }else {
            map.put("refundStatus", OrderTotalConstants.STATUS_REFUND_PART);
        }
 
        sqlSentence.setSqlSentence(" refundStatus=#{m.refundStatus}, reTotal=#{m.reTotal}, hasReNum=#{m.hasReNum} where isDel=#{m.isDel} AND id=#{m.orderItemId} ");
        commonService.updateWhere(OrderItemSonMapper.class,sqlSentence);
    }
}