sunshine
2024-11-05 1bd51ea22b75760704843d9bed886a7262bb1cb1
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
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
package com.nova.sankuai.infra.utils.eshidai;
 
import cn.hutool.core.map.MapBuilder;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.IdUtil;
import cn.hutool.crypto.digest.MD5;
import cn.hutool.crypto.symmetric.AES;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.nova.sankuai.domain.api.esd.EsdResponse;
import com.nova.sankuai.domain.entity.*;
import com.nova.sankuai.domain.enums.capitalInfo.CapitalInfoTypeCodeEnum;
import com.nova.sankuai.domain.vo.capitalresult.LvdiPushResultVo;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.mapper.CustomerCapitalResultMapper;
import com.nova.sankuai.infra.mapper.CustomerMapper;
import com.nova.sankuai.infra.utils.RbUtil;
import com.nova.sankuai.infra.utils.ResultJson;
import com.nova.sankuai.infra.utils.UserUtil;
import com.nova.sankuai.security.HttpClientUtil;
import com.nova.sankuai.security.UserDetail;
import com.nova.sankuai.service.IChannelInfoService;
import com.nova.sankuai.service.ICustomerScyIncomeService;
import com.nova.sankuai.service.ICustomerUserService;
import com.nova.sankuai.service.IPlatformCapitalService;
import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.DigestUtils;
 
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.TreeMap;
 
/**
 * e时贷对接
 */
@Component
@RequiredArgsConstructor
public class EsdUtil {
    private static final Logger log = LoggerFactory.getLogger("capitalLogger");
 
    // e时贷在capital_info数据库中的ID
    private static final Long capitalId = 25L;
 
    @Value("${eshidai.basicUrl}")
    private String basicUrl;
 
    @Value("${eshidai.clientId30}")
    private String clientId30;
 
    @Value("${eshidai.secretKey30}")
    private String secretKey30;
 
 
    private final CustomerMapper customerMapper;
    private final CustomerCapitalResultMapper capitalResultMapper;
    private final ICustomerUserService customerUserService;
    private final ICustomerScyIncomeService customerZcyIncomeService;
    private final IChannelInfoService channelInfoService;
 
    public static int checkValue(double value) {
        if (value < 30000) {
            return 1; // 3万以下
        } else if (value >= 30000 && value < 100000) {
            return 2; // 3万到10万
        } else if (value >= 100000 && value < 200000) {
            return 3; // 10万到20万
        } else {
            return 4; // 20万以上
        }
    }
 
