Sunshine
2024-11-05 8f7985d7764a0aad24bd593ac5ea47b7fc290961
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
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
package com.nova.sankuai.infra.utils.wolaidai;
 
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.map.MapUtil; // 工具类:Map工具
import cn.hutool.core.util.IdUtil; // 工具类:Id工具
import cn.hutool.crypto.symmetric.AES; // 工具类:AES
import cn.hutool.json.JSONObject; // JSON处理类
import cn.hutool.json.JSONUtil; // JSON工具类
import com.alibaba.fastjson.JSON; // FastJson库
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; // MyBatis条件查询
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.nova.sankuai.domain.api.rongbei.ApplyData; // 申请数据类
import com.nova.sankuai.domain.api.rongbei.RbResponse; // 响应结果类
import com.nova.sankuai.domain.api.yinsheng.SerialGenerator;
import com.nova.sankuai.domain.dto.rongbei.ApplyDto; // 申请DTO
import com.nova.sankuai.domain.dto.rongbei.ContactListDto; // 联系人列表DTO
import com.nova.sankuai.domain.dto.rongbei.ProfileDictDto;
import com.nova.sankuai.domain.dto.rongbei.RongBeBasicDto; // 融贝基础DTO
import com.nova.sankuai.domain.entity.*;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.utils.ConstantsUtil;
import com.nova.sankuai.infra.utils.eshidai.EsdUtil;
import com.nova.sankuai.infra.utils.hht.HhtUtil;
import com.nova.sankuai.infra.utils.hjqb.HjqbUtil;
import com.nova.sankuai.infra.utils.qinghuayoupin.QingHuaYouPinUtil;
import com.nova.sankuai.infra.utils.rongbei.RsaSupport; // RSA支持类
import com.nova.sankuai.infra.utils.sms.FirstMessage;
import com.nova.sankuai.infra.utils.sms.shandongMessage.ShanDongMessageSendUtil;
import com.nova.sankuai.infra.utils.syh.SyhUtil;
import com.nova.sankuai.security.HttpClientUtil; // HTTP客户端工具类
import com.nova.sankuai.service.*;
import lombok.Getter;
import lombok.RequiredArgsConstructor; // Lombok的构造函数生成器
import org.apache.commons.lang3.StringUtils; // 字符串工具类
import org.jetbrains.annotations.NotNull; // NotNull注解
import org.slf4j.Logger; // 日志类
import org.slf4j.LoggerFactory; // 日志工厂类
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value; // Spring属性注入
import org.springframework.stereotype.Component; // 组件标识
 
import java.util.*;
 
@Component
@RequiredArgsConstructor // 构造器注入
public class WolaidaiUtil {
    private static final Logger log = LoggerFactory.getLogger("capitalLogger"); // 定义日志对象
 
    // 定义请求常量
    private static final String HUI_QIAN = "慧钱"; // 定义常量:慧钱
    private static final String HUI_JIE = "慧借钱包"; // 定义常量:慧借钱包
    private static final String SUI_BEI = "随呗"; // 定义常量:随呗
    private static final String SHANG_CHENG = "商城"; // 定义常量:商城
    private static final String MANG_XIAO_CHENG = "芒小橙-WLD"; // 定义常量:芒小橙品牌名,后缀为-WLD
    private static final String YI_CHENG_YOU_PIN = "易橙优品-WLD"; // 定义常量:易橙优品品牌名,后缀为-WLD
    private static final String HUI_GOU = "汇购-WLD"; // 定义常量:易橙优品品牌名,后缀为-WLD
    private static final String YING_XIANG_HUA = "盈享花-WLD"; // 定义常量:易橙优品品牌名,后缀为-WLD
    private static final int FUND_TYPE_BANK_LOAN = 1; // 资金类型:银行直贷
    private static final int ENABLE_FLAG = 1; // 启用标志
    private static final int DISABLE_FLAG = 0; // 禁用标志
    private static final String SUCCESS_CODE = "0"; // 成功返回码
 
    // 各种密钥和ID的注入
    @Value("${rongbei.publicKey}")
    private String rbPublicKey; // 融呗公钥
 
    @Value("${rongbei.wolaidai.publicKey}")
    private String wldPublicKey; // 我来贷公钥
 
    @Value("${rongbei.privateKey}")
    private String privateKey; // 私钥
 
    @Value("${rongbei.encryptKey}")
    private String encryptKey; // 加密密钥
 
    @Value("${rongbei.partner_id}")
    private String RbPartnerId; // 融呗合作伙伴ID
 
    @Value("${rongbei.h5Url}")
    private String rbH5Url; // 融呗h5Url
 
    @Value("${rongbei.h5HalfUrl}")
    private String h5HalfUrl; // 融呗非半流程h5Url
 
    @Value("${front.refreshToUrl}")
    private String refreshToUrl; // 前端跳转地址
 
    @Value("${rongbei.wolaidai.url}")
    private String wldUrl; // 我来贷URL
 
    @Value("${rongbei.shangcheng.ip}")
    private String scUrl; // 商城URL
 
    @Value("${rongbei.shangcheng.h5Url}")
    private String scH5Url; // 商城h5Url
 
    @Value("${rongbei.shangcheng.partner_id}")
    private String scParentId; // 商城合作伙伴ID
 
    @Value("${rongbei.shangcheng.publicKey}")
    private String scPublicKey; // 商城公钥
 
    @Value("${rongbei.hjqb.ip}")
    private String hjUrl; // 慧钱URL
 
    @Value("${rongbei.hjqb.h5Url}")
    private String hjH5Url; // 慧钱h5Url
 
    @Value("${rongbei.hjqb.partner_id}")
    private String hjParnterId; // 慧钱合作伙伴ID
 
    @Value("${rongbei.hjqb.publicKey}")
    private String hjPublicKey; // 慧钱公钥
 
    @Value("${rongbei.mxch.ip}")
    private String mxchUrl; // 芒小橙URL
 
    @Value("${rongbei.mxch.h5Url}")
    private String mxchH5Url; // 芒小橙h5Url
 
    @Value("${rongbei.mxch.partner_id}")
    private String mxchParnterId; // 芒小橙ID
 
    @Value("${rongbei.mxch.publicKey}")
    private String mxchPublicKey; // 芒小橙公钥
 
    @Value("${rongbei.ycyp.ip}")
    private String ycypUrl; // 易橙优品URL
 
    @Value("${rongbei.ycyp.h5Url}")
    private String ycypH5Url; // 易橙优品h5Url
 
    @Value("${rongbei.ycyp.partner_id}")
    private String ycypParnterId; // 易橙优品ID
 
    @Value("${rongbei.ycyp.publicKey}")
    private String ycypPublicKey; // 易橙优品公钥
 
    @Value("${rongbei.huigou.ip}")
    private String hgUrl; // 汇购URL
 
    @Value("${rongbei.huigou.h5Url}")
    private String hgH5Url; // 汇购h5Url
 
    @Value("${rongbei.huigou.partner_id}")
    private String hgParnterId; // 汇购ID
 
    @Value("${rongbei.huigou.publicKey}")
    private String hgPublicKey; // 汇购公钥
 
    @Value("${rongbei.yingxianghua.ip}")
    private String yxhUrl; // 盈享花URL
 
    @Value("${rongbei.yingxianghua.h5Url}")
    private String yxhH5Url; // 盈享花品h5Url
 
    @Value("${rongbei.yingxianghua.partner_id}")
    private String yxhParnterId; // 盈享花ID
 
    @Value("${rongbei.yingxianghua.publicKey}")
    private String yxhPublicKey; // 盈享花公钥
 
    @Value("${rongbei.wld.ip}")
    private String wlddUrl; // 随呗URL
 
    @Value("${rongbei.wld.h5Url}")
    private String wldH5Url; // 慧钱h5Url
 
 
    @Value("${rongbei.wld.partner_id}")
    private String wlddParnterId; // 随呗代理合作伙伴ID
 
    @Value("${rongbei.wld.publicKey}")
    private String wlddPublicKey; // 我来贷代理公钥
 
    @Value("${rongbei.wolaidai.sms_notify_url}")
    private String smsNotifyUrl; // 我来贷短信通知URL
 
