ab
2024-11-05 bead00668eebce8d39d027515d564376de2f5978
src/main/java/com/nova/sankuai/infra/utils/wolaidai/WolaidaiUtil.java
@@ -177,6 +177,7 @@
    private final ICustomerCheckRecordService customerCheckRecordService; // 用户准入务
    private final ICustomerH5ClickService customerH5ClickService; // H5用户点击埋点服务
    private final ICapitalInfoService capitalInfoService; // 资金信息服务
    private final ICustomerWldPushRecordService customerWldPushRecordService; // 我来贷推送记录服务
    private final EsdUtil esdUtil;
    private final HjqbUtil hjqbUtil;
    private final SyhUtil syhUtil;
@@ -685,6 +686,10 @@
                log.error("日志编号:{},【我来贷】{}参数验签失败,jsonData:{} ex:{}", logNumber, basicInfo.get("targetName"), body, "验签失败");
            }
        } catch (Exception e) {
            // 失败,未执行的数据,则保存到记录表,后面再用定时器执行
            CustomerWldPushRecord customerWldPushRecord = new CustomerWldPushRecord();
            BeanUtils.copyProperties(customerWldPushRecord, body);
            savePushData(customerWldPushRecord);
            resp.setMsg(e.getMessage());
            log.error("日志编号:{},【我来贷】{},请求失败:{} 错误原因:{}", logNumber, basicInfo.get("targetName"), body, e.getMessage());
        }
