Commit 51710279 authored by 黎博's avatar 黎博

新增云信

parent 4011e8e8
...@@ -5,7 +5,8 @@ package cn.qg.qaplatform.common.enums; ...@@ -5,7 +5,8 @@ package cn.qg.qaplatform.common.enums;
*/ */
public enum FundEnum { public enum FundEnum {
GYXD("广达小贷", 480); GYXD("广达小贷", 480),
YNXT("云南信托", 1040);
private String name; private String name;
private Integer fundId; private Integer fundId;
......
...@@ -70,4 +70,6 @@ public interface QueryBasicLoanStatusDataMapper { ...@@ -70,4 +70,6 @@ public interface QueryBasicLoanStatusDataMapper {
Integer getAssignFundIdByUserId(String userId); Integer getAssignFundIdByUserId(String userId);
GenLoanUser getUserInfoByPhoneNo(String phoneNo); GenLoanUser getUserInfoByPhoneNo(String phoneNo);
Integer getLoanProgressByUserId(String userId);
} }
...@@ -350,6 +350,10 @@ public class MainProcess { ...@@ -350,6 +350,10 @@ public class MainProcess {
fundInfoObject.put("rateType", 1); fundInfoObject.put("rateType", 1);
fundInfoObject.put("priority", 1); fundInfoObject.put("priority", 1);
fundInfoObject.put("feeType", 1); fundInfoObject.put("feeType", 1);
// 如果是云南信托,需要该参数
if (fundId == 1040) {
fundInfoObject.put("fundProductId", 1061);
}
fundInfoList.add(fundInfoObject); fundInfoList.add(fundInfoObject);
firstTerm.put("fundInfo", fundInfoList); firstTerm.put("fundInfo", fundInfoList);
terms.add(firstTerm); terms.add(firstTerm);
...@@ -509,7 +513,7 @@ public class MainProcess { ...@@ -509,7 +513,7 @@ public class MainProcess {
/** /**
* 二次风控 * 二次风控
*/ */
public static boolean externalQuotaOrderAuditNotify(String namespace, String token, String uuid, Integer loanId, Integer bizType) { public static boolean externalQuotaOrderAuditNotify(String namespace, String token, String uuid, Integer loanId, Integer bizType, boolean auditResult) {
String url = "http://clotho-" + namespace + ".liangkebang.net" + "/external/quota/order_audit/notify"; String url = "http://clotho-" + namespace + ".liangkebang.net" + "/external/quota/order_audit/notify";
Map<String, Object> headers = new HashMap<>(); Map<String, Object> headers = new HashMap<>();
headers.put("Content-Type", "application/x-www-form-urlencoded"); headers.put("Content-Type", "application/x-www-form-urlencoded");
...@@ -521,7 +525,7 @@ public class MainProcess { ...@@ -521,7 +525,7 @@ public class MainProcess {
params.put("uuid", uuid); params.put("uuid", uuid);
params.put("bizNo", loanId); params.put("bizNo", loanId);
params.put("bizType", bizType); params.put("bizType", bizType);
params.put("auditResult", true); params.put("auditResult", auditResult);
params.put("deadLine", "1548518400"); params.put("deadLine", "1548518400");
JSONObject result = HttpClientUtils.doPost(url, params, headers); JSONObject result = HttpClientUtils.doPost(url, params, headers);
log.info("二次风控:" + result); log.info("二次风控:" + result);
...@@ -735,9 +739,11 @@ public class MainProcess { ...@@ -735,9 +739,11 @@ public class MainProcess {
Date date = new Date(); Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String today = formatter.format(date); String today = formatter.format(date);
for (int i=0; i < dataList.size(); i++) { if (dataList != null) {
if (dataList.get(i).get("planDate").toString().equals(today)) { for (int i=0; i < dataList.size(); i++) {
flag = true; if (dataList.get(i).get("planDate").toString().equals(today)) {
flag = true;
}
} }
} }
log.info("资金方是否已经分配:" + flag); log.info("资金方是否已经分配:" + flag);
......
...@@ -25,7 +25,7 @@ public interface GenUserDataService { ...@@ -25,7 +25,7 @@ public interface GenUserDataService {
* @param applyLoanInfo 造数据相关信息 * @param applyLoanInfo 造数据相关信息
* @return 成功或失败 * @return 成功或失败
*/ */
boolean withDraw(ApplyLoanInfo applyLoanInfo) throws Exception; boolean withDraw(ApplyLoanInfo applyLoanInfo, boolean auditResult) throws Exception;
/** /**
* 放款 * 放款
......
...@@ -70,4 +70,9 @@ public interface QueryBasicLoanStatusDataService { ...@@ -70,4 +70,9 @@ public interface QueryBasicLoanStatusDataService {
* 根据手机号查询用户信息 * 根据手机号查询用户信息
*/ */
GenLoanUser getUserInfoByPhoneNo(String namespace, String phoneNo); GenLoanUser getUserInfoByPhoneNo(String namespace, String phoneNo);
/**
* 根据userId获取用户放款状态
*/
Integer getLoanProgressByUserId(String namespace, String userId);
} }
...@@ -7,6 +7,7 @@ import cn.qg.qaplatform.process.xyqb.MainProcess; ...@@ -7,6 +7,7 @@ import cn.qg.qaplatform.process.xyqb.MainProcess;
import cn.qg.qaplatform.service.GenUserDataService; import cn.qg.qaplatform.service.GenUserDataService;
import cn.qg.qaplatform.service.QueryBasicLoanStatusDataService; import cn.qg.qaplatform.service.QueryBasicLoanStatusDataService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -110,14 +111,11 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -110,14 +111,11 @@ public class GenUserDataServiceImpl implements GenUserDataService {
String productId = authResult.get("product_id").toString(); String productId = authResult.get("product_id").toString();
// 风控授信回调 // 风控授信回调
boolean creditResult = MainProcess.creditAuthNotify(namespace, token, uuid, channelId, fundId, orderNo, 0, auditResult, amount, term); boolean creditResult = MainProcess.creditAuthNotify(namespace, token, uuid, channelId, fundId, orderNo, 0, auditResult, amount, term);
WebSocketServer.sendInfo("风控授信回调:" + creditResult, symbol); // 风控授信回调成功,redis值为0
String redisKey = namespace + "_" + phoneNo;
if (creditResult) { if (creditResult) {
redisTemplate.opsForValue().set(redisKey, 0); setUserStatusRedisValue(namespace, phoneNo, 0);
log.info("风控授信回调接口返回成功,设置redis缓存:" + redisKey + ": 0");
} else { } else {
redisTemplate.opsForValue().set(redisKey, 1); setUserStatusRedisValue(namespace, phoneNo, 1);
log.info("风控授信回调接口返回失败,设置redis缓存:" + redisKey + ": 1");
} }
return creditResult; return creditResult;
} }
...@@ -125,11 +123,12 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -125,11 +123,12 @@ public class GenUserDataServiceImpl implements GenUserDataService {
/** /**
* 提现 * 提现
* @param applyLoanInfo 造数据相关信息 * @param applyLoanInfo 造数据相关信息
* @param auditResult 二次风控成功or失败
* @return * @return
* @throws Exception * @throws Exception
*/ */
@Override @Override
public boolean withDraw(ApplyLoanInfo applyLoanInfo) throws Exception { public boolean withDraw(ApplyLoanInfo applyLoanInfo, boolean auditResult) throws Exception {
String namespace = applyLoanInfo.getNamespace(); String namespace = applyLoanInfo.getNamespace();
String phoneNo = applyLoanInfo.getPhoneNo(); String phoneNo = applyLoanInfo.getPhoneNo();
Integer channelId = applyLoanInfo.getChannel(); Integer channelId = applyLoanInfo.getChannel();
...@@ -171,16 +170,11 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -171,16 +170,11 @@ public class GenUserDataServiceImpl implements GenUserDataService {
// 绑卡后提现 // 绑卡后提现
Integer loanId = MainProcess.createLoan(namespace, token, amount, term, accountId, productId, cardId, cardBindInfoId); Integer loanId = MainProcess.createLoan(namespace, token, amount, term, accountId, productId, cardId, cardBindInfoId);
// 二次风控 // 二次风控
boolean result = MainProcess.externalQuotaOrderAuditNotify(namespace, token, uuid, loanId, 0); boolean result = MainProcess.externalQuotaOrderAuditNotify(namespace, token, uuid, loanId, 0, auditResult);
// 修改合同状态 // 修改合同状态
MainProcess.modifyContactStatus(namespace, userId); MainProcess.modifyContactStatus(namespace, userId);
String redisKey = namespace + "_" + phoneNo;
if (result) { if (result) {
redisTemplate.opsForValue().set(redisKey, 2); setUserStatusRedisValue(namespace, phoneNo, 2);
log.info("提现成功,设置redis缓存:" + redisKey + ": 2");
} else {
redisTemplate.opsForValue().set(redisKey, 10);
log.info("提现失败,设置redis缓存:" + redisKey + ": 10");
} }
return result; return result;
} }
...@@ -220,18 +214,71 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -220,18 +214,71 @@ public class GenUserDataServiceImpl implements GenUserDataService {
MainProcess.fundsPlanLoanApply(namespace,opToken, fundId, money, people); MainProcess.fundsPlanLoanApply(namespace,opToken, fundId, money, people);
Thread.sleep(30000); Thread.sleep(30000);
// 放款结果通知 // 放款结果通知
boolean result = MainProcess.payNotify(namespace, loanId, payStatus); boolean makeLoanResult = MainProcess.payNotify(namespace, loanId, payStatus);
if (result) { if (makeLoanResult) {
redisTemplate.opsForValue().set(namespace + "_" + phoneNo, 3); setUserStatusRedisValue(namespace, phoneNo, 3);
log.info("放款成功,设置redis缓存:" + namespace + "-" + phoneNo + ": 3");
} else { } else {
redisTemplate.opsForValue().set(namespace + "_" + phoneNo, 4); setUserStatusRedisValue(namespace, phoneNo, 4);
log.info("放款失败,设置redis缓存:" + namespace + "-" + phoneNo + ": 4");
} }
return result; return makeLoanResult;
}
/**
* 设置redis值,查询状态
* @param namespace
* @param phoneNo
* @param status 0-授信成功,1-授信失败,2-提现成功,3-放款成功,4-放款失败
*/
public void setUserStatusRedisValue(String namespace, String phoneNo, Integer status) {
String redisKey = namespace + "_" + phoneNo;
redisTemplate.opsForValue().set(redisKey, status);
} }
/**
* 查询资方分配进度
*/
public void queryFundingAssignProgress(String namespace, String userId, Integer fundId, String symbol) throws InterruptedException {
while (true) {
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId);
log.info(searchResult.toString());
if (fundId.equals(searchResult)) {
log.info("用户:" + userId + "资方分配成功!");
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方分配成功.", symbol);
}
break;
} else {
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
}
Thread.sleep(10000);
}
}
}
/**
* 查询用户放款状态
* @param namespace
* @param userId
* @param symbol
*/
public void queryLoanProgress(String namespace, String userId, String symbol) throws InterruptedException {
while (true) {
Integer progress = queryBasicLoanStatusDataService.getLoanProgressByUserId(namespace, userId);
if (progress == 15) {
log.info("用户:" + userId + "放款成功!");
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("放款成功.", symbol);
}
break;
} else {
if (!StringUtils.isEmpty(symbol)) {
WebSocketServer.sendInfo("查询到的状态为:" + progress + ",资方放款中,30秒后重新查询状态!", symbol);
}
Thread.sleep(30000);
}
}
}
@Override @Override
public boolean genLoanUser(ApplyLoanInfo applyLoanInfo) throws Exception { public boolean genLoanUser(ApplyLoanInfo applyLoanInfo) throws Exception {
...@@ -267,20 +314,9 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -267,20 +314,9 @@ public class GenUserDataServiceImpl implements GenUserDataService {
return false; return false;
} }
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId(); String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) { // 查询资方审核进度,如未分配成功,则阻塞下一步
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId); queryFundingAssignProgress(namespace, userId, fundId, symbol);
log.info(searchResult.toString()); return withDraw(applyLoanInfo, true);
if (fundId.equals(searchResult)) {
log.info("资方分配成功!");
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方分配成功.", symbol);
break;
} else {
log.info("资方仍未分配成功!");
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
Thread.sleep(10000);
}
}
return withDraw(applyLoanInfo);
} }
/** /**
...@@ -292,26 +328,23 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -292,26 +328,23 @@ public class GenUserDataServiceImpl implements GenUserDataService {
return false; return false;
} }
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId(); String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) { // 查询资方审核进度,如未分配成功,则阻塞下一步
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId); queryFundingAssignProgress(namespace, userId, fundId, symbol);
log.info(searchResult.toString()); boolean withDrawResult = withDraw(applyLoanInfo, true);
if (fundId.equals(searchResult)) {
log.info("资方分配成功!");
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方分配成功.", symbol);
break;
} else {
log.info("资方仍未分配成功!");
WebSocketServer.sendInfo("查询到的资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
Thread.sleep(10000);
}
}
boolean withDrawResult = withDraw(applyLoanInfo);
if (!withDrawResult) { if (!withDrawResult) {
WebSocketServer.sendInfo("提现失败!", symbol); WebSocketServer.sendInfo("提现失败!", symbol);
return false; return false;
} }
// 如果资方选择云信,则不需要手动调放款
if (fundId == 1040) {
WebSocketServer.sendInfo("提现成功,等待云信放款...", namespace);
queryLoanProgress(namespace, userId, symbol);
setUserStatusRedisValue(namespace, phoneNo, 3); // 因为没有调放款广达放款接口,因此需要手动设置redis值
return true;
}
WebSocketServer.sendInfo("提现成功,10秒后放款!", symbol); WebSocketServer.sendInfo("提现成功,10秒后放款!", symbol);
Thread.sleep(10000); Thread.sleep(10000);
// 广达小贷-手动放款
boolean makeLoanResult = makeLoan(applyLoanInfo, true); boolean makeLoanResult = makeLoan(applyLoanInfo, true);
if (makeLoanResult) { if (makeLoanResult) {
WebSocketServer.sendInfo("放款成功!", symbol); WebSocketServer.sendInfo("放款成功!", symbol);
...@@ -330,20 +363,16 @@ public class GenUserDataServiceImpl implements GenUserDataService { ...@@ -330,20 +363,16 @@ public class GenUserDataServiceImpl implements GenUserDataService {
return false; return false;
} }
String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId(); String userId = queryBasicLoanStatusDataService.getUserInfoByPhoneNo(namespace, phoneNo).getUserId();
while (true) { // 查询资方审核进度,如未分配成功,则阻塞下一步
Integer searchResult = queryBasicLoanStatusDataService.getAssignFundIdByUserId(namespace, userId); queryFundingAssignProgress(namespace, userId, fundId, symbol);
log.info(searchResult.toString()); // 云南信托:二次风控失败,即代表放款失败
if (fundId.equals(searchResult)) { if (fundId == 1040) {
log.info("资方分配成功!"); withDraw(applyLoanInfo, false);
WebSocketServer.sendInfo("查询到资方为:" + searchResult +",资方分配成功!", symbol); WebSocketServer.sendInfo("放款失败!", symbol);
break; setUserStatusRedisValue(namespace, phoneNo, 4);
} else { return true;
log.info("资方仍未分配成功!");
WebSocketServer.sendInfo("查询到资方为:" + searchResult +",资方还未分配成功,10秒后重试", symbol);
Thread.sleep(10000);
}
} }
boolean withDrawResult = withDraw(applyLoanInfo); boolean withDrawResult = withDraw(applyLoanInfo, true);
if (!withDrawResult) { if (!withDrawResult) {
WebSocketServer.sendInfo("提现失败!", symbol); WebSocketServer.sendInfo("提现失败!", symbol);
return false; return false;
......
...@@ -176,4 +176,10 @@ public class QueryBasicLoanStatusDataServiceImpl implements QueryBasicLoanStatus ...@@ -176,4 +176,10 @@ public class QueryBasicLoanStatusDataServiceImpl implements QueryBasicLoanStatus
SwitchDataSource.dataSourceSwitch(namespace, "xyqb_user"); SwitchDataSource.dataSourceSwitch(namespace, "xyqb_user");
return basicLoanStatusDataMapper.getUserInfoByPhoneNo(phoneNo); return basicLoanStatusDataMapper.getUserInfoByPhoneNo(phoneNo);
} }
@Override
public Integer getLoanProgressByUserId(String namespace, String userId) {
SwitchDataSource.dataSourceSwitch(namespace, "xyqb");
return basicLoanStatusDataMapper.getLoanProgressByUserId(userId);
}
} }
...@@ -99,4 +99,10 @@ ...@@ -99,4 +99,10 @@
WHERE `phone_no` = #{phoneNo} WHERE `phone_no` = #{phoneNo}
</select> </select>
<!-- 根据用户id获取放款进度 -->
<select id="getLoanProgressByUserId" resultType="java.lang.Integer">
SELECT `progress` FROM `loan_application_history`
WHERE `user_id`=#{userId}
</select>
</mapper> </mapper>
\ No newline at end of file
...@@ -17,10 +17,10 @@ import java.util.List; ...@@ -17,10 +17,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class xyqb { public class xyqb {
public static String namespace = "pre"; public static String namespace = "xyqb";
public static Integer channelId = 1; public static Integer channelId = 1;
public static Integer fundId = 480; public static Integer fundId = 1040;
public static String phone = "18300000378"; public static String phone = "18300120382";
public static String token = ""; public static String token = "";
public static String uuid = ""; public static String uuid = "";
public static Long userId; public static Long userId;
...@@ -307,6 +307,7 @@ public class xyqb { ...@@ -307,6 +307,7 @@ public class xyqb {
JSONArray financeProducts = createFinanceProducts(); JSONArray financeProducts = createFinanceProducts();
params.put("financeProducts", financeProducts); params.put("financeProducts", financeProducts);
JSONObject result = HttpClientUtils.doPost(url, params, headers); JSONObject result = HttpClientUtils.doPost(url, params, headers);
System.out.println("风控授信回调参数:" + params);
System.out.println("风控授信回调:" + result); System.out.println("风控授信回调:" + result);
} }
...@@ -328,6 +329,10 @@ public class xyqb { ...@@ -328,6 +329,10 @@ public class xyqb {
fundInfoObject.put("rateType", 1); fundInfoObject.put("rateType", 1);
fundInfoObject.put("priority", 1); fundInfoObject.put("priority", 1);
fundInfoObject.put("feeType", 1); fundInfoObject.put("feeType", 1);
// 云信判断
if (fundId == 1040) {
fundInfoObject.put("fundProductId", 1061);
}
fundInfoList.add(fundInfoObject); fundInfoList.add(fundInfoObject);
firstTerm.put("fundInfo", fundInfoList); firstTerm.put("fundInfo", fundInfoList);
terms.add(firstTerm); terms.add(firstTerm);
...@@ -628,15 +633,28 @@ public class xyqb { ...@@ -628,15 +633,28 @@ public class xyqb {
Date date = new Date(); Date date = new Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String today = formatter.format(date); String today = formatter.format(date);
for (int i=0; i < dataList.size(); i++) { if (dataList != null) {
if (dataList.get(i).get("planDate").toString().equals(today)) { for (int i=0; i < dataList.size(); i++) {
flag = true; if (dataList.get(i).get("planDate").toString().equals(today)) {
flag = true;
}
} }
} }
System.out.println("资金方是否已经分配:" + flag); System.out.println("资金方是否已经分配:" + flag);
return flag; return flag;
} }
/**
* 云信插入银行卡
*/
public static void insertBankCardOfYunxing() throws SQLException {
String sql = "INSERT INTO `card_check_record`(`user_id`, `card_no`, `bank_code`, `bank_name`, `branch_no`, `branch_name`, `province`, `city`, `card_type`, `is_active`, `created_at`, `updated_at`) VALUES (" + userId + ", '6222988108217968', 'PINGAN', '平安银行', NULL, NULL, NULL, NULL, 2, 1, '2020-08-13 14:04:27', '2020-08-13 14:04:27');";
System.out.println(sql);
DBUtils dbUtils = new DBUtils(namespace, "payment_center", "qa", "qatest");
Integer result = dbUtils.insert(sql);
System.out.println("云信插入银行卡结果:" + result);
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
// 分配资金方 // 分配资金方
...@@ -651,6 +669,10 @@ public class xyqb { ...@@ -651,6 +669,10 @@ public class xyqb {
// 授信 // 授信
login(); login();
checkUserId(); checkUserId();
// 如果是云信,则需要插入银行卡
if (fundId == 1040) {
insertBankCardOfYunxing();
}
syncSessionToXyqb(); syncSessionToXyqb();
creditSessionSync(); creditSessionSync();
realNameVerified(); realNameVerified();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment