myjf007
2024-11-04 627b61d17da1dbf02c0363c659b728627dd42890
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
package com.nova.sankuai.service.impl;
 
import cn.hutool.http.ContentType;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiCommitResponse;
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiHitResponse;
import com.nova.sankuai.domain.api.huizhongzhidai.HuiZhongZhiDaiUtil;
import com.nova.sankuai.domain.api.jinRiTouTiao.JinRiTouTiaoUtil;
import com.nova.sankuai.domain.api.jinxiushuke.JinXiuShuKeResponse;
import com.nova.sankuai.domain.api.jinxiushuke.JinXiuShuKeUtil;
import com.nova.sankuai.domain.api.jinzhanggui.JinZhangGuiResponse;
import com.nova.sankuai.domain.api.jinzhanggui.JinZhangGuiUtil;
import com.nova.sankuai.domain.api.minsheng.MinShengUtil;
import com.nova.sankuai.domain.api.nanjingmingtuo.NanJingMingTuoUtil;
import com.nova.sankuai.domain.api.rongduoduo.RongDuoDuoResponse;
import com.nova.sankuai.domain.api.rongduoduo.RongDuoDuoUtil;
import com.nova.sankuai.domain.api.rongduoduo.SanKuaiCustomer;
import com.nova.sankuai.domain.api.shanghaizhongzan.ShangHaiZhongZanUtil;
import com.nova.sankuai.domain.api.tianshi.TianShiResponse;
import com.nova.sankuai.domain.api.tianshi.TianShiUtil;
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.SignatureUtil;
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaResponse;
import com.nova.sankuai.domain.api.xiamenzhongheyinhua.XiaMenZhongHeYinHuaUtil;
import com.nova.sankuai.domain.api.xinyeyoupin.XinYeYouPinUtil;
import com.nova.sankuai.domain.api.yidai.YiDaiResponse;
import com.nova.sankuai.domain.api.yidai.YiDaiUtil;
import com.nova.sankuai.domain.api.yinsheng.SerialGenerator;
import com.nova.sankuai.domain.dto.ApiCompanyPageDto;
import com.nova.sankuai.domain.entity.*;
import com.nova.sankuai.domain.enums.ApiCompanyCodeEnum;
import com.nova.sankuai.domain.enums.SourceTypeEnum;
import com.nova.sankuai.domain.vo.ApiCompanyVo;
import com.nova.sankuai.infra.config.CommonException;
import com.nova.sankuai.infra.constants.Constants;
import com.nova.sankuai.infra.mapper.ApiCompanyMapper;
import com.nova.sankuai.infra.mapper.ChannelInfoMapper;
import com.nova.sankuai.infra.mapper.CustomerMapper;
import com.nova.sankuai.infra.utils.ApiCompanyCheckUtil;
import com.nova.sankuai.infra.utils.PageRequest;
import com.nova.sankuai.infra.utils.PageUtil;
import com.nova.sankuai.security.HttpClientUtil;
import com.nova.sankuai.service.*;
import lombok.AllArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
 
/**
 * @author weikangdi
 */
@Service
@AllArgsConstructor
public class ApiCompanyServiceImpl extends ServiceImpl<ApiCompanyMapper, ApiCompany> implements IApiCompanyService {
 
    private final ApiCompanyMapper mapper;
 
    private final PageUtil pageUtil;
 
    private final TianShiUtil tianShiUtil;
 
    private final HuiZhongZhiDaiUtil huiZhongZhiDaiUtil;
 
    private final ShangHaiZhongZanUtil shangHaiZhongZanUtil;
 
    private final NanJingMingTuoUtil nanJingMingTuoUtil;
 
    private final ICityService cityService;
 
    private final IApiCompanyRecordService recordService;
 
    private final IChannelLogService channelLogService;
 
    private final CustomerMapper customerMapper;
 
    private final IChannelCompanyConfigService channelCompanyConfigService;
 
    private final ChannelInfoMapper channelInfoMapper;
 
    private final ApiCompanyCheckUtil checkUtil;
 
    private final XinYeYouPinUtil xinYeYouPinUtil;
 
    private final RongDuoDuoUtil rongDuoDuoUtil;
 
    private static final Logger log = LoggerFactory.getLogger("apiCompanyInfoLogger");
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void edit(ApiCompany apiCompany) {
        ApiCompany company = getById(apiCompany.getId());
        if (company == null) {
            throw new CommonException("该接口公司不存在");
        }
        company.setCustomerNum(apiCompany.getCustomerNum());
        company.setDeliveryCity(apiCompany.getDeliveryCity());
        company.setDeliveryCityName(apiCompany.getDeliveryCityName());
        company.setEnableFlag(apiCompany.getEnableFlag());
        company.setMinLoanAmount(apiCompany.getMinLoanAmount());
        company.setAgeLowerLimit(apiCompany.getAgeLowerLimit());
        company.setAgeUpperLimit(apiCompany.getAgeUpperLimit());
        company.setMarriageLimit(apiCompany.getMarriageLimit());
        company.setSesameLimit(apiCompany.getSesameLimit());
        company.setSocialSecurityLimit(apiCompany.getSocialSecurityLimit());
        company.setProvidentFundLimit(apiCompany.getProvidentFundLimit());
        company.setHouseLimit(apiCompany.getHouseLimit());
        company.setCarLimit(apiCompany.getCarLimit());
        company.setPolicyLimit(apiCompany.getPolicyLimit());
        company.setCreditCardLimit(apiCompany.getCreditCardLimit());
        company.setAmountLowerLimit(apiCompany.getAmountLowerLimit());
        company.setAmountUpperLimit(apiCompany.getAmountUpperLimit());
        company.setMonthlyIncomeLimit(apiCompany.getMonthlyIncomeLimit());
        company.setEducationLimit(apiCompany.getEducationLimit());
        company.setChannelConfig(apiCompany.getChannelConfig());
        updateById(company);
        channelCompanyConfigService.updateConfig(apiCompany);
    }
 
 
    @Override
    public IPage<ApiCompanyVo> pageModel(PageRequest pageRequest, ApiCompanyPageDto pageDto) {
        IPage<ApiCompanyVo> page = mapper.pageModel(pageUtil.getPage(pageRequest), pageDto);
        List<ApiCompanyVo> records = page.getRecords();
        List<ApiCompanyVo> newRecords = new ArrayList<>();
        for (ApiCompanyVo record : records) {
            List<Long> channelIds = channelCompanyConfigService.getChannelsByCompanyId(record.getId());
            record.setChannelIds(channelIds);
            newRecords.add(record);
        }
        page.setRecords(newRecords);
        return page;
    }
 
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void pushCustomer(Customer customer) {
        try {
            City city = cityService.lambdaQuery().eq(City::getCityId, customer.getCity()).one();
            if (city != null) {
                List<ApiCompany> result = mapper.getCompanies(city.getCityId(), city.getProvinceId());
                ChannelInfo channelInfo = channelInfoMapper.getChannelByCode(customer.getSourceChannel());
                for (ApiCompany apiCompany : result) {
                    // 筛选渠道配置匹配的接口公司
                    String type = "有痕模式";
                    boolean checkChannelConfig = checkUtil.filterCustomer(customer, apiCompany, channelInfo, type);
                    if (!checkChannelConfig) {
                        log.error(type + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                                + "错误:该用户的不满足推送条件");
                        continue;
                    }
                    chooseApiCompany(apiCompany, customer, true);
                }
            } else {
                log.error("审批分流推送警告:城市信息为空, 客户数据" + customer.toString());
            }
        } catch (Exception e) {
            log.error("审批分流推送异常,原始数据" + customer.toString(), e);
        }
    }
 
    @Override
    public void pushCustomerNoTrace(Customer customer) {
        City city = cityService.lambdaQuery().eq(City::getCityId, customer.getCity()).one();
        if (city != null) {
            List<ApiCompany> companyList = mapper.getCompanies(city.getCityId(), city.getProvinceId());
            if (companyList == null || companyList.isEmpty()) {
                log.error("无痕推送错误:推送城市信息不匹配或推送机构未开启");
                throw new CommonException("没有符合条件的推送机构");
            }
            ChannelInfo channelInfo = channelInfoMapper.getChannelByCode(customer.getSourceChannel());
            boolean pushResult = false;
            for (ApiCompany apiCompany : companyList) {
                // 筛选渠道配置匹配的接口公司
                String type = "无痕模式";
                boolean checkChannelConfig = checkUtil.filterCustomer(customer, apiCompany, channelInfo, type);
                if (!checkChannelConfig) {
                    log.error("无痕推送" + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                            + "错误:该用户不满足推送条件");
                    continue;
                }
                ApiCompanyRecord record = chooseApiCompany(apiCompany, customer, false);
                if (record == null) {
                    log.error("无痕推送" + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                            + "错误:构建的ApiCompanyRecord为空");
                } else if (record.getStatus() == ApiCompanyRecord.FAIL) {
                    log.error("无痕推送" + apiCompany.getCompanyName() + "失败,用户手机号" + customer.getPhone()
                            + "错误:" + record.toString());
                } else {
                    pushResult = true;
                    log.info("无痕推送" + apiCompany.getCompanyName() + "成功,用户信息:" + customer.toString());
                }
            }
            if (!pushResult) {
                throw new CommonException("数据推送失败");
            }
        } else {
            log.error("无痕推送失败,错误:城市信息为空, 用户手机号" + customer.getPhone());
            throw new CommonException("城市信息不能为空");
        }
    }
 