    private JSONObject getParam(Customer customer) {
 
        JSONObject param = new JSONObject();
        param.put("userName", customer.getName());
        String sex = customer.getSex();
        param.put("sex", "男".equals(sex) ?  0 : 1);
        //param.put("city", "临沧市"); // 测试数据
        param.put("city", customer.getCityName());
        //param.put("city", "临沧市"); // 测试数据
        /* age    String    是    25    年龄(25-55之间)*/
        Integer age = customer.getAge();
        //age = 18;// 测试数据
        param.put("age", Objects.isNull(age) ? 25 : age);
 
        // 业务参数
        /**
         * 逾期
         * 1 ⽆逾期
         * 2 当前有逾期
         * 3 ⼀年以内⽆逾期
         */
        Random random = new Random();
        int[] values  = {1, 2, 3};
        // 随机选取一个字符
        //param.put("overdue", String.valueOf(values[random.nextInt(values.length)]));
        param.put("overdue", 1);
 
        // 获取source_channel
        Integer sourceChannel = customer.getSourceChannel();
        Integer version2Type = 0;//判断是否2.0开关子参数
        if (!Objects.isNull(sourceChannel)) {
            ChannelInfo channelInfo = channelInfoService.getOne(new LambdaQueryWrapper<ChannelInfo>().eq(ChannelInfo::getCode, sourceChannel).last(" limit 1 "));
            version2Type = channelInfo.getVersion2Type();
        }
        int soci, realEstateInfo, providentFund, insurancePolicy, creditLimit = 0;
 
        if (version2Type == 1) { //线上放款
            values = new int[]{2, 3, 4};
            /*社保缴纳*/
            soci = values[random.nextInt(values.length)];
            /*公积金*/
            providentFund = values[random.nextInt(values.length)];
            /*保险保单*/
            insurancePolicy = values[random.nextInt(values.length)];
 
            /*房产情况*/
            values = new int[]{2, 3, 4, 5, 6}; // 指定的字符集合
            realEstateInfo = values[random.nextInt(values.length)];
 
            /*信用卡额度*/
            values = new int[]{1, 2, 3, 4, 5, 6}; // 指定的字符集合
            creditLimit = values[random.nextInt(values.length)];
 
 
        }else{ //银行直贷
            /**
             * 社保缴纳
             * 1 ⽆社保
             * 2 缴纳6个⽉以下
             * 3 缴纳6个⽉以上
             * 4 有社保
             */
            // 随机选取一个字符
            Integer socialSecurity = customer.getSocialSecurity();
            int soc = Objects.isNull(socialSecurity) ? 0 : socialSecurity.intValue();
            if (soc == 1) {
                soci = 2;
            }else if (soc == 2) {
                soci = 3;
            }else {
                values = new int[]{2, 3, 4}; // 指定的字符集合
                soci = values[random.nextInt(values.length)];
            }
 
            /**
             * 房产情况
             * 1 ⽆房产
             * 2 有房不抵押
             * 3 有房可抵押
             * 4 有房产
             * 5 有按揭房产
             * 6 有全款房产
             */
            Integer house = customer.getHouseStatus();
            int hs = Objects.isNull(house) ? 0 : house.intValue();
            if (hs == 4) {
                realEstateInfo = 5;
            }else if (hs == 5) {
                realEstateInfo = 6;
            }else {
                values = new int[]{2, 3, 4, 5, 6}; // 指定的字符集合
                realEstateInfo = values[random.nextInt(values.length)];
            }
 
            /**
             * 公积⾦
             * 1 ⽆公积⾦
             * 2 缴纳6个⽉以下
             * 3 缴纳6个⽉以上
             * 4 有公积⾦
             */
            Integer provident = customer.getProvidentFund();
            int pf = Objects.isNull(provident) ? 0 : provident.intValue();
            if (pf == 1) {
                providentFund = 2;
            }else if (pf == 2) {
                providentFund = 3;
            }else {
                values = new int[]{2, 3, 4}; // 指定的字符集合
                providentFund = values[random.nextInt(values.length)];
            }
 
 
            /**
             * 信⽤卡额度
             * 1 ⽆信⽤卡
             * 2 3千以下
             * 3 3千-1万
             * 4 1-3万
             * 5 3万以上
             * 6 有信⽤卡
             */
            Integer creditCard = customer.getCreditCard();
            int cc = Objects.isNull(creditCard) ? 0 : creditCard.intValue();
            if (cc == 3) {
                values = new int[]{3, 4, 6}; // 指定的字符集合
                creditLimit = values[random.nextInt(values.length)];
            } else if (cc == 0) {
                values = new int[]{2, 3, 4, 5, 6}; // 指定的字符集合
                creditLimit = values[random.nextInt(values.length)];
            }
 
            /**
             * 保险保单
             * 1 ⽆保险保单
             * 2 缴纳未满1年
             * 3 缴纳1年以上
             * 4 有保险保单
             */
            Integer insurancePolicy1 = customer.getInsurancePolicy();
            int ipl = Objects.isNull(insurancePolicy1) ? 0 : insurancePolicy1;
            if (ipl == 7) {
                values = new int[]{3, 4}; // 指定的字符集合
                // 随机选取一个字符
            } else {
                values = new int[]{2, 3, 4}; // 指定的字符集合
                // 随机选取一个字符
            }
            insurancePolicy = values[random.nextInt(values.length)];
 
        }
        param.put("socialSecurity", soci + "");
        param.put("realEstateInfo", realEstateInfo + "");
        param.put("providentFund", providentFund + "");
        param.put("creditLimit", creditLimit + "");
        param.put("insurancePolicy", insurancePolicy + "");
 
        /**
         * ⻋辆情况
         * 1 ⽆⻋产
         * 2 有⻋不抵押
         * 3 有⻋可抵押
         * 4 有⻋产
         */
        values = new int[]{2, 3, 4}; // 指定的字符集合
        int car = values[random.nextInt(values.length)];
        // 随机选取一个字符
        //car = 4;//测试数据
        param.put("carInfo", String.valueOf(car));
 
        /**
         * 贷款⾦额
         * 1 3万以下
         * 2 5万-10万
         * 3 10万-20万
         * 4 20万以上
         */
        param.put("loanAmount", String.valueOf(checkValue(customer.getLoanAmount())));
 
        /**
         * 营业执照注册年限
         * 1 未注册
         * 2 注册1年以下
         * 3 注册1~5年
         * 4 注册5年以上
         */
        values = new int[]{1, 2, 3, 4}; // 指定的字符集合
        // 随机选取一个字符
        param.put("bizLicenseYear", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * 蚂蚁花呗可⽤额度
         * 1 ⽆额度
         * 2 3千以下
         * 3 3千-1万
         * 4 1-3万
         * 5 3万以上
         */
        values = new int[]{1, 2, 3, 4, 5}; // 指定的字符集合
        // 随机选取一个字符
        param.put("hbLimit", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * 芝⿇分
         * 1 600分以下
         * 2 600~649分
         * 3 650~699分
         * 4 700分以
         */
        int sesameCredit = customer.getSesame();
        if (sesameCredit == 1) {
            sesameCredit = 2;
        }else if (sesameCredit == 2) {
            sesameCredit = 3;
        }else if (sesameCredit == 3) {
            sesameCredit = 4;
        }else {
            sesameCredit = 1;
        }
        //sesameCredit = 4;//测试数据
        param.put("sesameCredit", String.valueOf(sesameCredit));
 
        /**
         * 职业
         * 1 上班族
         * 2 ⾃由职业
         * 3 企业主(有营业执照)
         * 4 公务员或事业单位
         */
        Integer professionInfo = customer.getProfessionInfo();
        int career = Objects.isNull(professionInfo) ? 1 : professionInfo.intValue();
        if (career == 1) { //自由职业
            career = 2;
        }else if (career == 2) { // 企业主
            career = 3;
        }else if (career == 3 || career == 4) { //公务员
            career = 4;
        }else if (career == 0) { // 上班族
            career = 1;
        }
        param.put("career", career);
 
        /**
         * 京东⽩条可⽤额度
         * 1 ⽆额度
         * 2 3千以下
         * 3 3千-1万
         * 4 1-3万
         * 5 3万以上
         */
        values = new int[]{1, 2, 3, 4, 5}; // 指定的字符集合
        // 随机选取一个字符
        param.put("btLimit", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * ⽉收⼊
         * 1 1000-3000
         * 2 3000-8000
         * 3 8000~15000
         * 4 15000~30000
         * 5 30000以上
         */
        int monthlySalary = customer.getMonthlyIncome();
        if (monthlySalary == 3) {
            values = new int[]{4, 5}; // 指定的字符集合
            monthlySalary = values[random.nextInt(values.length)];
        }else if (monthlySalary == 4) {
            monthlySalary = 5;
        }else {
            values = new int[]{1, 2}; // 指定的字符集合
            monthlySalary = values[random.nextInt(values.length)];
        }
        param.put("monthlySalary", String.valueOf(monthlySalary));
 
        /**
         * 总经营流⽔
         * 1 10~50万元
         * 2 50~100万元
         * 3 100~500万元
         */
        values = new int[]{1, 2, 3}; // 指定的字符集合
        param.put("bizBankDetails", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * ⼯资发放形式
         * 1 银⾏代发打卡
         * 2 现⾦收⼊
         * 3 个⼈转账
         */
        param.put("salaryPayMethod", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * ⼯对公账⼾经营收⼊
         * 1 10~50万元
         * 2 50~100万元
         * 3 100~500万元
         */
        param.put("bizPubAccBankDetails", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * 借款⽤途
         * 1 旅游
         * 2 教育
         * 3 婚庆
         * 4 装修
         * 5 医疗
         * 6 个⼈消费
         */
        String useOfLoan = customer.getUseOfLoan();
        if ("DEC".equals(useOfLoan)) { //装修
            useOfLoan = "4";
        }else if ("EDU".equals(useOfLoan)) { // 教育
            useOfLoan = "2";
        }else {
            values = new int[]{1, 2, 3, 4, 5, 6}; // 指定的字符集合
            // 随机选取一个字符
            useOfLoan = String.valueOf(values[random.nextInt(values.length)]);
        }
        param.put("loanPurpose", useOfLoan);
 
        /**
         * 单位⼯龄
         * 1 0-6个⽉
         * 2 6-12个⽉
         * 3 12个⽉以上
         */
        values = new int[]{1, 2, 3}; // 指定的字符集合
        // 随机选取一个字符
        param.put("yearsService", String.valueOf(values[random.nextInt(values.length)]));
 
        /**
         * 学历
         * 1 初中及以下
         * 2 中专
         * 3 ⾼中
         * 4 ⼤专
         * 5 本科
         * 6 研究⽣及以上
         */
        String eduction = customer.getEducation();
        if ("02".equals(eduction)) {
            eduction = "4";
        }else if ("03".equals(eduction)) {
            eduction = "5";
        }else if ("04".equals(eduction)) {
            eduction = "6";
        }else {
            int num = random.nextInt(3) + 1;
            eduction = String.valueOf(num);
        }
        param.put("educationAttainmen", eduction);
 
        return param;
    }
 
 
    /**
     * 中诚易数据推送到e时贷操作
     */
    public boolean zcyPushToEsd(Customer customer, String logNumber) {
        boolean isSucc = false;
        log.info("日志编号:" + logNumber + ",手机号:{},中诚易数据推送到【e时贷】流程开始", customer.getPhone());
        try {
            JSONObject param = getParam(customer);
 
            isSucc = push(customer, param, logNumber);
            Integer esd = 0;
            if (!isSucc) {
                log.error("日志编号:" + logNumber + ",手机号:{},中诚易数据推送到【e时贷】失败", customer.getPhone());
            } else {
                esd = 1;
            }
            saveStatus(customer, esd);
        } catch (Exception ex) {
            log.error("日志编号:" + logNumber + ",手机号:{},中诚易数据推送到【e时贷】失败", customer.getPhone());
        }
        return isSucc;
    }
 
 
    /**
     * 我来贷数据推送到e时贷操作
     */
    public boolean wldPushToEsd(Customer customer, String logNumber) {
        boolean isSucc = false;
        log.info("日志编号:{},手机号:{},【我来贷】数据推送到【e时贷】流程开始", logNumber, customer.getPhone());
        try {
            JSONObject param = getParam(customer);
 
            isSucc = push(customer, param, logNumber);
            Integer esd = 0;
            if (!isSucc) {
                log.error("日志编号:{},手机号:{},【我来贷】数据推送到【e时贷】失败", logNumber, customer.getPhone());
            } else {
                esd = 1;
            }
            saveStatus(customer, esd);
            if (isSucc) {
                isSucc = wldIncomeToEsd(customer, param, logNumber);
            }
        } catch (Exception ex) {
            log.error("日志编号:{},手机号:{},【我来贷】数据推送到【e时贷】失败: {}", logNumber, customer.getPhone(), ex.getMessage());
            isSucc = false;
        }
        return isSucc;
    }
 
    /**
     * 推送操作
     */
    public LvdiPushResultVo esdPush(CustomerUser customerUser, String channelCode) {
        String logNumber = IdUtil.randomUUID();
        log.info("日志编号:" + logNumber + "【e时贷】channelCode:" + channelCode + " 推送流程开始");
 
        Customer customer = customerMapper.getLatestCustomerRecord(customerUser.getPhone());
        CustomerCapitalResult capitalResult = capitalResultMapper.selectOne(new LambdaQueryWrapper<CustomerCapitalResult>()
                .eq(CustomerCapitalResult::getCustomerUserId, customerUser.getId())
                .eq(CustomerCapitalResult::getCustomerRecordId, customer.getId())
                .eq(CustomerCapitalResult::getCapitalInfoCode, CapitalInfoTypeCodeEnum.ESD.getCode()));
        if (capitalResult == null) {
            log.info("日志编号:" + logNumber + " 手机号:" + customerUser.getPhone() + "【e时贷】数据库结果不存在, customerUser id:" +
                    customerUser.getId() + " customer id:" + customer.getId());
            throw new CommonException("资方对接结果不存在");
        }
 
        JSONObject param = getParam(customer);
 
        boolean isSucc = push(customer, param, logNumber);
        if (!isSucc) {
            return null;
        }
 
        // 开始进件操作
        // 转成 LvdiPushResultVo
        LvdiPushResultVo result = new LvdiPushResultVo();
        result.setCheckResult(true);
        result.setUrlType("1");// APP下载链接
        return result;
    }
 
    private final IPlatformCapitalService platformCapitalService;
 
    /**
     * 中诚易进件数据给e时贷操作
     */
    public void zcyIncomeToEsd(Customer customer, String logNumber) {
        log.info("日志编号:" + logNumber + ",手机号:{},中诚易数据进件到【e时贷】流程开始", customer.getPhone());
        try {
            Integer esd = 3;
            ResultJson<LvdiPushResultVo> rs = getPushResult(logNumber, customer);
            if (rs == null) {
                log.error("日志编号:" + logNumber + ",手机号:{},中诚易数据进件到【e时贷】失败", customer.getPhone());
            } else {
                esd = 4;
                log.info("日志编号:" + logNumber + ",手机号:{},中诚易数据进件到【e时贷】成功", customer.getPhone());
            }
            saveStatus(customer, esd);
        } catch (Exception ex) {
            log.error("日志编号:" + logNumber + ",手机号:{},中诚易数据进件到【e时贷】失败", customer.getPhone());
        }
    }
 
    /**
     * 我来贷进件数据给e时贷操作
     */
    public boolean wldIncomeToEsd(Customer customer, JSONObject param, String logNumber) {
        boolean isSucc = false;
        log.info("日志编号:{},手机号:{},【我来贷】数据进件到【e时贷】流程开始", logNumber, customer.getPhone());
        try {
            Integer esd = 3;
            isSucc = getWldPushResult(logNumber, param, customer);
            if (!isSucc) {
                log.error("日志编号:{},手机号:{},【我来贷】数据进件到【e时贷】失败", logNumber, customer.getPhone());
            } else {
                esd = 4;
                log.info("日志编号:{},手机号:{},【我来贷】数据进件到【e时贷】成功", logNumber, customer.getPhone());
            }
            saveStatus(customer, esd);
        } catch (Exception ex) {
            log.error("日志编号:{},手机号:{},【我来贷】数据进件到【e时贷】失败: {}", logNumber, customer.getPhone(), ex.getMessage());
        }
        return isSucc;
    }
 
    private void saveStatus(Customer customer, Integer esd) {
        // 录入或更新到customer_scy_income表
        LambdaQueryWrapper<CustomerScyIncome> wr = new LambdaQueryWrapper<>();
        wr.eq(CustomerScyIncome::getCustomerZcyId, customer.getId());
        wr.last(" limit 1 ");
        CustomerScyIncome csi = customerZcyIncomeService.getOne(wr);
        if (Objects.isNull(csi)) {
            csi = new CustomerScyIncome();
        }
        csi.setCustomerZcyId(customer.getId());
        csi.setEsd(esd);
        customerZcyIncomeService.saveOrUpdate(csi);
    }
 
    private boolean push(Customer customer, JSONObject body, String logNumber) {
        /* 手机号md5(32位小写)*/
        body.put("phoneMd5",  DigestUtils.md5DigestAsHex(customer.getPhone().getBytes()));
 
        String sendData = getDataJson(body);
        String jsonData = encryptData(secretKey30, sendData);
        log.info("日志编号:" + logNumber + " 手机号为:{},【e时贷】参数:: {}, data加密 {}", customer.getPhone(), body, jsonData);
 
        log.info("日志编号:" + logNumber + " 开始推送手机号:" + customer.getPhone() + "的资料给资方【e时贷】");
        String result = null;
        try {
            result = HttpClientUtil.getInstance().postJsonData(basicUrl, jsonData, getHeader(sendData, clientId30, "A0001"));
            log.info("日志编号:" + logNumber + " 手机号为:" + customer.getPhone() + ",【e时贷】推送原始返回参数:{}", result);
        } catch (Exception ex) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】推送失败,传参:{} ex:{}", customer.getPhone(), jsonData , ex);
        }
        if (StringUtils.isBlank(result)) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】推送原始返回数据为空,传参:{} ", customer.getPhone(), jsonData);
        }
        try {
            EsdResponse res = JSON.parseObject(result, EsdResponse.class);
            if (res.getCode().intValue() == 0) {
                log.info("日志编号:" + logNumber + " 手机号为:" + customer.getPhone() + ",【e时贷】推送成功");
 
                String signsResult = JSON.toJSONString(res.getData());
 
                PlatformCapital platformCapital = JSON.parseObject(signsResult, PlatformCapital.class);
                // 删除同一资方的同一用户数据
                LambdaQueryWrapper<PlatformCapital> wrapper = new LambdaQueryWrapper<>();
                wrapper.eq(PlatformCapital::getCustomerId, customer.getId());
                wrapper.eq(PlatformCapital::getCapitalId, capitalId);
                platformCapitalService.remove(wrapper);
                // 录入到数据库
                platformCapital.setCustomerId(customer.getId());
                platformCapital.setCapitalId(capitalId);
                platformCapital.setLogoUrl(res.getData().getCompanyLogo());
                platformCapital.setCompanyName(res.getData().getCompanyName());
                platformCapital.setProductName(res.getData().getProductName());
                platformCapital.setProtocolList(res.getData().getProtocolList().toString());
                platformCapitalService.save(platformCapital);
 
                return true;
            } else {
                log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】推送失败:{},jsonData:{}", customer.getPhone(), res.getMsg(),jsonData);
            }
        } catch (Exception ex) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】推送原始返回参数转换失败,jsonData:{} ex:{}", customer.getPhone(), jsonData , ex);
        }
        return false;
    }
 
    /**
     * 进件操作
     */
    public ResultJson<?> income(HttpServletRequest request) {
        String logNumber = IdUtil.randomUUID();
        log.info("日志编号:" + logNumber + "【e时贷】进件流程开始");
        String token = request.getHeader("Authorization");
        UserDetail user = UserUtil.getUser(token);
        if (user == null) {
            log.info("日志编号:" + logNumber + "【e时贷】进件失败,原因:用户Token无效");
            throw new CommonException("用户Token无效");
        }
 
        Customer customer = customerMapper.getLatestCustomerRecord(user.getPhone());
        LambdaQueryWrapper<CustomerUser> wr = new LambdaQueryWrapper<>();
        wr.eq(CustomerUser::getPhone, user.getPhone());
        wr.eq(CustomerUser::getDeleteFlag, 0);
        wr.last(" limit 1 ");
        CustomerUser customerUser = customerUserService.getOne(wr);
        if (customerUser == null) {
            log.info("日志编号:" + logNumber + " 手机号:" + user.getPhone() + "【e时贷】进件失败,原因:用户不存在");
            throw new CommonException("用户不存在");
        }
        CustomerCapitalResult capitalResult = capitalResultMapper.selectOne(new LambdaQueryWrapper<CustomerCapitalResult>()
                .eq(CustomerCapitalResult::getCustomerUserId, customerUser.getId())
                .eq(CustomerCapitalResult::getCustomerRecordId, customer.getId())
                .eq(CustomerCapitalResult::getCapitalInfoCode, CapitalInfoTypeCodeEnum.ESD.getCode()));
        if (capitalResult == null) {
            log.info("日志编号:" + logNumber + " 手机号:" + customerUser.getPhone() + "进件失败,原因:【e时贷】数据库结果不存在, customerUser id:" +
                    customerUser.getId() + " customer id:" + customer.getId());
            throw new CommonException("资方对接结果不存在");
        }
 
        return getPushResult(logNumber, customer);
    }
 
    @Nullable
    private ResultJson<LvdiPushResultVo> getPushResult(String logNumber, Customer customer) {
        // 判断是否数据库中是否有数据,有过数据就不推送了
        LambdaQueryWrapper<PlatformCapital> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PlatformCapital::getCustomerId, customer.getId());
        wrapper.eq(PlatformCapital::getCapitalId, capitalId);
        wrapper.last(" limit 1 ");
        PlatformCapital platformCapital = platformCapitalService.getOne(wrapper);
        if (Objects.isNull(platformCapital)) {// 若没有数据
            log.info("日志编号:" + logNumber + " 手机号:" + customer.getPhone() + "进件失败,原因:【e时贷】推送结果不存在, customer id:" + customer.getId());
            throw new CommonException("资方推送结果不存在");
        }
        if (platformCapital.getIncomeStatus() == 1) {// 已进件成功
            log.info("日志编号:" + logNumber + " 手机号:" + customer.getPhone() + "进件失败,原因:【e时贷】已经进件成功过,不再进件, customer id:" + customer.getId());
            return null;
        }
 
        JSONObject param = getParam(customer);
        // 基本参数
        param.put("phone", customer.getPhone());
        param.put("name", customer.getName());
        param.put("ip", customer.getIpAddres());
        param.put("bankCard", customer.getCardNo());
        param.put("idcard", customer.getIdCard());
 
        String sendData = getDataJson(param);
        String jsonData = encryptData(secretKey30, sendData);
        log.info("日志编号:" + logNumber + " 手机号:" + customer.getPhone() + "开始进件给资方【e时贷】,参数:{}, 加密:{}", sendData, jsonData);
        String result = null;
        try {
            result = HttpClientUtil.getInstance().postJsonData(basicUrl, jsonData, getHeader(sendData, clientId30, "A0002"));
            log.info("日志编号:" + logNumber + " 手机号为:" + customer.getPhone() + ",【【e时贷】进件原始返回参数:{}", result);
        } catch (Exception ex) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】进件失败,传参:{} ex:{}", customer.getPhone(), jsonData , ex.getMessage());
        }
        if (StringUtils.isBlank(result)) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】进件返回数据为空,传参:{} ", customer.getPhone(), jsonData);
        }
        try {
            EsdResponse res = JSON.parseObject(result, EsdResponse.class);
            if (res.getCode().intValue() == 0) {
                log.info("日志编号:" + logNumber + " 手机号为:" + customer.getPhone() + ",【e时贷】进件成功");
                // 更新数据库
                platformCapital.setIncomeStatus(1);
                platformCapitalService.updateById(platformCapital);
                LvdiPushResultVo rs = new LvdiPushResultVo();
                rs.setCheckResult(true);
                rs.setUrlType("1");// APP下载链接
                return ResultJson.ok(rs);
            } else {
                log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】进件失败:{},jsonData:{}", customer.getPhone(), res.getMsg(), jsonData);
            }
        } catch (Exception ex) {
            log.error("日志编号:{} 手机号为:{},【e时贷】进件原始返回参数转换失败,jsonData:{} ex:{}", logNumber, customer.getPhone(), jsonData, ex.getMessage());
        }
        return null;
    }
 