    private final ICustomerZcyService customerZcyService; // 客户ZCY服务
    private final ICustomerApplyOrderService customerApplyOrderService; // 客户申请订单服务
    private final ICustomerCheckRecordService customerCheckRecordService; // 用户准入务
    private final ICustomerH5ClickService customerH5ClickService; // H5用户点击埋点服务
    private final ICapitalInfoService capitalInfoService; // 资金信息服务
    private final EsdUtil esdUtil;
    private final HjqbUtil hjqbUtil;
    private final SyhUtil syhUtil;
    private final HhtUtil hhtUtil;
    private final QingHuaYouPinUtil qingHuaYouPinUtil;
 
    public RbResponse saveH5ClickRecord(String mobile, Integer type){
        CustomerH5Click customerH5Click = new CustomerH5Click();
        customerH5Click.setMobile(mobile);
        customerH5Click.setType(type);
        customerH5ClickService.save(customerH5Click);
        RbResponse resp = new RbResponse();
        resp.setCode("0");
        resp.setMsg("保存成功");
        return resp;
    }
 
 
    /**
     * 设置公共的查询条件
     * @return LambdaQueryWrapper<CapitalInfo>
     */
    private LambdaQueryWrapper<CapitalInfo> getWrapper(){
        LambdaQueryWrapper<CapitalInfo> wrapper = new LambdaQueryWrapper<>(); // 创建查询条件
        wrapper.eq(CapitalInfo::getFundType, FUND_TYPE_BANK_LOAN); // 资金类型:银行直贷
        wrapper.eq(CapitalInfo::getEnableFlag, ENABLE_FLAG); // 是否启用:启用
        wrapper.eq(CapitalInfo::getAuditSwitch, DISABLE_FLAG); // 审核开关:不启用
        return wrapper;
    }
 
 
    /**
     * 获取要推送的半流程资方
     * @return 资金信息列表
     */
    private List<CapitalInfo> getCapitalInfoList() {
        LambdaQueryWrapper<CapitalInfo> wrapper = this.getWrapper(); // 创建查询条件
        wrapper.eq(CapitalInfo::getIsTopView, DISABLE_FLAG); // 显示主界面顶部:否
        wrapper.eq(CapitalInfo::getIsShowPage, DISABLE_FLAG); // 是否显示首页:否
        wrapper.eq(CapitalInfo::getAutoPush, ENABLE_FLAG); // 自动推送:不启用
        wrapper.eq(CapitalInfo::getCollionMode, ENABLE_FLAG); // 联登模式:半流程
        wrapper.isNull(CapitalInfo::getAlwayShow); // 是否一直显示:是
        wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列
        return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表
    }
 
    /**
     * 获取要推送的非半流程资方
     * @return 资金信息列表
     */
    private List<CapitalInfo> getNotHalfCapitalInfoList() {
        LambdaQueryWrapper<CapitalInfo> wrapper = this.getWrapper();
        wrapper.eq(CapitalInfo::getAutoPush, DISABLE_FLAG); // 自动推送:启用
        wrapper.eq(CapitalInfo::getCollionMode, DISABLE_FLAG); // 联登模式:非半流程
        wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列
        return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表
    }
 
    /**
     * 获取要推送的非半流程资金类型线上资方
     * @return 资金信息列表
     */
    private List<CapitalInfo> getNotHalfFundTypeCapitalInfoList() {
        LambdaQueryWrapper<CapitalInfo> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(CapitalInfo::getFundType, 0); // 资金类型:线上贷款
        wrapper.eq(CapitalInfo::getEnableFlag, ENABLE_FLAG); // 是否启用:启用
        wrapper.eq(CapitalInfo::getAutoPush, DISABLE_FLAG); // 自动推送:启用
        wrapper.eq(CapitalInfo::getCollionMode, DISABLE_FLAG); // 联登模式:非半流程
        wrapper.eq(CapitalInfo::getIsCollion, DISABLE_FLAG);//联登开关 不启用
        wrapper.eq(CapitalInfo::getAuditSwitch, DISABLE_FLAG); // 审核开关:不启用
        wrapper.eq(CapitalInfo::getExternalSwitch, ENABLE_FLAG);
        wrapper.isNull(CapitalInfo::getAlwayShow);//是否一直显示  是
        wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列
        return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表
    }
    /**
     * 根据资金名获取配置
     * @param capitalName 资金名
     * @return 配置映射
     */
    private Map<String, String> getConfigByCapitalName(String capitalName) {
        // 创建配置映射
        Map<String, String> config = new HashMap<>();
        switch (capitalName) {
            case HUI_QIAN: // 如果是慧钱
                config.put("partnerId", hjParnterId); // 设置合作伙伴ID
                config.put("publicKey", hjPublicKey); // 设置公钥
                config.put("basicUrl", hjUrl); // 设置基础URL
                config.put("h5Url", hjH5Url); // 设置H5Url
                break;
            case SUI_BEI: // 如果是随呗
                config.put("partnerId", wlddParnterId); // 设置合作伙伴ID
                config.put("publicKey", wlddPublicKey); // 设置公钥
                config.put("basicUrl", wlddUrl); // 设置基础URL
                config.put("h5Url", wldH5Url); // 设置H5Url
                break;
            case SHANG_CHENG: // 如果是商城
                config.put("partnerId", scParentId); // 设置合作伙伴ID
                config.put("publicKey", scPublicKey); // 设置公钥
                config.put("basicUrl", scUrl); // 设置基础URL
                config.put("h5Url", scH5Url); // 设置H5Url
                break;
            case MANG_XIAO_CHENG: // 如果是芒小橙
                config.put("partnerId", mxchParnterId); // 设置合作伙伴ID
                config.put("publicKey", mxchPublicKey); // 设置公钥
                config.put("basicUrl", mxchUrl); // 设置基础URL
                config.put("h5Url", mxchH5Url); // 设置H5Url
                break;
            case YI_CHENG_YOU_PIN: // 如果是易橙优品
                config.put("partnerId", ycypParnterId); // 设置合作伙伴ID
                config.put("publicKey", ycypPublicKey); // 设置公钥
                config.put("basicUrl", ycypUrl); // 设置基础URL
                config.put("h5Url", ycypH5Url); // 设置H5Url
                break;
            case HUI_GOU: // 如果是汇购
                config.put("partnerId", hgParnterId); // 设置合作伙伴ID
                config.put("publicKey", hgPublicKey); // 设置公钥
                config.put("basicUrl", hgUrl); // 设置基础URL
                config.put("h5Url", hgH5Url); // 设置H5Url
                break;
            case YING_XIANG_HUA: // 如果是盈享花
                config.put("partnerId", yxhParnterId); // 设置合作伙伴ID
                config.put("publicKey", yxhPublicKey); // 设置公钥
                config.put("basicUrl", yxhUrl); // 设置基础URL
                config.put("h5Url", yxhH5Url); // 设置H5Url
                break;
            default: // 其他情况,保持为空
                break;
        }
        return config; // 返回配置映射
    }
 
    @Getter
    private enum ActionEnum {
        CHECK("check", "准入接口"),
        APPLY("apply", "进件接口"),
        ORDER_STATUS("order_status", "查询订单状态接口"),
        CONCLUSION("conclusion", "查询授信结果"),
        REPAY_INFO("repay_info", "查询还款计划接口"),
        H5_URL("h5_url", "获取跳转H5页面地址接口");
 
        private final String actionName; // 动作名称
        private final String targetName; // 目标名称
 
        ActionEnum(String actionName, String targetName) {
            this.actionName = actionName;
            this.targetName = targetName;
        }
 
    }
 
