From 09d882262f530ded672f1c01fb65a1fefa00d52d Mon Sep 17 00:00:00 2001
From: ab <myjf007@126.com>
Date: Tue, 05 Nov 2024 09:37:41 +0800
Subject: [PATCH] [fixed]我来贷未推送数据存入到定时器中
---
src/main/java/com/nova/sankuai/infra/utils/wolaidai/WolaidaiUtil.java | 242 ++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 234 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/nova/sankuai/infra/utils/wolaidai/WolaidaiUtil.java b/src/main/java/com/nova/sankuai/infra/utils/wolaidai/WolaidaiUtil.java
index bb248df..b0e5c6a 100644
--- a/src/main/java/com/nova/sankuai/infra/utils/wolaidai/WolaidaiUtil.java
+++ b/src/main/java/com/nova/sankuai/infra/utils/wolaidai/WolaidaiUtil.java
@@ -17,6 +17,7 @@
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;
@@ -80,6 +81,9 @@
@Value("${rongbei.h5HalfUrl}")
private String h5HalfUrl; // 融呗非半流程h5Url
+
+ @Value("${front.refreshToUrl}")
+ private String refreshToUrl; // 前端跳转地址
@Value("${rongbei.wolaidai.url}")
private String wldUrl; // 我来贷URL
@@ -177,6 +181,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;
@@ -220,7 +225,6 @@
wrapper.eq(CapitalInfo::getCollionMode, ENABLE_FLAG); // 联登模式:半流程
wrapper.isNull(CapitalInfo::getAlwayShow); // 是否一直显示:是
wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列
- log.info("获取要推送的半流程资方的条件---getCapitalInfoList:{}", wrapper);
return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表
}
@@ -233,7 +237,6 @@
wrapper.eq(CapitalInfo::getAutoPush, DISABLE_FLAG); // 自动推送:启用
wrapper.eq(CapitalInfo::getCollionMode, DISABLE_FLAG); // 联登模式:非半流程
wrapper.orderByAsc(CapitalInfo::getSeq); // 按序号升序排列
- log.info("获取要推送的非半流程资方---getNotHalfCapitalInfoList:{}", wrapper);
return capitalInfoService.list(wrapper); // 返回匹配的资金信息列表
}
@@ -346,7 +349,6 @@
break;
}
}
-
return basicInfo; // 返回配置映射
}
@@ -397,7 +399,7 @@
JSON.toJSONString(applyDto);
decryptStr = JSON.toJSONString(applyDto);
//发送短信通知(等待供应商审批短信模板 申请完后在恢复注释)
- //smsNotify(profileDictDto.getPhone());
+ smsNotify(profileDictDto.getPhone());
}
String bizDataStr = "";
String fBizDataStr = "";
@@ -415,9 +417,22 @@
Long capitalId = customerApplyOrder.getCapitalId();
String h5Url = "";
// 如果是慧钱,随易花,e时贷,好汇推,则转为乐享融的指定id:28
- if (capitalId == 12L || capitalId == 41L || capitalId == 36L || capitalId == 25L || capitalId == 4L) {
+ 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;
@@ -433,7 +448,7 @@
List<CapitalInfo> capitalInfoList = getCapitalInfoList();
for (CapitalInfo capitalInfo : capitalInfoList) {
Map<String, String> config = getConfigByCapitalName(capitalInfo.getName());// 获取对应的配置
- log.info("日志编号:{},{}方法:{}, 资方名:【{}】,result: {}", logNumber, basicInfo.get("targetName"), action, capitalInfo.getName(), config); // 记录资金信息
+ 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());// 设置当前时间戳
@@ -688,6 +703,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());
}
@@ -726,6 +745,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 +954,14 @@
customerCheckRecord.setType(1);
log.error("日志编号:{},【{}】保存准入记录开始,customerCheckRecord:{}", IdUtil.randomUUID(), capitalName, customerCheckRecord);
return customerCheckRecord;
+ }
+
+ /**
+ * 保存我来贷推送的数据记录
+ * @param customerWldPushRecord 要保存的数据
+ */
+ private void savePushData(CustomerWldPushRecord customerWldPushRecord) {
+ customerWldPushRecordService.save(customerWldPushRecord);
}
/**
@@ -1302,7 +1507,28 @@
* @param phone
*/
public void smsNotify(String phone) {
- String content = "您申请的信用额已通过审核,请1小时内查看【" + smsNotifyUrl + "】 过期作废!拒收请回复R";
- ShanDongMessageSendUtil.sendSMSContent(phone, content);
+ 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("验证码发送失败");
+ }
+
}
}
--
Gitblit v1.9.3