@@ -723,6 +728,184 @@
        return resp;
    }
    public void wldCronPush(CustomerWldPushRecord customerWldPushRecord) {
        String logNumber = IdUtil.randomUUID(); // 生成日志编号
        log.info("日志编号:{} , 定时器自动进件, 要推送的数据:{}", logNumber, customerWldPushRecord);
        JSONObject getFullData = new JSONObject(); // 创建JSON对象存储数据
        getFullData.putOpt("partner_id", customerWldPushRecord.getPartnerId()); // 存储合作伙伴ID
        getFullData.putOpt("timestamp", customerWldPushRecord.getTimestamp()); // 存储时间戳
        getFullData.putOpt("biz_data", customerWldPushRecord.getBizData()); // 存储业务数据
        Map<String, String> basicInfo = getBasicInfoByAction("apply");
        String chnOrderId = "";
        // 解密+验签
        String  decryptStr = decrypt(getFullData, customerWldPushRecord.getSign(), wldPublicKey);// 解密
        if (StringUtils.isNotEmpty(decryptStr)) {
            Customer customer = new Customer();
            // 修改借款额度,采用随机生成
            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, applyDto);
            customer = saveData(applyDto);
            JSON.toJSONString(applyDto);
            decryptStr = JSON.toJSONString(applyDto);
            // 遍历半流程资金信息列表
            List<CapitalInfo> capitalInfoList = getCapitalInfoList();
            log.info("日志编号:{},定时器自动进件, 半半流程的资方列表:【{}】", logNumber, capitalInfoList); // 半流程的资方列表
            CustomerApplyOrder customerApplyOrder;
            LambdaQueryWrapper<CustomerApplyOrder> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(CustomerApplyOrder::getChnOrderId, chnOrderId);
            wrapper.last("limit 1");
            for (CapitalInfo capitalInfo : capitalInfoList) {
                // 先判断有没有推过,如果有则不再推送
                wrapper.eq(CustomerApplyOrder::getCapitalId, capitalInfo.getId());
                customerApplyOrder = customerApplyOrderService.getOne(wrapper);
                if (Objects.isNull(customerApplyOrder)) {
                    Map<String, String> config = getConfigByCapitalName(capitalInfo.getName());// 获取对应的配置
                    log.info("日志编号:{},定时器自动进件, 资方名:【{}】,config配置信息: {}", logNumber,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, capitalInfo.getName(), fullData, result);// 记录接口结果
                            if (result != null) { // 确保result不为空
                                RbResponse resp = JSON.parseObject(result, RbResponse.class);// 解析响应
                                String data = resp.getData();// 获取数据部分
                                JSONObject hjData = new JSONObject();
                                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)) {// 判断解密结果
                                        ApplyData applyData = JSON.parseObject(decryptHjStr, ApplyData.class);
                                        if (applyData.getStatus() == 0) { // 进件成功后才保存
                                            // 进件成功后,调用接受订单状态接口推送数据给我来贷
                                            OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id());
                                            // 调用接受授信结果接口推送授信结果给我来贷
                                            autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id());
                                        }
                                        // 保存进件记录
                                        customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, config.get("partnerId"), decryptStr);
                                        customerApplyOrderService.save(customerApplyOrder);
                                        log.info("日志编号:{},【{}】,定时器自动进件解密结果:{}", logNumber, capitalInfo.getName(), decryptHjStr);
                                    } else {
                                        log.error("日志编号:{}, 【{}】,定时器自动进件解密结果失败:{}", logNumber, capitalInfo.getName(), decryptHjStr);
                                    }
                                } else {
                                    log.error("日志编号:{}, 资方:【{}】定时器自动进件失败:{}", logNumber, capitalInfo.getName(), result);
                                }
                            }
                        } catch (Exception ex) {
                            // 处理请求异常
                            log.error("日志编号:{},定时器自动进件, 资方名:【{}】,传参:{} ex:{}", logNumber, capitalInfo.getName(), fullData, ex.getMessage());//记录异常堆栈
                        }
                    }
                }
            }
            // 遍历非半流程资金信息列表
            List<CapitalInfo> lst = getNotHalfCapitalInfoList();
            log.info("日志编号:{},定时器自动进件, 非半流程的资方列表:【{}】", logNumber, lst); // 非半流程的资方列表
            for (CapitalInfo capitalInfo : lst) {
                // 先判断有没有推过,如果有则不再推送
                wrapper.eq(CustomerApplyOrder::getCapitalId, capitalInfo.getId());
                customerApplyOrder = customerApplyOrderService.getOne(wrapper);
                if (Objects.isNull(customerApplyOrder)) {
                    wrapper.eq(CustomerApplyOrder::getCapitalId, capitalInfo.getId());
                    customerApplyOrder = customerApplyOrderService.getOne(wrapper);
                    if (Objects.isNull(customerApplyOrder)) {
                        boolean halfFlag = false;
                        //调用对应资方的推送机制
                        if (capitalInfo.getId() == 25L) { //e时贷
                            halfFlag = esdUtil.wldPushToEsd(customer, logNumber);
                        } else if (capitalInfo.getId() == 12L) { //慧借钱包
                            halfFlag = hjqbUtil.wldPushToHjqb(customer, logNumber);
                        } else if (capitalInfo.getId() == 41L) { //好汇推
                            halfFlag = hhtUtil.wldPushToHht(customer, logNumber);
                        } else if (capitalInfo.getId() == 36L) { //随易花
                            halfFlag = syhUtil.wldPushToSyh(customer, logNumber);
                        }
                        if (halfFlag) {
                            // 进件成功后,调用接受订单状态接口推送数据给我来贷
                            OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id());
                            // 调用接受授信结果接口推送授信结果给我来贷
                            autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id());
                        }
                        // 保存进件记录
                        customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, "28", decryptStr);
                        customerApplyOrderService.save(customerApplyOrder);
                    }
                }
            }
            // 遍历非半流程资金方式线上贷款信息列表
            List<CapitalInfo> notHalfFundTypeCapitalInfoList = getNotHalfFundTypeCapitalInfoList();
            log.info("日志编号:{},定时器自动进件, 非半流程资金方式线上贷款信息列表:【{}】", logNumber, lst); // 非半流程资金方式线上贷款信息列表
            Customer customer = new Customer();
            for (CapitalInfo capitalInfo : notHalfFundTypeCapitalInfoList) {
                // 先判断有没有推过,如果有则不再推送
                wrapper.eq(CustomerApplyOrder::getCapitalId, capitalInfo.getId());
                customerApplyOrder = customerApplyOrderService.getOne(wrapper);
                if (Objects.isNull(customerApplyOrder)) {
                    boolean halfFlag = false;
                    //调用对应资方的推送机制
                    if (capitalInfo.getId() == 25L) { //e时贷
                        halfFlag = esdUtil.wldPushToEsd(customer, logNumber);
                    } else if (capitalInfo.getId() == 12L) { //慧借钱包
                        halfFlag = hjqbUtil.wldPushToHjqb(customer, logNumber);
                    } else if (capitalInfo.getId() == 41L) { //好汇推
                        halfFlag = hhtUtil.wldPushToHht(customer, logNumber);
                    } else if (capitalInfo.getId() == 36L) { //随易花
                        halfFlag = syhUtil.wldPushToSyh(customer, logNumber);
                    }
                    if (halfFlag) {
                        // 进件成功后,调用接受订单状态接口推送数据给我来贷
                        OrderStatusByWld(chnOrderId, applyData.getPartner_flow_id());
                        // 调用接受授信结果接口推送授信结果给我来贷
                        autoPushCreditResult(chnOrderId, applyData.getPartner_flow_id());
                    }
                    // 保存进件记录
                    customerApplyOrder = getCustomerApplyOrder(chnOrderId, applyData, capitalInfo, "28", decryptStr);
                    customerApplyOrderService.save(customerApplyOrder);
                }
            }
        }
    }
    private static @NotNull CustomerApplyOrder getCustomerApplyOrder(String chnOrderId, ApplyData applyData, CapitalInfo capitalInfo, String partnerId, String decryptStr) {
        CustomerApplyOrder customerApplyOrder = new CustomerApplyOrder();
        customerApplyOrder.setCapitalId(capitalInfo.getId());
@@ -757,6 +940,14 @@
    }
    /**
     * 保存我来贷推送的数据记录
     * @param customerWldPushRecord 要保存的数据
     */
    private void savePushData(CustomerWldPushRecord customerWldPushRecord) {
        customerWldPushRecordService.save(customerWldPushRecord);
    }
    /**
     * 保存数据
     * @param applyDto 数据对象
     */