    /**
     * 根据方法名返回相应的数据
     * @param action 方法名
     * @return 配置映射
     */
    private Map<String, String> getBasicInfoByAction(String action) {
        // 创建配置映射
        Map<String, String> basicInfo = new HashMap<>();
        // 根据输入的动作名称进行配置映射
        for (ActionEnum enumAction : ActionEnum.values()) {
            if (enumAction.getActionName().equals(action)) {
                basicInfo.put("targetName", enumAction.getTargetName());
                basicInfo.put("url", enumAction.getActionName());
                break;
            }
        }
        return basicInfo; // 返回配置映射
    }
 
 
    /**
     * 接收我来贷请求的数据并中转给下游资方
     * @param body 请求体
     * @param action 方法名
     * @return RbResponse
     */
    public RbResponse wld2ThirdPlatform(RongBeBasicDto body, String action) {
        RbResponse resp = new RbResponse(); // 初始化响应对象
        String logNumber = IdUtil.randomUUID(); // 生成日志编号
        JSONObject hjData = new JSONObject();// 创建返回数据的JSON对象
        Map<String, String> basicInfo = getBasicInfoByAction(action);
        boolean flag = false;
        String decryptStr = "";
        resp.setMsg("成功");
        try {
            log.info("日志编号:{} , {}方法:{}, 接收到的数据:{}", logNumber, basicInfo.get("targetName"),  action, body); // 记录接收的数据
            JSONObject getFullData = new JSONObject(); // 创建JSON对象存储数据
            getFullData.putOpt("partner_id", body.getPartner_id()); // 存储合作伙伴ID
            getFullData.putOpt("timestamp", body.getTimestamp()); // 存储时间戳
            getFullData.putOpt("biz_data", body.getBiz_data()); // 存储业务数据
            // 解密+验签
            decryptStr = decrypt(getFullData, body.getSign(), wldPublicKey);// 解密
            String chnOrderId = "";
            log.info("日志编号:{}, , {}方法:{}, 解密接收到的数据:{}", logNumber, basicInfo.get("targetName"), action, decryptStr); // 记录解密数据
            if (StringUtils.isNotEmpty(decryptStr)) { // 判断解密结果是否有效
                Customer customer = new Customer();
                if (Objects.equals(action, "apply")) {
                    // 修改借款额度,采用随机生成
                    Random random = new Random();
                    int lowerBound = 5000; // 最小值
                    int upperBound = 50000; // 最大值
 
                    // 生成随机的100倍数
                    int randomValue = lowerBound + (random.nextInt((upperBound - lowerBound) / 100 + 1) * 100);
 
                    // 数据保存到数据库中
                    ApplyDto applyDto = JSON.parseObject(decryptStr, ApplyDto.class);
                    ProfileDictDto profileDictDto =  applyDto.getProfile_dict();
                    profileDictDto.setRequest_amount(String.valueOf(randomValue));
                    applyDto.setProfile_dict(profileDictDto);
                    chnOrderId = applyDto.getChn_order_id();
                    log.info("日志编号:{},{}方法:{}, 保存进件数据:{}", logNumber, basicInfo.get("targetName"), action, applyDto);
                    customer = saveData(applyDto);
                    JSON.toJSONString(applyDto);
                    decryptStr = JSON.toJSONString(applyDto);
                    //发送短信通知(等待供应商审批短信模板 申请完后在恢复注释)
                    smsNotify(profileDictDto.getPhone());
                }
                String bizDataStr = "";
                String fBizDataStr = "";
                String capitalName = "";
                String fCapitalName = "";
                if (Objects.equals(action, "h5_url")) {
                    JSONObject h5 = JSON.parseObject(decryptStr, JSONObject.class);
                    LambdaQueryWrapper<CustomerApplyOrder> wr = new LambdaQueryWrapper<>();
                    wr.eq(CustomerApplyOrder::getChnOrderId, h5.getStr("chn_order_id"));
                    wr.eq(CustomerApplyOrder::getPartnerFlowId, h5.getStr("partner_flow_id"));
                    wr.last(" limit 1 ");
                    CustomerApplyOrder customerApplyOrder = customerApplyOrderService.getOne(wr);
                    if (!Objects.isNull(customerApplyOrder)) {
                        JSONObject obj = new JSONObject();
                        Long capitalId = customerApplyOrder.getCapitalId();
                        String h5Url = "";
                        // 如果是慧钱,随易花,e时贷,好汇推,则转为乐享融的指定id:28
                        if (capitalId == 12L || capitalId == 41L || capitalId == 36L || capitalId == 25L) {
                            h5Url = h5HalfUrl + "&capitalId="+ capitalId + "&mobile=" + customerApplyOrder.getPhone();
                            //h5Url = rbH5Url + "&capitalId=28";
                        }else if(capitalId == 4L){
//                            com.nova.sankuai.domain.api.zhongzan.RbResponse rbResponse = qingHuaYouPinUtil.queryApprovalToWolaidai(customerApplyOrder.getChnOrderId());
//                            if (rbResponse != null) {
//                                if (Objects.equals("200",resp.getCode())){
//                                    if (rbResponse.getData() != null){
//                                        JSONObject smsObject = rbResponse.getData();
//                                        String amount = smsObject.get("amount") == null ? "" : String.valueOf(smsObject.get("amount"));
//                                        String expireTime = smsObject.get("expireTime") == null ? "" : String.valueOf(smsObject.get("expireTime"));
//                                        smsApprovalNotify(amount,expireTime,customerApplyOrder.getPhone());
//                                    }
//                                }
//                            }
                            h5Url = refreshToUrl + "/pages/ys/qh-sign?partnerOrderNo="+ customerApplyOrder.getChnOrderId() + "&capitalId = 28" ;
                        }else{
                            //h5Url = rbH5Url + "&capitalId="+ capitalId + "&mobile=" + customerApplyOrder.getPhone();
                            h5Url = rbH5Url + "&capitalId="+ capitalId;
                        }
                        obj.putOpt("url", h5Url);
                        obj.putOpt("remind", "");
                        bizDataStr = String.valueOf(obj);
                        capitalName = customerApplyOrder.getCapitalName();
                        flag = true;
                    }
                }else {
                    // 遍历半流程资金信息列表
                    List<CapitalInfo> capitalInfoList = getCapitalInfoList();
                    for (CapitalInfo capitalInfo : capitalInfoList) {
                        Map<String, String> config = getConfigByCapitalName(capitalInfo.getName());// 获取对应的配置
                        log.info("日志编号:{},{}方法:{}, 资方名:【{}】,config配置信息: {}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), config); // 记录资金信息
                        JSONObject fullData = new JSONObject();// 创建完整数据的JSON对象
                        fullData.putOpt("partner_id", config.get("partnerId")); // 设置合作伙伴ID
                        fullData.putOpt("timestamp", System.currentTimeMillis());// 设置当前时间戳
                        fullData.putOpt("biz_data", encrypt(decryptStr)); // 设置业务数据
                        //生成新的签名
                        fullData.putOpt("sign", getSign(fullData, config.get("publicKey")));// 计算签名
                        String result = null;// 初始化结果
                        if (StringUtils.isNotEmpty(config.get("basicUrl"))) {// 如果基础URL有效
                            try {
                                result = HttpClientUtil.getInstance().postJsonData(config.get("basicUrl") + basicInfo.get("url"), String.valueOf(fullData)); // 调用接口
                                log.info("日志编号:{},{}方法:{},资方名:【{}】,参数:{},result: {}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), fullData, result);// 记录接口结果
                            } catch (Exception ex) {
                                // 处理请求异常
                                resp.setMsg(ex.getMessage());// 设置响应消息
                                log.error("日志编号:{},{}方法:{}, 资方名:【{}】,传参:{} ex:{}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), fullData, ex.getMessage());//记录异常堆栈
                            }
                            // 将result解析为响应对象
                            try {
                                if (result != null) { // 确保result不为空
                                    resp = JSON.parseObject(result, RbResponse.class);// 解析响应
                                    String data = resp.getData();// 获取数据部分
                                    RongBeBasicDto rb = JSON.parseObject(data, RongBeBasicDto.class); // 解析业务DTO
                                    hjData.putOpt("biz_data", rb.getBiz_data());// 获取业务数据
                                    if (Objects.equals(resp.getCode(), SUCCESS_CODE)) { // // 判断是否成功
                                        // 解密biz_data
                                        hjData.putOpt("partner_id", rb.getPartner_id()); // 设置合作伙伴ID为融呗,我来贷只认融呗的信息
                                        hjData.putOpt("timestamp", rb.getTimestamp()); // 设置时间戳
                                        String decryptHjStr = decrypt(hjData, rb.getSign(), config.get("publicKey"));// 解密hjData
                                        if (StringUtils.isNotEmpty(decryptHjStr)) {// 判断解密结果
                                            if (Objects.equals(action, "check")) {
                                                JSONObject de = JSON.parseObject(decryptHjStr, JSONObject.class);
                                                /*if (de.getInt("status") == 1) {
                                                    if (StringUtils.isEmpty(bizDataStr)) {
                                                        bizDataStr = decryptHjStr;
                                                        capitalName = capitalInfo.getName();
                                                    }
                                                }else {
                                                    if (StringUtils.isEmpty(fBizDataStr)) {
                                                        fBizDataStr = decryptHjStr;
                                                        fCapitalName = capitalInfo.getName();
                                                    }
                                                }*/
                                                // ab修改于2024-10-20号,应张小明的提的需求,准入默认全部为通过状态
                                                if (StringUtils.isEmpty(bizDataStr)) {
                                                    JSONObject obj = new JSONObject();
                                                    obj.putOpt("status", 1);
                                                    obj.putOpt("retry_ts", (System.currentTimeMillis() + (1000 * 60 * 60 * 24)) / 1000);
                                                    bizDataStr = String.valueOf(obj);
                                                    capitalName = capitalInfo.getName();
                                                }
                                                // 保存准入记录
                                                CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(capitalInfo.getId(), capitalInfo.getName(), decryptStr, de.getInt("status"));
                                                customerCheckRecordService.save(customerCheckRecord);
 
                                            } else if (Objects.equals(action, "apply")) {
                                                ApplyData applyData = JSON.parseObject(decryptHjStr, ApplyData.class);
                                                if (applyData.getStatus() == 0) { // 进件成功后才保存
                                                    if (StringUtils.isEmpty(bizDataStr)) {
                                                        bizDataStr = decryptHjStr;
                                                        capitalName = capitalInfo.getName();
                                                    }
 
                                                    // 进件成功后,调用接受订单状态接口推送数据给我来贷
                                                    OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id());
 
                                                    // 调用接受授信结果接口推送授信结果给我来贷
                                                    autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id());
                                                }else {
                                                    if (StringUtils.isEmpty(fBizDataStr)) {
                                                        fBizDataStr = decryptHjStr;
                                                        fCapitalName = capitalInfo.getName();
                                                    }
                                                }
                                                // 保存进件记录
                                                CustomerApplyOrder customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, config.get("partnerId"), decryptStr);
                                                customerApplyOrderService.save(customerApplyOrder);
 
                                            } else if (Objects.equals(action, "h5_url")) { // 如果是获取h5跳转链接地址,则重置链接为融呗
                                                JSONObject h5UrlData = JSON.parseObject(decryptHjStr, JSONObject.class);
                                                h5UrlData.putOpt("url", config.get("h5Url"));
                                                bizDataStr = String.valueOf(h5UrlData);
                                                if (StringUtils.isEmpty(bizDataStr)) {
                                                    bizDataStr = decryptHjStr;
                                                    capitalName = capitalInfo.getName();
                                                }
                                            } else {
                                                if (StringUtils.isEmpty(bizDataStr)) {
                                                    bizDataStr = decryptHjStr;
                                                    capitalName = capitalInfo.getName();
                                                }
                                            }
                                            flag = true;
                                            resp.setMsg("成功");
                                            log.info("日志编号:{},【{}】,{}解密结果:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), decryptHjStr);
                                        } else {
                                            log.error("日志编号:{}, 【{}】,{}解密结果失败:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), decryptHjStr);
                                        }
                                    } else {
                                        log.error("日志编号:{},【{}】{}检测失败:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), result);
                                    }
                                }
                            } catch (Exception ex) {
                                log.error("日志编号:{}, 【{}】{}推送原始返回参数转换失败,jsonData:{} ex:{}", logNumber, capitalInfo.getName(), basicInfo.get("targetName"), fullData, ex.getMessage());// 记录解析异常
                            }
                        }
                    }
                    // 遍历非半流程资金信息列表
                    boolean halfFlag = false;
                    List<CapitalInfo> lst = getNotHalfCapitalInfoList();
                    log.info("日志编号:{},{}方法:{}, 非半流程的资方列表:【{}】", logNumber, basicInfo.get("targetName"), action, lst); // 非半流程的资方列表
                    if (!flag) {
                        if (Objects.equals(action, "check")) {
                            if (!lst.isEmpty()) {
                                if (StringUtils.isEmpty(bizDataStr)) {
                                    JSONObject obj = new JSONObject();
                                    obj.putOpt("status", 1);
                                    obj.putOpt("retry_ts", (System.currentTimeMillis() + (1000 * 60 * 60 * 24)) / 1000);
                                    bizDataStr = String.valueOf(obj);
                                    capitalName = lst.get(0).getName();
                                    flag = true;
                                }
                            }
                        }
                    }
 
                    for (CapitalInfo capitalInfo : lst) {
                        log.info("日志编号:{},{}方法:{}, 非半流程资方名:【{}】", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName()); // 记录资金信息
                        if (Objects.equals(action, "check")) {
                            // 保存准入记录
                            CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(capitalInfo.getId(), capitalInfo.getName(), decryptStr, 1);
                            customerCheckRecordService.save(customerCheckRecord);
                        }else if (Objects.equals(action, "apply")) {
                            ApplyData applyData = new ApplyData();
                            applyData.setStatus(1);
                            applyData.setPartner_flow_id("");
                            //调用对应资方的推送机制
                            if (capitalInfo.getId() == 25L) { //e时贷
                                halfFlag = esdUtil.wldPushToEsd(customer, logNumber);
                                if (halfFlag) {
                                    applyData.setStatus(0);
                                    applyData.setPartner_flow_id(SerialGenerator.getOrder());
                                    flag = true;
                                }
 
                            } else if (capitalInfo.getId() == 12L) { //慧借钱包
                                halfFlag = hjqbUtil.wldPushToHjqb(customer, logNumber);
                                if (halfFlag) {
                                    applyData.setStatus(0);
                                    applyData.setPartner_flow_id(SerialGenerator.getOrder());
                                    flag = true;
                                }
                            } else if (capitalInfo.getId() == 41L) { //好汇推
                                halfFlag = hhtUtil.wldPushToHht(customer, logNumber);
                                if (halfFlag) {
                                    applyData.setStatus(0);
                                    applyData.setPartner_flow_id(SerialGenerator.getOrder());
                                    flag = true;
                                }
 
                            } else if (capitalInfo.getId() == 36L) { //随易花
                                halfFlag = syhUtil.wldPushToSyh(customer, logNumber);
                                if (halfFlag) {
                                    applyData.setStatus(0);
                                    applyData.setPartner_flow_id(SerialGenerator.getOrder());
                                    flag = true;
                                }
                            }
                            if (StringUtils.isEmpty(bizDataStr) && StringUtils.isEmpty(fBizDataStr)) {
                                bizDataStr = JSONUtil.toJsonStr(applyData);
                                capitalName = capitalInfo.getName();
                            }
 
                            if (halfFlag) {
 
                                // 进件成功后,调用接受订单状态接口推送数据给我来贷
                                OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id());
 
                                // 调用接受授信结果接口推送授信结果给我来贷
                                autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id());
                            }
 
                            // 保存进件记录
                            CustomerApplyOrder customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, "28", decryptStr);
                            customerApplyOrderService.save(customerApplyOrder);
 
                        }
                    }
 
                    // 遍历非半流程资金方式线上贷款信息列表
                    List<CapitalInfo> notHalfFundTypeCapitalInfoList = getNotHalfFundTypeCapitalInfoList();
                    boolean halfFundTypeFlag = false;
                    for (CapitalInfo capitalInfo : notHalfFundTypeCapitalInfoList) {
                        log.info("日志编号:{},{}方法:{}, 资方名:【{}】", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName()); // 记录资金信息
                        if (Objects.equals(action, "check")) {
                            // 保存准入记录
                            CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(capitalInfo.getId(), capitalInfo.getName(), decryptStr, 1);
                            customerCheckRecordService.save(customerCheckRecord);
                        } else if (Objects.equals(action, "apply")) {
                            ApplyData applyData = new ApplyData();
                            applyData.setStatus(1);
                            applyData.setPartner_flow_id("");
                            //调用对应资方的推送机制
                            if (capitalInfo.getId() == 4L) { //青花优品
                                ApplyDto applyDto = JSON.parseObject(decryptStr, ApplyDto.class);
                                customer.setCreditNo(ConstantsUtil.getCreditNo());
                                halfFundTypeFlag = qingHuaYouPinUtil.wldPushToQHYP(capitalInfo, applyDto, customer, logNumber);
                                if (halfFundTypeFlag) {
                                    applyData.setStatus(0);
                                    applyData.setPartner_flow_id(customer.getCreditNo());
                                    flag = true;
                                }
                            }
                            if (StringUtils.isEmpty(bizDataStr) && StringUtils.isEmpty(fBizDataStr)) {
                                bizDataStr = JSONUtil.toJsonStr(applyData);
                                capitalName = capitalInfo.getName();
                            }
 
                            if (halfFundTypeFlag) {
 
                                // 进件成功后,调用接受订单状态接口推送数据给我来贷
                                OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id());
 
                                // 调用接受授信结果接口推送授信结果给我来贷
                                autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id());
                            }
 
                            // 保存进件记录
                            CustomerApplyOrder customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, "28", decryptStr);
                            customerApplyOrderService.save(customerApplyOrder);
 
                        }
                    }
                }
 
 
                if (flag) {
                    if (StringUtils.isEmpty(bizDataStr)) {
                        bizDataStr = fBizDataStr;
                        capitalName = fCapitalName;
                    }
 
                    // 返回最小序号的数据给我来贷
                    log.info("日志编号:{},{}方法返回最小资方【{}】的数据:{}", logNumber, action, capitalName, bizDataStr);
                    hjData.putOpt("partner_id", RbPartnerId);
                    hjData.putOpt("timestamp", System.currentTimeMillis());
                    hjData.putOpt("biz_data", encrypt(bizDataStr));
                    // 重新签名
                    hjData.putOpt("sign", getSign(hjData, wldPublicKey));
                }
            } else {
                resp.setMsg("验签失败");
                log.error("日志编号:{},【我来贷】{}参数验签失败,jsonData:{} ex:{}", logNumber, basicInfo.get("targetName"), body, "验签失败");
            }
        } catch (Exception e) {
            resp.setMsg(e.getMessage());
            log.error("日志编号:{},【我来贷】{},请求失败:{} 错误原因:{}", logNumber, basicInfo.get("targetName"), body, e.getMessage());
        }
        if (!flag) { // 数据检测不过,则返回对应的数据格式
            hjData.putOpt("partner_id", RbPartnerId);
            hjData.putOpt("timestamp", System.currentTimeMillis());
            JSONObject bizData = new JSONObject();
            if (Objects.equals(action, "check")) {
                bizData.putOpt("status", 2);
                //最好是1天以上
                bizData.putOpt("retry_ts", (System.currentTimeMillis() + (1000 * 60 * 60 * 24)) / 1000);
                // 保存准入记录
                CustomerCheckRecord customerCheckRecord = getCustomerCheckRecord(0L, "", decryptStr, 0);
                customerCheckRecordService.save(customerCheckRecord);
            }else if (Objects.equals(action, "apply")) {
                bizData.putOpt("status", 1);
                bizData.putOpt("partner_flow_id", "");
                bizData.putOpt("msg", "请求失败");
            }else if (Objects.equals(action, "order_status")) {
                bizData.putOpt("status", 100);
                bizData.putOpt("chn_order_id", "");
                bizData.putOpt("update_time", System.currentTimeMillis() / 1000);
            }else if (Objects.equals(action, "h5_url")) {
                bizData.putOpt("url", "");
                bizData.putOpt("remind", "");
            }else{
                bizData.putOpt("status", 1);
                bizData.putOpt("msg", "请求失败");
            }
            hjData.putOpt("biz_data", encrypt(String.valueOf(bizData)));
            hjData.putOpt("sign", getSign(hjData, wldPublicKey));
        }
        resp.setCode("0");
        resp.setData(String.valueOf(hjData));
 
        return resp;
    }
 
    private static @NotNull CustomerApplyOrder getCustomerApplyOrder(String chnOrderId, ApplyData applyData, CapitalInfo capitalInfo, String partnerId, String decryptStr) {
        CustomerApplyOrder customerApplyOrder = new CustomerApplyOrder();
        customerApplyOrder.setCapitalId(capitalInfo.getId());
        customerApplyOrder.setCapitalName(capitalInfo.getName());
        customerApplyOrder.setChnOrderId(chnOrderId);
        customerApplyOrder.setPartnerFlowId(applyData.getPartner_flow_id());
        customerApplyOrder.setStatus(applyData.getStatus() == 0 ? 0 : 1);
        customerApplyOrder.setType(1);
        customerApplyOrder.setPartnerId(partnerId);
        JSONObject de = JSON.parseObject(decryptStr, JSONObject.class);
        customerApplyOrder.setName(de.getJSONObject("profile_dict").getStr("name"));
        customerApplyOrder.setPhone(de.getJSONObject("profile_dict").getStr("phone"));
        log.error("日志编号:{},【{}】保存进件记录开始,customerApplyOrder:{}", IdUtil.randomUUID(), capitalInfo.getName(), customerApplyOrder);
        return customerApplyOrder;
    }
 
    private static @NotNull CustomerCheckRecord getCustomerCheckRecord(Long capitalId, String capitalName, String decryptStr, Integer status) {
        CustomerCheckRecord customerCheckRecord = new CustomerCheckRecord();
        JSONObject de = JSON.parseObject(decryptStr, JSONObject.class);
        customerCheckRecord.setCapitalId(capitalId);
        customerCheckRecord.setCapitalName(capitalName);
        customerCheckRecord.setMd5Phone(de.getStr("md5_phone"));
        customerCheckRecord.setMd5Idcard(de.getStr("md5_idcard"));
        customerCheckRecord.setMd5Name(de.getStr("md5_name"));
        customerCheckRecord.setPreIdNo(de.getStr("pre_id_no"));
        customerCheckRecord.setMaskPhone(de.getStr("mask_phone"));
        customerCheckRecord.setMaskIdcard(de.getStr("mask_idcard"));
        customerCheckRecord.setStatus(status == 1 ? status : 0);
        customerCheckRecord.setType(1);
        log.error("日志编号:{},【{}】保存准入记录开始,customerCheckRecord:{}", IdUtil.randomUUID(), capitalName, customerCheckRecord);
        return customerCheckRecord;
    }
 
    /**
     * 保存数据
     * @param applyDto 数据对象
     */
    private Customer saveData(ApplyDto applyDto) {
        LambdaQueryWrapper<CustomerZcy> wr = new LambdaQueryWrapper<>();
        wr.eq(CustomerZcy::getPhone, applyDto.getProfile_dict().getPhone());
        wr.last(" limit 1 ");
        CustomerZcy customerZcy = customerZcyService.getOne(wr);
        if (Objects.isNull(customerZcy)) {
            customerZcy = new CustomerZcy();
            //联系人列表(两个联系人)
            List<ContactListDto> contList = applyDto.getContact_list();
            int conSize = contList.size();
            for (int j = 0; j < conSize; j++) {
                ContactListDto dto = contList.get(j);
                String relationShip = getRelationShip(dto);
                if (j == 0) {
                    customerZcy.setRelationshipName(dto.getName());
                    customerZcy.setRelationshipPhone(dto.getPhone());
                    customerZcy.setRelationship(relationShip);
                }
                if (j == 1) {
                    customerZcy.setRelationship1Name(dto.getName());
                    customerZcy.setRelationship1Phone(dto.getPhone());
                    customerZcy.setRelationship1(relationShip);
                }
            }
 
            // 详细资料
            customerZcy.setName(applyDto.getProfile_dict().getName());
            customerZcy.setPhone(applyDto.getProfile_dict().getPhone());
            customerZcy.setLoanAmount(Double.valueOf(applyDto.getProfile_dict().getRequest_amount()));
            Random random = new Random();
            int[] values = {1, 2, 3, 4, 5}; // 指定的字符集合
 
            customerZcy.setLoanTerm(values[random.nextInt(values.length)]);
            customerZcy.setIdCard(applyDto.getProfile_dict().getId_card());
            customerZcy.setIdCardFrontPath(applyDto.getProfile_dict().getId_card_front());
            customerZcy.setIdCardBackPath(applyDto.getProfile_dict().getId_card_back());
            customerZcy.setNation(applyDto.getProfile_dict().getNation());
            customerZcy.setSignOrganization(applyDto.getProfile_dict().getIssued_by());
            String valid_date = applyDto.getProfile_dict().getValid_date();
            if (StringUtils.isNotBlank(valid_date)) {
                String[] valid_dates = valid_date.split("-");
                customerZcy.setIdValidDateBegin(valid_dates[0]);
                String endTime = valid_dates[1];
                customerZcy.setIdValidDateEnd(endTime);
                if ("⻓期".equals(endTime)) {
                    customerZcy.setIdLongTerm("1");
                }
            }
            customerZcy.setCityName(applyDto.getProfile_dict().getCity());
            customerZcy.setAddress(applyDto.getProfile_dict().getAddress());
            //sesame_point
            int sesame = applyDto.getProfile_dict().getSesame_point();
            if (sesame == 2) {
                sesame = 1;
            }else if (sesame == 3) {
                sesame = 2;
            }else if (sesame == 4) {
                sesame = 3;
            }else {
                sesame = random.nextInt(3) + 1;
            }
            customerZcy.setSesame(sesame);
 
 
            String area = applyDto.getProfile_dict().getCity();
            if (StringUtils.isNotBlank(area)) {
                String[] areas = area.split("-");
                customerZcy.setLiveProvince(areas[0]);
                customerZcy.setCityName(areas[1]);
                customerZcy.setLiveArea(areas[2]);
            }
 
            customerZcy.setHouseStatus(applyDto.getProfile_dict().isHas_house() ? 1 : 0);
            customerZcy.setCarStatus(applyDto.getProfile_dict().isHas_car() ? 1 : 0);
            customerZcy.setInsurancePolicy(applyDto.getProfile_dict().isInsurance() ? 1 : 0);
            customerZcy.setProvidentFund(applyDto.getProfile_dict().isHas_fund() ? 1 : 0);
            customerZcy.setSocialSecurity(applyDto.getProfile_dict().isHas_social() ? 1 : 0);
            // 学历
            String education = applyDto.getProfile_dict().getEducation();
            if ("2".equals(education)) {
                education = "1";
            }else if ("3".equals(education)) {
                education = "2";
            }else if ("4".equals(education)) {
                education = "3";
            }else {
                education = "4";
            }
            // 1. 高中及以下 2. 专科 3. 本科 4. 研究生及以上
            customerZcy.setEducation("0"+education);
            customerZcy.setCompanyName(applyDto.getProfile_dict().getOrganize_name());
            //婚姻状况
            String maritalStatus = applyDto.getProfile_dict().getMarital_status().toString();
            if ("2".equals(maritalStatus)) {
                maritalStatus = "3";
            }else if ("3".equals(maritalStatus) || "4".equals(maritalStatus) || "5".equals(maritalStatus) || "7".equals(maritalStatus)) {
                maritalStatus = "2";
            }else if ("6".equals(maritalStatus)) {
                maritalStatus = "4";
            }else {
                int num = random.nextInt(4) + 1;
                maritalStatus = String.valueOf(num);
            }
            customerZcy.setMaritalStatus(maritalStatus);
            String gender = applyDto.getProfile_dict().getGender();
            customerZcy.setAge("male".equals(gender) ? 1 : 2);
            customerZcy.setBirthday(applyDto.getProfile_dict().getBirthday());
            Integer monthlyIncome = applyDto.getProfile_dict().getMonthly_income();
            int mi = Objects.isNull(monthlyIncome) ? 0 : monthlyIncome.intValue();
            if (mi < 10000) { //'10000以下'
                mi = 3;
            }else if (mi < 30000){ //'10000-30000'
                mi = 4;
            }else { //'30000以上'
                mi = 13;
            }
            customerZcy.setMonthlyIncome(mi);
            //借款用途
            customerZcy.setUseOfLoan(applyDto.getProfile_dict().getLoan_usage());
            /**
             * (我来贷)所属行业 --> 融呗( (A:农、林、牧、渔业,B:采矿业,C:制造业,D:电力、热力、燃气及水生产和供应业,E:建筑业,F:批发和零售业,G:交通运输、仓储和邮储业,H:住宿和餐饮业,I:信息传输、软件和信息技术服务,J:金融业,K:房地产业,L:租赁和商务服务业,M:科学研究和技术服务业,N:水利、环境和公共设施管理业,O:居民服务、修理和其他服务业,P:教育,Q:卫生和社会工作,R:文化、体育和娱乐业,S:公共管理、社会保障和社会组织,T:国际组织,9:未知))
             * 1. 建筑业 -->(E)
             * 2. 电力,热力,燃气及水生产和供应业 -->(D)
             * 3. 交通运输、仓储和邮政业 -->(G)
             * 4. 教育 -->(P)
             * 5. 房地产业 -->(K)
             * 6. 住宿和餐饮业 -->(H)
             * 7. 批发和零售业 -->(F)
             * 8. 租赁和商务服务业 -->(L)
             * 9. 信息传输、软件和信息技术服务业 -->(I)
             * 10. 金融业 -->(J)
             * 11. 文化、体育和娱乐业 -->(R)
             * 12. 制造业 -->(C)
             * 13. 水利、环境和公共设施管理业 -->(N)
             * 14. 采矿业 -->(B)
             * 15. 农、林、牧、渔业 -->(A)
             * 16. 居民服务、修理和其他服务业 -->(O)
             * 17. 卫生和社会工作 -->(Q)
             * 18. 科学研究和技术服务业 -->(M)
             * 19. 公共管理、社会保障和社会组织 -->(S)
             */
            String companyTrade = applyDto.getProfile_dict().getIndustry();
            if ("1".equals(companyTrade)) { //建筑业
                companyTrade = "E";
            }else if ("2".equals(companyTrade)) { //电力,热力,燃气及水生产和供应业
                companyTrade = "D";
            }else if ("3".equals(companyTrade)) { //交通运输、仓储和邮政业
                companyTrade = "G";
            }else if ("4".equals(companyTrade)) { //教育
                companyTrade = "P";
            }else if ("5".equals(companyTrade)) { //房地产业
                companyTrade = "K";
            }else if ("6".equals(companyTrade)) { //住宿和餐饮业
                companyTrade = "H";
            }else if ("7".equals(companyTrade)) { //批发和零售业
                companyTrade = "F";
            }else if ("8".equals(companyTrade)) { //租赁和商务服务业
                companyTrade = "L";
            }else if ("9".equals(companyTrade)) { //信息传输、软件和信息技术服务业
                companyTrade = "I";
            }else if ("10".equals(companyTrade)) { //金融业
                companyTrade = "J";
            }else if ("11".equals(companyTrade)) { //文化、体育和娱乐业
                companyTrade = "R";
            }else if ("12".equals(companyTrade)) { //制造业
                companyTrade = "C";
            }else if ("13".equals(companyTrade)) { //水利、环境和公共设施管理业
                companyTrade = "N";
            }else if ("14".equals(companyTrade)) {  //采矿业
                companyTrade = "B";
            }else if ("15".equals(companyTrade)) { //农、林、牧、渔业
                companyTrade = "A";
            }else if ("16".equals(companyTrade)) { //居民服务、修理和其他服务业
                companyTrade = "O";
            }else if ("17".equals(companyTrade)) { //卫生和社会工作
                companyTrade = "Q";
            }else if ("18".equals(companyTrade)) { //科学研究和技术服务业
                companyTrade = "M";
            }else if ("19".equals(companyTrade)) { //公共管理、社会保障和社会组织
                companyTrade = "S";
            }
            customerZcy.setCompanyTrade(companyTrade);
            /**
             * 职业类型
             * 1. 上班
             * 2. 兼职
             * 3. 企业主
             * 4. 无业
             * 5. 个体户
             * 转融呗
             * 1. 自由职业
             * 2. 上班族
             * 3. 企业主
             * 4. 公务员/事业单位/国企
             */
            String jobType = applyDto.getProfile_dict().getJob_type();
            int professionInfo = 1;
            if ("1".equals(jobType)) {
                professionInfo = 2;
            }else if ("3".equals(jobType)) {
                professionInfo = 3;
            }else {
                professionInfo = random.nextInt(4) + 1;
            }
            customerZcy.setProfessionInfo(professionInfo);
            String companyCity = applyDto.getProfile_dict().getCompany_address();
            if (StringUtils.isNotEmpty(companyCity)) {
                String[] companyAddress = companyCity.split("-");
                customerZcy.setCompanyProvince(companyAddress[0]);
                customerZcy.setCompanyCity(companyAddress[1]);
                customerZcy.setCompanyArea(companyAddress[2]);
            }
            customerZcy.setCompanyAddress(applyDto.getProfile_dict().getCompany_address_detail());
 
            //活体对比数据
            if (!Objects.isNull(applyDto.getLive_info().getLive_data())) {
                // 活体分类
                customerZcy.setVerifySimilarity(applyDto.getLive_info().getLive_data().getFace_score());
            }
            customerZcy.setVerifySimilarityName(applyDto.getLive_info().getService_provider());
            customerZcy.setFacePhotoPath(applyDto.getLive_info().getBest_face_image());
 
            //设备信息
            customerZcy.setOs(applyDto.getDevice_info().getOs());
            customerZcy.setClientIp(applyDto.getDevice_info().getIp());
            String gps = applyDto.getDevice_info().getGps();
            if (StringUtils.isNotEmpty(gps)) {
                String[] gpsArray = gps.split(",");
                if (gpsArray.length == 2) {
                    customerZcy.setLng(gpsArray[0]);
                    customerZcy.setLat(gpsArray[1]);
                }
            }
            // 标记为我来数科的数据
            customerZcy.setMark(2);
            customerZcyService.save(customerZcy);
        }
        Customer cust = new Customer();
        BeanUtils.copyProperties(customerZcy, cust);
        return cust;
    }
 
    private static @NotNull String getRelationShip(ContactListDto dto) {
        int relation = dto.getRelation();
        if (relation == 1) {
            relation = 2;
        }else if (relation == 2) {
            relation = 1;
        }else if (relation >=5){
            Random random = new Random();
            int[] values = {2, 3, 4};
            relation = values[random.nextInt(values.length)];
        }
        return "0"+ relation;
    }
 
    /**
     * 从我来贷请求查询接受订单状态接口
     * @param body 请求体
     * @return RbResponse
     */
    public RbResponse checkOrderStatusByWld(RongBeBasicDto body) {
        RbResponse resp = new RbResponse();
        String logNumber = IdUtil.randomUUID();
        try {
            //解密biz_data
            JSONObject fullData = new JSONObject();
            fullData.putOpt("partner_id", body.getPartner_id());
            fullData.putOpt("timestamp", body.getTimestamp());
            fullData.putOpt("biz_data", body.getBiz_data());
            String decryptStr = decrypt(fullData, body.getSign(), wldPublicKey);
            if (StringUtils.isNotEmpty(decryptStr)) {
                // 用融呗的配置信息重新生成签名
                fullData.putOpt("partner_id", RbPartnerId);
                fullData.putOpt("timestamp", System.currentTimeMillis());
                fullData.putOpt("sign", getSign(fullData, rbPublicKey));
                try {
                    String result = HttpClientUtil.getInstance().postJsonData(wldUrl + "order_status", String.valueOf(fullData));
                    resp = JSON.parseObject(result, RbResponse.class);
                    return resp;
                } catch (Exception ex) {
                    log.error("日志编号:{}, 【我来贷】查询接受订单状态接口请求失败,传参:{} ex:{}",logNumber, fullData, ex.getMessage());
                }
                try {
                    resp.setCode("0");
                } catch (Exception ex) {
                    log.error("日志编号:{},【我来贷】查询接受订单状态接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage());
                }
            } else {
                resp.setCode("500");
            }
            return resp;
        } catch (Exception e) {
            resp.setCode("500");
            resp.setMsg(e.getMessage());
            log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求失败:{} 错误原因:{}", logNumber, body, e.getMessage());
            return resp;
        }
    }
 
    /**
     * 从我来贷请求查询接受订单状态接口
     */
    public void OrderStatusByWld(String chnOrderId, String partnerFlowId) {
        String logNumber = IdUtil.randomUUID();
        try {
            //解密biz_data
            JSONObject fullData = new JSONObject();
            JSONObject bizData = new JSONObject();
            bizData.putOpt("chn_order_id",chnOrderId);
            bizData.putOpt("partner_flow_id", partnerFlowId);
            bizData.putOpt("status", 101);
            bizData.putOpt("update_time", System.currentTimeMillis() / 1000);
            fullData.putOpt("biz_data", encrypt(String.valueOf(bizData)));
 
            fullData.putOpt("partner_id", RbPartnerId);
            fullData.putOpt("timestamp", System.currentTimeMillis());
            fullData.putOpt("sign", getSign(fullData, rbPublicKey));
            String result = null;
            try {
                result = HttpClientUtil.getInstance().postJsonData(wldUrl + "order_status", String.valueOf(fullData));
                log.info("日志编号:{} 【我来贷】查询接受订单状态接口请求失败,传参:{},返回结果:{}", logNumber, fullData, result);
            } catch (Exception ex) {
                log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求,传参:{} ex:{}",logNumber, fullData, ex.getMessage());
            }
            try {
                if (result != null) {
                    log.info("日志编号:{} 【我来贷】查询接受订单状态接口数据处理,传参:{},返回结果:{}", logNumber, fullData, result);
                }
            } catch (Exception ex) {
                log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage());
            }
        } catch (Exception e) {
            log.error("日志编号:{} 【我来贷】查询接受订单状态接口请求失败:{},{} 错误原因:{}", logNumber, chnOrderId, partnerFlowId, e.getMessage());
        }
    }
 
    /**
     * 从我来贷请求接受授信结果接口
     */
    public void autoPushCreditResult(String chnOrderId, String partnerFlowId) {
        String logNumber = IdUtil.randomUUID();
        try {
            //解密biz_data
            JSONObject fullData = new JSONObject();
            JSONObject bizData = new JSONObject();
            bizData.putOpt("chn_order_id", chnOrderId);
            bizData.putOpt("partner_flow_id", partnerFlowId);
            long currentTimestamp = System.currentTimeMillis();
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(currentTimestamp);
            calendar.add(Calendar.YEAR, 1); // 在当前时间上加一年
 
            // 获取一年后的时间戳(秒级时间戳)
            long nextYearTimestamp = calendar.getTimeInMillis() / 1000;
 
            bizData.putOpt("expired_ts", nextYearTimestamp);
            bizData.putOpt("max_amount", 5000000);
            bizData.putOpt("min_amount", 80000);
            bizData.putOpt("range_amount", 10000);
            Random random = new Random();
            int[] values  = {3, 6, 9, 12};
            int[] loanTerms = new int[1];
            int val = values[random.nextInt(values.length)];
            loanTerms[0] = val;
            bizData.putOpt("loan_terms", loanTerms);
            bizData.putOpt("withdraw_type", 1);
            log.info("日志编号:{} 【我来贷】接受授信结果接口请求结果 bizData:{}", logNumber, bizData);
 
            fullData.putOpt("biz_data", encrypt(String.valueOf(bizData)));
            fullData.putOpt("partner_id", RbPartnerId);
            fullData.putOpt("timestamp", System.currentTimeMillis());
            // 用融呗的配置信息重新生成签名
            fullData.putOpt("sign", getSign(fullData, rbPublicKey));
            String result = null;
            try {
                result = HttpClientUtil.getInstance().postJsonData(wldUrl + "credit_result", String.valueOf(fullData));
                log.info("日志编号:{} 【我来贷】接受授信结果接口请求结果:{}", logNumber, result);
            } catch (Exception ex) {
                log.error("日志编号:{} 【我来贷】接受授信结果接口请求失败,传参:{} ex:{}", logNumber, fullData, ex.getMessage());
            }
            try {
                if ( result != null) {
                    log.info("日志编号:{} 【我来贷】接受授信结果接口数据处理:{}", logNumber, result);
                }
            } catch (Exception ex) {
                log.error("日志编号:{} 【我来贷】接受授信结果接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage());
            }
 
        } catch (Exception e) {
            log.error("日志编号:{} 【我来贷】接受授信结果接口请求失败,参数:{}-{},错误原因:{}", logNumber, chnOrderId, partnerFlowId, e.getMessage());
        }
    }
    /**
     * 从我来贷请求接受授信结果接口
     * @return RbResponse
     */
    public RbResponse creditResultByWld(RongBeBasicDto body) {
        RbResponse resp = new RbResponse();
        String logNumber = IdUtil.randomUUID();
        try {
            //解密biz_data
            JSONObject fullData = new JSONObject();
            fullData.putOpt("partner_id", body.getPartner_id());
            fullData.putOpt("timestamp", body.getTimestamp());
            fullData.putOpt("biz_data", body.getBiz_data());
            String decryptStr = decrypt(fullData, body.getSign(), wldPublicKey);
            if (StringUtils.isNotEmpty(decryptStr)) {
                fullData.putOpt("partner_id", RbPartnerId);
                fullData.putOpt("timestamp", System.currentTimeMillis());
                // 用融呗的配置信息重新生成签名
                fullData.putOpt("sign", getSign(fullData, rbPublicKey));
                try {
                    String result = HttpClientUtil.getInstance().postJsonData(wldUrl + "credit_result", String.valueOf(fullData));
                    log.info("日志编号:{} 【我来贷】接受授信结果接口请求返回结果:{}", logNumber, result);
                    resp = JSON.parseObject(result, RbResponse.class);
                    return resp;
                } catch (Exception ex) {
                    log.error("日志编号:{}, 【我来贷】接受授信结果接口请求,传参:{} ex:{}", logNumber, fullData, ex.getMessage());
                }
                try {
                    resp.setCode("0");
                } catch (Exception ex) {
                    log.error("日志编号:{},【我来贷】接受授信结果接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage());
                }
            } else {
                resp.setCode("5000");
            }
            return resp;
        } catch (Exception e) {
            resp.setCode("5000");
            resp.setMsg(e.getMessage());
            log.error("日志编号:{} 【我来贷】接受授信结果接口请求失败:{} 错误原因:{}", logNumber, resp, e.getMessage());
            return resp;
        }
    }
 
    /**
     * 从我来贷请求接受还款计划接口
     * @param body 请求体
     * @return RbResponse
     */
    public RbResponse repayInfoByWld(RongBeBasicDto body) {
        RbResponse resp = new RbResponse();
        String logNumber = IdUtil.randomUUID();
        try {
            //解密biz_data
            JSONObject fullData = new JSONObject();
            fullData.putOpt("partner_id", body.getPartner_id());
            fullData.putOpt("timestamp", body.getTimestamp());
            fullData.putOpt("biz_data", body.getBiz_data());
            String decryptStr = decrypt(fullData, body.getSign(), wldPublicKey);
            if (StringUtils.isNotEmpty(decryptStr)) {
                // 用融呗的配置信息重新生成签名
                fullData.putOpt("partner_id", RbPartnerId);
                fullData.putOpt("timestamp", System.currentTimeMillis());
                fullData.putOpt("sign", getSign(fullData, rbPublicKey));
                try {
                    String result = HttpClientUtil.getInstance().postJsonData(wldUrl + "repay_info", String.valueOf(fullData));
                    resp = JSON.parseObject(result, RbResponse.class);
                    return resp;
                } catch (Exception ex) {
                    log.error("日志编号:, 【我来贷】接受还款计划接口请求失败,传参:{} ex:{}", logNumber, fullData, ex);
                }
                try {
                    resp.setCode("0");
                } catch (Exception ex) {
                    log.error("日志编号:{} 【我来贷】接受还款计划接口请求原始返回参数转换失败,jsonData:{} ex:{}", logNumber, fullData, ex.getMessage());
                }
            } else {
                resp.setCode("500");
            }
            return resp;
        } catch (Exception e) {
            resp.setCode("500");
            resp.setMsg(e.getMessage());
            log.error("日志编号:{} 【我来贷】查询订单状态接口请求失败:{} 错误原因:{}", logNumber, body, e.getMessage());
            return resp;
        }
    }
 
    /**
     * 加密
     * @param oriData 要加密的内容串
     * @return String
     */
    public String encrypt(String oriData) {
        AES aes = new AES("ECB", "PKCS5Padding", encryptKey.getBytes());
        String encryptString = aes.encryptBase64(oriData);
        log.info("加密后的数据:{}", encryptString);
        return encryptString;
    }
 
    /**
     * 生成签名(融呗私钥加密)
     * @param fullData 用于签名的对象
     * @param publicKey 公钥
     * @return String
     */
    public String getSign(JSONObject fullData, String publicKey) {
        //排序
        TreeMap treeMap = JSONUtil.toBean(fullData, TreeMap.class);
        String oriSignData = MapUtil.sortJoin(treeMap, "&", "=", true);
        RsaSupport rsaSupport = new RsaSupport("RSA", "SHA256WithRSA","RSA/ECB/PKCS1Padding", "utf-8", publicKey, privateKey);
        return rsaSupport.signByPrivateKey(oriSignData);
    }
 
    /**
     * 解密(公钥解密)
     * @param fullData 要解密的内容
     * @param publicKey 公钥
     * @return String
     */
    private String decrypt(JSONObject fullData, String sign, String publicKey) {
        log.info("publicKey:{}", publicKey);
        RsaSupport rsaSupport = new RsaSupport("RSA", "SHA256WithRSA", "RSA/ECB/PKCS1Padding", "utf-8", publicKey, privateKey);
        AES aes = new AES("ECB", "PKCS5Padding", encryptKey.getBytes());
        log.info("fullData:{}", fullData);
        //排序
        TreeMap treeMap = JSONUtil.toBean(fullData, TreeMap.class);
        String oriSignData = MapUtil.sortJoin(treeMap, "&", "=", true);
        log.info("oriSignData:{}", oriSignData);
        log.info("sign:{}", sign);
        boolean flag = rsaSupport.verifyByPublicKey(oriSignData, sign);
        log.info("验签结果:{}", flag);
        if (flag) {
            String decryptStr = aes.decryptStr(fullData.getStr("biz_data"));
            log.info("解密出来的数据:{}", decryptStr);
            return decryptStr;
        } else {
            return null;
        }
    }
 
    /**
     * 提供我来贷进件发送短信
     * @param phone
     */
    public void smsNotify(String phone) {
        String content = "【乐享融】您申请的信用额已通过审核,请1小时内查看【" + smsNotifyUrl + "】 过期作废!拒收请回复R";
        boolean success = FirstMessage.sendSmsApprovalNotify(phone, content);
        if (!success) {
            log.info("进件时短信通知日志: 用户手机:" + phone + "原短信商" + "发送返回失败");
            throw new CommonException("进件时短信通知发送失败");
        }
        log.info("进件时短信通知日志: 用户手机:" + phone + "原短信商" + "发送返回成功");
    }
 
    /**
     * 提供我来贷进件发送短信
     * @param phone
     */
    public void smsApprovalNotify(String one,String two,String phone) {
//        String content = "您申请的信用额已通过审核,请1小时内查看【" + smsNotifyUrl + "】 过期作废!拒收请回复R";
        String content = "【乐享融】你申请的信用额度【"+ one +"】于【"+ two +"】已通过审核:前往 【" + smsNotifyUrl + "】 提取贷款,拒收请回复R";
        boolean success = FirstMessage.sendSmsApprovalNotify(phone, content);
        log.info("青花优品进件通过手机号短信通知日志: 用户手机:" + phone + "原短信商" + "验证码发送返回成功");
        if (!success) {
            log.info("青花优品进件通过手机号短信通知日志: 用户手机:" + phone + "原短信商" + "验证码发送返回失败");
            throw new CommonException("验证码发送失败");
        }
 
    }
}