    /**
     * 通过公司code判断需要推送的公司
     *
     * @param apiCompany
     * @param customer
     */
    private ApiCompanyRecord chooseApiCompany(ApiCompany apiCompany, Customer customer, boolean saveLog) {
        try {
            // 调用接口公司对应API接口
            if (ApiCompanyCodeEnum.SHANG_HAI_ZHONG_ZAN.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接上海中赞
                return shangHaiZhongZanInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.NAN_JING_MING_TUO.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接南京名拓
                return nanJingMingTuoInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.XiaMenZhongHeYinHua.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接厦门众合银华
                return xiaMenZhongHeYinHuaInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.MIN_SHENG.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接民生
                return minShengInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.RONG_DUO_DUO.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接融多多
                return rongDuoDuoInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.TIAN_SHI.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接苏州天师
                return tianShiInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.HUI_ZHONG_ZHI_DAI.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接惠众直贷
                return huiZhongZhiDaiInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.JIN_XIU_SHU_KE.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接锦绣数科
                return jinXiuShuKeInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.YI_DAI.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接北京亿代
                return YiDaiInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.HUI_RONG.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接汇融
                return jinRiTouTiaoInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.XIN_YE_YOU_PIN.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接信业优品
                return xinyeyoupinInterface(customer, apiCompany.getId(), saveLog);
            } else if (ApiCompanyCodeEnum.SANDBOX_TEST.getCode().equals(apiCompany.getCompanyCode())) {
                ApiCompanyRecord apiCompanyRecord = new ApiCompanyRecord(apiCompany.getId(), customer.getId(), null);
                apiCompanyRecord.setStatus(ApiCompanyRecord.SUCCESS);
                apiCompanyRecord.setMessage("测试成功");
                if (saveLog) {
                    recordService.save(apiCompanyRecord);
                    channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.SANDBOX_EXPORT_TEST.getCode(), apiCompanyRecord.getStatus(), customer.getId(), null);
                }
                return apiCompanyRecord;
            } else if (ApiCompanyCodeEnum.JIN_ZHANG_GUI.getCode().equals(apiCompany.getCompanyCode())) {
                // 对接中银e贷-金掌柜
                return jinzhangguiInterface(customer, apiCompany.getId(), saveLog);
            }
        } catch (Exception e) {
            log.error("审批分流异常,公司code: " + apiCompany.getCompanyCode(), e);
        }
        log.error("未找到匹配的公司code: " + apiCompany.getCompanyCode());
        return null;
    }
 
    private ApiCompanyRecord nanJingMingTuoInterface(Customer customer, Long companyId, boolean saveLog) {
        String hitReq = nanJingMingTuoUtil.parseHitParam(customer);
        HttpResponse response = null;
        try {
            log.info("南京名拓接口撞库请求数据: {}", hitReq);
            response = HttpRequest.post(nanJingMingTuoUtil.getHitUrl())
                    .contentType(MediaType.APPLICATION_JSON_VALUE)
                    .body(hitReq)
                    .execute();
        } catch (Exception e) {
            log.error("南京名拓接口撞库失败!", e);
        }
        Assert.notNull(response, "南京名拓接口撞库数据响应为NULL!");
        if (nanJingMingTuoUtil.passHitResponse(response)) {
            try {
                String req = nanJingMingTuoUtil.parseParam(customer);
                log.info("南京名拓接口推送请求数据: {}", req);
                response = HttpRequest.post(nanJingMingTuoUtil.getUrl())
                        .contentType(MediaType.APPLICATION_JSON_VALUE)
                        .body(req)
                        .execute();
            } catch (Exception e) {
                log.error("南京名拓接口推送数据失败!", e);
            }
            Assert.notNull(response, "南京名拓接口推送数据响应为NULL!");
            ApiCompanyRecord record = ApiCompanyRecord.getNanJingMingTuoRecord(companyId, customer.getId(), response.body());
            if (saveLog) {
                recordService.save(record);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.NanJingMingTuo.getCode(), record.getStatus(), customer.getId(), response.body());
            }
            return record;
        } else {
            log.warn("南京名拓接口撞库:手机号[{}]已存在", customer.getPhone());
            ApiCompanyRecord record = ApiCompanyRecord.getNanJingMingTuoRecord(companyId, customer.getId(), response.body());
            if (saveLog) {
                recordService.save(record);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.NanJingMingTuo.getCode(), record.getStatus(), customer.getId(), response.body());
            }
            return record;
        }
    }
 
    private ApiCompanyRecord shangHaiZhongZanInterface(Customer customer, Long companyId, boolean saveLog) {
        String body = ShangHaiZhongZanUtil.parseParam(customer);
        HttpResponse response = null;
        try {
            log.info("上海中赞接口推送数据开始,原始数据: {}", body);
            response = HttpRequest.post(shangHaiZhongZanUtil.getUrl())
                    .contentType(MediaType.APPLICATION_JSON_VALUE)
                    .timeout(Constants.TIME_OUT)
                    .body(body)
                    .execute();
        } catch (Exception e) {
            log.error("上海中赞接口数据推送失败!", e);
        }
        Assert.notNull(response, "上海中赞接口推送数据响应为NULL!");
        ApiCompanyRecord record = ApiCompanyRecord.getShangHaiZhongZanRecord(companyId, customer.getId(), response.body());
        if (saveLog) {
            recordService.save(record);
            channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.ShangHaiZhongZan.getCode(), record.getStatus(), customer.getId(), response.body());
        }
        return record;
    }
 
    @Override
    public ApiCompanyRecord xiaMenZhongHeYinHuaInterface(Customer customer, Long companyId, boolean saveLog) {
        try {
            XiaMenZhongHeYinHuaResponse hitResp = XiaMenZhongHeYinHuaUtil.phoneCheckExists(customer.getPhone());
            if (Objects.equals(hitResp.getCode(), 0)) {
                JSONArray param = XiaMenZhongHeYinHuaUtil.parseParam(customer);
                HttpResponse response = null;
                try {
                    log.info("厦门众合银华推送数据开始,原始数据:" + param);
                    String requestBodyString = param.toString();
                    String timestamp = String.valueOf(System.currentTimeMillis());
                    String nonce = SignatureUtil.getRandomStr();
                    String encryptBody = SignatureUtil.encrypt(requestBodyString, SignatureUtil.SECRET_KEY);
                    response = HttpRequest.post(XiaMenZhongHeYinHuaUtil.PROD_URL_ENC)
                            .header("channel", XiaMenZhongHeYinHuaUtil.CHANNEL)
                            .header("timestamp", timestamp)
                            .header("nonce", nonce)
                            .header("sign", SignatureUtil.getSignature(encryptBody, nonce, SignatureUtil.SECRET_KEY, timestamp))
                            .contentType("text/plain")
                            .timeout(Constants.TIME_OUT)
                            .body(encryptBody).execute();
                    log.info("推送结果:" + response.body());
                } catch (Exception e) {
                    log.error("数据推送失败:" + e);
                }
                assert response != null;
                ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getXiaMenZhongHeYinHuaRecord(companyId, customer.getId(), response.body());
                if (saveLog) {
                    recordService.save(apiCompanyRecord);
                    channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.XiaMenZhongHeYinHua.getCode(), apiCompanyRecord.getStatus(), customer.getId(), response.body());
                }
                return apiCompanyRecord;
            } else {
                if (Objects.equals(hitResp.getCode(), 1)) {
                    hitResp.setMsg("撞库失败:数据已存在");
                } else {
                    hitResp.setMsg("撞库失败:参数不能为空");
                }
                String result = JSON.toJSONString(hitResp);
                ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getXiaMenZhongHeYinHuaRecord(companyId, customer.getId(), result);
                if (saveLog) {
                    recordService.save(apiCompanyRecord);
                    channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.XiaMenZhongHeYinHua.getCode(), apiCompanyRecord.getStatus(), customer.getId(), result);
                }
                return apiCompanyRecord;
            }
        } catch (RuntimeException e) {
            log.error("厦门众合银华接口报错.", e);
            return null;
        }
    }
 
    @Override
    public ApiCompanyRecord rongDuoDuoInterface(Customer customer, Long companyId, boolean saveLog) {
        try {
            String result = null;
            try {
                result = rongDuoDuoUtil.apiMd5Check(customer);
                RongDuoDuoResponse rongDuoDuoResponse = RongDuoDuoUtil.getResponse(result);
                if (rongDuoDuoResponse != null && 200 == rongDuoDuoResponse.getStatus()) {
                    try {
                        SanKuaiCustomer cstm = rongDuoDuoUtil.parseParam(customer);
                        String param = RongDuoDuoUtil.encrypt(JSONObject.toJSONString(cstm));
                        log.info("加密参数:" + param);
                        result = HttpClientUtil.getInstance().postJsonData(rongDuoDuoUtil.url2, JSONObject.toJSONString(param));
                        log.info("融多多推送数据返回:" + result);
                    } catch (Exception e) {
                        log.info("融多多推送数据失败:", e);
                    }
                }
            } catch (Exception e) {
                log.info("融多多撞库失败:", e);
            }
            ApiCompanyRecord rongDuoDuoRecord = ApiCompanyRecord.getRongDuoDuoRecord(companyId, customer.getId(), result);
            if (saveLog) {
                recordService.save(rongDuoDuoRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.RONG_DUO_DUO.getCode(), rongDuoDuoRecord.getStatus(), customer.getId(), result);
            }
            return rongDuoDuoRecord;
        } catch (Exception e) {
            log.info("融多多审批分流对接失败:", e);
        }
        return null;
    }
 
    @Override
    public ApiCompanyRecord minShengInterface(Customer customer, Long companyId, boolean saveLog) {
        HashMap<String, Object> param = MinShengUtil.parseParam(customer);
        String response = null;
        try {
            log.info("民生推送数据开始,原始数据:" + param.toString());
            response = HttpUtil.post(MinShengUtil.MINSHENG_URL, param, Constants.TIME_OUT);
            log.info("推送结果:" + response);
        } catch (Exception e) {
            log.error("民生推送数据失败:" + e);
        }
        ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getMinShengRecord(companyId, customer.getId(), response);
        if (saveLog) {
            recordService.save(apiCompanyRecord);
            channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.MIN_SHENG.getCode(), apiCompanyRecord.getStatus(), customer.getId(), response);
        }
        return apiCompanyRecord;
    }
 
    @Override
    public ApiCompanyRecord jinRiTouTiaoInterface(Customer customer, Long companyId, boolean saveLog) {
        String param = JinRiTouTiaoUtil.parseParam(customer);
        String result = null;
        try {
            log.info("汇融推送数据开始,原始数据:" + param);
            result = HttpUtil.post(JinRiTouTiaoUtil.HUIRONG_URL, param, Constants.TIME_OUT);
            log.info("推送结果:" + result);
        } catch (Exception e) {
            log.error("汇融推送数据失败:" + e);
        }
        ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinRiTouTiaoRecord(companyId, customer.getId(), result);
        if (saveLog) {
            recordService.save(apiCompanyRecord);
            channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.HUIRONG.getCode(), apiCompanyRecord.getStatus(), customer.getId(), result);
        }
        return apiCompanyRecord;
    }
 
    @Override
    public ApiCompanyRecord tianShiInterface(Customer customer, Long companyId, boolean saveLog) {
        JSONObject hitParam = tianShiUtil.parseHitParam(customer);
        TianShiResponse hitRes = new TianShiResponse();
        hitRes.setCode(-1);
        try {
            String hitResult = HttpRequest.post(tianShiUtil.hitUrl)
                    .header("secretapi", tianShiUtil.secretapi)
                    .contentType("application/json")
                    .timeout(Constants.TIME_OUT)
                    .body(JSONObject.toJSONString(hitParam), ContentType.JSON.getValue()).execute().body();
            hitRes.setCode(Integer.valueOf(hitResult));
        } catch (NumberFormatException e) {
            log.error("苏州天师撞库接口返回格式有误", e);
        } catch (Exception e) {
            log.error("苏州天师撞库接口对接失败", e);
        }
        if (TianShiResponse.SUCCESS == hitRes.getCode()) {
            JSONObject param = tianShiUtil.parseCommitParam(customer);
            Integer commitResultInt = -1;
            try {
                String commitResult = HttpRequest.post(tianShiUtil.commitUrl)
                        .header("secretapi", tianShiUtil.secretapi)
                        .contentType("application/json")
                        .timeout(Constants.TIME_OUT)
                        .body(JSONObject.toJSONString(param), ContentType.JSON.getValue()).execute().body();
                commitResultInt = Integer.valueOf(commitResult);
            } catch (NumberFormatException e) {
                log.error("苏州天师提交数据接口返回格式有误", e);
            } catch (Exception e) {
                log.error("苏州天师提交数据接口对接失败", e);
            }
            ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getTianShiRecord(companyId, customer.getId(), commitResultInt);
            if (saveLog) {
                recordService.save(apiCompanyRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.TianShi.getCode(), apiCompanyRecord.getStatus(), customer.getId(), Integer.toString(commitResultInt));
            }
            return apiCompanyRecord;
        } else {
            ApiCompanyRecord failRecord = ApiCompanyRecord.getTianShiRecord(companyId, customer.getId(), hitRes.getCode());
            if (saveLog) {
                recordService.save(failRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.TianShi.getCode(), failRecord.getStatus(), customer.getId(), Integer.toString(hitRes.getCode()));
            }
            return failRecord;
        }
    }
 
    @Override
    public ApiCompanyRecord YiDaiInterface(Customer customer, Long companyId, boolean saveLog) {
        JSONObject jsonObject = YiDaiUtil.parseMd5Param(customer);
        YiDaiResponse yiDaiResponse = new YiDaiResponse();
        HttpResponse response = null;
        try {
            log.info("北京亿代撞库试验开始,请求参数:" + jsonObject);
            response = HttpRequest.post(YiDaiUtil.YIDAI_ZC_URL).contentType("application/json")
                    .body(jsonObject.toJSONString())
                    .timeout(Constants.TIME_OUT)
                    .execute();
            log.info("北京亿代撞库试验结束,返回参数:" + response);
            yiDaiResponse.setRetCode("-1");
            try {
                yiDaiResponse = JSONObject.parseObject(response.body(), YiDaiResponse.class);
            } catch (Exception e) {
                log.error("撞库返回参数转换接受类失败");
            }
        } catch (Exception e) {
            log.error("北京亿代撞库对接失败");
        }
        if (YiDaiResponse.SUCCESS.equals(yiDaiResponse.getRetCode())) {
            YiDaiResponse yiDai = new YiDaiResponse();
            yiDai.setRetCode("-1");
            JSONObject parseRSAParam = YiDaiUtil.parseRSAParam(YiDaiUtil.parseParam(customer));
            if (parseRSAParam != null) {
                String replace = parseRSAParam.getString("encryptionData").replaceAll("\r|\n", "");
                parseRSAParam.put("encryptionData", replace);
            }
            HttpResponse httpResponse = null;
            try {
                log.info("北京亿代推送数据开始,数据源:" + parseRSAParam);
                httpResponse = HttpRequest.post(YiDaiUtil.YIDAI_RSA_URL)
                        .contentType("multipart/form-data")
                        .timeout(Constants.TIME_OUT)
                        .form(parseRSAParam).execute();
                log.info("推送结果:" + httpResponse.body());
            } catch (Exception e) {
                log.error("北京亿代推送数据失败:", e);
            }
            if (httpResponse != null) {
                ApiCompanyRecord yiDaiRecord = ApiCompanyRecord.getYiDaiRecord(companyId, customer.getId(), httpResponse.body());
                if (saveLog) {
                    recordService.save(yiDaiRecord);
                    channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.YIDAI.getCode(), yiDaiRecord.getStatus(), customer.getId(), httpResponse.body());
                }
                return yiDaiRecord;
            }
            return null;
        } else {
            ApiCompanyRecord yiDaiRecord = ApiCompanyRecord.getYiDaiRecord(companyId, customer.getId(), response.body());
            if (saveLog) {
                recordService.save(yiDaiRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.YIDAI.getCode(), yiDaiRecord.getStatus(), customer.getId(), yiDaiResponse.getRetCode());
            }
            return yiDaiRecord;
        }
    }
 
    @Override
    public List<ApiCompanyVo> getApiCompany() {
        List<ApiCompanyVo> apiCompany = mapper.getApiCompany();
        return apiCompany;
    }
 
    private ApiCompanyRecord jinXiuShuKeInterface(Customer customer, Long companyId, boolean saveLog) {
        JSONObject hitParam = JinXiuShuKeUtil.parseHitParam(customer);
        log.info("锦绣数科撞库开始,原始数据:" + hitParam);
        String hitResponse = HttpUtil.post(JinXiuShuKeUtil.HIT_URL, JSONObject.toJSONString(hitParam), Constants.TIME_OUT);
        log.info("撞库结果:" + hitResponse);
        JinXiuShuKeResponse hitResp = new JinXiuShuKeResponse();
        hitResp.setCode(-1);
        try {
            hitResp = JSONObject.parseObject(hitResponse, JinXiuShuKeResponse.class);
        } catch (Exception e) {
            log.error("锦绣数科撞库对接失败");
        }
        if (JinXiuShuKeUtil.SUCCESS.equals(hitResp.getCode())) {
            JSONObject commitParam = JinXiuShuKeUtil.parseCommitParam(customer);
            log.info("锦绣数科推送数据开始,原始数据:" + commitParam);
            String commitResponse = HttpUtil.post(JinXiuShuKeUtil.COMMIT_URL, JSONObject.toJSONString(commitParam), Constants.TIME_OUT);
            log.info("推送结果:" + commitResponse);
            ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinXiuShuKeRecord(companyId, customer.getId(), commitResponse);
            if (saveLog) {
                recordService.save(apiCompanyRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JinXiuShuKe.getCode(), apiCompanyRecord.getStatus(), customer.getId(), commitResponse);
            }
            return apiCompanyRecord;
        } else {
            ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinXiuShuKeRecord(companyId, customer.getId(), hitResponse);
            if (saveLog) {
                recordService.save(apiCompanyRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JinXiuShuKe.getCode(), apiCompanyRecord.getStatus(), customer.getId(), hitResponse);
            }
            return apiCompanyRecord;
        }
    }
 
    private ApiCompanyRecord huiZhongZhiDaiInterface(Customer customer, Long companyId, boolean saveLog) {
        JSONObject hitParam = huiZhongZhiDaiUtil.parseHitParam(customer);
        String hitResponse = null;
        try {
            log.info("惠众直贷撞库开始,原始数据:" + hitParam);
            hitResponse = HttpUtil.post(huiZhongZhiDaiUtil.hitUrl, JSONObject.toJSONString(hitParam), Constants.TIME_OUT);
            log.info("惠众直贷撞库结果:" + hitResponse);
        } catch (Exception e) {
            log.error("惠众直贷撞库失败:" + e);
        }
        HuiZhongZhiDaiHitResponse hitResp = new HuiZhongZhiDaiHitResponse();
        hitResp.setCode("0001");
        try {
            hitResp = JSONObject.parseObject(hitResponse, HuiZhongZhiDaiHitResponse.class);
        } catch (Exception e) {
            log.error("惠众直贷深圳撞库响应解析失败", e);
        }
        if (HuiZhongZhiDaiHitResponse.SUCCESS_CODE.equals(hitResp.getCode())) {
            JSONObject commitParam = huiZhongZhiDaiUtil.parseCommitParam(customer);
            JSONObject encrypt = new JSONObject();
            encrypt.put("data", huiZhongZhiDaiUtil.encrypt(JSONObject.toJSONString(commitParam)));
            log.info("惠众直贷数据推送开始,原始数据:" + encrypt);
            String commitResponse = HttpUtil.post(huiZhongZhiDaiUtil.commitUrl, JSONObject.toJSONString(encrypt), Constants.TIME_OUT);
            log.info("惠众直贷数据推送结果:" + commitResponse);
            try {
                JSONObject.parseObject(commitResponse, HuiZhongZhiDaiCommitResponse.class);
            } catch (Exception e) {
                log.error("惠众直贷数据推送响应解析失败", e);
            }
            ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getHuiZhongZhiDai(companyId, customer.getId(), commitResponse);
            if (saveLog) {
                recordService.save(apiCompanyRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.HuiZhongZhiDai.getCode(), apiCompanyRecord.getStatus(), customer.getId(), commitResponse);
            }
            return apiCompanyRecord;
        } else {
            ApiCompanyRecord failRecord = ApiCompanyRecord.getHuiZhongZhiDai(companyId, customer.getId(), hitResponse);
            if (saveLog) {
                recordService.save(failRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.HuiZhongZhiDai.getCode(), failRecord.getStatus(), customer.getId(), hitResponse);
            }
            return failRecord;
        }
    }
 
    /**
     * 手动审批分流
     *
     * @param customerId
     * @param apiCompanyId
     */
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public String manualApproval(Long customerId, Long apiCompanyId) {
        String result = null;
        try {
            Customer customer = customerMapper.selectById(customerId);
            if (customer == null) {
                throw new CommonException("客户不存在");
            }
            ApiCompany newApiCompany = getById(apiCompanyId);
            if (newApiCompany == null) {
                throw new CommonException("分流公司不存在");
            }
            log.info("手动审批分流开始,客户信息:" + customer.getName() + "分流公司:" + newApiCompany.getCompanyName());
            ApiCompanyRecord record = chooseApiCompany(newApiCompany, customer, true);
            if (record == null) {
                result = "数据推送失败,系统错误/网络超时/其他信息";
            } else if (record.getStatus() == ApiCompanyRecord.FAIL) {
                result = "数据推送失败," + record.getMessage();
            }
            log.info("手动审批分流结束");
        } catch (Exception e) {
            log.error("手动审批分流失败:" + e);
            result = "数据推送失败,系统错误/网络超时/其他信息";
        }
        return result;
    }
 
    private ApiCompanyRecord xinyeyoupinInterface(Customer customer, Long companyId, boolean saveLog) {
        String order = SerialGenerator.getOrder();
        String param = xinYeYouPinUtil.parseParam(customer, order);
        String result = null;
        try {
            log.info("信业优品推送数据开始,原始数据:" + param);
            result = HttpRequest.post(xinYeYouPinUtil.url)
                    .contentType("application/x-www-form-urlencoded")
                    .timeout(Constants.TIME_OUT)
                    .body(param).execute().body();
            log.info("信业优品推送结果:" + result);
        } catch (Exception e) {
            log.error("信业优品推送数据失败:" + e);
        }
        ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getXinYeYouPinRecord(companyId, customer.getId(), result);
        if (saveLog) {
            recordService.save(apiCompanyRecord);
            channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.XinYeYouPin.getCode(), apiCompanyRecord.getStatus(), customer.getId(), result);
        }
        return apiCompanyRecord;
    }
 
    private ApiCompanyRecord jinzhangguiInterface(Customer customer, Long companyId, boolean saveLog) {
        HashMap hitParam = JinZhangGuiUtil.parseHitParam(customer);
        log.info("金掌柜撞库开始,原始数据:" + hitParam);
        String hitResponse = HttpUtil.get(JinZhangGuiUtil.HIT_URL, hitParam, Constants.TIME_OUT);
        log.info("金掌柜撞库结果:" + hitResponse);
        JinZhangGuiResponse jinZhangGuiHitResponse = null;
        try {
            jinZhangGuiHitResponse = JSONObject.parseObject(hitResponse, JinZhangGuiResponse.class);
        } catch (Exception e) {
            log.error("金掌柜撞库对接失败");
        }
        if (jinZhangGuiHitResponse != null && JinZhangGuiUtil.SUCCESS.equals(jinZhangGuiHitResponse.getErrno())) {
            JSONObject commitParam = JinZhangGuiUtil.parseCommitParam(customer);
            log.info("金掌柜推送数据开始,原始数据:" + commitParam);
            String commitResponse = HttpUtil.post(JinZhangGuiUtil.COMMIT_URL, JSONObject.toJSONString(commitParam), Constants.TIME_OUT);
            log.info("金掌柜推送结果:" + commitResponse);
            ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinZhangGuiRecord(companyId, customer.getId(), commitResponse);
            if (saveLog) {
                recordService.save(apiCompanyRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JINZHANGGUI.getCode(), apiCompanyRecord.getStatus(), customer.getId(), commitResponse);
            }
            return apiCompanyRecord;
        } else {
            ApiCompanyRecord apiCompanyRecord = ApiCompanyRecord.getJinZhangGuiRecord(companyId, customer.getId(), hitResponse);
            if (saveLog) {
                recordService.save(apiCompanyRecord);
                channelLogService.createExportLog(customer.getSourceChannel(), SourceTypeEnum.JINZHANGGUI.getCode(), apiCompanyRecord.getStatus(), customer.getId(), hitResponse);
            }
            return apiCompanyRecord;
        }
    }
 
 
}