Commit 51710279 authored by 黎博's avatar 黎博

新增云信

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