    private boolean getWldPushResult(String logNumber, JSONObject param, Customer customer) {
        // 判断是否数据库中是否有数据,有过数据就不推送了
        LambdaQueryWrapper<PlatformCapital> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(PlatformCapital::getCustomerId, customer.getId());
        wrapper.eq(PlatformCapital::getCapitalId, capitalId);
        wrapper.last(" limit 1 ");
        PlatformCapital platformCapital = platformCapitalService.getOne(wrapper);
        if (Objects.isNull(platformCapital)) {// 若没有数据
            log.info("日志编号:" + logNumber + " 手机号:" + customer.getPhone() + "进件失败,原因:【e时贷】推送结果不存在, customer id:" + customer.getId());
            return false;
        }
        if (platformCapital.getIncomeStatus() == 1) {// 已进件成功
            log.info("日志编号:" + logNumber + " 手机号:" + customer.getPhone() + "进件失败,原因:【e时贷】已经进件成功过,不再进件, customer id:" + customer.getId());
            return false;
        }
 
        // 基本参数
        param.put("phone", customer.getPhone());
        param.put("name", customer.getName());
        param.put("ip", customer.getIpAddres());
        param.put("bankCard", customer.getCardNo());
        param.put("idcard", customer.getIdCard());
 
        String sendData = getDataJson(param);
        String jsonData = encryptData(secretKey30, sendData);
        log.info("日志编号:" + logNumber + " 手机号:" + customer.getPhone() + "开始进件给资方【e时贷】,参数:{}, 加密:{}", sendData, jsonData);
        String result = null;
        try {
            result = HttpClientUtil.getInstance().postJsonData(basicUrl, jsonData, getHeader(sendData, clientId30, "A0002"));
            log.info("日志编号:" + logNumber + " 手机号为:" + customer.getPhone() + ",【【e时贷】进件原始返回参数:{}", result);
        } catch (Exception ex) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】进件失败,传参:{} ex:{}", customer.getPhone(), jsonData , ex.getMessage());
        }
        if (StringUtils.isBlank(result)) {
            log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】进件返回数据为空,传参:{} ", customer.getPhone(), jsonData);
        }
        try {
            EsdResponse res = JSON.parseObject(result, EsdResponse.class);
            if (res.getCode().intValue() == 0) {
                log.info("日志编号:" + logNumber + " 手机号为:" + customer.getPhone() + ",【e时贷】进件成功");
                // 更新数据库
                platformCapital.setIncomeStatus(1);
                platformCapitalService.updateById(platformCapital);
                LvdiPushResultVo rs = new LvdiPushResultVo();
                rs.setCheckResult(true);
                rs.setUrlType("1");// APP下载链接
                return true;
            } else {
                log.error("日志编号:" + logNumber + " 手机号为:{},【e时贷】进件失败:{},jsonData:{}", customer.getPhone(), res.getMsg(), jsonData);
            }
        } catch (Exception ex) {
            log.error("日志编号:{} 手机号为:{},【e时贷】进件原始返回参数转换失败,jsonData:{} ex:{}", logNumber, customer.getPhone(), jsonData, ex.getMessage());
        }
        return false;
    }
 
    /**
     * 请求体数据进⾏排序
     * @param data 对象
     */
    @SuppressWarnings("unchecked")
    private static <T> String getDataJson(T data) {
        // 字段排序
        JSONObject jsonObject = (JSONObject)data;
        TreeMap<String, Object> treeMap = new TreeMap<>(jsonObject);
        // 业务数据
        return JSONObject.toJSONString(treeMap);
    }
 
    /**
     * 数据加密⽅法
     * @param privateKey 客⼾端id
     * @param dataJson 请求数据
     */
    private static <T> String encryptData(String privateKey, String dataJson) {
        Map<String, String> dataMap = MapUtil.newHashMap(16);
        AES aes = new AES(HexUtil.decodeHex(privateKey));
        // 业务数据
        dataMap.put("data", aes.encryptHex(dataJson));
        return JSONObject.toJSONString(dataMap);
    }
 
    /**
     * 交互请求头
     * @param body            请求体
     * @param clientId        客⼾端id
     * @param serviceCode     业务编码
     * @return
     */
    public static Map<String ,Object> getHeader(String body, String clientId, String serviceCode) {
        String timeStr = Long.toString(System.currentTimeMillis());
        return new MapBuilder<String, Object>(MapUtil.newHashMap(16))
                .put("client-id", clientId)
                .put("timestamp", timeStr)
                .put("sign", MD5.create().digestHex(body + clientId + String.valueOf(timeStr)))
                .put("service-code", serviceCode)
                .build();
 
 
    }
 
}